X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/0f74f7850de124626d556442d22d143d85457816..e1ffa412b4ebd244c834854098031756743236e0:/lisp/net/browse-url.el diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index e18b42a275..19e513a335 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -1,6 +1,6 @@ ;;; 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 ;; Maintainer: FSF @@ -36,6 +36,7 @@ ;; 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 @@ -47,6 +48,7 @@ ;; 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) @@ -98,7 +100,7 @@ ;; ; 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. @@ -120,8 +122,7 @@ ;; 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.) @@ -136,7 +137,7 @@ ;; 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 @@ -188,7 +189,7 @@ ;; ;; (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. @@ -203,8 +204,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variables -(eval-when-compile (require 'cl)) - (defgroup browse-url nil "Use a web browser to look at a URL." :prefix "browse-url-" @@ -230,6 +229,7 @@ regexp should probably be \".\" to specify a default browser." :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) @@ -294,7 +294,7 @@ Defaults to the value of `browse-url-netscape-arguments' at the time :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) @@ -336,6 +336,22 @@ Defaults to the value of `browse-url-firefox-arguments' at the time :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 @@ -370,7 +386,7 @@ Defaults to the value of `browse-url-epiphany-arguments' at the time :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 '() @@ -448,7 +464,7 @@ commands reverses the effect of this variable. Requires Netscape version ;; 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:///")) @@ -623,7 +639,7 @@ CHARS is a regexp-like character alternative (e.g., \"[)$]\")." (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))) @@ -636,7 +652,7 @@ regarding its parameter treatment." ;; 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 @@ -705,12 +721,6 @@ interactively. Turn the filename into a URL with function (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)))) @@ -732,7 +742,7 @@ narrowed." (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 @@ -913,6 +923,7 @@ used instead of `browse-url-new-window-flag'." ((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) @@ -924,12 +935,15 @@ used instead of `browse-url-new-window-flag'." 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. @@ -946,12 +960,18 @@ used instead of `browse-url-new-window-flag'." (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)) @@ -1103,26 +1123,32 @@ URL in a new window." (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." @@ -1134,6 +1160,22 @@ URL in a new window." 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. @@ -1576,22 +1618,21 @@ from `browse-url-elinks-wrapper'." (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)