annotate lisp/goto-addr.el @ 13696:f89aa5a5c485

* etags.c (Cplusplus_suffixes): Add .M suffix for Objective C++. (gperf): Added keywords for Objective C and GNU macros. (sym_type): Added values to account for Objective C and GNU macros. (begtk): The '@' character can start a token. (objdef, methodlen, objtag): New variables for Objective C. (consider_token, C_entries): Added code for Objective C. (plain_C_suffixes): Add .m and .lm for Objective C. (Yacc_suffixes): Add .ym for Objective yacc. (GROW_LINEBUFFER): New macro. (consider_token, C_entries, Pascal_functions): Use the new macro. (consider_token): Take one more argument. Caller changed. (consider_token): Use the hashing function to spot GNU macros. (C_entries): Consider // as a comment start even in plain C for the sake of Objective C parsing. (pfnote): Don't make a tag for ctags if there is no name. (getit, Asm_labels, Perl_functions, Pascal_functions, L_getit, get_scheme, prolog_getit): Name the tag in ctags mode. (pfnote): Truncate ctags lines to 50 chars, like it worked once. (Perl_interpreters): Accept "@PERL@" as an interpreter. (suggest_asking_for_help): New function. (main, get_language_from_name): Use suggest_asking_for_help. (main): Let get_language_from_name make language existence check. (streq, strneq): Check the arguments #if DEBUG.
author Francesco Potortì <pot@gnu.org>
date Thu, 07 Dec 1995 09:10:54 +0000
parents 06e46fbae7f0
children f6fa5b68f9c7
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
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
4 ;; Author: Eric Ding <ericding@mit.edu>
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Maintainer: Eric Ding <ericding@mit.edu>
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Created: 15 Aug 1995
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: mh-e, www, mouse, mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; 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
13 ;; the Free Software Foundation; either version 2, or (at your option)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
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 ;; 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
28 ;; 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
29 ;; 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
30 ;; address, to send an e-mail to that address. By default, we bind to
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
31 ;; the [S-mouse-2] and the [C-c return] key sequences.
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; INSTALLATION
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
35 ;; 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
36 ;; 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
37 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; (add-hook 'mh-show-mode-hook 'goto-address)
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 ;; By default, goto-address now sends using `mail' instead of `mh-send'.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; 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
42 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; (setq goto-address-mail-method 'goto-address-send-using-mhe)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; To rebind, for example, the mouse click method to [mouse-2] in
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; 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
47 ;; above) to your .emacs file:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; (defun my-goto-address ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; (goto-address)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
51 ;; (local-unset-key [S-mouse-2])
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; (local-set-key [mouse-2] 'goto-address-at-mouse))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; (add-hook 'mh-show-mode-hook 'my-goto-address)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; [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
57 ;; 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
58 ;; 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
59
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; BUG REPORTS
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 ;; Please send bug reports to me at ericding@mit.edu.
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 ;; Known bugs/features:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing,
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; not stuff like X.400 addresses, etc.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; * 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
68 ;; an Internet e-mail address (like Compuserve addresses)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; * If show buffer is fontified after goto-address-fontify is run
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; (say, using font-lock-fontify-buffer), then font-lock face will
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; override goto-address faces.
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 ;;; Code:
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (require 'browse-url)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
77 ;;; I don't expect users to want fontify'ing without highlighting.
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (defvar goto-address-fontify-p t
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
79 "*If t, URL's and e-mail addresses in buffer are fontified.
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
80 But only if `goto-address-highlight-p' is also non-nil.")
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
81
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
82 (defvar goto-address-highlight-p t
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
83 "*If t, URL's and e-mail addresses in buffer are highlighted.")
13208
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 (defvar goto-address-fontify-maximum-size 30000
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
86 "*Maximum size of file in which to fontify and/or highlight URL's.")
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (defvar goto-address-mail-regexp
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "A regular expression probably matching an e-mail address.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defvar goto-address-url-regexp
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*"
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 "[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 "A regular expression probably matching a URL.")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defvar goto-address-mail-method
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 'goto-address-send-using-mail
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "*Function to compose mail.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 Two pre-made functions are `goto-address-send-using-mail' (sendmail);
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 and `goto-address-send-using-mhe' (MH-E).")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defun goto-address-fontify ()
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
106 "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
107 This function implements `goto-address-highlight-p'
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
108 and `goto-address-fontify-p'."
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (let ((inhibit-read-only t)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
111 (inhibit-point-motion-hooks t)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (modified (buffer-modified-p)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (progn
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (while (re-search-forward goto-address-url-regexp nil t)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
117 (progn
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
118 (goto-char (match-end 0))
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
119 (and goto-address-fontify-p
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (put-text-property (match-beginning 0) (match-end 0)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
121 'face 'bold))
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
122 (put-text-property (match-beginning 0) (match-end 0)
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
123 'mouse-face 'highlight)))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (while (re-search-forward goto-address-mail-regexp nil t)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
126 (progn
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
127 (goto-char (match-end 0))
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
128 (and goto-address-fontify-p
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (put-text-property (match-beginning 0) (match-end 0)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
130 'face 'italic))
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
131 (put-text-property (match-beginning 0) (match-end 0)
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
132 'mouse-face 'secondary-selection)))))
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (and (buffer-modified-p)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (not modified)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (set-buffer-modified-p nil)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;;; code to find and goto addresses; much of this has been blatantly
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;;; snarfed from browse-url.el
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (defun goto-address-at-mouse (event)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 "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
142 Send mail to address at position of mouse click. See documentation for
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 `goto-address-find-address-at-point'. If no address is found
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 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
145 (interactive "e")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (let ((posn (event-start event)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (set-buffer (window-buffer (posn-window posn)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (goto-char (posn-point posn))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (let ((address
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (save-excursion (goto-address-find-address-at-point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if (string-equal address "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (let ((url (browse-url-url-at-point)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (if (string-equal url "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (error "No e-mail address or URL found")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (funcall browse-url-browser-function url)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (funcall goto-address-mail-method address))))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (defun goto-address-at-point ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 "Send to the e-mail address or load the URL at point.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 Send mail to address at point. See documentation for
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 `goto-address-find-address-at-point'. If no address is found
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 there, then load the URL at or before point."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (interactive)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (save-excursion
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (let ((address (save-excursion (goto-address-find-address-at-point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (if (string-equal address "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (let ((url (browse-url-url-at-point)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (if (string-equal url "")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (error "No e-mail address or URL found")
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (funcall browse-url-browser-function url)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (funcall goto-address-mail-method address)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (defun goto-address-find-address-at-point ()
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 "Find e-mail address around or before point.
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 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
177 address. If no e-mail address found, return the empty string."
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (let ((bol (save-excursion (beginning-of-line) (point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (re-search-backward "[^-_A-z0-9.@]" bol 'lim)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (if (or (looking-at goto-address-mail-regexp) ; already at start
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (let ((eol (save-excursion (end-of-line) (point))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (and (re-search-forward goto-address-mail-regexp eol 'lim)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (goto-char (match-beginning 0)))))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (buffer-substring (match-beginning 0) (match-end 0))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 "")))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (defun goto-address-send-using-mhe (to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (mh-find-path)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (let ((cc (mh-read-address "Cc: "))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (subject (read-string "Subject: "))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (config (current-window-configuration)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (delete-other-windows)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (mh-send-sub to cc subject config)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (defun goto-address-send-using-mail (to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (mail-other-window nil to)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (and (goto-char (point-min))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (end-of-line 2)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
200 ;;;###autoload
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (defun goto-address ()
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
202 "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
203 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
204 or to send e-mail.
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
205 By default, goto-address binds to S-mouse-2 and C-c RET.
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
206
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
207 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
208 `goto-address-highlight-p' for more information)."
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (interactive)
13550
06e46fbae7f0 (goto-address-highlight-p): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13208
diff changeset
210 (local-set-key [S-mouse-2] 'goto-address-at-mouse)
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (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
212 (if goto-address-highlight-p
13208
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (goto-address-fontify)))
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (provide 'goto-addr)
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216
7a20f2bb5ac9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;;; goto-addr.el ends here.