Mercurial > emacs
annotate lisp/mail/mailabbrev.el @ 102505:b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 12 Mar 2009 06:23:35 +0000 |
parents | ad9d2270860e |
children | 4e5a706e62fa |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
34921
diff
changeset
|
1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases |
1148 | 2 |
74509 | 3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1996, 1997, 2000, 2001, |
101009
ad9d2270860e
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
4 ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
ad9d2270860e
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
5 ;; Free Software Foundation, Inc. |
1148 | 6 |
100547 | 7 ;; Author: Jamie Zawinski <jwz@lucid.com; now jwz@jwz.org> |
27589 | 8 ;; Maintainer: FSF |
1148 | 9 ;; Created: 19 Oct 90 |
10 ;; Keywords: mail | |
11 | |
14169 | 12 ;; This file is part of GNU Emacs. |
459 | 13 |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
14169 | 15 ;; it under the terms of the GNU General Public License as published by |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
17 ;; (at your option) any later version. |
459 | 18 |
14169 | 19 ;; GNU Emacs is distributed in the hope that it will be useful, |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
459 | 23 |
14169 | 24 ;; You should have received a copy of the GNU General Public License |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
459 | 26 |
1148 | 27 ;;; Commentary: |
28 | |
15293
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
29 ;; This file ensures that, when the point is in a To:, CC:, BCC:, or From: |
14169 | 30 ;; field, word-abbrevs are defined for each of your mail aliases. These |
31 ;; aliases will be defined from your .mailrc file (or the file specified by | |
52685 | 32 ;; `mail-personal-alias-file') if it exists. Your mail aliases will |
14169 | 33 ;; expand any time you type a word-delimiter at the end of an abbreviation. |
34 ;; | |
35 ;; What you see is what you get: if mailabbrev is in use when you type | |
36 ;; a name, and the name does not expand, you know it is not an abbreviation. | |
37 ;; However, if you yank abbreviations into the headers | |
38 ;; in a way that bypasses the check for abbreviations, | |
39 ;; they are expanded (but not visibly) when you send the message. | |
40 ;; | |
41 ;; Your mail alias abbrevs will be in effect only when the point is in an | |
42 ;; appropriate header field. When in the body of the message, or other | |
43 ;; header fields, the mail aliases will not expand. Rather, the normal | |
44669
c94319aaffb8
(mail-mode-abbrev-table): Delete defvar.
Richard M. Stallman <rms@gnu.org>
parents:
44393
diff
changeset
|
44 ;; mode-specific abbrev table will be used if |
14169 | 45 ;; defined. So if you use mail-mode specific abbrevs, this code will not |
46 ;; adversely affect you. You can control which header fields the abbrevs | |
47 ;; are used in by changing the variable mail-abbrev-mode-regexp. | |
48 ;; | |
49 ;; If auto-fill mode is on, abbrevs will wrap at commas instead of at word | |
50 ;; boundaries; also, header continuation-lines will be properly indented. | |
51 ;; | |
28803
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
52 ;; You can also insert a mail alias with mail-abbrev-insert-alias |
14169 | 53 ;; (bound to C-c C-a), which prompts you for an alias (with completion) |
54 ;; and inserts its expansion at point. | |
55 ;; | |
56 ;; This file fixes a bug in the old system which prohibited your .mailrc | |
57 ;; file from having lines like | |
58 ;; | |
59 ;; alias someone "John Doe <doe@quux.com>" | |
60 ;; | |
61 ;; That is, if you want an address to have embedded spaces, simply surround it | |
62 ;; with double-quotes. This is necessary because the format of the .mailrc | |
63 ;; file bogusly uses spaces as address delimiters. The following line defines | |
64 ;; an alias which expands to three addresses: | |
65 ;; | |
66 ;; alias foobar addr-1 addr-2 "address three <addr-3>" | |
67 ;; | |
68 ;; (This is bogus because mail-delivery programs want commas, not spaces, | |
69 ;; but that's what the file format is, so we have to live with it.) | |
70 ;; | |
71 ;; If you like, you can call the function define-mail-abbrev to define your | |
72 ;; mail aliases instead of using a .mailrc file. When you call it in this | |
73 ;; way, addresses are separated by commas. | |
74 ;; | |
75 ;; CAVEAT: This works on most Sun systems; I have been told that some versions | |
76 ;; of /bin/mail do not understand double-quotes in the .mailrc file. So you | |
77 ;; should make sure your version does before including verbose addresses like | |
78 ;; this. One solution to this, if you are on a system whose /bin/mail doesn't | |
79 ;; work that way, (and you still want to be able to /bin/mail to send mail in | |
80 ;; addition to emacs) is to define minimal aliases (without full names) in | |
81 ;; your .mailrc file, and use define-mail-abbrev to redefine them when sending | |
82 ;; mail from emacs; this way, mail sent from /bin/mail will work, and mail | |
83 ;; sent from emacs will be pretty. | |
84 ;; | |
85 ;; Aliases in the mailrc file may be nested. If you define aliases like | |
86 ;; alias group1 fred ethel | |
87 ;; alias group2 larry curly moe | |
88 ;; alias everybody group1 group2 | |
89 ;; Then when you type "everybody" on the To: line, it will be expanded to | |
90 ;; fred, ethyl, larry, curly, moe | |
91 ;; | |
92 ;; Aliases may also contain forward references; the alias of "everybody" can | |
93 ;; precede the aliases of "group1" and "group2". | |
94 ;; | |
95 ;; This code also understands the "source" .mailrc command, for reading | |
96 ;; aliases from some other file as well. | |
97 ;; | |
98 ;; Aliases may contain hyphens, as in "alias foo-bar foo@bar"; word-abbrevs | |
99 ;; normally cannot contain hyphens, but this code works around that for the | |
100 ;; specific case of mail-alias word-abbrevs. | |
101 ;; | |
102 ;; To read in the contents of another .mailrc-type file from emacs, use the | |
103 ;; command Meta-X merge-mail-abbrevs. The rebuild-mail-abbrevs command is | |
104 ;; similar, but will delete existing aliases first. | |
105 ;; | |
106 ;; If you would like your aliases to be expanded when you type M-> or ^N to | |
107 ;; move out of the mail-header into the message body (instead of having to | |
108 ;; type SPC at the end of the abbrev before moving away) then you can do | |
109 ;; | |
110 ;; (add-hook | |
34921
fc01ec9131a8
(mail-abbrevs-enable, mail-abbrevs-disable):
Gerd Moellmann <gerd@gnu.org>
parents:
30888
diff
changeset
|
111 ;; 'mail-mode-hook |
30888
e559f0aa6b2d
Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28803
diff
changeset
|
112 ;; (lambda () |
49171
e0c2ecbf4fc5
(Commentary): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
47573
diff
changeset
|
113 ;; (define-key mail-mode-map [remap next-line] 'mail-abbrev-next-line) |
e0c2ecbf4fc5
(Commentary): Use command remapping instead of
Andreas Schwab <schwab@suse.de>
parents:
47573
diff
changeset
|
114 ;; (define-key mail-mode-map [remap end-of-buffer] 'mail-abbrev-end-of-buffer))) |
14169 | 115 ;; |
116 ;; If you want multiple addresses separated by a string other than ", " then | |
117 ;; you can set the variable mail-alias-separator-string to it. This has to | |
118 ;; be a comma bracketed by whitespace if you want any kind of reasonable | |
96376
c3309dba6542
American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents:
94674
diff
changeset
|
119 ;; behavior. |
14169 | 120 ;; |
121 ;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and | |
122 ;; Noah Friedman for suggestions and bug reports. | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
123 |
34921
fc01ec9131a8
(mail-abbrevs-enable, mail-abbrevs-disable):
Gerd Moellmann <gerd@gnu.org>
parents:
30888
diff
changeset
|
124 ;; To use this package, do (add-hook 'mail-mode-hook 'mail-abbrevs-setup). |
459 | 125 |
1148 | 126 ;;; Code: |
127 | |
43136
9c1aa7b635bd
Require sendmail only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
41998
diff
changeset
|
128 (eval-when-compile |
9c1aa7b635bd
Require sendmail only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
41998
diff
changeset
|
129 (require 'sendmail)) |
459 | 130 |
20097 | 131 (defgroup mail-abbrev nil |
132 "Expand mail aliases as abbrevs, in certain mail headers." | |
133 :group 'abbrev-mode) | |
134 | |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
135 ;;;###autoload |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
136 (define-minor-mode mail-abbrevs-mode |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
137 "Non-nil means expand mail aliases as abbrevs, in certain message headers." |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
138 :global t |
20097 | 139 :group 'mail-abbrev |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
140 :version "20.3" |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
141 (if mail-abbrevs-mode (mail-abbrevs-enable) (mail-abbrevs-disable))) |
20097 | 142 |
143 (defcustom mail-abbrevs-only nil | |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
144 "Non-nil means only mail abbrevs should expand automatically. |
20097 | 145 Other abbrevs expand only when you explicitly use `expand-abbrev'." |
146 :type 'boolean | |
147 :group 'mail-abbrev) | |
148 | |
459 | 149 ;; originally defined in sendmail.el - used to be an alist, now is a table. |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
150 (defvar mail-abbrevs nil |
598 | 151 "Word-abbrev table of mail address aliases. |
459 | 152 If this is nil, it means the aliases have not yet been initialized and |
153 should be read from the .mailrc file. (This is distinct from there being | |
154 no aliases, which is represented by this being a table with no entries.)") | |
155 | |
14800
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
156 (defvar mail-abbrev-modtime nil |
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
157 "The modification time of your mail alias file when it was last examined.") |
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
158 |
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
159 (defun mail-abbrevs-sync-aliases () |
52371
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
160 (when mail-personal-alias-file |
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
161 (if (file-exists-p mail-personal-alias-file) |
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
162 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file)))) |
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
163 (if (not (equal mail-abbrev-modtime modtime)) |
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
164 (progn |
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
165 (setq mail-abbrev-modtime modtime) |
d6c91e697cdc
(mail-abbrevs-sync-aliases): Do nothing if mail-personal-alias-file is nil.
Richard M. Stallman <rms@gnu.org>
parents:
49171
diff
changeset
|
166 (build-mail-abbrevs))))))) |
14800
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
167 |
474 | 168 ;;;###autoload |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
169 (defun mail-abbrevs-setup () |
14761
bef2b46521de
(mail-abbrevs-setup): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
170 "Initialize use of the `mailabbrev' package." |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
171 (if (and (not (vectorp mail-abbrevs)) |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
172 (file-exists-p mail-personal-alias-file)) |
14800
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
173 (progn |
15293
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
174 (setq mail-abbrev-modtime |
14800
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
175 (nth 5 (file-attributes mail-personal-alias-file))) |
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
176 (build-mail-abbrevs))) |
47631a15d6a2
(mail-abbrev-modtime): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14761
diff
changeset
|
177 (mail-abbrevs-sync-aliases) |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
178 (add-hook 'abbrev-expand-functions 'mail-abbrev-expand-wrapper nil t) |
459 | 179 (abbrev-mode 1)) |
180 | |
20097 | 181 (defun mail-abbrevs-enable () |
34921
fc01ec9131a8
(mail-abbrevs-enable, mail-abbrevs-disable):
Gerd Moellmann <gerd@gnu.org>
parents:
30888
diff
changeset
|
182 (add-hook 'mail-mode-hook 'mail-abbrevs-setup)) |
20097 | 183 |
184 (defun mail-abbrevs-disable () | |
185 "Turn off use of the `mailabbrev' package." | |
34921
fc01ec9131a8
(mail-abbrevs-enable, mail-abbrevs-disable):
Gerd Moellmann <gerd@gnu.org>
parents:
30888
diff
changeset
|
186 (remove-hook 'mail-mode-hook 'mail-abbrevs-setup) |
20097 | 187 (abbrev-mode (if (default-value 'abbrev-mode) 1 -1))) |
188 | |
598 | 189 ;;;###autoload |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
190 (defun build-mail-abbrevs (&optional file recursivep) |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
191 "Read mail aliases from personal mail alias file and set `mail-abbrevs'. |
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
192 By default this is the file specified by `mail-personal-alias-file'." |
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
193 (setq file (expand-file-name (or file mail-personal-alias-file))) |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
194 (if (vectorp mail-abbrevs) |
459 | 195 nil |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
196 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
197 (define-abbrev-table 'mail-abbrevs '())) |
606 | 198 (message "Parsing %s..." file) |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
199 (with-temp-buffer |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
200 (buffer-disable-undo) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
201 (cond ((get-file-buffer file) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
202 (insert (with-current-buffer (get-file-buffer file) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
203 (buffer-substring (point-min) (point-max))))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
204 ((not (file-exists-p file))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
205 (t (insert-file-contents file))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
206 ;; Don't lose if no final newline. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
207 (goto-char (point-max)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
208 (or (eq (preceding-char) ?\n) (newline)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
209 (goto-char (point-min)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
210 ;; Delete comments from the file |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
211 (while (search-forward "# " nil t) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
212 (let ((p (- (point) 2))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
213 (end-of-line) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
214 (delete-region p (point)))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
215 (goto-char (point-min)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
216 ;; handle "\\\n" continuation lines |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
217 (while (not (eobp)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
218 (end-of-line) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
219 (if (= (preceding-char) ?\\) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
220 (progn (delete-char -1) (delete-char 1) (insert ?\ )) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
221 (forward-char 1))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
222 (goto-char (point-min)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
223 (while (re-search-forward |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
224 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
225 (beginning-of-line) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
226 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)") |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
227 (progn |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
228 (end-of-line) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
229 (build-mail-abbrevs |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
230 (substitute-in-file-name |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
231 (buffer-substring (match-beginning 1) (match-end 1))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
232 t)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
233 (re-search-forward "[ \t]+\\([^ \t\n]+\\)") |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
234 (let* ((name (buffer-substring |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
235 (match-beginning 1) (match-end 1))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
236 (start (progn (skip-chars-forward " \t") (point)))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
237 (end-of-line) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
238 ;; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
239 (define-mail-abbrev |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
240 name |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
241 (buffer-substring start (point)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
242 t)))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
243 ;; Resolve forward references in .mailrc file. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
244 ;; This would happen automatically before the first abbrev was |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
245 ;; expanded, but why not do it now. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
246 (or recursivep (mail-resolve-all-aliases)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
247 mail-abbrevs) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
248 (message "Parsing %s... done" file)) |
459 | 249 |
627 | 250 (defvar mail-alias-separator-string ", " |
459 | 251 "*A string inserted between addresses in multi-address mail aliases. |
15293
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
252 This has to contain a comma, so \", \" is a reasonable value. You might |
459 | 253 also want something like \",\\n \" to get each address on its own line.") |
254 | |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
255 ;; define-mail-abbrev sets this flag, which causes mail-resolve-all-aliases |
459 | 256 ;; to be called before expanding abbrevs if it's necessary. |
257 (defvar mail-abbrev-aliases-need-to-be-resolved t) | |
258 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
259 ;; originally defined in mailalias.el ; build-mail-abbrevs calls this with |
459 | 260 ;; stuff parsed from the .mailrc file. |
261 ;; | |
474 | 262 ;;;###autoload |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
263 (defun define-mail-abbrev (name definition &optional from-mailrc-file) |
11059 | 264 "Define NAME as a mail alias abbrev that translates to DEFINITION. |
99927
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
265 If DEFINITION contains multiple addresses, separate them with commas. |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
266 |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
267 Optional argument FROM-MAILRC-FILE means that DEFINITION comes |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
268 from a mailrc file. In that case, addresses are separated with |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
269 spaces and addresses with embedded spaces are surrounded by |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
270 double-quotes." |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
271 ;; When this is called from build-mail-abbrevs, the third argument is |
459 | 272 ;; true, and we do some evil space->comma hacking like /bin/mail does. |
273 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") | |
274 ;; Read the defaults first, if we have not done so. | |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
275 (unless (vectorp mail-abbrevs) (build-mail-abbrevs)) |
459 | 276 ;; strip garbage from front and end |
277 (if (string-match "\\`[ \t\n,]+" definition) | |
278 (setq definition (substring definition (match-end 0)))) | |
279 (if (string-match "[ \t\n,]+\\'" definition) | |
280 (setq definition (substring definition 0 (match-beginning 0)))) | |
99927
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
281 (let* ((L (length definition)) |
8215
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
282 (start (if (> L 0) 0)) |
99927
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
283 end this-entry result) |
459 | 284 (while start |
99927
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
285 (cond |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
286 (from-mailrc-file |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
287 ;; If we're reading from the mailrc file, addresses are |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
288 ;; delimited by spaces, and addresses with embedded spaces are |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
289 ;; surrounded by non-escaped double-quotes. |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
290 (if (eq ?\" (aref definition start)) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
291 (setq start (1+ start) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
292 end (and (string-match |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
293 "[^\\]\\(\\([\\][\\]\\)*\\)\"[ \t,]*" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
294 definition start) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
295 (match-end 1))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
296 (setq end (string-match "[ \t,]+" definition start))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
297 ;; Extract the address and advance the loop past it. |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
298 (setq this-entry (substring definition start end) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
299 start (and end (/= (match-end 0) L) (match-end 0))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
300 ;; If the full name contains a problem character, quote it. |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
301 (and (string-match "\\(.+?\\)[ \t]*\\(<.*>\\)" this-entry) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
302 (string-match "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
303 (match-string 1 this-entry)) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
304 (setq this-entry (replace-regexp-in-string |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
305 "\\(.+?\\)[ \t]*\\(<.*>\\)" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
306 "\"\\1\" \\2" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
307 this-entry))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
308 (push this-entry result)) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
309 ;; When we are not reading from .mailrc, addresses are |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
310 ;; separated by commas. Try to accept a rfc822-like syntax. |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
311 ;; (Todo: extend rfc822.el to do the work for us.) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
312 ((equal (string-match |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
313 "[ \t,]*\\(\"\\(?:[^\"]\\|[^\\]\\(?:[\\][\\]\\)*\"\\)*\"[ \t]*\ |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
314 <[-.!#$%&'*+/0-9=?A-Za-z^_`{|}~@]+>\\)[ \t,]*" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
315 definition start) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
316 start) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
317 ;; If an entry has a valid [ "foo bar" <foo@example.com> ] |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
318 ;; form, use it literally . This also allows commas in the |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
319 ;; quoted string, e.g. [ "foo bar, jr" <foo@example.com> ] |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
320 (push (match-string 1 definition) result) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
321 (setq start (and (/= (match-end 0) L) (match-end 0)))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
322 (t |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
323 ;; Otherwise, read the next address by looking for a comma. |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
324 (setq end (string-match "[ \t\n,]*,[ \t\n]*" definition start)) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
325 (setq this-entry (substring definition start end)) |
59349
c3a4bd30088a
(sendmail-pre-abbrev-expand-hook):
Richard M. Stallman <rms@gnu.org>
parents:
52685
diff
changeset
|
326 ;; Advance the loop past this address. |
99927
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
327 (setq start (and end (/= (match-end 0) L) (match-end 0))) |
59349
c3a4bd30088a
(sendmail-pre-abbrev-expand-hook):
Richard M. Stallman <rms@gnu.org>
parents:
52685
diff
changeset
|
328 ;; If the full name contains a problem character, quote it. |
99927
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
329 (and (string-match "\\(.+?\\)[ \t]*\\(<.*>\\)" this-entry) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
330 (string-match "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
331 (match-string 1 this-entry)) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
332 (setq this-entry (replace-regexp-in-string |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
333 "\\(.+?\\)[ \t]*\\(<.*>\\)" "\"\\1\" \\2" |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
334 this-entry))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
335 (push this-entry result)))) |
342e1636063f
(define-mail-abbrev): When reading from mailrc, recognize string
Chong Yidong <cyd@stupidchicken.com>
parents:
96376
diff
changeset
|
336 |
459 | 337 (setq definition (mapconcat (function identity) |
338 (nreverse result) | |
627 | 339 mail-alias-separator-string))) |
459 | 340 (setq mail-abbrev-aliases-need-to-be-resolved t) |
341 (setq name (downcase name)) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
342 ;; use an abbrev table instead of an alist for mail-abbrevs. |
459 | 343 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed. |
43268
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
344 (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook 0 t))) |
459 | 345 |
346 | |
347 (defun mail-resolve-all-aliases () | |
348 "Resolve all forward references in the mail aliases table." | |
349 (if mail-abbrev-aliases-need-to-be-resolved | |
350 (progn | |
351 ;; (message "Resolving mail aliases...") | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
352 (if (vectorp mail-abbrevs) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
353 (mapatoms (function mail-resolve-all-aliases-1) mail-abbrevs)) |
459 | 354 (setq mail-abbrev-aliases-need-to-be-resolved nil) |
355 ;; (message "Resolving mail aliases... done.") | |
356 ))) | |
357 | |
717 | 358 (defun mail-resolve-all-aliases-1 (sym &optional so-far) |
359 (if (memq sym so-far) | |
360 (error "mail alias loop detected: %s" | |
361 (mapconcat 'symbol-name (cons sym so-far) " <- "))) | |
459 | 362 (let ((definition (and (boundp sym) (symbol-value sym)))) |
363 (if definition | |
364 (let ((result '()) | |
365 (start 0)) | |
366 (while start | |
367 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start))) | |
368 (setq result (cons (substring definition start end) result) | |
369 start (and end (match-end 0))))) | |
370 (setq definition | |
371 (mapconcat (function (lambda (x) | |
372 (or (mail-resolve-all-aliases-1 | |
12444
0f96d53b31b7
(mail-resolve-all-aliases-1):
Richard M. Stallman <rms@gnu.org>
parents:
11504
diff
changeset
|
373 (intern-soft (downcase x) mail-abbrevs) |
717 | 374 (cons sym so-far)) |
459 | 375 x))) |
376 (nreverse result) | |
627 | 377 mail-alias-separator-string)) |
459 | 378 (set sym definition)))) |
379 (symbol-value sym)) | |
380 | |
381 | |
627 | 382 (defun mail-abbrev-expand-hook () |
11059 | 383 "For use as the fourth arg to `define-abbrev'. |
384 After expanding a mail-abbrev, if Auto Fill mode is on and we're past the | |
385 fill-column, break the line at the previous comma, and indent the next line." | |
15293
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
386 ;; Disable abbrev mode to avoid recursion in indent-relative expanding |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
387 ;; part of the abbrev expansion as an abbrev itself. |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
388 (let ((abbrev-mode nil)) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
389 (save-excursion |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
390 (let ((p (point)) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
391 bol comma fp) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
392 (beginning-of-line) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
393 (setq bol (point)) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
394 (goto-char p) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
395 (while (and auto-fill-function |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
396 (>= (current-column) fill-column) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
397 (search-backward "," bol t)) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
398 (setq comma (point)) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
399 (forward-char 1) ; Now we are just past the comma. |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
400 (insert "\n") |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
401 (delete-horizontal-space) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
402 (setq p (point)) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
403 (indent-relative) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
404 (setq fp (buffer-substring p (point))) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
405 ;; Go to the end of the new line. |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
406 (end-of-line) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
407 (if (> (current-column) fill-column) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
408 ;; It's still too long; do normal auto-fill. |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
409 (let ((fill-prefix (or fp "\t"))) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
410 (do-auto-fill))) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
411 ;; Resume the search. |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
412 (goto-char comma) |
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
413 ))))) |
598 | 414 |
415 ;;; Syntax tables and abbrev-expansion | |
459 | 416 |
15293
1343afeec307
(mail-abbrev-expand-hook): Disable abbrev mode temporarily while working,
Roland McGrath <roland@gnu.org>
parents:
14800
diff
changeset
|
417 (defvar mail-abbrev-mode-regexp |
5559
e976a52296fc
(mail-abbrev-mode-regexp): Add Reply-to.
Richard M. Stallman <rms@gnu.org>
parents:
4805
diff
changeset
|
418 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):" |
11059 | 419 "*Regexp to select mail-headers in which mail abbrevs should be expanded. |
10776
52b3af3cb71a
(mail-abbrev-mode-regexp): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
10328
diff
changeset
|
420 This string will be handed to `looking-at' with point at the beginning |
459 | 421 of the current line; if it matches, abbrev mode will be turned on, otherwise |
422 it will be turned off. (You don't need to worry about continuation lines.) | |
423 This should be set to match those mail fields in which you want abbreviations | |
424 turned on.") | |
425 | |
43136
9c1aa7b635bd
Require sendmail only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
41998
diff
changeset
|
426 (defvar mail-abbrev-syntax-table nil |
13258
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
427 "The syntax-table used for abbrev-expansion purposes. |
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
428 This is not actually made the current syntax table of the buffer, but |
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
429 simply controls the set of characters which may be a part of the name |
43136
9c1aa7b635bd
Require sendmail only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
41998
diff
changeset
|
430 of a mail alias. The value is set up, buffer-local, when first needed.") |
598 | 431 |
44118
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
432 (defun mail-abbrev-make-syntax-table () |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
433 (make-local-variable 'mail-abbrev-syntax-table) |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
434 (unless mail-abbrev-syntax-table |
44393
6ae0e3db6a85
(mail-abbrev-make-syntax-table): Use (syntax-table), not old-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
44379
diff
changeset
|
435 (let ((tab (copy-syntax-table (syntax-table))) |
44118
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
436 (_ (aref (standard-syntax-table) ?_)) |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
437 (w (aref (standard-syntax-table) ?w))) |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
438 (map-char-table |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
439 (function (lambda (key value) |
46354
ff0c68e547f7
(mail-abbrev-make-syntax-table): Check the
Andreas Schwab <schwab@suse.de>
parents:
44669
diff
changeset
|
440 (if (null value) |
ff0c68e547f7
(mail-abbrev-make-syntax-table): Check the
Andreas Schwab <schwab@suse.de>
parents:
44669
diff
changeset
|
441 ;; Fetch the inherited value |
ff0c68e547f7
(mail-abbrev-make-syntax-table): Check the
Andreas Schwab <schwab@suse.de>
parents:
44669
diff
changeset
|
442 (setq value (aref tab key))) |
44118
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
443 (if (equal value _) |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
444 (set-char-table-range tab key w)))) |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
445 tab) |
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
446 (modify-syntax-entry ?@ "w" tab) |
47573
29a49406ad9d
(mail-abbrev-make-syntax-table): Give %!._- word constituent syntax.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
46354
diff
changeset
|
447 (modify-syntax-entry ?% "w" tab) |
29a49406ad9d
(mail-abbrev-make-syntax-table): Give %!._- word constituent syntax.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
46354
diff
changeset
|
448 (modify-syntax-entry ?! "w" tab) |
29a49406ad9d
(mail-abbrev-make-syntax-table): Give %!._- word constituent syntax.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
46354
diff
changeset
|
449 (modify-syntax-entry ?. "w" tab) |
29a49406ad9d
(mail-abbrev-make-syntax-table): Give %!._- word constituent syntax.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
46354
diff
changeset
|
450 (modify-syntax-entry ?_ "w" tab) |
29a49406ad9d
(mail-abbrev-make-syntax-table): Give %!._- word constituent syntax.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
46354
diff
changeset
|
451 (modify-syntax-entry ?- "w" tab) |
44118
00eee90af15f
(mail-abbrev-make-syntax-table): New subroutine
Richard M. Stallman <rms@gnu.org>
parents:
43268
diff
changeset
|
452 (setq mail-abbrev-syntax-table tab)))) |
459 | 453 |
598 | 454 (defun mail-abbrev-in-expansion-header-p () |
455 "Whether point is in a mail-address header field." | |
456 (let ((case-fold-search t)) | |
457 (and ;; | |
458 ;; we are on an appropriate header line... | |
459 (save-excursion | |
39566
497b8fa7e100
(mail-abbrev-in-expansion-header-p): Simplify.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
460 (unless (eobp) (forward-char 1)) |
497b8fa7e100
(mail-abbrev-in-expansion-header-p): Simplify.
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
461 (re-search-backward "^[^ \t]" nil 'move) |
598 | 462 ;; are we at the front of an appropriate header line? |
463 (looking-at mail-abbrev-mode-regexp)) | |
464 ;; | |
21866
d98a0a598fb9
(mail-abbrev-in-expansion-header-p): Use mail-header-end.
Richard M. Stallman <rms@gnu.org>
parents:
21670
diff
changeset
|
465 ;; ...and are we in the headers? |
43268
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
466 (< (point) |
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
467 (save-restriction |
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
468 (widen) |
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
469 (save-excursion |
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
470 (rfc822-goto-eoh) |
08fa5680829b
(define-mail-abbrev): Define as system abbrev.
Richard M. Stallman <rms@gnu.org>
parents:
43214
diff
changeset
|
471 (point))))))) |
598 | 472 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
473 (defun mail-abbrev-expand-wrapper (expand) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
474 (if (and mail-abbrevs (not (eq mail-abbrevs t))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
475 (if (mail-abbrev-in-expansion-header-p) |
43136
9c1aa7b635bd
Require sendmail only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
41998
diff
changeset
|
476 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
477 ;; We are in a To: (or CC:, or whatever) header, and |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
478 ;; should use word-abbrevs to expand mail aliases. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
479 (let ((local-abbrev-table mail-abbrevs)) |
1148 | 480 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
481 ;; Before anything else, resolve aliases if they need it. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
482 (and mail-abbrev-aliases-need-to-be-resolved |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
483 (mail-resolve-all-aliases)) |
1148 | 484 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
485 ;; Now proceed with the abbrev section. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
486 ;; - We already installed mail-abbrevs as the abbrev table. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
487 ;; - Then install the mail-abbrev-syntax-table, which |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
488 ;; temporarily marks all of the |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
489 ;; non-alphanumeric-atom-characters (the "_" |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
490 ;; syntax ones) as being normal word-syntax. We do this |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
491 ;; because the C code for expand-abbrev only works on words, |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
492 ;; and we want these characters to be considered words for |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
493 ;; the purpose of abbrev expansion. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
494 ;; - Then we call the expand function, to do |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
495 ;; the abbrev expansion with the above syntax table. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
496 |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
497 (mail-abbrev-make-syntax-table) |
1148 | 498 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
499 ;; If the character just typed was non-alpha-symbol-syntax, |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
500 ;; then don't expand the abbrev now (that is, don't expand |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
501 ;; when the user types -.) Check the character's syntax in |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
502 ;; the usual syntax table. |
1148 | 503 |
101009
ad9d2270860e
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
504 (or (and (integerp last-command-event) |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
505 ;; Some commands such as M-> may want to expand first. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
506 (equal this-command 'self-insert-command) |
101009
ad9d2270860e
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
507 (or (eq (char-syntax last-command-event) ?_) |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
508 ;; Don't expand on @. |
101009
ad9d2270860e
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
509 (memq last-command-event '(?@ ?. ?% ?! ?_ ?-)))) |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
510 ;; Use this table so that abbrevs can have hyphens in them. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
511 (with-syntax-table mail-abbrev-syntax-table |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
512 (funcall expand)))) |
1148 | 513 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
514 (if (or (not mail-abbrevs-only) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
515 (eq this-command 'expand-abbrev)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
516 ;; We're not in a mail header where mail aliases should |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
517 ;; be expanded, then use the normal mail-mode abbrev table |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
518 ;; (if any) and the normal mail-mode syntax table. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
519 (funcall expand) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
520 ;; This is not a mail abbrev, and we should not expand it. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
521 ;; Don't expand anything. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
522 nil)) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
523 ;; No mail-abbrevs at all, do the normal thing. |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
524 (funcall expand))) |
598 | 525 |
526 ;;; utilities | |
459 | 527 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
528 (defun merge-mail-abbrevs (file) |
459 | 529 "Merge mail aliases from the given file with existing ones." |
530 (interactive (list | |
531 (let ((insert-default-directory t) | |
532 (default-directory (expand-file-name "~/")) | |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
533 (def mail-personal-alias-file)) |
459 | 534 (read-file-name |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64754
diff
changeset
|
535 (format "Read additional aliases from file (default %s): " |
459 | 536 def) |
537 default-directory | |
538 (expand-file-name def default-directory) | |
539 t)))) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
540 (build-mail-abbrevs file)) |
459 | 541 |
12945
14e16370799d
(rebuild-mail-abbrevs): FILE defaults to visited file.
Richard M. Stallman <rms@gnu.org>
parents:
12444
diff
changeset
|
542 (defun rebuild-mail-abbrevs (&optional file) |
459 | 543 "Rebuild all the mail aliases from the given file." |
544 (interactive (list | |
545 (let ((insert-default-directory t) | |
546 (default-directory (expand-file-name "~/")) | |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
547 (def mail-personal-alias-file)) |
459 | 548 (read-file-name |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64754
diff
changeset
|
549 (format "Read mail aliases from file (default %s): " def) |
459 | 550 default-directory |
551 (expand-file-name def default-directory) | |
552 t)))) | |
12945
14e16370799d
(rebuild-mail-abbrevs): FILE defaults to visited file.
Richard M. Stallman <rms@gnu.org>
parents:
12444
diff
changeset
|
553 (if (null file) |
14e16370799d
(rebuild-mail-abbrevs): FILE defaults to visited file.
Richard M. Stallman <rms@gnu.org>
parents:
12444
diff
changeset
|
554 (setq file buffer-file-name)) |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
555 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
556 (build-mail-abbrevs file)) |
584 | 557 |
28803
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
558 (defun mail-abbrev-insert-alias (&optional alias) |
598 | 559 "Prompt for and insert a mail alias." |
907 | 560 (interactive (progn |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
561 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup)) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
562 (list (completing-read "Expand alias: " mail-abbrevs nil t)))) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
563 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup)) |
13000
a86ad056a1cd
(mail-interactive-insert-alias): Call mail-abbrev-expand-hook.
Richard M. Stallman <rms@gnu.org>
parents:
12956
diff
changeset
|
564 (insert (or (and alias (symbol-value (intern-soft alias mail-abbrevs))) "")) |
a86ad056a1cd
(mail-interactive-insert-alias): Call mail-abbrev-expand-hook.
Richard M. Stallman <rms@gnu.org>
parents:
12956
diff
changeset
|
565 (mail-abbrev-expand-hook)) |
598 | 566 |
28803
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
567 (defun mail-abbrev-complete-alias () |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
568 "Perform completion on alias preceding point." |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
569 ;; Based on lisp.el:lisp-complete-symbol |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
570 (interactive) |
44379
5e64981e7abd
(mail-abbrev-complete-alias): Call mail-abbrev-make-syntax-table.
Richard M. Stallman <rms@gnu.org>
parents:
44118
diff
changeset
|
571 (mail-abbrev-make-syntax-table) |
28803
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
572 (let* ((end (point)) |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
573 (beg (with-syntax-table mail-abbrev-syntax-table |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
574 (save-excursion |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
575 (backward-word 1) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
576 (point)))) |
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
577 (alias (buffer-substring beg end)) |
28803
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
578 (completion (try-completion alias mail-abbrevs))) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
579 (cond ((eq completion t) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
580 (message "%s" alias)) ; confirm |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
581 ((null completion) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
582 (error "[Can't complete \"%s\"]" alias)) ; (message ...) (ding) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
583 ((not (string= completion alias)) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
584 (delete-region beg end) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
585 (insert completion)) |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
586 (t (with-output-to-temp-buffer "*Completions*" |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
587 (display-completion-list |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
588 (prog2 |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
589 (message "Making completion list...") |
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
590 (all-completions alias mail-abbrevs) |
66114
13abee3a9bc6
* message.el (message-expand-group): Pass the common
Masatake YAMATO <jet@gyve.org>
parents:
65680
diff
changeset
|
591 (message "Making completion list...done")) |
13abee3a9bc6
* message.el (message-expand-group): Pass the common
Masatake YAMATO <jet@gyve.org>
parents:
65680
diff
changeset
|
592 alias)))))) |
28803
80075cf72ede
(mail-abbrev-insert-alias): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
27589
diff
changeset
|
593 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
594 (defun mail-abbrev-next-line (&optional arg) |
102505
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
595 "Expand a mail abbrev before point, then move vertically down ARG lines. |
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
596 This only expands an abbrev (if one is present) if called with |
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
597 point at the end of a line, or on whitespace before the end of a line. |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
598 |
102505
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
599 In terms of line motion, this behaves like `next-line', which see." |
598 | 600 (interactive "p") |
717 | 601 (if (looking-at "[ \t]*\n") (expand-abbrev)) |
602 (setq this-command 'next-line) | |
85825
13163bbed0bf
* progmodes/mixal-mode.el (mixal-run, mixal-debug): Call mixvm
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78506
diff
changeset
|
603 (with-no-warnings (next-line arg))) |
598 | 604 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
605 (defun mail-abbrev-end-of-buffer (&optional arg) |
102505
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
606 "Expand a mail abbrev before point, then move to the end of the buffer. |
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
607 This only expands an abbrev (if one is present) if called with |
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
608 point at the end of a line, or on whitespace before the end of a line. |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
609 |
102505
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
610 In other respects, this behaves like `end-of-buffer', which see." |
4034
9e585b42806d
(mail-abbrev-end-of-buffer): Fix interactive spec to "P", same as
Roland McGrath <roland@gnu.org>
parents:
3945
diff
changeset
|
611 (interactive "P") |
717 | 612 (if (looking-at "[ \t]*\n") (expand-abbrev)) |
613 (setq this-command 'end-of-buffer) | |
102505
b03522350562
(mail-abbrev-next-line, mail-abbrev-end-of-buffer): Doc fixes.
Glenn Morris <rgm@gnu.org>
parents:
101009
diff
changeset
|
614 (with-no-warnings (end-of-buffer arg))) |
598 | 615 |
43214
c7e8bcec1caf
(mail-mode-map): Use eval-after-load to change it.
Richard M. Stallman <rms@gnu.org>
parents:
43136
diff
changeset
|
616 (eval-after-load "sendmail" |
c7e8bcec1caf
(mail-mode-map): Use eval-after-load to change it.
Richard M. Stallman <rms@gnu.org>
parents:
43136
diff
changeset
|
617 '(progn |
c7e8bcec1caf
(mail-mode-map): Use eval-after-load to change it.
Richard M. Stallman <rms@gnu.org>
parents:
43136
diff
changeset
|
618 (define-key mail-mode-map "\C-c\C-a" 'mail-abbrev-insert-alias) |
c7e8bcec1caf
(mail-mode-map): Use eval-after-load to change it.
Richard M. Stallman <rms@gnu.org>
parents:
43136
diff
changeset
|
619 (define-key mail-mode-map "\e\t" ; like lisp-complete-symbol |
c7e8bcec1caf
(mail-mode-map): Use eval-after-load to change it.
Richard M. Stallman <rms@gnu.org>
parents:
43136
diff
changeset
|
620 'mail-abbrev-complete-alias))) |
598 | 621 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
622 ;;(define-key mail-mode-map "\C-n" 'mail-abbrev-next-line) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
623 ;;(define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer) |
598 | 624 |
2418
3af5c7b9f4a1
Provide mailabbrev, not mail-abbrevs.
Richard M. Stallman <rms@gnu.org>
parents:
1832
diff
changeset
|
625 (provide 'mailabbrev) |
14169 | 626 |
85842
96510b236eb5
(mail-abbrevs-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85825
diff
changeset
|
627 ;; arch-tag: 5aa2d901-73f8-4ad7-b73c-4802282ad2ff |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
34921
diff
changeset
|
628 ;;; mailabbrev.el ends here |