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