Function: browse-url
browse-url is an autoloaded, interactive and byte-compiled function
defined in browse-url.el.gz.
Signature
(browse-url URL &rest ARGS)
Documentation
Open URL using a configurable method.
This will typically (by default) open URL with an external web browser, but a wide variety of different methods can be used, depending on the URL type.
The variables browse-url-browser-function,
browse-url-handlers, and browse-url-default-handlers
determine which browser function to use.
Interactively, this command prompts for a URL, defaulting to the URL at or before point.
The additional ARGS are passed to the browser function. See the
doc strings of the actual functions, starting with
browse-url-browser-function, for information about the
significance of ARGS (most of the functions ignore it).
If ARGS are omitted, the default is to pass
browse-url-new-window-flag as ARGS. Interactively, pass the
prefix arg as ARGS; if browse-url-new-window-flag is non-nil,
invert the prefix arg instead.
Probably introduced at or before Emacs version 19.31.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/net/browse-url.el.gz
;;;###autoload
(defun browse-url (url &rest args)
"Open URL using a configurable method.
This will typically (by default) open URL with an external web
browser, but a wide variety of different methods can be used,
depending on the URL type.
The variables `browse-url-browser-function',
`browse-url-handlers', and `browse-url-default-handlers'
determine which browser function to use.
Interactively, this command prompts for a URL, defaulting to the
URL at or before point.
The additional ARGS are passed to the browser function. See the
doc strings of the actual functions, starting with
`browse-url-browser-function', for information about the
significance of ARGS (most of the functions ignore it).
If ARGS are omitted, the default is to pass
`browse-url-new-window-flag' as ARGS. Interactively, pass the
prefix arg as ARGS; if `browse-url-new-window-flag' is non-nil,
invert the prefix arg instead."
(interactive (browse-url-interactive-arg "URL: "))
(unless (called-interactively-p 'interactive)
(setq args (or args (list browse-url-new-window-flag))))
(when browse-url-transform-alist
(dolist (trans browse-url-transform-alist)
(when (string-match (car trans) url)
(setq url (replace-match (cdr trans) nil t url)))))
(when (and url-handler-mode
(not (file-name-absolute-p url))
(not (string-match "\\`[a-z]+:" url)))
(setq url (expand-file-name url)))
(let ((process-environment (copy-sequence process-environment))
(function (or (browse-url-select-handler url)
browse-url-browser-function))
;; Ensure that `default-directory' exists and is readable (bug#6077).
(default-directory (or (unhandled-file-name-directory default-directory)
(expand-file-name "~/"))))
;; When connected to various displays, be careful to use the display of
;; the currently selected frame, rather than the original start display,
;; which may not even exist any more.
(let ((dpy (frame-parameter nil 'display))
classname)
(if (stringp dpy)
(cond
((featurep 'pgtk)
(setq classname (pgtk-backend-display-class))
(if (equal classname "GdkWaylandDisplay")
(progn
;; The `display' frame parameter is probably wrong.
;; See bug#53969 for some context.
;; (setenv "WAYLAND_DISPLAY" dpy)
)
(setenv "DISPLAY" dpy)))
((featurep 'android)
;; Avoid modifying the DISPLAY environment variable here,
;; which interferes with any X server the user may have
;; expressly set.
nil)
(t
(setenv "DISPLAY" dpy)))))
(if (functionp function)
(apply function url args)
(error "No suitable browser for URL %s" url))))