annotate lisp/mail/mailalias.el @ 12185:7a18efea682a

(read_char_minibuf_menu_prompt): If the char to type doesn't match the prompt string, show the char explicitly.
author Karl Heuer <kwzh@gnu.org>
date Sun, 11 Jun 1995 20:09:49 +0000
parents abf2dbc46f7d
children 7291d1627d2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 474
diff changeset
1 ;;; mailalias.el --- expand mailing address aliases defined in ~/.mailrc.
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 474
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;; Copyright (C) 1985, 1987 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
5 ;; Maintainer: FSF
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
6 ;; Keywords: mail
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
7
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 ;; any later version.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1448
diff changeset
24 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1448
diff changeset
25
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1448
diff changeset
26 ;; Basic functions for defining and expanding mail aliases.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1448
diff changeset
27 ;; These seal off the interface to the alias-definition parts of a
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1448
diff changeset
28 ;; .mailrc file formatted for BSD's Mail or USL's mailx.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1448
diff changeset
29
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
30 ;;; Code:
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31
8801
eee06aef6f56 Require sendmail. Delete redundant defvar.
Karl Heuer <kwzh@gnu.org>
parents: 8494
diff changeset
32 (require 'sendmail)
1448
99fb20ef1a17 (mail-aliases): Add definition here.
Richard M. Stallman <rms@gnu.org>
parents: 1434
diff changeset
33
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 ;; Called from sendmail-send-it, or similar functions,
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 ;; only if some mail aliases are defined.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 (defun expand-mail-aliases (beg end &optional exclude)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 "Expand all mail aliases in suitable header fields found between BEG and END.
11856
abf2dbc46f7d (expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents: 11639
diff changeset
38 Suitable header fields are `To', `From', `CC' and `BCC', `Reply-to', and
abf2dbc46f7d (expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents: 11639
diff changeset
39 their `Resent-' variants.
abf2dbc46f7d (expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents: 11639
diff changeset
40
221
ce8e0192266e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 219
diff changeset
41 Optional second arg EXCLUDE may be a regular expression defining text to be
ce8e0192266e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 219
diff changeset
42 removed from alias expansions."
9005
e7fa0346e8f8 (expand-mail-aliases, define-mail-alias): Change sync-mail-aliases to
Karl Heuer <kwzh@gnu.org>
parents: 8801
diff changeset
43 (sendmail-synch-aliases)
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 (if (eq mail-aliases t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 (progn (setq mail-aliases nil) (build-mail-aliases)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 (goto-char beg)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 (setq end (set-marker (make-marker) end))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 (let ((case-fold-search nil))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 (while (let ((case-fold-search t))
11856
abf2dbc46f7d (expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents: 11639
diff changeset
50 (re-search-forward "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):" end t))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 (skip-chars-forward " \t")
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 (let ((beg1 (point))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 end1 pos epos seplen
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 ;; DISABLED-ALIASES records aliases temporarily disabled
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 ;; while we scan text that resulted from expanding those aliases.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 ;; Each element is (ALIAS . TILL-WHEN), where TILL-WHEN
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 ;; is where to reenable the alias (expressed as number of chars
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 ;; counting from END1).
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 (disabled-aliases nil))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 (re-search-forward "^[^ \t]" end 'move)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 (beginning-of-line)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 (skip-chars-backward " \t\n")
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 (setq end1 (point-marker))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 (goto-char beg1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (while (< (point) end1)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (setq pos (point))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 ;; Reenable any aliases which were disabled for ranges
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 ;; that we have passed out of.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (while (and disabled-aliases (> pos (- end1 (cdr (car disabled-aliases)))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 (setq disabled-aliases (cdr disabled-aliases)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 ;; EPOS gets position of end of next name;
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72 ;; SEPLEN gets length of whitespace&separator that follows it.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (if (re-search-forward "[ \t]*[\n,][ \t]*" end1 t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (setq epos (match-beginning 0)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 seplen (- (point) epos))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 (setq epos (marker-position end1) seplen 0))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 (let (translation
11639
462d55b84265 (expand-mail-aliases): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents: 10327
diff changeset
78 (string (buffer-substring-no-properties pos epos)))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 (if (and (not (assoc string disabled-aliases))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 (setq translation
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 (cdr (assoc string mail-aliases))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 (progn
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 ;; This name is an alias. Disable it.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 (setq disabled-aliases (cons (cons string (- end1 epos))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 disabled-aliases))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 ;; Replace the alias with its expansion
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 ;; then rescan the expansion for more aliases.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 (goto-char pos)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 (insert translation)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 (if exclude
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (let ((regexp
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (concat "\\b\\(" exclude "\\)\\b"))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 (end (point-marker)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 (goto-char pos)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 (while (re-search-forward regexp end t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 (replace-match ""))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 (goto-char end)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 (delete-region (point) (+ (point) (- epos pos)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (goto-char pos))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 ;; Name is not an alias. Skip to start of next name.
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (goto-char epos)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (forward-char seplen))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 (set-marker end1 nil)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (set-marker end nil)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105
10327
8822b968b11c Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents: 9644
diff changeset
106 ;; Called by mail-setup, or similar functions, only if the file specified
8822b968b11c Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents: 9644
diff changeset
107 ;; by mail-personal-alias-file (usually `~/.mailrc') exists.
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 (defun build-mail-aliases (&optional file)
10327
8822b968b11c Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents: 9644
diff changeset
109 "Read mail aliases from personal aliases file and set `mail-aliases'.
8822b968b11c Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents: 9644
diff changeset
110 By default, this is the file specified by `mail-personal-alias-file'."
8822b968b11c Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents: 9644
diff changeset
111 (setq file (expand-file-name (or file mail-personal-alias-file)))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 (let ((buffer nil)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 (obuf (current-buffer)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 (unwind-protect
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 (progn
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 (setq buffer (generate-new-buffer "mailrc"))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 (buffer-disable-undo buffer)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (set-buffer buffer)
7732
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
119 (while file
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
120 (cond ((get-file-buffer file)
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
121 (insert (save-excursion
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
122 (set-buffer (get-file-buffer file))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
123 (buffer-substring (point-min) (point-max)))))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
124 ((file-exists-p file) (insert-file-contents file))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
125 ((file-exists-p (setq file (concat "~/" file)))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
126 (insert-file-contents file))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
127 (t (setq file nil)))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
128 ;; Don't lose if no final newline.
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
129 (goto-char (point-max))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
130 (or (eq (preceding-char) ?\n) (newline))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
131 (goto-char (point-min))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
132 ;; handle "\\\n" continuation lines
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
133 (while (not (eobp))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
134 (end-of-line)
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
135 (if (= (preceding-char) ?\\)
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
136 (progn (delete-char -1) (delete-char 1) (insert ?\ ))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 (forward-char 1)))
7732
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
138 (goto-char (point-min))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
139 ;; handle `source' directives -- Eddy/1994/May/25
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
140 (cond ((re-search-forward "^source[ \t]+" nil t)
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
141 (re-search-forward "\\S-+")
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
142 (setq file
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
143 (buffer-substring (match-beginning 0) (match-end 0)))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
144 (beginning-of-line)
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
145 (insert "# ") ; to ensure we don't re-process this file
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
146 (beginning-of-line))
b99162ca5247 (build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents: 3743
diff changeset
147 (t (setq file nil))))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 (goto-char (point-min))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 (while (or (re-search-forward "^a\\(lias\\|\\)[ \t]+" nil t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 (re-search-forward "^g\\(roup\\|\\)[ \t]+" nil t))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
151 (re-search-forward "[^ \t]+")
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
152 (let* ((name (buffer-substring (match-beginning 0) (match-end 0)))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 (start (progn (skip-chars-forward " \t") (point))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 (end-of-line)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 (define-mail-alias
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 name
7971
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
157 (buffer-substring start (point))
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
158 t)))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
159 mail-aliases)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 (if buffer (kill-buffer buffer))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 (set-buffer obuf))))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
162
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
163 ;; Always autoloadable in case the user wants to define aliases
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
164 ;; interactively or in .emacs.
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 221
diff changeset
165 ;;;###autoload
7971
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
166 (defun define-mail-alias (name definition &optional from-mailrc-file)
221
ce8e0192266e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 219
diff changeset
167 "Define NAME as a mail alias that translates to DEFINITION.
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
168 This means that sending a message to NAME will actually send to DEFINITION.
7970
d8bede4feaed (define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 7732
diff changeset
169 DEFINITION can be one or more mail addresses separated by spaces.
d8bede4feaed (define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 7732
diff changeset
170 An address can contain spaces if it is quoted with double-quotes."
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
171 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
172 ;; Read the defaults first, if we have not done so.
9005
e7fa0346e8f8 (expand-mail-aliases, define-mail-alias): Change sync-mail-aliases to
Karl Heuer <kwzh@gnu.org>
parents: 8801
diff changeset
173 (sendmail-synch-aliases)
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
174 (if (eq mail-aliases t)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
175 (progn
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
176 (setq mail-aliases nil)
10327
8822b968b11c Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents: 9644
diff changeset
177 (if (file-exists-p mail-personal-alias-file)
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
178 (build-mail-aliases))))
3743
e67f922b73ed (define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
179 ;; strip garbage from front and end
e67f922b73ed (define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
180 (if (string-match "\\`[ \t\n,]+" definition)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 256
diff changeset
181 (setq definition (substring definition (match-end 0))))
3743
e67f922b73ed (define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
182 (if (string-match "[ \t\n,]+\\'" definition)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 256
diff changeset
183 (setq definition (substring definition 0 (match-beginning 0))))
7971
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
184 (let ((result '())
8494
ae554ccf4fb5 (define-mail-alias): Avoid error if DEFINITION is "".
Richard M. Stallman <rms@gnu.org>
parents: 7971
diff changeset
185 ;; If DEFINITION is null string, avoid looping even once.
ae554ccf4fb5 (define-mail-alias): Avoid error if DEFINITION is "".
Richard M. Stallman <rms@gnu.org>
parents: 7971
diff changeset
186 (start (and (not (equal definition "")) 0))
7971
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
187 (L (length definition))
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
188 end tem)
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
189 (while start
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
190 ;; If we're reading from the mailrc file, then addresses are delimited
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
191 ;; by spaces, and addresses with embedded spaces must be surrounded by
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
192 ;; double-quotes. Otherwise, addresses are separated by commas.
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
193 (if from-mailrc-file
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
194 (if (eq ?\" (aref definition start))
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
195 (setq start (1+ start)
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
196 end (string-match "\"[ \t,]*" definition start))
8494
ae554ccf4fb5 (define-mail-alias): Avoid error if DEFINITION is "".
Richard M. Stallman <rms@gnu.org>
parents: 7971
diff changeset
197 (setq end (string-match "[ \t,]+" definition start)))
ae554ccf4fb5 (define-mail-alias): Avoid error if DEFINITION is "".
Richard M. Stallman <rms@gnu.org>
parents: 7971
diff changeset
198 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
7971
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
199 (setq result (cons (substring definition start end) result))
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
200 (setq start (and end
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
201 (/= (match-end 0) L)
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
202 (match-end 0))))
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
203 (setq definition (mapconcat (function identity)
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
204 (nreverse result)
e02c5d5d76cd (define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents: 7970
diff changeset
205 ", "))
53
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
206 (setq tem (assoc name mail-aliases))
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
207 (if tem
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
208 (rplacd tem definition)
a8efef5eb891 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
209 (setq mail-aliases (cons (cons name definition) mail-aliases)))))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 474
diff changeset
210
923
9f3cc03dae67 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 846
diff changeset
211 (provide 'mailalias)
9f3cc03dae67 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 846
diff changeset
212
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 474
diff changeset
213 ;;; mailalias.el ends here