File: browse-url.el.html
This package provides functions which read a URL (Uniform Resource Locator) from the minibuffer, defaulting to the URL around point, and ask a World-Wide Web browser to load it. It can also load the URL associated with the current buffer. Different browsers use different methods of remote control so there is one function for each supported browser. If the chosen browser is not running, it is started. Currently there is support for the following browsers, as well as some other obsolete ones:
Function Browser Earliest version
browse-url-mozilla Mozilla Don't know
browse-url-firefox Firefox Don't know (tried with 1.0.1)
browse-url-chrome Chrome 47.0.2526.111
browse-url-chromium Chromium 3.0
browse-url-epiphany GNOME Web (Epiphany) Don't know
browse-url-w3 w3 0
browse-url-text-* Any text browser 0
browse-url-generic arbitrary
browse-url-default-windows-browser MS-Windows browser
browse-url-default-macosx-browser macOS browser
browse-url-xdg-open freedesktop.org xdg-open
browse-url-kde KDE konqueror (kfm)
browse-url-elinks Elinks Don't know (tried with 0.12.GIT)
eww-browse-url Emacs Web Wowser
Browsers can cache Web pages so it may be necessary to tell them to reload the current page if it has changed (e.g., if you have edited it). There is currently no perfect automatic solution to this.
This package generalizes function html-previewer-process in Marc Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the ffap.el package. The huge hyperbole package also contains similar functions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Usage
To display the URL at or before point: M-x browse-url-at-point RET or, similarly but with the opportunity to edit the URL extracted from the buffer, use: M-x browse-url
To display a URL by shift-clicking on it, put this in your init file:
(global-set-key [S-mouse-2] 'browse-url-at-mouse)
(Note that using Shift-mouse-1 is not desirable because
that event has a standard meaning in Emacs.)
To display the current buffer in a web browser: M-x browse-url-of-buffer RET
To display the current region in a web browser: M-x browse-url-of-region RET
In Dired, to display the file named on the current line: M-x browse-url-of-dired-file RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Customization (~/.emacs)
To see what variables are available for customization, type
M-x set-variable browse-url TAB. Better, use
M-x customize-group browse-url.
Bind the browse-url commands to keys with the C-c C-z prefix
(as used by html-helper-mode):
(global-set-key "\\C-c\\C-z." 'browse-url-at-point)
(global-set-key "\\C-c\\C-zb" 'browse-url-of-buffer)
(global-set-key "\\C-c\\C-zr" 'browse-url-of-region)
(global-set-key "\\C-c\\C-zu" 'browse-url)
(global-set-key "\\C-c\\C-zv" 'browse-url-of-file)
(add-hook 'dired-mode-hook
(lambda ()
(local-set-key "\\C-c\\C-zf" 'browse-url-of-dired-file)))
Browse URLs in mail messages under RMAIL by clicking mouse-2:
(add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup
(define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse)))
Alternatively, add goto-address to rmail-show-message-hook.
Gnus provides a standard feature to activate URLs in article buffers for invocation of browse-url.
Use the Emacs w3 browser when not running under X11:
(or (eq window-system 'x)
(setq browse-url-browser-function 'browse-url-w3))
To always save modified buffers before displaying the file in a browser:
(setq browse-url-save-file t)
To invoke different browsers/tools for different URLs, customize
browse-url-handlers. In earlier versions of Emacs, the same
could be done by setting browse-url-browser-function to an alist
but this usage is deprecated now.
All browser functions provided by here have a
browse-url-browser-kind symbol property set to either internal
or external which determines if they browse the given URL inside
Emacs or spawn an external application with it. Some parts of
Emacs make use of that, e.g., when an URL is dragged into Emacs, it
is not sensible to invoke an external browser with it, so here only
internal browsers are considered. Therefore, it is advised to put
that property also on custom browser functions.
(function-put 'my-browse-url-in-emacs 'browse-url-browser-kind
'internal)
(function-put 'my-browse-url-externally 'browse-url-browser-kind
'external)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Defined variables (57)
browse-url-browser-display | The X display for running the browser, if not same as Emacs’s. |
browse-url-browser-function | Function to display the current buffer in a WWW browser. |
browse-url-button-map | The keymap used for ‘browse-url’ buttons. |
browse-url-button-regexp | Regular expression that matches URLs. |
browse-url-chrome-arguments | A list of strings to pass to Google Chrome as arguments. |
browse-url-chrome-program | The name by which to invoke the Chrome browser. |
browse-url-chromium-arguments | A list of strings to pass to Chromium as arguments. |
browse-url-chromium-program | The name by which to invoke Chromium. |
browse-url-conkeror-arguments | A list of strings to pass to Conkeror as arguments. |
browse-url-conkeror-new-window-is-buffer | Whether to open up new windows in a buffer or a new window. |
browse-url-conkeror-program | The name by which to invoke Conkeror. |
browse-url-default-handlers | Like ‘browse-url-handlers’ but populated by Emacs and packages. |
browse-url-elinks-wrapper | Wrapper command prepended to the Elinks command-line. |
browse-url-epiphany-arguments | A list of strings to pass to GNOME Web (Epiphany) as arguments. |
browse-url-epiphany-new-window-is-tab | Whether to open up new windows in a tab or a new window. |
browse-url-epiphany-program | The name by which to invoke GNOME Web (Epiphany). |
browse-url-epiphany-startup-arguments | A list of strings to pass to GNOME Web (Epiphany) when it starts up. |
browse-url-filename-alist | An alist of (REGEXP . STRING) pairs used by ‘browse-url-of-file’. |
browse-url-firefox-arguments | A list of strings to pass to Firefox (or variant) as arguments. |
browse-url-firefox-new-window-is-tab | Whether to open up new windows in a tab or a new window. |
browse-url-firefox-program | The name by which to invoke Firefox or a variant of it. |
browse-url-firefox-startup-arguments | A list of strings to pass to Firefox (or variant) when it starts up. |
browse-url-galeon-arguments | A list of strings to pass to Galeon as arguments. |
browse-url-galeon-new-window-is-tab | Whether to open up new windows in a tab or a new window. |
browse-url-galeon-program | The name by which to invoke Galeon. |
browse-url-galeon-startup-arguments | A list of strings to pass to Galeon when it starts up. |
browse-url-generic-args | A list of strings defining options for ‘browse-url-generic-program’. |
browse-url-generic-program | The name of the browser program used by ‘browse-url-generic’. |
browse-url-gnome-moz-arguments | A list of strings passed to the GNOME mozilla viewer as arguments. |
browse-url-gnudoit-args | A list of strings defining options for ‘browse-url-gnudoit-program’. |
browse-url-gnudoit-program | The name of the ‘gnudoit’ program used by ‘browse-url-w3-gnudoit’. |
browse-url-handlers | An alist with elements of the form (REGEXP-OR-PREDICATE . HANDLER). |
browse-url-kde-args | A list of strings defining options for ‘browse-url-kde-program’. |
browse-url-kde-program | The name by which to invoke the KDE web browser. |
browse-url-mailto-function | Function to display mailto: links. |
browse-url-man-function | Function to display man: links. |
browse-url-mozilla-arguments | A list of strings to pass to Mozilla as arguments. |
browse-url-mozilla-new-window-is-tab | Whether to open up new windows in a tab or a new window. |
browse-url-mozilla-program | The name by which to invoke Mozilla. |
browse-url-mozilla-startup-arguments | A list of strings to pass to Mozilla when it starts up. |
browse-url-netscape-arguments | A list of strings to pass to Netscape as arguments. |
browse-url-netscape-new-window-is-tab | Whether to open up new windows in a tab or a new window. |
browse-url-netscape-program | The name by which to invoke Netscape. |
browse-url-netscape-startup-arguments | A list of strings to pass to Netscape when it starts up. |
browse-url-netscape-version | The version of Netscape you are using. |
browse-url-new-window-flag | Non-nil means always open a new browser window with appropriate browsers. |
browse-url-of-file-hook | Hook run after ‘browse-url-of-file’ has asked a browser to load a file. |
browse-url-save-file | If non-nil, save the buffer before displaying its file. |
browse-url-secondary-browser-function | Function used to launch an alternative browser. |
browse-url-temp-dir | The name of a directory for browse-url’s temporary files. |
browse-url-text-browser | The name of the text browser to invoke. |
browse-url-text-emacs-args | A list of strings defining options for a text browser in an Emacs buffer. |
browse-url-text-input-attempts | How many times to try to move down from a series of text browser input fields. |
browse-url-text-input-delay | Seconds to wait for a text browser between moves down from an input field. |
browse-url-text-input-field | Action on selecting an existing text browser buffer at an input field. |
browse-url-xterm-args | A list of strings defining options for ‘browse-url-xterm-program’. |
browse-url-xterm-program | The name of the terminal emulator used by ‘browse-url-text-xterm’. |
Defined functions (61)
Defined faces (1)
browse-url-button | Face for `browse-url' buttons (i.e., links). |