Mercurial > emacs
annotate lisp/mail/mailabbrev.el @ 10662:cd968ab6a0eb
(rmail-next-same-subject): New command.
(rmail-previous-same-subject): Likewise.
(rmail-mode-map): Add bindings for C-c C-n and C-c C-p.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 05 Feb 1995 02:46:08 +0000 |
parents | edd33989fb23 |
children | 52b3af3cb71a |
rev | line source |
---|---|
1148 | 1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases. |
2 | |
1832
f852ebc02465
(mail-abbrev-end-of-buffer): Changed interactive spec from "P" to "p".
Roland McGrath <roland@gnu.org>
parents:
1433
diff
changeset
|
3 ;;; Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc. |
1148 | 4 |
5 ;; Author: Jamie Zawinski <jwz@lucid.com> | |
6 ;; Maintainer: Jamie Zawinski <jwz@lucid.com> | |
7 ;; Created: 19 Oct 90 | |
8 ;; Keywords: mail | |
9 | |
459 | 10 ;;; This file is part of GNU Emacs. |
11 | |
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;;; it under the terms of the GNU General Public License as published by | |
717 | 14 ;;; the Free Software Foundation; either version 2, or (at your option) |
459 | 15 ;;; any later version. |
16 | |
17 ;;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;;; GNU General Public License for more details. | |
21 | |
22 ;;; You should have received a copy of the GNU General Public License | |
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
1148 | 26 ;;; Commentary: |
27 | |
459 | 28 ;;; This file ensures that, when the point is in a To:, CC:, BCC:, or From: |
29 ;;; field, word-abbrevs are defined for each of your mail aliases. These | |
30 ;;; aliases will be defined from your .mailrc file (or the file specified by | |
598 | 31 ;;; the MAILRC environment variable) if it exists. Your mail aliases will |
32 ;;; expand any time you type a word-delimiter at the end of an abbreviation. | |
459 | 33 ;;; |
34 ;;; What you see is what you get: no abbreviations will be expanded after you | |
35 ;;; have sent the mail, unlike the old system. This means you don't suffer | |
36 ;;; the annoyance of having the system do things behind your back -- if an | |
37 ;;; address you typed is going to be rewritten, you know it immediately, | |
38 ;;; instead of after the mail has been sent and it's too late to do anything | |
39 ;;; about it. You will never again be screwed because you forgot to delete an | |
40 ;;; old alias from your .mailrc when a new local user arrives and is given a | |
41 ;;; userid which conflicts with one of your aliases, for example. | |
42 ;;; | |
43 ;;; Your mail alias abbrevs will be in effect only when the point is in an | |
44 ;;; appropriate header field. When in the body of the message, or other | |
45 ;;; header fields, the mail aliases will not expand. Rather, the normal | |
46 ;;; mode-specific abbrev table (mail-mode-abbrev-table) will be used if | |
47 ;;; defined. So if you use mail-mode specific abbrevs, this code will not | |
48 ;;; adversely affect you. You can control which header fields the abbrevs | |
49 ;;; are used in by changing the variable mail-abbrev-mode-regexp. | |
50 ;;; | |
51 ;;; If auto-fill mode is on, abbrevs will wrap at commas instead of at word | |
52 ;;; boundaries; also, header continuation-lines will be properly indented. | |
53 ;;; | |
54 ;;; You can also insert a mail alias with mail-interactive-insert-alias | |
55 ;;; (bound to C-c C-a), which prompts you for an alias (with completion) | |
56 ;;; and inserts its expansion at point. | |
57 ;;; | |
58 ;;; This file fixes a bug in the old system which prohibited your .mailrc | |
59 ;;; file from having lines like | |
60 ;;; | |
61 ;;; alias someone "John Doe <doe@quux.com>" | |
62 ;;; | |
63 ;;; That is, if you want an address to have embedded spaces, simply surround it | |
64 ;;; with double-quotes. This is necessary because the format of the .mailrc | |
65 ;;; file bogusly uses spaces as address delimiters. The following line defines | |
66 ;;; an alias which expands to three addresses: | |
67 ;;; | |
68 ;;; alias foobar addr-1 addr-2 "address three <addr-3>" | |
69 ;;; | |
70 ;;; (This is bogus because mail-delivery programs want commas, not spaces, | |
71 ;;; but that's what the file format is, so we have to live with it.) | |
72 ;;; | |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
73 ;;; If you like, you can call the function define-mail-abbrev to define your |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
74 ;;; mail aliases instead of using a .mailrc file. When you call it in this |
627 | 75 ;;; way, addresses are separated by commas. |
459 | 76 ;;; |
77 ;;; CAVEAT: This works on most Sun systems; I have been told that some versions | |
78 ;;; of /bin/mail do not understand double-quotes in the .mailrc file. So you | |
79 ;;; should make sure your version does before including verbose addresses like | |
80 ;;; this. One solution to this, if you are on a system whose /bin/mail doesn't | |
81 ;;; work that way, (and you still want to be able to /bin/mail to send mail in | |
82 ;;; addition to emacs) is to define minimal aliases (without full names) in | |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
83 ;;; your .mailrc file, and use define-mail-abbrev to redefine them when sending |
459 | 84 ;;; mail from emacs; this way, mail sent from /bin/mail will work, and mail |
85 ;;; sent from emacs will be pretty. | |
86 ;;; | |
87 ;;; Aliases in the mailrc file may be nested. If you define aliases like | |
88 ;;; alias group1 fred ethel | |
89 ;;; alias group2 larry curly moe | |
90 ;;; alias everybody group1 group2 | |
91 ;;; Then when you type "everybody" on the To: line, it will be expanded to | |
92 ;;; fred, ethyl, larry, curly, moe | |
93 ;;; | |
94 ;;; Aliases may also contain forward references; the alias of "everybody" can | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2418
diff
changeset
|
95 ;;; precede the aliases of "group1" and "group2". |
459 | 96 ;;; |
97 ;;; This code also understands the "source" .mailrc command, for reading | |
98 ;;; aliases from some other file as well. | |
99 ;;; | |
598 | 100 ;;; Aliases may contain hyphens, as in "alias foo-bar foo@bar"; word-abbrevs |
101 ;;; normally cannot contain hyphens, but this code works around that for the | |
102 ;;; specific case of mail-alias word-abbrevs. | |
103 ;;; | |
459 | 104 ;;; To read in the contents of another .mailrc-type file from emacs, use the |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
105 ;;; command Meta-X merge-mail-abbrevs. The rebuild-mail-abbrevs command is |
459 | 106 ;;; similar, but will delete existing aliases first. |
107 ;;; | |
598 | 108 ;;; If you would like your aliases to be expanded when you type M-> or ^N to |
109 ;;; move out of the mail-header into the message body (instead of having to | |
110 ;;; type SPC at the end of the abbrev before moving away) then you can do | |
111 ;;; | |
1433 | 112 ;;; (define-key mail-mode-map "\C-n" 'mail-abbrev-next-line) |
113 ;;; (define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer) | |
598 | 114 ;;; |
627 | 115 ;;; If you want multiple addresses separated by a string other than ", " then |
116 ;;; you can set the variable mail-alias-separator-string to it. This has to | |
459 | 117 ;;; be a comma bracketed by whitespace if you want any kind of reasonable |
118 ;;; behaviour. | |
119 ;;; | |
120 ;;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and | |
121 ;;; Noah Friedman for suggestions and bug reports. | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
122 |
4317 | 123 ;;; To use this package, do (add-hook 'mail-setup-hook 'mail-abbrevs-setup). |
459 | 124 |
1148 | 125 ;;; Code: |
126 | |
459 | 127 (require 'sendmail) |
128 | |
129 ;; 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
|
130 (defvar mail-abbrevs nil |
598 | 131 "Word-abbrev table of mail address aliases. |
459 | 132 If this is nil, it means the aliases have not yet been initialized and |
133 should be read from the .mailrc file. (This is distinct from there being | |
134 no aliases, which is represented by this being a table with no entries.)") | |
135 | |
474 | 136 ;;;###autoload |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
137 (defun mail-abbrevs-setup () |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
138 (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
|
139 (file-exists-p mail-personal-alias-file)) |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
140 (build-mail-abbrevs)) |
606 | 141 (make-local-variable 'pre-abbrev-expand-hook) |
142 (setq pre-abbrev-expand-hook | |
143 (cond ((and (listp pre-abbrev-expand-hook) | |
144 (not (eq 'lambda (car pre-abbrev-expand-hook)))) | |
145 (cons 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook)) | |
146 (t | |
147 (list 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook)))) | |
459 | 148 (abbrev-mode 1)) |
149 | |
598 | 150 ;;;###autoload |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
151 (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
|
152 "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
|
153 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
|
154 (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
|
155 (if (vectorp mail-abbrevs) |
459 | 156 nil |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
157 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
158 (define-abbrev-table 'mail-abbrevs '())) |
606 | 159 (message "Parsing %s..." file) |
459 | 160 (let ((buffer nil) |
161 (obuf (current-buffer))) | |
162 (unwind-protect | |
163 (progn | |
164 (setq buffer (generate-new-buffer "mailrc")) | |
598 | 165 (buffer-disable-undo buffer) |
459 | 166 (set-buffer buffer) |
167 (cond ((get-file-buffer file) | |
168 (insert (save-excursion | |
169 (set-buffer (get-file-buffer file)) | |
170 (buffer-substring (point-min) (point-max))))) | |
171 ((not (file-exists-p file))) | |
172 (t (insert-file-contents file))) | |
173 ;; Don't lose if no final newline. | |
174 (goto-char (point-max)) | |
175 (or (eq (preceding-char) ?\n) (newline)) | |
176 (goto-char (point-min)) | |
177 ;; Delete comments from the file | |
178 (while (search-forward "# " nil t) | |
179 (let ((p (- (point) 2))) | |
180 (end-of-line) | |
181 (delete-region p (point)))) | |
182 (goto-char (point-min)) | |
183 ;; handle "\\\n" continuation lines | |
184 (while (not (eobp)) | |
185 (end-of-line) | |
186 (if (= (preceding-char) ?\\) | |
187 (progn (delete-char -1) (delete-char 1) (insert ?\ )) | |
188 (forward-char 1))) | |
189 (goto-char (point-min)) | |
190 (while (re-search-forward | |
907 | 191 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t) |
459 | 192 (beginning-of-line) |
193 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)") | |
194 (progn | |
195 (end-of-line) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
196 (build-mail-abbrevs |
3945
7a8d0a08eac7
(build-mail-abbrevs): Do substitute-in-file-name on the abbrev, for `source'.
Richard M. Stallman <rms@gnu.org>
parents:
3742
diff
changeset
|
197 (substitute-in-file-name |
7939
338a91733ff9
(build-mail-abbrevs): Pass a recursivep argument in recursive call.
Richard M. Stallman <rms@gnu.org>
parents:
5559
diff
changeset
|
198 (buffer-substring (match-beginning 1) (match-end 1))) |
338a91733ff9
(build-mail-abbrevs): Pass a recursivep argument in recursive call.
Richard M. Stallman <rms@gnu.org>
parents:
5559
diff
changeset
|
199 t)) |
459 | 200 (re-search-forward "[ \t]+\\([^ \t\n]+\\)") |
201 (let* ((name (buffer-substring | |
202 (match-beginning 1) (match-end 1))) | |
203 (start (progn (skip-chars-forward " \t") (point)))) | |
204 (end-of-line) | |
205 ; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1) | |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
206 (define-mail-abbrev |
459 | 207 name |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
208 (buffer-substring start (point)) |
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
209 t)))) |
459 | 210 ;; Resolve forward references in .mailrc file. |
211 ;; This would happen automatically before the first abbrev was | |
212 ;; expanded, but why not do it now. | |
213 (or recursivep (mail-resolve-all-aliases)) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
214 mail-abbrevs) |
459 | 215 (if buffer (kill-buffer buffer)) |
216 (set-buffer obuf))) | |
606 | 217 (message "Parsing %s... done" file)) |
459 | 218 |
627 | 219 (defvar mail-alias-separator-string ", " |
459 | 220 "*A string inserted between addresses in multi-address mail aliases. |
221 This has to contain a comma, so \", \" is a reasonable value. You might | |
222 also want something like \",\\n \" to get each address on its own line.") | |
223 | |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
224 ;; define-mail-abbrev sets this flag, which causes mail-resolve-all-aliases |
459 | 225 ;; to be called before expanding abbrevs if it's necessary. |
226 (defvar mail-abbrev-aliases-need-to-be-resolved t) | |
227 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
228 ;; originally defined in mailalias.el ; build-mail-abbrevs calls this with |
459 | 229 ;; stuff parsed from the .mailrc file. |
230 ;; | |
474 | 231 ;;;###autoload |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
232 (defun define-mail-abbrev (name definition &optional from-mailrc-file) |
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
233 "Define NAME as a mail-abbrev that translates to DEFINITION. |
627 | 234 If DEFINITION contains multiple addresses, separate them with commas." |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
235 ;; When this is called from build-mail-abbrevs, the third argument is |
459 | 236 ;; true, and we do some evil space->comma hacking like /bin/mail does. |
237 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") | |
238 ;; Read the defaults first, if we have not done so. | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
239 (if (vectorp mail-abbrevs) |
459 | 240 nil |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
241 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
242 (define-abbrev-table 'mail-abbrevs '()) |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
243 (if (file-exists-p mail-personal-alias-file) |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
244 (build-mail-abbrevs))) |
459 | 245 ;; strip garbage from front and end |
246 (if (string-match "\\`[ \t\n,]+" definition) | |
247 (setq definition (substring definition (match-end 0)))) | |
248 (if (string-match "[ \t\n,]+\\'" definition) | |
249 (setq definition (substring definition 0 (match-beginning 0)))) | |
8215
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
250 (let* ((result '()) |
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
251 (L (length definition)) |
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
252 (start (if (> L 0) 0)) |
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
253 end) |
459 | 254 (while start |
255 ;; If we're reading from the mailrc file, then addresses are delimited | |
256 ;; by spaces, and addresses with embedded spaces must be surrounded by | |
627 | 257 ;; double-quotes. Otherwise, addresses are separated by commas. |
459 | 258 (if from-mailrc-file |
259 (if (eq ?\" (aref definition start)) | |
260 (setq start (1+ start) | |
261 end (string-match "\"[ \t,]*" definition start)) | |
8215
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
262 (setq end (string-match "[ \t,]+" definition start))) |
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
263 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start))) |
459 | 264 (setq result (cons (substring definition start end) result)) |
265 (setq start (and end | |
266 (/= (match-end 0) L) | |
267 (match-end 0)))) | |
268 (setq definition (mapconcat (function identity) | |
269 (nreverse result) | |
627 | 270 mail-alias-separator-string))) |
459 | 271 (setq mail-abbrev-aliases-need-to-be-resolved t) |
272 (setq name (downcase name)) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
273 ;; use an abbrev table instead of an alist for mail-abbrevs. |
459 | 274 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed. |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
275 (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook))) |
459 | 276 |
277 | |
278 (defun mail-resolve-all-aliases () | |
279 "Resolve all forward references in the mail aliases table." | |
280 (if mail-abbrev-aliases-need-to-be-resolved | |
281 (progn | |
282 ;; (message "Resolving mail aliases...") | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
283 (if (vectorp mail-abbrevs) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
284 (mapatoms (function mail-resolve-all-aliases-1) mail-abbrevs)) |
459 | 285 (setq mail-abbrev-aliases-need-to-be-resolved nil) |
286 ;; (message "Resolving mail aliases... done.") | |
287 ))) | |
288 | |
717 | 289 (defun mail-resolve-all-aliases-1 (sym &optional so-far) |
290 (if (memq sym so-far) | |
291 (error "mail alias loop detected: %s" | |
292 (mapconcat 'symbol-name (cons sym so-far) " <- "))) | |
459 | 293 (let ((definition (and (boundp sym) (symbol-value sym)))) |
294 (if definition | |
295 (let ((result '()) | |
296 (start 0)) | |
297 (while start | |
298 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start))) | |
299 (setq result (cons (substring definition start end) result) | |
300 start (and end (match-end 0))))) | |
301 (setq definition | |
302 (mapconcat (function (lambda (x) | |
303 (or (mail-resolve-all-aliases-1 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
304 (intern-soft x mail-abbrevs) |
717 | 305 (cons sym so-far)) |
459 | 306 x))) |
307 (nreverse result) | |
627 | 308 mail-alias-separator-string)) |
459 | 309 (set sym definition)))) |
310 (symbol-value sym)) | |
311 | |
312 | |
627 | 313 (defun mail-abbrev-expand-hook () |
598 | 314 "For use as the fourth arg to define-abbrev. |
627 | 315 After expanding a mail-abbrev, if fill-mode is on and we're past the |
598 | 316 fill-column, break the line at the previous comma, and indent the next |
317 line." | |
608 | 318 (save-excursion |
319 (let ((p (point)) | |
320 bol comma fp) | |
321 (beginning-of-line) | |
322 (setq bol (point)) | |
323 (goto-char p) | |
606 | 324 (while (and auto-fill-function |
608 | 325 (>= (current-column) fill-column) |
326 (search-backward "," bol t)) | |
327 (setq comma (point)) | |
328 (forward-char 1) ; Now we are just past the comma. | |
329 (insert "\n") | |
330 (delete-horizontal-space) | |
627 | 331 (setq p (point)) |
608 | 332 (indent-relative) |
333 (setq fp (buffer-substring p (point))) | |
334 ;; Go to the end of the new line. | |
335 (end-of-line) | |
336 (if (> (current-column) fill-column) | |
337 ;; It's still too long; do normal auto-fill. | |
338 (let ((fill-prefix (or fp "\t"))) | |
339 (do-auto-fill))) | |
340 ;; Resume the search. | |
341 (goto-char comma) | |
342 )))) | |
598 | 343 |
344 ;;; Syntax tables and abbrev-expansion | |
459 | 345 |
5559
e976a52296fc
(mail-abbrev-mode-regexp): Add Reply-to.
Richard M. Stallman <rms@gnu.org>
parents:
4805
diff
changeset
|
346 (defvar mail-abbrev-mode-regexp |
e976a52296fc
(mail-abbrev-mode-regexp): Add Reply-to.
Richard M. Stallman <rms@gnu.org>
parents:
4805
diff
changeset
|
347 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):" |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
348 "*Regexp to select mail-headers in which mail-abbrevs should be expanded. |
459 | 349 This string it will be handed to `looking-at' with the point at the beginning |
350 of the current line; if it matches, abbrev mode will be turned on, otherwise | |
351 it will be turned off. (You don't need to worry about continuation lines.) | |
352 This should be set to match those mail fields in which you want abbreviations | |
353 turned on.") | |
354 | |
355 (defvar mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table) | |
598 | 356 "The syntax table which is used in send-mail mode message bodies.") |
459 | 357 |
358 (defvar mail-mode-header-syntax-table | |
359 (let ((tab (copy-syntax-table text-mode-syntax-table))) | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2418
diff
changeset
|
360 ;; This makes the characters "@%!._-" be considered symbol-constituents |
459 | 361 ;; but not word-constituents, so forward-sexp will move you over an |
362 ;; entire address, but forward-word will only move you over a sequence | |
363 ;; of alphanumerics. (Clearly the right thing.) | |
364 (modify-syntax-entry ?@ "_" tab) | |
365 (modify-syntax-entry ?% "_" tab) | |
366 (modify-syntax-entry ?! "_" tab) | |
367 (modify-syntax-entry ?. "_" tab) | |
368 (modify-syntax-entry ?_ "_" tab) | |
369 (modify-syntax-entry ?- "_" tab) | |
370 (modify-syntax-entry ?< "(>" tab) | |
371 (modify-syntax-entry ?> ")<" tab) | |
372 tab) | |
598 | 373 "The syntax table used in send-mail mode when in a mail-address header. |
374 mail-mode-syntax-table is used when the cursor is in the message body or in | |
375 non-address headers.") | |
376 | |
377 (defvar mail-abbrev-syntax-table | |
378 (let* ((tab (copy-syntax-table mail-mode-header-syntax-table)) | |
379 (i (1- (length tab))) | |
380 (_ (aref (standard-syntax-table) ?_)) | |
381 (w (aref (standard-syntax-table) ?w))) | |
382 (while (>= i 0) | |
383 (if (= (aref tab i) _) (aset tab i w)) | |
384 (setq i (1- i))) | |
385 tab) | |
386 "The syntax-table used for abbrev-expansion purposes; this is not actually | |
387 made the current syntax table of the buffer, but simply controls the set of | |
388 characters which may be a part of the name of a mail-alias.") | |
389 | |
459 | 390 |
598 | 391 (defun mail-abbrev-in-expansion-header-p () |
392 "Whether point is in a mail-address header field." | |
393 (let ((case-fold-search t)) | |
394 (and ;; | |
395 ;; we are on an appropriate header line... | |
396 (save-excursion | |
397 (beginning-of-line) | |
398 ;; skip backwards over continuation lines. | |
399 (while (and (looking-at "^[ \t]") | |
400 (not (= (point) (point-min)))) | |
401 (forward-line -1)) | |
402 ;; are we at the front of an appropriate header line? | |
403 (looking-at mail-abbrev-mode-regexp)) | |
404 ;; | |
405 ;; ...and we are before the mail-header-separator | |
406 (< (point) | |
407 (save-excursion | |
408 (goto-char (point-min)) | |
409 (search-forward (concat "\n" mail-header-separator "\n") | |
410 nil 0) | |
411 (point)))))) | |
412 | |
413 (defvar mail-mode-abbrev-table) ; quiet the compiler | |
414 | |
627 | 415 (defun sendmail-pre-abbrev-expand-hook () |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
416 (and (and mail-abbrevs (not (eq mail-abbrevs t))) |
1148 | 417 (if (mail-abbrev-in-expansion-header-p) |
418 (progn | |
419 ;; | |
420 ;; We are in a To: (or CC:, or whatever) header, and | |
421 ;; should use word-abbrevs to expand mail aliases. | |
422 | |
423 ;; Before anything else, resolve aliases if they need it. | |
424 (and mail-abbrev-aliases-need-to-be-resolved | |
425 (mail-resolve-all-aliases)) | |
426 | |
427 ;; Now proceed with the abbrev section. | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
428 ;; - First, install the mail-abbrevs as the word-abbrev table. |
1148 | 429 ;; - Then install the mail-abbrev-syntax-table, which |
430 ;; temporarily marks all of the | |
431 ;; non-alphanumeric-atom-characters (the "_" | |
432 ;; syntax ones) as being normal word-syntax. We do this | |
433 ;; because the C code for expand-abbrev only works on words, | |
434 ;; and we want these characters to be considered words for | |
435 ;; the purpose of abbrev expansion. | |
436 ;; - Then we call expand-abbrev again, recursively, to do | |
437 ;; the abbrev expansion with the above syntax table. | |
438 ;; - Then we do a trick which tells the expand-abbrev frame | |
439 ;; which invoked us to not continue (and thus not | |
440 ;; expand twice.) This means that any abbrev expansion | |
441 ;; will happen as a result of this function's call to | |
442 ;; expand-abbrev, and not as a result of the call to | |
443 ;; expand-abbrev which invoked *us*. | |
444 ;; - Then we set the syntax table to | |
445 ;; mail-mode-header-syntax-table, which doesn't have | |
446 ;; anything to do with abbrev expansion, but | |
447 ;; is just for the user's convenience (see its doc string.) | |
448 ;; | |
449 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
450 (setq local-abbrev-table mail-abbrevs) |
1148 | 451 |
452 ;; If the character just typed was non-alpha-symbol-syntax, | |
453 ;; then don't expand the abbrev now (that is, don't expand | |
454 ;; when the user types -.) Check the character's syntax in | |
455 ;; the mail-mode-header-syntax-table. | |
456 | |
457 (set-syntax-table mail-mode-header-syntax-table) | |
3668
87f7ff6bba51
(sendmail-pre-abbrev-expand-hook):
Richard M. Stallman <rms@gnu.org>
parents:
3664
diff
changeset
|
458 (or (and (integerp last-command-char) |
87f7ff6bba51
(sendmail-pre-abbrev-expand-hook):
Richard M. Stallman <rms@gnu.org>
parents:
3664
diff
changeset
|
459 (eq (char-syntax last-command-char) ?_)) |
1148 | 460 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop. |
461 ;; Use this table so that abbrevs can have hyphens in them. | |
462 (set-syntax-table mail-abbrev-syntax-table) | |
463 (expand-abbrev) | |
464 ;; Now set it back to what it was before. | |
465 (set-syntax-table mail-mode-header-syntax-table))) | |
466 (setq abbrev-start-location (point) ; This is the trick. | |
467 abbrev-start-location-buffer (current-buffer))) | |
468 | |
469 ;; We're not in a mail header where mail aliases should | |
470 ;; be expanded, then use the normal mail-mode abbrev table | |
471 ;; (if any) and the normal mail-mode syntax table. | |
472 | |
473 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table) | |
474 mail-mode-abbrev-table)) | |
475 (set-syntax-table mail-mode-syntax-table)) | |
476 )) | |
598 | 477 |
478 ;;; utilities | |
459 | 479 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
480 (defun merge-mail-abbrevs (file) |
459 | 481 "Merge mail aliases from the given file with existing ones." |
482 (interactive (list | |
483 (let ((insert-default-directory t) | |
484 (default-directory (expand-file-name "~/")) | |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
485 (def mail-personal-alias-file)) |
459 | 486 (read-file-name |
487 (format "Read additional aliases from file: (default %s) " | |
488 def) | |
489 default-directory | |
490 (expand-file-name def default-directory) | |
491 t)))) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
492 (build-mail-abbrevs file)) |
459 | 493 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
494 (defun rebuild-mail-abbrevs (file) |
459 | 495 "Rebuild all the mail aliases from the given file." |
496 (interactive (list | |
497 (let ((insert-default-directory t) | |
498 (default-directory (expand-file-name "~/")) | |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
499 (def mail-personal-alias-file)) |
459 | 500 (read-file-name |
501 (format "Read mail aliases from file: (default %s) " def) | |
502 default-directory | |
503 (expand-file-name def default-directory) | |
504 t)))) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
505 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
506 (build-mail-abbrevs file)) |
584 | 507 |
598 | 508 (defun mail-interactive-insert-alias (&optional alias) |
509 "Prompt for and insert a mail alias." | |
907 | 510 (interactive (progn |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
511 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup)) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
512 (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
|
513 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup)) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
514 (insert (or (and alias (symbol-value (intern-soft alias mail-abbrevs))) ""))) |
598 | 515 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
516 (defun mail-abbrev-next-line (&optional arg) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
517 "Expand any mail abbrev, then move cursor vertically down ARG lines. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
518 If there is no character in the target line exactly under the current column, |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
519 the cursor is positioned after the character in that line which spans this |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
520 column, or at the end of the line if it is not long enough. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
521 If there is no line in the buffer after this one, |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
522 a newline character is inserted to create a line |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
523 and the cursor moves to that line. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
524 |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
525 The command \\[set-goal-column] can be used to create |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
526 a semipermanent goal column to which this command always moves. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
527 Then it does not try to move vertically. This goal column is stored |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
528 in `goal-column', which is nil when there is none. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
529 |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
530 If you are thinking of using this in a Lisp program, consider |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
531 using `forward-line' instead. It is usually easier to use |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
532 and more reliable (no dependence on goal column, etc.)." |
598 | 533 (interactive "p") |
717 | 534 (if (looking-at "[ \t]*\n") (expand-abbrev)) |
535 (setq this-command 'next-line) | |
598 | 536 (next-line arg)) |
537 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
538 (defun mail-abbrev-end-of-buffer (&optional arg) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
539 "Expand any mail abbrev, then move point to end of buffer. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
540 Leave mark at previous position. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
541 With arg N, put point N/10 of the way from the true end. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
542 |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
543 Don't use this command in Lisp programs! |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
544 \(goto-char (point-max)) is faster and avoids clobbering the mark." |
4034
9e585b42806d
(mail-abbrev-end-of-buffer): Fix interactive spec to "P", same as
Roland McGrath <roland@gnu.org>
parents:
3945
diff
changeset
|
545 (interactive "P") |
717 | 546 (if (looking-at "[ \t]*\n") (expand-abbrev)) |
547 (setq this-command 'end-of-buffer) | |
598 | 548 (end-of-buffer arg)) |
549 | |
550 (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias) | |
551 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
552 ;;(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
|
553 ;;(define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer) |
598 | 554 |
2418
3af5c7b9f4a1
Provide mailabbrev, not mail-abbrevs.
Richard M. Stallman <rms@gnu.org>
parents:
1832
diff
changeset
|
555 (provide 'mailabbrev) |