Mercurial > emacs
annotate lisp/mail/mailabbrev.el @ 13548:9be6c740e36f
(fill-individual-paragraphs): Advance 1 line in inner loop.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 14 Nov 1995 23:28:24 +0000 |
parents | 1220026cd3a3 |
children | 2a2eaca9d6bb |
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)) |
11059 | 141 (make-local-hook 'pre-abbrev-expand-hook) |
142 (add-hook 'pre-abbrev-expand-hook 'sendmail-pre-abbrev-expand-hook | |
143 nil t) | |
459 | 144 (abbrev-mode 1)) |
145 | |
598 | 146 ;;;###autoload |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
147 (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
|
148 "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
|
149 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
|
150 (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
|
151 (if (vectorp mail-abbrevs) |
459 | 152 nil |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
153 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
154 (define-abbrev-table 'mail-abbrevs '())) |
606 | 155 (message "Parsing %s..." file) |
459 | 156 (let ((buffer nil) |
157 (obuf (current-buffer))) | |
158 (unwind-protect | |
159 (progn | |
160 (setq buffer (generate-new-buffer "mailrc")) | |
598 | 161 (buffer-disable-undo buffer) |
459 | 162 (set-buffer buffer) |
163 (cond ((get-file-buffer file) | |
164 (insert (save-excursion | |
165 (set-buffer (get-file-buffer file)) | |
166 (buffer-substring (point-min) (point-max))))) | |
167 ((not (file-exists-p file))) | |
168 (t (insert-file-contents file))) | |
169 ;; Don't lose if no final newline. | |
170 (goto-char (point-max)) | |
171 (or (eq (preceding-char) ?\n) (newline)) | |
172 (goto-char (point-min)) | |
173 ;; Delete comments from the file | |
174 (while (search-forward "# " nil t) | |
175 (let ((p (- (point) 2))) | |
176 (end-of-line) | |
177 (delete-region p (point)))) | |
178 (goto-char (point-min)) | |
179 ;; handle "\\\n" continuation lines | |
180 (while (not (eobp)) | |
181 (end-of-line) | |
182 (if (= (preceding-char) ?\\) | |
183 (progn (delete-char -1) (delete-char 1) (insert ?\ )) | |
184 (forward-char 1))) | |
185 (goto-char (point-min)) | |
186 (while (re-search-forward | |
907 | 187 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t) |
459 | 188 (beginning-of-line) |
189 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)") | |
190 (progn | |
191 (end-of-line) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
192 (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
|
193 (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
|
194 (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
|
195 t)) |
459 | 196 (re-search-forward "[ \t]+\\([^ \t\n]+\\)") |
197 (let* ((name (buffer-substring | |
198 (match-beginning 1) (match-end 1))) | |
199 (start (progn (skip-chars-forward " \t") (point)))) | |
200 (end-of-line) | |
201 ; (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
|
202 (define-mail-abbrev |
459 | 203 name |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
204 (buffer-substring start (point)) |
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
205 t)))) |
459 | 206 ;; Resolve forward references in .mailrc file. |
207 ;; This would happen automatically before the first abbrev was | |
208 ;; expanded, but why not do it now. | |
209 (or recursivep (mail-resolve-all-aliases)) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
210 mail-abbrevs) |
459 | 211 (if buffer (kill-buffer buffer)) |
212 (set-buffer obuf))) | |
606 | 213 (message "Parsing %s... done" file)) |
459 | 214 |
627 | 215 (defvar mail-alias-separator-string ", " |
459 | 216 "*A string inserted between addresses in multi-address mail aliases. |
217 This has to contain a comma, so \", \" is a reasonable value. You might | |
218 also want something like \",\\n \" to get each address on its own line.") | |
219 | |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
220 ;; define-mail-abbrev sets this flag, which causes mail-resolve-all-aliases |
459 | 221 ;; to be called before expanding abbrevs if it's necessary. |
222 (defvar mail-abbrev-aliases-need-to-be-resolved t) | |
223 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
224 ;; originally defined in mailalias.el ; build-mail-abbrevs calls this with |
459 | 225 ;; stuff parsed from the .mailrc file. |
226 ;; | |
474 | 227 ;;;###autoload |
3742
f5bbe69b8bc5
(define-mail-abbrev): Renamed from define-mail-alias.
Richard M. Stallman <rms@gnu.org>
parents:
3741
diff
changeset
|
228 (defun define-mail-abbrev (name definition &optional from-mailrc-file) |
11059 | 229 "Define NAME as a mail alias abbrev that translates to DEFINITION. |
627 | 230 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
|
231 ;; When this is called from build-mail-abbrevs, the third argument is |
459 | 232 ;; true, and we do some evil space->comma hacking like /bin/mail does. |
233 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") | |
234 ;; 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
|
235 (if (vectorp mail-abbrevs) |
459 | 236 nil |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
237 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
238 (define-abbrev-table 'mail-abbrevs '()) |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
239 (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
|
240 (build-mail-abbrevs))) |
459 | 241 ;; strip garbage from front and end |
242 (if (string-match "\\`[ \t\n,]+" definition) | |
243 (setq definition (substring definition (match-end 0)))) | |
244 (if (string-match "[ \t\n,]+\\'" definition) | |
245 (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
|
246 (let* ((result '()) |
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
247 (L (length definition)) |
767bef8ec35b
(define-mail-abbrev): Don't try to parse empty aliases.
Richard M. Stallman <rms@gnu.org>
parents:
7939
diff
changeset
|
248 (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
|
249 end) |
459 | 250 (while start |
251 ;; If we're reading from the mailrc file, then addresses are delimited | |
252 ;; by spaces, and addresses with embedded spaces must be surrounded by | |
627 | 253 ;; double-quotes. Otherwise, addresses are separated by commas. |
459 | 254 (if from-mailrc-file |
255 (if (eq ?\" (aref definition start)) | |
256 (setq start (1+ start) | |
257 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
|
258 (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
|
259 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start))) |
459 | 260 (setq result (cons (substring definition start end) result)) |
261 (setq start (and end | |
262 (/= (match-end 0) L) | |
263 (match-end 0)))) | |
264 (setq definition (mapconcat (function identity) | |
265 (nreverse result) | |
627 | 266 mail-alias-separator-string))) |
459 | 267 (setq mail-abbrev-aliases-need-to-be-resolved t) |
268 (setq name (downcase name)) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
269 ;; use an abbrev table instead of an alist for mail-abbrevs. |
459 | 270 (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
|
271 (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook))) |
459 | 272 |
273 | |
274 (defun mail-resolve-all-aliases () | |
275 "Resolve all forward references in the mail aliases table." | |
276 (if mail-abbrev-aliases-need-to-be-resolved | |
277 (progn | |
278 ;; (message "Resolving mail aliases...") | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
279 (if (vectorp mail-abbrevs) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
280 (mapatoms (function mail-resolve-all-aliases-1) mail-abbrevs)) |
459 | 281 (setq mail-abbrev-aliases-need-to-be-resolved nil) |
282 ;; (message "Resolving mail aliases... done.") | |
283 ))) | |
284 | |
717 | 285 (defun mail-resolve-all-aliases-1 (sym &optional so-far) |
286 (if (memq sym so-far) | |
287 (error "mail alias loop detected: %s" | |
288 (mapconcat 'symbol-name (cons sym so-far) " <- "))) | |
459 | 289 (let ((definition (and (boundp sym) (symbol-value sym)))) |
290 (if definition | |
291 (let ((result '()) | |
292 (start 0)) | |
293 (while start | |
294 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start))) | |
295 (setq result (cons (substring definition start end) result) | |
296 start (and end (match-end 0))))) | |
297 (setq definition | |
298 (mapconcat (function (lambda (x) | |
299 (or (mail-resolve-all-aliases-1 | |
12444
0f96d53b31b7
(mail-resolve-all-aliases-1):
Richard M. Stallman <rms@gnu.org>
parents:
11504
diff
changeset
|
300 (intern-soft (downcase x) mail-abbrevs) |
717 | 301 (cons sym so-far)) |
459 | 302 x))) |
303 (nreverse result) | |
627 | 304 mail-alias-separator-string)) |
459 | 305 (set sym definition)))) |
306 (symbol-value sym)) | |
307 | |
308 | |
627 | 309 (defun mail-abbrev-expand-hook () |
11059 | 310 "For use as the fourth arg to `define-abbrev'. |
311 After expanding a mail-abbrev, if Auto Fill mode is on and we're past the | |
312 fill-column, break the line at the previous comma, and indent the next line." | |
608 | 313 (save-excursion |
314 (let ((p (point)) | |
315 bol comma fp) | |
316 (beginning-of-line) | |
317 (setq bol (point)) | |
318 (goto-char p) | |
606 | 319 (while (and auto-fill-function |
608 | 320 (>= (current-column) fill-column) |
321 (search-backward "," bol t)) | |
322 (setq comma (point)) | |
323 (forward-char 1) ; Now we are just past the comma. | |
324 (insert "\n") | |
325 (delete-horizontal-space) | |
627 | 326 (setq p (point)) |
608 | 327 (indent-relative) |
328 (setq fp (buffer-substring p (point))) | |
329 ;; Go to the end of the new line. | |
330 (end-of-line) | |
331 (if (> (current-column) fill-column) | |
332 ;; It's still too long; do normal auto-fill. | |
333 (let ((fill-prefix (or fp "\t"))) | |
334 (do-auto-fill))) | |
335 ;; Resume the search. | |
336 (goto-char comma) | |
337 )))) | |
598 | 338 |
339 ;;; Syntax tables and abbrev-expansion | |
459 | 340 |
5559
e976a52296fc
(mail-abbrev-mode-regexp): Add Reply-to.
Richard M. Stallman <rms@gnu.org>
parents:
4805
diff
changeset
|
341 (defvar mail-abbrev-mode-regexp |
e976a52296fc
(mail-abbrev-mode-regexp): Add Reply-to.
Richard M. Stallman <rms@gnu.org>
parents:
4805
diff
changeset
|
342 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):" |
11059 | 343 "*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
|
344 This string will be handed to `looking-at' with point at the beginning |
459 | 345 of the current line; if it matches, abbrev mode will be turned on, otherwise |
346 it will be turned off. (You don't need to worry about continuation lines.) | |
347 This should be set to match those mail fields in which you want abbreviations | |
348 turned on.") | |
349 | |
350 (defvar mail-mode-header-syntax-table | |
351 (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
|
352 ;; This makes the characters "@%!._-" be considered symbol-constituents |
459 | 353 ;; but not word-constituents, so forward-sexp will move you over an |
354 ;; entire address, but forward-word will only move you over a sequence | |
355 ;; of alphanumerics. (Clearly the right thing.) | |
356 (modify-syntax-entry ?@ "_" tab) | |
357 (modify-syntax-entry ?% "_" tab) | |
358 (modify-syntax-entry ?! "_" tab) | |
359 (modify-syntax-entry ?. "_" tab) | |
360 (modify-syntax-entry ?_ "_" tab) | |
361 (modify-syntax-entry ?- "_" tab) | |
362 (modify-syntax-entry ?< "(>" tab) | |
363 (modify-syntax-entry ?> ")<" tab) | |
364 tab) | |
598 | 365 "The syntax table used in send-mail mode when in a mail-address header. |
11059 | 366 `mail-mode-syntax-table' is used when the cursor is in the message body or in |
598 | 367 non-address headers.") |
368 | |
369 (defvar mail-abbrev-syntax-table | |
370 (let* ((tab (copy-syntax-table mail-mode-header-syntax-table)) | |
371 (_ (aref (standard-syntax-table) ?_)) | |
372 (w (aref (standard-syntax-table) ?w))) | |
13258
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
373 (map-char-table |
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
374 (function (lambda (key value) |
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
375 (if (equal value _) |
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
376 (set-char-table-range tab key w)))) |
13362
1220026cd3a3
(mail-abbrev-syntax-table): Fix initialization.
Richard M. Stallman <rms@gnu.org>
parents:
13258
diff
changeset
|
377 tab) |
1220026cd3a3
(mail-abbrev-syntax-table): Fix initialization.
Richard M. Stallman <rms@gnu.org>
parents:
13258
diff
changeset
|
378 tab) |
13258
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
379 "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
|
380 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
|
381 simply controls the set of characters which may be a part of the name |
2a96bf08bccb
(mail-abbrev-syntax-table): Rewrite using map-char-table.
Richard M. Stallman <rms@gnu.org>
parents:
13161
diff
changeset
|
382 of a mail alias.") |
598 | 383 |
459 | 384 |
598 | 385 (defun mail-abbrev-in-expansion-header-p () |
386 "Whether point is in a mail-address header field." | |
387 (let ((case-fold-search t)) | |
388 (and ;; | |
389 ;; we are on an appropriate header line... | |
390 (save-excursion | |
391 (beginning-of-line) | |
392 ;; skip backwards over continuation lines. | |
393 (while (and (looking-at "^[ \t]") | |
394 (not (= (point) (point-min)))) | |
395 (forward-line -1)) | |
396 ;; are we at the front of an appropriate header line? | |
397 (looking-at mail-abbrev-mode-regexp)) | |
398 ;; | |
399 ;; ...and we are before the mail-header-separator | |
400 (< (point) | |
401 (save-excursion | |
402 (goto-char (point-min)) | |
403 (search-forward (concat "\n" mail-header-separator "\n") | |
404 nil 0) | |
405 (point)))))) | |
406 | |
407 (defvar mail-mode-abbrev-table) ; quiet the compiler | |
408 | |
627 | 409 (defun sendmail-pre-abbrev-expand-hook () |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
410 (and (and mail-abbrevs (not (eq mail-abbrevs t))) |
1148 | 411 (if (mail-abbrev-in-expansion-header-p) |
412 (progn | |
413 ;; | |
414 ;; We are in a To: (or CC:, or whatever) header, and | |
415 ;; should use word-abbrevs to expand mail aliases. | |
416 | |
417 ;; Before anything else, resolve aliases if they need it. | |
418 (and mail-abbrev-aliases-need-to-be-resolved | |
419 (mail-resolve-all-aliases)) | |
420 | |
421 ;; Now proceed with the abbrev section. | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
422 ;; - First, install the mail-abbrevs as the word-abbrev table. |
1148 | 423 ;; - Then install the mail-abbrev-syntax-table, which |
424 ;; temporarily marks all of the | |
425 ;; non-alphanumeric-atom-characters (the "_" | |
426 ;; syntax ones) as being normal word-syntax. We do this | |
427 ;; because the C code for expand-abbrev only works on words, | |
428 ;; and we want these characters to be considered words for | |
429 ;; the purpose of abbrev expansion. | |
430 ;; - Then we call expand-abbrev again, recursively, to do | |
431 ;; the abbrev expansion with the above syntax table. | |
432 ;; - Then we do a trick which tells the expand-abbrev frame | |
433 ;; which invoked us to not continue (and thus not | |
434 ;; expand twice.) This means that any abbrev expansion | |
435 ;; will happen as a result of this function's call to | |
436 ;; expand-abbrev, and not as a result of the call to | |
437 ;; expand-abbrev which invoked *us*. | |
438 ;; - Then we set the syntax table to | |
439 ;; mail-mode-header-syntax-table, which doesn't have | |
440 ;; anything to do with abbrev expansion, but | |
441 ;; is just for the user's convenience (see its doc string.) | |
442 ;; | |
443 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
444 (setq local-abbrev-table mail-abbrevs) |
1148 | 445 |
446 ;; If the character just typed was non-alpha-symbol-syntax, | |
447 ;; then don't expand the abbrev now (that is, don't expand | |
448 ;; when the user types -.) Check the character's syntax in | |
449 ;; the mail-mode-header-syntax-table. | |
450 | |
451 (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
|
452 (or (and (integerp last-command-char) |
87f7ff6bba51
(sendmail-pre-abbrev-expand-hook):
Richard M. Stallman <rms@gnu.org>
parents:
3664
diff
changeset
|
453 (eq (char-syntax last-command-char) ?_)) |
1148 | 454 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop. |
455 ;; Use this table so that abbrevs can have hyphens in them. | |
456 (set-syntax-table mail-abbrev-syntax-table) | |
457 (expand-abbrev) | |
458 ;; Now set it back to what it was before. | |
459 (set-syntax-table mail-mode-header-syntax-table))) | |
11504
ae5b033ad31f
(sendmail-pre-abbrev-expand-hook): When setting the
Karl Heuer <kwzh@gnu.org>
parents:
11059
diff
changeset
|
460 (setq abbrev-start-location (point-max) ; This is the trick. |
1148 | 461 abbrev-start-location-buffer (current-buffer))) |
462 | |
463 ;; We're not in a mail header where mail aliases should | |
464 ;; be expanded, then use the normal mail-mode abbrev table | |
465 ;; (if any) and the normal mail-mode syntax table. | |
466 | |
467 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table) | |
468 mail-mode-abbrev-table)) | |
469 (set-syntax-table mail-mode-syntax-table)) | |
470 )) | |
598 | 471 |
472 ;;; utilities | |
459 | 473 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
474 (defun merge-mail-abbrevs (file) |
459 | 475 "Merge mail aliases from the given file with existing ones." |
476 (interactive (list | |
477 (let ((insert-default-directory t) | |
478 (default-directory (expand-file-name "~/")) | |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
479 (def mail-personal-alias-file)) |
459 | 480 (read-file-name |
481 (format "Read additional aliases from file: (default %s) " | |
482 def) | |
483 default-directory | |
484 (expand-file-name def default-directory) | |
485 t)))) | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
486 (build-mail-abbrevs file)) |
459 | 487 |
12945
14e16370799d
(rebuild-mail-abbrevs): FILE defaults to visited file.
Richard M. Stallman <rms@gnu.org>
parents:
12444
diff
changeset
|
488 (defun rebuild-mail-abbrevs (&optional file) |
459 | 489 "Rebuild all the mail aliases from the given file." |
490 (interactive (list | |
491 (let ((insert-default-directory t) | |
492 (default-directory (expand-file-name "~/")) | |
10328
edd33989fb23
(mail-abbrev-mailrc-file): Variable and macro deleted.
Noah Friedman <friedman@splode.com>
parents:
8215
diff
changeset
|
493 (def mail-personal-alias-file)) |
459 | 494 (read-file-name |
495 (format "Read mail aliases from file: (default %s) " def) | |
496 default-directory | |
497 (expand-file-name def default-directory) | |
498 t)))) | |
12945
14e16370799d
(rebuild-mail-abbrevs): FILE defaults to visited file.
Richard M. Stallman <rms@gnu.org>
parents:
12444
diff
changeset
|
499 (if (null file) |
14e16370799d
(rebuild-mail-abbrevs): FILE defaults to visited file.
Richard M. Stallman <rms@gnu.org>
parents:
12444
diff
changeset
|
500 (setq file buffer-file-name)) |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
501 (setq mail-abbrevs nil) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
502 (build-mail-abbrevs file)) |
584 | 503 |
598 | 504 (defun mail-interactive-insert-alias (&optional alias) |
505 "Prompt for and insert a mail alias." | |
907 | 506 (interactive (progn |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
507 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup)) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
508 (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
|
509 (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
|
510 (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
|
511 (mail-abbrev-expand-hook)) |
598 | 512 |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
513 (defun mail-abbrev-next-line (&optional arg) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
514 "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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 and the cursor moves to that line. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
521 |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 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
|
526 |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
527 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
|
528 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
|
529 and more reliable (no dependence on goal column, etc.)." |
598 | 530 (interactive "p") |
717 | 531 (if (looking-at "[ \t]*\n") (expand-abbrev)) |
532 (setq this-command 'next-line) | |
598 | 533 (next-line arg)) |
534 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
535 (defun mail-abbrev-end-of-buffer (&optional arg) |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
536 "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
|
537 Leave mark at previous position. |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
538 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
|
539 |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
540 Don't use this command in Lisp programs! |
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
541 \(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
|
542 (interactive "P") |
717 | 543 (if (looking-at "[ \t]*\n") (expand-abbrev)) |
544 (setq this-command 'end-of-buffer) | |
598 | 545 (end-of-buffer arg)) |
546 | |
547 (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias) | |
548 | |
1432
7446ab662993
Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents:
1150
diff
changeset
|
549 ;;(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
|
550 ;;(define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer) |
598 | 551 |
2418
3af5c7b9f4a1
Provide mailabbrev, not mail-abbrevs.
Richard M. Stallman <rms@gnu.org>
parents:
1832
diff
changeset
|
552 (provide 'mailabbrev) |