File: browse-url.el.html
This package provides functions which read a URL from the minibuffer, defaulting to the URL around point, and ask a web browser to load it. It can also load the URL at point, or one associated with the current buffer. The main functions are:
browse-url Open URL
browse-url-at-point Open URL at point
browse-url-of-buffer Use web browser to display buffer
browse-url-of-file Use web browser to display file
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-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-webpositive WebPositive 1.2-alpha (Haiku R1/beta3)
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)
browse-url-default-android-browser Android 2.3.3 (should work on 2.2 too)
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.
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 (Init File)
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:
(keymap-global-set "C-c C-z ." 'browse-url-at-point)
(keymap-global-set "C-c C-z b" 'browse-url-of-buffer)
(keymap-global-set "C-c C-z r" 'browse-url-of-region)
(keymap-global-set "C-c C-z u" 'browse-url)
(keymap-global-set "C-c C-z v" 'browse-url-of-file)
(add-hook 'dired-mode-hook
(lambda ()
(keymap-local-set "C-c C-z f" '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
(keymap-set 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 Web Wowser (EWW) when not running under X11:
(or (eq window-system 'x)
(setopt browse-url-browser-function #'eww-browse-url))
To always save modified buffers before displaying the file in a browser:
(setopt 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 (52)
browse-url-android-share | If non-nil, share URLs on Android systems instead of opening them. |
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-default-scheme | URL scheme that ‘browse-url’ (and related commands) will use by default. |
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-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-irc-function | Function to open an irc:// link. |
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-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-webpositive-program | The name by which to invoke WebPositive. |
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). |