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