Merge from emacs--rel--22
[bpt/emacs.git] / lisp / mail / mailabbrev.el
1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases
2
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1996, 1997, 2000, 2001,
4 ;; 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Jamie Zawinski <jwz@lucid.com>, now <jwz@jwz.org>
7 ;; Maintainer: FSF
8 ;; Created: 19 Oct 90
9 ;; Keywords: mail
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;; This file ensures that, when the point is in a To:, CC:, BCC:, or From:
31 ;; field, word-abbrevs are defined for each of your mail aliases. These
32 ;; aliases will be defined from your .mailrc file (or the file specified by
33 ;; `mail-personal-alias-file') if it exists. Your mail aliases will
34 ;; expand any time you type a word-delimiter at the end of an abbreviation.
35 ;;
36 ;; What you see is what you get: if mailabbrev is in use when you type
37 ;; a name, and the name does not expand, you know it is not an abbreviation.
38 ;; However, if you yank abbreviations into the headers
39 ;; in a way that bypasses the check for abbreviations,
40 ;; they are expanded (but not visibly) when you send the message.
41 ;;
42 ;; Your mail alias abbrevs will be in effect only when the point is in an
43 ;; appropriate header field. When in the body of the message, or other
44 ;; header fields, the mail aliases will not expand. Rather, the normal
45 ;; mode-specific abbrev table will be used if
46 ;; defined. So if you use mail-mode specific abbrevs, this code will not
47 ;; adversely affect you. You can control which header fields the abbrevs
48 ;; are used in by changing the variable mail-abbrev-mode-regexp.
49 ;;
50 ;; If auto-fill mode is on, abbrevs will wrap at commas instead of at word
51 ;; boundaries; also, header continuation-lines will be properly indented.
52 ;;
53 ;; You can also insert a mail alias with mail-abbrev-insert-alias
54 ;; (bound to C-c C-a), which prompts you for an alias (with completion)
55 ;; and inserts its expansion at point.
56 ;;
57 ;; This file fixes a bug in the old system which prohibited your .mailrc
58 ;; file from having lines like
59 ;;
60 ;; alias someone "John Doe <doe@quux.com>"
61 ;;
62 ;; That is, if you want an address to have embedded spaces, simply surround it
63 ;; with double-quotes. This is necessary because the format of the .mailrc
64 ;; file bogusly uses spaces as address delimiters. The following line defines
65 ;; an alias which expands to three addresses:
66 ;;
67 ;; alias foobar addr-1 addr-2 "address three <addr-3>"
68 ;;
69 ;; (This is bogus because mail-delivery programs want commas, not spaces,
70 ;; but that's what the file format is, so we have to live with it.)
71 ;;
72 ;; If you like, you can call the function define-mail-abbrev to define your
73 ;; mail aliases instead of using a .mailrc file. When you call it in this
74 ;; way, addresses are separated by commas.
75 ;;
76 ;; CAVEAT: This works on most Sun systems; I have been told that some versions
77 ;; of /bin/mail do not understand double-quotes in the .mailrc file. So you
78 ;; should make sure your version does before including verbose addresses like
79 ;; this. One solution to this, if you are on a system whose /bin/mail doesn't
80 ;; work that way, (and you still want to be able to /bin/mail to send mail in
81 ;; addition to emacs) is to define minimal aliases (without full names) in
82 ;; your .mailrc file, and use define-mail-abbrev to redefine them when sending
83 ;; mail from emacs; this way, mail sent from /bin/mail will work, and mail
84 ;; sent from emacs will be pretty.
85 ;;
86 ;; Aliases in the mailrc file may be nested. If you define aliases like
87 ;; alias group1 fred ethel
88 ;; alias group2 larry curly moe
89 ;; alias everybody group1 group2
90 ;; Then when you type "everybody" on the To: line, it will be expanded to
91 ;; fred, ethyl, larry, curly, moe
92 ;;
93 ;; Aliases may also contain forward references; the alias of "everybody" can
94 ;; precede the aliases of "group1" and "group2".
95 ;;
96 ;; This code also understands the "source" .mailrc command, for reading
97 ;; aliases from some other file as well.
98 ;;
99 ;; Aliases may contain hyphens, as in "alias foo-bar foo@bar"; word-abbrevs
100 ;; normally cannot contain hyphens, but this code works around that for the
101 ;; specific case of mail-alias word-abbrevs.
102 ;;
103 ;; To read in the contents of another .mailrc-type file from emacs, use the
104 ;; command Meta-X merge-mail-abbrevs. The rebuild-mail-abbrevs command is
105 ;; similar, but will delete existing aliases first.
106 ;;
107 ;; If you would like your aliases to be expanded when you type M-> or ^N to
108 ;; move out of the mail-header into the message body (instead of having to
109 ;; type SPC at the end of the abbrev before moving away) then you can do
110 ;;
111 ;; (add-hook
112 ;; 'mail-mode-hook
113 ;; (lambda ()
114 ;; (define-key mail-mode-map [remap next-line] 'mail-abbrev-next-line)
115 ;; (define-key mail-mode-map [remap end-of-buffer] 'mail-abbrev-end-of-buffer)))
116 ;;
117 ;; If you want multiple addresses separated by a string other than ", " then
118 ;; you can set the variable mail-alias-separator-string to it. This has to
119 ;; be a comma bracketed by whitespace if you want any kind of reasonable
120 ;; behaviour.
121 ;;
122 ;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and
123 ;; Noah Friedman for suggestions and bug reports.
124
125 ;; To use this package, do (add-hook 'mail-mode-hook 'mail-abbrevs-setup).
126
127 ;;; Code:
128
129 (eval-when-compile
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 ;;;###autoload
137 (define-minor-mode mail-abbrevs-mode
138 "Non-nil means expand mail aliases as abbrevs, in certain message headers."
139 :global t
140 :group 'mail-abbrev
141 :version "20.3"
142 (if mail-abbrevs-mode (mail-abbrevs-enable) (mail-abbrevs-disable)))
143
144 (defcustom mail-abbrevs-only nil
145 "Non-nil means only mail abbrevs should expand automatically.
146 Other abbrevs expand only when you explicitly use `expand-abbrev'."
147 :type 'boolean
148 :group 'mail-abbrev)
149
150 ;; originally defined in sendmail.el - used to be an alist, now is a table.
151 (defvar mail-abbrevs nil
152 "Word-abbrev table of mail address aliases.
153 If this is nil, it means the aliases have not yet been initialized and
154 should be read from the .mailrc file. (This is distinct from there being
155 no aliases, which is represented by this being a table with no entries.)")
156
157 (defvar mail-abbrev-modtime nil
158 "The modification time of your mail alias file when it was last examined.")
159
160 (defun mail-abbrevs-sync-aliases ()
161 (when mail-personal-alias-file
162 (if (file-exists-p mail-personal-alias-file)
163 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
164 (if (not (equal mail-abbrev-modtime modtime))
165 (progn
166 (setq mail-abbrev-modtime modtime)
167 (build-mail-abbrevs)))))))
168
169 ;;;###autoload
170 (defun mail-abbrevs-setup ()
171 "Initialize use of the `mailabbrev' package."
172 (if (and (not (vectorp mail-abbrevs))
173 (file-exists-p mail-personal-alias-file))
174 (progn
175 (setq mail-abbrev-modtime
176 (nth 5 (file-attributes mail-personal-alias-file)))
177 (build-mail-abbrevs)))
178 (mail-abbrevs-sync-aliases)
179 (add-hook 'abbrev-expand-functions 'mail-abbrev-expand-wrapper nil t)
180 (abbrev-mode 1))
181
182 (defun mail-abbrevs-enable ()
183 (add-hook 'mail-mode-hook 'mail-abbrevs-setup))
184
185 (defun mail-abbrevs-disable ()
186 "Turn off use of the `mailabbrev' package."
187 (remove-hook 'mail-mode-hook 'mail-abbrevs-setup)
188 (abbrev-mode (if (default-value 'abbrev-mode) 1 -1)))
189
190 ;;;###autoload
191 (defun build-mail-abbrevs (&optional file recursivep)
192 "Read mail aliases from personal mail alias file and set `mail-abbrevs'.
193 By default this is the file specified by `mail-personal-alias-file'."
194 (setq file (expand-file-name (or file mail-personal-alias-file)))
195 (if (vectorp mail-abbrevs)
196 nil
197 (setq mail-abbrevs nil)
198 (define-abbrev-table 'mail-abbrevs '()))
199 (message "Parsing %s..." file)
200 (with-temp-buffer
201 (buffer-disable-undo)
202 (cond ((get-file-buffer file)
203 (insert (with-current-buffer (get-file-buffer file)
204 (buffer-substring (point-min) (point-max)))))
205 ((not (file-exists-p file)))
206 (t (insert-file-contents file)))
207 ;; Don't lose if no final newline.
208 (goto-char (point-max))
209 (or (eq (preceding-char) ?\n) (newline))
210 (goto-char (point-min))
211 ;; Delete comments from the file
212 (while (search-forward "# " nil t)
213 (let ((p (- (point) 2)))
214 (end-of-line)
215 (delete-region p (point))))
216 (goto-char (point-min))
217 ;; handle "\\\n" continuation lines
218 (while (not (eobp))
219 (end-of-line)
220 (if (= (preceding-char) ?\\)
221 (progn (delete-char -1) (delete-char 1) (insert ?\ ))
222 (forward-char 1)))
223 (goto-char (point-min))
224 (while (re-search-forward
225 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t)
226 (beginning-of-line)
227 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)")
228 (progn
229 (end-of-line)
230 (build-mail-abbrevs
231 (substitute-in-file-name
232 (buffer-substring (match-beginning 1) (match-end 1)))
233 t))
234 (re-search-forward "[ \t]+\\([^ \t\n]+\\)")
235 (let* ((name (buffer-substring
236 (match-beginning 1) (match-end 1)))
237 (start (progn (skip-chars-forward " \t") (point))))
238 (end-of-line)
239 ;; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1)
240 (define-mail-abbrev
241 name
242 (buffer-substring start (point))
243 t))))
244 ;; Resolve forward references in .mailrc file.
245 ;; This would happen automatically before the first abbrev was
246 ;; expanded, but why not do it now.
247 (or recursivep (mail-resolve-all-aliases))
248 mail-abbrevs)
249 (message "Parsing %s... done" file))
250
251 (defvar mail-alias-separator-string ", "
252 "*A string inserted between addresses in multi-address mail aliases.
253 This has to contain a comma, so \", \" is a reasonable value. You might
254 also want something like \",\\n \" to get each address on its own line.")
255
256 ;; define-mail-abbrev sets this flag, which causes mail-resolve-all-aliases
257 ;; to be called before expanding abbrevs if it's necessary.
258 (defvar mail-abbrev-aliases-need-to-be-resolved t)
259
260 ;; originally defined in mailalias.el ; build-mail-abbrevs calls this with
261 ;; stuff parsed from the .mailrc file.
262 ;;
263 ;;;###autoload
264 (defun define-mail-abbrev (name definition &optional from-mailrc-file)
265 "Define NAME as a mail alias abbrev that translates to DEFINITION.
266 If DEFINITION contains multiple addresses, separate them with commas."
267 ;; When this is called from build-mail-abbrevs, the third argument is
268 ;; true, and we do some evil space->comma hacking like /bin/mail does.
269 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
270 ;; Read the defaults first, if we have not done so.
271 (unless (vectorp mail-abbrevs) (build-mail-abbrevs))
272 ;; strip garbage from front and end
273 (if (string-match "\\`[ \t\n,]+" definition)
274 (setq definition (substring definition (match-end 0))))
275 (if (string-match "[ \t\n,]+\\'" definition)
276 (setq definition (substring definition 0 (match-beginning 0))))
277 (let* ((result '())
278 (L (length definition))
279 (start (if (> L 0) 0))
280 end)
281 (while start
282 ;; If we're reading from the mailrc file, then addresses are delimited
283 ;; by spaces, and addresses with embedded spaces must be surrounded by
284 ;; double-quotes. Otherwise, addresses are separated by commas.
285 (if from-mailrc-file
286 (if (eq ?\" (aref definition start))
287 (setq start (1+ start)
288 end (string-match "\"[ \t,]*" definition start))
289 (setq end (string-match "[ \t,]+" definition start)))
290 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
291 (let ((tem (substring definition start end)))
292 ;; Advance the loop past this address.
293 (setq start (and end
294 (/= (match-end 0) L)
295 (match-end 0)))
296 ;; If the full name contains a problem character, quote it.
297 (when (string-match "\\(.+?\\)[ \t]*\\(<.*>\\)" tem)
298 (if (string-match "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]"
299 (match-string 1 tem))
300 (setq tem (replace-regexp-in-string
301 "\\(.+?\\)[ \t]*\\(<.*>\\)" "\"\\1\" \\2"
302 tem))))
303 (push tem result)))
304 (setq definition (mapconcat (function identity)
305 (nreverse result)
306 mail-alias-separator-string)))
307 (setq mail-abbrev-aliases-need-to-be-resolved t)
308 (setq name (downcase name))
309 ;; use an abbrev table instead of an alist for mail-abbrevs.
310 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed.
311 (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook 0 t)))
312
313
314 (defun mail-resolve-all-aliases ()
315 "Resolve all forward references in the mail aliases table."
316 (if mail-abbrev-aliases-need-to-be-resolved
317 (progn
318 ;; (message "Resolving mail aliases...")
319 (if (vectorp mail-abbrevs)
320 (mapatoms (function mail-resolve-all-aliases-1) mail-abbrevs))
321 (setq mail-abbrev-aliases-need-to-be-resolved nil)
322 ;; (message "Resolving mail aliases... done.")
323 )))
324
325 (defun mail-resolve-all-aliases-1 (sym &optional so-far)
326 (if (memq sym so-far)
327 (error "mail alias loop detected: %s"
328 (mapconcat 'symbol-name (cons sym so-far) " <- ")))
329 (let ((definition (and (boundp sym) (symbol-value sym))))
330 (if definition
331 (let ((result '())
332 (start 0))
333 (while start
334 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start)))
335 (setq result (cons (substring definition start end) result)
336 start (and end (match-end 0)))))
337 (setq definition
338 (mapconcat (function (lambda (x)
339 (or (mail-resolve-all-aliases-1
340 (intern-soft (downcase x) mail-abbrevs)
341 (cons sym so-far))
342 x)))
343 (nreverse result)
344 mail-alias-separator-string))
345 (set sym definition))))
346 (symbol-value sym))
347
348
349 (defun mail-abbrev-expand-hook ()
350 "For use as the fourth arg to `define-abbrev'.
351 After expanding a mail-abbrev, if Auto Fill mode is on and we're past the
352 fill-column, break the line at the previous comma, and indent the next line."
353 ;; Disable abbrev mode to avoid recursion in indent-relative expanding
354 ;; part of the abbrev expansion as an abbrev itself.
355 (let ((abbrev-mode nil))
356 (save-excursion
357 (let ((p (point))
358 bol comma fp)
359 (beginning-of-line)
360 (setq bol (point))
361 (goto-char p)
362 (while (and auto-fill-function
363 (>= (current-column) fill-column)
364 (search-backward "," bol t))
365 (setq comma (point))
366 (forward-char 1) ; Now we are just past the comma.
367 (insert "\n")
368 (delete-horizontal-space)
369 (setq p (point))
370 (indent-relative)
371 (setq fp (buffer-substring p (point)))
372 ;; Go to the end of the new line.
373 (end-of-line)
374 (if (> (current-column) fill-column)
375 ;; It's still too long; do normal auto-fill.
376 (let ((fill-prefix (or fp "\t")))
377 (do-auto-fill)))
378 ;; Resume the search.
379 (goto-char comma)
380 )))))
381 \f
382 ;;; Syntax tables and abbrev-expansion
383
384 (defvar mail-abbrev-mode-regexp
385 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):"
386 "*Regexp to select mail-headers in which mail abbrevs should be expanded.
387 This string will be handed to `looking-at' with point at the beginning
388 of the current line; if it matches, abbrev mode will be turned on, otherwise
389 it will be turned off. (You don't need to worry about continuation lines.)
390 This should be set to match those mail fields in which you want abbreviations
391 turned on.")
392
393 (defvar mail-abbrev-syntax-table nil
394 "The syntax-table used for abbrev-expansion purposes.
395 This is not actually made the current syntax table of the buffer, but
396 simply controls the set of characters which may be a part of the name
397 of a mail alias. The value is set up, buffer-local, when first needed.")
398
399 (defun mail-abbrev-make-syntax-table ()
400 (make-local-variable 'mail-abbrev-syntax-table)
401 (unless mail-abbrev-syntax-table
402 (let ((tab (copy-syntax-table (syntax-table)))
403 (_ (aref (standard-syntax-table) ?_))
404 (w (aref (standard-syntax-table) ?w)))
405 (map-char-table
406 (function (lambda (key value)
407 (if (null value)
408 ;; Fetch the inherited value
409 (setq value (aref tab key)))
410 (if (equal value _)
411 (set-char-table-range tab key w))))
412 tab)
413 (modify-syntax-entry ?@ "w" tab)
414 (modify-syntax-entry ?% "w" tab)
415 (modify-syntax-entry ?! "w" tab)
416 (modify-syntax-entry ?. "w" tab)
417 (modify-syntax-entry ?_ "w" tab)
418 (modify-syntax-entry ?- "w" tab)
419 (setq mail-abbrev-syntax-table tab))))
420
421 (defun mail-abbrev-in-expansion-header-p ()
422 "Whether point is in a mail-address header field."
423 (let ((case-fold-search t))
424 (and ;;
425 ;; we are on an appropriate header line...
426 (save-excursion
427 (unless (eobp) (forward-char 1))
428 (re-search-backward "^[^ \t]" nil 'move)
429 ;; are we at the front of an appropriate header line?
430 (looking-at mail-abbrev-mode-regexp))
431 ;;
432 ;; ...and are we in the headers?
433 (< (point)
434 (save-restriction
435 (widen)
436 (save-excursion
437 (rfc822-goto-eoh)
438 (point)))))))
439
440 (defun mail-abbrev-expand-wrapper (expand)
441 (if (and mail-abbrevs (not (eq mail-abbrevs t)))
442 (if (mail-abbrev-in-expansion-header-p)
443
444 ;; We are in a To: (or CC:, or whatever) header, and
445 ;; should use word-abbrevs to expand mail aliases.
446 (let ((local-abbrev-table mail-abbrevs))
447
448 ;; Before anything else, resolve aliases if they need it.
449 (and mail-abbrev-aliases-need-to-be-resolved
450 (mail-resolve-all-aliases))
451
452 ;; Now proceed with the abbrev section.
453 ;; - We already installed mail-abbrevs as the abbrev table.
454 ;; - Then install the mail-abbrev-syntax-table, which
455 ;; temporarily marks all of the
456 ;; non-alphanumeric-atom-characters (the "_"
457 ;; syntax ones) as being normal word-syntax. We do this
458 ;; because the C code for expand-abbrev only works on words,
459 ;; and we want these characters to be considered words for
460 ;; the purpose of abbrev expansion.
461 ;; - Then we call the expand function, to do
462 ;; the abbrev expansion with the above syntax table.
463
464 (mail-abbrev-make-syntax-table)
465
466 ;; If the character just typed was non-alpha-symbol-syntax,
467 ;; then don't expand the abbrev now (that is, don't expand
468 ;; when the user types -.) Check the character's syntax in
469 ;; the usual syntax table.
470
471 (or (and (integerp last-command-char)
472 ;; Some commands such as M-> may want to expand first.
473 (equal this-command 'self-insert-command)
474 (or (eq (char-syntax last-command-char) ?_)
475 ;; Don't expand on @.
476 (memq last-command-char '(?@ ?. ?% ?! ?_ ?-))))
477 ;; Use this table so that abbrevs can have hyphens in them.
478 (with-syntax-table mail-abbrev-syntax-table
479 (funcall expand))))
480
481 (if (or (not mail-abbrevs-only)
482 (eq this-command 'expand-abbrev))
483 ;; We're not in a mail header where mail aliases should
484 ;; be expanded, then use the normal mail-mode abbrev table
485 ;; (if any) and the normal mail-mode syntax table.
486 (funcall expand)
487 ;; This is not a mail abbrev, and we should not expand it.
488 ;; Don't expand anything.
489 nil))
490 ;; No mail-abbrevs at all, do the normal thing.
491 (funcall expand)))
492 \f
493 ;;; utilities
494
495 (defun merge-mail-abbrevs (file)
496 "Merge mail aliases from the given file with existing ones."
497 (interactive (list
498 (let ((insert-default-directory t)
499 (default-directory (expand-file-name "~/"))
500 (def mail-personal-alias-file))
501 (read-file-name
502 (format "Read additional aliases from file (default %s): "
503 def)
504 default-directory
505 (expand-file-name def default-directory)
506 t))))
507 (build-mail-abbrevs file))
508
509 (defun rebuild-mail-abbrevs (&optional file)
510 "Rebuild all the mail aliases from the given file."
511 (interactive (list
512 (let ((insert-default-directory t)
513 (default-directory (expand-file-name "~/"))
514 (def mail-personal-alias-file))
515 (read-file-name
516 (format "Read mail aliases from file (default %s): " def)
517 default-directory
518 (expand-file-name def default-directory)
519 t))))
520 (if (null file)
521 (setq file buffer-file-name))
522 (setq mail-abbrevs nil)
523 (build-mail-abbrevs file))
524
525 (defun mail-abbrev-insert-alias (&optional alias)
526 "Prompt for and insert a mail alias."
527 (interactive (progn
528 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup))
529 (list (completing-read "Expand alias: " mail-abbrevs nil t))))
530 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup))
531 (insert (or (and alias (symbol-value (intern-soft alias mail-abbrevs))) ""))
532 (mail-abbrev-expand-hook))
533
534 (defun mail-abbrev-complete-alias ()
535 "Perform completion on alias preceding point."
536 ;; Based on lisp.el:lisp-complete-symbol
537 (interactive)
538 (mail-abbrev-make-syntax-table)
539 (let* ((end (point))
540 (beg (with-syntax-table mail-abbrev-syntax-table
541 (save-excursion
542 (backward-word 1)
543 (point))))
544 (alias (buffer-substring beg end))
545 (completion (try-completion alias mail-abbrevs)))
546 (cond ((eq completion t)
547 (message "%s" alias)) ; confirm
548 ((null completion)
549 (error "[Can't complete \"%s\"]" alias)) ; (message ...) (ding)
550 ((not (string= completion alias))
551 (delete-region beg end)
552 (insert completion))
553 (t (with-output-to-temp-buffer "*Completions*"
554 (display-completion-list
555 (prog2
556 (message "Making completion list...")
557 (all-completions alias mail-abbrevs)
558 (message "Making completion list...done"))
559 alias))))))
560
561 (defun mail-abbrev-next-line (&optional arg)
562 "Expand any mail abbrev, then move cursor vertically down ARG lines.
563 If there is no character in the target line exactly under the current column,
564 the cursor is positioned after the character in that line which spans this
565 column, or at the end of the line if it is not long enough.
566 If there is no line in the buffer after this one,
567 a newline character is inserted to create a line
568 and the cursor moves to that line.
569
570 The command \\[set-goal-column] can be used to create
571 a semipermanent goal column to which this command always moves.
572 Then it does not try to move vertically. This goal column is stored
573 in `goal-column', which is nil when there is none.
574
575 If you are thinking of using this in a Lisp program, consider
576 using `forward-line' instead. It is usually easier to use
577 and more reliable (no dependence on goal column, etc.)."
578 (interactive "p")
579 (if (looking-at "[ \t]*\n") (expand-abbrev))
580 (setq this-command 'next-line)
581 (with-no-warnings (next-line arg)))
582
583 (defun mail-abbrev-end-of-buffer (&optional arg)
584 "Expand any mail abbrev, then move point to end of buffer.
585 Leave mark at previous position.
586 With arg N, put point N/10 of the way from the true end.
587
588 Don't use this command in Lisp programs!
589 \(goto-char (point-max)) is faster and avoids clobbering the mark."
590 (interactive "P")
591 (if (looking-at "[ \t]*\n") (expand-abbrev))
592 (setq this-command 'end-of-buffer)
593 (with-no-warnings
594 (end-of-buffer arg)))
595
596 (eval-after-load "sendmail"
597 '(progn
598 (define-key mail-mode-map "\C-c\C-a" 'mail-abbrev-insert-alias)
599 (define-key mail-mode-map "\e\t" ; like lisp-complete-symbol
600 'mail-abbrev-complete-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 ;; arch-tag: 5aa2d901-73f8-4ad7-b73c-4802282ad2ff
608 ;;; mailabbrev.el ends here