annotate lisp/mail/mailabbrev.el @ 1686:10650dfc82d0

* Makefile.in (install, install.sysv, install.xenix, install.aix): Install the info files in ${infodir}. Install the executable under both `emacs' and `emacs-VERSION'. * Makefile.in: Doc fix. * Makefile.in (exec_prefix): New variable, as per latest version of coding standards. (bindir, libdir): Use it, instead of `prefix'. (lib-src/Makefile): Edit value of exec_prefix into lib-src/Makefile. * Makefile.in (mandir): Make the default value for this depend on $(prefix). * Makefile.in (datadir, statedir, libdir): Make these all default to ${prefix}/lib. (lispdir, locallisppath, etcdir, lockdir, archlibdir): Adjusted to compensate. * Makefile.in (install, install.sysv, install.xenix, install.aix): Install the etags and ctags man pages too. * Makefile.in (distclean): Don't delete backup files; that's the job of extraclean. (extraclean): Like distclean, but deletes backup and autosave files. Make path specification conform to GNU coding standards. * configure (long_usage): Remove all traces of old arguments from usage messages, and document the options we do accept in more detail: -with-x... and --srcdir. (options, boolean_opts): Deleted; we don't have enough options to make this worthwhile. (prefix, bindir, lisppath, datadir, libdir, lockdir): Deleted, along with the code which supported them; these should be set as arguments to the top-level make. (config_h_opts): Since this no longer doubles as a list of option names, make them upper case; this simplifies the code which uses them to build the sed command to edit src/config.h. Change the code which sets them. (cc, g, O): Don't allow the user to set these using options; they should be specified using `CC=' and `CFLAGS=' arguments to the top-level make. Just choose reasonable default values for them, and edit them into Makefile.in's default CC and CONFIG_CFLAGS values. (gnu_malloc, rel_alloc): Don't allow the user to set these using options; use them whenever the configuration files say they're possible. Simplify the argument processing loop. Don't accept abbreviations for option names; these might conflict with other configuration options in the future. Add some support for the `--srcdir' option. Check for the sources in . and .. if `--srcdir' is omitted. If the directories we will compile in don't exist yet, create them under the current directory. Note that the rest of the build process doesn't really support this. Edit only the top Makefile. That should edit the others. Edit into the makefile: `version', from lisp/version.el, `configname' and `srcdir' from the configuration arguments, `CC' and `CONFIG_CFLAGS' as guessed from the presence or absence of GCC in the user's path, and LOADLIBES as gleaned from the system description files. Simplify the report generated; it doesn't need to include any description of paths now. Make `config.status' exec configure instead of just calling it, so there's no harm in overwriting `config.status'. * Makefile.in (version, configname): New variables, used to choose the default values for datadir and libdir. Path variables rearranged into two clearer groups: - In the first group are the variables specified by the GNU coding standards (prefix, bindir, datadir, statedir, libdir, mandir, manext, infodir, and srcdir). - In the second are the variables actually used for Emacs's paths (lispdir, locallisppath, lisppath, buildlisppath, etcdir, lockdir, archlibdir), which depend on the first category. datadir and libdir default to directories under ${prefix}/lib/emacs instead of ${prefix}/emacs, by popular demand. etcdir and lispdir default to subdirectories of datadir. archlibdir defaults to libdir. The new installation tree is a bit deeper than it used to be, so use the new make-path program in lib-src to build them all. Always build a new src/paths.h.tmp and then move-if-change it to src/paths.h, to avoid unnecessary rebuilds while responding to the right changes. Remove all mention of arch-lib. Run utility commands from lib-src, and let the executables be copied into archlibdir when Emacs is installed. Add targets for src/Makefile, lib-src/Makefile, and oldXMenu/Makefile, editing the values of the path variables into them. Let lib-src do its own installation. (datadir): Default to putting data files under ${prefix}/lib/emacs/${version}, not /usr/local/emacs. (emacsdir): Variable deleted; it would only be confusing to use. (lispdir, etcdir): Default to ${datadir}/lisp. (mkdir): Use make-path for this. (lockdir): Do this in mkdir. (Makefile): New target.
author Jim Blandy <jimb@redhat.com>
date Sat, 12 Dec 1992 15:42:14 +0000
parents c5fe2f36dda5
children f852ebc02465
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
4
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
6 ;; Maintainer: Jamie Zawinski <jwz@lucid.com>
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
7 ;; Created: 19 Oct 90
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
8 ;; Keywords: mail
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
9
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;;; This file is part of GNU Emacs.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;;; 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
14 ;;; the Free Software Foundation; either version 2, or (at your option)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;;; any later version.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;;; GNU General Public License for more details.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;; You should have received a copy of the GNU General Public License
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
26 ;;; Commentary:
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
27
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; 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
29 ;;; field, word-abbrevs are defined for each of your mail aliases. These
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; 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
31 ;;; the MAILRC environment variable) if it exists. Your mail aliases will
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
32 ;;; 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
33 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; 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
35 ;;; 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
36 ;;; 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
37 ;;; address you typed is going to be rewritten, you know it immediately,
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; 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
39 ;;; 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
40 ;;; 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
41 ;;; userid which conflicts with one of your aliases, for example.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; 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
44 ;;; appropriate header field. When in the body of the message, or other
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; header fields, the mail aliases will not expand. Rather, the normal
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; mode-specific abbrev table (mail-mode-abbrev-table) will be used if
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; 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
48 ;;; adversely affect you. You can control which header fields the abbrevs
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; are used in by changing the variable mail-abbrev-mode-regexp.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; 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
52 ;;; boundaries; also, header continuation-lines will be properly indented.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; You can also insert a mail alias with mail-interactive-insert-alias
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; (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
56 ;;; and inserts its expansion at point.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;; 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
59 ;;; file from having lines like
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; alias someone "John Doe <doe@quux.com>"
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; 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
64 ;;; with double-quotes. This is necessary because the format of the .mailrc
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;; file bogusly uses spaces as address delimiters. The following line defines
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;; an alias which expands to three addresses:
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; alias foobar addr-1 addr-2 "address three <addr-3>"
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;; (This is bogus because mail-delivery programs want commas, not spaces,
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; 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
72 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;; If you like, you can call the function define-mail-alias to define your
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
74 ;;; 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
75 ;;; way, addresses are separated by commas.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; 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
78 ;;; 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
79 ;;; should make sure your version does before including verbose addresses like
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;; 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
81 ;;; 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
82 ;;; addition to emacs) is to define minimal aliases (without full names) in
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;; 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
84 ;;; 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
85 ;;; sent from emacs will be pretty.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;; 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
88 ;;; alias group1 fred ethel
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;; alias group2 larry curly moe
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;; alias everybody group1 group2
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;; 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
92 ;;; fred, ethyl, larry, curly, moe
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;; Aliases may also contain forward references; the alias of "everybody" can
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;; preceed the aliases of "group1" and "group2".
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;; This code also understands the "source" .mailrc command, for reading
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;; aliases from some other file as well.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;;;
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
100 ;;; 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
101 ;;; 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
102 ;;; specific case of mail-alias word-abbrevs.
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
103 ;;;
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;;; To read in the contents of another .mailrc-type file from emacs, use the
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
105 ;;; command Meta-X merge-mail-abbrevs. The rebuild-mail-abbrevs command is
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;;; similar, but will delete existing aliases first.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;;
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
108 ;;; 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
109 ;;; 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
110 ;;; 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
111 ;;;
1433
c5fe2f36dda5 Comment fix.
Richard M. Stallman <rms@gnu.org>
parents: 1432
diff changeset
112 ;;; (define-key mail-mode-map "\C-n" 'mail-abbrev-next-line)
c5fe2f36dda5 Comment fix.
Richard M. Stallman <rms@gnu.org>
parents: 1432
diff changeset
113 ;;; (define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
114 ;;;
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
115 ;;; 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
116 ;;; 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
117 ;;; 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
118 ;;; behaviour.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;;;
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;;; Noah Friedman for suggestions and bug reports.
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
122
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
123 ;;; To use this file, add mail-abbrevs-setup as a hook
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
124 ;;; to the hook list `mail-setup-hook'.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
126 ;;; Code:
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
127
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (require 'sendmail)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (defvar mail-abbrev-mailrc-file nil
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 "Name of file with mail aliases. If nil, ~/.mailrc is used.")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (defmacro mail-abbrev-mailrc-file ()
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 '(or mail-abbrev-mailrc-file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (setq mail-abbrev-mailrc-file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (or (getenv "MAILRC") "~/.mailrc"))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;; originally defined in sendmail.el - used to be an alist, now is a table.
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
139 (defvar mail-abbrevs nil
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
140 "Word-abbrev table of mail address aliases.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 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
142 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
143 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
144
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 459
diff changeset
145 ;;;###autoload
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
146 (defun mail-abbrevs-setup ()
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
147 (if (and (not (vectorp mail-abbrevs))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (file-exists-p (mail-abbrev-mailrc-file)))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
149 (build-mail-abbrevs))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
150 (make-local-variable 'pre-abbrev-expand-hook)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
151 (setq pre-abbrev-expand-hook
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
152 (cond ((and (listp pre-abbrev-expand-hook)
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
153 (not (eq 'lambda (car pre-abbrev-expand-hook))))
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
154 (cons 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook))
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
155 (t
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
156 (list 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook))))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (abbrev-mode 1))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
159 ;;;###autoload
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
160 (defun build-mail-abbrevs (&optional file recursivep)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
161 "Read mail aliases from `~/.mailrc' file and set `mail-abbrevs'."
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (setq file (expand-file-name (or file (mail-abbrev-mailrc-file))))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
163 (if (vectorp mail-abbrevs)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 nil
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
165 (setq mail-abbrevs nil)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
166 (define-abbrev-table 'mail-abbrevs '()))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
167 (message "Parsing %s..." file)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (let ((buffer nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (obuf (current-buffer)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (unwind-protect
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (progn
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (setq buffer (generate-new-buffer "mailrc"))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
173 (buffer-disable-undo buffer)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (set-buffer buffer)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (cond ((get-file-buffer file)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (insert (save-excursion
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (set-buffer (get-file-buffer file))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (buffer-substring (point-min) (point-max)))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ((not (file-exists-p file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (t (insert-file-contents file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;; Don't lose if no final newline.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (goto-char (point-max))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (or (eq (preceding-char) ?\n) (newline))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (goto-char (point-min))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;; Delete comments from the file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (while (search-forward "# " nil t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (let ((p (- (point) 2)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (delete-region p (point))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (goto-char (point-min))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; handle "\\\n" continuation lines
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (while (not (eobp))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (if (= (preceding-char) ?\\)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (progn (delete-char -1) (delete-char 1) (insert ?\ ))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (forward-char 1)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (goto-char (point-min))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (while (re-search-forward
907
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
199 "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (beginning-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (if (looking-at "source[ \t]+\\([^ \t\n]+\\)")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (progn
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (end-of-line)
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
204 (build-mail-abbrevs
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (buffer-substring (match-beginning 1) (match-end 1)) t))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (re-search-forward "[ \t]+\\([^ \t\n]+\\)")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (let* ((name (buffer-substring
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (match-beginning 1) (match-end 1)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (start (progn (skip-chars-forward " \t") (point))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (end-of-line)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (define-mail-alias
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 name
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (buffer-substring start (point))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 t))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;; Resolve forward references in .mailrc file.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; This would happen automatically before the first abbrev was
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; expanded, but why not do it now.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (or recursivep (mail-resolve-all-aliases))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
220 mail-abbrevs)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (if buffer (kill-buffer buffer))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (set-buffer obuf)))
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
223 (message "Parsing %s... done" file))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
225 (defvar mail-alias-separator-string ", "
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 "*A string inserted between addresses in multi-address mail aliases.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 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
228 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
229
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; define-mail-alias sets this flag, which causes mail-resolve-all-aliases
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;; to be called before expanding abbrevs if it's necessary.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (defvar mail-abbrev-aliases-need-to-be-resolved t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
234 ;; originally defined in mailalias.el ; build-mail-abbrevs calls this with
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 ;; stuff parsed from the .mailrc file.
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;;
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 459
diff changeset
237 ;;;###autoload
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (defun define-mail-alias (name definition &optional from-mailrc-file)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 "Define NAME as a mail-alias that translates to DEFINITION.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
240 If DEFINITION contains multiple addresses, separate them with commas."
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
241 ;; When this is called from build-mail-abbrevs, the third argument is
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;; 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
243 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ;; Read the defaults first, if we have not done so.
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
245 (if (vectorp mail-abbrevs)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 nil
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
247 (setq mail-abbrevs nil)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
248 (define-abbrev-table 'mail-abbrevs '())
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (if (file-exists-p (mail-abbrev-mailrc-file))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
250 (build-mail-abbrevs)))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 ;; strip garbage from front and end
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (if (string-match "\\`[ \t\n,]+" definition)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (setq definition (substring definition (match-end 0))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (if (string-match "[ \t\n,]+\\'" definition)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (setq definition (substring definition 0 (match-beginning 0))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (let ((result '())
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (start 0)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (L (length definition))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 end)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (while start
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;; If we're reading from the mailrc file, then addresses are delimited
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 ;; 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
263 ;; double-quotes. Otherwise, addresses are separated by commas.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (if from-mailrc-file
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (if (eq ?\" (aref definition start))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (setq start (1+ start)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 end (string-match "\"[ \t,]*" definition start))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (setq end (string-match "[ \t,]+" definition start)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (setq result (cons (substring definition start end) result))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (setq start (and end
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (/= (match-end 0) L)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (match-end 0))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (setq definition (mapconcat (function identity)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (nreverse result)
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
276 mail-alias-separator-string)))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (setq mail-abbrev-aliases-need-to-be-resolved t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (setq name (downcase name))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
279 ;; use an abbrev table instead of an alist for mail-abbrevs.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed.
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
281 (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook)))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (defun mail-resolve-all-aliases ()
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 "Resolve all forward references in the mail aliases table."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (if mail-abbrev-aliases-need-to-be-resolved
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (progn
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 ;; (message "Resolving mail aliases...")
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
289 (if (vectorp mail-abbrevs)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
290 (mapatoms (function mail-resolve-all-aliases-1) mail-abbrevs))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (setq mail-abbrev-aliases-need-to-be-resolved nil)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ;; (message "Resolving mail aliases... done.")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 )))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
295 (defun mail-resolve-all-aliases-1 (sym &optional so-far)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
296 (if (memq sym so-far)
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
297 (error "mail alias loop detected: %s"
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
298 (mapconcat 'symbol-name (cons sym so-far) " <- ")))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (let ((definition (and (boundp sym) (symbol-value sym))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (if definition
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (let ((result '())
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (start 0))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (while start
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (let ((end (string-match "[ \t\n]*,[, \t\n]*" definition start)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (setq result (cons (substring definition start end) result)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 start (and end (match-end 0)))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (setq definition
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (mapconcat (function (lambda (x)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (or (mail-resolve-all-aliases-1
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
310 (intern-soft x mail-abbrevs)
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
311 (cons sym so-far))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 x)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (nreverse result)
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
314 mail-alias-separator-string))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (set sym definition))))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (symbol-value sym))
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
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
319 (defun mail-abbrev-expand-hook ()
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
320 "For use as the fourth arg to define-abbrev.
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
321 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
322 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
323 line."
608
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
324 (save-excursion
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
325 (let ((p (point))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
326 bol comma fp)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
327 (beginning-of-line)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
328 (setq bol (point))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
329 (goto-char p)
606
d9428f32691a *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 599
diff changeset
330 (while (and auto-fill-function
608
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
331 (>= (current-column) fill-column)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
332 (search-backward "," bol t))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
333 (setq comma (point))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
334 (forward-char 1) ; Now we are just past the comma.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
335 (insert "\n")
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
336 (delete-horizontal-space)
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
337 (setq p (point))
608
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
338 (indent-relative)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
339 (setq fp (buffer-substring p (point)))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
340 ;; Go to the end of the new line.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
341 (end-of-line)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
342 (if (> (current-column) fill-column)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
343 ;; It's still too long; do normal auto-fill.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
344 (let ((fill-prefix (or fp "\t")))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
345 (do-auto-fill)))
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
346 ;; Resume the search.
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
347 (goto-char comma)
615cdef1368d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 606
diff changeset
348 ))))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
349
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
350 ;;; Syntax tables and abbrev-expansion
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
352 (defvar mail-abbrev-mode-regexp "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\):"
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
353 "*Regexp to select mail-headers in which mail-abbrevs should be expanded.
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 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
355 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
356 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
357 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
358 turned on.")
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (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
361 "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
362
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (defvar mail-mode-header-syntax-table
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (let ((tab (copy-syntax-table text-mode-syntax-table)))
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
365 ;; This makes the characters "@%!._-" be considered symbol-consituents
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 ;; but not word-constituents, so forward-sexp will move you over an
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 ;; entire address, but forward-word will only move you over a sequence
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ;; of alphanumerics. (Clearly the right thing.)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (modify-syntax-entry ?@ "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (modify-syntax-entry ?% "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (modify-syntax-entry ?! "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (modify-syntax-entry ?. "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (modify-syntax-entry ?_ "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (modify-syntax-entry ?- "_" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (modify-syntax-entry ?< "(>" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (modify-syntax-entry ?> ")<" tab)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 tab)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
378 "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
379 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
380 non-address headers.")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
381
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
382 (defvar mail-abbrev-syntax-table
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
383 (let* ((tab (copy-syntax-table mail-mode-header-syntax-table))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
384 (i (1- (length tab)))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
385 (_ (aref (standard-syntax-table) ?_))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
386 (w (aref (standard-syntax-table) ?w)))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
387 (while (>= i 0)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
388 (if (= (aref tab i) _) (aset tab i w))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
389 (setq i (1- i)))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
390 tab)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
391 "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
392 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
393 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
394
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
396 (defun mail-abbrev-in-expansion-header-p ()
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
397 "Whether point is in a mail-address header field."
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
398 (let ((case-fold-search t))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
399 (and ;;
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
400 ;; we are on an appropriate header line...
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
401 (save-excursion
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
402 (beginning-of-line)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
403 ;; skip backwards over continuation lines.
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
404 (while (and (looking-at "^[ \t]")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
405 (not (= (point) (point-min))))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
406 (forward-line -1))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
407 ;; are we at the front of an appropriate header line?
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
408 (looking-at mail-abbrev-mode-regexp))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
409 ;;
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
410 ;; ...and we are before the mail-header-separator
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
411 (< (point)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
412 (save-excursion
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
413 (goto-char (point-min))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
414 (search-forward (concat "\n" mail-header-separator "\n")
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
415 nil 0)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
416 (point))))))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
417
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
418 (defvar mail-mode-abbrev-table) ; quiet the compiler
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
419
627
59b674ceaf31 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 608
diff changeset
420 (defun sendmail-pre-abbrev-expand-hook ()
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
421 (and (and mail-abbrevs (not (eq mail-abbrevs t)))
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
422 (if (mail-abbrev-in-expansion-header-p)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
423 (progn
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
424 ;;
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
425 ;; We are in a To: (or CC:, or whatever) header, and
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
426 ;; should use word-abbrevs to expand mail aliases.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
427
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
428 ;; Before anything else, resolve aliases if they need it.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
429 (and mail-abbrev-aliases-need-to-be-resolved
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
430 (mail-resolve-all-aliases))
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
431
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
432 ;; Now proceed with the abbrev section.
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
433 ;; - First, install the mail-abbrevs as the word-abbrev table.
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
434 ;; - Then install the mail-abbrev-syntax-table, which
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
435 ;; temporarily marks all of the
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
436 ;; non-alphanumeric-atom-characters (the "_"
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
437 ;; syntax ones) as being normal word-syntax. We do this
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
438 ;; because the C code for expand-abbrev only works on words,
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
439 ;; and we want these characters to be considered words for
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
440 ;; the purpose of abbrev expansion.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
441 ;; - Then we call expand-abbrev again, recursively, to do
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
442 ;; the abbrev expansion with the above syntax table.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
443 ;; - Then we do a trick which tells the expand-abbrev frame
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
444 ;; which invoked us to not continue (and thus not
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
445 ;; expand twice.) This means that any abbrev expansion
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
446 ;; will happen as a result of this function's call to
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
447 ;; expand-abbrev, and not as a result of the call to
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
448 ;; expand-abbrev which invoked *us*.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
449 ;; - Then we set the syntax table to
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
450 ;; mail-mode-header-syntax-table, which doesn't have
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
451 ;; anything to do with abbrev expansion, but
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
452 ;; is just for the user's convenience (see its doc string.)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
453 ;;
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
454
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
455 (setq local-abbrev-table mail-abbrevs)
1148
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
456
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
457 ;; If the character just typed was non-alpha-symbol-syntax,
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
458 ;; then don't expand the abbrev now (that is, don't expand
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
459 ;; when the user types -.) Check the character's syntax in
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
460 ;; the mail-mode-header-syntax-table.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
461
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
462 (set-syntax-table mail-mode-header-syntax-table)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
463 (or (eq (char-syntax last-command-char) ?_)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
464 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
465 ;; Use this table so that abbrevs can have hyphens in them.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
466 (set-syntax-table mail-abbrev-syntax-table)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
467 (expand-abbrev)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
468 ;; Now set it back to what it was before.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
469 (set-syntax-table mail-mode-header-syntax-table)))
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
470 (setq abbrev-start-location (point) ; This is the trick.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
471 abbrev-start-location-buffer (current-buffer)))
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
472
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
473 ;; We're not in a mail header where mail aliases should
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
474 ;; be expanded, then use the normal mail-mode abbrev table
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
475 ;; (if any) and the normal mail-mode syntax table.
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
476
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
477 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table)
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
478 mail-mode-abbrev-table))
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
479 (set-syntax-table mail-mode-syntax-table))
b32ae4969b78 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 1147
diff changeset
480 ))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
481
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
482 ;;; utilities
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
484 (defun merge-mail-abbrevs (file)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 "Merge mail aliases from the given file with existing ones."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (interactive (list
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (let ((insert-default-directory t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (default-directory (expand-file-name "~/"))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (def (mail-abbrev-mailrc-file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (read-file-name
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (format "Read additional aliases from file: (default %s) "
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 def)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 default-directory
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (expand-file-name def default-directory)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 t))))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
496 (build-mail-abbrevs file))
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
498 (defun rebuild-mail-abbrevs (file)
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "Rebuild all the mail aliases from the given file."
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (interactive (list
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (let ((insert-default-directory t)
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (default-directory (expand-file-name "~/"))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (def (mail-abbrev-mailrc-file)))
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (read-file-name
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (format "Read mail aliases from file: (default %s) " 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))))
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
509 (setq mail-abbrevs nil)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
510 (build-mail-abbrevs file))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
511
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
512 (defun mail-interactive-insert-alias (&optional alias)
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
513 "Prompt for and insert a mail alias."
907
48ca3bf4b5f8 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
514 (interactive (progn
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
515 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup))
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
516 (list (completing-read "Expand alias: " mail-abbrevs nil t))))
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
517 (if (not (vectorp mail-abbrevs)) (mail-abbrevs-setup))
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
518 (insert (or (and alias (symbol-value (intern-soft alias mail-abbrevs))) "")))
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
519
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
520 (defun mail-abbrev-next-line (&optional arg)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
521 "Expand any mail abbrev, then move cursor vertically down ARG lines.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
522 If there is no character in the target line exactly under the current column,
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
523 the cursor is positioned after the character in that line which spans this
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
524 column, or at the end of the line if it is not long enough.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
525 If there is no line in the buffer after this one,
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
526 a newline character is inserted to create a line
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
527 and the cursor moves to that line.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
528
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
529 The command \\[set-goal-column] can be used to create
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
530 a semipermanent goal column to which this command always moves.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
531 Then it does not try to move vertically. This goal column is stored
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
532 in `goal-column', which is nil when there is none.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
533
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
534 If you are thinking of using this in a Lisp program, consider
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
535 using `forward-line' instead. It is usually easier to use
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
536 and more reliable (no dependence on goal column, etc.)."
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
537 (interactive "p")
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
538 (if (looking-at "[ \t]*\n") (expand-abbrev))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
539 (setq this-command 'next-line)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
540 (next-line arg))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
541
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
542 (defun mail-abbrev-end-of-buffer (&optional arg)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
543 "Expand any mail abbrev, then move point to end of buffer.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
544 Leave mark at previous position.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
545 With arg N, put point N/10 of the way from the true end.
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
546
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
547 Don't use this command in Lisp programs!
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
548 \(goto-char (point-max)) is faster and avoids clobbering the mark."
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
549 (interactive "P")
717
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
550 (if (looking-at "[ \t]*\n") (expand-abbrev))
950a63133bc4 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 669
diff changeset
551 (setq this-command 'end-of-buffer)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
552 (end-of-buffer arg))
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
553
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
554 (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
555
1432
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
556 ;;(define-key mail-mode-map "\C-n" 'mail-abbrev-next-line)
7446ab662993 Delete version 18 compatibility stuff.
Richard M. Stallman <rms@gnu.org>
parents: 1150
diff changeset
557 ;;(define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer)
598
75b23846ac96 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 584
diff changeset
558
459
a4742d1b81bc Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (provide 'mail-abbrevs)