Mercurial > emacs
annotate lisp/net/browse-url.el @ 33067:adc6c04ffe30
*** empty log message ***
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 30 Oct 2000 15:21:36 +0000 |
parents | 851690316add |
children | ea170167e034 |
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)) | |
28210 | 272 :version "20.4" |
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 | |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
326 `(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/") |
28210 | 327 ;; The above loses the username to avoid the browser prompting for |
328 ;; it in anonymous cases. If it's not anonymous the next regexp | |
329 ;; applies. | |
330 ("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/") | |
31575
722700be186b
(browse-url-filename-alist): Use , not ,@ to add DOS/Windows specific association.
Jason Rumney <jasonr@gnu.org>
parents:
30798
diff
changeset
|
331 ,(if (memq system-type '(windows-nt ms-dos)) |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
332 '("^\\([a-zA-Z]:\\)[\\/]" . "file:\\1/")) |
28210 | 333 ("^/+" . "file:/")) |
334 "An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'. | |
335 Any substring of a filename matching one of the REGEXPs is replaced by | |
336 the corresponding STRING using `replace-match', not treating STRING | |
337 literally. All pairs are applied in the order given. The default | |
338 value converts ange-ftp/EFS-style paths into ftp URLs and prepends | |
339 `file:' to any path beginning with `/'. | |
340 | |
341 For example, adding to the default a specific translation of an ange-ftp | |
342 address to an HTTP URL: | |
343 | |
344 (setq browse-url-filename-alist | |
345 '((\"/webmaster@webserver:/home/www/html/\" . | |
346 \"http://www.acme.co.uk/\") | |
347 (\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\") | |
348 (\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\") | |
349 (\"^/+\" . \"file:/\"))) | |
350 " | |
351 :type '(repeat (cons :format "%v" | |
352 (regexp :tag "Regexp") | |
353 (string :tag "Replacement"))) | |
354 :version "20.3" | |
355 :group 'browse-url) | |
356 | |
357 ;;;###autoload | |
358 (defcustom browse-url-save-file nil | |
359 "*If non-nil, save the buffer before displaying its file. | |
360 Used by the `browse-url-of-file' command." | |
361 :type 'boolean | |
362 :group 'browse-url) | |
363 | |
364 (defcustom browse-url-of-file-hook nil | |
365 "Run after `browse-url-of-file' has asked a browser to load a file. | |
366 | |
367 Set this to `browse-url-netscape-reload' to force Netscape to load the | |
368 file rather than displaying a cached copy." | |
369 :type 'hook | |
370 :options '(browse-url-netscape-reload) | |
371 :group 'browse-url) | |
372 | |
373 (defvar browse-url-usr1-signal | |
374 (if (and (boundp 'emacs-major-version) | |
375 (or (> emacs-major-version 19) (>= emacs-minor-version 29))) | |
376 'SIGUSR1 ; Why did I think this was in lower case before? | |
377 30) ; Check /usr/include/signal.h. | |
378 "The argument to `signal-process' for sending SIGUSR1 to XMosaic. | |
379 Emacs 19.29 accepts 'SIGUSR1, earlier versions require an integer | |
380 which is 30 on SunOS and 16 on HP-UX and Solaris.") | |
381 | |
382 (defcustom browse-url-CCI-port 3003 | |
383 "Port to access XMosaic via CCI. | |
384 This can be any number between 1024 and 65535 but must correspond to | |
385 the value set in the browser." | |
386 :type 'integer | |
387 :group 'browse-url) | |
388 | |
389 (defcustom browse-url-CCI-host "localhost" | |
390 "*Host to access XMosaic via CCI. | |
391 This should be the host name of the machine running XMosaic with CCI | |
392 enabled. The port number should be set in `browse-url-CCI-port'." | |
393 :type 'string | |
394 :group 'browse-url) | |
395 | |
396 (defvar browse-url-temp-file-name nil) | |
397 (make-variable-buffer-local 'browse-url-temp-file-name) | |
398 | |
399 (defcustom browse-url-xterm-program "xterm" | |
400 "The name of the terminal emulator used by `browse-url-lynx-xterm'. | |
401 This might, for instance, be a separate colour version of xterm." | |
402 :type 'string | |
403 :group 'browse-url) | |
404 | |
405 (defcustom browse-url-xterm-args nil | |
406 "*A list of strings defining options for `browse-url-xterm-program'. | |
407 These might set its size, for instance." | |
408 :type '(repeat (string :tag "Argument")) | |
409 :group 'browse-url) | |
410 | |
31909
36892782f26a
(browse-url-file-url): Check for null maps.
Sam Steingold <sds@gnu.org>
parents:
31575
diff
changeset
|
411 (defcustom browse-url-lynx-emacs-args (and (not window-system) |
28210 | 412 '("-show_cursor")) |
413 "A list of strings defining options for Lynx in an Emacs buffer. | |
414 | |
415 The default is none in a window system, otherwise `-show_cursor' to | |
416 indicate the position of the current link in the absence of | |
417 highlighting, assuming the normal default for showing the cursor." | |
418 :type '(repeat (string :tag "Argument")) | |
419 :version "20.3" | |
420 :group 'browse-url) | |
421 | |
422 (defcustom browse-url-gnudoit-program "gnudoit" | |
423 "The name of the `gnudoit' program used by `browse-url-w3-gnudoit'." | |
424 :type 'string | |
425 :group 'browse-url) | |
426 | |
427 (defcustom browse-url-gnudoit-args '("-q") | |
428 "*A list of strings defining options for `browse-url-gnudoit-program'. | |
429 These might set the port, for instance." | |
430 :type '(repeat (string :tag "Argument")) | |
431 :group 'browse-url) | |
432 | |
433 ;;;###autoload | |
434 (defcustom browse-url-generic-program nil | |
435 "*The name of the browser program used by `browse-url-generic'." | |
436 :type '(choice string (const :tag "None" nil)) | |
437 :group 'browse-url) | |
438 | |
439 (defcustom browse-url-generic-args nil | |
440 "*A list of strings defining options for `browse-url-generic-program'." | |
441 :type '(repeat (string :tag "Argument")) | |
442 :group 'browse-url) | |
443 | |
444 (defcustom browse-url-temp-dir temporary-file-directory | |
445 "The name of a directory for browse-url's temporary files. | |
446 Such files are generated by functions like `browse-url-of-region'. | |
447 You might want to set this to somewhere with restricted read permissions | |
448 for privacy's sake." | |
449 :type 'string | |
450 :group 'browse-url) | |
451 | |
452 (defcustom browse-url-netscape-version | |
453 3 | |
454 "The version of Netscape you are using. | |
455 This affects how URL reloading is done; the mechanism changed | |
456 incompatibly at version 4." | |
457 :type 'number | |
458 :group 'browse-url) | |
459 | |
460 (defcustom browse-url-lynx-input-field 'avoid | |
461 "*Action on selecting an existing Lynx buffer at an input field. | |
462 What to do when sending a new URL to an existing Lynx buffer in Emacs | |
463 if the Lynx cursor is on an input field (in which case the `g' command | |
464 would be entered as data). Such fields are recognized by the | |
465 underlines ____. Allowed values: nil: disregard it, 'warn: warn the | |
466 user and don't emit the URL, 'avoid: try to avoid the field by moving | |
467 down (this *won't* always work)." | |
468 :type '(choice (const :tag "Move to try to avoid field" :value avoid) | |
469 (const :tag "Disregard" :value nil) | |
470 (const :tag "Warn, don't emit URL" :value warn)) | |
471 :version "20.3" | |
472 :group 'browse-url) | |
473 | |
474 (defvar browse-url-lynx-input-attempts 10 | |
475 "*How many times to try to move down from a series of lynx input fields.") | |
476 | |
477 (defcustom browse-url-lynx-input-delay 0.2 | |
478 "How many seconds to wait for lynx between moves down from an input field.") | |
479 | |
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
481 ;; URL input | |
482 | |
483 (defun browse-url-url-at-point () | |
484 (let ((url (thing-at-point 'url))) | |
485 (set-text-properties 0 (length url) nil url) | |
486 url)) | |
487 | |
488 ;; Having this as a separate function called by the browser-specific | |
489 ;; functions allows them to be stand-alone commands, making it easier | |
490 ;; to switch between browsers. | |
491 | |
492 (defun browse-url-interactive-arg (prompt) | |
493 "Read a URL from the minibuffer, prompting with PROMPT. | |
494 Default to the URL at or before point. If invoked with a mouse button, | |
495 set point to the position clicked first. Return a list for use in | |
496 `interactive' containing the URL and `browse-url-new-window-p' or its | |
497 negation if a prefix argument was given." | |
498 (let ((event (elt (this-command-keys) 0))) | |
499 (and (listp event) (mouse-set-point event))) | |
500 (list (read-string prompt (browse-url-url-at-point)) | |
501 (not (eq (null browse-url-new-window-p) | |
502 (null current-prefix-arg))))) | |
503 | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
504 ;; 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
|
505 ;; the macro. |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
506 (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
|
507 `(if (interactive-p) |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
508 ,arg |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
509 browse-url-new-window-p)) |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
510 |
28210 | 511 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
512 ;; Browse current buffer | |
513 | |
514 ;;;###autoload | |
515 (defun browse-url-of-file (&optional file) | |
516 "Ask a WWW browser to display FILE. | |
517 Display the current buffer's file if FILE is nil or if called | |
518 interactively. Turn the filename into a URL with function | |
519 `browse-url-file-url'. Pass the URL to a browser using the | |
520 `browse-url' function then run `browse-url-of-file-hook'." | |
521 (interactive) | |
522 (or file | |
523 (setq file (buffer-file-name)) | |
524 (error "Current buffer has no file")) | |
525 (let ((buf (get-file-buffer file))) | |
526 (if buf | |
527 (save-excursion | |
528 (set-buffer buf) | |
529 (cond ((not (buffer-modified-p))) | |
530 (browse-url-save-file (save-buffer)) | |
531 (t (message "%s modified since last save" file)))))) | |
532 (browse-url (browse-url-file-url file)) | |
533 (run-hooks 'browse-url-of-file-hook)) | |
534 | |
535 (defun browse-url-file-url (file) | |
536 "Return the URL corresponding to FILE. | |
537 Use variable `browse-url-filename-alist' to map filenames to URLs." | |
538 ;; URL-encode special chars, do % first | |
539 (let ((s 0)) | |
540 (while (setq s (string-match "%" file s)) | |
541 (setq file (replace-match "%25" t t file) | |
542 s (1+ s)))) | |
543 (while (string-match "[*\"()',=;? ]" file) | |
544 (let ((enc (format "%%%x" (aref file (match-beginning 0))))) | |
545 (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
|
546 (dolist (map browse-url-filename-alist) |
36892782f26a
(browse-url-file-url): Check for null maps.
Sam Steingold <sds@gnu.org>
parents:
31575
diff
changeset
|
547 (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
|
548 (setq file (replace-match (cdr map) t nil file)))) |
28210 | 549 file) |
550 | |
551 ;;;###autoload | |
552 (defun browse-url-of-buffer (&optional buffer) | |
553 "Ask a WWW browser to display BUFFER. | |
554 Display the current buffer if BUFFER is nil. Display only the | |
555 currently visible part of BUFFER (from a temporary file) if buffer is | |
556 narrowed." | |
557 (interactive) | |
558 (save-excursion | |
559 (and buffer (set-buffer buffer)) | |
560 (let ((file-name | |
561 ;; Ignore real name if restricted | |
562 (and (= (- (point-max) (point-min)) (buffer-size)) | |
563 (or buffer-file-name | |
564 (and (boundp 'dired-directory) dired-directory))))) | |
565 (or file-name | |
566 (progn | |
567 (or browse-url-temp-file-name | |
568 (setq browse-url-temp-file-name | |
569 (convert-standard-filename | |
570 (make-temp-file | |
571 (expand-file-name "burl" browse-url-temp-dir))))) | |
572 (setq file-name browse-url-temp-file-name) | |
573 (write-region (point-min) (point-max) file-name nil 'no-message))) | |
574 (browse-url-of-file file-name)))) | |
575 | |
576 (defun browse-url-delete-temp-file (&optional temp-file-name) | |
577 ;; Delete browse-url-temp-file-name from the file system | |
578 ;; If optional arg TEMP-FILE-NAME is non-nil, delete it instead | |
579 (let ((file-name (or temp-file-name browse-url-temp-file-name))) | |
580 (if (and file-name (file-exists-p file-name)) | |
581 (delete-file file-name)))) | |
582 | |
583 (add-hook 'kill-buffer-hook 'browse-url-delete-temp-file) | |
584 | |
585 ;;;###autoload | |
586 (defun browse-url-of-dired-file () | |
587 "In Dired, ask a WWW browser to display the file named on this line." | |
588 (interactive) | |
589 (browse-url-of-file (dired-get-filename))) | |
590 | |
591 ;;;###autoload | |
592 (defun browse-url-of-region (min max) | |
593 "Ask a WWW browser to display the current region." | |
594 (interactive "r") | |
595 (save-excursion | |
596 (save-restriction | |
597 (narrow-to-region min max) | |
598 (browse-url-of-buffer)))) | |
599 | |
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
601 ;; Browser-independent commands | |
602 | |
603 ;; A generic command to call the current browse-url-browser-function | |
604 | |
605 ;;;###autoload | |
606 (defun browse-url (url &rest args) | |
607 "Ask a WWW browser to load URL. | |
608 Prompts for a URL, defaulting to the URL at or before point. Variable | |
609 `browse-url-browser-function' says which browser to use." | |
610 (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
|
611 (unless (interactive-p) |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
612 (setq args (or args (list browse-url-new-window-p)))) |
28210 | 613 (if (functionp browse-url-browser-function) |
614 (apply browse-url-browser-function url args) | |
615 ;; The `function' can be an alist; look down it for first match | |
616 ;; and apply the function (which might be a lambda). | |
617 (catch 'done | |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
618 (dolist (bf browse-url-browser-function) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
619 (when (string-match (car bf) url) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
620 (apply (cdr bf) url args) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
621 (throw 'done t))) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
622 (error "No browse-url-browser-function matching URL %s" |
28210 | 623 url)))) |
624 | |
625 ;;;###autoload | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
626 (defun browse-url-at-point (&optional arg) |
28210 | 627 "Ask a WWW browser to load the URL at or before point. |
628 Doesn't let you edit the URL like `browse-url'. Variable | |
629 `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
|
630 (interactive "P") |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
631 (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
|
632 (if url |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
633 (browse-url url (if arg |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
634 (not browse-url-new-window-p) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
635 browse-url-new-window-p)) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
636 (error "No URL found")))) |
28210 | 637 |
638 ;;;###autoload | |
639 (defun browse-url-at-mouse (event) | |
640 "Ask a WWW browser to load a URL clicked with the mouse. | |
641 The URL is the one around or before the position of the mouse click | |
642 but point is not changed. Doesn't let you edit the URL like | |
643 `browse-url'. Variable `browse-url-browser-function' says which browser | |
644 to use." | |
645 (interactive "e") | |
646 (save-excursion | |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
647 (mouse-set-point event) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
648 (browse-url-at-point browse-url-new-window-p))) |
28210 | 649 |
650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
651 ;; Browser-specific commands | |
652 | |
653 ;; --- Default MS-Windows browser --- | |
654 | |
655 (defun browse-url-default-windows-browser (url &optional new-window) | |
656 (interactive (browse-url-interactive-arg "URL: ")) | |
657 (w32-shell-execute "open" url)) | |
658 | |
659 ;; --- Netscape --- | |
660 | |
661 (defun browse-url-process-environment () | |
662 "Set DISPLAY in the environment to the X display Netscape is running on. | |
663 This is either the value of variable `browse-url-netscape-display' if | |
664 non-nil, or the same display as Emacs if different from the current | |
665 environment, otherwise just use the current environment." | |
666 (let ((display (or browse-url-netscape-display (browse-url-emacs-display)))) | |
667 (if display | |
668 (cons (concat "DISPLAY=" display) process-environment) | |
669 process-environment))) | |
670 | |
671 (defun browse-url-emacs-display () | |
672 "Return the X display Emacs is running on. | |
673 This is nil if the display is the same as the DISPLAY environment variable. | |
674 | |
675 Actually Emacs could be using several displays; this just returns the | |
676 one showing the selected frame." | |
677 (let ((display (cdr-safe (assq 'display (frame-parameters))))) | |
678 (and (not (equal display (getenv "DISPLAY"))) | |
679 display))) | |
680 | |
681 ;;;###autoload | |
682 (defun browse-url-netscape (url &optional new-window) | |
683 "Ask the Netscape WWW browser to load URL. | |
684 Default to the URL around or before point. The strings in variable | |
685 `browse-url-netscape-arguments' are also passed to Netscape. | |
686 | |
687 When called interactively, if variable `browse-url-new-window-p' is | |
688 non-nil, load the document in a new Netscape window, otherwise use a | |
689 random existing one. A non-nil interactive prefix argument reverses | |
690 the effect of `browse-url-new-window-p'. | |
691 | |
692 When called non-interactively, optional second argument NEW-WINDOW is | |
693 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
|
694 (interactive (browse-url-interactive-arg "URL: ")) |
28210 | 695 ;; URL encode any `confusing' characters in the URL. This needs to |
696 ;; include at least commas; presumably also close parens. | |
697 (while (string-match "[,)]" url) | |
698 (setq url (replace-match | |
699 (format "%%%x" (string-to-char (match-string 0 url))) t t url))) | |
700 (let* ((process-environment (browse-url-process-environment)) | |
701 (process (apply 'start-process | |
702 (concat "netscape " url) nil | |
703 browse-url-netscape-program | |
704 (append | |
705 browse-url-netscape-arguments | |
706 (if (eq window-system 'w32) | |
707 (list url) | |
708 (append | |
709 (if new-window '("-noraise")) | |
710 (list "-remote" | |
711 (concat "openURL(" url | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
712 (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
|
713 new-window) |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
714 ",new-window") |
28210 | 715 ")")))))))) |
716 (set-process-sentinel process | |
30798
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
717 `(lambda (process change) |
8884b93379ef
(browse-url-filename-alist): Add a clause for
Dave Love <fx@gnu.org>
parents:
28330
diff
changeset
|
718 (browse-url-netscape-sentinel process ,url))))) |
28210 | 719 |
720 (defun browse-url-netscape-sentinel (process url) | |
721 "Handle a change to the process communicating with Netscape." | |
722 (or (eq (process-exit-status process) 0) | |
723 (let* ((process-environment (browse-url-process-environment))) | |
724 ;; Netscape not running - start it | |
725 (message "Starting Netscape...") | |
726 (apply 'start-process (concat "netscape" url) nil | |
727 browse-url-netscape-program | |
728 (append browse-url-netscape-startup-arguments (list url)))))) | |
729 | |
730 (defun browse-url-netscape-reload () | |
731 "Ask Netscape to reload its current document. | |
732 How depends on `browse-url-netscape-version'." | |
733 (interactive) | |
734 ;; Backwards incompatibility reported by | |
735 ;; <peter.kruse@psychologie.uni-regensburg.de>. | |
736 (browse-url-netscape-send (if (>= browse-url-netscape-version 4) | |
737 "xfeDoCommand(reload)" | |
738 "reload"))) | |
739 | |
740 (defun browse-url-netscape-send (command) | |
741 "Send a remote control command to Netscape." | |
742 (let* ((process-environment (browse-url-process-environment))) | |
743 (apply 'start-process "netscape" nil | |
744 browse-url-netscape-program | |
745 (append browse-url-netscape-arguments | |
746 (list "-remote" command))))) | |
747 | |
32245
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
748 ;; 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
|
749 |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
750 (defcustom browse-url-gnome-moz-arguments '() |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
751 "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
|
752 :version "21.1" |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
753 :type '(repeat (string :tag "Argument")) |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
754 :group 'browse-url) |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
755 |
32246
851690316add
(browse-url-browser-function): Use it.
Dave Love <fx@gnu.org>
parents:
32245
diff
changeset
|
756 ;;;###autoload |
32245
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
757 (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
|
758 "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
|
759 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
|
760 `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
|
761 |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
762 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
|
763 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
|
764 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
|
765 effect of `browse-url-new-window-p'. |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
766 |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
767 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
|
768 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
|
769 (interactive (browse-url-interactive-arg "URL: ")) |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
770 (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
|
771 nil |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
772 "gnome-moz-remote" |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
773 (append |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
774 browse-url-gnome-moz-arguments |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
775 (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
|
776 '("--newwin")) |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
777 (list "--raise" url)))) |
d35dba8183fd
(browse-url-gnome-moz-arguments): New option.
Dave Love <fx@gnu.org>
parents:
31909
diff
changeset
|
778 |
28210 | 779 ;; --- Mosaic --- |
780 | |
781 ;;;###autoload | |
782 (defun browse-url-mosaic (url &optional new-window) | |
783 "Ask the XMosaic WWW browser to load URL. | |
784 | |
785 Default to the URL around or before point. The strings in variable | |
786 `browse-url-mosaic-arguments' are also passed to Mosaic and the | |
787 program is invoked according to the variable | |
788 `browse-url-mosaic-program'. | |
789 | |
790 When called interactively, if variable `browse-url-new-window-p' is | |
791 non-nil, load the document in a new Mosaic window, otherwise use a | |
792 random existing one. A non-nil interactive prefix argument reverses | |
793 the effect of `browse-url-new-window-p'. | |
794 | |
795 When called non-interactively, optional second argument NEW-WINDOW is | |
796 used instead of `browse-url-new-window-p'." | |
797 (interactive (browse-url-interactive-arg "Mosaic URL: ")) | |
798 (let ((pidfile (expand-file-name "~/.mosaicpid")) | |
799 pid) | |
800 (if (file-readable-p pidfile) | |
801 (save-excursion | |
802 (find-file pidfile) | |
803 (goto-char (point-min)) | |
804 (setq pid (read (current-buffer))) | |
805 (kill-buffer nil))) | |
806 (if (and pid (zerop (signal-process pid 0))) ; Mosaic running | |
807 (save-excursion | |
808 (find-file (format "/tmp/Mosaic.%d" pid)) | |
809 (erase-buffer) | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
810 (insert (if (browse-url-maybe-new-window new-window) |
28210 | 811 "newwin\n" |
812 "goto\n") | |
813 url "\n") | |
814 (save-buffer) | |
815 (kill-buffer nil) | |
816 ;; Send signal SIGUSR to Mosaic | |
817 (message "Signalling Mosaic...") | |
818 (signal-process pid browse-url-usr1-signal) | |
819 ;; Or you could try: | |
820 ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid)) | |
821 (message "Signalling Mosaic...done") | |
822 ) | |
823 ;; Mosaic not running - start it | |
824 (message "Starting Mosaic...") | |
825 (apply 'start-process "xmosaic" nil browse-url-mosaic-program | |
826 (append browse-url-mosaic-arguments (list url))) | |
827 (message "Starting Mosaic...done")))) | |
828 | |
829 ;; --- Grail --- | |
830 | |
831 ;;;###autoload | |
832 (defvar browse-url-grail | |
833 (concat (or (getenv "GRAILDIR") "~/.grail") "/user/rcgrail.py") | |
834 "Location of Grail remote control client script `rcgrail.py'. | |
835 Typically found in $GRAILDIR/rcgrail.py, or ~/.grail/user/rcgrail.py.") | |
836 | |
837 ;;;###autoload | |
838 (defun browse-url-grail (url &optional new-window) | |
839 "Ask the Grail WWW browser to load URL. | |
840 Default to the URL around or before point. Runs the program in the | |
841 variable `browse-url-grail'." | |
842 (interactive (browse-url-interactive-arg "Grail URL: ")) | |
843 (message "Sending URL to Grail...") | |
844 (save-excursion | |
845 (set-buffer (get-buffer-create " *Shell Command Output*")) | |
846 (erase-buffer) | |
847 ;; don't worry about this failing. | |
848 (if new-window | |
849 (call-process browse-url-grail nil 0 nil "-b" url) | |
850 (call-process browse-url-grail nil 0 nil url)) | |
851 (message "Sending URL to Grail... done"))) | |
852 | |
853 ;; --- Mosaic using CCI --- | |
854 | |
855 ;;;###autoload | |
856 (defun browse-url-cci (url &optional new-window) | |
857 "Ask the XMosaic WWW browser to load URL. | |
858 Default to the URL around or before point. | |
859 | |
860 This function only works for XMosaic version 2.5 or later. You must | |
861 select `CCI' from XMosaic's File menu, set the CCI Port Address to the | |
862 value of variable `browse-url-CCI-port', and enable `Accept requests'. | |
863 | |
864 When called interactively, if variable `browse-url-new-window-p' is | |
865 non-nil, load the document in a new browser window, otherwise use a | |
866 random existing one. A non-nil interactive prefix argument reverses | |
867 the effect of `browse-url-new-window-p'. | |
868 | |
869 When called non-interactively, optional second argument NEW-WINDOW is | |
870 used instead of `browse-url-new-window-p'." | |
871 (interactive (browse-url-interactive-arg "Mosaic URL: ")) | |
872 (open-network-stream "browse-url" " *browse-url*" | |
873 browse-url-CCI-host browse-url-CCI-port) | |
874 ;; Todo: start browser if fails | |
875 (process-send-string "browse-url" | |
876 (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
|
877 (if (browse-url-maybe-new-window new-window) |
28210 | 878 "new" |
879 "current") | |
880 "\r\n")) | |
881 (process-send-string "browse-url" "disconnect\r\n") | |
882 (delete-process "browse-url")) | |
883 | |
884 ;; --- IXI Mosaic --- | |
885 | |
886 ;;;###autoload | |
887 (defun browse-url-iximosaic (url &optional new-window) | |
888 ;; new-window ignored | |
889 "Ask the IXIMosaic WWW browser to load URL. | |
890 Default to the URL around or before point." | |
891 (interactive (browse-url-interactive-arg "IXI Mosaic URL: ")) | |
892 (start-process "tellw3b" nil "tellw3b" | |
893 "-service WWW_BROWSER ixi_showurl " url)) | |
894 | |
895 ;; --- W3 --- | |
896 | |
897 ;;;###autoload | |
898 (defun browse-url-w3 (url &optional new-window) | |
899 "Ask the w3 WWW browser to load URL. | |
900 Default to the URL around or before point. | |
901 | |
902 When called interactively, if variable `browse-url-new-window-p' is | |
903 non-nil, load the document in a new window. A non-nil interactive | |
904 prefix argument reverses the effect of `browse-url-new-window-p'. | |
905 | |
906 When called non-interactively, optional second argument NEW-WINDOW is | |
907 used instead of `browse-url-new-window-p'." | |
908 (interactive (browse-url-interactive-arg "W3 URL: ")) | |
909 (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
|
910 (if (browse-url-maybe-new-window new-window) |
28210 | 911 (w3-fetch-other-window url) |
912 (w3-fetch url))) | |
913 | |
914 ;;;###autoload | |
915 (defun browse-url-w3-gnudoit (url &optional new-window) | |
916 ;; new-window ignored | |
917 "Ask another Emacs running gnuserv to load the URL using the W3 browser. | |
918 The `browse-url-gnudoit-program' program is used with options given by | |
919 `browse-url-gnudoit-args'. Default to the URL around or before point." | |
920 (interactive (browse-url-interactive-arg "W3 URL: ")) | |
921 (apply 'start-process (concat "gnudoit:" url) nil | |
922 browse-url-gnudoit-program | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
923 (append browse-url-gnudoit-args |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
924 (list (concat "(w3-fetch \"" url "\")") |
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
925 "(raise-frame)")))) |
28210 | 926 |
927 ;; --- Lynx in an xterm --- | |
928 | |
929 ;;;###autoload | |
930 (defun browse-url-lynx-xterm (url &optional new-window) | |
931 ;; new-window ignored | |
932 "Ask the Lynx WWW browser to load URL. | |
933 Default to the URL around or before point. A new Lynx process is run | |
934 in an Xterm window using the Xterm program named by `browse-url-xterm-program' | |
935 with possible additional arguments `browse-url-xterm-args'." | |
936 (interactive (browse-url-interactive-arg "Lynx URL: ")) | |
937 (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
|
938 ,@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
|
939 ,url))) |
28210 | 940 |
941 ;; --- Lynx in an Emacs "term" window --- | |
942 | |
943 ;;;###autoload | |
944 (defun browse-url-lynx-emacs (url &optional new-buffer) | |
945 "Ask the Lynx WWW browser to load URL. | |
946 Default to the URL around or before point. With a prefix argument, run | |
947 a new Lynx process in a new buffer. | |
948 | |
949 When called interactively, if variable `browse-url-new-window-p' is | |
950 non-nil, load the document in a new lynx in a new term window, | |
951 otherwise use any existing one. A non-nil interactive prefix argument | |
952 reverses the effect of `browse-url-new-window-p'. | |
953 | |
954 When called non-interactively, optional second argument NEW-WINDOW is | |
955 used instead of `browse-url-new-window-p'." | |
956 (interactive (browse-url-interactive-arg "Lynx URL: ")) | |
957 (let* ((system-uses-terminfo t) ; Lynx uses terminfo | |
958 ;; (term-term-name "vt100") ; ?? | |
959 (buf (get-buffer "*lynx*")) | |
960 (proc (and buf (get-buffer-process buf))) | |
961 (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
|
962 (if (and (browse-url-maybe-new-window new-buffer) buf) |
28210 | 963 ;; Rename away the OLD buffer. This isn't very polite, but |
964 ;; term insists on working in a buffer named *lynx* and would | |
965 ;; choke on *lynx*<1> | |
966 (progn (set-buffer buf) | |
967 (rename-uniquely))) | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
968 (if (or (browse-url-maybe-new-window new-buffer) |
28210 | 969 (not buf) |
970 (not proc) | |
971 (not (memq (process-status proc) '(run stop)))) | |
972 ;; start a new lynx | |
973 (progn | |
974 (setq buf | |
975 (apply #'make-term | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
976 `("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
|
977 ,url))) |
28210 | 978 (switch-to-buffer buf) |
979 (term-char-mode) | |
980 (set-process-sentinel | |
981 (get-buffer-process buf) | |
982 ;; Don't leave around a dead one (especially because of its | |
983 ;; munged keymap.) | |
984 (lambda (process event) | |
985 (if (not (memq (process-status process) '(run stop))) | |
986 (let ((buf (process-buffer process))) | |
987 (if buf (kill-buffer buf))))))) | |
988 ;; send the url to lynx in the old buffer | |
989 (let ((win (get-buffer-window buf t))) | |
990 (if win | |
991 (select-window win) | |
992 (switch-to-buffer buf))) | |
993 (if (eq (following-char) ?_) | |
994 (cond ((eq browse-url-lynx-input-field 'warn) | |
995 (error "Please move out of the input field first.")) | |
996 ((eq browse-url-lynx-input-field 'avoid) | |
997 (while (and (eq (following-char) ?_) (> n 0)) | |
998 (term-send-down) ; down arrow | |
999 (sit-for browse-url-lynx-input-delay)) | |
1000 (if (eq (following-char) ?_) | |
1001 (error "Cannot move out of the input field, sorry."))))) | |
1002 (term-send-string proc (concat "g" ; goto | |
1003 "\C-u" ; kill default url | |
1004 url | |
1005 "\r"))))) | |
1006 | |
1007 ;; --- MMM --- | |
1008 | |
1009 ;;;###autoload | |
1010 (defun browse-url-mmm (url &optional new-window) | |
1011 "Ask the MMM WWW browser to load URL. | |
1012 Default to the URL around or before point." | |
1013 (interactive (browse-url-interactive-arg "MMM URL: ")) | |
1014 (message "Sending URL to MMM...") | |
1015 (save-excursion | |
1016 (set-buffer (get-buffer-create " *Shell Command Output*")) | |
1017 (erase-buffer) | |
1018 ;; mmm_remote just SEGVs if the file isn't there... | |
1019 (if (or (file-exists-p (expand-file-name "~/.mmm_remote")) | |
1020 ;; location in v 0.4: | |
1021 (file-exists-p (expand-file-name "~/.mmm/remote"))) | |
1022 (call-process "mmm_remote" nil 0 nil url) | |
1023 (call-process "mmm" nil 0 nil "-external" url)) | |
1024 (message "Sending URL to MMM... done"))) | |
1025 | |
1026 ;; --- mailto --- | |
1027 | |
1028 ;;;###autoload | |
1029 (defun browse-url-mail (url &optional new-window) | |
1030 "Open a new mail message buffer within Emacs. | |
1031 Default to using the mailto: URL around or before point as the | |
1032 recipient's address. Supplying a non-nil interactive prefix argument | |
1033 will cause the mail to be composed in another window rather than the | |
1034 current one. | |
1035 | |
1036 When called interactively, if variable `browse-url-new-window-p' is | |
1037 non-nil use `compose-mail-other-window', otherwise `compose-mail'. A | |
1038 non-nil interactive prefix argument reverses the effect of | |
1039 `browse-url-new-window-p'. | |
1040 | |
1041 When called non-interactively, optional second argument NEW-WINDOW is | |
1042 used instead of `browse-url-new-window-p'." | |
1043 (interactive (browse-url-interactive-arg "Mailto URL: ")) | |
1044 (save-excursion | |
1045 (let ((to (if (string-match "^mailto:" url) | |
1046 (substring url 7) | |
1047 url))) | |
28274
e9c99955f520
Restore previous use of browse-url-maybe-new-window.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
1048 (if (browse-url-maybe-new-window new-window) |
28210 | 1049 (compose-mail-other-window to nil nil nil |
1050 (list 'insert-buffer (current-buffer))) | |
1051 (compose-mail to nil nil nil nil | |
1052 (list 'insert-buffer (current-buffer))))))) | |
1053 | |
1054 ;; --- Random browser --- | |
1055 | |
1056 ;;;###autoload | |
1057 (defun browse-url-generic (url &optional new-window) | |
1058 ;; new-window ignored | |
1059 "Ask the WWW browser defined by `browse-url-generic-program' to load URL. | |
1060 Default to the URL around or before point. A fresh copy of the | |
1061 browser is started up in a new process with possible additional arguments | |
1062 `browse-url-generic-args'. This is appropriate for browsers which | |
1063 don't offer a form of remote control." | |
1064 (interactive (browse-url-interactive-arg "URL: ")) | |
1065 (if (not browse-url-generic-program) | |
1066 (error "No browser defined (`browse-url-generic-program')")) | |
1067 (apply 'start-process (concat browse-url-generic-program url) nil | |
1068 browse-url-generic-program | |
1069 (append browse-url-generic-args (list url)))) | |
1070 | |
1071 (provide 'browse-url) | |
1072 | |
1073 ;;; browse-url.el ends here |