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