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