annotate lisp/mail/mailabbrev.el @ 85842:96510b236eb5

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