1 ;;; browse-url.el --- Pass a URL to a WWW browser
3 ;; Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
5 ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
6 ;; Maintainer: Dave Love <d.love@dl.ac.uk>
7 ;; Created: 03 Apr 1995
8 ;; Keywords: hypertext, hypermedia, mouse
9 ;; X-Home page: http://wombat.doc.ic.ac.uk/
11 ;; This file is part of GNU Emacs.
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)
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.
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.
30 ;; The latest version of this package should be available from
31 ;; <URL:http://wombat.doc.ic.ac.uk/emacs/browse-url.el>.
33 ;; This package provides functions which read a URL (Uniform Resource
34 ;; Locator) from the minibuffer, defaulting to the URL around point,
35 ;; and ask a World-Wide Web browser to load it. It can also load the
36 ;; URL associated with the current buffer. Different browsers use
37 ;; different methods of remote control so there is one function for
38 ;; each supported browser. If the chosen browser is not running, it
39 ;; is started. Currently there is support for:
41 ;; Function Browser Earliest version
42 ;; browse-url-netscape Netscape 1.1b1
43 ;; browse-url-mosaic XMosaic <= 2.4
44 ;; browse-url-cci XMosaic 2.5
46 ;; browse-url-w3-gnudoit w3 remotely
47 ;; browse-url-iximosaic IXI Mosaic ?
48 ;; browse-url-lynx-* Lynx 0
49 ;; browse-url-grail Grail 0.3b1
50 ;; browse-url-mmm MMM ?
51 ;; browse-url-generic arbitrary
53 ;; Note that versions of Netscape before 1.1b1 did not have remote
54 ;; control. <URL:http://www.netscape.com/newsref/std/x-remote.html>.
56 ;; Netscape can cache Web pages so it may be necessary to tell it to
57 ;; reload the current page if it has changed (e.g. if you have edited
58 ;; it). There is currently no perfect automatic solution to this.
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
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>
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>
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.
76 ;; The `gnuserv' package that can be used to control it in another
77 ;; Emacs process is available from
78 ;; <URL:http://hplbwww.hpl.hp.com/people/ange/gnuserv/>.
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>.
88 ;; MMM is the freely available WWW browser implemented in Caml Special
89 ;; Light, a cool impure functional programming language, by Francois
90 ;; Rouaix. See the MMM home page
91 ;; <URL:http://pauillac.inria.fr/%7Erouaix/mmm/>.
93 ;; Lynx is now distributed by the FSF. See also
94 ;; <URL:http://lynx.browser.org/>.
96 ;; Free graphical browsers that could be used by `browse-url-generic'
97 ;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera>, Arena
98 ;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena>, Amaya
99 ;; <URL:ftp://ftp.w3.org/pub/amaya>, mMosaic
100 ;; <URL:ftp://sig.enst.fr/pub/multicast/mMosaic/> (the latter with
101 ;; development support for Java applets).
103 ;; I recommend Nelson Minar <nelson@santafe.edu>'s excellent
104 ;; html-helper-mode.el for editing HTML and thank Nelson for
105 ;; his many useful comments on this code.
106 ;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/>
108 ;; This package generalises function html-previewer-process in Marc
109 ;; Andreessen <marca@ncsa.uiuc.edu>'s html-mode (LCD
110 ;; modes/html-mode.el.Z) and provides better versions of the URL
111 ;; functions in Michelangelo Grigni <mic@cs.ucsd.edu>'s ffap.el
112 ;; (find-file-at-point) <URL:ftp://cs.ucsd.edu:/pub/mic/>. The huge
113 ;; hyperbole package also contains similar functions.
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118 ;; Can you write and test some code for the Macintrash and Windoze
119 ;; Netscape remote control APIs? (See the URL above).
121 ;; Do any other browsers have remote control?
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
126 ;; To display the URL at or before point:
127 ;; M-x browse-url-at-point RET
128 ;; or, similarly but with the opportunity to edit the URL extracted from
132 ;; To display a URL by shift-clicking on it, put this in your ~/.emacs
134 ;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)
135 ;; (Note that using Shift-mouse-1 is not desirable because
136 ;; that event has a standard meaning in Emacs.)
138 ;; To display the current buffer in a web browser:
139 ;; M-x browse-url-of-buffer RET
141 ;; To display the current region in a web browser:
142 ;; M-x browse-url-of-region RET
144 ;; In Dired, to display the file named on the current line:
145 ;; M-x browse-url-of-dired-file RET
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
148 ;; Customisation (~/.emacs)
150 ;; To see what variables are available for customization, type
151 ;; `M-x set-variable browse-url TAB'.
153 ;; Bind the browse-url commands to keys with the `C-c C-z' prefix
154 ;; (as used by html-helper-mode):
155 ;; (global-set-key "\C-c\C-z." 'browse-url-at-point)
156 ;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer)
157 ;; (global-set-key "\C-c\C-zr" 'browse-url-of-region)
158 ;; (global-set-key "\C-c\C-zu" 'browse-url)
159 ;; (global-set-key "\C-c\C-zv" 'browse-url-of-file)
160 ;; (add-hook 'dired-mode-hook
161 ;; (function (lambda ()
162 ;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file))))
164 ;; Browse URLs in mail messages by clicking mouse-2:
165 ;; (add-hook 'rmail-mode-hook (function (lambda () ; rmail-mode startup
166 ;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse))))
168 ;; Browse URLs in Usenet messages by clicking mouse-2:
169 ;; (eval-after-load "gnus"
170 ;; '(define-key gnus-article-mode-map [mouse-2] 'browse-url-at-mouse))
172 ;; Use the Emacs w3 browser when not running under X11:
173 ;; (or (eq window-system 'x)
174 ;; (setq browse-url-browser-function 'browse-url-w3))
176 ;; To always save modified buffers before displaying the file in a browser:
177 ;; (setq browse-url-save-file t)
179 ;; To get round the Netscape caching problem, you could EITHER have
180 ;; write-file in html-helper-mode make Netscape reload the document:
182 ;; (autoload 'browse-url-netscape-reload "browse-url"
183 ;; "Ask a WWW browser to redisplay the current file." t)
184 ;; (add-hook 'html-helper-mode-hook
185 ;; (function (lambda ()
186 ;; (add-hook 'local-write-file-hooks
187 ;; (function (lambda ()
188 ;; (let ((local-write-file-hooks))
190 ;; (browse-url-netscape-reload)
191 ;; t)) ; => file written by hook
192 ;; t)))) ; append to l-w-f-hooks
194 ;; OR have browse-url-of-file ask Netscape to load and then reload the
197 ;; (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload)
199 ;; You may also want to customise browse-url-netscape-arguments, e.g.
200 ;; (setq browse-url-netscape-arguments '("-install"))
202 ;; or similarly for the other browsers.
204 ;; To invoke different browsers for different URLs:
205 ;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
206 ;; ("." . browse-url-netscape)))
208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
211 (eval-when-compile (require 'dired
)
212 (require 'thingatpt
))
214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
218 (defgroup browse-url nil
219 "Use a web browser to look at a URL."
220 :group
'applications
)
223 (defcustom browse-url-browser-function
225 "*Function to display the current buffer in a WWW browser.
226 This is used by the `browse-url-at-point', `browse-url-at-mouse', and
227 `browse-url-of-file' commands.
229 If the value is not a function it should be a list of pairs
230 (REGEXP.FUNCTION). In this case the function called will be the one
231 associated with the first REGEXP which matches the current URL. The
232 function is passed the URL and any other args of `browse-url'. The last
233 regexp should probably be \".\" to specify a default browser."
237 (defcustom browse-url-netscape-program
"netscape"
238 "*The name by which to invoke Netscape."
242 (defcustom browse-url-netscape-arguments nil
243 "*A list of strings to pass to Netscape as arguments."
244 :type
'(repeat (string :tag
"Argument"))
247 (defcustom browse-url-netscape-startup-arguments browse-url-netscape-arguments
248 "*A list of strings to pass to Netscape when it starts up.
249 Defaults to the value of `browse-url-netscape-arguments' at the time
250 `browse-url' is loaded."
251 :type
'(repeat (string :tag
"Argument"))
254 (defcustom browse-url-new-window-p nil
255 "*If non-nil, always open a new browser window.
256 Passing an interactive argument to \\[browse-url-netscape] or
257 \\[browse-url-cci] reverses the effect of this variable. Requires
258 Netscape version 1.1N or later or XMosaic version 2.5 or later."
262 (defcustom browse-url-netscape-display nil
263 "*The X display on which Netscape is running if different from
268 (defcustom browse-url-mosaic-arguments nil
269 "*A list of strings to pass to Mosaic as arguments."
270 :type
'(repeat (string :tag
"Argument"))
273 (defvar browse-url-path-regexp
274 "[^]\t\n \"'()<>[^`{}]*[^]\t\n \"'()<>[^`{}.,;]+"
275 "A regular expression probably matching the host, path or e-mail part of a URL.")
277 (defvar browse-url-short-regexp
278 (concat "[-A-Za-z0-9.]+" browse-url-path-regexp
)
279 "A regular expression probably matching a URL without an access scheme.
280 Hostname matching is stricter in this case than for
281 ``browse-url-regexp''.")
283 (defvar browse-url-regexp
285 "\\(https?://\\|ftp://\\|gopher://\\|telnet://\\|wais://\\|file:/\\|s?news:\\|mailto:\\)"
286 browse-url-path-regexp
)
287 "A regular expression probably matching a complete URL.")
289 (defvar browse-url-markedup-regexp
291 "A regular expression matching a URL marked up per RFC1738.
292 This may be broken across lines.")
294 (defvar browse-url-filename-alist
295 '(("^/+" .
"file:/"))
296 "An alist of (REGEXP . STRING) pairs.
297 Any substring of a filename matching one of the REGEXPs is replaced by
298 the corresponding STRING. All pairs are applied in the order given.
299 The default value prepends `file:' to any path beginning with `/'.
300 Used by the `browse-url-of-file' command.
302 For example, to map EFS filenames to URLs:
304 (setq browse-url-filename-alist
305 '((\"/webmaster@webserver:/home/www/html/\" .
306 \"http://www.acme.co.uk/\")
307 (\"^/+\" . \"file:/\")))
310 (defvar browse-url-save-file nil
311 "If non-nil, save the buffer before displaying its file.
312 Used by the `browse-url-of-file' command.")
314 (defvar browse-url-of-file-hook nil
315 "A hook to be run with run-hook after `browse-url-of-file' has asked
316 a browser to load a file.
318 Set this to `browse-url-netscape-reload' to force Netscape to load the
319 file rather than displaying a cached copy.")
321 (defvar browse-url-usr1-signal
322 (if (and (boundp 'emacs-major-version
)
323 (or (> emacs-major-version
19) (>= emacs-minor-version
29)))
324 'SIGUSR1
; Why did I think this was in lower case before?
325 30) ; Check /usr/include/signal.h.
326 "The argument to `signal-process' for sending SIGUSR1 to XMosaic.
327 Emacs 19.29 accepts 'SIGUSR1, earlier versions require an integer
328 which is 30 on SunOS and 16 on HP-UX and Solaris.")
330 (defvar browse-url-CCI-port
3003
331 "Port to access XMosaic via CCI.
332 This can be any number between 1024 and 65535 but must correspond to
333 the value set in the browser.")
335 (defvar browse-url-CCI-host
"localhost"
336 "*Host to access XMosaic via CCI.
337 This should be the host name of the machine running XMosaic with CCI
338 enabled. The port number should be set in `browse-url-CCI-port'.")
340 (defvar browse-url-temp-file-name nil
)
341 (make-variable-buffer-local 'browse-url-temp-file-name
)
343 (defcustom browse-url-xterm-program
"xterm"
344 "*The name of the terminal emulator used by `browse-url-lynx-xterm'.
345 This might, for instance, be a separate colour version of xterm."
349 (defcustom browse-url-xterm-args nil
350 "*A list of strings defining options for `browse-url-xterm-program'.
351 These might set its size, for instance."
352 :type
'(repeat (string :tag
"Argument"))
355 (defcustom browse-url-gnudoit-program
"gnudoit"
356 "*The name of the `gnudoit' program used by `browse-url-w3-gnudoit'."
360 (defcustom browse-url-gnudoit-args
'("-q")
361 "*A list of strings defining options for `browse-url-gnudoit-program'.
362 These might set the port, for instance."
363 :type
'(repeat (string :tag
"Argument"))
366 (defcustom browse-url-generic-program nil
367 "*The name of the browser program used by `browse-url-generic'."
371 (defcustom browse-url-generic-args nil
372 "*A list of strings defining options for `browse-url-generic-program'."
373 :type
'(repeat (string :tag
"Argument"))
376 (defvar browse-url-temp-file-list
'())
378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
381 (defun browse-url-url-at-point ()
382 (let ((url (thing-at-point 'url
)))
383 (set-text-properties 0 (length url
) nil url
)
386 ;; Having this as a separate function called by the browser-specific
387 ;; functions allows them to be stand-alone commands, making it easier
388 ;; to switch between browsers.
390 (defun browse-url-interactive-arg (prompt)
391 "Read a URL from the minibuffer, prompting with PROMPT.
392 Default to the URL at or before point. If invoke with a mouse button,
393 set point to the position clicked first. Return a list for use in
394 `interactive' containing the URL and `browse-url-new-window-p' or its
395 negation if a prefix argument was given."
396 (let ((event (elt (this-command-keys) 0)))
397 (and (listp event
) (mouse-set-point event
)))
398 (list (read-string prompt
(browse-url-url-at-point))
399 (not (eq (null browse-url-new-window-p
)
400 (null current-prefix-arg
)))))
402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
403 ;; Browse current buffer
406 (defun browse-url-of-file (&optional file
)
407 "Ask a WWW browser to display FILE.
408 Display the current buffer's file if FILE is nil or if called
409 interactively. Turn the filename into a URL with function
410 `browse-url-file-url'. Pass the URL to a browser using the
411 `browse-url' function then run `browse-url-of-file-hook'."
414 (setq file
(buffer-file-name))
415 (error "Current buffer has no file"))
416 (let ((buf (get-file-buffer file
)))
420 (cond ((not (buffer-modified-p)))
421 (browse-url-save-file (save-buffer))
422 (t (message "%s modified since last save" file
))))))
423 (browse-url (browse-url-file-url file
))
424 (run-hooks 'browse-url-of-file-hook
))
426 (defun browse-url-file-url (file)
427 "Return the URL corresponding to FILE.
428 Use variable `browse-url-filename-alist' to map filenames to URLs.
429 Convert EFS file names of the form /USER@HOST:PATH to ftp://HOST/PATH."
430 ;; URL-encode special chars, do % first
432 (while (setq s
(string-match "%" file s
))
433 (setq file
(replace-match "%25" t t file
)
435 (while (string-match "[*\"()',=;? ]" file
)
436 (let ((enc (format "%%%x" (aref file
(match-beginning 0)))))
437 (setq file
(replace-match enc t t file
))))
438 (let ((maps browse-url-filename-alist
))
440 (let* ((map (car maps
))
442 (to-string (cdr map
)))
443 (setq maps
(cdr maps
))
444 (and (string-match from-re file
)
445 (setq file
(replace-match to-string t t file
))))))
446 ;; Check for EFS path
447 (and (string-match "^/\\([^:@]+@\\)?\\([^:]+\\):/*" file
)
448 (setq file
(concat "ftp://"
449 (substring file
(match-beginning 2) (match-end 2))
450 "/" (substring file
(match-end 0)))))
454 (defun browse-url-of-buffer (&optional buffer
)
455 "Ask a WWW browser to display BUFFER.
456 Display the current buffer if BUFFER is nil. Display only the
457 currently visible part of BUFFER (from a temporary file) if buffer is
461 (and buffer
(set-buffer buffer
))
463 ;; Ignore real name if restricted
464 (and (= (- (point-max) (point-min)) (buffer-size))
466 (and (boundp 'dired-directory
) dired-directory
)))))
469 (or browse-url-temp-file-name
470 (setq browse-url-temp-file-name
472 (expand-file-name (buffer-name)
473 (or (getenv "TMPDIR") "/tmp")))
474 browse-url-temp-file-list
475 (cons browse-url-temp-file-name
476 browse-url-temp-file-list
)))
477 (setq file-name browse-url-temp-file-name
)
478 (write-region (point-min) (point-max) file-name nil
'no-message
)))
479 (browse-url-of-file file-name
))))
481 (defun browse-url-delete-temp-file (&optional temp-file-name
)
482 ;; Delete browse-url-temp-file-name from the file system and from
483 ;; browse-url-temp-file-list. If optional arg TEMP-FILE-NAME is
484 ;; non-nil, delete it instead, but only from the file system --
485 ;; browse-url-temp-file-list is not affected.
486 (let ((file-name (or temp-file-name browse-url-temp-file-name
)))
487 (if (and file-name
(file-exists-p file-name
))
489 (delete-file file-name
)
490 (if (null temp-file-name
)
491 (setq browse-url-temp-file-list
492 (delete browse-url-temp-file-name
493 browse-url-temp-file-list
)))))))
495 (defun browse-url-delete-temp-file-list ()
496 ;; Delete all elements of browse-url-temp-file-list.
497 (while browse-url-temp-file-list
498 (browse-url-delete-temp-file (car browse-url-temp-file-list
))
499 (setq browse-url-temp-file-list
500 (cdr browse-url-temp-file-list
))))
502 (add-hook 'kill-buffer-hook
'browse-url-delete-temp-file
)
503 (add-hook 'kill-emacs-hook
'browse-url-delete-temp-file-list
)
506 (defun browse-url-of-dired-file ()
507 "In Dired, ask a WWW browser to display the file named on this line."
509 (browse-url-of-file (dired-get-filename)))
512 (defun browse-url-of-region (min max
)
513 "Ask a WWW browser to display the current region."
517 (narrow-to-region (mark) (point))
518 (browse-url-of-buffer))))
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
521 ;; Browser-independent commands
523 ;; A generic command to call the current browse-url-browser-function
526 (defun browse-url (&rest args
)
527 "Ask a WWW browser to load URL.
528 Prompts for a URL, defaulting to the URL at or before point. Variable
529 `browse-url-browser-function' says which browser to use."
530 (interactive (browse-url-interactive-arg "URL: "))
531 (if (consp browse-url-browser-function
)
532 (browse-url-choose-browser args
)
533 (apply browse-url-browser-function args
)))
535 (defun browse-url-choose-browser (url &rest args
)
536 "Pass URL to a browser function chosen.
537 This is done according to the association list in variable
538 `browse-url-browser-function'."
539 (let ((blist browse-url-browser-function
)
542 (setq re
(car (car blist
))
545 (if (string-match re url
)
546 (progn (apply bf url args
) (setq blist t
))))
548 (error "No browser in browse-url-browser-function matching URL %s" url
))))
551 (defun browse-url-at-point ()
552 "Ask a WWW browser to load the URL at or before point.
553 Doesn't let you edit the URL like browse-url. Variable
554 `browse-url-browser-function' says which browser to use."
556 (browse-url (browse-url-url-at-point)))
558 (defun browse-url-event-buffer (event)
559 (window-buffer (posn-window (event-start event
))))
561 (defun browse-url-event-point (event)
562 (posn-point (event-start event
)))
565 (defun browse-url-at-mouse (event)
566 "Ask a WWW browser to load a URL clicked with the mouse.
567 The URL is the one around or before the position of the mouse click
568 but point is not changed. Doesn't let you edit the URL like
569 browse-url. Variable `browse-url-browser-function' says which browser
573 (set-buffer (browse-url-event-buffer event
))
574 (goto-char (browse-url-event-point event
))
575 (let ((url (browse-url-url-at-point)))
576 (if (string-equal url
"")
577 (error "No URL found"))
580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
581 ;; Browser-specific commands
585 (defun browse-url-process-environment ()
586 "Set DISPLAY in the environment to the X display Netscape is running on.
587 This is either the value of variable `browse-url-netscape-display' if
588 non-nil, or the same display as Emacs if different from the current
589 environment, otherwise just use the current environment."
590 (let ((display (or browse-url-netscape-display
(browse-url-emacs-display))))
592 (cons (concat "DISPLAY=" display
) process-environment
)
593 process-environment
)))
595 (defun browse-url-emacs-display ()
596 "Return the X display Emacs is running on.
597 This nil if the display is the same as the DISPLAY environment variable.
599 Actually Emacs could be using several screens on several displays, as
600 listed by (emacs-display-list) and (x-display-screens DISPLAY), this
601 just returns the display showing the selected frame. You got a
603 (let (device display
)
604 (and (fboundp 'selected-device
) (fboundp 'device-type
) (fboundp 'device-connection
)
605 (setq device
(selected-device))
606 (eq (device-type device
) 'x
)
607 (setq display
(device-connection device
))
608 (not (equal display
(getenv "DISPLAY")))
612 (defun browse-url-netscape (url &optional new-window
)
613 "Ask the Netscape WWW browser to load URL.
615 Default to the URL around or before point. The strings in variable
616 `browse-url-netscape-arguments' are also passed to Netscape.
618 When called interactively, if variable `browse-url-new-window-p' is
619 non-nil, load the document in a new Netscape window, otherwise use a
620 random existing one. A non-nil interactive prefix argument reverses
621 the effect of `browse-url-new-window-p'.
623 When called non-interactively, optional second argument NEW-WINDOW is
624 used instead of `browse-url-new-window-p'."
625 (interactive (browse-url-interactive-arg "Netscape URL: "))
626 ;; URL encode any commas in the URL
627 (while (string-match "," url
)
628 (setq url
(replace-match "%2C" t t url
)))
629 (let* ((process-environment (browse-url-process-environment))
630 (process (apply 'start-process
631 (concat "netscape " url
) nil
632 browse-url-netscape-program
633 (append browse-url-netscape-arguments
634 (if (string-equal "win32" window-system
)
636 (if new-window
'("-noraise"))
638 (concat "openURL(" url
639 (if new-window
",new-window")
641 (set-process-sentinel process
642 (list 'lambda
'(process change
)
643 (list 'browse-url-netscape-sentinel
'process url
)))))
645 (defun browse-url-netscape-sentinel (process url
)
646 "Handle a change to the process communicating with Netscape."
647 (or (eq (process-exit-status process
) 0)
648 (let* ((process-environment (browse-url-process-environment)))
649 ;; Netscape not running - start it
650 (message "Starting Netscape...")
651 (apply 'start-process
(concat "netscape" url
) nil
652 browse-url-netscape-program
653 (append browse-url-netscape-startup-arguments
(list url
))))))
655 (defun browse-url-netscape-reload ()
656 "Ask Netscape to reload its current document."
658 (browse-url-netscape-send "reload"))
660 (defun browse-url-netscape-send (command)
661 "Send a remote control command to Netscape."
662 (let* ((process-environment (browse-url-process-environment)))
663 (apply 'start-process
"netscape" nil
664 browse-url-netscape-program
665 (append browse-url-netscape-arguments
666 (list "-remote" command
)))))
671 (defun browse-url-mosaic (url &optional new-window
)
672 ;; new-window ignored
673 "Ask the XMosaic WWW browser to load URL.
674 Default to the URL around or before point."
675 (interactive (browse-url-interactive-arg "Mosaic URL: "))
676 (let ((pidfile (expand-file-name "~/.mosaicpid"))
678 (if (file-readable-p pidfile
)
681 (goto-char (point-min))
682 (setq pid
(read (current-buffer)))
684 (if (and pid
(zerop (signal-process pid
0))) ; Mosaic running
686 (find-file (format "/tmp/Mosaic.%d" pid
))
688 (insert "goto\n" url
"\n")
691 ;; Send signal SIGUSR to Mosaic
692 (message "Signalling Mosaic...")
693 (signal-process pid browse-url-usr1-signal
)
695 ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
696 (message "Signalling Mosaic...done")
698 ;; Mosaic not running - start it
699 (message "Starting Mosaic...")
700 (apply 'start-process
"xmosaic" nil
"xmosaic"
701 (append browse-url-mosaic-arguments
(list url
)))
702 (message "Starting Mosaic...done"))))
707 (defvar browse-url-grail
708 (concat (or (getenv "GRAILDIR") "~/.grail") "/user/rcgrail.py")
709 "*Location of Grail remote control client script `rcgrail.py'.
710 Typically found in $GRAILDIR/rcgrail.py, or ~/.grail/user/rcgrail.py.")
713 (defun browse-url-grail (url &optional new-window
)
714 "Ask the Grail WWW browser to load URL.
715 Default to the URL around or before point. Runs the program in the
716 variable `browse-url-grail'."
717 (interactive (browse-url-interactive-arg "Grail URL: "))
718 (message "Sending URL to Grail...")
720 (set-buffer (get-buffer-create " *Shell Command Output*"))
722 ;; don't worry about this failing.
723 (call-process browse-url-grail nil
0 nil url
)
724 (message "Sending URL to Grail... done")))
726 ;; --- Mosaic using CCI ---
728 (defun browse-url-cci (url &optional new-window
)
729 "Ask the XMosaic WWW browser to load URL.
730 Default to the URL around or before point.
732 This function only works for XMosaic version 2.5 or later. You must
733 select `CCI' from XMosaic's File menu, set the CCI Port Address to the
734 value of variable `browse-url-CCI-port', and enable `Accept requests'.
736 When called interactively, if variable `browse-url-new-window-p' is
737 non-nil, load the document in a new browser window, otherwise use a
738 random existing one. A non-nil interactive prefix argument reverses
739 the effect of `browse-url-new-window-p'.
741 When called non-interactively, optional second argument NEW-WINDOW is
742 used instead of `browse-url-new-window-p'."
743 (interactive (browse-url-interactive-arg "Mosaic URL: "))
744 (open-network-stream "browse-url" " *browse-url*"
745 browse-url-CCI-host browse-url-CCI-port
)
746 ;; Todo: start browser if fails
747 (process-send-string "browse-url"
748 (concat "get url (" url
") output "
749 (if new-window
"new" "current") "\r\n"))
750 (process-send-string "browse-url" "disconnect\r\n")
751 (delete-process "browse-url"))
753 ;; --- IXI Mosaic ---
756 (defun browse-url-iximosaic (url &optional new-window
)
757 ;; new-window ignored
758 "Ask the IXIMosaic WWW browser to load URL.
759 Default to the URL around or before point."
760 (interactive (browse-url-interactive-arg "IXI Mosaic URL: "))
761 (start-process "tellw3b" nil
"tellw3b"
762 "-service WWW_BROWSER ixi_showurl " url
))
767 (defun browse-url-w3 (url &optional new-window
)
768 ;; new-window ignored
769 "Ask the w3 WWW browser to load URL.
770 Default to the URL around or before point."
771 (interactive (browse-url-interactive-arg "W3 URL: "))
775 (defun browse-url-w3-gnudoit (url &optional new-window
)
776 ;; new-window ignored
777 "Ask another Emacs running gnuserv to load the URL using the W3 browser.
778 The `browse-url-gnudoit-program' program is used with options given by
779 `browse-url-gnudoit-args'. Default to the URL around or before point."
780 (interactive (browse-url-interactive-arg "W3 URL: "))
781 (apply 'start-process
(concat "gnudoit:" url
) nil
782 browse-url-gnudoit-program
783 (append browse-url-gnudoit-args
(list (concat "(w3-fetch \"" url
"\")") "(raise-frame)"))))
785 ;; --- Lynx in an xterm ---
788 (defun browse-url-lynx-xterm (url &optional new-window
)
789 ;; new-window ignored
790 "Ask the Lynx WWW browser to load URL.
791 Default to the URL around or before point. A new Lynx process is run
792 in an Xterm window using the Xterm program named by `browse-url-xterm-program'
793 with possible additional arguments `browse-url-xterm-args'."
794 (interactive (browse-url-interactive-arg "Lynx URL: "))
795 (apply 'start-process
(concat "lynx" url
) nil browse-url-xterm-program
796 (append browse-url-xterm-args
(list "-e" "lynx" url
))))
798 ;; --- Lynx in an Emacs "term" window ---
801 (defun browse-url-lynx-emacs (url &optional new-window
)
802 ;; new-window ignored
803 "Ask the Lynx WWW browser to load URL.
804 Default to the URL around or before point. Run a new Lynx process in
806 (interactive (browse-url-interactive-arg "Lynx URL: "))
807 (let ((system-uses-terminfo t
)) ; Lynx uses terminfo
808 (if (fboundp 'make-term
)
809 (let ((term-term-name "vt100"))
810 (set-buffer (make-term "browse-url" "lynx" nil url
))
813 (switch-to-buffer "*browse-url*"))
814 (terminal-emulator "*browse-url*" "lynx" (list url
)))))
819 (defun browse-url-mmm (url &optional new-window
)
820 "Ask the MMM WWW browser to load URL.
821 Default to the URL around or before point."
822 (interactive (browse-url-interactive-arg "MMM URL: "))
823 (message "Sending URL to MMM...")
825 (set-buffer (get-buffer-create " *Shell Command Output*"))
827 ;; mmm_remote just SEGVs if the file isn't there...
828 (if (or (file-exists-p (expand-file-name "~/.mmm_remote"))
829 ;; location in v 0.4:
830 (file-exists-p (expand-file-name "~/.mmm/remote")))
831 (call-process "mmm_remote" nil
0 nil url
)
832 (call-process "mmm" nil
0 nil
"-external" url
))
833 (message "Sending URL to MMM... done")))
838 (defun browse-url-mail (url)
839 "Open a new mail message buffer within Emacs.
840 Default to the mailto URL around or before point."
841 (interactive (browse-url-interactive-arg "Mailto URL: "))
843 ;; open mail buffer, specifying TO and REPLYBUFFER
844 (mail nil
(if (string-match "^mailto:" url
)
850 ;; --- Random browser ---
853 (defun browse-url-generic (url &optional new-window
)
854 ;; new-window ignored
855 "Ask the WWW browser defined by `browse-url-generic-program' to load URL.
856 Default to the URL around or before point. A fresh copy of the
857 browser is started up in a new process with possible additional arguments
858 `browse-url-generic-args'. This is appropriate for browsers which
859 don't offer a form of remote control."
860 (interactive (browse-url-interactive-arg "URL: "))
861 (if (not browse-url-generic-program
)
862 (error "No browser defined (`browse-url-generic-program')"))
863 (apply 'start-process
(concat browse-url-generic-program url
) nil
864 browse-url-generic-program
865 (append browse-url-generic-args
(list url
))))
867 (provide 'browse-url
)
869 ;;; browse-url.el ends here