Mercurial > emacs
annotate lisp/goto-addr.el @ 17216:ef3033d89075
(tq-process-buffer): Catch errors running tq-queue-head-fn.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 22 Mar 1997 03:55:49 +0000 |
parents | 22c70a622b67 |
children | 247c2a11843d |
rev | line source |
---|---|
13208 | 1 ;;; goto-addr.el --- click to browse URL or to send to e-mail address |
14169 | 2 |
13208 | 3 ;; Copyright (C) 1995 Free Software Foundation, Inc. |
4 | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
5 ;; Author: Eric Ding <ericding@mit.edu> |
13208 | 6 ;; Maintainer: Eric Ding <ericding@mit.edu> |
7 ;; Created: 15 Aug 1995 | |
8 ;; Keywords: mh-e, www, mouse, mail | |
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 | |
14169 | 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. | |
13208 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; This package allows you to click or hit a key sequence while on a | |
30 ;; URL or e-mail address, and either load the URL into a browser of | |
31 ;; your choice using the browse-url package, or if it's an e-mail | |
32 ;; address, to send an e-mail to that address. By default, we bind to | |
13739
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
33 ;; the [mouse-2] and the [C-c return] key sequences. |
13208 | 34 |
35 ;; INSTALLATION | |
36 ;; | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
37 ;; To use goto-address in a particular mode (for example, while |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
38 ;; reading mail in mh-e), add something like this in your .emacs file: |
13208 | 39 ;; |
40 ;; (add-hook 'mh-show-mode-hook 'goto-address) | |
41 ;; | |
42 ;; By default, goto-address now sends using `mail' instead of `mh-send'. | |
43 ;; To use mh-e to send mail, add the following to your .emacs file: | |
44 ;; | |
15028
4572159ddf04
(goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents:
14208
diff
changeset
|
45 ;; (setq goto-address-mail-method 'goto-address-send-using-mh-e) |
13208 | 46 ;; |
13739
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
47 ;; The mouse click method is bound to [mouse-2] on highlighted URL's or |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
48 ;; e-mail addresses only; it functions normally everywhere else. To bind |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
49 ;; another mouse click to the function, add the following to your .emacs |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
50 ;; (for example): |
13208 | 51 ;; |
13739
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
52 ;; (setq goto-address-highlight-keymap |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
53 ;; (let ((m (make-sparse-keymap))) |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
54 ;; (define-key m [S-mouse-2] 'goto-address-at-mouse) |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
55 ;; m)) |
13208 | 56 ;; |
57 | |
58 ;; BUG REPORTS | |
59 ;; | |
60 ;; Please send bug reports to me at ericding@mit.edu. | |
61 | |
62 ;; Known bugs/features: | |
63 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing, | |
64 ;; not stuff like X.400 addresses, etc. | |
65 ;; * regexp also catches Message-Id line, since it is in the format of | |
66 ;; an Internet e-mail address (like Compuserve addresses) | |
67 ;; * If show buffer is fontified after goto-address-fontify is run | |
68 ;; (say, using font-lock-fontify-buffer), then font-lock face will | |
69 ;; override goto-address faces. | |
70 | |
71 ;;; Code: | |
72 | |
73 (require 'browse-url) | |
74 | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
75 ;;; I don't expect users to want fontify'ing without highlighting. |
13208 | 76 (defvar goto-address-fontify-p t |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
77 "*If t, URL's and e-mail addresses in buffer are fontified. |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
78 But only if `goto-address-highlight-p' is also non-nil.") |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
79 |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
80 (defvar goto-address-highlight-p t |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
81 "*If t, URL's and e-mail addresses in buffer are highlighted.") |
13208 | 82 |
83 (defvar goto-address-fontify-maximum-size 30000 | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
84 "*Maximum size of file in which to fontify and/or highlight URL's.") |
13208 | 85 |
86 (defvar goto-address-mail-regexp | |
87 "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+" | |
88 "A regular expression probably matching an e-mail address.") | |
89 | |
90 (defvar goto-address-url-regexp | |
91 (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|" | |
92 "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:" | |
93 "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*" | |
94 "[-a-zA-Z0-9_=#$@~`%&*+|\\/]") | |
95 "A regular expression probably matching a URL.") | |
96 | |
97 (defvar goto-address-mail-method | |
98 'goto-address-send-using-mail | |
99 "*Function to compose mail. | |
100 Two pre-made functions are `goto-address-send-using-mail' (sendmail); | |
15028
4572159ddf04
(goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents:
14208
diff
changeset
|
101 and `goto-address-send-using-mh-e' (MH-E).") |
13208 | 102 |
13739
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
103 (defvar goto-address-highlight-keymap |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
104 (let ((m (make-sparse-keymap))) |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
105 (define-key m [mouse-2] 'goto-address-at-mouse) |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
106 m) |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
107 "keymap to hold goto-addr's mouse key defs under highlighted URLs.") |
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
108 |
15502
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
109 (defvar goto-address-url-face 'bold |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
110 "*Face to use for URLs.") |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
111 |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
112 (defvar goto-address-url-mouse-face 'highlight |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
113 "*Face to use for URLs when the mouse is on them.") |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
114 |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
115 (defvar goto-address-mail-face 'italic |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
116 "*Face to use for e-mail addresses.") |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
117 |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
118 (defvar goto-address-mail-mouse-face 'secondary-selection |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
119 "*Face to use for e-mail addresses when the mouse is on them.") |
5053b03d18cb
(goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents:
15028
diff
changeset
|
120 |
13208 | 121 (defun goto-address-fontify () |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
122 "Fontify the URL's and e-mail addresses in the current buffer. |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
123 This function implements `goto-address-highlight-p' |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
124 and `goto-address-fontify-p'." |
13208 | 125 (save-excursion |
126 (let ((inhibit-read-only t) | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
127 (inhibit-point-motion-hooks t) |
13208 | 128 (modified (buffer-modified-p))) |
129 (goto-char (point-min)) | |
130 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size) | |
131 (progn | |
132 (while (re-search-forward goto-address-url-regexp nil t) | |
16661
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
133 (let* ((s (match-beginning 0)) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
134 (e (match-end 0)) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
135 (this-overlay (make-overlay s e))) |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
136 (and goto-address-fontify-p |
16661
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
137 (overlay-put this-overlay 'face goto-address-url-face)) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
138 (overlay-put this-overlay |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
139 'mouse-face goto-address-url-mouse-face) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
140 (overlay-put this-overlay |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
141 'local-map goto-address-highlight-keymap))) |
13208 | 142 (goto-char (point-min)) |
143 (while (re-search-forward goto-address-mail-regexp nil t) | |
16661
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
144 (let* ((s (match-beginning 0)) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
145 (e (match-end 0)) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
146 (this-overlay (make-overlay s e))) |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
147 (and goto-address-fontify-p |
16661
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
148 (overlay-put this-overlay 'face goto-address-mail-face)) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
149 (overlay-put this-overlay 'mouse-face |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
150 goto-address-mail-mouse-face) |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
151 (overlay-put this-overlay |
22c70a622b67
(goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents:
15502
diff
changeset
|
152 'local-map goto-address-highlight-keymap))))) |
13208 | 153 (and (buffer-modified-p) |
154 (not modified) | |
155 (set-buffer-modified-p nil))))) | |
156 | |
157 ;;; code to find and goto addresses; much of this has been blatantly | |
158 ;;; snarfed from browse-url.el | |
159 | |
14208
1f2f55478197
(goto-address-at-point, goto-address-at-mouse): Add autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
160 ;;;###autoload |
13208 | 161 (defun goto-address-at-mouse (event) |
162 "Send to the e-mail address or load the URL clicked with the mouse. | |
163 Send mail to address at position of mouse click. See documentation for | |
164 `goto-address-find-address-at-point'. If no address is found | |
165 there, then load the URL at or before the position of the mouse click." | |
166 (interactive "e") | |
167 (save-excursion | |
168 (let ((posn (event-start event))) | |
169 (set-buffer (window-buffer (posn-window posn))) | |
170 (goto-char (posn-point posn)) | |
171 (let ((address | |
172 (save-excursion (goto-address-find-address-at-point)))) | |
173 (if (string-equal address "") | |
174 (let ((url (browse-url-url-at-point))) | |
175 (if (string-equal url "") | |
176 (error "No e-mail address or URL found") | |
177 (funcall browse-url-browser-function url))) | |
178 (funcall goto-address-mail-method address)))))) | |
179 | |
14208
1f2f55478197
(goto-address-at-point, goto-address-at-mouse): Add autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
180 ;;;###autoload |
13208 | 181 (defun goto-address-at-point () |
182 "Send to the e-mail address or load the URL at point. | |
183 Send mail to address at point. See documentation for | |
184 `goto-address-find-address-at-point'. If no address is found | |
185 there, then load the URL at or before point." | |
186 (interactive) | |
187 (save-excursion | |
188 (let ((address (save-excursion (goto-address-find-address-at-point)))) | |
189 (if (string-equal address "") | |
190 (let ((url (browse-url-url-at-point))) | |
191 (if (string-equal url "") | |
192 (error "No e-mail address or URL found") | |
193 (funcall browse-url-browser-function url))) | |
194 (funcall goto-address-mail-method address))))) | |
195 | |
196 (defun goto-address-find-address-at-point () | |
197 "Find e-mail address around or before point. | |
198 Then search backwards to beginning of line for the start of an e-mail | |
199 address. If no e-mail address found, return the empty string." | |
200 (let ((bol (save-excursion (beginning-of-line) (point)))) | |
201 (re-search-backward "[^-_A-z0-9.@]" bol 'lim) | |
202 (if (or (looking-at goto-address-mail-regexp) ; already at start | |
203 (let ((eol (save-excursion (end-of-line) (point)))) | |
204 (and (re-search-forward goto-address-mail-regexp eol 'lim) | |
205 (goto-char (match-beginning 0))))) | |
206 (buffer-substring (match-beginning 0) (match-end 0)) | |
207 ""))) | |
208 | |
15028
4572159ddf04
(goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents:
14208
diff
changeset
|
209 (defun goto-address-send-using-mh-e (to) |
4572159ddf04
(goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents:
14208
diff
changeset
|
210 (require 'mh-comp) |
13208 | 211 (mh-find-path) |
212 (let ((cc (mh-read-address "Cc: ")) | |
213 (subject (read-string "Subject: ")) | |
214 (config (current-window-configuration))) | |
215 (delete-other-windows) | |
216 (mh-send-sub to cc subject config))) | |
217 | |
15028
4572159ddf04
(goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents:
14208
diff
changeset
|
218 (fset 'goto-address-send-using-mhe 'goto-address-send-using-mh-e) |
4572159ddf04
(goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents:
14208
diff
changeset
|
219 |
13208 | 220 (defun goto-address-send-using-mail (to) |
221 (mail-other-window nil to) | |
222 (and (goto-char (point-min)) | |
223 (end-of-line 2))) | |
224 | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
225 ;;;###autoload |
13208 | 226 (defun goto-address () |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
227 "Sets up goto-address functionality in the current buffer. |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
228 Allows user to use mouse/keyboard command to click to go to a URL |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
229 or to send e-mail. |
13739
f6fa5b68f9c7
Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents:
13550
diff
changeset
|
230 By default, goto-address binds to mouse-2 and C-c RET. |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
231 |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
232 Also fontifies the buffer appropriately (see `goto-address-fontify-p' and |
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
233 `goto-address-highlight-p' for more information)." |
13208 | 234 (interactive) |
235 (local-set-key "\C-c\r" 'goto-address-at-point) | |
13550
06e46fbae7f0
(goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13208
diff
changeset
|
236 (if goto-address-highlight-p |
13208 | 237 (goto-address-fontify))) |
238 | |
239 (provide 'goto-addr) | |
240 | |
241 ;;; goto-addr.el ends here. |