1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
* browse-url.el has been enhanced.
Patch: browse-url.diff
Added-by: Rob Browning <rlb@defaultvalue.org>
Support for mozilla has been fixed, support for galeon has been
added, and Emacs now uses free browsers by default when available,
instead of just trying netscape.
--- emacs21-21.2.orig/lisp/net/browse-url.el
+++ emacs21-21.2/lisp/net/browse-url.el
@@ -4,7 +4,7 @@
;; Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
-;; Maintainer: Dave Love <fx@gnu.org>
+;; Maintainer: FSF
;; Created: 03 Apr 1995
;; Keywords: hypertext, hypermedia, mouse
@@ -66,14 +66,6 @@
;; control but which window DO you want to control and how do you
;; discover its id?
-;; If using XMosaic before version 2.5, check the definition of
-;; browse-url-usr1-signal below.
-;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html>
-
-;; XMosaic version 2.5 introduced Common Client Interface allowing you
-;; to control mosaic through Unix sockets.
-;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/CCI/cci-spec.html>
-
;; William M. Perry's excellent "w3" WWW browser for
;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
;; has a function w3-follow-url-at-point, but that
@@ -90,10 +82,6 @@
;; Python see <url:http://www.python.org/>. Grail support in
;; browse-url.el written by Barry Warsaw <bwarsaw@python.org>.
-;; MMM is a semi-free WWW browser implemented in Objective Caml, an
-;; interesting impure functional programming language. See
-;; <URL:http://pauillac.inria.fr/%7Erouaix/mmm/>.
-
;; Lynx is now distributed by the FSF. See also
;; <URL:http://lynx.browser.org/>.
@@ -226,8 +214,10 @@
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
+ (require 'executable)
(require 'w3-auto nil t))
+
(defgroup browse-url nil
"Use a web browser to look at a URL."
:prefix "browse-url-"
@@ -238,7 +228,8 @@
(defcustom browse-url-browser-function
(if (memq system-type '(windows-nt ms-dos))
'browse-url-default-windows-browser
- 'browse-url-netscape)
+ 'browse-url-default-browser)
+
"*Function to display the current buffer in a WWW browser.
This is used by the `browse-url-at-point', `browse-url-at-mouse', and
`browse-url-of-file' commands.
@@ -252,6 +243,8 @@
(function-item :tag "Emacs W3" :value browse-url-w3)
(function-item :tag "W3 in another Emacs via `gnudoit'"
:value browse-url-w3-gnudoit)
+ (function-item :tag "Mozilla" :value browse-url-mozilla)
+ (function-item :tag "Galeon" :value browse-url-galeon)
(function-item :tag "Netscape" :value browse-url-netscape)
(function-item :tag "Mosaic" :value browse-url-mosaic)
(function-item :tag "Mosaic using CCI" :value browse-url-cci)
@@ -269,6 +262,8 @@
:value browse-url-default-windows-browser)
(function-item :tag "GNOME invoking Mozilla"
:value browse-url-gnome-moz)
+ (function-item :tag "Default browser"
+ :value browse-url-default-browser)
(function :tag "Your own function")
(alist :tag "Regexp/function association list"
:key-type regexp :value-type function))
@@ -300,6 +295,47 @@
:group 'browse-url)
;;;###autoload
+(defcustom browse-url-browser-display nil
+ "*The X display for running the browser, if not same as Emacs'."
+ :type '(choice string (const :tag "Default" nil))
+ :group 'browse-url)
+
+(defcustom browse-url-mozilla-program "mozilla"
+ "The name by which to invoke Mozilla."
+ :type 'string
+ :group 'browse-url)
+
+(defcustom browse-url-mozilla-arguments nil
+ "A list of strings to pass to Mozilla as arguments."
+ :type '(repeat (string :tag "Argument"))
+ :group 'browse-url)
+
+(defcustom browse-url-mozilla-startup-arguments browse-url-mozilla-arguments
+ "A list of strings to pass to Mozilla when it starts up.
+Defaults to the value of `browse-url-mozilla-arguments' at the time
+`browse-url' is loaded."
+ :type '(repeat (string :tag "Argument"))
+ :group 'browse-url)
+
+;;;###autoload
+(defcustom browse-url-galeon-program "galeon"
+ "The name by which to invoke Galeon."
+ :type 'string
+ :group 'browse-url)
+
+(defcustom browse-url-galeon-arguments nil
+ "A list of strings to pass to Galeon as arguments."
+ :type '(repeat (string :tag "Argument"))
+ :group 'browse-url)
+
+(defcustom browse-url-galeon-startup-arguments browse-url-galeon-arguments
+ "A list of strings to pass to Galeon when it starts up.
+Defaults to the value of `browse-url-galeon-arguments' at the time
+`browse-url' is loaded."
+ :type '(repeat (string :tag "Argument"))
+ :group 'browse-url)
+
+;;;###autoload
(defcustom browse-url-new-window-flag nil
"*If non-nil, always open a new browser window with appropriate browsers.
Passing an interactive argument to \\[browse-url], or specific browser
@@ -308,12 +344,6 @@
:type 'boolean
:group 'browse-url)
-;;;###autoload
-(defcustom browse-url-netscape-display nil
- "*The X display for running Netscape, if not same as Emacs'."
- :type '(choice string (const :tag "Default" nil))
- :group 'browse-url)
-
(defcustom browse-url-mosaic-program "xmosaic"
"The name by which to invoke Mosaic (or mMosaic)."
:type 'string
@@ -681,11 +711,11 @@
;; --- Netscape ---
(defun browse-url-process-environment ()
- "Set DISPLAY in the environment to the X display Netscape is running on.
-This is either the value of variable `browse-url-netscape-display' if
+ "Set DISPLAY in the environment to the X display the browser will use.
+This is either the value of variable `browse-url-browser-display' if
non-nil, or the same display as Emacs if different from the current
environment, otherwise just use the current environment."
- (let ((display (or browse-url-netscape-display (browse-url-emacs-display))))
+ (let ((display (or browse-url-browser-display (browse-url-emacs-display))))
(if display
(cons (concat "DISPLAY=" display) process-environment)
process-environment)))
@@ -701,6 +731,35 @@
display)))
;;;###autoload
+(defun browse-url-default-browser (url &rest args)
+ "Find a suitable browser and ask it to load URL.
+Default to the URL around or before point.
+
+When called interactively, if variable `browse-url-new-window-flag' is
+non-nil, load the document in a new window, if possible, otherwise use
+a random existing one. A non-nil interactive prefix argument reverses
+the effect of `browse-url-new-window-flag'.
+
+When called non-interactively, optional second argument NEW-WINDOW is
+used instead of `browse-url-new-window-flag'.
+
+The order attempted is gnome-moz-remote, Mozilla, Galeon, Netscape,
+Mosaic, IXI Mosaic, Lynx in an xterm, MMM, Konqueror, and then W3."
+ (apply
+ (cond
+ ((executable-find "gnome-moz-remote") 'browse-url-gnome-moz)
+ ((executable-find browse-url-mozilla-program) 'browse-url-mozilla)
+ ((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)
+ ((executable-find browse-url-mosaic-program) 'browse-url-mosaic)
+ ((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))
+ url args))
+
+;;;###autoload
(defun browse-url-netscape (url &optional new-window)
"Ask the Netscape WWW browser to load URL.
Default to the URL around or before point. The strings in variable
@@ -767,6 +826,50 @@
(append browse-url-netscape-arguments
(list "-remote" command)))))
+;;;###autoload
+(defun browse-url-mozilla (url &optional new-window)
+ "Ask the Mozilla WWW browser to load URL.
+Default to the URL around or before point. The strings in variable
+`browse-url-mozilla-arguments' are also passed to Mozilla.
+
+When called interactively, if variable `browse-url-new-window-flag' is
+non-nil, load the document in a new Mozilla window, otherwise use a
+random existing one. A non-nil interactive prefix argument reverses
+the effect of `browse-url-new-window-flag'.
+
+When called non-interactively, optional second argument NEW-WINDOW is
+used instead of `browse-url-new-window-flag'."
+ (interactive (browse-url-interactive-arg "URL: "))
+ ;; URL encode any `confusing' characters in the URL. This needs to
+ ;; include at least commas; presumably also close parens.
+ (while (string-match "[,)]" url)
+ (setq url (replace-match
+ (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+ (let* ((process-environment (browse-url-process-environment))
+ (process (apply 'start-process
+ (concat "mozilla " url) nil
+ browse-url-mozilla-program
+ (append
+ browse-url-mozilla-arguments
+ (list "-remote"
+ (concat "openurl("
+ url
+ (if new-window ",new-window" "")
+ ")"))))))
+ (set-process-sentinel process
+ `(lambda (process change)
+ (browse-url-mozilla-sentinel process ,url)))))
+
+(defun browse-url-mozilla-sentinel (process url)
+ "Handle a change to the process communicating with Mozilla."
+ (or (eq (process-exit-status process) 0)
+ (let* ((process-environment (browse-url-process-environment)))
+ ;; Mozilla is not running - start it
+ (message "Starting Mozilla...")
+ (apply 'start-process (concat "mozilla " url) nil
+ browse-url-mozilla-program
+ (append browse-url-mozilla-startup-arguments (list url))))))
+
;; GNOME means of invoking either Mozilla or Netrape.
(defcustom browse-url-gnome-moz-arguments '()
@@ -776,6 +880,48 @@
:group 'browse-url)
;;;###autoload
+(defun browse-url-galeon (url &optional new-window)
+ "Ask the Galeon WWW browser to load URL.
+Default to the URL around or before point. The strings in variable
+`browse-url-galeon-arguments' are also passed to Galeon.
+
+When called interactively, if variable `browse-url-new-window-flag' is
+non-nil, load the document in a new Galeon window, otherwise use a
+random existing one. A non-nil interactive prefix argument reverses
+the effect of `browse-url-new-window-flag'.
+
+When called non-interactively, optional second argument NEW-WINDOW is
+used instead of `browse-url-new-window-flag'."
+ (interactive (browse-url-interactive-arg "URL: "))
+ ;; URL encode any `confusing' characters in the URL. This needs to
+ ;; include at least commas; presumably also close parens.
+ (while (string-match "[,)]" url)
+ (setq url (replace-match
+ (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+ (let* ((process-environment (browse-url-process-environment))
+ (process (apply 'start-process
+ (concat "galeon " url) nil
+ browse-url-galeon-program
+ (append
+ browse-url-galeon-arguments
+ (if new-window '("-w" "--noraise")
+ '("-x"))
+ (list url)))))
+ (set-process-sentinel process
+ `(lambda (process change)
+ (browse-url-galeon-sentinel process ,url)))))
+
+(defun browse-url-galeon-sentinel (process url)
+ "Handle a change to the process communicating with Galeon."
+ (or (eq (process-exit-status process) 0)
+ (let* ((process-environment (browse-url-process-environment)))
+ ;; Galeon is not running - start it
+ (message "Starting Galeon...")
+ (apply 'start-process (concat "galeon " url) nil
+ browse-url-galeon-program
+ (append browse-url-galeon-startup-arguments (list url))))))
+
+;;;###autoload
(defun browse-url-gnome-moz (url &optional new-window)
"Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'.
Default to the URL around or before point. The strings in variable
|