aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-12-15 21:19:29 +0000
committerKarl Heuer1995-12-15 21:19:29 +0000
commit7caa5416572dbfc0fb0376ea67a25d6aee5faa9f (patch)
treec9aeae09627182ab1e91f72ea0372fb5dda64bf1
parentc7608a53b0919fd7d55a29d1198f77fb3bbe3a59 (diff)
downloademacs-7caa5416572dbfc0fb0376ea67a25d6aee5faa9f.tar.gz
emacs-7caa5416572dbfc0fb0376ea67a25d6aee5faa9f.zip
Mouse-click method now bound using text
properties rather than local-set-key
-rw-r--r--lisp/goto-addr.el51
1 files changed, 28 insertions, 23 deletions
diff --git a/lisp/goto-addr.el b/lisp/goto-addr.el
index 8a14bbbdc5c..975c0ee216e 100644
--- a/lisp/goto-addr.el
+++ b/lisp/goto-addr.el
@@ -28,7 +28,7 @@
28;; 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
29;; 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
30;; 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
31;; the [S-mouse-2] and the [C-c return] key sequences. 31;; the [mouse-2] and the [C-c return] key sequences.
32 32
33;; INSTALLATION 33;; INSTALLATION
34;; 34;;
@@ -42,20 +42,16 @@
42;; 42;;
43;; (setq goto-address-mail-method 'goto-address-send-using-mhe) 43;; (setq goto-address-mail-method 'goto-address-send-using-mhe)
44;; 44;;
45;; To rebind, for example, the mouse click method to [mouse-2] in 45;; The mouse click method is bound to [mouse-2] on highlighted URL's or
46;; mh-show-mode, add the following (instead of the first add-hook example 46;; e-mail addresses only; it functions normally everywhere else. To bind
47;; above) to your .emacs file: 47;; another mouse click to the function, add the following to your .emacs
48;; (for example):
48;; 49;;
49;; (defun my-goto-address () 50;; (setq goto-address-highlight-keymap
50;; (goto-address) 51;; (let ((m (make-sparse-keymap)))
51;; (local-unset-key [S-mouse-2]) 52;; (define-key m [S-mouse-2] 'goto-address-at-mouse)
52;; (local-set-key [mouse-2] 'goto-address-at-mouse)) 53;; m))
53;; 54;;
54;; (add-hook 'mh-show-mode-hook 'my-goto-address)
55;;
56;; [mouse-2] is not the default mouse binding because I use goto-address in
57;; some editable buffers, where [mouse-2] means mouse-yank-at-click, as well
58;; as in some modes where [mouse-2] is bound to other useful functions.
59 55
60;; BUG REPORTS 56;; BUG REPORTS
61;; 57;;
@@ -102,6 +98,12 @@ But only if `goto-address-highlight-p' is also non-nil.")
102Two pre-made functions are `goto-address-send-using-mail' (sendmail); 98Two pre-made functions are `goto-address-send-using-mail' (sendmail);
103and `goto-address-send-using-mhe' (MH-E).") 99and `goto-address-send-using-mhe' (MH-E).")
104 100
101(defvar goto-address-highlight-keymap
102 (let ((m (make-sparse-keymap)))
103 (define-key m [mouse-2] 'goto-address-at-mouse)
104 m)
105 "keymap to hold goto-addr's mouse key defs under highlighted URLs.")
106
105(defun goto-address-fontify () 107(defun goto-address-fontify ()
106 "Fontify the URL's and e-mail addresses in the current buffer. 108 "Fontify the URL's and e-mail addresses in the current buffer.
107This function implements `goto-address-highlight-p' 109This function implements `goto-address-highlight-p'
@@ -114,22 +116,26 @@ and `goto-address-fontify-p'."
114 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size) 116 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
115 (progn 117 (progn
116 (while (re-search-forward goto-address-url-regexp nil t) 118 (while (re-search-forward goto-address-url-regexp nil t)
117 (progn 119 (let ((s (match-beginning 0))
118 (goto-char (match-end 0)) 120 (e (match-end 0)))
121 (goto-char e)
119 (and goto-address-fontify-p 122 (and goto-address-fontify-p
120 (put-text-property (match-beginning 0) (match-end 0) 123 (put-text-property s e 'face 'bold))
121 'face 'bold)) 124 (put-text-property s e 'mouse-face 'highlight)
122 (put-text-property (match-beginning 0) (match-end 0) 125 (put-text-property
123 'mouse-face 'highlight))) 126 s e 'local-map goto-address-highlight-keymap)))
124 (goto-char (point-min)) 127 (goto-char (point-min))
125 (while (re-search-forward goto-address-mail-regexp nil t) 128 (while (re-search-forward goto-address-mail-regexp nil t)
126 (progn 129 (let ((s (match-beginning 0))
130 (e (match-end 0)))
127 (goto-char (match-end 0)) 131 (goto-char (match-end 0))
128 (and goto-address-fontify-p 132 (and goto-address-fontify-p
129 (put-text-property (match-beginning 0) (match-end 0) 133 (put-text-property (match-beginning 0) (match-end 0)
130 'face 'italic)) 134 'face 'italic))
131 (put-text-property (match-beginning 0) (match-end 0) 135 (put-text-property (match-beginning 0) (match-end 0)
132 'mouse-face 'secondary-selection))))) 136 'mouse-face 'secondary-selection)
137 (put-text-property
138 s e 'local-map goto-address-highlight-keymap)))))
133 (and (buffer-modified-p) 139 (and (buffer-modified-p)
134 (not modified) 140 (not modified)
135 (set-buffer-modified-p nil))))) 141 (set-buffer-modified-p nil)))))
@@ -202,12 +208,11 @@ address. If no e-mail address found, return the empty string."
202 "Sets up goto-address functionality in the current buffer. 208 "Sets up goto-address functionality in the current buffer.
203Allows user to use mouse/keyboard command to click to go to a URL 209Allows user to use mouse/keyboard command to click to go to a URL
204or to send e-mail. 210or to send e-mail.
205By default, goto-address binds to S-mouse-2 and C-c RET. 211By default, goto-address binds to mouse-2 and C-c RET.
206 212
207Also fontifies the buffer appropriately (see `goto-address-fontify-p' and 213Also fontifies the buffer appropriately (see `goto-address-fontify-p' and
208`goto-address-highlight-p' for more information)." 214`goto-address-highlight-p' for more information)."
209 (interactive) 215 (interactive)
210 (local-set-key [S-mouse-2] 'goto-address-at-mouse)
211 (local-set-key "\C-c\r" 'goto-address-at-point) 216 (local-set-key "\C-c\r" 'goto-address-at-point)
212 (if goto-address-highlight-p 217 (if goto-address-highlight-p
213 (goto-address-fontify))) 218 (goto-address-fontify)))