]> code.delx.au - gnu-emacs/blob - lisp/mail/mailabbrev.el
(rmail-dont-reply-to): Understand
[gnu-emacs] / lisp / mail / mailabbrev.el
1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases.
2
3 ;; Copyright (C) 1985, 86, 87, 92, 93, 96, 1997 Free Software Foundation, Inc.
4
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
6 ;; Maintainer: Jamie Zawinski <jwz@lucid.com>
7 ;; Created: 19 Oct 90
8 ;; Keywords: mail
9
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
14 ;; the Free Software Foundation; either version 2, or (at your option)
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 the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; This file ensures that, when the point is in a To:, CC:, BCC:, or From:
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
32 ;; the MAILRC environment variable) if it exists. Your mail aliases will
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
44 ;; mode-specific abbrev table (mail-mode-abbrev-table) will be used if
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 ;;
52 ;; You can also insert a mail alias with mail-interactive-insert-alias
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
111 ;; 'mail-setup-hook
112 ;; '(lambda ()
113 ;; (substitute-key-definition 'next-line 'mail-abbrev-next-line
114 ;; mail-mode-map global-map)
115 ;; (substitute-key-definition 'end-of-buffer 'mail-abbrev-end-of-buffer
116 ;; mail-mode-map global-map)))
117 ;;
118 ;; If you want multiple addresses separated by a string other than ", " then
119 ;; you can set the variable mail-alias-separator-string to it. This has to
120 ;; be a comma bracketed by whitespace if you want any kind of reasonable
121 ;; behaviour.
122 ;;
123 ;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and
124 ;; Noah Friedman for suggestions and bug reports.
125
126 ;; To use this package, do (add-hook 'mail-setup-hook 'mail-abbrevs-setup).
127
128 ;;; Code:
129
130 (require 'sendmail)
131
132 (defgroup mail-abbrev nil
133 "Expand mail aliases as abbrevs, in certain mail headers."
134 :group 'abbrev-mode)
135
136 (defcustom mail-abbrevs-mode nil
137 "*Non-nil means expand mail aliases as abbrevs, in certain message headers."
138 :type 'boolean
139 :group 'mail-abbrev
140 :require 'mailabbrev
141 :set '(lambda (symbol value)
142 (setq mail-abbrevs-mode value)
143 (if value (mail-abbrevs-enable) (mail-abbrevs-disable)))
144 :initialize 'custom-initialize-default
145 :version "20.3")
146
147 (defcustom mail-abbrevs-only nil
148 "*Non-nil means only mail abbrevs should expand automatically.
149 Other abbrevs expand only when you explicitly use `expand-abbrev'."
150 :type 'boolean
151 :group 'mail-abbrev)
152
153 ;; originally defined in sendmail.el - used to be an alist, now is a table.
154 (defvar mail-abbrevs nil
155 "Word-abbrev table of mail address aliases.
156 If this is nil, it means the aliases have not yet been initialized and
157 should be read from the .mailrc file. (This is distinct from there being
158 no aliases, which is represented by this being a table with no entries.)")
159
160 (defvar mail-abbrev-modtime nil
161 "The modification time of your mail alias file when it was last examined.")
162
163 (defun mail-abbrevs-sync-aliases ()
164 (if (file-exists-p mail-personal-alias-file)
165 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
166 (if (not (equal mail-abbrev-modtime modtime))
167 (progn
168 (setq mail-abbrev-modtime modtime)
169 (build-mail-abbrevs))))))
170
171 ;;;###autoload
172 (defun mail-abbrevs-setup ()
173 "Initialize use of the `mailabbrev' package."
174 (if (and (not (vectorp mail-abbrevs))
175 (file-exists-p mail-personal-alias-file))
176 (progn
177 (setq mail-abbrev-modtime
178 (nth 5 (file-attributes mail-personal-alias-file)))
179 (build-mail-abbrevs)))
180 (mail-abbrevs-sync-aliases)
181 (make-local-hook 'pre-abbrev-expand-hook)
182 (add-hook 'pre-abbrev-expand-hook 'sendmail-pre-abbrev-expand-hook
183 nil t)
184 (abbrev-mode 1))
185
186 (defun mail-abbrevs-enable ()
187 (add-hook 'mail-setup-hook 'mail-abbrevs-setup))
188
189 (defun mail-abbrevs-disable ()
190 "Turn off use of the `mailabbrev' package."
191 (remove-hook 'mail-setup-hook 'mail-abbrevs-setup)
192 (abbrev-mode (if (default-value 'abbrev-mode) 1 -1)))
193
194 ;;;###autoload
195 (defun build-mail-abbrevs (&optional file recursivep)
196 "Read mail aliases from personal mail alias file and set `mail-abbrevs'.
197 By default this is the file specified by `mail-personal-alias-file'."
198 (setq file (expand-file-name (or file mail-personal-alias-file)))
199 (if (vectorp mail-abbrevs)
200 nil
201 (setq mail-abbrevs nil)
202 (define-abbrev-table 'mail-abbrevs '()))
203 (message "Parsing %s..." file)
204 (let ((buffer nil)
205 (obuf (current-buffer)))
206 (unwind-protect
207 (progn
208 (setq buffer (generate-new-buffer " mailrc"))
209 (buffer-disable-undo buffer)
210 (set-buffer buffer)
211 (cond ((get-file-buffer file)
212 (insert (save-excursion
213 (set-buffer (get-file-buffer file))
214 (buffer-substring (point-min) (point-max)))))
215 ((not (file-exists-p file)))
216 (t (insert-file-contents file)))
217 ;; Don't lose if no final newline.
218 (goto-char (point-max))
219 (or (eq (preceding-char) ?\n) (newline))
220 (goto-char (point-min))
221 ;; Delete comments from the file
222 (while (search-forward "# " nil t)
223 (let ((p (- (point) 2)))
224 (end-of-line)
225 (delete-region p (point))))
226 (goto-char (point-min))
227 ;; handle "\\\n" continuation lines
228 (while (not (eobp))
229 (end-of-line)
230 (if (= (preceding-char) ?\\)
231 (progn (delete-char -1) (delete-char 1) (insert ?\ ))
232 (forward-char 1)))
233 (goto-char (point-min))
234 (while (re-search-forward
235 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t)
236 (beginning-of-line)
237 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)")
238 (progn
239 (end-of-line)
240 (build-mail-abbrevs
241 (substitute-in-file-name
242 (buffer-substring (match-beginning 1) (match-end 1)))
243 t))
244 (re-search-forward "[ \t]+\\([^ \t\n]+\\)")
245 (let* ((name (buffer-substring
246 (match-beginning 1) (match-end 1)))
247 (start (progn (skip-chars-forward " \t") (point))))
248 (end-of-line)
249 ; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1)
250 (define-mail-abbrev
251 name
252 (buffer-substring start (point))
253 t))))
254 ;; Resolve forward references in .mailrc file.
255 ;; This would happen automatically before the first abbrev was
256 ;; expanded, but why not do it now.
257 (or recursivep (mail-resolve-all-aliases))
258 mail-abbrevs)
259 (if buffer (kill-buffer buffer))
260 (set-buffer obuf)))
261 (message "Parsing %s... done" file))
262
263 (defvar mail-alias-separator-string ", "
264 "*A string inserted between addresses in multi-address mail aliases.
265 This has to contain a comma, so \", \" is a reasonable value. You might
266 also want something like \",\\n \" to get each address on its own line.")
267
268 ;; define-mail-abbrev sets this flag, which causes mail-resolve-all-aliases
269 ;; to be called before expanding abbrevs if it's necessary.
270 (defvar mail-abbrev-aliases-need-to-be-resolved t)
271
272 ;; originally defined in mailalias.el ; build-mail-abbrevs calls this with
273 ;; stuff parsed from the .mailrc file.
274 ;;
275 ;;;###autoload
276 (defun define-mail-abbrev (name definition &optional from-mailrc-file)
277 "Define NAME as a mail alias abbrev that translates to DEFINITION.
278 If DEFINITION contains multiple addresses, separate them with commas."
279 ;; When this is called from build-mail-abbrevs, the third argument is
280 ;; true, and we do some evil space->comma hacking like /bin/mail does.
281 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
282 ;; Read the defaults first, if we have not done so.
283 (if (vectorp mail-abbrevs)
284 nil
285 (setq mail-abbrevs nil)
286 (define-abbrev-table 'mail-abbrevs '())
287 (if (file-exists-p mail-personal-alias-file)
288 (build-mail-abbrevs)))
289 ;; strip garbage from front and end
290 (if (string-match "\\`[ \t\n,]+" definition)
291 (setq definition (substring definition (match-end 0))))
292 (if (string-match "[ \t\n,]+\\'" definition)
293 (setq definition (substring definition 0 (match-beginning 0))))
294 (let* ((result '())
295 (L (length definition))
296 (start (if (> L 0) 0))
297 end)
298 (while start
299 ;; If we're reading from the mailrc file, then addresses are delimited
300 ;; by spaces, and addresses with embedded spaces must be surrounded by
301 ;; double-quotes. Otherwise, addresses are separated by commas.
302 (if from-mailrc-file
303 (if (eq ?\" (aref definition start))
304 (setq start (1+ start)
305 end (string-match "\"[ \t,]*" definition start))
306 (setq end (string-match "[ \t,]+" definition start)))
307 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
308 (setq result (cons (substring definition start end) result))
309 (setq start (and end
310 (/= (match-end 0) L)
311 (match-end 0))))
312 (setq definition (mapconcat (function identity)
313 (nreverse result)
314 mail-alias-separator-string)))
315 (setq mail-abbrev-aliases-need-to-be-resolved t)
316 (setq name (downcase name))
317 ;; use an abbrev table instead of an alist for mail-abbrevs.
318 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed.
319 (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook)))
320
321
322 (defun mail-resolve-all-aliases ()
323 "Resolve all forward references in the mail aliases table."
324 (if mail-abbrev-aliases-need-to-be-resolved
325 (progn
326 ;; (message "Resolving mail aliases...")
327 (if (vectorp mail-abbrevs)
328 (mapatoms (function mail-resolve-all-aliases-1) mail-abbrevs))
329 (setq mail-abbrev-aliases-need-to-be-resolved nil)
330 ;; (message "Resolving mail aliases... done.")
331 )))
332
333 (defun mail-resolve-all-aliases-1 (sym &optional so-far)
334 (if (memq sym so-far)
335 (error "mail alias loop detected: %s"
336 (mapconcat 'symbol-name (cons sym so-far) " <- ")))
337 (let ((definition (and (boundp sym) (symbol-value sym))))
338 (if definition
339 (let ((result '())
340 (start 0))
341 (while start
342 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start)))
343 (setq result (cons (substring definition start end) result)
344 start (and end (match-end 0)))))
345 (setq definition
346 (mapconcat (function (lambda (x)
347 (or (mail-resolve-all-aliases-1
348 (intern-soft (downcase x) mail-abbrevs)
349 (cons sym so-far))
350 x)))
351 (nreverse result)
352 mail-alias-separator-string))
353 (set sym definition))))
354 (symbol-value sym))
355
356
357 (defun mail-abbrev-expand-hook ()
358 "For use as the fourth arg to `define-abbrev'.
359 After expanding a mail-abbrev, if Auto Fill mode is on and we're past the
360 fill-column, break the line at the previous comma, and indent the next line."
361 ;; Disable abbrev mode to avoid recursion in indent-relative expanding
362 ;; part of the abbrev expansion as an abbrev itself.
363 (let ((abbrev-mode nil))
364 (save-excursion
365 (let ((p (point))
366 bol comma fp)
367 (beginning-of-line)
368 (setq bol (point))
369 (goto-char p)
370 (while (and auto-fill-function
371 (>= (current-column) fill-column)
372 (search-backward "," bol t))
373 (setq comma (point))
374 (forward-char 1) ; Now we are just past the comma.
375 (insert "\n")
376 (delete-horizontal-space)
377 (setq p (point))
378 (indent-relative)
379 (setq fp (buffer-substring p (point)))
380 ;; Go to the end of the new line.
381 (end-of-line)
382 (if (> (current-column) fill-column)
383 ;; It's still too long; do normal auto-fill.
384 (let ((fill-prefix (or fp "\t")))
385 (do-auto-fill)))
386 ;; Resume the search.
387 (goto-char comma)
388 )))))
389 \f
390 ;;; Syntax tables and abbrev-expansion
391
392 (defvar mail-abbrev-mode-regexp
393 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):"
394 "*Regexp to select mail-headers in which mail abbrevs should be expanded.
395 This string will be handed to `looking-at' with point at the beginning
396 of the current line; if it matches, abbrev mode will be turned on, otherwise
397 it will be turned off. (You don't need to worry about continuation lines.)
398 This should be set to match those mail fields in which you want abbreviations
399 turned on.")
400
401 (defvar mail-mode-header-syntax-table
402 (let ((tab (copy-syntax-table text-mode-syntax-table)))
403 ;; This makes the characters "@%!._-" be considered symbol-constituents
404 ;; but not word-constituents, so forward-sexp will move you over an
405 ;; entire address, but forward-word will only move you over a sequence
406 ;; of alphanumerics. (Clearly the right thing.)
407 (modify-syntax-entry ?@ "_" tab)
408 (modify-syntax-entry ?% "_" tab)
409 (modify-syntax-entry ?! "_" tab)
410 (modify-syntax-entry ?. "_" tab)
411 (modify-syntax-entry ?_ "_" tab)
412 (modify-syntax-entry ?- "_" tab)
413 (modify-syntax-entry ?< "(>" tab)
414 (modify-syntax-entry ?> ")<" tab)
415 tab)
416 "The syntax table used in send-mail mode when in a mail-address header.
417 `mail-mode-syntax-table' is used when the cursor is in the message body or in
418 non-address headers.")
419
420 (defvar mail-abbrev-syntax-table
421 (let* ((tab (copy-syntax-table mail-mode-header-syntax-table))
422 (_ (aref (standard-syntax-table) ?_))
423 (w (aref (standard-syntax-table) ?w)))
424 (map-char-table
425 (function (lambda (key value)
426 (if (equal value _)
427 (set-char-table-range tab key w))))
428 tab)
429 tab)
430 "The syntax-table used for abbrev-expansion purposes.
431 This is not actually made the current syntax table of the buffer, but
432 simply controls the set of characters which may be a part of the name
433 of a mail alias.")
434
435
436 (defun mail-abbrev-in-expansion-header-p ()
437 "Whether point is in a mail-address header field."
438 (let ((case-fold-search t))
439 (and ;;
440 ;; we are on an appropriate header line...
441 (save-excursion
442 (beginning-of-line)
443 ;; skip backwards over continuation lines.
444 (while (and (looking-at "^[ \t]")
445 (not (= (point) (point-min))))
446 (forward-line -1))
447 ;; are we at the front of an appropriate header line?
448 (looking-at mail-abbrev-mode-regexp))
449 ;;
450 ;; ...and are we in the headers?
451 (< (point) (mail-header-end)))))
452
453 (defvar mail-mode-abbrev-table) ; quiet the compiler
454
455 (defun sendmail-pre-abbrev-expand-hook ()
456 (and (and mail-abbrevs (not (eq mail-abbrevs t)))
457 (if (mail-abbrev-in-expansion-header-p)
458 (progn
459 ;;
460 ;; We are in a To: (or CC:, or whatever) header, and
461 ;; should use word-abbrevs to expand mail aliases.
462
463 ;; Before anything else, resolve aliases if they need it.
464 (and mail-abbrev-aliases-need-to-be-resolved
465 (mail-resolve-all-aliases))
466
467 ;; Now proceed with the abbrev section.
468 ;; - First, install the mail-abbrevs as the word-abbrev table.
469 ;; - Then install the mail-abbrev-syntax-table, which
470 ;; temporarily marks all of the
471 ;; non-alphanumeric-atom-characters (the "_"
472 ;; syntax ones) as being normal word-syntax. We do this
473 ;; because the C code for expand-abbrev only works on words,
474 ;; and we want these characters to be considered words for
475 ;; the purpose of abbrev expansion.
476 ;; - Then we call expand-abbrev again, recursively, to do
477 ;; the abbrev expansion with the above syntax table.
478 ;; - Then we do a trick which tells the expand-abbrev frame
479 ;; which invoked us to not continue (and thus not
480 ;; expand twice.) This means that any abbrev expansion
481 ;; will happen as a result of this function's call to
482 ;; expand-abbrev, and not as a result of the call to
483 ;; expand-abbrev which invoked *us*.
484 ;; - Then we set the syntax table to
485 ;; mail-mode-header-syntax-table, which doesn't have
486 ;; anything to do with abbrev expansion, but
487 ;; is just for the user's convenience (see its doc string.)
488 ;;
489
490 (setq local-abbrev-table mail-abbrevs)
491
492 ;; If the character just typed was non-alpha-symbol-syntax,
493 ;; then don't expand the abbrev now (that is, don't expand
494 ;; when the user types -.) Check the character's syntax in
495 ;; the mail-mode-header-syntax-table.
496
497 (set-syntax-table mail-mode-header-syntax-table)
498 (or (and (integerp last-command-char)
499 (eq (char-syntax last-command-char) ?_))
500 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop.
501 ;; Use this table so that abbrevs can have hyphens in them.
502 (set-syntax-table mail-abbrev-syntax-table)
503 (expand-abbrev)
504 ;; Now set it back to what it was before.
505 (set-syntax-table mail-mode-header-syntax-table)))
506 (setq abbrev-start-location (point-max) ; This is the trick.
507 abbrev-start-location-buffer (current-buffer)))
508
509 (if (or (not mail-abbrevs-only)
510 (eq this-command 'expand-abbrev))
511 (progn
512 ;; We're not in a mail header where mail aliases should
513 ;; be expanded, then use the normal mail-mode abbrev table
514 ;; (if any) and the normal mail-mode syntax table.
515
516 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table)
517 mail-mode-abbrev-table))
518 (set-syntax-table mail-mode-syntax-table))
519 ;; This is not a mail abbrev, and we should not expand it.
520 ;; This kludge stops expand-abbrev from doing anything.
521 (setq abbrev-start-location (point-max)
522 abbrev-start-location-buffer (current-buffer))))
523 ))
524 \f
525 ;;; utilities
526
527 (defun merge-mail-abbrevs (file)
528 "Merge mail aliases from the given file with existing ones."
529 (interactive (list
530 (let ((insert-default-directory t)
531 (default-directory (expand-file-name "~/"))
532 (def mail-personal-alias-file))
533 (read-file-name
534 (format "Read additional aliases from file: (default %s) "
535 def)
536 default-directory
537 (expand-file-name def default-directory)
538 t))))
539 (build-mail-abbrevs file))
540
541 (defun rebuild-mail-abbrevs (&optional file)
542 "Rebuild all the mail aliases from the given file."
543 (interactive (list
544 (let ((insert-default-directory t)
545 (default-directory (expand-file-name "~/"))
546 (def mail-personal-alias-file))
547 (read-file-name
548 (format "Read mail aliases from file: (default %s) " def)
549 default-directory
550 (expand-file-name def default-directory)
551 t))))
552 (if (null file)
553 (setq file buffer-file-name))
554 (setq mail-abbrevs nil)
555 (build-mail-abbrevs file))
556
557 (defun mail-interactive-insert-alias (&optional alias)
558 "Prompt for and insert a mail alias."
559 (interactive (progn
560 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup))
561 (list (completing-read "Expand alias: " mail-abbrevs nil t))))
562 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup))
563 (insert (or (and alias (symbol-value (intern-soft alias mail-abbrevs))) ""))
564 (mail-abbrev-expand-hook))
565
566 (defun mail-abbrev-next-line (&optional arg)
567 "Expand any mail abbrev, then move cursor vertically down ARG lines.
568 If there is no character in the target line exactly under the current column,
569 the cursor is positioned after the character in that line which spans this
570 column, or at the end of the line if it is not long enough.
571 If there is no line in the buffer after this one,
572 a newline character is inserted to create a line
573 and the cursor moves to that line.
574
575 The command \\[set-goal-column] can be used to create
576 a semipermanent goal column to which this command always moves.
577 Then it does not try to move vertically. This goal column is stored
578 in `goal-column', which is nil when there is none.
579
580 If you are thinking of using this in a Lisp program, consider
581 using `forward-line' instead. It is usually easier to use
582 and more reliable (no dependence on goal column, etc.)."
583 (interactive "p")
584 (if (looking-at "[ \t]*\n") (expand-abbrev))
585 (setq this-command 'next-line)
586 (next-line arg))
587
588 (defun mail-abbrev-end-of-buffer (&optional arg)
589 "Expand any mail abbrev, then move point to end of buffer.
590 Leave mark at previous position.
591 With arg N, put point N/10 of the way from the true end.
592
593 Don't use this command in Lisp programs!
594 \(goto-char (point-max)) is faster and avoids clobbering the mark."
595 (interactive "P")
596 (if (looking-at "[ \t]*\n") (expand-abbrev))
597 (setq this-command 'end-of-buffer)
598 (end-of-buffer arg))
599
600 (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias)
601
602 ;;(define-key mail-mode-map "\C-n" 'mail-abbrev-next-line)
603 ;;(define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer)
604
605 (provide 'mailabbrev)
606
607 (if mail-abbrevs-mode
608 (mail-abbrevs-enable))
609
610 ;;; mailabbrev.el ends here.