*** empty log message ***
[gnus] / lisp / browse-url.el
1 ;;; browse-url.el --- ask a WWW browser to load a URL
2
3 ;; Copyright 1995 Free Software Foundation, Inc.
4
5 ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
6 ;; Maintainer: Denis Howe <dbh@doc.ic.ac.uk>
7 ;; Created: 03 Apr 1995
8 ;; Version: 0.22 13 Sep 1995
9 ;; Keywords: hypertext
10 ;; X-Home page: http://wombat.doc.ic.ac.uk/
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published
16 ;; by the Free Software Foundation; either version 1, or (at your
17 ;; option) any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 ;; General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
26 ;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;;; Commentary:
30
31 ;; The latest version of this package should be available from
32 ;; <URL:http://wombat.doc.ic.ac.uk/emacs/browse-url.el>.
33
34 ;; This package provides functions which read a URL (Uniform Resource
35 ;; Locator) from the minibuffer, defaulting to the URL around point,
36 ;; and ask a World-Wide Web browser to load it.  It can also load the
37 ;; URL associated with the current buffer.  Different browsers use
38 ;; different methods of remote control so there is one function for
39 ;; each supported browser.  If the chosen browser is not running, it
40 ;; is started.  Currently there is support for:
41
42 ;; Function              Browser     Earliest version
43 ;; browse-url-netscape   Netscape    1.1b1         
44 ;; browse-url-mosaic     XMosaic     <= 2.4
45 ;; browse-url-cci        XMosaic     2.5
46 ;; browse-url-w3         w3          0
47 ;; browse-url-iximosaic  IXI Mosaic  ?
48
49 ;; Note that versions of Netscape before 1.1b1 did not have remote
50 ;; control.  <URL:http://home.netscape.com/newsref/std/x-remote.html>
51 ;; and <URL:http://home.netscape.com/info/APIs/>.
52
53 ;; Netscape can cache Web pages so it may be necessary to tell it to
54 ;; reload the current page if it has changed (eg. if you have edited
55 ;; it).  There is currently no perfect automatic solution to this.
56
57 ;; Netscape allows you to specify the id of the window you want to
58 ;; control but which window DO you want to control and how do you
59 ;; discover its id?
60
61 ;; If using XMosaic before version 2.5, check the definition of
62 ;; browse-url-usr1-signal below.
63 ;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html>
64
65 ;; XMosaic version 2.5 introduced Common Client Interface allowing you
66 ;; to control mosaic through Unix sockets.
67 ;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/CCI/cci-spec.html>
68
69
70 ;; William M. Perry's excellent "w3" WWW browser for
71 ;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
72 ;; has a function w3-follow-url-at-point, but that
73 ;; doesn't let you edit the URL like browse-url.
74
75 ;; I recommend Nelson Minar <nelson@santafe.edu>'s excellent
76 ;; html-helper-mode.el for editing HTML and thank Nelson for
77 ;; his many useful comments on this code.
78 ;; <URL:http://www.santafe.edu/~nelson/hhm-beta/>
79
80 ;; This package generalises function html-previewer-process in Marc
81 ;; Andreessen <marca@ncsa.uiuc.edu>'s html-mode (LCD
82 ;; modes/html-mode.el.Z) and provides better versions of the URL
83 ;; functions in Michelangelo Grigni <mic@cs.ucsd.edu>'s ffap.el
84 ;; (find-file-at-point) <URL:ftp://cs.ucsd.edu:/pub/mic/>.  The huge
85 ;; hyperbole package also contains similar functions.
86
87 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
88 ;; Help!
89
90 ;; Can you write and test some code for the Macintrash and Windoze
91 ;; Netscape remote control APIs?  (See the URL above).
92
93 ;; Do any other browsers have remote control?
94
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ;; Installation
97
98 ;; Put the following in your ~/.emacs file:
99 ;;
100 ;; (autoload 'browse-url-at-point "browse-url"
101 ;;   "Ask a WWW browser to load the URL at or before point." t)
102 ;; (autoload 'browse-url-at-mouse "browse-url"
103 ;;   "Ask a WWW browser to load a URL clicked with the mouse." t)
104 ;; (autoload 'browse-url-of-buffer "browse-url"
105 ;;   "Ask a WWW browser to display BUFFER." t)
106 ;; (autoload 'browse-url-of-file "browse-url"
107 ;;   "Ask a WWW browser to display FILE." t)
108 ;; (autoload 'browse-url-of-dired-file "browse-url"
109 ;;   "In Dired, ask a WWW browser to display the file named on this line." t)
110
111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;; Usage
113
114 ;; To display the URL at or before point:
115 ;; M-x browse-url-at-point RET
116
117 ;; To display a URL by shift-clicking on it, put this in your ~/.emacs
118 ;; file:
119 ;;      (global-set-key [S-mouse-1] 'browse-url-at-mouse)
120
121 ;; To display the current buffer in a web browser:
122 ;; M-x browse-url-of-buffer RET
123
124 ;; In Dired, to display the file named on the current line:
125 ;; M-x browse-url-of-dired-file RET
126
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128 ;; Customisation (~/.emacs)
129
130 ;; To see what variables are available for customization, type `M-x
131 ;; set-variable browse-url TAB'.
132
133 ;; To bind the browse-url commands to keys with the `C-c u' prefix:
134 ;;      (global-set-key "\C-cu." 'browse-url-at-point)
135 ;;      (global-set-key "\C-cub" 'browse-url-of-buffer)
136 ;;      (global-set-key "\C-cuf" 'browse-url-of-file)
137 ;;      (add-hook 'dired-mode-hook
138 ;;                (function (lambda ()
139 ;;                            (local-set-key "\C-cuf" 'browse-url-of-dired-file))))
140 ;;      (if (boundp 'browse-url-browser-function)
141 ;;          (global-set-key "\C-cuu" browse-url-browser-function)
142 ;;        (eval-after-load
143 ;;         "browse-url"
144 ;;         '(global-set-key "\C-cuu" browse-url-browser-function)))
145
146 ;; To use the Emacs w3 browser when not running under X11:
147 ;;      (if (not (eq window-system 'x))
148 ;;          (setq browse-url-browser-function 'browse-url-w3))
149
150 ;; To always save modified buffers before displaying the file in a browser:
151 ;;      (setq browse-url-save-file t)
152
153 ;; To get round the Netscape caching problem, you could try either of
154 ;; the following (but not both).  EITHER write-file in
155 ;; html-helper-mode makes Netscape reload document:
156 ;;
157 ;;      (autoload 'browse-url-netscape-reload "browse-url"
158 ;;        "Ask a WWW browser to redisplay the current file." t)
159 ;;      (add-hook 'html-helper-mode-hook
160 ;;                (function (lambda ()
161 ;;                   (add-hook 'local-write-file-hooks
162 ;;                             (function (lambda ()
163 ;;                                (let ((local-write-file-hooks))
164 ;;                                  (save-buffer))
165 ;;                                (browse-url-netscape-reload)
166 ;;                                t))                   ; => file written by hook
167 ;;                             t))))                    ; append to l-w-f-hooks
168 ;;
169 ;; [Does this work for html-mode too?]
170 ;;
171 ;; OR browse-url-of-file ask Netscape to load and then reload the
172 ;; file:
173 ;;
174 ;;      (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload)
175
176 ;; You may also want to customise browse-url-netscape-arguments, eg.
177 ;;
178 ;;      (setq browse-url-netscape-arguments '("-install"))
179 ;;
180 ;; or similarly for the other browsers. 
181
182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
183 ;;; Change Log:
184
185 ;; 0.00 03 Apr 1995 Denis Howe <dbh@doc.ic.ac.uk>
186 ;;      Created.
187
188 ;; 0.01 04 Apr 1995
189 ;;      All names start with "browse-url-".  Added provide.
190
191 ;; 0.02 05 Apr 1995
192 ;;      Save file at start of browse-url-of-file.
193 ;;      Use start-process instead of start-process-shell-command.
194
195 ;; 0.03 06 Apr 1995
196 ;;      Add browse-url-netscape-reload, browse-url-netscape-command.
197 ;;      browse-url-of-file save file option.
198
199 ;; 0.04 08 Apr 1995
200 ;;      b-u-file-url separate function.  Change b-u-filename-alist
201 ;;      default.
202
203 ;; 0.05 09 Apr 1995
204 ;;      Added b-u-of-file-hook.
205
206 ;; 0.06 11 Apr 1995
207 ;;      Improved .emacs suggestions and documentation.
208
209 ;; 0.07 13 Apr 1995
210 ;;      Added browse-url-interactive-arg optional prompt.
211
212 ;; 0.08 18 Apr 1995
213 ;;      Exclude final "." from browse-url-regexp.
214
215 ;; 0.09 21 Apr 1995
216 ;;      Added mouse-set-point to browse-url-interactive-arg.
217
218 ;; 0.10 24 Apr 1995
219 ;;      Added Mosaic signal sending variations.
220 ;;      Thanks Brian K Servis <servis@ecn.purdue.edu>.
221 ;;      Don't use xprop for Netscape.
222
223 ;; 0.11 25 Apr 1995
224 ;;      Fix reading of ~/.mosaicpid.  Thanks Dag.H.Wanvik@kvatro.no.
225
226 ;; 0.12 27 Apr 1995
227 ;;      Interactive prefix arg => URL *after* point.
228 ;;      Thanks Michelangelo Grigni <mic@cs.ucsd.edu>.
229 ;;      Added IXI Mosaic support.
230 ;;      Thanks David Karr <dkarr@nmo.gtegsc.com>.
231
232 ;; 0.13 28 Apr 1995
233 ;;      Exclude final [,;] from browse-url-regexp.
234
235 ;; 0.14 02 May 1995
236 ;;      Provide browser argument variables.
237
238 ;; 0.15 07 May 1995
239 ;;      More Netscape options.  Thanks Peter Arius
240 ;;      <arius@immd2.informatik.uni-erlangen.de>.
241
242 ;; 0.16 17 May 1995
243 ;;      Added browse-url-at-mouse.
244 ;;      Thanks Wayne Mesard <wmesard@sgi.com>
245
246 ;; 0.17 27 Jun 1995
247 ;;      Renamed browse-url-at-point to browse-url-url-at-point.
248 ;;      Added browse-url-at-point.
249 ;;      Thanks Jonathan Cano <cano@patch.tandem.com>.
250
251 ;; 0.18 16 Aug 1995
252 ;;      Fixed call to browse-url-url-at-point in browse-url-at-point.
253 ;;      Thanks Eric Ding <ericding@San-Jose.ate.slb.com>.
254
255 ;; 0.19 24 Aug 1995
256 ;;      Improved documentation.
257 ;;      Thanks Kevin Rodgers <kevin.rodgers@ihs.com>.
258
259 ;; 0.20 31 Aug 1995
260 ;;      browse-url-of-buffer to handle file-less buffers.
261 ;;      browse-url-of-dired-file browses current file in dired.
262 ;;      Thanks Kevin Rodgers <kevin.rodgers@ihs.com>.
263
264 ;; 0.21 09 Sep 1995
265 ;;      XMosaic CCI functions.
266 ;;      Thanks Marc Furrer <Marc.Furrer@di.epfl.ch>.
267
268 ;; 0.22 13 Sep 1995
269 ;;      Fixed new-window documentation and added to browse-url-cci.
270 ;;      Thanks Dilip Sequeira <djs@dcs.ed.ac.uk>.
271
272 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
273 ;;; Code:
274
275 (defvar browse-url-regexp
276   "\\(https?://\\|ftp://\\|gopher://\\|telnet://\\|wais://\\|file:/\\|s?news:\\|mailto:\\)[^]\t\n \"'()<>[^`{}]*[^]\t\n \"'()<>[^`{}.,;]+"
277   "A regular expression probably matching a URL.")
278
279 (defvar browse-url-browser-function
280   'browse-url-netscape
281   "*Function to display the current buffer in a WWW browser.
282 Used by the `browse-url-at-point', `browse-url-at-mouse', and
283 `browse-url-of-file' commands.")
284
285 (defvar browse-url-netscape-arguments nil
286   "*A list of strings to pass to Netscape as arguments.")
287
288 (defvar browse-url-new-window-p nil
289   "*If non-nil, always open a new browser window.
290 Passing an interactive argument to \\[browse-url-netscape] or
291 \\[browse-url-cci] reverses the effect of this variable.  Requires
292 Netscape version 1.1N or later or XMosaic version 2.5 or later.")
293
294 (defvar browse-url-mosaic-arguments nil
295   "*A list of strings to pass to Mosaic as arguments.")
296
297 (defvar browse-url-filename-alist
298   '(("^/+" . "file:/"))
299   "An alist of (REGEXP . STRING) pairs.
300 Any substring of a filename matching one of the REGEXPs is replaced by
301 the corresponding STRING.  All pairs are applied in the order given.
302 Used by the `browse-url-of-file' command.")
303
304 (defvar browse-url-save-file nil
305   "If non-nil, save the buffer before displaying its file.
306 Used by the `browse-url-of-file' command.")
307
308 (defvar browse-url-of-file-hook nil
309   "A hook to be run with run-hook after `browse-url-of-file' has asked
310 a browser to load a file.
311
312 Set this to `browse-url-netscape-reload' to force Netscape to load the
313 file rather than displaying a cached copy.")
314
315 (defvar browse-url-usr1-signal
316   (if (and (boundp 'emacs-major-version)
317            (or (> emacs-major-version 19) (>= emacs-minor-version 29)))
318       'sigusr1
319     30)                                 ; Check /usr/include/signal.h.
320   "The argument to `signal-process' for sending SIGUSR1 to XMosaic.
321 Emacs 19.29 accepts 'sigusr1, earlier versions require an integer
322 which is 30 on SunOS and 16 on HP-UX and Solaris.")
323
324 (defvar browse-url-CCI-port 3003
325   "Port to access XMosaic via CCI.
326 This can be any number between 1024 and 65535 but must correspond to
327 the value set in the browser.")
328
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
330 ;; URL input
331
332 ;; thingatpt.el doesn't work for complex regexps.
333
334 (defun browse-url-url-at-point ()
335   "Return the URL around or before point.
336 Then search backwards for the start of a URL.  If no URL found, return
337 the empty string."
338   (if (or (looking-at browse-url-regexp)        ; Already at start
339           (let ((eol (save-excursion (end-of-line) (point))))
340             ;; Search forwards for the next URL or end of line in case
341             ;; we're in the middle of one.
342             (and (re-search-forward browse-url-regexp eol 'lim)
343                  (goto-char (match-beginning 0)))
344             ;; Now back to where we started or earlier.
345             (re-search-backward browse-url-regexp nil t)))
346       (buffer-substring (match-beginning 0) (match-end 0))
347     ""))                                ; No match
348
349 ;; Todo: restrict to around or immediately before point.  Expand bare
350 ;; hostname to URL.
351
352 (defun browse-url-interactive-arg (&optional prompt)
353   "Read a URL from the minibuffer, optionally prompting with PROMPT.
354 Default to the URL at or before point.  If bound to a mouse button,
355 set point to the position clicked.  Return the result as a list for
356 use in `interactive'."
357   (let ((event (elt (this-command-keys) 0)))
358     (and (listp event) (mouse-set-point event)))
359   (list (read-string (or prompt "URL: ") (browse-url-url-at-point))))
360
361 (defun browse-url-at-point ()
362   "Ask a WWW browser to load the URL at or before point.
363 The URL is loaded according to the value of `browse-url-browser-function'."
364   (interactive)
365   (funcall browse-url-browser-function (browse-url-url-at-point)))
366
367 (defun browse-url-at-mouse (event)
368   "Ask a WWW browser to load a URL clicked with the mouse.
369 The URL is the one around or before the position of the mouse click
370 but point is not changed.  The URL is loaded according to the value of
371 `browse-url-browser-function'."
372   (interactive "e")
373   (save-excursion
374     (let ((posn (event-start event)))
375       (set-buffer (window-buffer (posn-window posn)))
376       (goto-char (posn-point posn))
377       (let ((url (browse-url-url-at-point)))
378         (if (string-equal url "")
379             (error "No URL found"))
380         (funcall browse-url-browser-function url)))))
381
382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383 ;; Browse current buffer
384
385 (defun browse-url-of-file (&optional file)
386   "Ask a WWW browser to display FILE.
387 Display the current buffer's file if FILE is nil or if called
388 interactively.  Turn the filename into a URL by performing
389 replacements given in variable `browse-url-filename-alist'.  Pass the
390 URL to a browser using variable `browse-url-browser-function' then run
391 `browse-url-of-file-hook'."
392   (interactive)
393   (setq file
394         (or file
395             (buffer-file-name)
396             (error "Current buffer has no file")))
397   (let ((buf (get-file-buffer file)))
398     (if buf
399         (save-excursion
400           (set-buffer buf)
401           (cond ((not (buffer-modified-p)))
402                 (browse-url-save-file (save-buffer))
403                 (t (message "%s modified since last save" file))))))
404   (funcall browse-url-browser-function (browse-url-file-url file))
405   (run-hooks 'browse-url-of-file-hook))
406
407 (defun browse-url-file-url (file)
408   "Return the URL corresponding to FILE.
409 Uses variable `browse-url-filename-alist' to map filenames to URLs."
410   (let ((maps browse-url-filename-alist))
411     (while maps
412       (let* ((map (car maps))
413              (from-re (car map))
414              (to-string (cdr map)))
415         (setq maps (cdr maps))
416         (if (string-match from-re file)
417             (setq file (concat (substring file 0 (match-beginning 0))
418                                to-string
419                                (substring file (match-end 0))))))))
420   file)
421
422 (defvar browse-url-temp-file-name nil)
423 (make-variable-buffer-local 'browse-url-temp-file-name)
424
425 (defvar browse-url-temp-file-list '())
426
427 (defun browse-url-of-buffer (&optional buffer)
428   "Ask a WWW browser to display BUFFER.
429 Display the current buffer if BUFFER is nil."
430   (interactive)
431   (save-excursion
432     (set-buffer (or buffer (current-buffer)))
433     (let ((file-name
434            (or buffer-file-name
435                (and (boundp 'dired-directory) dired-directory))))
436       (if (null file-name)
437           (progn
438             (if (null browse-url-temp-file-name)
439                 (progn
440                   (setq browse-url-temp-file-name
441                         (make-temp-name
442                          (expand-file-name (buffer-name)
443                                            (or (getenv "TMPDIR") "/tmp"))))
444                   (setq browse-url-temp-file-list
445                         (cons browse-url-temp-file-name
446                               browse-url-temp-file-list))))
447             (write-region (point-min) (point-max) browse-url-temp-file-name
448                           nil 'no-message)))
449       (browse-url-of-file (or file-name browse-url-temp-file-name)))))
450
451 (defun browse-url-delete-temp-file (&optional temp-file-name)
452   ;; Delete browse-url-temp-file-name from the file system and from
453   ;; browse-url-temp-file-list.  If optional arg TEMP-FILE-NAME is
454   ;; non-nil, delete it instead, but only from the file system --
455   ;; browse-url-temp-file-list is not affected.
456   (let ((file-name (or temp-file-name browse-url-temp-file-name)))
457     (if (and file-name (file-exists-p file-name))
458         (progn
459           (delete-file file-name)
460           (if (null temp-file-name)
461               (setq browse-url-temp-file-list
462                     (delete browse-url-temp-file-name
463                             browse-url-temp-file-list)))))))
464
465 (defun browse-url-delete-temp-file-list ()
466   ;; Delete all elements of browse-url-temp-file-list.
467   (while browse-url-temp-file-list
468     (browse-url-delete-temp-file (car browse-url-temp-file-list))
469     (setq browse-url-temp-file-list
470           (cdr browse-url-temp-file-list))))
471
472 (add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
473 (add-hook 'kill-emacs-hook 'browse-url-delete-temp-file-list)
474
475 (defun browse-url-of-dired-file ()
476   "In Dired, ask a WWW browser to display the file named on this line."
477   (interactive)
478   (browse-url-of-file (dired-get-filename)))
479
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
481 ;; Browser-specific functions
482
483 (defun browse-url-netscape (url &optional new-window)
484   "Ask the Netscape WWW browser to load URL.
485
486 Default to the URL around or before point.  The strings in variable
487 `browse-url-netscape-arguments' are also passed to Netscape.
488
489 When called interactively, if variable `browse-url-new-window-p' is
490 non-nil, load the document in a new Netscape window, otherwise use a
491 random existing one.  A non-nil interactive prefix argument reverses
492 the effect of browse-url-new-window-p.
493
494 When called non-interactively, optional second argument NEW-WINDOW is
495 used instead of browse-url-new-window-p."
496
497   (interactive (append (browse-url-interactive-arg "Netscape URL: ")
498                        (list (not (eq (null browse-url-new-window-p)
499                                       (null current-prefix-arg))))))
500   (or (zerop
501        (apply 'call-process "netscape" nil nil nil
502               (append browse-url-netscape-arguments
503                       (if new-window '("-noraise"))
504                       (list "-remote" 
505                             (concat "openURL(" url 
506                                     (if new-window ",new-window")
507                                     ")")))))
508       (progn                            ; Netscape not running - start it
509         (message "Starting Netscape...")
510         (apply 'start-process "netscape" nil "netscape"
511                (append browse-url-netscape-arguments (list url))))))
512
513 (defun browse-url-netscape-reload ()
514   "Ask Netscape to reload its current document."
515   (interactive)
516   (browse-url-netscape-command "reload"))
517
518 (defun browse-url-netscape-command (command)
519   "Send a remote control command to Netscape."
520   (apply 'start-process "netscape" nil "netscape"
521          (append browse-url-netscape-arguments
522                  (list "-remote" command))))
523
524
525 (defun browse-url-mosaic (url)
526   "Ask the XMosaic WWW browser to load URL.
527 Default to the URL around or before point."
528   (interactive (browse-url-interactive-arg "Mosaic URL: "))
529   (let ((pidfile (expand-file-name "~/.mosaicpid"))
530         pid pidbuf)
531     (if (file-readable-p pidfile)
532         (save-excursion
533           (find-file pidfile)
534           (goto-char (point-min))
535           (setq pid (read (current-buffer)))
536           (kill-buffer nil)))
537     (if (and pid (zerop (signal-process pid 0))) ; Mosaic running
538         (save-excursion
539           (find-file (format "/tmp/Mosaic.%d" pid))
540           (erase-buffer)
541           (insert "goto\n" url "\n")
542           (save-buffer)
543           (kill-buffer nil)
544           ;; Send signal SIGUSR to Mosaic
545           (message "Signalling Mosaic...")
546           (signal-process pid browse-url-usr1-signal)
547           ;; Or you could try:
548           ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
549           )
550       ;; Mosaic not running - start it
551       (message "Starting Mosaic...")
552       (apply 'start-process "xmosaic" nil "xmosaic"
553              (append browse-url-mosaic-arguments (list url))))))
554
555
556 (defun browse-url-cci (url &optional new-window)
557   "Ask the XMosaic WWW browser to load URL.
558 Default to the URL around or before point.
559
560 This function only works for XMosaic version 2.5 or later.  You must
561 select `CCI' from XMosaic's File menu, set the CCI Port Address to the
562 value of variable `browse-url-CCI-port', and enable `Accept requests'.
563
564 When called interactively, if variable `browse-url-new-window-p' is
565 non-nil, load the document in a new browser window, otherwise use a
566 random existing one.  A non-nil interactive prefix argument reverses
567 the effect of browse-url-new-window-p.
568
569 When called non-interactively, optional second argument NEW-WINDOW is
570 used instead of browse-url-new-window-p."
571   (interactive (append (browse-url-interactive-arg "Mosaic URL: ")
572                        (list (not (eq (null browse-url-new-window-p)
573                                       (null current-prefix-arg))))))
574   (open-network-stream "browse-url" " *browse-url*"
575                        "localhost" browse-url-CCI-port)
576   ;; Todo: start browser if fails
577   (process-send-string "browse-url"
578                        (concat "get url (" url ") output "
579                                (if new-window "new" "current") "\r\n"))
580   (process-send-string "browse-url" "disconnect\r\n")
581   (delete-process "browse-url"))
582
583
584 (defun browse-url-iximosaic (url)
585   "Ask the IXIMosaic WWW browser to load URL.
586 Default to the URL around or before point."
587   (interactive (browse-url-interactive-arg "IXI Mosaic URL: "))
588   (start-process "tellw3b" nil "tellw3b"
589                  "-service WWW_BROWSER ixi_showurl " url))
590
591
592 (defun browse-url-w3 (url)
593   "Ask the w3 WWW browser to load URL.
594 Default to the URL around or before point."
595   (interactive (browse-url-interactive-arg "W3 URL: "))
596   (w3-fetch url))
597
598
599 (provide 'browse-url)
600
601 ;;; browse-url.el ends here