Homepage: https://www.gnu.org/software/emacs
Author: Denis Howe
Pass a URL to a web browser
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)