]> code.delx.au - gnu-emacs/blobdiff - lisp/net/browse-url.el
* net/tramp.el (tramp-tramp-file-p): Check, whether NAME is unibyte.
[gnu-emacs] / lisp / net / browse-url.el
index 89948a2c81a8a2337f1b46f06833f5f3d9e7332b..19e513a335413ed3a943a04d3741f2ed5c019f84 100644 (file)
@@ -1,6 +1,6 @@
 ;;; browse-url.el --- pass a URL to a WWW browser
 
-;; Copyright (C) 1995-201 Free Software Foundation, Inc.
+;; Copyright (C) 1995-2013 Free Software Foundation, Inc.
 
 ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
 ;; Maintainer: FSF
 ;; <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-"
@@ -297,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)
 
@@ -467,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:///"))
@@ -642,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)))
@@ -655,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
@@ -724,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))))
@@ -751,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
@@ -944,7 +935,9 @@ 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, Xfce4 or LXDE."
+  "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
@@ -967,6 +960,7 @@ 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))
           (member (getenv "DESKTOP_SESSION") '("LXDE" "Lubuntu"))
@@ -974,7 +968,10 @@ used instead of `browse-url-new-window-flag'."
 
 
 ;;;###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))
 
@@ -1621,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)