Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; browse-url.el --- pass a URL to a WWW browser |
8749abea | 2 | |
95df8112 | 3 | ;; Copyright (C) 1995-2011 Free Software Foundation, Inc. |
8749abea GM |
4 | |
5 | ;; Author: Denis Howe <dbh@doc.ic.ac.uk> | |
7f61a9ee | 6 | ;; Maintainer: FSF |
8749abea GM |
7 | ;; Created: 03 Apr 1995 |
8 | ;; Keywords: hypertext, hypermedia, mouse | |
9 | ||
10 | ;; This file is part of GNU Emacs. | |
11 | ||
874a927a | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
8749abea | 13 | ;; it under the terms of the GNU General Public License as published by |
874a927a GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
8749abea GM |
16 | |
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
874a927a | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8749abea GM |
24 | |
25 | ;;; Commentary: | |
26 | ||
27 | ;; This package provides functions which read a URL (Uniform Resource | |
28 | ;; Locator) from the minibuffer, defaulting to the URL around point, | |
29 | ;; and ask a World-Wide Web browser to load it. It can also load the | |
30 | ;; URL associated with the current buffer. Different browsers use | |
31 | ;; different methods of remote control so there is one function for | |
32 | ;; each supported browser. If the chosen browser is not running, it | |
3abc9fa1 DL |
33 | ;; is started. Currently there is support for the following browsers, |
34 | ;; some of them probably now obsolete: | |
35 | ||
36 | ;; Function Browser Earliest version | |
7f61a9ee | 37 | ;; browse-url-mozilla Mozilla Don't know |
49866ff8 | 38 | ;; browse-url-firefox Firefox Don't know (tried with 1.0.1) |
7f61a9ee | 39 | ;; browse-url-galeon Galeon Don't know |
654805e3 | 40 | ;; browse-url-epiphany Epiphany Don't know |
3abc9fa1 DL |
41 | ;; browse-url-netscape Netscape 1.1b1 |
42 | ;; browse-url-mosaic XMosaic/mMosaic <= 2.4 | |
43 | ;; browse-url-cci XMosaic 2.5 | |
44 | ;; browse-url-w3 w3 0 | |
45 | ;; browse-url-w3-gnudoit w3 remotely | |
d9774611 | 46 | ;; browse-url-text-* Any text browser 0 |
3abc9fa1 DL |
47 | ;; browse-url-generic arbitrary |
48 | ;; browse-url-default-windows-browser MS-Windows browser | |
662871dd | 49 | ;; browse-url-default-macosx-browser Mac OS X browser |
b12e6de3 | 50 | ;; browse-url-gnome-moz GNOME interface to Mozilla |
af06f459 | 51 | ;; browse-url-kde KDE konqueror (kfm) |
8c22c51a | 52 | ;; browse-url-elinks Elinks Don't know (tried with 0.12.GIT) |
8749abea GM |
53 | |
54 | ;; [A version of the Netscape browser is now free software | |
55 | ;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is | |
56 | ;; reasonable to have that as the default.] | |
57 | ||
58 | ;; Note that versions of Netscape before 1.1b1 did not have remote | |
59 | ;; control. <URL:http://www.netscape.com/newsref/std/x-remote.html>. | |
60 | ||
61 | ;; Browsers can cache Web pages so it may be necessary to tell them to | |
62 | ;; reload the current page if it has changed (e.g. if you have edited | |
63 | ;; it). There is currently no perfect automatic solution to this. | |
64 | ||
65 | ;; Netscape allows you to specify the id of the window you want to | |
66 | ;; control but which window DO you want to control and how do you | |
67 | ;; discover its id? | |
68 | ||
6eddc3bb | 69 | ;; William M. Perry's excellent "w3" WWW browser for |
8749abea GM |
70 | ;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/> |
71 | ;; has a function w3-follow-url-at-point, but that | |
72 | ;; doesn't let you edit the URL like browse-url. | |
73 | ;; The `gnuserv' package that can be used to control it in another | |
74 | ;; Emacs process is available from | |
75 | ;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>. | |
76 | ||
8749abea GM |
77 | ;; Lynx is now distributed by the FSF. See also |
78 | ;; <URL:http://lynx.browser.org/>. | |
79 | ||
80 | ;; Free graphical browsers that could be used by `browse-url-generic' | |
81 | ;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera> and | |
82 | ;; <URL:http://www.unlv.edu/chimera/>, Arena | |
83 | ;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena> and Amaya | |
84 | ;; <URL:ftp://ftp.w3.org/pub/amaya>. mMosaic | |
85d30d29 PJ |
85 | ;; <URL:ftp://ftp.enst.fr/pub/mbone/mMosaic/>, |
86 | ;; <URL:http://www.enst.fr/~dauphin/mMosaic/> (with development | |
8749abea GM |
87 | ;; support for Java applets and multicast) can be used like Mosaic by |
88 | ;; setting `browse-url-mosaic-program' appropriately. | |
89 | ||
90 | ;; I [Denis Howe, not Dave Love] recommend Nelson Minar | |
91 | ;; <nelson@santafe.edu>'s excellent html-helper-mode.el for editing | |
92 | ;; HTML and thank Nelson for his many useful comments on this code. | |
93 | ;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/> | |
94 | ||
95 | ;; See also hm--html-menus <URL:http://www.tnt.uni-hannover.de/%7Emuenkel/ | |
96 | ;; software/own/hm--html-menus/>. For composing correct HTML see also | |
97 | ;; PSGML the general SGML structure editor package | |
98 | ;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used | |
99 | ;; with this. | |
100 | ||
101 | ;; This package generalises function html-previewer-process in Marc | |
102 | ;; Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the | |
103 | ;; ffap.el package. The huge hyperbole package also contains similar | |
104 | ;; functions. | |
105 | ||
106 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
107 | ;; Help! | |
108 | ||
109 | ;; Can you write and test some code for the Macintrash and Windoze | |
110 | ;; Netscape remote control APIs? (See the URL above). | |
111 | ||
112 | ;; Do any other browsers have remote control? | |
113 | ||
114 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
115 | ;; Usage | |
116 | ||
117 | ;; To display the URL at or before point: | |
118 | ;; M-x browse-url-at-point RET | |
119 | ;; or, similarly but with the opportunity to edit the URL extracted from | |
120 | ;; the buffer, use: | |
121 | ;; M-x browse-url | |
122 | ||
123 | ;; To display a URL by shift-clicking on it, put this in your ~/.emacs | |
124 | ;; file: | |
125 | ;; (global-set-key [S-mouse-2] 'browse-url-at-mouse) | |
126 | ;; (Note that using Shift-mouse-1 is not desirable because | |
127 | ;; that event has a standard meaning in Emacs.) | |
128 | ||
129 | ;; To display the current buffer in a web browser: | |
130 | ;; M-x browse-url-of-buffer RET | |
131 | ||
132 | ;; To display the current region in a web browser: | |
133 | ;; M-x browse-url-of-region RET | |
134 | ||
135 | ;; In Dired, to display the file named on the current line: | |
136 | ;; M-x browse-url-of-dired-file RET | |
137 | ||
138 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
139 | ;; Customisation (~/.emacs) | |
140 | ||
141 | ;; To see what variables are available for customization, type | |
142 | ;; `M-x set-variable browse-url TAB'. Better, use | |
143 | ;; `M-x customize-group browse-url'. | |
144 | ||
145 | ;; Bind the browse-url commands to keys with the `C-c C-z' prefix | |
146 | ;; (as used by html-helper-mode): | |
147 | ;; (global-set-key "\C-c\C-z." 'browse-url-at-point) | |
148 | ;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer) | |
149 | ;; (global-set-key "\C-c\C-zr" 'browse-url-of-region) | |
150 | ;; (global-set-key "\C-c\C-zu" 'browse-url) | |
151 | ;; (global-set-key "\C-c\C-zv" 'browse-url-of-file) | |
152 | ;; (add-hook 'dired-mode-hook | |
153 | ;; (lambda () | |
154 | ;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file))) | |
155 | ||
3abc9fa1 | 156 | ;; Browse URLs in mail messages under RMAIL by clicking mouse-2: |
8749abea GM |
157 | ;; (add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup |
158 | ;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse))) | |
3abc9fa1 | 159 | ;; Alternatively, add `goto-address' to `rmail-show-message-hook'. |
8749abea | 160 | |
3abc9fa1 DL |
161 | ;; Gnus provides a standard feature to activate URLs in article |
162 | ;; buffers for invocation of browse-url. | |
8749abea GM |
163 | |
164 | ;; Use the Emacs w3 browser when not running under X11: | |
165 | ;; (or (eq window-system 'x) | |
166 | ;; (setq browse-url-browser-function 'browse-url-w3)) | |
167 | ||
168 | ;; To always save modified buffers before displaying the file in a browser: | |
169 | ;; (setq browse-url-save-file t) | |
170 | ||
171 | ;; To get round the Netscape caching problem, you could EITHER have | |
172 | ;; write-file in html-helper-mode make Netscape reload the document: | |
173 | ;; | |
174 | ;; (autoload 'browse-url-netscape-reload "browse-url" | |
175 | ;; "Ask a WWW browser to redisplay the current file." t) | |
176 | ;; (add-hook 'html-helper-mode-hook | |
177 | ;; (lambda () | |
178 | ;; (add-hook 'local-write-file-hooks | |
179 | ;; (lambda () | |
180 | ;; (let ((local-write-file-hooks)) | |
181 | ;; (save-buffer)) | |
182 | ;; (browse-url-netscape-reload) | |
183 | ;; t) ; => file written by hook | |
184 | ;; t))) ; append to l-w-f-hooks | |
185 | ;; | |
186 | ;; OR have browse-url-of-file ask Netscape to load and then reload the | |
187 | ;; file: | |
188 | ;; | |
189 | ;; (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload) | |
190 | ||
191 | ;; You may also want to customise browse-url-netscape-arguments, e.g. | |
192 | ;; (setq browse-url-netscape-arguments '("-install")) | |
193 | ;; | |
194 | ;; or similarly for the other browsers. | |
195 | ||
196 | ;; To invoke different browsers for different URLs: | |
197 | ;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail) | |
198 | ;; ("." . browse-url-netscape))) | |
199 | ||
200 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
201 | ;;; Code: | |
202 | ||
203 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
204 | ;; Variables | |
205 | ||
a1ab97d0 | 206 | (eval-when-compile (require 'cl)) |
8749abea GM |
207 | |
208 | (defgroup browse-url nil | |
209 | "Use a web browser to look at a URL." | |
210 | :prefix "browse-url-" | |
082527fe | 211 | :link '(emacs-commentary-link "browse-url") |
eba5b4dd | 212 | :group 'external |
26f4b8ab | 213 | :group 'comm) |
8749abea GM |
214 | |
215 | ;;;###autoload | |
216 | (defcustom browse-url-browser-function | |
876d1684 LMI |
217 | (cond |
218 | ((memq system-type '(windows-nt ms-dos cygwin)) | |
219 | 'browse-url-default-windows-browser) | |
220 | ((memq system-type '(darwin)) | |
221 | 'browse-url-default-macosx-browser) | |
222 | (t | |
223 | 'browse-url-default-browser)) | |
5e835c9f | 224 | "Function to display the current buffer in a WWW browser. |
8749abea GM |
225 | This is used by the `browse-url-at-point', `browse-url-at-mouse', and |
226 | `browse-url-of-file' commands. | |
227 | ||
228 | If the value is not a function it should be a list of pairs | |
082527fe | 229 | \(REGEXP . FUNCTION). In this case the function called will be the one |
8749abea GM |
230 | associated with the first REGEXP which matches the current URL. The |
231 | function is passed the URL and any other args of `browse-url'. The last | |
232 | regexp should probably be \".\" to specify a default browser." | |
233 | :type '(choice | |
082527fe DL |
234 | (function-item :tag "Emacs W3" :value browse-url-w3) |
235 | (function-item :tag "W3 in another Emacs via `gnudoit'" | |
236 | :value browse-url-w3-gnudoit) | |
7f61a9ee | 237 | (function-item :tag "Mozilla" :value browse-url-mozilla) |
49866ff8 | 238 | (function-item :tag "Firefox" :value browse-url-firefox) |
7f61a9ee | 239 | (function-item :tag "Galeon" :value browse-url-galeon) |
654805e3 | 240 | (function-item :tag "Epiphany" :value browse-url-epiphany) |
082527fe DL |
241 | (function-item :tag "Netscape" :value browse-url-netscape) |
242 | (function-item :tag "Mosaic" :value browse-url-mosaic) | |
243 | (function-item :tag "Mosaic using CCI" :value browse-url-cci) | |
d9774611 RS |
244 | (function-item :tag "Text browser in an xterm window" |
245 | :value browse-url-text-xterm) | |
246 | (function-item :tag "Text browser in an Emacs window" | |
247 | :value browse-url-text-emacs) | |
af06f459 | 248 | (function-item :tag "KDE" :value browse-url-kde) |
8c22c51a | 249 | (function-item :tag "Elinks" :value browse-url-elinks) |
082527fe DL |
250 | (function-item :tag "Specified by `Browse Url Generic Program'" |
251 | :value browse-url-generic) | |
252 | (function-item :tag "Default Windows browser" | |
b12e6de3 | 253 | :value browse-url-default-windows-browser) |
662871dd SM |
254 | (function-item :tag "Default Mac OS X browser" |
255 | :value browse-url-default-macosx-browser) | |
b12e6de3 DL |
256 | (function-item :tag "GNOME invoking Mozilla" |
257 | :value browse-url-gnome-moz) | |
7f61a9ee RS |
258 | (function-item :tag "Default browser" |
259 | :value browse-url-default-browser) | |
082527fe DL |
260 | (function :tag "Your own function") |
261 | (alist :tag "Regexp/function association list" | |
262 | :key-type regexp :value-type function)) | |
afe2870b | 263 | :version "24.1" |
8749abea GM |
264 | :group 'browse-url) |
265 | ||
876d1684 LMI |
266 | (defcustom browse-url-mailto-function 'browse-url-mail |
267 | "Function to display mailto: links. | |
268 | This variable uses the same syntax as the | |
269 | `browse-url-browser-function' variable. If the | |
270 | `browse-url-mailto-function' variable is nil, that variable will | |
271 | be used instead." | |
272 | :type '(choice | |
273 | (function-item :tag "Emacs Mail" :value browse-url-mail) | |
274 | (function-item :tag "None" nil)) | |
275 | :version "24.1" | |
276 | :group 'browse-url) | |
277 | ||
8749abea GM |
278 | (defcustom browse-url-netscape-program "netscape" |
279 | ;; Info about netscape-remote from Karl Berry. | |
5e835c9f | 280 | "The name by which to invoke Netscape. |
8749abea GM |
281 | |
282 | The free program `netscape-remote' from | |
283 | <URL:http://home.netscape.com/newsref/std/remote.c> is said to start | |
284 | up very much quicker than `netscape'. Reported to compile on a GNU | |
285 | system, given vroot.h from the same directory, with cc flags | |
286 | -DSTANDALONE -L/usr/X11R6/lib -lXmu -lX11." | |
287 | :type 'string | |
288 | :group 'browse-url) | |
289 | ||
290 | (defcustom browse-url-netscape-arguments nil | |
5e835c9f | 291 | "A list of strings to pass to Netscape as arguments." |
8749abea GM |
292 | :type '(repeat (string :tag "Argument")) |
293 | :group 'browse-url) | |
294 | ||
295 | (defcustom browse-url-netscape-startup-arguments browse-url-netscape-arguments | |
5e835c9f | 296 | "A list of strings to pass to Netscape when it starts up. |
8749abea GM |
297 | Defaults to the value of `browse-url-netscape-arguments' at the time |
298 | `browse-url' is loaded." | |
299 | :type '(repeat (string :tag "Argument")) | |
300 | :group 'browse-url) | |
301 | ||
7f61a9ee | 302 | (defcustom browse-url-browser-display nil |
5e835c9f | 303 | "The X display for running the browser, if not same as Emacs'." |
7f61a9ee RS |
304 | :type '(choice string (const :tag "Default" nil)) |
305 | :group 'browse-url) | |
306 | ||
307 | (defcustom browse-url-mozilla-program "mozilla" | |
5e835c9f | 308 | "The name by which to invoke Mozilla." |
7f61a9ee RS |
309 | :type 'string |
310 | :group 'browse-url) | |
311 | ||
312 | (defcustom browse-url-mozilla-arguments nil | |
5e835c9f | 313 | "A list of strings to pass to Mozilla as arguments." |
7f61a9ee RS |
314 | :type '(repeat (string :tag "Argument")) |
315 | :group 'browse-url) | |
316 | ||
317 | (defcustom browse-url-mozilla-startup-arguments browse-url-mozilla-arguments | |
5e835c9f | 318 | "A list of strings to pass to Mozilla when it starts up. |
7f61a9ee RS |
319 | Defaults to the value of `browse-url-mozilla-arguments' at the time |
320 | `browse-url' is loaded." | |
321 | :type '(repeat (string :tag "Argument")) | |
322 | :group 'browse-url) | |
323 | ||
7d353d11 SM |
324 | (defcustom browse-url-firefox-program |
325 | (let ((candidates '("firefox" "iceweasel"))) | |
326 | (while (and candidates (not (executable-find (car candidates)))) | |
327 | (setq candidates (cdr candidates))) | |
328 | (or (car candidates) "firefox")) | |
5e835c9f | 329 | "The name by which to invoke Firefox." |
49866ff8 EZ |
330 | :type 'string |
331 | :group 'browse-url) | |
332 | ||
333 | (defcustom browse-url-firefox-arguments nil | |
5e835c9f | 334 | "A list of strings to pass to Firefox as arguments." |
49866ff8 EZ |
335 | :type '(repeat (string :tag "Argument")) |
336 | :group 'browse-url) | |
337 | ||
338 | (defcustom browse-url-firefox-startup-arguments browse-url-firefox-arguments | |
5e835c9f | 339 | "A list of strings to pass to Firefox when it starts up. |
49866ff8 EZ |
340 | Defaults to the value of `browse-url-firefox-arguments' at the time |
341 | `browse-url' is loaded." | |
342 | :type '(repeat (string :tag "Argument")) | |
343 | :group 'browse-url) | |
344 | ||
7d353d11 | 345 | (defcustom browse-url-galeon-program "galeon" |
5e835c9f | 346 | "The name by which to invoke Galeon." |
7f61a9ee RS |
347 | :type 'string |
348 | :group 'browse-url) | |
349 | ||
350 | (defcustom browse-url-galeon-arguments nil | |
5e835c9f | 351 | "A list of strings to pass to Galeon as arguments." |
7f61a9ee RS |
352 | :type '(repeat (string :tag "Argument")) |
353 | :group 'browse-url) | |
354 | ||
355 | (defcustom browse-url-galeon-startup-arguments browse-url-galeon-arguments | |
5e835c9f | 356 | "A list of strings to pass to Galeon when it starts up. |
7f61a9ee RS |
357 | Defaults to the value of `browse-url-galeon-arguments' at the time |
358 | `browse-url' is loaded." | |
359 | :type '(repeat (string :tag "Argument")) | |
360 | :group 'browse-url) | |
361 | ||
654805e3 | 362 | (defcustom browse-url-epiphany-program "epiphany" |
5e835c9f | 363 | "The name by which to invoke Epiphany." |
654805e3 RS |
364 | :type 'string |
365 | :group 'browse-url) | |
366 | ||
367 | (defcustom browse-url-epiphany-arguments nil | |
5e835c9f | 368 | "A list of strings to pass to Epiphany as arguments." |
654805e3 RS |
369 | :type '(repeat (string :tag "Argument")) |
370 | :group 'browse-url) | |
371 | ||
372 | (defcustom browse-url-epiphany-startup-arguments browse-url-epiphany-arguments | |
5e835c9f | 373 | "A list of strings to pass to Epiphany when it starts up. |
654805e3 RS |
374 | Defaults to the value of `browse-url-epiphany-arguments' at the time |
375 | `browse-url' is loaded." | |
376 | :type '(repeat (string :tag "Argument")) | |
377 | :group 'browse-url) | |
378 | ||
db324706 RS |
379 | ;; GNOME means of invoking either Mozilla or Netrape. |
380 | (defvar browse-url-gnome-moz-program "gnome-moz-remote") | |
381 | ||
382 | (defcustom browse-url-gnome-moz-arguments '() | |
5e835c9f | 383 | "A list of strings passed to the GNOME mozilla viewer as arguments." |
db324706 RS |
384 | :version "21.1" |
385 | :type '(repeat (string :tag "Argument")) | |
386 | :group 'browse-url) | |
387 | ||
d6da15ec | 388 | (defcustom browse-url-mozilla-new-window-is-tab nil |
5e835c9f | 389 | "Whether to open up new windows in a tab or a new window. |
d6da15ec SJ |
390 | If non-nil, then open the URL in a new tab rather than a new window if |
391 | `browse-url-mozilla' is asked to open it in a new window." | |
392 | :type 'boolean | |
393 | :group 'browse-url) | |
394 | ||
49866ff8 | 395 | (defcustom browse-url-firefox-new-window-is-tab nil |
5e835c9f | 396 | "Whether to open up new windows in a tab or a new window. |
49866ff8 EZ |
397 | If non-nil, then open the URL in a new tab rather than a new window if |
398 | `browse-url-firefox' is asked to open it in a new window. | |
399 | ||
400 | This option is currently ignored on MS-Windows, since the necessary | |
401 | functionality is not available there." | |
402 | :type 'boolean | |
403 | :group 'browse-url) | |
404 | ||
1d5d4123 | 405 | (defcustom browse-url-galeon-new-window-is-tab nil |
5e835c9f | 406 | "Whether to open up new windows in a tab or a new window. |
1d5d4123 RS |
407 | If non-nil, then open the URL in a new tab rather than a new window if |
408 | `browse-url-galeon' is asked to open it in a new window." | |
409 | :type 'boolean | |
410 | :group 'browse-url) | |
411 | ||
654805e3 | 412 | (defcustom browse-url-epiphany-new-window-is-tab nil |
5e835c9f | 413 | "Whether to open up new windows in a tab or a new window. |
654805e3 RS |
414 | If non-nil, then open the URL in a new tab rather than a new window if |
415 | `browse-url-epiphany' is asked to open it in a new window." | |
416 | :type 'boolean | |
417 | :group 'browse-url) | |
418 | ||
fe77c061 | 419 | (defcustom browse-url-netscape-new-window-is-tab nil |
5e835c9f | 420 | "Whether to open up new windows in a tab or a new window. |
fe77c061 SJ |
421 | If non-nil, then open the URL in a new tab rather than a new |
422 | window if `browse-url-netscape' is asked to open it in a new | |
423 | window." | |
424 | :type 'boolean | |
425 | :group 'browse-url) | |
426 | ||
408d5219 | 427 | (defcustom browse-url-new-window-flag nil |
6eddc3bb | 428 | "Non-nil means always open a new browser window with appropriate browsers. |
8749abea GM |
429 | Passing an interactive argument to \\[browse-url], or specific browser |
430 | commands reverses the effect of this variable. Requires Netscape version | |
431 | 1.1N or later or XMosaic version 2.5 or later if using those browsers." | |
432 | :type 'boolean | |
433 | :group 'browse-url) | |
434 | ||
8749abea | 435 | (defcustom browse-url-mosaic-program "xmosaic" |
5e835c9f | 436 | "The name by which to invoke Mosaic (or mMosaic)." |
8749abea GM |
437 | :type 'string |
438 | :version "20.3" | |
439 | :group 'browse-url) | |
440 | ||
441 | (defcustom browse-url-mosaic-arguments nil | |
5e835c9f | 442 | "A list of strings to pass to Mosaic as arguments." |
8749abea GM |
443 | :type '(repeat (string :tag "Argument")) |
444 | :group 'browse-url) | |
445 | ||
1665be47 | 446 | (defcustom browse-url-mosaic-pidfile "~/.mosaicpid" |
5e835c9f | 447 | "The name of the pidfile created by Mosaic." |
1665be47 RS |
448 | :type 'string |
449 | :group 'browse-url) | |
450 | ||
8749abea | 451 | (defcustom browse-url-filename-alist |
5e835c9f | 452 | `(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/") |
8749abea GM |
453 | ;; The above loses the username to avoid the browser prompting for |
454 | ;; it in anonymous cases. If it's not anonymous the next regexp | |
455 | ;; applies. | |
456 | ("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/") | |
5e835c9f | 457 | ,@(if (memq system-type '(windows-nt ms-dos cygwin)) |
5241b291 | 458 | '(("^\\([a-zA-Z]:\\)[\\/]" . "file:///\\1/") |
5e835c9f | 459 | ("^[\\/][\\/]+" . "file://"))) |
dee8ac10 | 460 | ("^/+" . "file:///")) |
5e835c9f | 461 | "An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'. |
8749abea GM |
462 | Any substring of a filename matching one of the REGEXPs is replaced by |
463 | the corresponding STRING using `replace-match', not treating STRING | |
464 | literally. All pairs are applied in the order given. The default | |
4dd14ef0 KS |
465 | value converts ange-ftp/EFS-style file names into ftp URLs and prepends |
466 | `file:' to any file name beginning with `/'. | |
8749abea GM |
467 | |
468 | For example, adding to the default a specific translation of an ange-ftp | |
469 | address to an HTTP URL: | |
470 | ||
471 | (setq browse-url-filename-alist | |
472 | '((\"/webmaster@webserver:/home/www/html/\" . | |
473 | \"http://www.acme.co.uk/\") | |
474 | (\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\") | |
475 | (\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\") | |
5e835c9f | 476 | (\"^/+\" . \"file:/\")))" |
8749abea GM |
477 | :type '(repeat (cons :format "%v" |
478 | (regexp :tag "Regexp") | |
479 | (string :tag "Replacement"))) | |
3257a734 | 480 | :version "23.1" |
8749abea GM |
481 | :group 'browse-url) |
482 | ||
8749abea | 483 | (defcustom browse-url-save-file nil |
5e835c9f | 484 | "If non-nil, save the buffer before displaying its file. |
8749abea GM |
485 | Used by the `browse-url-of-file' command." |
486 | :type 'boolean | |
487 | :group 'browse-url) | |
488 | ||
489 | (defcustom browse-url-of-file-hook nil | |
5e835c9f | 490 | "Run after `browse-url-of-file' has asked a browser to load a file. |
8749abea GM |
491 | |
492 | Set this to `browse-url-netscape-reload' to force Netscape to load the | |
493 | file rather than displaying a cached copy." | |
494 | :type 'hook | |
495 | :options '(browse-url-netscape-reload) | |
496 | :group 'browse-url) | |
497 | ||
8749abea | 498 | (defcustom browse-url-CCI-port 3003 |
5e835c9f | 499 | "Port to access XMosaic via CCI. |
8749abea GM |
500 | This can be any number between 1024 and 65535 but must correspond to |
501 | the value set in the browser." | |
502 | :type 'integer | |
503 | :group 'browse-url) | |
504 | ||
505 | (defcustom browse-url-CCI-host "localhost" | |
5e835c9f | 506 | "Host to access XMosaic via CCI. |
8749abea GM |
507 | This should be the host name of the machine running XMosaic with CCI |
508 | enabled. The port number should be set in `browse-url-CCI-port'." | |
509 | :type 'string | |
510 | :group 'browse-url) | |
511 | ||
512 | (defvar browse-url-temp-file-name nil) | |
513 | (make-variable-buffer-local 'browse-url-temp-file-name) | |
db6003fb | 514 | |
8749abea | 515 | (defcustom browse-url-xterm-program "xterm" |
d9774611 | 516 | "The name of the terminal emulator used by `browse-url-text-xterm'. |
028f45d2 | 517 | This might, for instance, be a separate color version of xterm." |
8749abea GM |
518 | :type 'string |
519 | :group 'browse-url) | |
520 | ||
521 | (defcustom browse-url-xterm-args nil | |
5e835c9f | 522 | "A list of strings defining options for `browse-url-xterm-program'. |
8749abea GM |
523 | These might set its size, for instance." |
524 | :type '(repeat (string :tag "Argument")) | |
525 | :group 'browse-url) | |
526 | ||
8749abea | 527 | (defcustom browse-url-gnudoit-program "gnudoit" |
5e835c9f | 528 | "The name of the `gnudoit' program used by `browse-url-w3-gnudoit'." |
8749abea GM |
529 | :type 'string |
530 | :group 'browse-url) | |
531 | ||
532 | (defcustom browse-url-gnudoit-args '("-q") | |
5e835c9f | 533 | "A list of strings defining options for `browse-url-gnudoit-program'. |
8749abea GM |
534 | These might set the port, for instance." |
535 | :type '(repeat (string :tag "Argument")) | |
536 | :group 'browse-url) | |
537 | ||
8749abea | 538 | (defcustom browse-url-generic-program nil |
5e835c9f | 539 | "The name of the browser program used by `browse-url-generic'." |
8749abea GM |
540 | :type '(choice string (const :tag "None" nil)) |
541 | :group 'browse-url) | |
542 | ||
543 | (defcustom browse-url-generic-args nil | |
5e835c9f | 544 | "A list of strings defining options for `browse-url-generic-program'." |
8749abea GM |
545 | :type '(repeat (string :tag "Argument")) |
546 | :group 'browse-url) | |
547 | ||
548 | (defcustom browse-url-temp-dir temporary-file-directory | |
5e835c9f | 549 | "The name of a directory for browse-url's temporary files. |
8749abea GM |
550 | Such files are generated by functions like `browse-url-of-region'. |
551 | You might want to set this to somewhere with restricted read permissions | |
552 | for privacy's sake." | |
553 | :type 'string | |
554 | :group 'browse-url) | |
555 | ||
5e835c9f SM |
556 | (defcustom browse-url-netscape-version 3 |
557 | "The version of Netscape you are using. | |
8749abea GM |
558 | This affects how URL reloading is done; the mechanism changed |
559 | incompatibly at version 4." | |
560 | :type 'number | |
561 | :group 'browse-url) | |
562 | ||
d9774611 RS |
563 | (defcustom browse-url-text-browser "lynx" |
564 | "The name of the text browser to invoke." | |
565 | :type 'string | |
566 | :group 'browse-url | |
567 | :version "23.1") | |
568 | ||
569 | (defcustom browse-url-text-emacs-args (and (not window-system) | |
570 | '("-show_cursor")) | |
571 | "A list of strings defining options for a text browser in an Emacs buffer. | |
572 | ||
573 | The default is none in a window system, otherwise `-show_cursor' to | |
574 | indicate the position of the current link in the absence of | |
575 | highlighting, assuming the normal default for showing the cursor." | |
576 | :type '(repeat (string :tag "Argument")) | |
577 | :version "23.1" | |
578 | :group 'browse-url) | |
579 | ||
580 | (defcustom browse-url-text-input-field 'avoid | |
581 | "Action on selecting an existing text browser buffer at an input field. | |
582 | What to do when sending a new URL to an existing text browser buffer in Emacs | |
583 | if the browser cursor is on an input field (in which case the `g' command | |
8749abea | 584 | would be entered as data). Such fields are recognized by the |
d9774611 RS |
585 | underlines ____. Allowed values: nil: disregard it, `warn': warn the |
586 | user and don't emit the URL, `avoid': try to avoid the field by moving | |
8749abea GM |
587 | down (this *won't* always work)." |
588 | :type '(choice (const :tag "Move to try to avoid field" :value avoid) | |
589 | (const :tag "Disregard" :value nil) | |
590 | (const :tag "Warn, don't emit URL" :value warn)) | |
d9774611 | 591 | :version "23.1" |
8749abea GM |
592 | :group 'browse-url) |
593 | ||
d9774611 RS |
594 | (defcustom browse-url-text-input-attempts 10 |
595 | "How many times to try to move down from a series of text browser input fields." | |
64f6f486 | 596 | :type 'integer |
d9774611 | 597 | :version "23.1" |
64f6f486 | 598 | :group 'browse-url) |
8749abea | 599 | |
d9774611 RS |
600 | (defcustom browse-url-text-input-delay 0.2 |
601 | "Seconds to wait for a text browser between moves down from an input field." | |
64f6f486 | 602 | :type 'number |
d9774611 | 603 | :version "23.1" |
64f6f486 | 604 | :group 'browse-url) |
8749abea | 605 | |
af06f459 | 606 | (defcustom browse-url-kde-program "kfmclient" |
5e835c9f | 607 | "The name by which to invoke the KDE web browser." |
af06f459 GM |
608 | :type 'string |
609 | :version "21.1" | |
610 | :group 'browse-url) | |
611 | ||
612 | (defcustom browse-url-kde-args '("openURL") | |
5e835c9f | 613 | "A list of strings defining options for `browse-url-kde-program'." |
af06f459 GM |
614 | :type '(repeat (string :tag "Argument")) |
615 | :group 'browse-url) | |
616 | ||
8c22c51a | 617 | (defcustom browse-url-elinks-wrapper '("xterm" "-e") |
1fc7dabf | 618 | "Wrapper command prepended to the Elinks command-line." |
8c22c51a GM |
619 | :type '(repeat (string :tag "Wrapper")) |
620 | :group 'browse-url) | |
621 | ||
622 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
623 | ;; URL encoding | |
624 | ||
6eddc3bb MC |
625 | (defun browse-url-url-encode-chars (text chars) |
626 | "URL-encode the chars in TEXT that match CHARS. | |
da76998b | 627 | CHARS is a regexp-like character alternative (e.g., \"[)$]\")." |
59c4e1da | 628 | (let ((encoded-text (copy-sequence text)) |
ad56e18b | 629 | (s 0)) |
59c4e1da MC |
630 | (while (setq s (string-match chars encoded-text s)) |
631 | (setq encoded-text | |
8c22c51a | 632 | (replace-match (format "%%%x" |
59c4e1da MC |
633 | (string-to-char (match-string 0 encoded-text))) |
634 | t t encoded-text) | |
ad56e18b | 635 | s (1+ s))) |
59c4e1da | 636 | encoded-text)) |
8c22c51a | 637 | |
6eddc3bb MC |
638 | (defun browse-url-encode-url (url) |
639 | "Escape annoying characters in URL. | |
da76998b CY |
640 | The annoying characters are those that can mislead a web browser |
641 | regarding its parameter treatment." | |
642 | ;; FIXME: Is there an actual example of a web browser getting | |
643 | ;; confused? (This used to encode commas, but at least Firefox | |
644 | ;; handles commas correctly and doesn't accept encoded commas.) | |
645 | (browse-url-url-encode-chars url "[)$]")) | |
6eddc3bb | 646 | |
8749abea GM |
647 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
648 | ;; URL input | |
649 | ||
650 | (defun browse-url-url-at-point () | |
651 | (let ((url (thing-at-point 'url))) | |
652 | (set-text-properties 0 (length url) nil url) | |
653 | url)) | |
654 | ||
655 | ;; Having this as a separate function called by the browser-specific | |
656 | ;; functions allows them to be stand-alone commands, making it easier | |
657 | ;; to switch between browsers. | |
658 | ||
659 | (defun browse-url-interactive-arg (prompt) | |
660 | "Read a URL from the minibuffer, prompting with PROMPT. | |
4c493999 | 661 | If `transient-mark-mode' is non-nil and the mark is active, |
657962fc RS |
662 | it defaults to the current region, else to the URL at or before |
663 | point. If invoked with a mouse button, it moves point to the | |
664 | position clicked before acting. | |
665 | ||
666 | This function returns a list (URL NEW-WINDOW-FLAG) | |
667 | for use in `interactive'." | |
8749abea GM |
668 | (let ((event (elt (this-command-keys) 0))) |
669 | (and (listp event) (mouse-set-point event))) | |
4c493999 JB |
670 | (list (read-string prompt (or (and transient-mark-mode mark-active |
671 | ;; rfc2396 Appendix E. | |
672 | (replace-regexp-in-string | |
673 | "[\t\r\f\n ]+" "" | |
674 | (buffer-substring-no-properties | |
675 | (region-beginning) (region-end)))) | |
676 | (browse-url-url-at-point))) | |
408d5219 | 677 | (not (eq (null browse-url-new-window-flag) |
8749abea GM |
678 | (null current-prefix-arg))))) |
679 | ||
2de9d0c3 RS |
680 | ;; called-interactive-p needs to be called at a function's top-level, hence |
681 | ;; this macro. We use that rather than interactive-p because | |
682 | ;; use in a keyboard macro should not change this behavior. | |
01f97560 | 683 | (defmacro browse-url-maybe-new-window (arg) |
12a3c28c | 684 | `(if (or noninteractive (not (called-interactively-p 'any))) |
01f97560 | 685 | ,arg |
408d5219 | 686 | browse-url-new-window-flag)) |
01f97560 | 687 | |
8749abea GM |
688 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
689 | ;; Browse current buffer | |
690 | ||
691 | ;;;###autoload | |
692 | (defun browse-url-of-file (&optional file) | |
693 | "Ask a WWW browser to display FILE. | |
694 | Display the current buffer's file if FILE is nil or if called | |
695 | interactively. Turn the filename into a URL with function | |
696 | `browse-url-file-url'. Pass the URL to a browser using the | |
697 | `browse-url' function then run `browse-url-of-file-hook'." | |
698 | (interactive) | |
699 | (or file | |
700 | (setq file (buffer-file-name)) | |
701 | (error "Current buffer has no file")) | |
702 | (let ((buf (get-file-buffer file))) | |
703 | (if buf | |
378f9937 | 704 | (with-current-buffer buf |
8749abea GM |
705 | (cond ((not (buffer-modified-p))) |
706 | (browse-url-save-file (save-buffer)) | |
707 | (t (message "%s modified since last save" file)))))) | |
708 | (browse-url (browse-url-file-url file)) | |
709 | (run-hooks 'browse-url-of-file-hook)) | |
710 | ||
711 | (defun browse-url-file-url (file) | |
712 | "Return the URL corresponding to FILE. | |
713 | Use variable `browse-url-filename-alist' to map filenames to URLs." | |
5241b291 CY |
714 | ;; De-munge Cygwin filenames before passing them to Windows browser. |
715 | (if (eq system-type 'cygwin) | |
716 | (let ((winfile (with-output-to-string | |
717 | (call-process "cygpath" nil standard-output | |
718 | nil "-m" file)))) | |
719 | (setq file (substring winfile 0 -1)))) | |
95e55d20 | 720 | (let ((coding (and (default-value 'enable-multibyte-characters) |
59b71501 YM |
721 | (or file-name-coding-system |
722 | default-file-name-coding-system)))) | |
723 | (if coding (setq file (encode-coding-string file coding)))) | |
6eddc3bb | 724 | (setq file (browse-url-url-encode-chars file "[*\"()',=;?% ]")) |
63900fcf SS |
725 | (dolist (map browse-url-filename-alist) |
726 | (when (and map (string-match (car map) file)) | |
727 | (setq file (replace-match (cdr map) t nil file)))) | |
8749abea GM |
728 | file) |
729 | ||
730 | ;;;###autoload | |
731 | (defun browse-url-of-buffer (&optional buffer) | |
732 | "Ask a WWW browser to display BUFFER. | |
733 | Display the current buffer if BUFFER is nil. Display only the | |
734 | currently visible part of BUFFER (from a temporary file) if buffer is | |
735 | narrowed." | |
736 | (interactive) | |
737 | (save-excursion | |
738 | (and buffer (set-buffer buffer)) | |
739 | (let ((file-name | |
740 | ;; Ignore real name if restricted | |
741 | (and (= (- (point-max) (point-min)) (buffer-size)) | |
742 | (or buffer-file-name | |
743 | (and (boundp 'dired-directory) dired-directory))))) | |
744 | (or file-name | |
745 | (progn | |
746 | (or browse-url-temp-file-name | |
747 | (setq browse-url-temp-file-name | |
748 | (convert-standard-filename | |
749 | (make-temp-file | |
2e167dc4 RS |
750 | (expand-file-name "burl" browse-url-temp-dir) |
751 | nil ".html")))) | |
8749abea GM |
752 | (setq file-name browse-url-temp-file-name) |
753 | (write-region (point-min) (point-max) file-name nil 'no-message))) | |
754 | (browse-url-of-file file-name)))) | |
755 | ||
756 | (defun browse-url-delete-temp-file (&optional temp-file-name) | |
757 | ;; Delete browse-url-temp-file-name from the file system | |
758 | ;; If optional arg TEMP-FILE-NAME is non-nil, delete it instead | |
759 | (let ((file-name (or temp-file-name browse-url-temp-file-name))) | |
760 | (if (and file-name (file-exists-p file-name)) | |
761 | (delete-file file-name)))) | |
762 | ||
763 | (add-hook 'kill-buffer-hook 'browse-url-delete-temp-file) | |
764 | ||
a1ab97d0 GM |
765 | (declare-function dired-get-filename "dired" |
766 | (&optional localp no-error-if-not-filep)) | |
767 | ||
8749abea GM |
768 | ;;;###autoload |
769 | (defun browse-url-of-dired-file () | |
770 | "In Dired, ask a WWW browser to display the file named on this line." | |
771 | (interactive) | |
772 | (browse-url-of-file (dired-get-filename))) | |
773 | ||
774 | ;;;###autoload | |
775 | (defun browse-url-of-region (min max) | |
776 | "Ask a WWW browser to display the current region." | |
777 | (interactive "r") | |
778 | (save-excursion | |
779 | (save-restriction | |
780 | (narrow-to-region min max) | |
781 | (browse-url-of-buffer)))) | |
782 | ||
783 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
784 | ;; Browser-independent commands | |
785 | ||
786 | ;; A generic command to call the current browse-url-browser-function | |
787 | ||
788 | ;;;###autoload | |
789 | (defun browse-url (url &rest args) | |
790 | "Ask a WWW browser to load URL. | |
791 | Prompts for a URL, defaulting to the URL at or before point. Variable | |
876d1684 LMI |
792 | `browse-url-browser-function' says which browser to use. |
793 | If the URL is a mailto: URL, consult `browse-url-mailto-function' | |
794 | first, if that exists." | |
8749abea | 795 | (interactive (browse-url-interactive-arg "URL: ")) |
32226619 | 796 | (unless (called-interactively-p 'interactive) |
408d5219 | 797 | (setq args (or args (list browse-url-new-window-flag)))) |
876d1684 LMI |
798 | (let ((process-environment (copy-sequence process-environment)) |
799 | (function (or (and (string-match "\\`mailto:" url) | |
800 | browse-url-mailto-function) | |
9d982739 GM |
801 | browse-url-browser-function)) |
802 | ;; Ensure that `default-directory' exists and is readable (b#6077). | |
803 | (default-directory (if (and (file-directory-p default-directory) | |
804 | (file-readable-p default-directory)) | |
805 | default-directory | |
806 | (expand-file-name "~/")))) | |
addc252e SM |
807 | ;; When connected to various displays, be careful to use the display of |
808 | ;; the currently selected frame, rather than the original start display, | |
809 | ;; which may not even exist any more. | |
810 | (if (stringp (frame-parameter (selected-frame) 'display)) | |
811 | (setenv "DISPLAY" (frame-parameter (selected-frame) 'display))) | |
876d1684 LMI |
812 | (if (and (consp function) |
813 | (not (functionp function))) | |
9c16fc95 KR |
814 | ;; The `function' can be an alist; look down it for first match |
815 | ;; and apply the function (which might be a lambda). | |
816 | (catch 'done | |
876d1684 | 817 | (dolist (bf function) |
9c16fc95 KR |
818 | (when (string-match (car bf) url) |
819 | (apply (cdr bf) url args) | |
820 | (throw 'done t))) | |
821 | (error "No browse-url-browser-function matching URL %s" | |
822 | url)) | |
823 | ;; Unbound symbols go down this leg, since void-function from | |
824 | ;; apply is clearer than wrong-type-argument from dolist. | |
876d1684 | 825 | (apply function url args)))) |
8749abea GM |
826 | |
827 | ;;;###autoload | |
01f97560 | 828 | (defun browse-url-at-point (&optional arg) |
8749abea GM |
829 | "Ask a WWW browser to load the URL at or before point. |
830 | Doesn't let you edit the URL like `browse-url'. Variable | |
831 | `browse-url-browser-function' says which browser to use." | |
01f97560 | 832 | (interactive "P") |
3abc9fa1 DL |
833 | (let ((url (browse-url-url-at-point))) |
834 | (if url | |
835 | (browse-url url (if arg | |
408d5219 GM |
836 | (not browse-url-new-window-flag) |
837 | browse-url-new-window-flag)) | |
3abc9fa1 | 838 | (error "No URL found")))) |
8749abea GM |
839 | |
840 | ;;;###autoload | |
841 | (defun browse-url-at-mouse (event) | |
842 | "Ask a WWW browser to load a URL clicked with the mouse. | |
843 | The URL is the one around or before the position of the mouse click | |
844 | but point is not changed. Doesn't let you edit the URL like | |
845 | `browse-url'. Variable `browse-url-browser-function' says which browser | |
846 | to use." | |
847 | (interactive "e") | |
848 | (save-excursion | |
3abc9fa1 | 849 | (mouse-set-point event) |
857356cb RS |
850 | ;; This handles browse-url-new-window-flag properly |
851 | ;; when it gets no arg. | |
852 | (browse-url-at-point))) | |
8749abea GM |
853 | |
854 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
855 | ;; Browser-specific commands | |
856 | ||
857 | ;; --- Default MS-Windows browser --- | |
858 | ||
14a06a2d | 859 | (defvar dos-windows-version) |
73e6adaa | 860 | (declare-function w32-shell-execute "w32fns.c") ;; Defined in C. |
14a06a2d | 861 | |
8749abea GM |
862 | (defun browse-url-default-windows-browser (url &optional new-window) |
863 | (interactive (browse-url-interactive-arg "URL: ")) | |
e572025f CY |
864 | (cond ((eq system-type 'ms-dos) |
865 | (if dos-windows-version | |
866 | (shell-command (concat "start " (shell-quote-argument url))) | |
867 | (error "Browsing URLs is not supported on this system"))) | |
868 | ((eq system-type 'cygwin) | |
5241b291 | 869 | (call-process "cygstart" nil nil nil url)) |
e572025f | 870 | (t (w32-shell-execute "open" url)))) |
8749abea | 871 | |
662871dd SM |
872 | (defun browse-url-default-macosx-browser (url &optional new-window) |
873 | (interactive (browse-url-interactive-arg "URL: ")) | |
874 | (start-process (concat "open " url) nil "open" url)) | |
875 | ||
8749abea GM |
876 | ;; --- Netscape --- |
877 | ||
878 | (defun browse-url-process-environment () | |
7f61a9ee RS |
879 | "Set DISPLAY in the environment to the X display the browser will use. |
880 | This is either the value of variable `browse-url-browser-display' if | |
8749abea GM |
881 | non-nil, or the same display as Emacs if different from the current |
882 | environment, otherwise just use the current environment." | |
7f61a9ee | 883 | (let ((display (or browse-url-browser-display (browse-url-emacs-display)))) |
8749abea GM |
884 | (if display |
885 | (cons (concat "DISPLAY=" display) process-environment) | |
886 | process-environment))) | |
887 | ||
888 | (defun browse-url-emacs-display () | |
889 | "Return the X display Emacs is running on. | |
890 | This is nil if the display is the same as the DISPLAY environment variable. | |
891 | ||
892 | Actually Emacs could be using several displays; this just returns the | |
893 | one showing the selected frame." | |
894 | (let ((display (cdr-safe (assq 'display (frame-parameters))))) | |
895 | (and (not (equal display (getenv "DISPLAY"))) | |
896 | display))) | |
897 | ||
7f61a9ee RS |
898 | (defun browse-url-default-browser (url &rest args) |
899 | "Find a suitable browser and ask it to load URL. | |
900 | Default to the URL around or before point. | |
901 | ||
902 | When called interactively, if variable `browse-url-new-window-flag' is | |
903 | non-nil, load the document in a new window, if possible, otherwise use | |
904 | a random existing one. A non-nil interactive prefix argument reverses | |
905 | the effect of `browse-url-new-window-flag'. | |
906 | ||
907 | When called non-interactively, optional second argument NEW-WINDOW is | |
908 | used instead of `browse-url-new-window-flag'. | |
909 | ||
49866ff8 | 910 | The order attempted is gnome-moz-remote, Mozilla, Firefox, |
66dc1ca2 | 911 | Galeon, Konqueror, Netscape, Mosaic, Lynx in an xterm, and then W3." |
7f61a9ee | 912 | (apply |
6eddc3bb | 913 | (cond |
2269b349 | 914 | ((browse-url-can-use-xdg-open) 'browse-url-xdg-open) |
6eddc3bb MC |
915 | ((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz) |
916 | ((executable-find browse-url-mozilla-program) 'browse-url-mozilla) | |
917 | ((executable-find browse-url-firefox-program) 'browse-url-firefox) | |
918 | ((executable-find browse-url-galeon-program) 'browse-url-galeon) | |
919 | ((executable-find browse-url-kde-program) 'browse-url-kde) | |
920 | ((executable-find browse-url-netscape-program) 'browse-url-netscape) | |
921 | ((executable-find browse-url-mosaic-program) 'browse-url-mosaic) | |
d9774611 | 922 | ((executable-find browse-url-xterm-program) 'browse-url-text-xterm) |
6eddc3bb MC |
923 | ((locate-library "w3") 'browse-url-w3) |
924 | (t | |
db6003fb | 925 | (lambda (&rest ignore) (error "No usable browser found")))) |
6eddc3bb | 926 | url args)) |
7f61a9ee | 927 | |
2269b349 JD |
928 | (defun browse-url-can-use-xdg-open () |
929 | "Check if xdg-open can be used, i.e. we are on Gnome, KDE or xfce4." | |
930 | (and (getenv "DISPLAY") | |
931 | (executable-find "xdg-open") | |
932 | ;; xdg-open may call gnome-open and that does not wait for its child | |
933 | ;; to finish. This child may then be killed when the parent dies. | |
934 | ;; Use nohup to work around. | |
935 | (executable-find "nohup") | |
936 | (or (getenv "GNOME_DESKTOP_SESSION_ID") | |
937 | ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also. | |
938 | (condition-case nil | |
939 | (eq 0 (call-process | |
940 | "dbus-send" nil nil nil | |
941 | "--dest=org.gnome.SessionManager" | |
942 | "--print-reply" | |
943 | "/org/gnome/SessionManager" | |
944 | "org.gnome.SessionManager.CanShutdown")) | |
945 | (error nil)) | |
946 | (equal (getenv "KDE_FULL_SESSION") "true") | |
947 | (condition-case nil | |
948 | (eq 0 (call-process | |
949 | "/bin/sh" nil nil nil | |
950 | "-c" | |
951 | "xprop -root _DT_SAVE_MODE|grep xfce4")) | |
952 | (error nil))))) | |
953 | ||
954 | ||
955 | ;;;###autoload | |
956 | (defun browse-url-xdg-open (url &optional new-window) | |
957 | (interactive (browse-url-interactive-arg "URL: ")) | |
2187e5bb | 958 | (call-process "nohup" nil nil nil "xdg-open" url)) |
2269b349 | 959 | |
8749abea GM |
960 | ;;;###autoload |
961 | (defun browse-url-netscape (url &optional new-window) | |
962 | "Ask the Netscape WWW browser to load URL. | |
8749abea GM |
963 | Default to the URL around or before point. The strings in variable |
964 | `browse-url-netscape-arguments' are also passed to Netscape. | |
965 | ||
408d5219 | 966 | When called interactively, if variable `browse-url-new-window-flag' is |
8749abea GM |
967 | non-nil, load the document in a new Netscape window, otherwise use a |
968 | random existing one. A non-nil interactive prefix argument reverses | |
408d5219 | 969 | the effect of `browse-url-new-window-flag'. |
8749abea | 970 | |
fe77c061 SJ |
971 | If `browse-url-netscape-new-window-is-tab' is non-nil, then |
972 | whenever a document would otherwise be loaded in a new window, it | |
973 | is loaded in a new tab in an existing window instead. | |
974 | ||
8749abea | 975 | When called non-interactively, optional second argument NEW-WINDOW is |
408d5219 | 976 | used instead of `browse-url-new-window-flag'." |
de5552d5 | 977 | (interactive (browse-url-interactive-arg "URL: ")) |
8c22c51a | 978 | (setq url (browse-url-encode-url url)) |
8749abea | 979 | (let* ((process-environment (browse-url-process-environment)) |
fe77c061 SJ |
980 | (process |
981 | (apply 'start-process | |
982 | (concat "netscape " url) nil | |
983 | browse-url-netscape-program | |
984 | (append | |
985 | browse-url-netscape-arguments | |
986 | (if (eq window-system 'w32) | |
987 | (list url) | |
988 | (append | |
989 | (if new-window '("-noraise")) | |
990 | (list "-remote" | |
991 | (concat "openURL(" url | |
992 | (if (browse-url-maybe-new-window | |
993 | new-window) | |
994 | (if browse-url-netscape-new-window-is-tab | |
995 | ",new-tab" | |
996 | ",new-window")) | |
997 | ")")))))))) | |
8749abea | 998 | (set-process-sentinel process |
3abc9fa1 DL |
999 | `(lambda (process change) |
1000 | (browse-url-netscape-sentinel process ,url))))) | |
8749abea GM |
1001 | |
1002 | (defun browse-url-netscape-sentinel (process url) | |
1003 | "Handle a change to the process communicating with Netscape." | |
1004 | (or (eq (process-exit-status process) 0) | |
1005 | (let* ((process-environment (browse-url-process-environment))) | |
1006 | ;; Netscape not running - start it | |
7844257c | 1007 | (message "Starting %s..." browse-url-netscape-program) |
8749abea GM |
1008 | (apply 'start-process (concat "netscape" url) nil |
1009 | browse-url-netscape-program | |
1010 | (append browse-url-netscape-startup-arguments (list url)))))) | |
1011 | ||
1012 | (defun browse-url-netscape-reload () | |
1013 | "Ask Netscape to reload its current document. | |
1014 | How depends on `browse-url-netscape-version'." | |
1015 | (interactive) | |
1016 | ;; Backwards incompatibility reported by | |
1017 | ;; <peter.kruse@psychologie.uni-regensburg.de>. | |
1018 | (browse-url-netscape-send (if (>= browse-url-netscape-version 4) | |
1019 | "xfeDoCommand(reload)" | |
6eddc3bb | 1020 | "reload"))) |
8749abea GM |
1021 | |
1022 | (defun browse-url-netscape-send (command) | |
1023 | "Send a remote control command to Netscape." | |
1024 | (let* ((process-environment (browse-url-process-environment))) | |
1025 | (apply 'start-process "netscape" nil | |
1026 | browse-url-netscape-program | |
1027 | (append browse-url-netscape-arguments | |
1028 | (list "-remote" command))))) | |
1029 | ||
7f61a9ee RS |
1030 | ;;;###autoload |
1031 | (defun browse-url-mozilla (url &optional new-window) | |
1032 | "Ask the Mozilla WWW browser to load URL. | |
1033 | Default to the URL around or before point. The strings in variable | |
1034 | `browse-url-mozilla-arguments' are also passed to Mozilla. | |
1035 | ||
1036 | When called interactively, if variable `browse-url-new-window-flag' is | |
1037 | non-nil, load the document in a new Mozilla window, otherwise use a | |
1038 | random existing one. A non-nil interactive prefix argument reverses | |
1039 | the effect of `browse-url-new-window-flag'. | |
1040 | ||
d6da15ec SJ |
1041 | If `browse-url-mozilla-new-window-is-tab' is non-nil, then whenever a |
1042 | document would otherwise be loaded in a new window, it is loaded in a | |
1043 | new tab in an existing window instead. | |
1044 | ||
7f61a9ee RS |
1045 | When called non-interactively, optional second argument NEW-WINDOW is |
1046 | used instead of `browse-url-new-window-flag'." | |
1047 | (interactive (browse-url-interactive-arg "URL: ")) | |
8c22c51a | 1048 | (setq url (browse-url-encode-url url)) |
7f61a9ee | 1049 | (let* ((process-environment (browse-url-process-environment)) |
d6da15ec SJ |
1050 | (process |
1051 | (apply 'start-process | |
1052 | (concat "mozilla " url) nil | |
1053 | browse-url-mozilla-program | |
1054 | (append | |
1055 | browse-url-mozilla-arguments | |
1056 | (list "-remote" | |
1057 | (concat "openURL(" | |
1058 | url | |
1059 | (if (browse-url-maybe-new-window | |
1060 | new-window) | |
1061 | (if browse-url-mozilla-new-window-is-tab | |
c29cf9a4 RS |
1062 | ",new-tab" |
1063 | ",new-window")) | |
d6da15ec | 1064 | ")")))))) |
7f61a9ee RS |
1065 | (set-process-sentinel process |
1066 | `(lambda (process change) | |
1067 | (browse-url-mozilla-sentinel process ,url))))) | |
1068 | ||
1069 | (defun browse-url-mozilla-sentinel (process url) | |
1070 | "Handle a change to the process communicating with Mozilla." | |
1071 | (or (eq (process-exit-status process) 0) | |
1072 | (let* ((process-environment (browse-url-process-environment))) | |
1073 | ;; Mozilla is not running - start it | |
7844257c | 1074 | (message "Starting %s..." browse-url-mozilla-program) |
7f61a9ee RS |
1075 | (apply 'start-process (concat "mozilla " url) nil |
1076 | browse-url-mozilla-program | |
1077 | (append browse-url-mozilla-startup-arguments (list url)))))) | |
49866ff8 EZ |
1078 | |
1079 | ;;;###autoload | |
1080 | (defun browse-url-firefox (url &optional new-window) | |
1081 | "Ask the Firefox WWW browser to load URL. | |
1082 | Default to the URL around or before point. The strings in | |
1083 | variable `browse-url-firefox-arguments' are also passed to | |
1084 | Firefox. | |
1085 | ||
1086 | When called interactively, if variable | |
1087 | `browse-url-new-window-flag' is non-nil, load the document in a | |
1088 | new Firefox window, otherwise use a random existing one. A | |
1089 | non-nil interactive prefix argument reverses the effect of | |
1090 | `browse-url-new-window-flag'. | |
1091 | ||
1092 | If `browse-url-firefox-new-window-is-tab' is non-nil, then | |
1093 | whenever a document would otherwise be loaded in a new window, it | |
1094 | is loaded in a new tab in an existing window instead. | |
1095 | ||
1096 | When called non-interactively, optional second argument | |
1097 | NEW-WINDOW is used instead of `browse-url-new-window-flag'. | |
1098 | ||
1099 | On MS-Windows systems the optional `new-window' parameter is | |
1100 | ignored. Firefox for Windows does not support the \"-remote\" | |
1101 | command line parameter. Therefore, the | |
1102 | `browse-url-new-window-flag' and `browse-url-firefox-new-window-is-tab' | |
1103 | are ignored as well. Firefox on Windows will always open the requested | |
1104 | URL in a new window." | |
1105 | (interactive (browse-url-interactive-arg "URL: ")) | |
8c22c51a | 1106 | (setq url (browse-url-encode-url url)) |
49866ff8 EZ |
1107 | (let* ((process-environment (browse-url-process-environment)) |
1108 | (process | |
1109 | (apply 'start-process | |
1110 | (concat "firefox " url) nil | |
1111 | browse-url-firefox-program | |
1112 | (append | |
1113 | browse-url-firefox-arguments | |
3c4671f4 | 1114 | (if (memq system-type '(windows-nt ms-dos)) |
49866ff8 EZ |
1115 | (list url) |
1116 | (list "-remote" | |
1117 | (concat "openURL(" | |
1118 | url | |
1119 | (if (browse-url-maybe-new-window | |
1120 | new-window) | |
1121 | (if browse-url-firefox-new-window-is-tab | |
1122 | ",new-tab" | |
1123 | ",new-window")) | |
1124 | ")"))))))) | |
1125 | (set-process-sentinel process | |
1126 | `(lambda (process change) | |
1127 | (browse-url-firefox-sentinel process ,url))))) | |
1128 | ||
1129 | (defun browse-url-firefox-sentinel (process url) | |
1130 | "Handle a change to the process communicating with Firefox." | |
1131 | (or (eq (process-exit-status process) 0) | |
1132 | (let* ((process-environment (browse-url-process-environment))) | |
1133 | ;; Firefox is not running - start it | |
1134 | (message "Starting Firefox...") | |
1135 | (apply 'start-process (concat "firefox " url) nil | |
1136 | browse-url-firefox-program | |
1137 | (append browse-url-firefox-startup-arguments (list url)))))) | |
7f61a9ee RS |
1138 | |
1139 | ;;;###autoload | |
1140 | (defun browse-url-galeon (url &optional new-window) | |
1141 | "Ask the Galeon WWW browser to load URL. | |
1142 | Default to the URL around or before point. The strings in variable | |
1143 | `browse-url-galeon-arguments' are also passed to Galeon. | |
1144 | ||
1145 | When called interactively, if variable `browse-url-new-window-flag' is | |
1146 | non-nil, load the document in a new Galeon window, otherwise use a | |
1147 | random existing one. A non-nil interactive prefix argument reverses | |
1148 | the effect of `browse-url-new-window-flag'. | |
1149 | ||
b77784f7 RS |
1150 | If `browse-url-galeon-new-window-is-tab' is non-nil, then whenever a |
1151 | document would otherwise be loaded in a new window, it is loaded in a | |
1152 | new tab in an existing window instead. | |
1153 | ||
7f61a9ee RS |
1154 | When called non-interactively, optional second argument NEW-WINDOW is |
1155 | used instead of `browse-url-new-window-flag'." | |
1156 | (interactive (browse-url-interactive-arg "URL: ")) | |
5edcabcb | 1157 | (setq url (browse-url-encode-url url)) |
7f61a9ee RS |
1158 | (let* ((process-environment (browse-url-process-environment)) |
1159 | (process (apply 'start-process | |
654805e3 RS |
1160 | (concat "galeon " url) |
1161 | nil | |
7f61a9ee RS |
1162 | browse-url-galeon-program |
1163 | (append | |
1164 | browse-url-galeon-arguments | |
1d5d4123 RS |
1165 | (if (browse-url-maybe-new-window new-window) |
1166 | (if browse-url-galeon-new-window-is-tab | |
1167 | '("--new-tab") | |
b77784f7 RS |
1168 | '("--new-window" "--noraise")) |
1169 | '("--existing")) | |
1170 | (list url))))) | |
7f61a9ee RS |
1171 | (set-process-sentinel process |
1172 | `(lambda (process change) | |
1173 | (browse-url-galeon-sentinel process ,url))))) | |
1174 | ||
1175 | (defun browse-url-galeon-sentinel (process url) | |
1176 | "Handle a change to the process communicating with Galeon." | |
1177 | (or (eq (process-exit-status process) 0) | |
1178 | (let* ((process-environment (browse-url-process-environment))) | |
1179 | ;; Galeon is not running - start it | |
7844257c | 1180 | (message "Starting %s..." browse-url-galeon-program) |
7f61a9ee RS |
1181 | (apply 'start-process (concat "galeon " url) nil |
1182 | browse-url-galeon-program | |
1183 | (append browse-url-galeon-startup-arguments (list url)))))) | |
1184 | ||
654805e3 RS |
1185 | (defun browse-url-epiphany (url &optional new-window) |
1186 | "Ask the Epiphany WWW browser to load URL. | |
1187 | Default to the URL around or before point. The strings in variable | |
1188 | `browse-url-galeon-arguments' are also passed to Epiphany. | |
1189 | ||
1190 | When called interactively, if variable `browse-url-new-window-flag' is | |
1191 | non-nil, load the document in a new Epiphany window, otherwise use a | |
1192 | random existing one. A non-nil interactive prefix argument reverses | |
1193 | the effect of `browse-url-new-window-flag'. | |
1194 | ||
674dd916 | 1195 | If `browse-url-epiphany-new-window-is-tab' is non-nil, then whenever a |
654805e3 RS |
1196 | document would otherwise be loaded in a new window, it is loaded in a |
1197 | new tab in an existing window instead. | |
1198 | ||
1199 | When called non-interactively, optional second argument NEW-WINDOW is | |
1200 | used instead of `browse-url-new-window-flag'." | |
1201 | (interactive (browse-url-interactive-arg "URL: ")) | |
8c22c51a | 1202 | (setq url (browse-url-encode-url url)) |
654805e3 RS |
1203 | (let* ((process-environment (browse-url-process-environment)) |
1204 | (process (apply 'start-process | |
1205 | (concat "epiphany " url) | |
1206 | nil | |
1207 | browse-url-epiphany-program | |
1208 | (append | |
1209 | browse-url-epiphany-arguments | |
1210 | (if (browse-url-maybe-new-window new-window) | |
1211 | (if browse-url-epiphany-new-window-is-tab | |
1212 | '("--new-tab") | |
1213 | '("--new-window" "--noraise")) | |
1214 | '("--existing")) | |
1215 | (list url))))) | |
1216 | (set-process-sentinel process | |
1217 | `(lambda (process change) | |
1218 | (browse-url-epiphany-sentinel process ,url))))) | |
1219 | ||
1220 | (defun browse-url-epiphany-sentinel (process url) | |
1221 | "Handle a change to the process communicating with Epiphany." | |
1222 | (or (eq (process-exit-status process) 0) | |
1223 | (let* ((process-environment (browse-url-process-environment))) | |
1224 | ;; Epiphany is not running - start it | |
7844257c | 1225 | (message "Starting %s..." browse-url-epiphany-program) |
654805e3 RS |
1226 | (apply 'start-process (concat "epiphany " url) nil |
1227 | browse-url-epiphany-program | |
1228 | (append browse-url-epiphany-startup-arguments (list url)))))) | |
1229 | ||
3fe5c37a DN |
1230 | (defvar url-handler-regexp) |
1231 | ||
378f9937 SM |
1232 | ;;;###autoload |
1233 | (defun browse-url-emacs (url &optional new-window) | |
1234 | "Ask Emacs to load URL into a buffer and show it in another window." | |
1235 | (interactive (browse-url-interactive-arg "URL: ")) | |
1236 | (require 'url-handlers) | |
1237 | (let ((file-name-handler-alist | |
1238 | (cons (cons url-handler-regexp 'url-file-handler) | |
1239 | file-name-handler-alist))) | |
1240 | ;; Ignore `new-window': with all other browsers the URL is always shown | |
1241 | ;; in another window than the current Emacs one since it's shown in | |
1242 | ;; another application's window. | |
1243 | ;; (if new-window (find-file-other-window url) (find-file url)) | |
1244 | (find-file-other-window url))) | |
1245 | ||
b12e6de3 | 1246 | ;;;###autoload |
de5552d5 DL |
1247 | (defun browse-url-gnome-moz (url &optional new-window) |
1248 | "Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'. | |
1249 | Default to the URL around or before point. The strings in variable | |
1250 | `browse-url-gnome-moz-arguments' are also passed. | |
1251 | ||
408d5219 | 1252 | When called interactively, if variable `browse-url-new-window-flag' is |
de5552d5 DL |
1253 | non-nil, load the document in a new browser window, otherwise use an |
1254 | existing one. A non-nil interactive prefix argument reverses the | |
408d5219 | 1255 | effect of `browse-url-new-window-flag'. |
de5552d5 DL |
1256 | |
1257 | When called non-interactively, optional second argument NEW-WINDOW is | |
408d5219 | 1258 | used instead of `browse-url-new-window-flag'." |
c60ee5e7 | 1259 | (interactive (browse-url-interactive-arg "URL: ")) |
de5552d5 DL |
1260 | (apply 'start-process (concat "gnome-moz-remote " url) |
1261 | nil | |
662871dd | 1262 | browse-url-gnome-moz-program |
de5552d5 DL |
1263 | (append |
1264 | browse-url-gnome-moz-arguments | |
1265 | (if (browse-url-maybe-new-window new-window) | |
6eddc3bb | 1266 | '("--newwin")) |
de5552d5 DL |
1267 | (list "--raise" url)))) |
1268 | ||
8749abea GM |
1269 | ;; --- Mosaic --- |
1270 | ||
1271 | ;;;###autoload | |
1272 | (defun browse-url-mosaic (url &optional new-window) | |
1273 | "Ask the XMosaic WWW browser to load URL. | |
1274 | ||
1275 | Default to the URL around or before point. The strings in variable | |
1276 | `browse-url-mosaic-arguments' are also passed to Mosaic and the | |
1277 | program is invoked according to the variable | |
1278 | `browse-url-mosaic-program'. | |
1279 | ||
408d5219 | 1280 | When called interactively, if variable `browse-url-new-window-flag' is |
8749abea GM |
1281 | non-nil, load the document in a new Mosaic window, otherwise use a |
1282 | random existing one. A non-nil interactive prefix argument reverses | |
408d5219 | 1283 | the effect of `browse-url-new-window-flag'. |
8749abea GM |
1284 | |
1285 | When called non-interactively, optional second argument NEW-WINDOW is | |
408d5219 | 1286 | used instead of `browse-url-new-window-flag'." |
8749abea | 1287 | (interactive (browse-url-interactive-arg "Mosaic URL: ")) |
1665be47 | 1288 | (let ((pidfile (expand-file-name browse-url-mosaic-pidfile)) |
8749abea GM |
1289 | pid) |
1290 | (if (file-readable-p pidfile) | |
1291 | (save-excursion | |
1292 | (find-file pidfile) | |
1293 | (goto-char (point-min)) | |
1294 | (setq pid (read (current-buffer))) | |
1295 | (kill-buffer nil))) | |
1296 | (if (and pid (zerop (signal-process pid 0))) ; Mosaic running | |
1297 | (save-excursion | |
1298 | (find-file (format "/tmp/Mosaic.%d" pid)) | |
1299 | (erase-buffer) | |
01f97560 | 1300 | (insert (if (browse-url-maybe-new-window new-window) |
8749abea GM |
1301 | "newwin\n" |
1302 | "goto\n") | |
1303 | url "\n") | |
1304 | (save-buffer) | |
1305 | (kill-buffer nil) | |
1306 | ;; Send signal SIGUSR to Mosaic | |
84c2714c | 1307 | (message "Signaling Mosaic...") |
662871dd | 1308 | (signal-process pid 'SIGUSR1) |
8749abea GM |
1309 | ;; Or you could try: |
1310 | ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid)) | |
84c2714c | 1311 | (message "Signaling Mosaic...done") |
8749abea GM |
1312 | ) |
1313 | ;; Mosaic not running - start it | |
7844257c | 1314 | (message "Starting %s..." browse-url-mosaic-program) |
8749abea GM |
1315 | (apply 'start-process "xmosaic" nil browse-url-mosaic-program |
1316 | (append browse-url-mosaic-arguments (list url))) | |
7844257c | 1317 | (message "Starting %s...done" browse-url-mosaic-program)))) |
8749abea | 1318 | |
8749abea GM |
1319 | ;; --- Mosaic using CCI --- |
1320 | ||
1321 | ;;;###autoload | |
1322 | (defun browse-url-cci (url &optional new-window) | |
1323 | "Ask the XMosaic WWW browser to load URL. | |
1324 | Default to the URL around or before point. | |
1325 | ||
1326 | This function only works for XMosaic version 2.5 or later. You must | |
1327 | select `CCI' from XMosaic's File menu, set the CCI Port Address to the | |
1328 | value of variable `browse-url-CCI-port', and enable `Accept requests'. | |
1329 | ||
408d5219 | 1330 | When called interactively, if variable `browse-url-new-window-flag' is |
8749abea GM |
1331 | non-nil, load the document in a new browser window, otherwise use a |
1332 | random existing one. A non-nil interactive prefix argument reverses | |
408d5219 | 1333 | the effect of `browse-url-new-window-flag'. |
8749abea GM |
1334 | |
1335 | When called non-interactively, optional second argument NEW-WINDOW is | |
408d5219 | 1336 | used instead of `browse-url-new-window-flag'." |
8749abea GM |
1337 | (interactive (browse-url-interactive-arg "Mosaic URL: ")) |
1338 | (open-network-stream "browse-url" " *browse-url*" | |
1339 | browse-url-CCI-host browse-url-CCI-port) | |
1340 | ;; Todo: start browser if fails | |
1341 | (process-send-string "browse-url" | |
1342 | (concat "get url (" url ") output " | |
01f97560 | 1343 | (if (browse-url-maybe-new-window new-window) |
8749abea GM |
1344 | "new" |
1345 | "current") | |
1346 | "\r\n")) | |
1347 | (process-send-string "browse-url" "disconnect\r\n") | |
1348 | (delete-process "browse-url")) | |
1349 | ||
8749abea GM |
1350 | ;; --- W3 --- |
1351 | ||
352d2dea GM |
1352 | ;; External. |
1353 | (declare-function w3-fetch-other-window "ext:w3m" (&optional url)) | |
1354 | (declare-function w3-fetch "ext:w3m" (&optional url target)) | |
1355 | ||
8749abea GM |
1356 | ;;;###autoload |
1357 | (defun browse-url-w3 (url &optional new-window) | |
1358 | "Ask the w3 WWW browser to load URL. | |
1359 | Default to the URL around or before point. | |
1360 | ||
408d5219 | 1361 | When called interactively, if variable `browse-url-new-window-flag' is |
8749abea | 1362 | non-nil, load the document in a new window. A non-nil interactive |
408d5219 | 1363 | prefix argument reverses the effect of `browse-url-new-window-flag'. |
8749abea GM |
1364 | |
1365 | When called non-interactively, optional second argument NEW-WINDOW is | |
408d5219 | 1366 | used instead of `browse-url-new-window-flag'." |
8749abea | 1367 | (interactive (browse-url-interactive-arg "W3 URL: ")) |
6eddc3bb | 1368 | (require 'w3) ; w3-fetch-other-window not autoloaded |
01f97560 | 1369 | (if (browse-url-maybe-new-window new-window) |
8749abea GM |
1370 | (w3-fetch-other-window url) |
1371 | (w3-fetch url))) | |
1372 | ||
1373 | ;;;###autoload | |
1374 | (defun browse-url-w3-gnudoit (url &optional new-window) | |
1375 | ;; new-window ignored | |
1376 | "Ask another Emacs running gnuserv to load the URL using the W3 browser. | |
1377 | The `browse-url-gnudoit-program' program is used with options given by | |
1378 | `browse-url-gnudoit-args'. Default to the URL around or before point." | |
1379 | (interactive (browse-url-interactive-arg "W3 URL: ")) | |
6eddc3bb MC |
1380 | (apply 'start-process (concat "gnudoit:" url) nil |
1381 | browse-url-gnudoit-program | |
1382 | (append browse-url-gnudoit-args | |
1383 | (list (concat "(w3-fetch \"" url "\")") | |
1384 | "(raise-frame)")))) | |
8749abea GM |
1385 | |
1386 | ;; --- Lynx in an xterm --- | |
1387 | ||
1388 | ;;;###autoload | |
d9774611 | 1389 | (defun browse-url-text-xterm (url &optional new-window) |
8749abea | 1390 | ;; new-window ignored |
d9774611 | 1391 | "Ask a text browser to load URL. |
db6003fb | 1392 | URL defaults to the URL around or before point. |
d9774611 | 1393 | This runs the text browser specified by `browse-url-text-browser'. |
8749abea GM |
1394 | in an Xterm window using the Xterm program named by `browse-url-xterm-program' |
1395 | with possible additional arguments `browse-url-xterm-args'." | |
d9774611 RS |
1396 | (interactive (browse-url-interactive-arg "Text browser URL: ")) |
1397 | (apply #'start-process `(,(concat browse-url-text-browser url) | |
1398 | nil ,browse-url-xterm-program | |
03e49c06 | 1399 | ,@browse-url-xterm-args "-e" ,browse-url-text-browser |
6eddc3bb | 1400 | ,url))) |
8749abea GM |
1401 | |
1402 | ;; --- Lynx in an Emacs "term" window --- | |
1403 | ||
a1ab97d0 GM |
1404 | (declare-function term-char-mode "term" ()) |
1405 | (declare-function term-send-down "term" ()) | |
1406 | (declare-function term-send-string "term" (proc str)) | |
1407 | ||
8749abea | 1408 | ;;;###autoload |
d9774611 RS |
1409 | (defun browse-url-text-emacs (url &optional new-buffer) |
1410 | "Ask a text browser to load URL. | |
db6003fb | 1411 | URL defaults to the URL around or before point. |
d9774611 RS |
1412 | This runs the text browser specified by `browse-url-text-browser'. |
1413 | With a prefix argument, it runs a new browser process in a new buffer. | |
8749abea | 1414 | |
408d5219 | 1415 | When called interactively, if variable `browse-url-new-window-flag' is |
d9774611 | 1416 | non-nil, load the document in a new browser process in a new term window, |
8749abea | 1417 | otherwise use any existing one. A non-nil interactive prefix argument |
408d5219 | 1418 | reverses the effect of `browse-url-new-window-flag'. |
8749abea GM |
1419 | |
1420 | When called non-interactively, optional second argument NEW-WINDOW is | |
408d5219 | 1421 | used instead of `browse-url-new-window-flag'." |
d9774611 | 1422 | (interactive (browse-url-interactive-arg "Text browser URL: ")) |
6eddc3bb | 1423 | (let* ((system-uses-terminfo t) ; Lynx uses terminfo |
8749abea | 1424 | ;; (term-term-name "vt100") ; ?? |
d9774611 | 1425 | (buf (get-buffer "*text browser*")) |
8749abea | 1426 | (proc (and buf (get-buffer-process buf))) |
d9774611 | 1427 | (n browse-url-text-input-attempts)) |
a1ab97d0 | 1428 | (require 'term) |
01f97560 | 1429 | (if (and (browse-url-maybe-new-window new-buffer) buf) |
8749abea GM |
1430 | ;; Rename away the OLD buffer. This isn't very polite, but |
1431 | ;; term insists on working in a buffer named *lynx* and would | |
1432 | ;; choke on *lynx*<1> | |
1433 | (progn (set-buffer buf) | |
1434 | (rename-uniquely))) | |
01f97560 | 1435 | (if (or (browse-url-maybe-new-window new-buffer) |
8749abea GM |
1436 | (not buf) |
1437 | (not proc) | |
1438 | (not (memq (process-status proc) '(run stop)))) | |
d9774611 | 1439 | ;; start a new text browser |
8749abea GM |
1440 | (progn |
1441 | (setq buf | |
1442 | (apply #'make-term | |
d9774611 RS |
1443 | `(,browse-url-text-browser |
1444 | ,browse-url-text-browser | |
1445 | nil ,@browse-url-text-emacs-args | |
01f97560 | 1446 | ,url))) |
8749abea GM |
1447 | (switch-to-buffer buf) |
1448 | (term-char-mode) | |
1449 | (set-process-sentinel | |
1450 | (get-buffer-process buf) | |
1451 | ;; Don't leave around a dead one (especially because of its | |
1452 | ;; munged keymap.) | |
1453 | (lambda (process event) | |
1454 | (if (not (memq (process-status process) '(run stop))) | |
1455 | (let ((buf (process-buffer process))) | |
1456 | (if buf (kill-buffer buf))))))) | |
d9774611 | 1457 | ;; Send the url to the text browser in the old buffer |
8749abea GM |
1458 | (let ((win (get-buffer-window buf t))) |
1459 | (if win | |
1460 | (select-window win) | |
1461 | (switch-to-buffer buf))) | |
1462 | (if (eq (following-char) ?_) | |
d9774611 | 1463 | (cond ((eq browse-url-text-input-field 'warn) |
e8af40ee | 1464 | (error "Please move out of the input field first")) |
d9774611 | 1465 | ((eq browse-url-text-input-field 'avoid) |
8749abea | 1466 | (while (and (eq (following-char) ?_) (> n 0)) |
6eddc3bb | 1467 | (term-send-down) ; down arrow |
d9774611 | 1468 | (sit-for browse-url-text-input-delay)) |
8749abea | 1469 | (if (eq (following-char) ?_) |
e8af40ee | 1470 | (error "Cannot move out of the input field, sorry"))))) |
6eddc3bb | 1471 | (term-send-string proc (concat "g" ; goto |
8749abea GM |
1472 | "\C-u" ; kill default url |
1473 | url | |
1474 | "\r"))))) | |
1475 | ||
8749abea GM |
1476 | ;; --- mailto --- |
1477 | ||
1abcd088 EZ |
1478 | (autoload 'rfc2368-parse-mailto-url "rfc2368") |
1479 | ||
8749abea GM |
1480 | ;;;###autoload |
1481 | (defun browse-url-mail (url &optional new-window) | |
1abcd088 | 1482 | "Open a new mail message buffer within Emacs for the RFC 2368 URL. |
8749abea GM |
1483 | Default to using the mailto: URL around or before point as the |
1484 | recipient's address. Supplying a non-nil interactive prefix argument | |
1485 | will cause the mail to be composed in another window rather than the | |
1486 | current one. | |
1487 | ||
408d5219 | 1488 | When called interactively, if variable `browse-url-new-window-flag' is |
8749abea GM |
1489 | non-nil use `compose-mail-other-window', otherwise `compose-mail'. A |
1490 | non-nil interactive prefix argument reverses the effect of | |
408d5219 | 1491 | `browse-url-new-window-flag'. |
8749abea GM |
1492 | |
1493 | When called non-interactively, optional second argument NEW-WINDOW is | |
408d5219 | 1494 | used instead of `browse-url-new-window-flag'." |
8749abea GM |
1495 | (interactive (browse-url-interactive-arg "Mailto URL: ")) |
1496 | (save-excursion | |
1abcd088 EZ |
1497 | (let* ((alist (rfc2368-parse-mailto-url url)) |
1498 | (to (assoc "To" alist)) | |
1499 | (subject (assoc "Subject" alist)) | |
1500 | (body (assoc "Body" alist)) | |
5ad3e885 | 1501 | (rest (delq to (delq subject (delq body alist)))) |
1abcd088 EZ |
1502 | (to (cdr to)) |
1503 | (subject (cdr subject)) | |
1504 | (body (cdr body)) | |
1505 | (mail-citation-hook (unless body mail-citation-hook))) | |
01f97560 | 1506 | (if (browse-url-maybe-new-window new-window) |
1abcd088 | 1507 | (compose-mail-other-window to subject rest nil |
5ad3e885 | 1508 | (list 'insert-buffer (current-buffer))) |
1abcd088 | 1509 | (compose-mail to subject rest nil nil |
5ad3e885 KY |
1510 | (list 'insert-buffer (current-buffer)))) |
1511 | (when body | |
1512 | (goto-char (point-min)) | |
1513 | (unless (or (search-forward (concat "\n" mail-header-separator "\n") | |
1514 | nil 'move) | |
1515 | (bolp)) | |
1516 | (insert "\n")) | |
1517 | (goto-char (prog1 | |
1518 | (point) | |
1519 | (insert (replace-regexp-in-string "\r\n" "\n" body)) | |
1520 | (unless (bolp) | |
1521 | (insert "\n")))))))) | |
8749abea GM |
1522 | |
1523 | ;; --- Random browser --- | |
1524 | ||
1525 | ;;;###autoload | |
1526 | (defun browse-url-generic (url &optional new-window) | |
1527 | ;; new-window ignored | |
1528 | "Ask the WWW browser defined by `browse-url-generic-program' to load URL. | |
1529 | Default to the URL around or before point. A fresh copy of the | |
1530 | browser is started up in a new process with possible additional arguments | |
1531 | `browse-url-generic-args'. This is appropriate for browsers which | |
1532 | don't offer a form of remote control." | |
1533 | (interactive (browse-url-interactive-arg "URL: ")) | |
1534 | (if (not browse-url-generic-program) | |
6eddc3bb | 1535 | (error "No browser defined (`browse-url-generic-program')")) |
78cfc6ad DK |
1536 | (apply 'call-process browse-url-generic-program nil |
1537 | 0 nil | |
8749abea GM |
1538 | (append browse-url-generic-args (list url)))) |
1539 | ||
af06f459 GM |
1540 | ;;;###autoload |
1541 | (defun browse-url-kde (url &optional new-window) | |
1542 | "Ask the KDE WWW browser to load URL. | |
1543 | Default to the URL around or before point." | |
1544 | (interactive (browse-url-interactive-arg "KDE URL: ")) | |
1545 | (message "Sending URL to KDE...") | |
662871dd | 1546 | (apply #'start-process (concat "KDE " url) nil browse-url-kde-program |
6eddc3bb | 1547 | (append browse-url-kde-args (list url)))) |
af06f459 | 1548 | |
a38de16e MC |
1549 | (defun browse-url-elinks-new-window (url) |
1550 | "Ask the Elinks WWW browser to load URL in a new window." | |
db6003fb | 1551 | (let ((process-environment (browse-url-process-environment))) |
a38de16e MC |
1552 | (apply #'start-process |
1553 | (append (list (concat "elinks:" url) | |
1554 | nil) | |
1555 | browse-url-elinks-wrapper | |
1556 | (list "elinks" url))))) | |
1557 | ||
8c22c51a | 1558 | ;;;###autoload |
a38de16e | 1559 | (defun browse-url-elinks (url &optional new-window) |
8c22c51a GM |
1560 | "Ask the Elinks WWW browser to load URL. |
1561 | Default to the URL around the point. | |
1562 | ||
1563 | The document is loaded in a new tab of a running Elinks or, if | |
1564 | none yet running, a newly started instance. | |
1565 | ||
1566 | The Elinks command will be prepended by the program+arguments | |
a38de16e | 1567 | from `browse-url-elinks-wrapper'." |
8c22c51a GM |
1568 | (interactive (browse-url-interactive-arg "URL: ")) |
1569 | (setq url (browse-url-encode-url url)) | |
a38de16e MC |
1570 | (if new-window |
1571 | (browse-url-elinks-new-window url) | |
1572 | (let ((process-environment (browse-url-process-environment)) | |
1573 | (elinks-ping-process (start-process "elinks-ping" nil | |
1574 | "elinks" "-remote" "ping()"))) | |
1575 | (set-process-sentinel elinks-ping-process | |
1576 | `(lambda (process change) | |
1577 | (browse-url-elinks-sentinel process ,url)))))) | |
8c22c51a GM |
1578 | |
1579 | (defun browse-url-elinks-sentinel (process url) | |
1580 | "Determines if Elinks is running or a new one has to be started." | |
a38de16e | 1581 | (let ((exit-status (process-exit-status process))) |
8c22c51a GM |
1582 | ;; Try to determine if an instance is running or if we have to |
1583 | ;; create a new one. | |
1584 | (case exit-status | |
6eddc3bb MC |
1585 | (5 |
1586 | ;; No instance, start a new one. | |
a38de16e | 1587 | (browse-url-elinks-new-window url)) |
6eddc3bb MC |
1588 | (0 |
1589 | ;; Found an instance, open URL in new tab. | |
a38de16e MC |
1590 | (let ((process-environment (browse-url-process-environment))) |
1591 | (start-process (concat "elinks:" url) nil | |
1592 | "elinks" "-remote" | |
1593 | (concat "openURL(\"" url "\",new-tab)")))) | |
6eddc3bb | 1594 | (otherwise |
a38de16e MC |
1595 | (error "Unrecognized exit-code %d of process `elinks'" |
1596 | exit-status))))) | |
8c22c51a | 1597 | |
8749abea GM |
1598 | (provide 'browse-url) |
1599 | ||
1600 | ;;; browse-url.el ends here |