annotate lisp/goto-addr.el @ 13299:d6bfe124472c

General reorganisation; moving and renaming etc. Addition to font-lock-keywords; MATCH-ANCHORED structure and OVERRIDE values. font-lock-fontify-anchored-keywords written to use the former, font-lock-apply-highlight modified to use the latter.
author Simon Marshall <simon@gnu.org>
date Thu, 26 Oct 1995 13:27:36 +0000
parents 7a20f2bb5ac9
children 06e46fbae7f0
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
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Maintainer: Eric Ding <ericding@mit.edu>
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Created: 15 Aug 1995
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mh-e, www, mouse, mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
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 ;; GNU Emacs is free software; you can redistribute it and/or modify
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; 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
12 ;; the Free Software Foundation; either version 2, or (at your option)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; 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
27 ;; 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
28 ;; 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
29 ;; address, to send an e-mail to that address. By default, we bind to
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; the [S-mouse-1] and the [C-c return] key sequences.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; You will also need the browse-url.el package to use goto-address.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; You can find it at <URL:http://wombat.doc.ic.ac.uk/emacs/browse-url.el>.
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 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; To install goto-address, put goto-addr.el somewhere in
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; your load-path and add the following to your .emacs file:
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 ;; (autoload 'goto-address "goto-addr"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; "Set up buffer to click to browse URL or to send to e-mail address" t)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; To use it in a particular mode (for example, while reading mail in
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; mh-e), add something like this in your .emacs file:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; (add-hook 'mh-show-mode-hook 'goto-address)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; By default, goto-address now sends using `mail' instead of `mh-send'.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; 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
50 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; (setq goto-address-mail-method 'goto-address-send-using-mhe)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; To rebind, for example, the mouse click method to [mouse-2] in
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; mh-show-mode, add the following (instead of the first add-hook example
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; above) to your .emacs file:
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 ;; (defun my-goto-address ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; (goto-address)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; (local-unset-key [S-mouse-1])
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; (local-set-key [mouse-2] 'goto-address-at-mouse))
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 ;; (add-hook 'mh-show-mode-hook 'my-goto-address)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; [mouse-2] is not the default mouse binding because I use goto-address in
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; some editable buffers, where [mouse-2] means mouse-yank-at-click, as well
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; as in some modes where [mouse-2] is bound to other useful functions.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; BUG REPORTS
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; Please send bug reports to me at ericding@mit.edu.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; Known bugs/features:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing,
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; not stuff like X.400 addresses, etc.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; * 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
76 ;; an Internet e-mail address (like Compuserve addresses)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; * If show buffer is fontified after goto-address-fontify is run
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; (say, using font-lock-fontify-buffer), then font-lock face will
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; override goto-address faces.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; Change log:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;; Code:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (require 'browse-url)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (defvar goto-address-fontify-p t
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 "*If t, URL's and e-mail address in buffer are fontified.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defvar goto-address-fontify-maximum-size 30000
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 "*Maximum size of file in which to fontify URL's.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defvar goto-address-mail-regexp
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 "A regular expression probably matching an e-mail address.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defvar goto-address-url-regexp
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "A regular expression probably matching a URL.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defvar goto-address-mail-method
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 'goto-address-send-using-mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "*Function to compose mail.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 Two pre-made functions are `goto-address-send-using-mail' (sendmail);
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 and `goto-address-send-using-mhe' (MH-E).")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (defun goto-address-fontify ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 "Fontify the URL's and e-mail addresses in the current buffer."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (let ((inhibit-read-only t)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (modified (buffer-modified-p)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (progn
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (while (re-search-forward goto-address-url-regexp nil t)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; if text is invisible, we ignore it
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (and (goto-address-skip-invisible (match-beginning 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (progn
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (goto-char (match-end 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (put-text-property (match-beginning 0) (match-end 0)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 'face 'bold)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (put-text-property (match-beginning 0) (match-end 0)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 'mouse-face 'highlight))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (while (re-search-forward goto-address-mail-regexp nil t)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; if text is invisible, we ignore it
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (and (goto-address-skip-invisible (match-beginning 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (progn
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (goto-char (match-end 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (put-text-property (match-beginning 0) (match-end 0)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 'face 'italic)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (put-text-property (match-beginning 0) (match-end 0)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 'mouse-face 'secondary-selection))))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (and (buffer-modified-p)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (not modified)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (set-buffer-modified-p nil)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (defun goto-address-skip-invisible (char)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 "If char is not invisible, then return t. Otherwise, move forward in buffer
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 until a non-invisible char is found, goto that position, and return nil."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (if (get-text-property char 'invisible)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (let ((char (1+ char)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (while (get-text-property char 'invisible)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (setq char (1+ char))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (goto-char char)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 t))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;;; code to find and goto addresses; much of this has been blatantly
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;;; snarfed from browse-url.el
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defun goto-address-at-mouse (event)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "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
156 Send mail to address at position of mouse click. See documentation for
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 `goto-address-find-address-at-point'. If no address is found
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 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
159 (interactive "e")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (let ((posn (event-start event)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (set-buffer (window-buffer (posn-window posn)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (goto-char (posn-point posn))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (let ((address
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (save-excursion (goto-address-find-address-at-point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (if (string-equal address "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (let ((url (browse-url-url-at-point)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (if (string-equal url "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (error "No e-mail address or URL found")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (funcall browse-url-browser-function url)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (funcall goto-address-mail-method address))))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (defun goto-address-at-point ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 "Send to the e-mail address or load the URL at point.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 Send mail to address at point. See documentation for
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 `goto-address-find-address-at-point'. If no address is found
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 there, then load the URL at or before point."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (interactive)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (let ((address (save-excursion (goto-address-find-address-at-point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (if (string-equal address "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (let ((url (browse-url-url-at-point)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (if (string-equal url "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (error "No e-mail address or URL found")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (funcall browse-url-browser-function url)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (funcall goto-address-mail-method address)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defun goto-address-find-address-at-point ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "Find e-mail address around or before point.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 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
191 address. If no e-mail address found, return the empty string."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (let ((bol (save-excursion (beginning-of-line) (point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (re-search-backward "[^-_A-z0-9.@]" bol 'lim)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (if (or (looking-at goto-address-mail-regexp) ; already at start
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (let ((eol (save-excursion (end-of-line) (point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (and (re-search-forward goto-address-mail-regexp eol 'lim)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (goto-char (match-beginning 0)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (buffer-substring (match-beginning 0) (match-end 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 "")))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (defun goto-address-send-using-mhe (to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (mh-find-path)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (let ((cc (mh-read-address "Cc: "))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (subject (read-string "Subject: "))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (config (current-window-configuration)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (delete-other-windows)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (mh-send-sub to cc subject config)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (defun goto-address-send-using-mail (to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (mail-other-window nil to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (and (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (end-of-line 2)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (defun goto-address ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (interactive)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (local-set-key [S-mouse-1] 'goto-address-at-mouse)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (local-set-key "\C-c\r" 'goto-address-at-point)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (if goto-address-fontify-p
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (goto-address-fontify)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (provide 'goto-addr)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;;; goto-addr.el ends here.