]> code.delx.au - gnu-emacs/blobdiff - lisp/net/browse-url.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / net / browse-url.el
index 3b6cc279a1e5d4fb06800f1183129a047e52f85f..b3276ef9c409c257e5bfa90c925008fcab27702d 100644 (file)
@@ -1,7 +1,7 @@
 ;;; browse-url.el --- pass a URL to a WWW browser
 
-;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001, 2005
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+;;   2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
 ;; Maintainer: FSF
@@ -680,6 +680,10 @@ 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."
+  (let ((coding (and default-enable-multibyte-characters
+                    (or file-name-coding-system
+                        default-file-name-coding-system))))
+    (if coding (setq file (encode-coding-string file coding))))
   ;; URL-encode special chars, do % first
   (let ((s 0))
     (while (setq s (string-match "%" file s))
@@ -713,7 +717,8 @@ narrowed."
                (setq browse-url-temp-file-name
                      (convert-standard-filename
                       (make-temp-file
-                       (expand-file-name "burl" browse-url-temp-dir)))))
+                       (expand-file-name "burl" browse-url-temp-dir)
+                       nil ".html"))))
            (setq file-name browse-url-temp-file-name)
            (write-region (point-min) (point-max) file-name nil 'no-message)))
       (browse-url-of-file file-name))))
@@ -755,17 +760,23 @@ Prompts for a URL, defaulting to the URL at or before point.  Variable
   (interactive (browse-url-interactive-arg "URL: "))
   (unless (interactive-p)
     (setq args (or args (list browse-url-new-window-flag))))
-  (if (functionp browse-url-browser-function)
-      (apply browse-url-browser-function url args)
-    ;; The `function' can be an alist; look down it for first match
-    ;; and apply the function (which might be a lambda).
-    (catch 'done
-      (dolist (bf browse-url-browser-function)
-       (when (string-match (car bf) url)
-         (apply (cdr bf) url args)
-         (throw 'done t)))
-      (error "No browse-url-browser-function matching URL %s"
-            url))))
+  (let ((process-environment (copy-sequence process-environment)))
+    ;; When connected to various displays, be careful to use the display of
+    ;; the currently selected frame, rather than the original start display,
+    ;; which may not even exist any more.
+    (if (stringp (frame-parameter (selected-frame) 'display))
+        (setenv "DISPLAY" (frame-parameter (selected-frame) 'display)))
+    (if (functionp browse-url-browser-function)
+        (apply browse-url-browser-function url args)
+      ;; The `function' can be an alist; look down it for first match
+      ;; and apply the function (which might be a lambda).
+      (catch 'done
+        (dolist (bf browse-url-browser-function)
+          (when (string-match (car bf) url)
+            (apply (cdr bf) url args)
+            (throw 'done t)))
+        (error "No browse-url-browser-function matching URL %s"
+               url)))))
 
 ;;;###autoload
 (defun browse-url-at-point (&optional arg)
@@ -863,7 +874,9 @@ xterm, MMM, and then W3."
      ((executable-find "tellw3b") 'browse-url-iximosaic)
      ((executable-find browse-url-xterm-program) 'browse-url-lynx-xterm)
      ((executable-find "mmm") 'browse-url-mmm)
-     (t 'browse-url-w3))
+     ((locate-library "w3") 'browse-url-w3)
+     (t
+      (lambda (&ignore args) (error "No usable browser found"))))
      url args))
 
 ;;;###autoload