diff options
| author | Richard M. Stallman | 1995-11-15 05:03:42 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-11-15 05:03:42 +0000 |
| commit | e137161b7886b2c95e040ca99cd752b77d8165a4 (patch) | |
| tree | f336dcc3b2997caf9428f8a7b6b8dd3239cd42d6 | |
| parent | 86ddc17c9cfa5938287cd9507e083ebb76547741 (diff) | |
| download | emacs-e137161b7886b2c95e040ca99cd752b77d8165a4.tar.gz emacs-e137161b7886b2c95e040ca99cd752b77d8165a4.zip | |
(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.
| -rw-r--r-- | lisp/goto-addr.el | 82 |
1 files changed, 38 insertions, 44 deletions
diff --git a/lisp/goto-addr.el b/lisp/goto-addr.el index f338cdcf10e..8a14bbbdc5c 100644 --- a/lisp/goto-addr.el +++ b/lisp/goto-addr.el | |||
| @@ -1,6 +1,7 @@ | |||
| 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 |
| @@ -27,21 +28,12 @@ | |||
| 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 | ;; |
| @@ -56,7 +48,7 @@ | |||
| 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) |
| @@ -78,17 +70,20 @@ | |||
| 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]+" |
| @@ -108,46 +103,37 @@ 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) | ||
| 134 | 'face 'italic) | ||
| 135 | (put-text-property (match-beginning 0) (match-end 0) | 129 | (put-text-property (match-beginning 0) (match-end 0) |
| 136 | 'mouse-face 'secondary-selection)))))) | 130 | 'face 'italic)) |
| 131 | (put-text-property (match-beginning 0) (match-end 0) | ||
| 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 | 136 | ||
| 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 | |||
| 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 | ||
| @@ -211,11 +197,19 @@ address. If no e-mail address found, return the empty string." | |||
| 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) |