annotate lisp/goto-addr.el @ 26165:cdd1c350aae9

Patches from rms.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 25 Oct 1999 11:06:44 +0000
parents 133e5c5c2e64
children a74c3ac8e0d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; goto-addr.el --- click to browse URL or to send to e-mail address
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13739
diff changeset
2
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
5 ;; Author: Eric Ding <ericding@mit.edu>
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Eric Ding <ericding@mit.edu>
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: 15 Aug 1995
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: mh-e, www, mouse, mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13739
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13739
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13739
diff changeset
25 ;; Boston, MA 02111-1307, USA.
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; This package allows you to click or hit a key sequence while on a
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; URL or e-mail address, and either load the URL into a browser of
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; your choice using the browse-url package, or if it's an e-mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; address, to send an e-mail to that address. By default, we bind to
13739
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
33 ;; the [mouse-2] and the [C-c return] key sequences.
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; INSTALLATION
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
37 ;; To use goto-address in a particular mode (for example, while
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
38 ;; reading mail in mh-e), add something like this in your .emacs file:
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; (add-hook 'mh-show-mode-hook 'goto-address)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; By default, goto-address now sends using `mail' instead of `mh-send'.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; To use mh-e to send mail, add the following to your .emacs file:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
15028
4572159ddf04 (goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents: 14208
diff changeset
45 ;; (setq goto-address-mail-method 'goto-address-send-using-mh-e)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;
13739
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
47 ;; The mouse click method is bound to [mouse-2] on highlighted URL's or
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
48 ;; e-mail addresses only; it functions normally everywhere else. To bind
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
49 ;; another mouse click to the function, add the following to your .emacs
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
50 ;; (for example):
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;
13739
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
52 ;; (setq goto-address-highlight-keymap
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
53 ;; (let ((m (make-sparse-keymap)))
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
54 ;; (define-key m [S-mouse-2] 'goto-address-at-mouse)
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
55 ;; m))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; BUG REPORTS
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; Please send bug reports to me at ericding@mit.edu.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; Known bugs/features:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing,
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; not stuff like X.400 addresses, etc.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; * regexp also catches Message-Id line, since it is in the format of
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; an Internet e-mail address (like Compuserve addresses)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; * If show buffer is fontified after goto-address-fontify is run
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; (say, using font-lock-fontify-buffer), then font-lock face will
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; override goto-address faces.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; Code:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (require 'browse-url)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
75 (defgroup goto-address nil
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
76 "Click to browse URL or to send to e-mail address."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
77 :group 'mouse
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
78 :group 'hypermedia)
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
79
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
80
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
81 ;;; I don't expect users to want fontify'ing without highlighting.
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
82 (defcustom goto-address-fontify-p t
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
83 "*If t, URL's and e-mail addresses in buffer are fontified.
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
84 But only if `goto-address-highlight-p' is also non-nil."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
85 :type 'boolean
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
86 :group 'goto-address)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
88 (defcustom goto-address-highlight-p t
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
89 "*If t, URL's and e-mail addresses in buffer are highlighted."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
90 :type 'boolean
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
91 :group 'goto-address)
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
92
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
93 (defcustom goto-address-fontify-maximum-size 30000
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
94 "*Maximum size of file in which to fontify and/or highlight URL's."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
95 :type 'integer
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
96 :group 'goto-address)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defvar goto-address-mail-regexp
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "A regular expression probably matching an e-mail address.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defvar goto-address-url-regexp
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 "A regular expression probably matching a URL.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
109 (defcustom goto-address-mail-method
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 'goto-address-send-using-mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 "*Function to compose mail.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 Two pre-made functions are `goto-address-send-using-mail' (sendmail);
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
113 and `goto-address-send-using-mh-e' (MH-E)."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
114 :type 'function
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
115 :group 'goto-address)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
13739
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
117 (defvar goto-address-highlight-keymap
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
118 (let ((m (make-sparse-keymap)))
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
119 (define-key m [mouse-2] 'goto-address-at-mouse)
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
120 m)
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
121 "keymap to hold goto-addr's mouse key defs under highlighted URLs.")
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
122
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
123 (defcustom goto-address-url-face 'bold
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
124 "*Face to use for URLs."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
125 :type 'face
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
126 :group 'goto-address)
15502
5053b03d18cb (goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents: 15028
diff changeset
127
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
128 (defcustom goto-address-url-mouse-face 'highlight
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
129 "*Face to use for URLs when the mouse is on them."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
130 :type 'face
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
131 :group 'goto-address)
15502
5053b03d18cb (goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents: 15028
diff changeset
132
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
133 (defcustom goto-address-mail-face 'italic
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
134 "*Face to use for e-mail addresses."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
135 :type 'face
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
136 :group 'goto-address)
15502
5053b03d18cb (goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents: 15028
diff changeset
137
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
138 (defcustom goto-address-mail-mouse-face 'secondary-selection
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
139 "*Face to use for e-mail addresses when the mouse is on them."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
140 :type 'face
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 16661
diff changeset
141 :group 'goto-address)
15502
5053b03d18cb (goto-address-url-face, goto-address-mail-face)
Richard M. Stallman <rms@gnu.org>
parents: 15028
diff changeset
142
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defun goto-address-fontify ()
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
144 "Fontify the URL's and e-mail addresses in the current buffer.
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
145 This function implements `goto-address-highlight-p'
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
146 and `goto-address-fontify-p'."
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (let ((inhibit-read-only t)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
149 (inhibit-point-motion-hooks t)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (modified (buffer-modified-p)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (progn
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (while (re-search-forward goto-address-url-regexp nil t)
16661
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
155 (let* ((s (match-beginning 0))
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
156 (e (match-end 0))
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
157 (this-overlay (make-overlay s e)))
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
158 (and goto-address-fontify-p
16661
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
159 (overlay-put this-overlay 'face goto-address-url-face))
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
160 (overlay-put this-overlay
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
161 'mouse-face goto-address-url-mouse-face)
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
162 (overlay-put this-overlay
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
163 'local-map goto-address-highlight-keymap)))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (while (re-search-forward goto-address-mail-regexp nil t)
16661
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
166 (let* ((s (match-beginning 0))
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
167 (e (match-end 0))
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
168 (this-overlay (make-overlay s e)))
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
169 (and goto-address-fontify-p
16661
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
170 (overlay-put this-overlay 'face goto-address-mail-face))
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
171 (overlay-put this-overlay 'mouse-face
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
172 goto-address-mail-mouse-face)
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
173 (overlay-put this-overlay
22c70a622b67 (goto-address-fontify): Use overlay, not text props.
Richard M. Stallman <rms@gnu.org>
parents: 15502
diff changeset
174 'local-map goto-address-highlight-keymap)))))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (and (buffer-modified-p)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (not modified)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (set-buffer-modified-p nil)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;;; code to find and goto addresses; much of this has been blatantly
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;;; snarfed from browse-url.el
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
14208
1f2f55478197 (goto-address-at-point, goto-address-at-mouse): Add autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
182 ;;;###autoload
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (defun goto-address-at-mouse (event)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 "Send to the e-mail address or load the URL clicked with the mouse.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 Send mail to address at position of mouse click. See documentation for
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 `goto-address-find-address-at-point'. If no address is found
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 there, then load the URL at or before the position of the mouse click."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (interactive "e")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (let ((posn (event-start event)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (set-buffer (window-buffer (posn-window posn)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (goto-char (posn-point posn))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (let ((address
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (save-excursion (goto-address-find-address-at-point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (if (string-equal address "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (let ((url (browse-url-url-at-point)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (if (string-equal url "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (error "No e-mail address or URL found")
23609
133e5c5c2e64 (goto-address-at-point, goto-address-at-mouse):
Dave Love <fx@gnu.org>
parents: 17634
diff changeset
199 (browse-url url)))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (funcall goto-address-mail-method address))))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
14208
1f2f55478197 (goto-address-at-point, goto-address-at-mouse): Add autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
202 ;;;###autoload
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (defun goto-address-at-point ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 "Send to the e-mail address or load the URL at point.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 Send mail to address at point. See documentation for
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 `goto-address-find-address-at-point'. If no address is found
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 there, then load the URL at or before point."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (interactive)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (let ((address (save-excursion (goto-address-find-address-at-point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (if (string-equal address "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (let ((url (browse-url-url-at-point)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (if (string-equal url "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (error "No e-mail address or URL found")
23609
133e5c5c2e64 (goto-address-at-point, goto-address-at-mouse):
Dave Love <fx@gnu.org>
parents: 17634
diff changeset
215 (browse-url url)))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (funcall goto-address-mail-method address)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (defun goto-address-find-address-at-point ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 "Find e-mail address around or before point.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 Then search backwards to beginning of line for the start of an e-mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 address. If no e-mail address found, return the empty string."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (let ((bol (save-excursion (beginning-of-line) (point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (re-search-backward "[^-_A-z0-9.@]" bol 'lim)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (if (or (looking-at goto-address-mail-regexp) ; already at start
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (let ((eol (save-excursion (end-of-line) (point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (and (re-search-forward goto-address-mail-regexp eol 'lim)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (goto-char (match-beginning 0)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (buffer-substring (match-beginning 0) (match-end 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 "")))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
15028
4572159ddf04 (goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents: 14208
diff changeset
231 (defun goto-address-send-using-mh-e (to)
4572159ddf04 (goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents: 14208
diff changeset
232 (require 'mh-comp)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (mh-find-path)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (let ((cc (mh-read-address "Cc: "))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (subject (read-string "Subject: "))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (config (current-window-configuration)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (delete-other-windows)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (mh-send-sub to cc subject config)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
15028
4572159ddf04 (goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents: 14208
diff changeset
240 (fset 'goto-address-send-using-mhe 'goto-address-send-using-mh-e)
4572159ddf04 (goto-address-send-using-mh-e):
Richard M. Stallman <rms@gnu.org>
parents: 14208
diff changeset
241
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (defun goto-address-send-using-mail (to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (mail-other-window nil to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (and (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (end-of-line 2)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
247 ;;;###autoload
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (defun goto-address ()
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
249 "Sets up goto-address functionality in the current buffer.
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
250 Allows user to use mouse/keyboard command to click to go to a URL
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
251 or to send e-mail.
13739
f6fa5b68f9c7 Mouse-click method now bound using text
Karl Heuer <kwzh@gnu.org>
parents: 13550
diff changeset
252 By default, goto-address binds to mouse-2 and C-c RET.
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
253
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
254 Also fontifies the buffer appropriately (see `goto-address-fontify-p' and
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
255 `goto-address-highlight-p' for more information)."
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (interactive)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (local-set-key "\C-c\r" 'goto-address-at-point)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
258 (if goto-address-highlight-p
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (goto-address-fontify)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (provide 'goto-addr)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;;; goto-addr.el ends here.