Add `extensions' to keywords, since it's internal.
[bpt/emacs.git] / lisp / net / goto-addr.el
index 2cf502b..21f027a 100644 (file)
@@ -1,9 +1,9 @@
 ;;; goto-addr.el --- click to browse URL or to send to e-mail address
 
-;; Copyright (C) 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2000 Free Software Foundation, Inc.
 
-;; Author: Eric Ding <ericding@mit.edu>
-;; Maintainer: Eric Ding <ericding@mit.edu>
+;; Author: Eric Ding <ericding@alum.mit.edu>
+;; Maintainer: FSF
 ;; Created: 15 Aug 1995
 ;; Keywords: mh-e, www, mouse, mail
 
@@ -39,7 +39,7 @@
 ;;
 ;; (add-hook 'mh-show-mode-hook 'goto-address)
 ;;
-;; The mouse click method is bound to [mouse-2] on highlighted URL's or
+;; The mouse click method is bound to [mouse-2] on highlighted URLs or
 ;; e-mail addresses only; it functions normally everywhere else.  To bind
 ;; another mouse click to the function, add the following to your .emacs
 ;; (for example):
 ;;     m))
 ;;
 
-;; BUG REPORTS
-;;
-;; Please send bug reports to me at ericding@mit.edu.
-
 ;; Known bugs/features:
 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing,
 ;;   not stuff like X.400 addresses, etc.
 ;; * regexp also catches Message-Id line, since it is in the format of
 ;;   an Internet e-mail address (like Compuserve addresses)
-;; * If show buffer is fontified after goto-address-fontify is run
-;;   (say, using font-lock-fontify-buffer), then font-lock face will
+;; * If the buffer is fontified after goto-address-fontify is run
+;;   (say, using font-lock-fontify-buffer), then font-lock faces will
 ;;   override goto-address faces.
 
 ;;; Code:
 
 ;;; I don't expect users to want fontify'ing without highlighting.
 (defcustom goto-address-fontify-p t
-  "*If t, URL's and e-mail addresses in buffer are fontified.
+  "*If t, URLs and e-mail addresses in buffer are fontified.
 But only if `goto-address-highlight-p' is also non-nil."
   :type 'boolean
   :group 'goto-address)
 
 (defcustom goto-address-highlight-p t
-  "*If t, URL's and e-mail addresses in buffer are highlighted."
+  "*If t, URLs and e-mail addresses in buffer are highlighted."
   :type 'boolean
   :group 'goto-address)
 
 (defcustom goto-address-fontify-maximum-size 30000
-  "*Maximum size of file in which to fontify and/or highlight URL's."
+  "*Maximum size of file in which to fontify and/or highlight URLs."
   :type 'integer
   :group 'goto-address)
 
@@ -104,6 +100,7 @@ But only if `goto-address-highlight-p' is also non-nil."
 (defvar goto-address-highlight-keymap
   (let ((m (make-sparse-keymap)))
     (define-key m [mouse-2] 'goto-address-at-mouse)
+    (define-key m "\C-c\r" 'goto-address-at-point)
     m)
   "keymap to hold goto-addr's mouse key defs under highlighted URLs.")
 
@@ -128,13 +125,15 @@ But only if `goto-address-highlight-p' is also non-nil."
   :group 'goto-address)
 
 (defun goto-address-fontify ()
-  "Fontify the URL's and e-mail addresses in the current buffer.
+  "Fontify the URLs and e-mail addresses in the current buffer.
 This function implements `goto-address-highlight-p'
 and `goto-address-fontify-p'."
+  ;; Clean up from any previous go.
+  (dolist (overlay (overlays-in (point-min) (point-max)))
+    (if (overlay-get overlay 'goto-address)
+       (delete-overlay overlay)))
   (save-excursion
-    (let ((inhibit-read-only t)
-         (inhibit-point-motion-hooks t)
-         (modified (buffer-modified-p)))
+    (let ((inhibit-point-motion-hooks t))
       (goto-char (point-min))
       (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
          (progn
@@ -147,7 +146,10 @@ and `goto-address-fontify-p'."
                (overlay-put this-overlay
                              'mouse-face goto-address-url-mouse-face)
                (overlay-put this-overlay
-                             'local-map goto-address-highlight-keymap)))
+                            'help-echo "mouse-2: follow URL")
+               (overlay-put this-overlay
+                             'keymap goto-address-highlight-keymap)
+               (overlay-put this-overlay 'goto-address t)))
            (goto-char (point-min))
            (while (re-search-forward goto-address-mail-regexp nil t)
               (let* ((s (match-beginning 0))
@@ -157,11 +159,11 @@ and `goto-address-fontify-p'."
                      (overlay-put this-overlay 'face goto-address-mail-face))
                 (overlay-put this-overlay 'mouse-face
                              goto-address-mail-mouse-face)
+               (overlay-put this-overlay
+                            'help-echo "mouse-2: follow URL")
                 (overlay-put this-overlay
-                             'local-map goto-address-highlight-keymap)))))
-      (and (buffer-modified-p)
-          (not modified)
-          (set-buffer-modified-p nil)))))
+                             'keymap goto-address-highlight-keymap)
+               (overlay-put this-overlay 'goto-address t))))))))
 
 ;;; code to find and goto addresses; much of this has been blatantly
 ;;; snarfed from browse-url.el
@@ -225,7 +227,6 @@ By default, goto-address binds to mouse-2 and C-c RET.
 Also fontifies the buffer appropriately (see `goto-address-fontify-p' and
 `goto-address-highlight-p' for more information)."
   (interactive)
-  (local-set-key "\C-c\r" 'goto-address-at-point)
   (if goto-address-highlight-p
       (goto-address-fontify)))