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