annotate lisp/mail/mailabbrev.el @ 1113:0ffcf74fb8ad

entered into RCS
author Jim Blandy <jimb@redhat.com>
date Sun, 13 Sep 1992 11:44:06 +0000
parents 48ca3bf4b5f8
children 907639748f24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
791
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases.
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
791
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
907
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
6 ;; Maintainer: Jamie Zawinski <jwz@lucid.com>
791
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
7 ;; Created: 19 Oct 90
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 791
diff changeset
8 ;; Keywords: mail
791
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
9
669
4c64c671426f *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 659
diff changeset
10 ;;; ??? We must get papers for this or delete it.
907
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
11
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;;; This file is part of GNU Emacs.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;;; GNU Emacs is free software; you can redistribute it and/or modify
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;;; it under the terms of the GNU General Public License as published by
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
16 ;;; the Free Software Foundation; either version 2, or (at your option)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;;; any later version.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;;; GNU Emacs is distributed in the hope that it will be useful,
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;; GNU General Public License for more details.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; You should have received a copy of the GNU General Public License
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; along with GNU Emacs; see the file COPYING. If not, write to
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
791
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
28 ;;; Commentary:
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
29
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; This file ensures that, when the point is in a To:, CC:, BCC:, or From:
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; field, word-abbrevs are defined for each of your mail aliases. These
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; aliases will be defined from your .mailrc file (or the file specified by
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
33 ;;; the MAILRC environment variable) if it exists. Your mail aliases will
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
34 ;;; expand any time you type a word-delimiter at the end of an abbreviation.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; What you see is what you get: no abbreviations will be expanded after you
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; have sent the mail, unlike the old system. This means you don't suffer
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; the annoyance of having the system do things behind your back -- if an
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; address you typed is going to be rewritten, you know it immediately,
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;; instead of after the mail has been sent and it's too late to do anything
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; about it. You will never again be screwed because you forgot to delete an
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;; old alias from your .mailrc when a new local user arrives and is given a
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; userid which conflicts with one of your aliases, for example.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; Your mail alias abbrevs will be in effect only when the point is in an
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; appropriate header field. When in the body of the message, or other
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; header fields, the mail aliases will not expand. Rather, the normal
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; mode-specific abbrev table (mail-mode-abbrev-table) will be used if
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; defined. So if you use mail-mode specific abbrevs, this code will not
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; adversely affect you. You can control which header fields the abbrevs
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; are used in by changing the variable mail-abbrev-mode-regexp.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; If auto-fill mode is on, abbrevs will wrap at commas instead of at word
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; boundaries; also, header continuation-lines will be properly indented.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; You can also insert a mail alias with mail-interactive-insert-alias
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; (bound to C-c C-a), which prompts you for an alias (with completion)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;; and inserts its expansion at point.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; This file fixes a bug in the old system which prohibited your .mailrc
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; file from having lines like
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; alias someone "John Doe <doe@quux.com>"
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;; That is, if you want an address to have embedded spaces, simply surround it
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;; with double-quotes. This is necessary because the format of the .mailrc
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;; file bogusly uses spaces as address delimiters. The following line defines
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; an alias which expands to three addresses:
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;; alias foobar addr-1 addr-2 "address three <addr-3>"
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; (This is bogus because mail-delivery programs want commas, not spaces,
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;; but that's what the file format is, so we have to live with it.)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;; If you like, you can call the function define-mail-alias to define your
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;; mail-aliases instead of using a .mailrc file. When you call it in this
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
77 ;;; way, addresses are separated by commas.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;; CAVEAT: This works on most Sun systems; I have been told that some versions
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;; of /bin/mail do not understand double-quotes in the .mailrc file. So you
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; should make sure your version does before including verbose addresses like
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;; this. One solution to this, if you are on a system whose /bin/mail doesn't
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;; work that way, (and you still want to be able to /bin/mail to send mail in
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;; addition to emacs) is to define minimal aliases (without full names) in
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;; your .mailrc file, and use define-mail-alias to redefine them when sending
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;; mail from emacs; this way, mail sent from /bin/mail will work, and mail
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;; sent from emacs will be pretty.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;; Aliases in the mailrc file may be nested. If you define aliases like
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;; alias group1 fred ethel
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;; alias group2 larry curly moe
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;;; alias everybody group1 group2
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;; Then when you type "everybody" on the To: line, it will be expanded to
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;; fred, ethyl, larry, curly, moe
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;; Aliases may also contain forward references; the alias of "everybody" can
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;; preceed the aliases of "group1" and "group2".
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;;; This code also understands the "source" .mailrc command, for reading
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;;; aliases from some other file as well.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;;;
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
102 ;;; Aliases may contain hyphens, as in "alias foo-bar foo@bar"; word-abbrevs
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
103 ;;; normally cannot contain hyphens, but this code works around that for the
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
104 ;;; specific case of mail-alias word-abbrevs.
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
105 ;;;
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;;; To read in the contents of another .mailrc-type file from emacs, use the
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;; command Meta-X merge-mail-aliases. The rebuild-mail-aliases command is
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;;; similar, but will delete existing aliases first.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;;
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
110 ;;; If you would like your aliases to be expanded when you type M-> or ^N to
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
111 ;;; move out of the mail-header into the message body (instead of having to
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
112 ;;; type SPC at the end of the abbrev before moving away) then you can do
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
113 ;;;
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
114 ;;; (define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
115 ;;; (define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
116 ;;;
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
117 ;;; If you want multiple addresses separated by a string other than ", " then
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
118 ;;; you can set the variable mail-alias-separator-string to it. This has to
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;;; be a comma bracketed by whitespace if you want any kind of reasonable
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;;; behaviour.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;;; Noah Friedman for suggestions and bug reports.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
124 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
125 ;;; INSTALLATION
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
126 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
127 ;;; If you are using Emacs 18, you shouldn't have to do anything at all to
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
128 ;;; install this code other than load this file. You might want to do this
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
129 ;;; to have this code loaded only when needed:
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
130 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
131 ;;; (setq mail-setup-hook '(lambda () (require 'mail-abbrevs)))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
132 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
133 ;;; Simply loading this file will redefine and overload the required
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
134 ;;; functions.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
135 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
136 ;;; If you want to install this code more permanently (instead of loading
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
137 ;;; it as a patch) you need to do the following:
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
138 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
139 ;;; - Remove the entire file mailalias.el;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
140 ;;; - Remove the definition of mail-aliases from sendmail.el;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
141 ;;; - Add a call to mail-aliases-setup to the front of the function
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
142 ;;; mail-setup in the file sendmail.el;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
143 ;;; - Remove the call to expand-mail-aliases from the function
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
144 ;;; sendmail-send-it in the file sendmail.el;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
145 ;;; - Remove the autoload of expand-mail-aliases from the file sendmail.el;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
146 ;;; - Remove the autoload of build-mail-aliases from the file sendmail.el;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
147 ;;; - Add an autoload of define-mail-alias to loaddefs.el.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
791
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
149 ;;; Code:
203c23c9f22c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 717
diff changeset
150
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (require 'sendmail)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (defvar mail-abbrev-mailrc-file nil
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 "Name of file with mail aliases. If nil, ~/.mailrc is used.")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defmacro mail-abbrev-mailrc-file ()
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 '(or mail-abbrev-mailrc-file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (setq mail-abbrev-mailrc-file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (or (getenv "MAILRC") "~/.mailrc"))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; originally defined in sendmail.el - used to be an alist, now is a table.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (defvar mail-aliases nil
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
163 "Word-abbrev table of mail address aliases.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 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
165 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
166 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
167
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 459
diff changeset
168 ;;;###autoload
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (defun mail-aliases-setup ()
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (if (and (not (vectorp mail-aliases))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (file-exists-p (mail-abbrev-mailrc-file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (build-mail-aliases))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
173 (make-local-variable 'pre-abbrev-expand-hook)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
174 (setq pre-abbrev-expand-hook
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
175 (cond ((and (listp pre-abbrev-expand-hook)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
176 (not (eq 'lambda (car pre-abbrev-expand-hook))))
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
177 (cons 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook))
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
178 (t
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
179 (list 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook))))
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
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;;; Originally defined in mailalias.el. Changed to call define-mail-alias
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;;; with an additional argument.
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
184 ;;;###autoload
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (defun build-mail-aliases (&optional file recursivep)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "Read mail aliases from .mailrc and set mail-aliases."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (setq file (expand-file-name (or file (mail-abbrev-mailrc-file))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (if (vectorp mail-aliases)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 nil
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (setq mail-aliases nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (define-abbrev-table 'mail-aliases '()))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
192 (message "Parsing %s..." file)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (let ((buffer nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (obuf (current-buffer)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (unwind-protect
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (progn
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (setq buffer (generate-new-buffer "mailrc"))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
198 (buffer-disable-undo buffer)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (set-buffer buffer)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (cond ((get-file-buffer file)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (insert (save-excursion
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (set-buffer (get-file-buffer file))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (buffer-substring (point-min) (point-max)))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ((not (file-exists-p file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (t (insert-file-contents file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; Don't lose if no final newline.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (goto-char (point-max))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (or (eq (preceding-char) ?\n) (newline))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (goto-char (point-min))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; Delete comments from the file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (while (search-forward "# " nil t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (let ((p (- (point) 2)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (delete-region p (point))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (goto-char (point-min))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;; handle "\\\n" continuation lines
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (while (not (eobp))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (if (= (preceding-char) ?\\)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (progn (delete-char -1) (delete-char 1) (insert ?\ ))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (forward-char 1)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (goto-char (point-min))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (while (re-search-forward
907
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
224 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (beginning-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (progn
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (build-mail-aliases
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (buffer-substring (match-beginning 1) (match-end 1)) t))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (re-search-forward "[ \t]+\\([^ \t\n]+\\)")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (let* ((name (buffer-substring
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (match-beginning 1) (match-end 1)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (start (progn (skip-chars-forward " \t") (point))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (define-mail-alias
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 name
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (buffer-substring start (point))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 t))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;; Resolve forward references in .mailrc file.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;; This would happen automatically before the first abbrev was
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 ;; expanded, but why not do it now.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (or recursivep (mail-resolve-all-aliases))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 mail-aliases)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (if buffer (kill-buffer buffer))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (set-buffer obuf)))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
248 (message "Parsing %s... done" file))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
250 (defvar mail-alias-separator-string ", "
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 "*A string inserted between addresses in multi-address mail aliases.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 This has to contain a comma, so \", \" is a reasonable value. You might
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 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
254
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ;; define-mail-alias sets this flag, which causes mail-resolve-all-aliases
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; to be called before expanding abbrevs if it's necessary.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (defvar mail-abbrev-aliases-need-to-be-resolved t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 ;; originally defined in mailalias.el ; build-mail-aliases calls this with
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ;; stuff parsed from the .mailrc file.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;;
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 459
diff changeset
262 ;;;###autoload
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (defun define-mail-alias (name definition &optional from-mailrc-file)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 "Define NAME as a mail-alias that translates to DEFINITION.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
265 If DEFINITION contains multiple addresses, separate them with commas."
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; When this is called from build-mail-aliases, the third argument is
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;; 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
268 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 ;; Read the defaults first, if we have not done so.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (if (vectorp mail-aliases)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 nil
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (setq mail-aliases nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (define-abbrev-table 'mail-aliases '())
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (if (file-exists-p (mail-abbrev-mailrc-file))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (build-mail-aliases)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 ;; strip garbage from front and end
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (if (string-match "\\`[ \t\n,]+" definition)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (setq definition (substring definition (match-end 0))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (if (string-match "[ \t\n,]+\\'" definition)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (setq definition (substring definition 0 (match-beginning 0))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (let ((result '())
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (start 0)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (L (length definition))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 end)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (while start
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 ;; If we're reading from the mailrc file, then addresses are delimited
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 ;; 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
288 ;; double-quotes. Otherwise, addresses are separated by commas.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (if from-mailrc-file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (if (eq ?\" (aref definition start))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (setq start (1+ start)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 end (string-match "\"[ \t,]*" definition start))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (setq end (string-match "[ \t,]+" definition start)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (setq result (cons (substring definition start end) result))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (setq start (and end
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (/= (match-end 0) L)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (match-end 0))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (setq definition (mapconcat (function identity)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (nreverse result)
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
301 mail-alias-separator-string)))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (setq mail-abbrev-aliases-need-to-be-resolved t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (setq name (downcase name))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 ;; use an abbrev table instead of an alist for mail-aliases.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (define-abbrev mail-aliases name definition 'mail-abbrev-expand-hook)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (defun mail-resolve-all-aliases ()
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 "Resolve all forward references in the mail aliases table."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (if mail-abbrev-aliases-need-to-be-resolved
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (progn
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; (message "Resolving mail aliases...")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (if (vectorp mail-aliases)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (mapatoms (function mail-resolve-all-aliases-1) mail-aliases))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (setq mail-abbrev-aliases-need-to-be-resolved nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ;; (message "Resolving mail aliases... done.")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 )))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
320 (defun mail-resolve-all-aliases-1 (sym &optional so-far)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
321 (if (memq sym so-far)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
322 (error "mail alias loop detected: %s"
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
323 (mapconcat 'symbol-name (cons sym so-far) " <- ")))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (let ((definition (and (boundp sym) (symbol-value sym))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (if definition
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (let ((result '())
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (start 0))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (while start
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (setq result (cons (substring definition start end) result)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 start (and end (match-end 0)))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (setq definition
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (mapconcat (function (lambda (x)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (or (mail-resolve-all-aliases-1
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
335 (intern-soft x mail-aliases)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
336 (cons sym so-far))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 x)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (nreverse result)
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
339 mail-alias-separator-string))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (set sym definition))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (symbol-value sym))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
344 (defun mail-abbrev-expand-hook ()
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
345 "For use as the fourth arg to define-abbrev.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
346 After expanding a mail-abbrev, if fill-mode is on and we're past the
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
347 fill-column, break the line at the previous comma, and indent the next
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
348 line."
608
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
349 (save-excursion
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
350 (let ((p (point))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
351 bol comma fp)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
352 (beginning-of-line)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
353 (setq bol (point))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
354 (goto-char p)
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
355 (while (and auto-fill-function
608
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
356 (>= (current-column) fill-column)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
357 (search-backward "," bol t))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
358 (setq comma (point))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
359 (forward-char 1) ; Now we are just past the comma.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
360 (insert "\n")
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
361 (delete-horizontal-space)
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
362 (setq p (point))
608
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
363 (indent-relative)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
364 (setq fp (buffer-substring p (point)))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
365 ;; Go to the end of the new line.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
366 (end-of-line)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
367 (if (> (current-column) fill-column)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
368 ;; It's still too long; do normal auto-fill.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
369 (let ((fill-prefix (or fp "\t")))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
370 (do-auto-fill)))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
371 ;; Resume the search.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
372 (goto-char comma)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
373 ))))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
374
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
375 ;;; Syntax tables and abbrev-expansion
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
377 (defvar mail-abbrev-mode-regexp "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\):"
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 "*Regexp to select mail-headers in which mail-aliases should be expanded.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 This string it will be handed to `looking-at' with the point at the beginning
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 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
381 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
382 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
383 turned on.")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (defvar mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
386 "The syntax table which is used in send-mail mode message bodies.")
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (defvar mail-mode-header-syntax-table
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (let ((tab (copy-syntax-table text-mode-syntax-table)))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
390 ;; This makes the characters "@%!._-" be considered symbol-consituents
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 ;; but not word-constituents, so forward-sexp will move you over an
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 ;; entire address, but forward-word will only move you over a sequence
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 ;; of alphanumerics. (Clearly the right thing.)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (modify-syntax-entry ?@ "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (modify-syntax-entry ?% "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (modify-syntax-entry ?! "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (modify-syntax-entry ?. "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (modify-syntax-entry ?_ "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (modify-syntax-entry ?- "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (modify-syntax-entry ?< "(>" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (modify-syntax-entry ?> ")<" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 tab)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
403 "The syntax table used in send-mail mode when in a mail-address header.
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
404 mail-mode-syntax-table is used when the cursor is in the message body or in
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
405 non-address headers.")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
406
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
407 (defvar mail-abbrev-syntax-table
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
408 (let* ((tab (copy-syntax-table mail-mode-header-syntax-table))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
409 (i (1- (length tab)))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
410 (_ (aref (standard-syntax-table) ?_))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
411 (w (aref (standard-syntax-table) ?w)))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
412 (while (>= i 0)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
413 (if (= (aref tab i) _) (aset tab i w))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
414 (setq i (1- i)))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
415 tab)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
416 "The syntax-table used for abbrev-expansion purposes; this is not actually
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
417 made the current syntax table of the buffer, but simply controls the set of
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
418 characters which may be a part of the name of a mail-alias.")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
419
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
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
427 (beginning-of-line)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
428 ;; skip backwards over continuation lines.
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
429 (while (and (looking-at "^[ \t]")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
430 (not (= (point) (point-min))))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
431 (forward-line -1))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
432 ;; are we at the front of an appropriate header line?
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
433 (looking-at mail-abbrev-mode-regexp))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
434 ;;
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
435 ;; ...and we are before the mail-header-separator
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
436 (< (point)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
437 (save-excursion
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
438 (goto-char (point-min))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
439 (search-forward (concat "\n" mail-header-separator "\n")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
440 nil 0)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
441 (point))))))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
442
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
443 (defvar mail-mode-abbrev-table) ; quiet the compiler
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
444
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
445 (defun sendmail-pre-abbrev-expand-hook ()
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (if mail-abbrev-aliases-need-to-be-resolved
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (mail-resolve-all-aliases))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
448 (if (and mail-aliases (not (eq mail-aliases t)))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
449 (if (not (mail-abbrev-in-expansion-header-p))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
450 ;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
451 ;; If we're not in a mail header in which mail aliases should
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
452 ;; be expanded, then use the normal mail-mode abbrev table (if any)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
453 ;; and the normal mail-mode syntax table.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
454 ;;
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (progn
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
456 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
457 mail-mode-abbrev-table))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
458 (set-syntax-table mail-mode-syntax-table))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
459 ;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
460 ;; Otherwise, we are in a To: (or CC:, or whatever) header, and
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
461 ;; should use word-abbrevs to expand mail aliases.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
462 ;; - First, install the mail-aliases as the word-abbrev table.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
463 ;; - Then install the mail-abbrev-syntax-table, which temporarily
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
464 ;; marks all of the non-alphanumeric-atom-characters (the "_"
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
465 ;; syntax ones) as being normal word-syntax. We do this because
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
466 ;; the C code for expand-abbrev only works on words, and we want
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
467 ;; these characters to be considered words for the purpose of
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
468 ;; abbrev expansion.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
469 ;; - Then we call expand-abbrev again, recursively, to do the abbrev
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
470 ;; expansion with the above syntax table.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
471 ;; - Then we do a trick which tells the expand-abbrev frame which
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
472 ;; invoked us to not continue (and thus not expand twice.)
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
473 ;; This means that any abbrev expansion will happen as a result
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
474 ;; of this function's call to expand-abbrev, and not as a result
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
475 ;; of the call to expand-abbrev which invoked *us*.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
476 ;; - Then we set the syntax table to mail-mode-header-syntax-table,
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
477 ;; which doesn't have anything to do with abbrev expansion, but
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
478 ;; is just for the user's convenience (see its doc string.)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
479 ;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
480 (setq local-abbrev-table mail-aliases)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
481 ;; If the character just typed was non-alpha-symbol-syntax, then don't
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
482 ;; expand the abbrev now (that is, don't expand when the user types -.)
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
483 ;; Check the character's syntax in the mail-mode-header-syntax-table.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
484 (set-syntax-table mail-mode-header-syntax-table)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
485 (or (eq (char-syntax last-command-char) ?_)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
486 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
487 ;; Use this table so that abbrevs can have hyphens in them.
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
488 (set-syntax-table mail-abbrev-syntax-table)
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
489 (expand-abbrev)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
490 ;; Now set it back to what it was before.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
491 (set-syntax-table mail-mode-header-syntax-table)))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
492 (setq abbrev-start-location (point) ; This is the trick.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
493 abbrev-start-location-buffer (current-buffer))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
494 )))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
495
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
496 ;;; utilities
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (defun merge-mail-aliases (file)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "Merge mail aliases from the given file with existing ones."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (interactive (list
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (let ((insert-default-directory t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (default-directory (expand-file-name "~/"))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (def (mail-abbrev-mailrc-file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (read-file-name
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (format "Read additional aliases from file: (default %s) "
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 def)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 default-directory
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (expand-file-name def default-directory)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 t))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (build-mail-aliases file))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (defun rebuild-mail-aliases (file)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 "Rebuild all the mail aliases from the given file."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (interactive (list
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (let ((insert-default-directory t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (default-directory (expand-file-name "~/"))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (def (mail-abbrev-mailrc-file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (read-file-name
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (format "Read mail aliases from file: (default %s) " def)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 default-directory
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (expand-file-name def default-directory)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 t))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (setq mail-aliases nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (build-mail-aliases file))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
525
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
526 (defun mail-interactive-insert-alias (&optional alias)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
527 "Prompt for and insert a mail alias."
907
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
528 (interactive (progn
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
529 (if (not (vectorp mail-aliases)) (mail-aliases-setup))
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
530 (list (completing-read "Expand alias: " mail-aliases nil t))))
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
531 (if (not (vectorp mail-aliases)) (mail-aliases-setup))
599
c1e8cc0b3fb5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 598
diff changeset
532 (insert (or (and alias (symbol-value (intern-soft alias mail-aliases))) "")))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
533
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
534 (defun abbrev-hacking-next-line (&optional arg)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
535 "Just like `next-line' (\\[next-line]) but expands abbrevs when at \
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
536 end of line."
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
537 (interactive "p")
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
538 (if (looking-at "[ \t]*\n") (expand-abbrev))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
539 (setq this-command 'next-line)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
540 (next-line arg))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
541
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
542 (defun abbrev-hacking-end-of-buffer (&optional arg)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
543 "Just like `end-of-buffer' (\\[end-of-buffer]) but expands abbrevs when at \
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
544 end of line."
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
545 (interactive "P")
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
546 (if (looking-at "[ \t]*\n") (expand-abbrev))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
547 (setq this-command 'end-of-buffer)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
548 (end-of-buffer arg))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
549
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
550 (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
551
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
552 ;;(define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
553 ;;(define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
554
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (provide 'mail-abbrevs)
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
556
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
557
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
558 ;;; V18 compatibility
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
559 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
560 ;;; All of the Emacs18 stuff is isolated down here so that it will be
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
561 ;;; easy to delete once v18 finally bites the dust.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
562 ;;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
563 ;;; These defuns and defvars aren't inside the cond in deference to
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
564 ;;; the intense brokenness of the v18 byte-compiler.
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
565 ;;;
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
566 ;;; All the code on this page is gross and hidious and awful and might
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
567 ;;; not even work all that well. Comfort yourself with knowing that the
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
568 ;;; v19 code above works wonderfully.
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
569
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
570 (defun sendmail-v18-self-insert-command (arg)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
571 "Just like self-insert-command, but runs sendmail-pre-abbrev-expand-hook."
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
572 (interactive "p")
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
573 (if (not (eq (char-syntax last-command-char) ?w))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
574 (progn
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
575 (sendmail-pre-abbrev-expand-hook)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
576 ;; Unhack expand-abbrev, so it will work right next time around.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
577 (setq abbrev-start-location nil)))
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
578 ;; this is gross and wasteful.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
579 (let ((abbrev-mode (if (mail-abbrev-in-expansion-header-p)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
580 nil
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
581 abbrev-mode)))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
582 (self-insert-command arg)))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
583
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
584 (defun abbrev-hacking-next-line-v18 (arg)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
585 (if (looking-at "[ \t]*\n") (sendmail-pre-abbrev-expand-hook))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
586 (setq this-command 'next-line)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
587 (next-line arg))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
588
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
589 (defun abbrev-hacking-end-of-buffer-v18 (arg)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
590 (if (looking-at "[ \t]*\n") (sendmail-pre-abbrev-expand-hook))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
591 (setq this-command 'end-of-buffer)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
592 (end-of-buffer arg))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
593
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
594 (defvar mail-abbrevs-v18-map-munged nil)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
595
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
596 (defun mail-abbrevs-v18-munge-map ()
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
597 ;; For every key that is bound to self-insert-command in global-map,
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
598 ;; bind that key to sendmail-self-insert-command in mail-mode-map.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
599 ;; We used to do this by making the mail-mode-map be a non-sparse map,
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
600 ;; but that made the esc-map be shared in such a way that making a
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
601 ;; local meta binding in the mail-mode-map made a *global* binding
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
602 ;; instead. Yucko.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
603 (let ((global-map (current-global-map))
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
604 new-bindings
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
605 (i 0))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
606 (while (< i 128)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
607 (if (eq 'self-insert-command (or (cdr (assq i mail-mode-map))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
608 (aref global-map i)))
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
609 (setq new-bindings
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
610 (cons (cons i 'sendmail-v18-self-insert-command)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
611 new-bindings)))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
612 (setq i (1+ i)))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
613 (setq mail-mode-map
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
614 (nconc (copy-keymap mail-mode-map) (nreverse new-bindings))))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
615 (setq mail-abbrevs-v18-map-munged t))
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
616
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
617 (defun mail-aliases-setup-v18 ()
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
618 "Put this on `mail-setup-hook' to use mail-abbrevs."
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
619 (if (not (eq major-mode 'mail-mode))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
620 nil
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
621 (or (and mail-mode-map (eq (current-local-map) mail-mode-map))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
622 (error "shut 'er down clancy, she's suckin' mud"))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
623 (if (and (not (vectorp mail-aliases))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
624 (file-exists-p (mail-abbrev-mailrc-file)))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
625 (build-mail-aliases))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
626 (or mail-abbrevs-v18-map-munged (mail-abbrevs-v18-munge-map))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
627 (use-local-map mail-mode-map)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
628 (abbrev-mode 1)))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
629
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
630
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
631 (cond ((or (string-match "^18\\." emacs-version)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
632 (and (boundp 'epoch::version) epoch::version))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
633 ;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
634 ;; v19 (and this code) uses a new name for this function.
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
635 (or (fboundp 'buffer-disable-undo)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
636 (fset 'buffer-disable-undo 'buffer-flush-undo))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
637 ;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
638 ;; v19 (and this code) uses a new name for auto-fill-hook (-function).
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
639 ;; Encapsulate the function that uses it to bind the new name.
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
640 (or (fboundp 'mail-abbrev-expand-hook-v19)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
641 (fset 'mail-abbrev-expand-hook-v19
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
642 (symbol-function 'mail-abbrev-expand-hook)))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
643 (fset 'mail-abbrev-expand-hook
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
644 (function (lambda ()
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
645 (let ((auto-fill-function auto-fill-hook))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
646 (mail-abbrev-expand-hook-v19)))))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
647 ;;
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
648 ;; Turn off the broken v18 code (that is still called from sendmail.el)
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
649 (fset 'expand-mail-aliases
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
650 (function (lambda (&rest args)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
651 "Obsoleted by mail-abbrevs. Does nothing."
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
652 nil)))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
653 ;;
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
654 ;; Redefine the abbrev-hacking functions. Yuck.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
655 (fset 'abbrev-hacking-next-line
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
656 (function (lambda (p) (interactive "p")
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
657 (abbrev-hacking-next-line-v18 p))))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
658 (fset 'abbrev-hacking-end-of-buffer
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
659 (function (lambda (p) (interactive "P")
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
660 (abbrev-hacking-end-of-buffer-v18 p))))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
661 ;;
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
662 ;; Encapsulate mail-setup to do the necessary buffer initializations.
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
663 (or (fboundp 'mail-setup-v18)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
664 (fset 'mail-setup-v18 (symbol-function 'mail-setup)))
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
665 (fset 'mail-setup
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
666 (function (lambda (&rest args)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
667 (mail-aliases-setup-v18)
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
668 (apply 'mail-setup-v18 args))))
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
669
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
670 ;;
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
671 ;; Encapsulate VM's version of mail-setup as well, if vm-mail is
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
672 ;; defined as a function or as an autoload.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
673 (cond ((and (fboundp 'vm-mail)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
674 (if (eq 'autoload (car-safe (symbol-function 'vm-mail)))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
675 (load (nth 1 (symbol-function 'vm-mail)) t)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
676 t))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
677 (or (fboundp 'vm-mail-internal-v18)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
678 (fset 'vm-mail-internal-v18
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
679 (symbol-function 'vm-mail-internal)))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
680 (fset 'vm-mail-internal
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
681 (function (lambda (&rest args)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
682 (mail-aliases-setup-v18)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
683 (apply 'vm-mail-internal-v18 args))))))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
684
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
685 ;; If we're being loaded from mail-setup-hook or mail-mode-hook
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
686 ;; as run from inside mail-setup or vm-mail-internal, then install
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
687 ;; right now.
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
688 (if (eq major-mode 'mail-mode)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
689 (mail-aliases-setup-v18))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
690 )
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
691
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
692 (t ; v19
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
693 (fmakunbound 'expand-mail-aliases)))