annotate lisp/net/goto-addr.el @ 41273:793fceb3e6de

(iswitchb-cannot-complete-hook): New variable to control behaviour when no further completion is possible.
author Richard M. Stallman <rms@gnu.org>
date Mon, 19 Nov 2001 14:08:49 +0000
parents 1802ca573682
children 0560d7169eba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; goto-addr.el --- click to browse URL or to send to e-mail address
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
37423
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
3 ;; Copyright (C) 1995, 2000, 2001 Free Software Foundation, Inc.
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
30192
7d917a6185d3 Change maintainer address.
Dave Love <fx@gnu.org>
parents: 29664
diff changeset
5 ;; Author: Eric Ding <ericding@alum.mit.edu>
30285
0ff2877c9bbe Change maintainer to FSF.
Gerd Moellmann <gerd@gnu.org>
parents: 30192
diff changeset
6 ;; Maintainer: FSF
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Created: 15 Aug 1995
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Keywords: mh-e, www, mouse, mail
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; any later version.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; This package allows you to click or hit a key sequence while on a
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; URL or e-mail address, and either load the URL into a browser of
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; your choice using the browse-url package, or if it's an e-mail
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; address, to send an e-mail to that address. By default, we bind to
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; the [mouse-2] and the [C-c return] key sequences.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; INSTALLATION
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; To use goto-address in a particular mode (for example, while
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; reading mail in mh-e), add something like this in your .emacs file:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; (add-hook 'mh-show-mode-hook 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;
29664
3e03d72fadea (goto-address-fontify): Use keymap property, not local-map.
Dave Love <fx@gnu.org>
parents: 29653
diff changeset
42 ;; The mouse click method is bound to [mouse-2] on highlighted URLs or
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; e-mail addresses only; it functions normally everywhere else. To bind
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; another mouse click to the function, add the following to your .emacs
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; (for example):
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; (setq goto-address-highlight-keymap
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; (let ((m (make-sparse-keymap)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; (define-key m [S-mouse-2] 'goto-address-at-mouse)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; m))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; Known bugs/features:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; * goto-address-mail-regexp only catches foo@bar.org style addressing,
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; not stuff like X.400 addresses, etc.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; * regexp also catches Message-Id line, since it is in the format of
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; an Internet e-mail address (like Compuserve addresses)
30345
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
58 ;; * If the buffer is fontified after goto-address-fontify is run
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
59 ;; (say, using font-lock-fontify-buffer), then font-lock faces will
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; override goto-address faces.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;;; Code:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
64 (require 'thingatpt)
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
65 (autoload 'browse-url-url-at-point "browse-url")
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66
37423
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
67 ;; XEmacs needs the following definitions.
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
68 (unless (fboundp 'overlays-in)
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
69 (require 'overlay))
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
70 (unless (fboundp 'line-beginning-position)
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
71 (defalias 'line-beginning-position 'point-at-bol))
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
72 (unless (fboundp 'line-end-position)
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
73 (defalias 'line-end-position 'point-at-eol))
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
74 (unless (fboundp 'match-string-no-properties)
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
75 (defalias 'match-string-no-properties 'match-string))
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
76
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (defgroup goto-address nil
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 "Click to browse URL or to send to e-mail address."
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 :group 'mouse
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 :group 'hypermedia)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82
39568
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
83 ;; I don't expect users to want fontify'ing without highlighting.
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 (defcustom goto-address-fontify-p t
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
85 "*Non-nil means URLs and e-mail addresses in buffer are fontified.
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 But only if `goto-address-highlight-p' is also non-nil."
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 :type 'boolean
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (defcustom goto-address-highlight-p t
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
91 "*Non-nil means URLs and e-mail addresses in buffer are highlighted."
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 :type 'boolean
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (defcustom goto-address-fontify-maximum-size 30000
29664
3e03d72fadea (goto-address-fontify): Use keymap property, not local-map.
Dave Love <fx@gnu.org>
parents: 29653
diff changeset
96 "*Maximum size of file in which to fontify and/or highlight URLs."
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 :type 'integer
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (defvar goto-address-mail-regexp
39790
1802ca573682 (goto-address-mail-regexp): Allow + in username.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39568
diff changeset
101 ;; Actually pretty much any char could appear in the username part. -stef
1802ca573682 (goto-address-mail-regexp): Allow + in username.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39568
diff changeset
102 "[-a-zA-Z0-9._+]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+"
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 "A regular expression probably matching an e-mail address.")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
105 (defvar goto-address-url-regexp thing-at-point-url-regexp
39568
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
106 ;; (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|"
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
107 ;; "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:"
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
108 ;; "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*"
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
109 ;; "[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 "A regular expression probably matching a URL.")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (defvar goto-address-highlight-keymap
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (let ((m (make-sparse-keymap)))
37423
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
114 (if (featurep 'xemacs)
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
115 (define-key m (kbd "<button2>") 'goto-address-at-mouse)
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
116 (define-key m (kbd "<mouse-2>") 'goto-address-at-mouse))
3ab2c865a8e5 Instead of defining line-beginning-position and
Gerd Moellmann <gerd@gnu.org>
parents: 30891
diff changeset
117 (define-key m (kbd "C-c RET") 'goto-address-at-point)
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 m)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 "keymap to hold goto-addr's mouse key defs under highlighted URLs.")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (defcustom goto-address-url-face 'bold
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
122 "Face to use for URLs."
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 :type 'face
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 (defcustom goto-address-url-mouse-face 'highlight
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
127 "Face to use for URLs when the mouse is on them."
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 :type 'face
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (defcustom goto-address-mail-face 'italic
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
132 "Face to use for e-mail addresses."
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 :type 'face
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (defcustom goto-address-mail-mouse-face 'secondary-selection
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
137 "Face to use for e-mail addresses when the mouse is on them."
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 :type 'face
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 :group 'goto-address)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (defun goto-address-fontify ()
29664
3e03d72fadea (goto-address-fontify): Use keymap property, not local-map.
Dave Love <fx@gnu.org>
parents: 29653
diff changeset
142 "Fontify the URLs and e-mail addresses in the current buffer.
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 This function implements `goto-address-highlight-p'
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 and `goto-address-fontify-p'."
30345
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
145 ;; Clean up from any previous go.
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
146 (dolist (overlay (overlays-in (point-min) (point-max)))
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
147 (if (overlay-get overlay 'goto-address)
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
148 (delete-overlay overlay)))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (save-excursion
30345
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
150 (let ((inhibit-point-motion-hooks t))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (goto-char (point-min))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (if (< (- (point-max) (point)) goto-address-fontify-maximum-size)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (progn
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (while (re-search-forward goto-address-url-regexp nil t)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (let* ((s (match-beginning 0))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (e (match-end 0))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (this-overlay (make-overlay s e)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (and goto-address-fontify-p
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (overlay-put this-overlay 'face goto-address-url-face))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (overlay-put this-overlay
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 'mouse-face goto-address-url-mouse-face)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (overlay-put this-overlay
29209
67618bef1515 (goto-address-fontify): Add help-echo property.
Dave Love <fx@gnu.org>
parents: 28210
diff changeset
163 'help-echo "mouse-2: follow URL")
67618bef1515 (goto-address-fontify): Add help-echo property.
Dave Love <fx@gnu.org>
parents: 28210
diff changeset
164 (overlay-put this-overlay
30345
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
165 'keymap goto-address-highlight-keymap)
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
166 (overlay-put this-overlay 'goto-address t)))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (goto-char (point-min))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (while (re-search-forward goto-address-mail-regexp nil t)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (let* ((s (match-beginning 0))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (e (match-end 0))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (this-overlay (make-overlay s e)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (and goto-address-fontify-p
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (overlay-put this-overlay 'face goto-address-mail-face))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (overlay-put this-overlay 'mouse-face
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 goto-address-mail-mouse-face)
29209
67618bef1515 (goto-address-fontify): Add help-echo property.
Dave Love <fx@gnu.org>
parents: 28210
diff changeset
176 (overlay-put this-overlay
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
177 'help-echo "mouse-2: mail this address")
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (overlay-put this-overlay
30345
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
179 'keymap goto-address-highlight-keymap)
d24028985f3d (goto-address-fontify): Don't bother with buffer-modified and read-only
Dave Love <fx@gnu.org>
parents: 30285
diff changeset
180 (overlay-put this-overlay 'goto-address t))))))))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
39568
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
182 ;; code to find and goto addresses; much of this has been blatantly
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
183 ;; snarfed from browse-url.el
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 ;;;###autoload
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (defun goto-address-at-mouse (event)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 "Send to the e-mail address or load the URL clicked with the mouse.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 Send mail to address at position of mouse click. See documentation for
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 `goto-address-find-address-at-point'. If no address is found
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 there, then load the URL at or before the position of the mouse click."
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (interactive "e")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (save-excursion
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
193 (mouse-set-point event)
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
194 (goto-address-at-point)))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 ;;;###autoload
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (defun goto-address-at-point ()
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 "Send to the e-mail address or load the URL at point.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 Send mail to address at point. See documentation for
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 `goto-address-find-address-at-point'. If no address is found
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 there, then load the URL at or before point."
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (interactive)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (save-excursion
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (let ((address (save-excursion (goto-address-find-address-at-point))))
37809
5bc4eff5115e (goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents: 37423
diff changeset
205 (if (and address
5bc4eff5115e (goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents: 37423
diff changeset
206 (save-excursion
5bc4eff5115e (goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents: 37423
diff changeset
207 (goto-char (previous-single-char-property-change
5bc4eff5115e (goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents: 37423
diff changeset
208 (point) 'goto-address nil
5bc4eff5115e (goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents: 37423
diff changeset
209 (line-beginning-position)))
5bc4eff5115e (goto-address-at-point): Deal with URLs
Gerd Moellmann <gerd@gnu.org>
parents: 37423
diff changeset
210 (not (looking-at goto-address-url-regexp))))
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
211 (compose-mail address)
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
212 (let ((url (browse-url-url-at-point)))
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
213 (if url
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
214 (browse-url url)
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
215 (error "No e-mail address or URL found")))))))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (defun goto-address-find-address-at-point ()
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 "Find e-mail address around or before point.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 Then search backwards to beginning of line for the start of an e-mail
30891
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
220 address. If no e-mail address found, return nil."
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
221 (re-search-backward "[^-_A-z0-9.@]" (line-beginning-position) 'lim)
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
222 (if (or (looking-at goto-address-mail-regexp) ; already at start
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
223 (and (re-search-forward goto-address-mail-regexp
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
224 (line-end-position) 'lim)
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
225 (goto-char (match-beginning 0))))
42ce5997aa4a Don't require browse-url. Require thingatpt.
Dave Love <fx@gnu.org>
parents: 30345
diff changeset
226 (match-string-no-properties 0)))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 ;;;###autoload
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (defun goto-address ()
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 "Sets up goto-address functionality in the current buffer.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 Allows user to use mouse/keyboard command to click to go to a URL
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 or to send e-mail.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 By default, goto-address binds to mouse-2 and C-c RET.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 Also fontifies the buffer appropriately (see `goto-address-fontify-p' and
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 `goto-address-highlight-p' for more information)."
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (interactive)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (if goto-address-highlight-p
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 (goto-address-fontify)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (provide 'goto-addr)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242
38412
253f761ad37b Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents: 37809
diff changeset
243 ;;; goto-addr.el ends here