(tibetan-pre-write-conversion): Cancel previous
[bpt/emacs.git] / lisp / browse-url.el
CommitLineData
5db57514 1;;; browse-url.el --- Pass a URL to a WWW browser
b578f267 2
a43d1a2a 3;; Copyright 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
a69315a1
RS
4
5;; Author: Denis Howe <dbh@doc.ic.ac.uk>
a43d1a2a 6;; Maintainer: Dave Love <fx@gnu.org>
a69315a1 7;; Created: 03 Apr 1995
5db57514 8;; Keywords: hypertext, hypermedia, mouse
a69315a1
RS
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
b578f267
EN
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
a69315a1 16
b578f267
EN
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
a69315a1
RS
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to the
b578f267
EN
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
a69315a1 26
a69315a1
RS
27;;; Commentary:
28
a69315a1
RS
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
35;; is started. Currently there is support for:
36
37;; Function Browser Earliest version
a43d1a2a 38;; browse-url-netscape Netscape 1.1b1
837984b1 39;; browse-url-mosaic XMosaic/mMosaic <= 2.4
a69315a1
RS
40;; browse-url-cci XMosaic 2.5
41;; browse-url-w3 w3 0
5db57514 42;; browse-url-w3-gnudoit w3 remotely
a69315a1 43;; browse-url-iximosaic IXI Mosaic ?
96adeb99
RS
44;; browse-url-lynx-* Lynx 0
45;; browse-url-grail Grail 0.3b1
5db57514
RS
46;; browse-url-mmm MMM ?
47;; browse-url-generic arbitrary
a69315a1 48
9d843bef
DL
49;; [The Netscape browser is now free software
50;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is
51;; reasonable to keep it as the default.]
52
a69315a1 53;; Note that versions of Netscape before 1.1b1 did not have remote
5db57514 54;; control. <URL:http://www.netscape.com/newsref/std/x-remote.html>.
a69315a1 55
9d843bef 56;; Browsers can cache Web pages so it may be necessary to tell them to
96adeb99 57;; reload the current page if it has changed (e.g. if you have edited
a69315a1
RS
58;; it). There is currently no perfect automatic solution to this.
59
60;; Netscape allows you to specify the id of the window you want to
61;; control but which window DO you want to control and how do you
62;; discover its id?
63
64;; If using XMosaic before version 2.5, check the definition of
65;; browse-url-usr1-signal below.
66;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html>
67
68;; XMosaic version 2.5 introduced Common Client Interface allowing you
69;; to control mosaic through Unix sockets.
70;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/CCI/cci-spec.html>
71
72;; William M. Perry's excellent "w3" WWW browser for
73;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
74;; has a function w3-follow-url-at-point, but that
75;; doesn't let you edit the URL like browse-url.
5db57514
RS
76;; The `gnuserv' package that can be used to control it in another
77;; Emacs process is available from
a43d1a2a 78;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>.
5db57514
RS
79
80;; Grail is the freely available WWW browser implemented in Python, a
81;; cool object-oriented freely available interpreted language. Grail
82;; 0.3b1 was the first version to have remote control as distributed.
83;; For more information on Grail see
84;; <URL:http://grail.cnri.reston.va.us/> and for more information on
85;; Python see <url:http://www.python.org/>. Grail support in
86;; browse-url.el written by Barry Warsaw <bwarsaw@python.org>.
87
a43d1a2a
DL
88;; MMM is the freely available WWW browser implemented in Objective
89;; Caml, a cool impure functional programming language, by Francois
5db57514
RS
90;; Rouaix. See the MMM home page
91;; <URL:http://pauillac.inria.fr/%7Erouaix/mmm/>.
92
93;; Lynx is now distributed by the FSF. See also
94;; <URL:http://lynx.browser.org/>.
95
96;; Free graphical browsers that could be used by `browse-url-generic'
bc6d0d71
RS
97;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera> and
98;; <URL:http://www.unlv.edu/chimera/>, Arena
837984b1
DL
99;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena> and Amaya
100;; <URL:ftp://ftp.w3.org/pub/amaya>. mMosaic
101;; <URL:ftp://sig.enst.fr/pub/multicast/mMosaic/> (with development
102;; support for Java applets and multicast) can be used like Mosaic by
103;; setting `browse-url-mosaic-program' appropriately.
a69315a1 104
9d843bef
DL
105;; I [Denis Howe, not Dave Love] recommend Nelson Minar
106;; <nelson@santafe.edu>'s excellent html-helper-mode.el for editing
107;; HTML and thank Nelson for his many useful comments on this code.
5db57514 108;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/>
a69315a1 109
59966fb6
RS
110;; See also hm--html-menus <URL:http://www.tnt.uni-hannover.de/%7Emuenkel/
111;; software/own/hm--html-menus/>. For composing correct HTML see also
112;; PSGML the general SGML structure editor package
113;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used
114;; with this.
115
a69315a1 116;; This package generalises function html-previewer-process in Marc
a43d1a2a
DL
117;; Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the
118;; ffap.el package. The huge hyperbole package also contains similar
119;; functions.
a69315a1
RS
120
121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122;; Help!
123
124;; Can you write and test some code for the Macintrash and Windoze
125;; Netscape remote control APIs? (See the URL above).
126
127;; Do any other browsers have remote control?
128
a69315a1
RS
129;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
130;; Usage
131
132;; To display the URL at or before point:
133;; M-x browse-url-at-point RET
5db57514
RS
134;; or, similarly but with the opportunity to edit the URL extracted from
135;; the buffer, use:
136;; M-x browse-url
a69315a1
RS
137
138;; To display a URL by shift-clicking on it, put this in your ~/.emacs
139;; file:
a5f6b207
RS
140;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)
141;; (Note that using Shift-mouse-1 is not desirable because
142;; that event has a standard meaning in Emacs.)
a69315a1
RS
143
144;; To display the current buffer in a web browser:
145;; M-x browse-url-of-buffer RET
146
5db57514
RS
147;; To display the current region in a web browser:
148;; M-x browse-url-of-region RET
149
a69315a1
RS
150;; In Dired, to display the file named on the current line:
151;; M-x browse-url-of-dired-file RET
152
153;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154;; Customisation (~/.emacs)
155
96adeb99 156;; To see what variables are available for customization, type
09d8b0bc
DL
157;; `M-x set-variable browse-url TAB'. Better, use
158;; `M-x customize-group browse-url'.
a69315a1 159
96adeb99
RS
160;; Bind the browse-url commands to keys with the `C-c C-z' prefix
161;; (as used by html-helper-mode):
162;; (global-set-key "\C-c\C-z." 'browse-url-at-point)
163;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer)
5db57514 164;; (global-set-key "\C-c\C-zr" 'browse-url-of-region)
96adeb99
RS
165;; (global-set-key "\C-c\C-zu" 'browse-url)
166;; (global-set-key "\C-c\C-zv" 'browse-url-of-file)
5db57514 167;; (add-hook 'dired-mode-hook
e49172c8
DL
168;; (lambda ()
169;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file)))
96adeb99
RS
170
171;; Browse URLs in mail messages by clicking mouse-2:
e49172c8
DL
172;; (add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup
173;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse)))
96adeb99
RS
174
175;; Browse URLs in Usenet messages by clicking mouse-2:
176;; (eval-after-load "gnus"
177;; '(define-key gnus-article-mode-map [mouse-2] 'browse-url-at-mouse))
59966fb6
RS
178;; [The current version of Gnus provides a standard feature to
179;; activate URLs in article buffers for invocation of browse-url with
180;; mouse-2.]
96adeb99
RS
181
182;; Use the Emacs w3 browser when not running under X11:
183;; (or (eq window-system 'x)
5db57514 184;; (setq browse-url-browser-function 'browse-url-w3))
a69315a1
RS
185
186;; To always save modified buffers before displaying the file in a browser:
5db57514 187;; (setq browse-url-save-file t)
a69315a1 188
96adeb99
RS
189;; To get round the Netscape caching problem, you could EITHER have
190;; write-file in html-helper-mode make Netscape reload the document:
a69315a1 191;;
5db57514
RS
192;; (autoload 'browse-url-netscape-reload "browse-url"
193;; "Ask a WWW browser to redisplay the current file." t)
194;; (add-hook 'html-helper-mode-hook
e49172c8 195;; (lambda ()
5db57514 196;; (add-hook 'local-write-file-hooks
e49172c8 197;; (lambda ()
5db57514
RS
198;; (let ((local-write-file-hooks))
199;; (save-buffer))
200;; (browse-url-netscape-reload)
e49172c8
DL
201;; t) ; => file written by hook
202;; t))) ; append to l-w-f-hooks
a69315a1 203;;
96adeb99 204;; OR have browse-url-of-file ask Netscape to load and then reload the
a69315a1
RS
205;; file:
206;;
5db57514 207;; (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload)
a69315a1 208
96adeb99 209;; You may also want to customise browse-url-netscape-arguments, e.g.
5db57514 210;; (setq browse-url-netscape-arguments '("-install"))
a69315a1 211;;
5db57514 212;; or similarly for the other browsers.
a69315a1 213
5db57514
RS
214;; To invoke different browsers for different URLs:
215;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
216;; ("." . browse-url-netscape)))
a69315a1
RS
217
218;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219;;; Code:
220
5db57514
RS
221;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222;; Variables
a69315a1 223
380a0a12 224(eval-when-compile (require 'thingatpt)
a43d1a2a
DL
225 (require 'term))
226
0a3fc8a2
RS
227(defgroup browse-url nil
228 "Use a web browser to look at a URL."
09d8b0bc 229 :prefix "browse-url-"
f6680f0b 230 :group 'hypermedia)
96adeb99
RS
231
232;;;###autoload
0a3fc8a2 233(defcustom browse-url-browser-function
96adeb99 234 'browse-url-netscape
a69315a1 235 "*Function to display the current buffer in a WWW browser.
0a3fc8a2 236This is used by the `browse-url-at-point', `browse-url-at-mouse', and
1341d237 237`browse-url-of-file' commands.
5db57514
RS
238
239If the value is not a function it should be a list of pairs
a43d1a2a 240(REGEXP . FUNCTION). In this case the function called will be the one
5db57514
RS
241associated with the first REGEXP which matches the current URL. The
242function is passed the URL and any other args of `browse-url'. The last
243regexp should probably be \".\" to specify a default browser."
e49172c8
DL
244 :type '(choice
245 (function-item :tag "Emacs W3" :value browse-url-w3)
246 (function-item :tag "W3 in another Emacs via `gnudoit'"
247 :value browse-url-w3-gnudoit)
248 (function-item :tag "Netscape" :value browse-url-netscape)
249 (function-item :tag "Mosaic" :value browse-url-mosaic)
250 (function-item :tag "Mosaic using CCI" :value browse-url-cci)
251 (function-item :tag "IXI Mosaic" :value browse-url-iximosaic)
252 (function-item :tag "Lynx in an xterm window"
253 :value browse-url-lynx-xterm)
254 (function-item :tag "Lynx in an Emacs window"
255 :value browse-url-lynx-emacs)
256 (function-item :tag "Grail" :value browse-url-grail)
257 (function-item :tag "MMM" :value browse-url-mmm)
258 (function-item :tag "Specified by `Browse Url Generic Program'"
259 :value browse-url-generic)
260 (function :tag "Your own function"))
0a3fc8a2
RS
261 :group 'browse-url)
262
263(defcustom browse-url-netscape-program "netscape"
ac999fb9 264 ;; Info about netscape-remote from Kurt Swanson in gnu.emacs.gnus
a43d1a2a 265 "The name by which to invoke Netscape.
ac999fb9
DL
266
267It is said that source is available for a program `netscape-remote'
268which starts up very much quicker than `netscape' and that it is
269useful to set this variable to the name of a script which invokes that
270program like:
271 #!/bin/sh
272 /usr/local/bin/netscape-remote \"$@\" > /dev/null 2>&1
273"
0a3fc8a2
RS
274 :type 'string
275 :group 'browse-url)
276
277(defcustom browse-url-netscape-arguments nil
a43d1a2a 278 "A list of strings to pass to Netscape as arguments."
0a3fc8a2
RS
279 :type '(repeat (string :tag "Argument"))
280 :group 'browse-url)
281
282(defcustom browse-url-netscape-startup-arguments browse-url-netscape-arguments
a43d1a2a 283 "A list of strings to pass to Netscape when it starts up.
0a3fc8a2 284Defaults to the value of `browse-url-netscape-arguments' at the time
5db57514 285`browse-url' is loaded."
0a3fc8a2
RS
286 :type '(repeat (string :tag "Argument"))
287 :group 'browse-url)
96adeb99 288
a43d1a2a 289;;;###autoload
0a3fc8a2 290(defcustom browse-url-new-window-p nil
e49172c8
DL
291 "*If non-nil, always open a new browser window with appropriate browsers.
292Passing an interactive argument to \\[browse-url], or specific browser
293commands reverses the effect of this variable. Requires Netscape version
2941.1N or later or XMosaic version 2.5 or later if using those browsers."
0a3fc8a2
RS
295 :type 'boolean
296 :group 'browse-url)
297
a43d1a2a 298;;;###autoload
5db57514 299(defcustom browse-url-netscape-display nil
837984b1 300 "*The X display for running Netscape, if not same as Emacs'."
e49172c8 301 :type '(choice string (const :tag "Default" nil))
5db57514
RS
302 :group 'browse-url)
303
837984b1 304(defcustom browse-url-mosaic-program "xmosaic"
a43d1a2a 305 "The name by which to invoke Mosaic (or mMosaic)."
837984b1 306 :type 'string
a43d1a2a 307 :version "20.3"
837984b1
DL
308 :group 'browse-url)
309
0a3fc8a2 310(defcustom browse-url-mosaic-arguments nil
a43d1a2a 311 "A list of strings to pass to Mosaic as arguments."
0a3fc8a2
RS
312 :type '(repeat (string :tag "Argument"))
313 :group 'browse-url)
a69315a1 314
09d8b0bc 315(defcustom browse-url-filename-alist
ac999fb9
DL
316 '(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/")
317 ;; The above loses the username to avoid the browser prompting for
318 ;; it in anonymous cases. If it's not anonymous the next regexp
319 ;; applies.
320 ("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/")
321 ("^/+" . "file:/"))
a43d1a2a 322 "An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'.
a69315a1 323Any substring of a filename matching one of the REGEXPs is replaced by
ac999fb9
DL
324the corresponding STRING using `replace-match', not treating STRING
325literally. All pairs are applied in the order given. The default
326value converts ange-ftp/EFS-style paths into ftp URLs and prepends
327`file:' to any path beginning with `/'.
5db57514 328
ac999fb9
DL
329For example, adding to the default a specific translation of an ange-ftp
330address to an HTTP URL:
5db57514
RS
331
332 (setq browse-url-filename-alist
333 '((\"/webmaster@webserver:/home/www/html/\" .
334 \"http://www.acme.co.uk/\")
ac999fb9
DL
335 (\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\")
336 (\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\")
5db57514 337 (\"^/+\" . \"file:/\")))
09d8b0bc
DL
338"
339 :type '(repeat (cons :format "%v"
e49172c8 340 (regexp :tag "Regexp")
09d8b0bc 341 (string :tag "Replacement")))
ac999fb9 342 :version "20.3"
09d8b0bc 343 :group 'browse-url)
a69315a1 344
a43d1a2a 345;;;###autoload
09d8b0bc
DL
346(defcustom browse-url-save-file nil
347 "*If non-nil, save the buffer before displaying its file.
348Used by the `browse-url-of-file' command."
349 :type 'boolean
350 :group 'browse-url)
a69315a1 351
09d8b0bc 352(defcustom browse-url-of-file-hook nil
a43d1a2a 353 "Run after `browse-url-of-file' has asked a browser to load a file.
a69315a1
RS
354
355Set this to `browse-url-netscape-reload' to force Netscape to load the
09d8b0bc
DL
356file rather than displaying a cached copy."
357 :type 'hook
a43d1a2a 358 :options '(browse-url-netscape-reload)
09d8b0bc 359 :group 'browse-url)
a69315a1
RS
360
361(defvar browse-url-usr1-signal
362 (if (and (boundp 'emacs-major-version)
5db57514 363 (or (> emacs-major-version 19) (>= emacs-minor-version 29)))
96adeb99 364 'SIGUSR1 ; Why did I think this was in lower case before?
5db57514 365 30) ; Check /usr/include/signal.h.
a69315a1 366 "The argument to `signal-process' for sending SIGUSR1 to XMosaic.
00232ce3 367Emacs 19.29 accepts 'SIGUSR1, earlier versions require an integer
a69315a1
RS
368which is 30 on SunOS and 16 on HP-UX and Solaris.")
369
09d8b0bc 370(defcustom browse-url-CCI-port 3003
a43d1a2a 371 "Port to access XMosaic via CCI.
a69315a1 372This can be any number between 1024 and 65535 but must correspond to
09d8b0bc
DL
373the value set in the browser."
374 :type 'integer
375 :group 'browse-url)
a69315a1 376
09d8b0bc 377(defcustom browse-url-CCI-host "localhost"
96adeb99
RS
378 "*Host to access XMosaic via CCI.
379This should be the host name of the machine running XMosaic with CCI
09d8b0bc
DL
380enabled. The port number should be set in `browse-url-CCI-port'."
381 :type 'string
382 :group 'browse-url)
96adeb99
RS
383
384(defvar browse-url-temp-file-name nil)
385(make-variable-buffer-local 'browse-url-temp-file-name)
386
5db57514 387(defcustom browse-url-xterm-program "xterm"
a43d1a2a 388 "The name of the terminal emulator used by `browse-url-lynx-xterm'.
5db57514
RS
389This might, for instance, be a separate colour version of xterm."
390 :type 'string
391 :group 'browse-url)
392
393(defcustom browse-url-xterm-args nil
394 "*A list of strings defining options for `browse-url-xterm-program'.
395These might set its size, for instance."
396 :type '(repeat (string :tag "Argument"))
397 :group 'browse-url)
398
a43d1a2a
DL
399(defcustom browse-url-lynx-emacs-args (and (not window-system)
400 '("-show_cursor"))
401 "A list of strings defining options for Lynx in an Emacs buffer.
402
403The default is none in a window system, otherwise `-show_cursor' to
404indicate the position of the current link in the absence of
405highlighting, assuming the normal default for showing the cursor."
406 :type '(repeat (string :tag "Argument"))
407 :version "20.3"
408 :group 'browse-url)
409
5db57514 410(defcustom browse-url-gnudoit-program "gnudoit"
a43d1a2a 411 "The name of the `gnudoit' program used by `browse-url-w3-gnudoit'."
5db57514
RS
412 :type 'string
413 :group 'browse-url)
414
415(defcustom browse-url-gnudoit-args '("-q")
416 "*A list of strings defining options for `browse-url-gnudoit-program'.
417These might set the port, for instance."
418 :type '(repeat (string :tag "Argument"))
419 :group 'browse-url)
420
a43d1a2a 421;;;###autoload
5db57514
RS
422(defcustom browse-url-generic-program nil
423 "*The name of the browser program used by `browse-url-generic'."
e49172c8 424 :type '(choice string (const :tag "None" nil))
5db57514
RS
425 :group 'browse-url)
426
427(defcustom browse-url-generic-args nil
428 "*A list of strings defining options for `browse-url-generic-program'."
429 :type '(repeat (string :tag "Argument"))
430 :group 'browse-url)
431
406757ff 432(defcustom browse-url-temp-dir temporary-file-directory
a43d1a2a 433 "The name of a directory for browse-url's temporary files.
837984b1
DL
434Such files are generated by functions like `browse-url-of-region'.
435You might want to set this to somewhere with restricted read permissions
436for privacy's sake."
bc6d0d71
RS
437 :type 'string
438 :group 'browse-url)
439
f6680f0b
RS
440(defcustom browse-url-netscape-version
441 3
a43d1a2a 442 "The version of Netscape you are using.
f6680f0b
RS
443This affects how URL reloading is done; the mechanism changed
444incompatibly at version 4."
445 :type 'number
446 :group 'browse-url)
447
09d8b0bc 448(defcustom browse-url-lynx-input-field 'avoid
837984b1
DL
449 "*Action on selecting an existing Lynx buffer at an input field.
450What to do when sending a new URL to an existing Lynx buffer in Emacs
451if the Lynx cursor is on an input field (in which case the `g' command
452would be entered as data). Such fields are recognized by the
453underlines ____. Allowed values: nil: disregard it, 'warn: warn the
454user and don't emit the URL, 'avoid: try to avoid the field by moving
09d8b0bc
DL
455down (this *won't* always work)."
456 :type '(choice (const :tag "Move to try to avoid field" :value avoid)
457 (const :tag "Disregard" :value nil)
458 (const :tag "Warn, don't emit URL" :value warn))
a43d1a2a 459 :version "20.3"
09d8b0bc 460 :group 'browse-url)
837984b1 461
380a0a12
DL
462(defvar browse-url-lynx-input-attempts 10
463 "*How many times to try to move down from a series of lynx input fields.")
837984b1 464
09d8b0bc 465(defcustom browse-url-lynx-input-delay 0.2
380a0a12 466 "How many seconds to wait for lynx between moves down from an input field.")
837984b1 467
96adeb99
RS
468(defvar browse-url-temp-file-list '())
469
a69315a1
RS
470;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
471;; URL input
472
a69315a1 473(defun browse-url-url-at-point ()
6debdec5
RS
474 (let ((url (thing-at-point 'url)))
475 (set-text-properties 0 (length url) nil url)
5db57514
RS
476 url))
477
96adeb99
RS
478;; Having this as a separate function called by the browser-specific
479;; functions allows them to be stand-alone commands, making it easier
480;; to switch between browsers.
481
482(defun browse-url-interactive-arg (prompt)
483 "Read a URL from the minibuffer, prompting with PROMPT.
bc6d0d71 484Default to the URL at or before point. If invoked with a mouse button,
96adeb99 485set point to the position clicked first. Return a list for use in
5db57514 486`interactive' containing the URL and `browse-url-new-window-p' or its
96adeb99 487negation if a prefix argument was given."
a69315a1
RS
488 (let ((event (elt (this-command-keys) 0)))
489 (and (listp event) (mouse-set-point event)))
96adeb99
RS
490 (list (read-string prompt (browse-url-url-at-point))
491 (not (eq (null browse-url-new-window-p)
492 (null current-prefix-arg)))))
a69315a1 493
837984b1
DL
494(defun browse-url-maybe-new-window (arg)
495 (if (interactive-p)
496 arg
497 browse-url-new-window-p))
498
a69315a1
RS
499;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
500;; Browse current buffer
501
8941c0cf 502;;;###autoload
a69315a1
RS
503(defun browse-url-of-file (&optional file)
504 "Ask a WWW browser to display FILE.
505Display the current buffer's file if FILE is nil or if called
96adeb99 506interactively. Turn the filename into a URL with function
5db57514
RS
507`browse-url-file-url'. Pass the URL to a browser using the
508`browse-url' function then run `browse-url-of-file-hook'."
a69315a1 509 (interactive)
5db57514 510 (or file
96adeb99
RS
511 (setq file (buffer-file-name))
512 (error "Current buffer has no file"))
a69315a1
RS
513 (let ((buf (get-file-buffer file)))
514 (if buf
5db57514
RS
515 (save-excursion
516 (set-buffer buf)
517 (cond ((not (buffer-modified-p)))
518 (browse-url-save-file (save-buffer))
519 (t (message "%s modified since last save" file))))))
520 (browse-url (browse-url-file-url file))
a69315a1
RS
521 (run-hooks 'browse-url-of-file-hook))
522
523(defun browse-url-file-url (file)
524 "Return the URL corresponding to FILE.
ac999fb9 525Use variable `browse-url-filename-alist' to map filenames to URLs."
96adeb99
RS
526 ;; URL-encode special chars, do % first
527 (let ((s 0))
528 (while (setq s (string-match "%" file s))
529 (setq file (replace-match "%25" t t file)
530 s (1+ s))))
531 (while (string-match "[*\"()',=;? ]" file)
532 (let ((enc (format "%%%x" (aref file (match-beginning 0)))))
533 (setq file (replace-match enc t t file))))
a69315a1
RS
534 (let ((maps browse-url-filename-alist))
535 (while maps
536 (let* ((map (car maps))
5db57514
RS
537 (from-re (car map))
538 (to-string (cdr map)))
539 (setq maps (cdr maps))
96adeb99 540 (and (string-match from-re file)
ac999fb9 541 (setq file (replace-match to-string t nil file))))))
a69315a1
RS
542 file)
543
8941c0cf 544;;;###autoload
a69315a1
RS
545(defun browse-url-of-buffer (&optional buffer)
546 "Ask a WWW browser to display BUFFER.
5db57514
RS
547Display the current buffer if BUFFER is nil. Display only the
548currently visible part of BUFFER (from a temporary file) if buffer is
549narrowed."
a69315a1
RS
550 (interactive)
551 (save-excursion
96adeb99 552 (and buffer (set-buffer buffer))
a69315a1 553 (let ((file-name
5db57514
RS
554 ;; Ignore real name if restricted
555 (and (= (- (point-max) (point-min)) (buffer-size))
556 (or buffer-file-name
557 (and (boundp 'dired-directory) dired-directory)))))
96adeb99 558 (or file-name
5db57514 559 (progn
96adeb99 560 (or browse-url-temp-file-name
5db57514 561 (setq browse-url-temp-file-name
bc6d0d71
RS
562 (convert-standard-filename
563 (make-temp-name
564 (expand-file-name "burl" browse-url-temp-dir)))))
96adeb99
RS
565 (setq file-name browse-url-temp-file-name)
566 (write-region (point-min) (point-max) file-name nil 'no-message)))
567 (browse-url-of-file file-name))))
a69315a1
RS
568
569(defun browse-url-delete-temp-file (&optional temp-file-name)
570 ;; Delete browse-url-temp-file-name from the file system and from
571 ;; browse-url-temp-file-list. If optional arg TEMP-FILE-NAME is
572 ;; non-nil, delete it instead, but only from the file system --
573 ;; browse-url-temp-file-list is not affected.
574 (let ((file-name (or temp-file-name browse-url-temp-file-name)))
575 (if (and file-name (file-exists-p file-name))
5db57514
RS
576 (progn
577 (delete-file file-name)
578 (if (null temp-file-name)
579 (setq browse-url-temp-file-list
580 (delete browse-url-temp-file-name
581 browse-url-temp-file-list)))))))
a69315a1
RS
582
583(defun browse-url-delete-temp-file-list ()
584 ;; Delete all elements of browse-url-temp-file-list.
585 (while browse-url-temp-file-list
586 (browse-url-delete-temp-file (car browse-url-temp-file-list))
587 (setq browse-url-temp-file-list
5db57514 588 (cdr browse-url-temp-file-list))))
a69315a1
RS
589
590(add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
591(add-hook 'kill-emacs-hook 'browse-url-delete-temp-file-list)
592
8941c0cf 593;;;###autoload
a69315a1
RS
594(defun browse-url-of-dired-file ()
595 "In Dired, ask a WWW browser to display the file named on this line."
596 (interactive)
597 (browse-url-of-file (dired-get-filename)))
598
5db57514
RS
599;;;###autoload
600(defun browse-url-of-region (min max)
601 "Ask a WWW browser to display the current region."
602 (interactive "r")
603 (save-excursion
604 (save-restriction
f64905b5 605 (narrow-to-region min max)
5db57514
RS
606 (browse-url-of-buffer))))
607
a69315a1 608;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5db57514 609;; Browser-independent commands
96adeb99 610
5db57514 611;; A generic command to call the current browse-url-browser-function
96adeb99 612
5db57514 613;;;###autoload
a43d1a2a 614(defun browse-url (url &rest args)
96adeb99
RS
615 "Ask a WWW browser to load URL.
616Prompts for a URL, defaulting to the URL at or before point. Variable
617`browse-url-browser-function' says which browser to use."
618 (interactive (browse-url-interactive-arg "URL: "))
a43d1a2a
DL
619 (let ((bf browse-url-browser-function) re)
620 (while (consp bf)
621 (setq re (car (car bf))
622 bf (if (string-match re url)
623 (cdr (car bf)) ; The function
624 (cdr bf)))) ; More pairs
625 (or bf (error "No browser in browse-url-browser-function matching URL %s"
626 url))
627 (apply bf url args)))
96adeb99 628
8941c0cf 629;;;###autoload
96adeb99
RS
630(defun browse-url-at-point ()
631 "Ask a WWW browser to load the URL at or before point.
837984b1 632Doesn't let you edit the URL like `browse-url'. Variable
96adeb99
RS
633`browse-url-browser-function' says which browser to use."
634 (interactive)
5db57514 635 (browse-url (browse-url-url-at-point)))
96adeb99 636
78c11a9c
RS
637(defun browse-url-event-buffer (event)
638 (window-buffer (posn-window (event-start event))))
96adeb99 639
78c11a9c
RS
640(defun browse-url-event-point (event)
641 (posn-point (event-start event)))
96adeb99 642
8941c0cf 643;;;###autoload
96adeb99
RS
644(defun browse-url-at-mouse (event)
645 "Ask a WWW browser to load a URL clicked with the mouse.
646The URL is the one around or before the position of the mouse click
647but point is not changed. Doesn't let you edit the URL like
837984b1 648`browse-url'. Variable `browse-url-browser-function' says which browser
96adeb99
RS
649to use."
650 (interactive "e")
651 (save-excursion
78c11a9c
RS
652 (set-buffer (browse-url-event-buffer event))
653 (goto-char (browse-url-event-point event))
96adeb99
RS
654 (let ((url (browse-url-url-at-point)))
655 (if (string-equal url "")
656 (error "No URL found"))
837984b1 657 (browse-url url browse-url-new-window-p))))
96adeb99
RS
658
659;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
660;; Browser-specific commands
661
662;; --- Netscape ---
663
96adeb99 664(defun browse-url-process-environment ()
5db57514
RS
665 "Set DISPLAY in the environment to the X display Netscape is running on.
666This is either the value of variable `browse-url-netscape-display' if
667non-nil, or the same display as Emacs if different from the current
668environment, otherwise just use the current environment."
669 (let ((display (or browse-url-netscape-display (browse-url-emacs-display))))
96adeb99 670 (if display
5db57514 671 (cons (concat "DISPLAY=" display) process-environment)
96adeb99
RS
672 process-environment)))
673
5db57514
RS
674(defun browse-url-emacs-display ()
675 "Return the X display Emacs is running on.
837984b1 676This is nil if the display is the same as the DISPLAY environment variable.
5db57514 677
a43d1a2a
DL
678Actually Emacs could be using several displays; this just returns the
679one showing the selected frame."
680 (let ((display (cdr-safe (assq 'display (frame-parameters)))))
681 (and (not (equal display (getenv "DISPLAY")))
682 display)))
a69315a1 683
96adeb99 684;;;###autoload
a69315a1
RS
685(defun browse-url-netscape (url &optional new-window)
686 "Ask the Netscape WWW browser to load URL.
687
688Default to the URL around or before point. The strings in variable
689`browse-url-netscape-arguments' are also passed to Netscape.
690
691When called interactively, if variable `browse-url-new-window-p' is
692non-nil, load the document in a new Netscape window, otherwise use a
693random existing one. A non-nil interactive prefix argument reverses
5db57514 694the effect of `browse-url-new-window-p'.
a69315a1
RS
695
696When called non-interactively, optional second argument NEW-WINDOW is
5db57514 697used instead of `browse-url-new-window-p'."
96adeb99 698 (interactive (browse-url-interactive-arg "Netscape URL: "))
9d843bef
DL
699 ;; URL encode any `confusing' characters in the URL. This needs to
700 ;; include at least commas; presumably also close parens.
701 (while (string-match "[,)]" url)
702 (setq url (replace-match
ddff3d80 703 (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
96adeb99
RS
704 (let* ((process-environment (browse-url-process-environment))
705 (process (apply 'start-process
706 (concat "netscape " url) nil
6be23be6 707 browse-url-netscape-program
5db57514 708 (append browse-url-netscape-arguments
78557fbf 709 (if (eq window-system 'w32)
5db57514
RS
710 (list url)
711 (if new-window '("-noraise"))
a43d1a2a
DL
712 (list "-remote"
713 (concat "openURL(" url
837984b1
DL
714 (if (browse-url-maybe-new-window
715 new-window)
716 ",new-window")
5db57514 717 ")")))))))
96adeb99 718 (set-process-sentinel process
5db57514
RS
719 (list 'lambda '(process change)
720 (list 'browse-url-netscape-sentinel 'process url)))))
96adeb99
RS
721
722(defun browse-url-netscape-sentinel (process url)
723 "Handle a change to the process communicating with Netscape."
724 (or (eq (process-exit-status process) 0)
725 (let* ((process-environment (browse-url-process-environment)))
726 ;; Netscape not running - start it
5db57514 727 (message "Starting Netscape...")
96adeb99 728 (apply 'start-process (concat "netscape" url) nil
6be23be6 729 browse-url-netscape-program
96adeb99 730 (append browse-url-netscape-startup-arguments (list url))))))
a69315a1
RS
731
732(defun browse-url-netscape-reload ()
837984b1
DL
733 "Ask Netscape to reload its current document.
734How depends on `browse-url-netscape-version'."
a69315a1 735 (interactive)
f6680f0b
RS
736 ;; Backwards incompatibility reported by
737 ;; <peter.kruse@psychologie.uni-regensburg.de>.
738 (browse-url-netscape-send (if (>= browse-url-netscape-version 4)
739 "xfeDoCommand(reload)"
740 "reload")))
a69315a1 741
96adeb99 742(defun browse-url-netscape-send (command)
a69315a1 743 "Send a remote control command to Netscape."
96adeb99
RS
744 (let* ((process-environment (browse-url-process-environment)))
745 (apply 'start-process "netscape" nil
6be23be6 746 browse-url-netscape-program
5db57514 747 (append browse-url-netscape-arguments
96adeb99
RS
748 (list "-remote" command)))))
749
750;; --- Mosaic ---
a69315a1 751
96adeb99
RS
752;;;###autoload
753(defun browse-url-mosaic (url &optional new-window)
754 ;; new-window ignored
a69315a1 755 "Ask the XMosaic WWW browser to load URL.
837984b1
DL
756
757Default to the URL around or before point. The strings in variable
758`browse-url-mosaic-arguments' are also passed to Mosaic and the
759program is invoked according to the variable
760`browse-url-mosaic-program'.
761
762When called interactively, if variable `browse-url-new-window-p' is
763non-nil, load the document in a new Mosaic window, otherwise use a
764random existing one. A non-nil interactive prefix argument reverses
765the effect of `browse-url-new-window-p'.
766
767When called non-interactively, optional second argument NEW-WINDOW is
768used instead of `browse-url-new-window-p'."
a69315a1
RS
769 (interactive (browse-url-interactive-arg "Mosaic URL: "))
770 (let ((pidfile (expand-file-name "~/.mosaicpid"))
380a0a12 771 pid)
a69315a1 772 (if (file-readable-p pidfile)
5db57514
RS
773 (save-excursion
774 (find-file pidfile)
775 (goto-char (point-min))
776 (setq pid (read (current-buffer)))
777 (kill-buffer nil)))
a69315a1 778 (if (and pid (zerop (signal-process pid 0))) ; Mosaic running
5db57514
RS
779 (save-excursion
780 (find-file (format "/tmp/Mosaic.%d" pid))
781 (erase-buffer)
837984b1
DL
782 (insert (if (browse-url-maybe-new-window new-window)
783 "newwin\n"
784 "goto\n")
785 url "\n")
5db57514
RS
786 (save-buffer)
787 (kill-buffer nil)
788 ;; Send signal SIGUSR to Mosaic
96adeb99 789 (message "Signalling Mosaic...")
5db57514
RS
790 (signal-process pid browse-url-usr1-signal)
791 ;; Or you could try:
792 ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
96adeb99 793 (message "Signalling Mosaic...done")
5db57514 794 )
a69315a1
RS
795 ;; Mosaic not running - start it
796 (message "Starting Mosaic...")
837984b1 797 (apply 'start-process "xmosaic" nil browse-url-mosaic-program
5db57514 798 (append browse-url-mosaic-arguments (list url)))
a5f6b207 799 (message "Starting Mosaic...done"))))
a69315a1 800
96adeb99
RS
801;; --- Grail ---
802
803;;;###autoload
804(defvar browse-url-grail
805 (concat (or (getenv "GRAILDIR") "~/.grail") "/user/rcgrail.py")
a43d1a2a 806 "Location of Grail remote control client script `rcgrail.py'.
96adeb99
RS
807Typically found in $GRAILDIR/rcgrail.py, or ~/.grail/user/rcgrail.py.")
808
809;;;###autoload
5db57514 810(defun browse-url-grail (url &optional new-window)
96adeb99
RS
811 "Ask the Grail WWW browser to load URL.
812Default to the URL around or before point. Runs the program in the
813variable `browse-url-grail'."
814 (interactive (browse-url-interactive-arg "Grail URL: "))
815 (message "Sending URL to Grail...")
816 (save-excursion
817 (set-buffer (get-buffer-create " *Shell Command Output*"))
818 (erase-buffer)
819 ;; don't worry about this failing.
380a0a12
DL
820 (if new-window
821 (call-process browse-url-grail nil 0 nil "-b" url)
822 (call-process browse-url-grail nil 0 nil url))
96adeb99
RS
823 (message "Sending URL to Grail... done")))
824
825;; --- Mosaic using CCI ---
826
380a0a12 827;;;###autoload
a69315a1
RS
828(defun browse-url-cci (url &optional new-window)
829 "Ask the XMosaic WWW browser to load URL.
830Default to the URL around or before point.
831
832This function only works for XMosaic version 2.5 or later. You must
833select `CCI' from XMosaic's File menu, set the CCI Port Address to the
834value of variable `browse-url-CCI-port', and enable `Accept requests'.
835
836When called interactively, if variable `browse-url-new-window-p' is
837non-nil, load the document in a new browser window, otherwise use a
838random existing one. A non-nil interactive prefix argument reverses
5db57514 839the effect of `browse-url-new-window-p'.
a69315a1
RS
840
841When called non-interactively, optional second argument NEW-WINDOW is
5db57514 842used instead of `browse-url-new-window-p'."
96adeb99 843 (interactive (browse-url-interactive-arg "Mosaic URL: "))
a69315a1 844 (open-network-stream "browse-url" " *browse-url*"
96adeb99 845 browse-url-CCI-host browse-url-CCI-port)
a69315a1
RS
846 ;; Todo: start browser if fails
847 (process-send-string "browse-url"
5db57514 848 (concat "get url (" url ") output "
837984b1
DL
849 (if (browse-url-maybe-new-window
850 new-window)
851 "new"
852 "current")
853 "\r\n"))
a69315a1
RS
854 (process-send-string "browse-url" "disconnect\r\n")
855 (delete-process "browse-url"))
856
96adeb99
RS
857;; --- IXI Mosaic ---
858
859;;;###autoload
860(defun browse-url-iximosaic (url &optional new-window)
861 ;; new-window ignored
a69315a1
RS
862 "Ask the IXIMosaic WWW browser to load URL.
863Default to the URL around or before point."
864 (interactive (browse-url-interactive-arg "IXI Mosaic URL: "))
865 (start-process "tellw3b" nil "tellw3b"
5db57514 866 "-service WWW_BROWSER ixi_showurl " url))
a69315a1 867
96adeb99
RS
868;; --- W3 ---
869
870;;;###autoload
871(defun browse-url-w3 (url &optional new-window)
a69315a1 872 "Ask the w3 WWW browser to load URL.
e49172c8
DL
873Default to the URL around or before point.
874
875When called interactively, if variable `browse-url-new-window-p' is
876non-nil, load the document in a new window. A non-nil interactive
877prefix argument reverses the effect of `browse-url-new-window-p'.
878
879When called non-interactively, optional second argument NEW-WINDOW is
880used instead of `browse-url-new-window-p'."
a69315a1 881 (interactive (browse-url-interactive-arg "W3 URL: "))
837984b1
DL
882 (if (browse-url-maybe-new-window new-window)
883 (w3-fetch-other-window)
884 (w3-fetch url)))
a69315a1 885
5db57514
RS
886;;;###autoload
887(defun browse-url-w3-gnudoit (url &optional new-window)
888 ;; new-window ignored
889 "Ask another Emacs running gnuserv to load the URL using the W3 browser.
890The `browse-url-gnudoit-program' program is used with options given by
891`browse-url-gnudoit-args'. Default to the URL around or before point."
892 (interactive (browse-url-interactive-arg "W3 URL: "))
893 (apply 'start-process (concat "gnudoit:" url) nil
894 browse-url-gnudoit-program
895 (append browse-url-gnudoit-args (list (concat "(w3-fetch \"" url "\")") "(raise-frame)"))))
896
96adeb99
RS
897;; --- Lynx in an xterm ---
898
899;;;###autoload
900(defun browse-url-lynx-xterm (url &optional new-window)
901 ;; new-window ignored
902 "Ask the Lynx WWW browser to load URL.
903Default to the URL around or before point. A new Lynx process is run
5db57514
RS
904in an Xterm window using the Xterm program named by `browse-url-xterm-program'
905with possible additional arguments `browse-url-xterm-args'."
96adeb99 906 (interactive (browse-url-interactive-arg "Lynx URL: "))
a43d1a2a
DL
907 (apply #'start-process `(,(concat "lynx" url) nil ,browse-url-xterm-program
908 ,@browse-url-xterm-args "-e" "lynx" ,url)))
96adeb99 909
96adeb99
RS
910;; --- Lynx in an Emacs "term" window ---
911
912;;;###autoload
837984b1 913(defun browse-url-lynx-emacs (url &optional new-buffer)
96adeb99 914 "Ask the Lynx WWW browser to load URL.
837984b1 915Default to the URL around or before point. With a prefix argument, run
e49172c8
DL
916a new Lynx process in a new buffer.
917
918When called interactively, if variable `browse-url-new-window-p' is
919non-nil, load the document in a new lynx in a new term window,
920otherwise use any existing one. A non-nil interactive prefix argument
921reverses the effect of `browse-url-new-window-p'.
922
923When called non-interactively, optional second argument NEW-WINDOW is
924used instead of `browse-url-new-window-p'."
96adeb99 925 (interactive (browse-url-interactive-arg "Lynx URL: "))
837984b1
DL
926 (let* ((system-uses-terminfo t) ; Lynx uses terminfo
927 ;; (term-term-name "vt100") ; ??
928 (buf (get-buffer "*lynx*"))
929 (proc (and buf (get-buffer-process buf)))
930 (n browse-url-lynx-input-attempts))
931 (if (and (browse-url-maybe-new-window new-buffer) buf)
932 ;; Rename away the OLD buffer. This isn't very polite, but
933 ;; term insists on working in a buffer named *lynx* and would
934 ;; choke on *lynx*<1>
935 (progn (set-buffer buf)
936 (rename-uniquely)))
937 (if (or (browse-url-maybe-new-window new-buffer)
938 (not buf)
939 (not proc)
940 (not (memq (process-status proc) '(run stop))))
941 ;; start a new lynx
a43d1a2a
DL
942 (progn
943 (setq buf
944 (apply #'make-term
945 `("lynx" "lynx" nil ,@browse-url-lynx-emacs-args ,url)))
946 (switch-to-buffer buf)
947 (term-char-mode)
948 (set-process-sentinel
949 (get-buffer-process buf)
950 ;; Don't leave around a dead one (especially because of its
951 ;; munged keymap.)
952 (lambda (process event)
953 (if (not (memq (process-status process) '(run stop)))
954 (let ((buf (process-buffer process)))
955 (if buf (kill-buffer buf)))))))
837984b1
DL
956 ;; send the url to lynx in the old buffer
957 (let ((win (get-buffer-window buf t)))
958 (if win
959 (select-window win)
960 (switch-to-buffer buf)))
961 (if (eq (following-char) ?_)
962 (cond ((eq browse-url-lynx-input-field 'warn)
963 (error "Please move out of the input field first."))
964 ((eq browse-url-lynx-input-field 'avoid)
965 (while (and (eq (following-char) ?_) (> n 0))
966 (term-send-down) ; down arrow
967 (sit-for browse-url-lynx-input-delay))
968 (if (eq (following-char) ?_)
969 (error "Cannot move out of the input field, sorry.")))))
970 (term-send-string proc (concat "g" ; goto
971 "\C-u" ; kill default url
972 url
973 "\r")))))
8bc9b4f1 974
5db57514
RS
975;; --- MMM ---
976
977;;;###autoload
978(defun browse-url-mmm (url &optional new-window)
979 "Ask the MMM WWW browser to load URL.
980Default to the URL around or before point."
981 (interactive (browse-url-interactive-arg "MMM URL: "))
982 (message "Sending URL to MMM...")
983 (save-excursion
984 (set-buffer (get-buffer-create " *Shell Command Output*"))
985 (erase-buffer)
986 ;; mmm_remote just SEGVs if the file isn't there...
987 (if (or (file-exists-p (expand-file-name "~/.mmm_remote"))
988 ;; location in v 0.4:
989 (file-exists-p (expand-file-name "~/.mmm/remote")))
990 (call-process "mmm_remote" nil 0 nil url)
991 (call-process "mmm" nil 0 nil "-external" url))
992 (message "Sending URL to MMM... done")))
993
994;; --- mailto ---
995
996;;;###autoload
59966fb6 997(defun browse-url-mail (url &optional new-window)
5db57514 998 "Open a new mail message buffer within Emacs.
59966fb6
RS
999Default to using the mailto: URL around or before point as the
1000recipient's address. Supplying a non-nil interactive prefix argument
1001will cause the mail to be composed in another window rather than the
e49172c8
DL
1002current one.
1003
1004When called interactively, if variable `browse-url-new-window-p' is
1005non-nil use `compose-mail-other-window', otherwise `compose-mail'. A
1006non-nil interactive prefix argument reverses the effect of
1007`browse-url-new-window-p'.
1008
1009When called non-interactively, optional second argument NEW-WINDOW is
1010used instead of `browse-url-new-window-p'."
5db57514
RS
1011 (interactive (browse-url-interactive-arg "Mailto URL: "))
1012 (save-excursion
837984b1 1013 (let ((func (if (browse-url-maybe-new-window new-window)
59966fb6
RS
1014 'compose-mail-other-window
1015 'compose-mail))
1016 (to (if (string-match "^mailto:" url)
5db57514 1017 (substring url 7)
59966fb6
RS
1018 url)))
1019 (apply func
1020 (list to nil nil nil nil nil (cons 'insert-buffer
1021 (current-buffer)))))))
5db57514
RS
1022
1023;; --- Random browser ---
1024
1025;;;###autoload
1026(defun browse-url-generic (url &optional new-window)
1027 ;; new-window ignored
1028 "Ask the WWW browser defined by `browse-url-generic-program' to load URL.
1029Default to the URL around or before point. A fresh copy of the
1030browser is started up in a new process with possible additional arguments
1031`browse-url-generic-args'. This is appropriate for browsers which
1032don't offer a form of remote control."
1033 (interactive (browse-url-interactive-arg "URL: "))
1034 (if (not browse-url-generic-program)
1035 (error "No browser defined (`browse-url-generic-program')"))
1036 (apply 'start-process (concat browse-url-generic-program url) nil
1037 browse-url-generic-program
1038 (append browse-url-generic-args (list url))))
1039
a69315a1
RS
1040(provide 'browse-url)
1041
1042;;; browse-url.el ends here