comparison lisp/goto-addr.el @ 13550:06e46fbae7f0

(goto-address-highlight-p): New variable. (goto-address-fontify): Removed check for invisible text, set inhibit-point-motion-hooks instead (goto-address): Use S-mouse-2, not S-mouse-1. Add autoload cookie.
author Richard M. Stallman <rms@gnu.org>
date Wed, 15 Nov 1995 05:03:42 +0000
parents 7a20f2bb5ac9
children f6fa5b68f9c7
comparison
equal deleted inserted replaced
13549:f8afa95d197e 13550:06e46fbae7f0
1 ;;; goto-addr.el --- click to browse URL or to send to e-mail address 1 ;;; goto-addr.el --- click to browse URL or to send to e-mail address
2 ;; Copyright (C) 1995 Free Software Foundation, Inc. 2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
3 3
4 ;; Author: Eric Ding <ericding@mit.edu>
4 ;; Maintainer: Eric Ding <ericding@mit.edu> 5 ;; Maintainer: Eric Ding <ericding@mit.edu>
5 ;; Created: 15 Aug 1995 6 ;; Created: 15 Aug 1995
6 ;; Keywords: mh-e, www, mouse, mail 7 ;; Keywords: mh-e, www, mouse, mail
7 8
8 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
25 26
26 ;; This package allows you to click or hit a key sequence while on a 27 ;; This package allows you to click or hit a key sequence while on a
27 ;; URL or e-mail address, and either load the URL into a browser of 28 ;; URL or e-mail address, and either load the URL into a browser of
28 ;; your choice using the browse-url package, or if it's an e-mail 29 ;; your choice using the browse-url package, or if it's an e-mail
29 ;; address, to send an e-mail to that address. By default, we bind to 30 ;; address, to send an e-mail to that address. By default, we bind to
30 ;; the [S-mouse-1] and the [C-c return] key sequences. 31 ;; the [S-mouse-2] and the [C-c return] key sequences.
31 ;;
32 ;; You will also need the browse-url.el package to use goto-address.
33 ;; You can find it at <URL:http://wombat.doc.ic.ac.uk/emacs/browse-url.el>.
34 32
35 ;; INSTALLATION 33 ;; INSTALLATION
36 ;; 34 ;;
37 ;; To install goto-address, put goto-addr.el somewhere in 35 ;; To use goto-address in a particular mode (for example, while
38 ;; your load-path and add the following to your .emacs file: 36 ;; reading mail in mh-e), add something like this in your .emacs file:
39 ;;
40 ;; (autoload 'goto-address "goto-addr"
41 ;; "Set up buffer to click to browse URL or to send to e-mail address" t)
42 ;;
43 ;; To use it in a particular mode (for example, while reading mail in
44 ;; mh-e), add something like this in your .emacs file:
45 ;; 37 ;;
46 ;; (add-hook 'mh-show-mode-hook 'goto-address) 38 ;; (add-hook 'mh-show-mode-hook 'goto-address)
47 ;; 39 ;;
48 ;; By default, goto-address now sends using `mail' instead of `mh-send'. 40 ;; By default, goto-address now sends using `mail' instead of `mh-send'.
49 ;; To use mh-e to send mail, add the following to your .emacs file: 41 ;; To use mh-e to send mail, add the following to your .emacs file:
54 ;; mh-show-mode, add the following (instead of the first add-hook example 46 ;; mh-show-mode, add the following (instead of the first add-hook example
55 ;; above) to your .emacs file: 47 ;; above) to your .emacs file:
56 ;; 48 ;;
57 ;; (defun my-goto-address () 49 ;; (defun my-goto-address ()
58 ;; (goto-address) 50 ;; (goto-address)
59 ;; (local-unset-key [S-mouse-1]) 51 ;; (local-unset-key [S-mouse-2])
60 ;; (local-set-key [mouse-2] 'goto-address-at-mouse)) 52 ;; (local-set-key [mouse-2] 'goto-address-at-mouse))
61 ;; 53 ;;
62 ;; (add-hook 'mh-show-mode-hook 'my-goto-address) 54 ;; (add-hook 'mh-show-mode-hook 'my-goto-address)
63 ;; 55 ;;
64 ;; [mouse-2] is not the default mouse binding because I use goto-address in 56 ;; [mouse-2] is not the default mouse binding because I use goto-address in
76 ;; an Internet e-mail address (like Compuserve addresses) 68 ;; an Internet e-mail address (like Compuserve addresses)
77 ;; * If show buffer is fontified after goto-address-fontify is run 69 ;; * If show buffer is fontified after goto-address-fontify is run
78 ;; (say, using font-lock-fontify-buffer), then font-lock face will 70 ;; (say, using font-lock-fontify-buffer), then font-lock face will
79 ;; override goto-address faces. 71 ;; override goto-address faces.
80 72
81 ;;; Change log:
82
83 ;;; Code: 73 ;;; Code:
84 74
85 (require 'browse-url) 75 (require 'browse-url)
86 76
77 ;;; I don't expect users to want fontify'ing without highlighting.
87 (defvar goto-address-fontify-p t 78 (defvar goto-address-fontify-p t
88 "*If t, URL's and e-mail address in buffer are fontified.") 79 "*If t, URL's and e-mail addresses in buffer are fontified.
80 But only if `goto-address-highlight-p' is also non-nil.")
81
82 (defvar goto-address-highlight-p t
83 "*If t, URL's and e-mail addresses in buffer are highlighted.")
89 84
90 (defvar goto-address-fontify-maximum-size 30000 85 (defvar goto-address-fontify-maximum-size 30000
91 "*Maximum size of file in which to fontify URL's.") 86 "*Maximum size of file in which to fontify and/or highlight URL's.")
92 87
93 (defvar goto-address-mail-regexp 88 (defvar goto-address-mail-regexp
94 "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+" 89 "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+"
95 "A regular expression probably matching an e-mail address.") 90 "A regular expression probably matching an e-mail address.")
96 91
106 "*Function to compose mail. 101 "*Function to compose mail.
107 Two pre-made functions are `goto-address-send-using-mail' (sendmail); 102 Two pre-made functions are `goto-address-send-using-mail' (sendmail);
108 and `goto-address-send-using-mhe' (MH-E).") 103 and `goto-address-send-using-mhe' (MH-E).")
109 104
110 (defun goto-address-fontify () 105 (defun goto-address-fontify ()
111 "Fontify the URL's and e-mail addresses in the current buffer." 106 "Fontify the URL's and e-mail addresses in the current buffer.
107 This function implements `goto-address-highlight-p'
108 and `goto-address-fontify-p'."
112 (save-excursion 109 (save-excursion
113 (let ((inhibit-read-only t) 110 (let ((inhibit-read-only t)
111 (inhibit-point-motion-hooks t)
114 (modified (buffer-modified-p))) 112 (modified (buffer-modified-p)))
115 (goto-char (point-min)) 113 (goto-char (point-min))
116 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size) 114 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
117 (progn 115 (progn
118 (while (re-search-forward goto-address-url-regexp nil t) 116 (while (re-search-forward goto-address-url-regexp nil t)
119 ;; if text is invisible, we ignore it 117 (progn
120 (and (goto-address-skip-invisible (match-beginning 0)) 118 (goto-char (match-end 0))
121 (progn 119 (and goto-address-fontify-p
122 (goto-char (match-end 0))
123 (put-text-property (match-beginning 0) (match-end 0) 120 (put-text-property (match-beginning 0) (match-end 0)
124 'face 'bold) 121 'face 'bold))
125 (put-text-property (match-beginning 0) (match-end 0) 122 (put-text-property (match-beginning 0) (match-end 0)
126 'mouse-face 'highlight)))) 123 'mouse-face 'highlight)))
127 (goto-char (point-min)) 124 (goto-char (point-min))
128 (while (re-search-forward goto-address-mail-regexp nil t) 125 (while (re-search-forward goto-address-mail-regexp nil t)
129 ;; if text is invisible, we ignore it 126 (progn
130 (and (goto-address-skip-invisible (match-beginning 0)) 127 (goto-char (match-end 0))
131 (progn 128 (and goto-address-fontify-p
132 (goto-char (match-end 0))
133 (put-text-property (match-beginning 0) (match-end 0) 129 (put-text-property (match-beginning 0) (match-end 0)
134 'face 'italic) 130 'face 'italic))
135 (put-text-property (match-beginning 0) (match-end 0) 131 (put-text-property (match-beginning 0) (match-end 0)
136 'mouse-face 'secondary-selection)))))) 132 'mouse-face 'secondary-selection)))))
137 (and (buffer-modified-p) 133 (and (buffer-modified-p)
138 (not modified) 134 (not modified)
139 (set-buffer-modified-p nil))))) 135 (set-buffer-modified-p nil)))))
140
141 (defun goto-address-skip-invisible (char)
142 "If char is not invisible, then return t. Otherwise, move forward in buffer
143 until a non-invisible char is found, goto that position, and return nil."
144 (if (get-text-property char 'invisible)
145 (let ((char (1+ char)))
146 (while (get-text-property char 'invisible)
147 (setq char (1+ char))
148 (goto-char char)))
149 t))
150 136
151 ;;; code to find and goto addresses; much of this has been blatantly 137 ;;; code to find and goto addresses; much of this has been blatantly
152 ;;; snarfed from browse-url.el 138 ;;; snarfed from browse-url.el
153 139
154 (defun goto-address-at-mouse (event) 140 (defun goto-address-at-mouse (event)
209 (defun goto-address-send-using-mail (to) 195 (defun goto-address-send-using-mail (to)
210 (mail-other-window nil to) 196 (mail-other-window nil to)
211 (and (goto-char (point-min)) 197 (and (goto-char (point-min))
212 (end-of-line 2))) 198 (end-of-line 2)))
213 199
200 ;;;###autoload
214 (defun goto-address () 201 (defun goto-address ()
202 "Sets up goto-address functionality in the current buffer.
203 Allows user to use mouse/keyboard command to click to go to a URL
204 or to send e-mail.
205 By default, goto-address binds to S-mouse-2 and C-c RET.
206
207 Also fontifies the buffer appropriately (see `goto-address-fontify-p' and
208 `goto-address-highlight-p' for more information)."
215 (interactive) 209 (interactive)
216 (local-set-key [S-mouse-1] 'goto-address-at-mouse) 210 (local-set-key [S-mouse-2] 'goto-address-at-mouse)
217 (local-set-key "\C-c\r" 'goto-address-at-point) 211 (local-set-key "\C-c\r" 'goto-address-at-point)
218 (if goto-address-fontify-p 212 (if goto-address-highlight-p
219 (goto-address-fontify))) 213 (goto-address-fontify)))
220 214
221 (provide 'goto-addr) 215 (provide 'goto-addr)
222 216
223 ;;; goto-addr.el ends here. 217 ;;; goto-addr.el ends here.