;;; browse-url.el --- pass a URL to a WWW browser
-;; Copyright (C) 1995-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1995-2013 Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
;; Maintainer: FSF
;; 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-chromium Chromium 3.0
;; browse-url-galeon Galeon Don't know
;; browse-url-epiphany Epiphany Don't know
;; browse-url-netscape Netscape 1.1b1
;; browse-url-generic arbitrary
;; browse-url-default-windows-browser MS-Windows browser
;; browse-url-default-macosx-browser Mac OS X browser
+;; browse-url-xdg-open Free Desktop xdg-open on Gnome, KDE, Xfce4, LXDE
;; browse-url-gnome-moz GNOME interface to Mozilla
;; browse-url-kde KDE konqueror (kfm)
;; browse-url-elinks Elinks Don't know (tried with 0.12.GIT)
;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used
;; with this.
-;; This package generalises function html-previewer-process in Marc
+;; 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.
;; the buffer, use:
;; M-x browse-url
-;; To display a URL by shift-clicking on it, put this in your ~/.emacs
-;; file:
+;; 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.)
;; M-x browse-url-of-dired-file RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Customisation (~/.emacs)
+;; Customization (~/.emacs)
;; To see what variables are available for customization, type
;; `M-x set-variable browse-url TAB'. Better, use
;;
;; (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload)
-;; You may also want to customise browse-url-netscape-arguments, e.g.
+;; You may also want to customize browse-url-netscape-arguments, e.g.
;; (setq browse-url-netscape-arguments '("-install"))
;;
;; or similarly for the other browsers.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
-(eval-when-compile (require 'cl))
-
(defgroup browse-url nil
"Use a web browser to look at a URL."
:prefix "browse-url-"
:value browse-url-w3-gnudoit)
(function-item :tag "Mozilla" :value browse-url-mozilla)
(function-item :tag "Firefox" :value browse-url-firefox)
+ (function-item :tag "Chromium" :value browse-url-chromium)
(function-item :tag "Galeon" :value browse-url-galeon)
(function-item :tag "Epiphany" :value browse-url-epiphany)
(function-item :tag "Netscape" :value browse-url-netscape)
:group 'browse-url)
(defcustom browse-url-browser-display nil
- "The X display for running the browser, if not same as Emacs'."
+ "The X display for running the browser, if not same as Emacs's."
:type '(choice string (const :tag "Default" nil))
:group 'browse-url)
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
+(defcustom browse-url-chromium-program
+ (let ((candidates '("chromium" "chromium-browser")))
+ (while (and candidates (not (executable-find (car candidates))))
+ (setq candidates (cdr candidates)))
+ (or (car candidates) "chromium"))
+ "The name by which to invoke Chromium."
+ :type 'string
+ :version "24.1"
+ :group 'browse-url)
+
+(defcustom browse-url-chromium-arguments nil
+ "A list of strings to pass to Chromium as arguments."
+ :type '(repeat (string :tag "Argument"))
+ :version "24.1"
+ :group 'browse-url)
+
(defcustom browse-url-galeon-program "galeon"
"The name by which to invoke Galeon."
:type 'string
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
-;; GNOME means of invoking either Mozilla or Netrape.
+;; GNOME means of invoking either Mozilla or Netscape.
(defvar browse-url-gnome-moz-program "gnome-moz-remote")
(defcustom browse-url-gnome-moz-arguments '()
;; it in anonymous cases. If it's not anonymous the next regexp
;; applies.
("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/")
- ,@(if (memq system-type '(windows-nt ms-dos cygwin))
+ ,@(if (memq system-type '(windows-nt ms-dos))
'(("^\\([a-zA-Z]:\\)[\\/]" . "file:///\\1/")
("^[\\/][\\/]+" . "file://")))
("^/+" . "file:///"))
(s 0))
(while (setq s (string-match chars encoded-text s))
(setq encoded-text
- (replace-match (format "%%%x"
+ (replace-match (format "%%%X"
(string-to-char (match-string 0 encoded-text)))
t t encoded-text)
s (1+ s)))
;; FIXME: Is there an actual example of a web browser getting
;; confused? (This used to encode commas, but at least Firefox
;; handles commas correctly and doesn't accept encoded commas.)
- (browse-url-url-encode-chars url "[)$]"))
+ (browse-url-url-encode-chars url "[\")$] "))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; URL input
(defun browse-url-file-url (file)
"Return the URL corresponding to FILE.
Use variable `browse-url-filename-alist' to map filenames to URLs."
- ;; De-munge Cygwin filenames before passing them to Windows browser.
- (if (eq system-type 'cygwin)
- (let ((winfile (with-output-to-string
- (call-process "cygpath" nil standard-output
- nil "-m" file))))
- (setq file (substring winfile 0 -1))))
(let ((coding (and (default-value 'enable-multibyte-characters)
(or file-name-coding-system
default-file-name-coding-system))))
(and buffer (set-buffer buffer))
(let ((file-name
;; Ignore real name if restricted
- (and (= (- (point-max) (point-min)) (buffer-size))
+ (and (not (buffer-narrowed-p))
(or buffer-file-name
(and (boundp 'dired-directory) dired-directory)))))
(or file-name
((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz)
((executable-find browse-url-mozilla-program) 'browse-url-mozilla)
((executable-find browse-url-firefox-program) 'browse-url-firefox)
+ ((executable-find browse-url-chromium-program) 'browse-url-chromium)
((executable-find browse-url-galeon-program) 'browse-url-galeon)
((executable-find browse-url-kde-program) 'browse-url-kde)
((executable-find browse-url-netscape-program) 'browse-url-netscape)
url args))
(defun browse-url-can-use-xdg-open ()
- "Check if xdg-open can be used, i.e. we are on Gnome, KDE or xfce4."
+ "Return non-nil if the \"xdg-open\" program can be used.
+xdg-open is a desktop utility that calls your preferred web browser.
+This requires you to be running either Gnome, KDE, Xfce4 or LXDE."
(and (getenv "DISPLAY")
(executable-find "xdg-open")
;; xdg-open may call gnome-open and that does not wait for its child
;; to finish. This child may then be killed when the parent dies.
- ;; Use nohup to work around.
+ ;; Use nohup to work around. See bug#7166, bug#8917, bug#9779 and
+ ;; http://lists.gnu.org/archive/html/emacs-devel/2009-07/msg00279.html
(executable-find "nohup")
(or (getenv "GNOME_DESKTOP_SESSION_ID")
;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
(eq 0 (call-process
"/bin/sh" nil nil nil
"-c"
+ ;; FIXME use string-match rather than grep.
"xprop -root _DT_SAVE_MODE|grep xfce4"))
- (error nil)))))
+ (error nil))
+ (member (getenv "DESKTOP_SESSION") '("LXDE" "Lubuntu"))
+ (equal (getenv "XDG_CURRENT_DESKTOP") "LXDE"))))
;;;###autoload
-(defun browse-url-xdg-open (url &optional new-window)
+(defun browse-url-xdg-open (url &optional ignored)
+ "Pass the specified URL to the \"xdg-open\" command.
+xdg-open is a desktop utility that calls your preferred web browser.
+The optional argument IGNORED is not used."
(interactive (browse-url-interactive-arg "URL: "))
(call-process "xdg-open" nil 0 nil url))
(interactive (browse-url-interactive-arg "URL: "))
(setq url (browse-url-encode-url url))
(let* ((process-environment (browse-url-process-environment))
+ (use-remote
+ (not (memq system-type '(windows-nt ms-dos))))
(process
(apply 'start-process
(concat "firefox " url) nil
browse-url-firefox-program
(append
browse-url-firefox-arguments
- (if (memq system-type '(windows-nt ms-dos))
- (list url)
- (list "-remote"
- (concat "openURL("
- url
- (if (browse-url-maybe-new-window
- new-window)
- (if browse-url-firefox-new-window-is-tab
- ",new-tab"
- ",new-window"))
- ")")))))))
- (set-process-sentinel process
- `(lambda (process change)
- (browse-url-firefox-sentinel process ,url)))))
+ (if use-remote
+ (list "-remote"
+ (concat
+ "openURL("
+ url
+ (if (browse-url-maybe-new-window new-window)
+ (if browse-url-firefox-new-window-is-tab
+ ",new-tab"
+ ",new-window"))
+ ")"))
+ (list url))))))
+ ;; If we use -remote, the process exits with status code 2 if
+ ;; Firefox is not already running. The sentinel runs firefox
+ ;; directly if that happens.
+ (when use-remote
+ (set-process-sentinel process
+ `(lambda (process change)
+ (browse-url-firefox-sentinel process ,url))))))
(defun browse-url-firefox-sentinel (process url)
"Handle a change to the process communicating with Firefox."
browse-url-firefox-program
(append browse-url-firefox-startup-arguments (list url))))))
+;;;###autoload
+(defun browse-url-chromium (url &optional new-window)
+ "Ask the Chromium WWW browser to load URL.
+Default to the URL around or before point. The strings in
+variable `browse-url-chromium-arguments' are also passed to
+Chromium."
+ (interactive (browse-url-interactive-arg "URL: "))
+ (setq url (browse-url-encode-url url))
+ (let* ((process-environment (browse-url-process-environment)))
+ (apply 'start-process
+ (concat "chromium " url) nil
+ browse-url-chromium-program
+ (append
+ browse-url-chromium-arguments
+ (list url)))))
+
;;;###autoload
(defun browse-url-galeon (url &optional new-window)
"Ask the Galeon WWW browser to load URL.
(defun browse-url-elinks-sentinel (process url)
"Determines if Elinks is running or a new one has to be started."
- (let ((exit-status (process-exit-status process)))
- ;; Try to determine if an instance is running or if we have to
- ;; create a new one.
- (case exit-status
- (5
- ;; No instance, start a new one.
- (browse-url-elinks-new-window url))
- (0
- ;; Found an instance, open URL in new tab.
- (let ((process-environment (browse-url-process-environment)))
- (start-process (concat "elinks:" url) nil
- "elinks" "-remote"
- (concat "openURL(\"" url "\",new-tab)"))))
- (otherwise
- (error "Unrecognized exit-code %d of process `elinks'"
- exit-status)))))
+ ;; Try to determine if an instance is running or if we have to
+ ;; create a new one.
+ (pcase (process-exit-status process)
+ (5
+ ;; No instance, start a new one.
+ (browse-url-elinks-new-window url))
+ (0
+ ;; Found an instance, open URL in new tab.
+ (let ((process-environment (browse-url-process-environment)))
+ (start-process (concat "elinks:" url) nil
+ "elinks" "-remote"
+ (concat "openURL(\"" url "\",new-tab)"))))
+ (exit-status
+ (error "Unrecognized exit-code %d of process `elinks'"
+ exit-status))))
(provide 'browse-url)