annotate lisp/mail/mailabbrev.el @ 804:33aaf4b71a1d

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