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-displayThe X display for running the browser, if not same as Emacs’s.
browse-url-browser-functionFunction to display the current buffer in a WWW browser.
browse-url-button-mapThe keymap used for ‘browse-url’ buttons.
browse-url-button-regexpRegular expression that matches URLs.
browse-url-chrome-argumentsA list of strings to pass to Google Chrome as arguments.
browse-url-chrome-programThe name by which to invoke the Chrome browser.
browse-url-chromium-argumentsA list of strings to pass to Chromium as arguments.
browse-url-chromium-programThe name by which to invoke Chromium.
browse-url-conkeror-argumentsA list of strings to pass to Conkeror as arguments.
browse-url-conkeror-new-window-is-bufferWhether to open up new windows in a buffer or a new window.
browse-url-conkeror-programThe name by which to invoke Conkeror.
browse-url-default-handlersLike ‘browse-url-handlers’ but populated by Emacs and packages.
browse-url-elinks-wrapperWrapper command prepended to the Elinks command-line.
browse-url-epiphany-argumentsA list of strings to pass to GNOME Web (Epiphany) as arguments.
browse-url-epiphany-new-window-is-tabWhether to open up new windows in a tab or a new window.
browse-url-epiphany-programThe name by which to invoke GNOME Web (Epiphany).
browse-url-epiphany-startup-argumentsA list of strings to pass to GNOME Web (Epiphany) when it starts up.
browse-url-filename-alistAn alist of (REGEXP . STRING) pairs used by ‘browse-url-of-file’.
browse-url-firefox-argumentsA list of strings to pass to Firefox (or variant) as arguments.
browse-url-firefox-new-window-is-tabWhether to open up new windows in a tab or a new window.
browse-url-firefox-programThe name by which to invoke Firefox or a variant of it.
browse-url-firefox-startup-argumentsA list of strings to pass to Firefox (or variant) when it starts up.
browse-url-galeon-argumentsA list of strings to pass to Galeon as arguments.
browse-url-galeon-new-window-is-tabWhether to open up new windows in a tab or a new window.
browse-url-galeon-programThe name by which to invoke Galeon.
browse-url-galeon-startup-argumentsA list of strings to pass to Galeon when it starts up.
browse-url-generic-argsA list of strings defining options for ‘browse-url-generic-program’.
browse-url-generic-programThe name of the browser program used by ‘browse-url-generic’.
browse-url-gnome-moz-argumentsA list of strings passed to the GNOME mozilla viewer as arguments.
browse-url-gnudoit-argsA list of strings defining options for ‘browse-url-gnudoit-program’.
browse-url-gnudoit-programThe name of the ‘gnudoit’ program used by ‘browse-url-w3-gnudoit’.
browse-url-handlersAn alist with elements of the form (REGEXP-OR-PREDICATE . HANDLER).
browse-url-kde-argsA list of strings defining options for ‘browse-url-kde-program’.
browse-url-kde-programThe name by which to invoke the KDE web browser.
browse-url-mailto-functionFunction to display mailto: links.
browse-url-man-functionFunction to display man: links.
browse-url-mozilla-argumentsA list of strings to pass to Mozilla as arguments.
browse-url-mozilla-new-window-is-tabWhether to open up new windows in a tab or a new window.
browse-url-mozilla-programThe name by which to invoke Mozilla.
browse-url-mozilla-startup-argumentsA list of strings to pass to Mozilla when it starts up.
browse-url-netscape-argumentsA list of strings to pass to Netscape as arguments.
browse-url-netscape-new-window-is-tabWhether to open up new windows in a tab or a new window.
browse-url-netscape-programThe name by which to invoke Netscape.
browse-url-netscape-startup-argumentsA list of strings to pass to Netscape when it starts up.
browse-url-netscape-versionThe version of Netscape you are using.
browse-url-new-window-flagNon-nil means always open a new browser window with appropriate browsers.
browse-url-of-file-hookHook run after ‘browse-url-of-file’ has asked a browser to load a file.
browse-url-save-fileIf non-nil, save the buffer before displaying its file.
browse-url-secondary-browser-functionFunction used to launch an alternative browser.
browse-url-temp-dirThe name of a directory for browse-url’s temporary files.
browse-url-text-browserThe name of the text browser to invoke.
browse-url-text-emacs-argsA list of strings defining options for a text browser in an Emacs buffer.
browse-url-text-input-attemptsHow many times to try to move down from a series of text browser input fields.
browse-url-text-input-delaySeconds to wait for a text browser between moves down from an input field.
browse-url-text-input-fieldAction on selecting an existing text browser buffer at an input field.
browse-url-xterm-argsA list of strings defining options for ‘browse-url-xterm-program’.
browse-url-xterm-programThe name of the terminal emulator used by ‘browse-url-text-xterm’.

Defined functions (61)

browse-url(URL &rest ARGS)
browse-url--browser(URL &rest ARGS)
browse-url--browser-kind(FUNCTION URL)
browse-url--browser-kind-browser(URL)
browse-url--browser-kind-mailto(URL)
browse-url--browser-kind-man(URL)
browse-url--mailto(URL &rest ARGS)
browse-url--man(URL &rest ARGS)
browse-url--non-html-file-url-p(URL)
browse-url-add-buttons()
browse-url-at-mouse(EVENT)
browse-url-at-point(&optional ARG)
browse-url-button-copy()
browse-url-button-open(&optional EXTERNAL MOUSE-EVENT)
browse-url-button-open-url(URL)
browse-url-can-use-xdg-open()
browse-url-chrome(URL &optional NEW-WINDOW)
browse-url-chromium(URL &optional NEW-WINDOW)
browse-url-conkeror(URL &optional NEW-WINDOW)
browse-url-default-browser(URL &rest ARGS)
browse-url-default-macosx-browser(URL &optional NEW-WINDOW)
browse-url-default-windows-browser(URL &optional NEW-WINDOW)
browse-url-delete-temp-file(&optional TEMP-FILE-NAME)
browse-url-elinks(URL &optional NEW-WINDOW)
browse-url-elinks-new-window(URL)
browse-url-elinks-sentinel(PROCESS URL)
browse-url-emacs(URL &optional SAME-WINDOW)
browse-url-emacs-display()
browse-url-encode-url(URL)
browse-url-epiphany(URL &optional NEW-WINDOW)
browse-url-epiphany-sentinel(PROCESS URL)
browse-url-file-url(FILE)
browse-url-firefox(URL &optional NEW-WINDOW)
browse-url-galeon(URL &optional NEW-WINDOW)
browse-url-galeon-sentinel(PROCESS URL)
browse-url-generic(URL &optional NEW-WINDOW)
browse-url-gnome-moz(URL &optional NEW-WINDOW)
browse-url-interactive-arg(PROMPT)
browse-url-kde(URL &optional NEW-WINDOW)
browse-url-mail(URL &optional NEW-WINDOW)
browse-url-man(URL &optional NEW-WINDOW)
browse-url-maybe-new-window(ARG)
browse-url-mozilla(URL &optional NEW-WINDOW)
browse-url-mozilla-sentinel(PROCESS URL)
browse-url-netscape(URL &optional NEW-WINDOW)
browse-url-netscape-reload()
browse-url-netscape-send(COMMAND)
browse-url-netscape-sentinel(PROCESS URL)
browse-url-of-buffer(&optional BUFFER)
browse-url-of-dired-file()
browse-url-of-file(&optional FILE)
browse-url-of-region(MIN MAX)
browse-url-process-environment()
browse-url-select-handler(URL &optional KIND)
browse-url-text-emacs(URL &optional NEW-BUFFER)
browse-url-text-xterm(URL &optional NEW-WINDOW)
browse-url-url-encode-chars(TEXT CHARS)
browse-url-w3(URL &optional NEW-WINDOW)
browse-url-w3-gnudoit(URL &optional NEW-WINDOW)
browse-url-with-browser-kind(KIND URL &optional ARG)
browse-url-xdg-open(URL &optional IGNORED)

Defined faces (1)

browse-url-buttonFace for `browse-url' buttons (i.e., links).