Mercurial > emacs
annotate lisp/net/goto-addr.el @ 94029:97873d4b0d7a
Move non-autoloaded define-obsolete-variable-alias calls for
defcustoms not in dumped files before the associated defcustom.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 12 Apr 2008 03:15:19 +0000 |
parents | 6888fd3398e8 |
children | 606f2d163a64 76f3f9a141a5 |
rev | line source |
---|---|
28210 | 1 ;;; goto-addr.el --- click to browse URL or to send to e-mail address |
2 | |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1995, 2000, 2001, 2002, 2003, 2004, |
79714 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
28210 | 5 |
30192 | 6 ;; Author: Eric Ding <ericding@alum.mit.edu> |
30285 | 7 ;; Maintainer: FSF |
28210 | 8 ;; Created: 15 Aug 1995 |
9 ;; Keywords: mh-e, www, mouse, mail | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
78230
84cf1e2214c5
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
28210 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
28210 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This package allows you to click or hit a key sequence while on a | |
31 ;; URL or e-mail address, and either load the URL into a browser of | |
32 ;; your choice using the browse-url package, or if it's an e-mail | |
33 ;; address, to send an e-mail to that address. By default, we bind to | |
34 ;; the [mouse-2] and the [C-c return] key sequences. | |
35 | |
36 ;; INSTALLATION | |
37 ;; | |
38 ;; To use goto-address in a particular mode (for example, while | |
39 ;; reading mail in mh-e), add something like this in your .emacs file: | |
40 ;; | |
41 ;; (add-hook 'mh-show-mode-hook 'goto-address) | |
42 ;; | |
29664
3e03d72fadea
(goto-address-fontify): Use keymap property, not local-map.
Dave Love <fx@gnu.org>
parents:
29653
diff
changeset
|
43 ;; The mouse click method is bound to [mouse-2] on highlighted URLs or |
28210 | 44 ;; e-mail addresses only; it functions normally everywhere else. To bind |
45 ;; another mouse click to the function, add the following to your .emacs | |
46 ;; (for example): | |
47 ;; | |
48 ;; (setq goto-address-highlight-keymap | |
49 ;; (let ((m (make-sparse-keymap))) | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
50 ;; (define-key m [S-mouse-2] 'goto-address-at-point) |
28210 | 51 ;; m)) |
52 ;; | |
53 | |
54 ;; Known bugs/features: | |
55 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing, | |
56 ;; not stuff like X.400 addresses, etc. | |
57 ;; * regexp also catches Message-Id line, since it is in the format of | |
58 ;; an Internet e-mail address (like Compuserve addresses) | |
30345
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
59 ;; * If the buffer is fontified after goto-address-fontify is run |
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
60 ;; (say, using font-lock-fontify-buffer), then font-lock faces will |
28210 | 61 ;; override goto-address faces. |
62 | |
63 ;;; Code: | |
64 | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
65 (require 'thingatpt) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
66 (autoload 'browse-url-url-at-point "browse-url") |
28210 | 67 |
37423
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
68 ;; XEmacs needs the following definitions. |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
69 (unless (fboundp 'overlays-in) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
70 (require 'overlay)) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
71 (unless (fboundp 'line-beginning-position) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
72 (defalias 'line-beginning-position 'point-at-bol)) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
73 (unless (fboundp 'line-end-position) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
74 (defalias 'line-end-position 'point-at-eol)) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
75 (unless (fboundp 'match-string-no-properties) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
76 (defalias 'match-string-no-properties 'match-string)) |
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
77 |
28210 | 78 (defgroup goto-address nil |
79 "Click to browse URL or to send to e-mail address." | |
80 :group 'mouse | |
81 :group 'hypermedia) | |
82 | |
83 | |
39568
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
84 ;; I don't expect users to want fontify'ing without highlighting. |
28210 | 85 (defcustom goto-address-fontify-p t |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
86 "*Non-nil means URLs and e-mail addresses in buffer are fontified. |
28210 | 87 But only if `goto-address-highlight-p' is also non-nil." |
88 :type 'boolean | |
89 :group 'goto-address) | |
90 | |
91 (defcustom goto-address-highlight-p t | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
92 "*Non-nil means URLs and e-mail addresses in buffer are highlighted." |
28210 | 93 :type 'boolean |
94 :group 'goto-address) | |
95 | |
96 (defcustom goto-address-fontify-maximum-size 30000 | |
51098
9277afae9517
(goto-address-fontify-maximum-size): Value t means no limit.
Richard M. Stallman <rms@gnu.org>
parents:
49598
diff
changeset
|
97 "*Maximum size of file in which to fontify and/or highlight URLs. |
9277afae9517
(goto-address-fontify-maximum-size): Value t means no limit.
Richard M. Stallman <rms@gnu.org>
parents:
49598
diff
changeset
|
98 A value of t means there is no limit--fontify regardless of the size." |
9277afae9517
(goto-address-fontify-maximum-size): Value t means no limit.
Richard M. Stallman <rms@gnu.org>
parents:
49598
diff
changeset
|
99 :type '(choice (integer :tag "Maximum size") (const :tag "No limit" t)) |
28210 | 100 :group 'goto-address) |
101 | |
102 (defvar goto-address-mail-regexp | |
39790
1802ca573682
(goto-address-mail-regexp): Allow + in username.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39568
diff
changeset
|
103 ;; Actually pretty much any char could appear in the username part. -stef |
59117
7aa5e44f673f
(goto-address-mail-regexp): Allow = in username.
Richard M. Stallman <rms@gnu.org>
parents:
56210
diff
changeset
|
104 "[-a-zA-Z0-9=._+]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+" |
28210 | 105 "A regular expression probably matching an e-mail address.") |
106 | |
48068
0560d7169eba
(goto-address-url-regexp): Don't match `mailto'.
Richard M. Stallman <rms@gnu.org>
parents:
39790
diff
changeset
|
107 (defvar goto-address-url-regexp |
66695
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
108 (concat |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
109 "\\<\\(" |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
110 (mapconcat 'identity |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
111 (delete "mailto:" |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
112 ;; Remove `data:', as it's not terribly useful to follow |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
113 ;; those. Leaving them causes `use Data::Dumper;' to be |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
114 ;; fontified oddly in Perl files. |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
115 (delete "data:" |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
116 (copy-sequence thing-at-point-uri-schemes))) |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
117 "\\|") |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
118 "\\)" |
0ade01371c2e
(goto-address-url-regexp): Remove `data:' URLs from goto-address-url-regexp.
Eli Zaretskii <eliz@gnu.org>
parents:
64701
diff
changeset
|
119 thing-at-point-url-path-regexp) |
39568
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
120 ;; (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|" |
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
121 ;; "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:" |
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
122 ;; "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*" |
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
123 ;; "[-a-zA-Z0-9_=#$@~`%&*+|\\/]") |
28210 | 124 "A regular expression probably matching a URL.") |
125 | |
126 (defvar goto-address-highlight-keymap | |
127 (let ((m (make-sparse-keymap))) | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
128 (define-key m (if (featurep 'xemacs) (kbd "<button2>") (kbd "<mouse-2>")) |
62131
ae455ff58429
Paren typo again.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
62130
diff
changeset
|
129 'goto-address-at-point) |
37423
3ab2c865a8e5
Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents:
30891
diff
changeset
|
130 (define-key m (kbd "C-c RET") 'goto-address-at-point) |
28210 | 131 m) |
67914
f7b57b2971ba
(goto-address-highlight-keymap): Fix docstring.
Juri Linkov <juri@jurta.org>
parents:
67083
diff
changeset
|
132 "Keymap to hold goto-addr's mouse key defs under highlighted URLs.") |
28210 | 133 |
134 (defcustom goto-address-url-face 'bold | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
135 "Face to use for URLs." |
28210 | 136 :type 'face |
137 :group 'goto-address) | |
138 | |
139 (defcustom goto-address-url-mouse-face 'highlight | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
140 "Face to use for URLs when the mouse is on them." |
28210 | 141 :type 'face |
142 :group 'goto-address) | |
143 | |
144 (defcustom goto-address-mail-face 'italic | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
145 "Face to use for e-mail addresses." |
28210 | 146 :type 'face |
147 :group 'goto-address) | |
148 | |
149 (defcustom goto-address-mail-mouse-face 'secondary-selection | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
150 "Face to use for e-mail addresses when the mouse is on them." |
28210 | 151 :type 'face |
152 :group 'goto-address) | |
153 | |
154 (defun goto-address-fontify () | |
29664
3e03d72fadea
(goto-address-fontify): Use keymap property, not local-map.
Dave Love <fx@gnu.org>
parents:
29653
diff
changeset
|
155 "Fontify the URLs and e-mail addresses in the current buffer. |
28210 | 156 This function implements `goto-address-highlight-p' |
157 and `goto-address-fontify-p'." | |
30345
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
158 ;; Clean up from any previous go. |
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
159 (dolist (overlay (overlays-in (point-min) (point-max))) |
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
160 (if (overlay-get overlay 'goto-address) |
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
161 (delete-overlay overlay))) |
28210 | 162 (save-excursion |
30345
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
163 (let ((inhibit-point-motion-hooks t)) |
28210 | 164 (goto-char (point-min)) |
51098
9277afae9517
(goto-address-fontify-maximum-size): Value t means no limit.
Richard M. Stallman <rms@gnu.org>
parents:
49598
diff
changeset
|
165 (if (or (eq t goto-address-fontify-maximum-size) |
9277afae9517
(goto-address-fontify-maximum-size): Value t means no limit.
Richard M. Stallman <rms@gnu.org>
parents:
49598
diff
changeset
|
166 (< (- (point-max) (point)) goto-address-fontify-maximum-size)) |
28210 | 167 (progn |
168 (while (re-search-forward goto-address-url-regexp nil t) | |
169 (let* ((s (match-beginning 0)) | |
170 (e (match-end 0)) | |
171 (this-overlay (make-overlay s e))) | |
172 (and goto-address-fontify-p | |
173 (overlay-put this-overlay 'face goto-address-url-face)) | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
174 (overlay-put this-overlay 'evaporate t) |
28210 | 175 (overlay-put this-overlay |
176 'mouse-face goto-address-url-mouse-face) | |
67083
78a5a90bd7ec
(goto-address-fontify): Put `follow-link' property on mail and url overlays.
John Paul Wallington <jpw@pobox.com>
parents:
66695
diff
changeset
|
177 (overlay-put this-overlay 'follow-link t) |
28210 | 178 (overlay-put this-overlay |
56210
92bfc3abe98f
(goto-address-fontify): Fix help-echo text.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
179 'help-echo "mouse-2, C-c RET: follow URL") |
29209
67618bef1515
(goto-address-fontify): Add help-echo property.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
180 (overlay-put this-overlay |
30345
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
181 'keymap goto-address-highlight-keymap) |
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
182 (overlay-put this-overlay 'goto-address t))) |
28210 | 183 (goto-char (point-min)) |
184 (while (re-search-forward goto-address-mail-regexp nil t) | |
185 (let* ((s (match-beginning 0)) | |
186 (e (match-end 0)) | |
187 (this-overlay (make-overlay s e))) | |
188 (and goto-address-fontify-p | |
189 (overlay-put this-overlay 'face goto-address-mail-face)) | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
190 (overlay-put this-overlay 'evaporate t) |
28210 | 191 (overlay-put this-overlay 'mouse-face |
192 goto-address-mail-mouse-face) | |
67083
78a5a90bd7ec
(goto-address-fontify): Put `follow-link' property on mail and url overlays.
John Paul Wallington <jpw@pobox.com>
parents:
66695
diff
changeset
|
193 (overlay-put this-overlay 'follow-link t) |
29209
67618bef1515
(goto-address-fontify): Add help-echo property.
Dave Love <fx@gnu.org>
parents:
28210
diff
changeset
|
194 (overlay-put this-overlay |
56210
92bfc3abe98f
(goto-address-fontify): Fix help-echo text.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
195 'help-echo "mouse-2, C-c RET: mail this address") |
28210 | 196 (overlay-put this-overlay |
30345
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
197 'keymap goto-address-highlight-keymap) |
d24028985f3d
(goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents:
30285
diff
changeset
|
198 (overlay-put this-overlay 'goto-address t)))))))) |
28210 | 199 |
39568
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
200 ;; code to find and goto addresses; much of this has been blatantly |
e67950065cf9
Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
201 ;; snarfed from browse-url.el |
28210 | 202 |
203 ;;;###autoload | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
204 (define-obsolete-function-alias |
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
205 'goto-address-at-mouse 'goto-address-at-point "22.1") |
28210 | 206 |
207 ;;;###autoload | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
208 (defun goto-address-at-point (&optional event) |
28210 | 209 "Send to the e-mail address or load the URL at point. |
210 Send mail to address at point. See documentation for | |
211 `goto-address-find-address-at-point'. If no address is found | |
212 there, then load the URL at or before point." | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
213 (interactive (list last-input-event)) |
28210 | 214 (save-excursion |
67083
78a5a90bd7ec
(goto-address-fontify): Put `follow-link' property on mail and url overlays.
John Paul Wallington <jpw@pobox.com>
parents:
66695
diff
changeset
|
215 (if event (posn-set-point (event-end event))) |
28210 | 216 (let ((address (save-excursion (goto-address-find-address-at-point)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48068
diff
changeset
|
217 (if (and address |
37809
5bc4eff5115e
(goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents:
37423
diff
changeset
|
218 (save-excursion |
5bc4eff5115e
(goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents:
37423
diff
changeset
|
219 (goto-char (previous-single-char-property-change |
5bc4eff5115e
(goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents:
37423
diff
changeset
|
220 (point) 'goto-address nil |
5bc4eff5115e
(goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents:
37423
diff
changeset
|
221 (line-beginning-position))) |
5bc4eff5115e
(goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents:
37423
diff
changeset
|
222 (not (looking-at goto-address-url-regexp)))) |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
223 (compose-mail address) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
224 (let ((url (browse-url-url-at-point))) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
225 (if url |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
226 (browse-url url) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
227 (error "No e-mail address or URL found"))))))) |
28210 | 228 |
229 (defun goto-address-find-address-at-point () | |
230 "Find e-mail address around or before point. | |
231 Then search backwards to beginning of line for the start of an e-mail | |
30891
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
232 address. If no e-mail address found, return nil." |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
233 (re-search-backward "[^-_A-z0-9.@]" (line-beginning-position) 'lim) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
234 (if (or (looking-at goto-address-mail-regexp) ; already at start |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
235 (and (re-search-forward goto-address-mail-regexp |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
236 (line-end-position) 'lim) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
237 (goto-char (match-beginning 0)))) |
42ce5997aa4a
Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents:
30345
diff
changeset
|
238 (match-string-no-properties 0))) |
28210 | 239 |
240 ;;;###autoload | |
241 (defun goto-address () | |
242 "Sets up goto-address functionality in the current buffer. | |
243 Allows user to use mouse/keyboard command to click to go to a URL | |
244 or to send e-mail. | |
67914
f7b57b2971ba
(goto-address-highlight-keymap): Fix docstring.
Juri Linkov <juri@jurta.org>
parents:
67083
diff
changeset
|
245 By default, goto-address binds `goto-address-at-point' to mouse-2 and C-c RET |
f7b57b2971ba
(goto-address-highlight-keymap): Fix docstring.
Juri Linkov <juri@jurta.org>
parents:
67083
diff
changeset
|
246 only on URLs and e-mail addresses. |
28210 | 247 |
248 Also fontifies the buffer appropriately (see `goto-address-fontify-p' and | |
249 `goto-address-highlight-p' for more information)." | |
250 (interactive) | |
251 (if goto-address-highlight-p | |
252 (goto-address-fontify))) | |
71636
0fa81d575f41
* net/goto-addr.el (goto-address): Mark as safe for local evals.
Chong Yidong <cyd@stupidchicken.com>
parents:
68648
diff
changeset
|
253 ;;;###autoload(put 'goto-address 'safe-local-eval-function t) |
28210 | 254 |
255 (provide 'goto-addr) | |
256 | |
62130
109432f1fa94
(goto-address-fontify): Make sure the overlays
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59117
diff
changeset
|
257 ;; arch-tag: ca47c505-5661-425d-a471-62bc6e75cf0a |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37809
diff
changeset
|
258 ;;; goto-addr.el ends here |