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