2012-04-26 12:43:28 +00:00
|
|
|
;;; url.el --- Uniform Resource Locator retrieval tool -*- lexical-binding: t -*-
|
2004-04-12 20:50:16 +00:00
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
;; Copyright (C) 1996-1999, 2001, 2004-2024 Free Software Foundation,
|
2015-01-01 22:26:41 +00:00
|
|
|
;; Inc.
|
2004-04-12 20:50:16 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Author: Bill Perry <wmperry@gnu.org>
|
2019-05-25 20:43:06 +00:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Keywords: comm, data, processes, hypermedia
|
|
|
|
|
2004-04-12 20:50:16 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 04:29:13 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2004-04-12 20:50:16 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2004-04-12 20:50:16 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2008-05-06 04:29:13 +00:00
|
|
|
|
2004-04-12 20:50:16 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2004-04-12 20:50:16 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2020-10-01 13:24:21 +00:00
|
|
|
;; Registered URI schemes: https://www.iana.org/assignments/uri-schemes
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2004-04-12 20:50:16 +00:00
|
|
|
;;; Code:
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
|
Stop message.el from loading about 40 libraries it doesn't always need.
The general approach is to autoload rather than require, and to
require in the specific functions rather than the file. (Bug#5642)
* url/url.el: Move mailcap require earlier in the file.
* gnus/gmm-utils.el: Don't require wid-edit.
(widget-create-child-value, widget-convert, widget-default-get):
Autoload.
* gnus/gnus-util.el: Don't require time-date, netrc.
(message-fetch-field, gnus-group-name-decode): Declare rather than
autoloading.
(gnus-fetch-field): Require message.
(gnus-decode-newsgroups): Require gnus-group.
* gnus/ietf-drums.el: Don't require time-date.
* gnus/message.el: Don't require hashcash, canlock, ecomplete.
Do require mail-utils. Require nnheader only when compiling.
(smtpmail-default-smtp-server): Remove declaration.
(message-send-mail-function): Check smtpmail-default-smtp-server
is bound rather than requiring smtpmail.
(message-auto-save-directory, message-insert-signature): Use
expand-file-name rather than nnheader-concat.
(nnheader-insert-file-contents): Autoload.
(hashcash-wait-async): Declare.
(message-send-mail): Only call gnus-setup-posting-charset if
gnus-group-posting-charset-alist is bound. Require hashcash if needed.
(message-send-mail-with-sendmail): Require sendmail.
(canlock-password, canlock-password-for-verify): Declare.
(message-canlock-password): Require canlock.
(nnheader-get-report): Autoload.
(gnus-setup-posting-charset): Declare.
(message-send-news): Require gnus-msg.
(message-make-references, message-make-in-reply-to): Use mail-header-id
rather than the alias mail-header-message-id.
(ecomplete-add-item, ecomplete-save): Declare.
(message-put-addresses-in-ecomplete): Require ecomplete.
(ecomplete-display-matches): Autoload.
* gnus/mm-decode.el: Don't require mailcap, gnus-util.
(gnus-map-function, gnus-replace-in-string, gnus-read-shell-command)
(message-fetch-field, mailcap-parse-mailcaps, mailcap-mime-info):
Autoload.
(mailcap-mime-extensions): Declare.
* gnus/mm-encode.el: Don't require mailcap.
(mailcap-extension-to-mime): Autoload.
* gnus/mml-sec.el: Don't require password-cache.
* gnus/mml.el (gnus-setup-posting-charset): Declare rather than autoload.
(mailcap-parse-mimetypes, mailcap-mime-types): Declare.
(mml-minibuffer-read-type): Require mailcap.
(mml-preview): Require gnus-msg.
* gnus/mml1991.el: Require password-cache.
(password-cache-expiry): Remove declaration.
* gnus/mml2015.el: Require password-cache.
(password-cache-expiry): Remove declaration.
* gnus/nneething.el (mailcap): Require mailcap.
* gnus/nnheader.el: (declare-function): Add compatibility stub.
(message-remove-header): Declare rather than autoload.
(nnheader-replace-header): Require message.
* gnus/nnimap.el (declare-function): Add compatibility stub.
(netrc-parse, netrc-machine-user-or-password): Declare.
(nnimap-open-connection): Require netrc.
* gnus/nntp.el (declare-function): Add compatibility stub.
(netrc-parse, netrc-machine, netrc-get): Declare.
(nntp-send-authinfo): Require netrc.
* gnus/rfc2047.el: Don't require qp.
(quoted-printable-encode-region, quoted-printable-decode-string):
Autoload.
* gnus/sieve-mode.el: Don't require easymenu.
(easy-menu-add-item): Autoload it.
* gnus/spam-stat.el (time-to-number-of-days): Autoload it.
* password-cache.el (password-cache, password-cache-expiry):
Autoload.
2010-03-19 02:55:37 +00:00
|
|
|
(require 'mailcap)
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
(eval-when-compile
|
|
|
|
(require 'mm-decode)
|
|
|
|
(require 'mm-view))
|
|
|
|
|
|
|
|
(require 'url-vars)
|
|
|
|
(require 'url-cookie)
|
|
|
|
(require 'url-history)
|
|
|
|
(require 'url-expand)
|
|
|
|
(require 'url-privacy)
|
|
|
|
(require 'url-methods)
|
|
|
|
(require 'url-proxy)
|
|
|
|
(require 'url-parse)
|
|
|
|
(require 'url-util)
|
|
|
|
|
2007-12-11 05:48:25 +00:00
|
|
|
|
|
|
|
(defcustom url-configuration-directory
|
2008-10-24 09:44:46 +00:00
|
|
|
(locate-user-emacs-file "url/" ".url/")
|
2007-12-11 05:48:25 +00:00
|
|
|
"Directory used by the URL package for cookies, history, etc."
|
|
|
|
:type 'directory
|
|
|
|
:group 'url)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-do-setup ()
|
Typo and docstring fixes.
* url.el (url-do-setup):
* url-dired.el (url-dired-minor-mode):
* url-file.el (url-file-find-possibly-compressed-file):
* url-gw.el (url-gateway-broken-resolution):
* url-handlers.el (url-handler-regexp):
* url-imap.el (url-imap-default-port):
* url-methods.el (url-scheme-get-property): Fix typos in docstrings.
* url-auth.el (url-basic-auth-storage, url-digest-auth):
Fix typos in docstrings.
(url-digest-auth-storage, url-register-auth-scheme): Reflow docstrings.
* url-cache.el (url-cache-prepare): Doc fix.
(url-cache-create-filename-human-readable, url-cache-extract):
Fix typos in docstrings.
* url-dav.el (url-intersection, url-dav-iso8601-regexp)
(url-dav-delete-something): Fix typos in docstrings.
(url-dav-http-success-p, url-dav-file-name-all-completions)
(url-dav-directory-files, url-dav-file-name-completion): Doc fixes.
* url-http.el (url-http-idle-sentinel): Doc fix.
* url-irc.el (url-irc-default-port): Fix typo in docstring.
(url-irc-function): Doc fix.
* url-util.el (url-get-url-filename-chars, url-unhex-string):
Fix typos in docstrings.
(url-file-extension): Doc fix.
* url-vars.el (url-current-object, url-current-mime-headers)
(url-privacy-level, url-mail-command, url-mime-language-string):
Fix typos in docstrings.
(url-honor-refresh-requests): Reflow docstring.
(url-using-proxy): Doc fix.
2008-07-02 11:14:38 +00:00
|
|
|
"Setup the URL package.
|
2004-04-04 01:21:46 +00:00
|
|
|
This is to avoid conflict with user settings if URL is dumped with
|
|
|
|
Emacs."
|
|
|
|
(unless url-setup-done
|
|
|
|
|
|
|
|
(mailcap-parse-mailcaps)
|
|
|
|
(mailcap-parse-mimetypes)
|
2005-08-06 15:55:38 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Register all the authentication schemes we can handle
|
|
|
|
(url-register-auth-scheme "basic" nil 4)
|
|
|
|
(url-register-auth-scheme "digest" nil 7)
|
|
|
|
|
|
|
|
(setq url-cookie-file
|
|
|
|
(or url-cookie-file
|
|
|
|
(expand-file-name "cookies" url-configuration-directory)))
|
2005-08-06 15:55:38 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq url-history-file
|
|
|
|
(or url-history-file
|
|
|
|
(expand-file-name "history" url-configuration-directory)))
|
2005-08-06 15:55:38 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Parse the global history file if it exists, so that it can be used
|
|
|
|
;; for URL completion, etc.
|
|
|
|
(url-history-parse-history)
|
|
|
|
(url-history-setup-save-timer)
|
|
|
|
|
|
|
|
;; Ditto for cookies
|
|
|
|
(url-cookie-setup-save-timer)
|
|
|
|
(url-cookie-parse-file url-cookie-file)
|
|
|
|
|
|
|
|
;; Read in proxy gateways
|
|
|
|
(let ((noproxy (and (not (assoc "no_proxy" url-proxy-services))
|
|
|
|
(or (getenv "NO_PROXY")
|
|
|
|
(getenv "no_PROXY")
|
|
|
|
(getenv "no_proxy")))))
|
|
|
|
(if noproxy
|
|
|
|
(setq url-proxy-services
|
|
|
|
(cons (cons "no_proxy"
|
|
|
|
(concat "\\("
|
|
|
|
(mapconcat
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
((= x ?,) "\\|")
|
|
|
|
((= x ? ) "")
|
|
|
|
((= x ?.) (regexp-quote "."))
|
|
|
|
((= x ?*) ".*")
|
|
|
|
((= x ??) ".")
|
|
|
|
(t (char-to-string x))))
|
|
|
|
noproxy "") "\\)"))
|
|
|
|
url-proxy-services))))
|
|
|
|
|
|
|
|
(url-setup-privacy-info)
|
|
|
|
(run-hooks 'url-load-hook)
|
|
|
|
(setq url-setup-done t)))
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Retrieval functions
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2006-02-20 21:54:23 +00:00
|
|
|
|
|
|
|
(defvar url-redirect-buffer nil
|
|
|
|
"New buffer into which the retrieval will take place.
|
|
|
|
Sometimes while retrieving a URL, the URL library needs to use another buffer
|
|
|
|
than the one returned initially by `url-retrieve'. In this case, it sets this
|
|
|
|
variable in the original buffer as a forwarding pointer.")
|
|
|
|
|
2012-02-06 21:06:15 +00:00
|
|
|
(defvar url-retrieve-number-of-calls 0)
|
|
|
|
(autoload 'url-cache-prune-cache "url-cache")
|
2017-09-13 18:10:51 +00:00
|
|
|
(defvar url-asynchronous t
|
|
|
|
"Bind to nil before calling `url-retrieve' to signal :nowait connections.")
|
2012-02-06 21:06:15 +00:00
|
|
|
|
2006-01-02 05:24:31 +00:00
|
|
|
;;;###autoload
|
2012-02-08 00:04:42 +00:00
|
|
|
(defun url-retrieve (url callback &optional cbargs silent inhibit-cookies)
|
2004-04-04 01:21:46 +00:00
|
|
|
"Retrieve URL asynchronously and call CALLBACK with CBARGS when finished.
|
2012-05-09 08:33:48 +00:00
|
|
|
URL is either a string or a parsed URL. If it is a string
|
|
|
|
containing characters that are not valid in a URI, those
|
|
|
|
characters are percent-encoded; see `url-encode-url'.
|
2005-07-15 05:11:28 +00:00
|
|
|
|
|
|
|
CALLBACK is called when the object has been completely retrieved, with
|
2004-04-04 01:21:46 +00:00
|
|
|
the current buffer containing the object, and any MIME headers associated
|
2006-10-27 14:46:59 +00:00
|
|
|
with it. It is called as (apply CALLBACK STATUS CBARGS).
|
2012-10-13 09:37:25 +00:00
|
|
|
STATUS is a plist representing what happened during the request,
|
|
|
|
with most recent events first, or an empty list if no events have
|
|
|
|
occurred. Each pair is one of:
|
2006-10-27 14:44:25 +00:00
|
|
|
|
2019-05-15 07:45:08 +00:00
|
|
|
\(:redirect REDIRECTED-TO) - the request was redirected to this URL.
|
|
|
|
|
|
|
|
\(:error (error type . DATA)) - an error occurred. TYPE is a
|
|
|
|
symbol that says something about where the error occurred, and
|
|
|
|
DATA is a list (possibly nil) that describes the error further.
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
Return the buffer URL will load into, or nil if the process has
|
2006-10-27 14:44:25 +00:00
|
|
|
already completed (i.e. URL was a mailto URL or similar; in this case
|
|
|
|
the callback is not called).
|
|
|
|
|
|
|
|
The variables `url-request-data', `url-request-method' and
|
|
|
|
`url-request-extra-headers' can be dynamically bound around the
|
|
|
|
request; dynamic binding of other variables doesn't necessarily
|
2010-10-02 02:04:20 +00:00
|
|
|
take effect.
|
|
|
|
|
2012-02-08 00:04:42 +00:00
|
|
|
If SILENT, then don't message progress reports and the like.
|
|
|
|
If INHIBIT-COOKIES, cookies will neither be stored nor sent to
|
2012-04-10 11:22:08 +00:00
|
|
|
the server.
|
|
|
|
If URL is a multibyte string, it will be encoded as utf-8 and
|
|
|
|
URL-encoded before it's used."
|
2021-01-26 23:17:00 +00:00
|
|
|
;; XXX: There is code in Emacs that does dynamic binding
|
|
|
|
;; of the following variables around url-retrieve:
|
2022-07-07 11:25:23 +00:00
|
|
|
;; url-standalone-mode, url-gateway-unplugged,
|
2021-01-26 23:17:00 +00:00
|
|
|
;; url-confirmation-func, url-cookie-multiple-line,
|
|
|
|
;; url-cookie-{{,secure-}storage,confirmation}
|
|
|
|
;; url-standalone-mode and url-gateway-unplugged should work as
|
|
|
|
;; usual. url-confirmation-func is only used in nnwarchive.el and
|
|
|
|
;; webmail.el; the latter should be updated. Is
|
|
|
|
;; url-cookie-multiple-line needed anymore? The other url-cookie-*
|
|
|
|
;; are (for now) only used in synchronous retrievals.
|
2012-02-08 00:04:42 +00:00
|
|
|
(url-retrieve-internal url callback (cons nil cbargs) silent
|
|
|
|
inhibit-cookies))
|
2006-10-27 14:44:25 +00:00
|
|
|
|
2012-02-08 00:04:42 +00:00
|
|
|
(defun url-retrieve-internal (url callback cbargs &optional silent
|
|
|
|
inhibit-cookies)
|
2006-10-27 14:44:25 +00:00
|
|
|
"Internal function; external interface is `url-retrieve'.
|
2014-09-19 01:55:43 +00:00
|
|
|
The callback function will receive an updated value of CBARGS as
|
|
|
|
arguments; its first element should be a plist specifying what has
|
2012-10-13 09:37:25 +00:00
|
|
|
happened so far during the request, as described in the docstring
|
|
|
|
of `url-retrieve' (if in doubt, specify nil).
|
2010-10-02 02:04:20 +00:00
|
|
|
|
2012-02-08 00:04:42 +00:00
|
|
|
If SILENT, don't message progress reports and the like.
|
|
|
|
If INHIBIT-COOKIES, cookies will neither be stored nor sent to
|
2012-04-10 11:22:08 +00:00
|
|
|
the server.
|
|
|
|
If URL is a multibyte string, it will be encoded as utf-8 and
|
|
|
|
URL-encoded before it's used."
|
2004-04-04 01:21:46 +00:00
|
|
|
(url-do-setup)
|
|
|
|
(url-gc-dead-buffers)
|
2012-06-21 09:21:28 +00:00
|
|
|
(when (stringp url)
|
|
|
|
(set-text-properties 0 (length url) nil url)
|
|
|
|
(setq url (url-encode-url url)))
|
2017-03-21 19:48:52 +00:00
|
|
|
(if (not (url-p url))
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq url (url-generic-parse-url url)))
|
|
|
|
(if (not (functionp callback))
|
|
|
|
(error "Must provide a callback function to url-retrieve"))
|
|
|
|
(unless (url-type url)
|
|
|
|
(error "Bad url: %s" (url-recreate-url url)))
|
2010-10-02 02:04:20 +00:00
|
|
|
(setf (url-silent url) silent)
|
2017-09-13 18:10:51 +00:00
|
|
|
(setf (url-asynchronous url) url-asynchronous)
|
2012-02-08 00:04:42 +00:00
|
|
|
(setf (url-use-cookies url) (not inhibit-cookies))
|
2012-02-06 21:06:15 +00:00
|
|
|
;; Once in a while, remove old entries from the URL cache.
|
|
|
|
(when (zerop (% url-retrieve-number-of-calls 1000))
|
2012-02-20 08:22:41 +00:00
|
|
|
(condition-case error
|
|
|
|
(url-cache-prune-cache)
|
|
|
|
(file-error
|
|
|
|
(message "Error when expiring the cache: %s" error))))
|
2012-02-06 21:06:15 +00:00
|
|
|
(setq url-retrieve-number-of-calls (1+ url-retrieve-number-of-calls))
|
2004-04-04 01:21:46 +00:00
|
|
|
(let ((loader (url-scheme-get-property (url-type url) 'loader))
|
|
|
|
(url-using-proxy (if (url-host url)
|
|
|
|
(url-find-proxy-for-url url (url-host url))))
|
|
|
|
(buffer nil)
|
|
|
|
(asynch (url-scheme-get-property (url-type url) 'asynchronous-p)))
|
2021-07-19 15:42:18 +00:00
|
|
|
(when url-using-proxy
|
|
|
|
(setf asynch t
|
|
|
|
loader #'url-proxy
|
|
|
|
(url-asynchronous url) t))
|
2004-04-04 01:21:46 +00:00
|
|
|
(if asynch
|
2010-10-02 02:04:20 +00:00
|
|
|
(let ((url-current-object url))
|
|
|
|
(setq buffer (funcall loader url callback cbargs)))
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq buffer (funcall loader url))
|
|
|
|
(if buffer
|
2004-04-12 20:50:16 +00:00
|
|
|
(with-current-buffer buffer
|
2004-04-04 01:21:46 +00:00
|
|
|
(apply callback cbargs))))
|
2005-12-01 19:14:15 +00:00
|
|
|
(if url-history-track
|
|
|
|
(url-history-update-url url (current-time)))
|
2004-04-04 01:21:46 +00:00
|
|
|
buffer))
|
|
|
|
|
2006-01-02 05:24:31 +00:00
|
|
|
;;;###autoload
|
2016-04-25 22:47:51 +00:00
|
|
|
(defun url-retrieve-synchronously (url &optional silent inhibit-cookies timeout)
|
2004-04-04 01:21:46 +00:00
|
|
|
"Retrieve URL synchronously.
|
|
|
|
Return the buffer containing the data, or nil if there are no data
|
|
|
|
associated with it (the case for dired, info, or mailto URLs that need
|
2016-04-25 22:47:51 +00:00
|
|
|
no further processing). URL is either a string or a parsed URL.
|
|
|
|
|
|
|
|
If SILENT is non-nil, don't do any messaging while retrieving.
|
|
|
|
If INHIBIT-COOKIES is non-nil, refuse to store cookies. If
|
|
|
|
TIMEOUT is passed, it should be a number that says (in seconds)
|
|
|
|
how long to wait for a response before giving up."
|
2004-04-04 01:21:46 +00:00
|
|
|
(url-do-setup)
|
2021-08-06 11:24:53 +00:00
|
|
|
(let* (url-asynchronous
|
|
|
|
data-buffer
|
|
|
|
(callback (lambda (&rest _args)
|
|
|
|
(setq data-buffer (current-buffer))
|
|
|
|
(url-debug 'retrieval
|
|
|
|
"Synchronous fetching done (%S)"
|
|
|
|
data-buffer)))
|
|
|
|
(start-time (current-time))
|
|
|
|
(proc-buffer (url-retrieve url callback nil silent
|
|
|
|
inhibit-cookies)))
|
|
|
|
(if (not proc-buffer)
|
|
|
|
(url-debug 'retrieval "Synchronous fetching unnecessary %s" url)
|
|
|
|
(unwind-protect
|
|
|
|
(catch 'done
|
|
|
|
(while (not data-buffer)
|
|
|
|
(when (and timeout (time-less-p timeout
|
|
|
|
(time-since start-time)))
|
|
|
|
(url-debug 'retrieval "Timed out %s (after %ss)" url
|
|
|
|
(float-time (time-since start-time)))
|
|
|
|
(throw 'done 'timeout))
|
|
|
|
(url-debug 'retrieval
|
|
|
|
"Spinning in url-retrieve-synchronously: nil (%S)"
|
|
|
|
proc-buffer)
|
|
|
|
(when-let ((redirect-buffer
|
|
|
|
(buffer-local-value 'url-redirect-buffer
|
|
|
|
proc-buffer)))
|
|
|
|
(unless (eq redirect-buffer proc-buffer)
|
|
|
|
(url-debug
|
|
|
|
'retrieval "Redirect in url-retrieve-synchronously: %S -> %S"
|
|
|
|
proc-buffer redirect-buffer)
|
|
|
|
(let (kill-buffer-query-functions)
|
|
|
|
(kill-buffer proc-buffer))
|
|
|
|
;; Accommodate hack in commit 55d1d8b.
|
|
|
|
(setq proc-buffer redirect-buffer)))
|
|
|
|
(when-let ((proc (get-buffer-process proc-buffer)))
|
|
|
|
(when (memq (process-status proc)
|
|
|
|
'(closed exit signal failed))
|
|
|
|
;; Process sentinel vagaries occasionally cause
|
|
|
|
;; url-retrieve to fail calling callback.
|
|
|
|
(unless data-buffer
|
|
|
|
(url-debug 'retrieval "Dead process %s" url)
|
|
|
|
(throw 'done 'exception))))
|
|
|
|
;; Querying over consumer internet in the US takes 100
|
|
|
|
;; ms, so split the difference.
|
|
|
|
(accept-process-output nil 0.05)))
|
2022-10-01 12:50:22 +00:00
|
|
|
;; Kill the process buffer on redirects.
|
|
|
|
(when (and data-buffer
|
|
|
|
(not (eq data-buffer proc-buffer)))
|
2021-08-06 11:24:53 +00:00
|
|
|
(let (kill-buffer-query-functions)
|
|
|
|
(kill-buffer proc-buffer)))))
|
|
|
|
data-buffer))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2013-05-23 04:58:09 +00:00
|
|
|
;; url-mm-callback called from url-mm, which requires mm-decode.
|
|
|
|
(declare-function mm-dissect-buffer "mm-decode"
|
|
|
|
(&optional no-strict-mime loose-mime from))
|
2013-05-23 07:42:16 +00:00
|
|
|
(declare-function mm-display-part "mm-decode"
|
|
|
|
(handle &optional no-default force))
|
2013-05-23 04:58:09 +00:00
|
|
|
|
2022-10-26 13:35:59 +00:00
|
|
|
(defun url-mm-callback (&rest _ignored)
|
2004-04-04 01:21:46 +00:00
|
|
|
(let ((handle (mm-dissect-buffer t)))
|
2005-06-10 21:14:34 +00:00
|
|
|
(url-mark-buffer-as-dead (current-buffer))
|
|
|
|
(with-current-buffer
|
|
|
|
(generate-new-buffer (url-recreate-url url-current-object))
|
2004-04-04 01:21:46 +00:00
|
|
|
(if (eq (mm-display-part handle) 'external)
|
|
|
|
(progn
|
|
|
|
(set-process-sentinel
|
|
|
|
;; Fixme: this shouldn't have to know the form of the
|
|
|
|
;; undisplayer produced by `mm-display-part'.
|
|
|
|
(get-buffer-process (cdr (mm-handle-undisplayer handle)))
|
|
|
|
`(lambda (proc event)
|
|
|
|
(mm-destroy-parts (quote ,handle))))
|
|
|
|
(message "Viewing externally")
|
|
|
|
(kill-buffer (current-buffer)))
|
|
|
|
(display-buffer (current-buffer))
|
2005-08-06 15:55:38 +00:00
|
|
|
(add-hook 'kill-buffer-hook
|
2004-11-20 03:57:59 +00:00
|
|
|
`(lambda () (mm-destroy-parts ',handle))
|
|
|
|
nil
|
|
|
|
t)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-mm-url (url)
|
|
|
|
"Retrieve URL and pass to the appropriate viewing application."
|
2005-10-16 14:12:35 +00:00
|
|
|
;; These requires could advantageously be moved to url-mm-callback or
|
|
|
|
;; turned into autoloads, but I suspect that it would introduce some bugs
|
|
|
|
;; because loading those files from a process sentinel or filter may
|
2011-11-15 07:55:13 +00:00
|
|
|
;; result in some undesirable corner cases.
|
2004-04-04 01:21:46 +00:00
|
|
|
(require 'mm-decode)
|
|
|
|
(require 'mm-view)
|
|
|
|
(url-retrieve url 'url-mm-callback nil))
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Miscellaneous
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(defvar url-dead-buffer-list nil)
|
|
|
|
|
|
|
|
(defun url-mark-buffer-as-dead (buff)
|
|
|
|
(push buff url-dead-buffer-list))
|
|
|
|
|
|
|
|
(defun url-gc-dead-buffers ()
|
|
|
|
(let ((buff))
|
|
|
|
(while (setq buff (pop url-dead-buffer-list))
|
|
|
|
(if (buffer-live-p buff)
|
|
|
|
(kill-buffer buff)))))
|
|
|
|
|
2020-11-19 16:41:18 +00:00
|
|
|
(define-obsolete-function-alias 'url-warn #'display-warning "28.1")
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(provide 'url)
|
|
|
|
|
|
|
|
;;; url.el ends here
|