Mercurial > emacs
annotate lisp/mail/mailalias.el @ 16652:eb3f3934a185
(normal-top-level, command-line, command-line-1):
User w32 instead of ms-windows for window-system symbol.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Mon, 09 Dec 1996 23:38:03 +0000 |
parents | 3cc16244b779 |
children | 5c7c572f57f8 |
rev | line source |
---|---|
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
1 ;;; mailalias.el --- expand and complete mailing address aliases |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
2 |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
3 ;; Copyright (C) 1985, 1987, 1995, 1996 Free Software Foundation, Inc. |
846
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 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
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 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
53 | 24 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
25 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
26 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
27 ;; 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
|
28 ;; 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
|
29 ;; .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
|
30 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
31 ;;; Code: |
53 | 32 |
8801
eee06aef6f56
Require sendmail. Delete redundant defvar.
Karl Heuer <kwzh@gnu.org>
parents:
8494
diff
changeset
|
33 (require 'sendmail) |
1448
99fb20ef1a17
(mail-aliases): Add definition here.
Richard M. Stallman <rms@gnu.org>
parents:
1434
diff
changeset
|
34 |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
35 (defvar mail-names t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
36 "Alist of local users, aliases and directory entries as available. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
37 When t this still needs to be initialized. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
38 This is the basis for `mail-complete'.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
39 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
40 (defvar mail-local-names t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
41 "Alist of local users. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
42 When t this still needs to be initialized.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
43 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
44 (defvar mail-directory-names t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
45 "Alist of mail address directory entries. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
46 When t this still needs to be initialized.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
47 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
48 (defvar mail-address-field-regexp |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
49 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
50 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
51 (defvar mail-complete-alist |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
52 `((,mail-address-field-regexp mail-get-names pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
53 ("Newsgroups:" . (if (boundp 'gnus-active-hashtb) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
54 gnus-active-hashtb |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
55 (if (boundp news-group-article-assoc) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
56 news-group-article-assoc))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
57 ("Followup-To:" . (mail-sentto-newsgroups)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
58 ;;("Distribution:" ???) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
59 ) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
60 "Alist of header field and expression to return alist for completion. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
61 Expression may reference variable `pattern' which is the string being completed. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
62 If not on matching header, `mail-complete-function' gets called instead.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
63 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
64 (defvar mail-complete-function 'ispell-complete-word |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
65 "Function to call when completing outside `mail-complete-alist'-header.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
66 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
67 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
68 (defvar mail-directory-function nil |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
69 "Function to get completions from directory service or `nil' for none. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
70 See `mail-directory-requery'.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
71 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
72 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
73 ;; This is for when the directory is huge, or changes frequently. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
74 (defvar mail-directory-requery nil |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
75 "When non-`nil' call `mail-directory-function' for each completion. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
76 In that case, one argument gets passed to the function, the partial string |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
77 entered so far.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
78 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
79 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
80 (defvar mail-directory-process nil |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
81 "Unix command when `mail-directory-function' is `mail-directory-process'. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
82 This is a list of the form (COMMAND ARG ...), where each of the list elements |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
83 is evaluated. When `mail-directory-requery' is non-`nil', during |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
84 evaluation the variable `pattern' contains the partial input being completed. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
85 This might look like |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
86 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
87 '(remote-shell-program \"HOST\" \"-nl\" \"USER\" \"COMMAND\") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
88 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
89 or |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
90 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
91 '(remote-shell-program \"HOST\" \"-n\" \"COMMAND '^\" pattern \"'\")") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
92 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
93 (defvar mail-directory-stream () |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
94 "List of (HOST SERVICE) for stream connection to mail directory.") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
95 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
96 (defvar mail-directory-parser nil |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
97 "How to interpret the output of `mail-directory-function'. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
98 Three types of values are possible: |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
99 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
100 - nil means to gather each line as one name |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
101 - regexp means first \\(grouping\\) in successive matches is name |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
102 - function called at beginning of buffer that returns an alist of names") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
103 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
104 |
53 | 105 ;; Called from sendmail-send-it, or similar functions, |
106 ;; only if some mail aliases are defined. | |
107 (defun expand-mail-aliases (beg end &optional exclude) | |
108 "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
|
109 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
|
110 their `Resent-' variants. |
abf2dbc46f7d
(expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents:
11639
diff
changeset
|
111 |
221
ce8e0192266e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
219
diff
changeset
|
112 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
|
113 removed from alias expansions." |
14038
49642146f16c
(expand-mail-aliases, define-mail-alias): Fix calls to `sendmail-sync-aliases'
Karl Heuer <kwzh@gnu.org>
parents:
13653
diff
changeset
|
114 (sendmail-sync-aliases) |
53 | 115 (if (eq mail-aliases t) |
116 (progn (setq mail-aliases nil) (build-mail-aliases))) | |
117 (goto-char beg) | |
118 (setq end (set-marker (make-marker) end)) | |
119 (let ((case-fold-search nil)) | |
120 (while (let ((case-fold-search t)) | |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
121 (re-search-forward mail-address-field-regexp end t)) |
53 | 122 (skip-chars-forward " \t") |
123 (let ((beg1 (point)) | |
124 end1 pos epos seplen | |
125 ;; DISABLED-ALIASES records aliases temporarily disabled | |
126 ;; while we scan text that resulted from expanding those aliases. | |
127 ;; Each element is (ALIAS . TILL-WHEN), where TILL-WHEN | |
128 ;; is where to reenable the alias (expressed as number of chars | |
129 ;; counting from END1). | |
130 (disabled-aliases nil)) | |
131 (re-search-forward "^[^ \t]" end 'move) | |
132 (beginning-of-line) | |
133 (skip-chars-backward " \t\n") | |
134 (setq end1 (point-marker)) | |
135 (goto-char beg1) | |
136 (while (< (point) end1) | |
137 (setq pos (point)) | |
138 ;; Reenable any aliases which were disabled for ranges | |
139 ;; that we have passed out of. | |
140 (while (and disabled-aliases (> pos (- end1 (cdr (car disabled-aliases))))) | |
141 (setq disabled-aliases (cdr disabled-aliases))) | |
142 ;; EPOS gets position of end of next name; | |
143 ;; SEPLEN gets length of whitespace&separator that follows it. | |
144 (if (re-search-forward "[ \t]*[\n,][ \t]*" end1 t) | |
145 (setq epos (match-beginning 0) | |
146 seplen (- (point) epos)) | |
147 (setq epos (marker-position end1) seplen 0)) | |
148 (let (translation | |
11639
462d55b84265
(expand-mail-aliases): Use buffer-substring-no-properties.
Richard M. Stallman <rms@gnu.org>
parents:
10327
diff
changeset
|
149 (string (buffer-substring-no-properties pos epos))) |
53 | 150 (if (and (not (assoc string disabled-aliases)) |
151 (setq translation | |
152 (cdr (assoc string mail-aliases)))) | |
153 (progn | |
154 ;; This name is an alias. Disable it. | |
155 (setq disabled-aliases (cons (cons string (- end1 epos)) | |
156 disabled-aliases)) | |
157 ;; Replace the alias with its expansion | |
158 ;; then rescan the expansion for more aliases. | |
159 (goto-char pos) | |
160 (insert translation) | |
161 (if exclude | |
162 (let ((regexp | |
163 (concat "\\b\\(" exclude "\\)\\b")) | |
164 (end (point-marker))) | |
165 (goto-char pos) | |
166 (while (re-search-forward regexp end t) | |
167 (replace-match "")) | |
168 (goto-char end))) | |
169 (delete-region (point) (+ (point) (- epos pos))) | |
170 (goto-char pos)) | |
171 ;; Name is not an alias. Skip to start of next name. | |
172 (goto-char epos) | |
173 (forward-char seplen)))) | |
174 (set-marker end1 nil))) | |
175 (set-marker end nil))) | |
176 | |
10327
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
177 ;; 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
|
178 ;; by mail-personal-alias-file (usually `~/.mailrc') exists. |
53 | 179 (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
|
180 "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
|
181 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
|
182 (setq file (expand-file-name (or file mail-personal-alias-file))) |
53 | 183 (let ((buffer nil) |
184 (obuf (current-buffer))) | |
185 (unwind-protect | |
186 (progn | |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
187 (setq buffer (generate-new-buffer " mailrc")) |
53 | 188 (set-buffer buffer) |
7732
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
189 (while file |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
190 (cond ((get-file-buffer file) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
191 (insert (save-excursion |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
192 (set-buffer (get-file-buffer file)) |
13653
acde2327c000
(build-mail-aliases): Use buffer-substring-no-properties not buffer-substring.
Richard M. Stallman <rms@gnu.org>
parents:
12516
diff
changeset
|
193 (buffer-substring-no-properties |
acde2327c000
(build-mail-aliases): Use buffer-substring-no-properties not buffer-substring.
Richard M. Stallman <rms@gnu.org>
parents:
12516
diff
changeset
|
194 (point-min) (point-max))))) |
7732
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
195 ((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
|
196 ((file-exists-p (setq file (concat "~/" file))) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
197 (insert-file-contents file)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
198 (t (setq file nil))) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
199 ;; Don't lose if no final newline. |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
200 (goto-char (point-max)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
201 (or (eq (preceding-char) ?\n) (newline)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
202 (goto-char (point-min)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
203 ;; handle "\\\n" continuation lines |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
204 (while (not (eobp)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
205 (end-of-line) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
206 (if (= (preceding-char) ?\\) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
207 (progn (delete-char -1) (delete-char 1) (insert ?\ )) |
53 | 208 (forward-char 1))) |
7732
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
209 (goto-char (point-min)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
210 ;; handle `source' directives -- Eddy/1994/May/25 |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
211 (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
|
212 (re-search-forward "\\S-+") |
13653
acde2327c000
(build-mail-aliases): Use buffer-substring-no-properties not buffer-substring.
Richard M. Stallman <rms@gnu.org>
parents:
12516
diff
changeset
|
213 (setq file (buffer-substring-no-properties |
acde2327c000
(build-mail-aliases): Use buffer-substring-no-properties not buffer-substring.
Richard M. Stallman <rms@gnu.org>
parents:
12516
diff
changeset
|
214 (match-beginning 0) (match-end 0))) |
7732
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
215 (beginning-of-line) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
216 (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
|
217 (beginning-of-line)) |
b99162ca5247
(build-mail-aliases): Handle source directives.
Richard M. Stallman <rms@gnu.org>
parents:
3743
diff
changeset
|
218 (t (setq file nil)))) |
53 | 219 (goto-char (point-min)) |
12516
254987dd395f
* mailalias.el (build-mail-aliases): Fixed the regexp for "^group".
Francesco Potortì <pot@gnu.org>
parents:
12448
diff
changeset
|
220 (while (re-search-forward |
254987dd395f
* mailalias.el (build-mail-aliases): Fixed the regexp for "^group".
Francesco Potortì <pot@gnu.org>
parents:
12448
diff
changeset
|
221 "^\\(a\\|alias\\|g\\|group\\)[ \t]+\\([^ \t]+\\)" nil t) |
254987dd395f
* mailalias.el (build-mail-aliases): Fixed the regexp for "^group".
Francesco Potortì <pot@gnu.org>
parents:
12448
diff
changeset
|
222 (let* ((name (match-string 2)) |
53 | 223 (start (progn (skip-chars-forward " \t") (point)))) |
224 (end-of-line) | |
225 (define-mail-alias | |
226 name | |
13653
acde2327c000
(build-mail-aliases): Use buffer-substring-no-properties not buffer-substring.
Richard M. Stallman <rms@gnu.org>
parents:
12516
diff
changeset
|
227 (buffer-substring-no-properties start (point)) |
7971
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
228 t))) |
53 | 229 mail-aliases) |
230 (if buffer (kill-buffer buffer)) | |
231 (set-buffer obuf)))) | |
232 | |
233 ;; Always autoloadable in case the user wants to define aliases | |
234 ;; interactively or in .emacs. | |
256 | 235 ;;;###autoload |
7971
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
236 (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
|
237 "Define NAME as a mail alias that translates to DEFINITION. |
53 | 238 This means that sending a message to NAME will actually send to DEFINITION. |
12448
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
239 |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
240 Normally, the addresses in DEFINITION must be separated by commas. |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
241 If FROM-MAILRC-FILE is non-nil, then addresses in DEFINITION |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
242 can be separated by spaces; an address can contain spaces |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
243 if it is quoted with double-quotes." |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
244 |
53 | 245 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") |
246 ;; Read the defaults first, if we have not done so. | |
14038
49642146f16c
(expand-mail-aliases, define-mail-alias): Fix calls to `sendmail-sync-aliases'
Karl Heuer <kwzh@gnu.org>
parents:
13653
diff
changeset
|
247 (sendmail-sync-aliases) |
53 | 248 (if (eq mail-aliases t) |
249 (progn | |
250 (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
|
251 (if (file-exists-p mail-personal-alias-file) |
53 | 252 (build-mail-aliases)))) |
3743
e67f922b73ed
(define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
253 ;; strip garbage from front and end |
e67f922b73ed
(define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
254 (if (string-match "\\`[ \t\n,]+" definition) |
474 | 255 (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
|
256 (if (string-match "[ \t\n,]+\\'" definition) |
474 | 257 (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
|
258 (let ((result '()) |
8494
ae554ccf4fb5
(define-mail-alias): Avoid error if DEFINITION is "".
Richard M. Stallman <rms@gnu.org>
parents:
7971
diff
changeset
|
259 ;; 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
|
260 (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
|
261 (L (length definition)) |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
262 end tem) |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
263 (while start |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
264 ;; 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
|
265 ;; 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
|
266 ;; 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
|
267 (if from-mailrc-file |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
268 (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
|
269 (setq start (1+ start) |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
270 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
|
271 (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
|
272 (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
|
273 (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
|
274 (setq start (and end |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
275 (/= (match-end 0) L) |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
276 (match-end 0)))) |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
277 (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
|
278 (nreverse result) |
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
279 ", ")) |
53 | 280 (setq tem (assoc name mail-aliases)) |
281 (if tem | |
282 (rplacd tem definition) | |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
283 (setq mail-aliases (cons (cons name definition) mail-aliases) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
284 mail-names t)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
285 |
14678
f77d51b836d0
(mail-complete): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
14551
diff
changeset
|
286 ;;;###autoload |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
287 (defun mail-complete (arg) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
288 "Perform completion on header field or word preceding point. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
289 Completable headers are according to `mail-complete-alist'. If none matches |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
290 current header, calls `mail-complete-function' and passes prefix arg if any." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
291 (interactive "P") |
15501
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
292 ;; Read the defaults first, if we have not done so. |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
293 (sendmail-sync-aliases) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
294 (if (eq mail-aliases t) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
295 (progn |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
296 (setq mail-aliases nil) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
297 (if (file-exists-p mail-personal-alias-file) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
298 (build-mail-aliases)))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
299 (let ((list mail-complete-alist)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
300 (if (and (save-excursion (search-forward |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
301 (concat "\n" mail-header-separator "\n") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
302 nil t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
303 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
304 (if (re-search-backward "^[^\t]" nil t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
305 (while list |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
306 (if (looking-at (car (car list))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
307 (setq arg (cdr (car list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
308 list ()) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
309 (setq list (cdr list))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
310 arg)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
311 (let* ((end (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
312 (beg (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
313 (skip-chars-backward "^ \t<,:") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
314 (point))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
315 (pattern (buffer-substring beg end)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
316 completion) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
317 (setq list (eval arg) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
318 completion (try-completion pattern list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
319 (cond ((eq completion t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
320 ((null completion) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
321 (message "Can't find completion for \"%s\"" pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
322 (ding)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
323 ((not (string= pattern completion)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
324 (delete-region beg end) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
325 (insert completion)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
326 (t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
327 (message "Making completion list...") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
328 (with-output-to-temp-buffer "*Completions*" |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
329 (display-completion-list |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
330 (all-completions pattern list))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
331 (message "Making completion list...%s" "done")))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
332 (funcall mail-complete-function arg)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
333 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
334 (defun mail-get-names (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
335 "Fetch local users and global mail adresses for completion. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
336 Consults `/etc/passwd' and a directory service if one is set up via |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
337 `mail-directory-function'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
338 (if (eq mail-local-names t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
339 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
340 (set-buffer (generate-new-buffer " passwd")) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
341 (insert-file-contents "/etc/passwd" nil nil nil t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
342 (setq mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
343 (while (not (eobp)) |
14799
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
344 ;;Recognize lines like |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
345 ;; nobody:*:65534:65534::/: |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
346 ;; +demo::::::/bin/csh |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
347 ;; +ethanb |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
348 ;;while skipping |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
349 ;; +@SOFTWARE |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
350 (if (looking-at "\\+?\\([^:@\n+]+\\)") |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
351 (add-to-list 'mail-local-names (list (match-string 1)))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
352 (beginning-of-line 2)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
353 (kill-buffer (current-buffer)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
354 (if (or (eq mail-names t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
355 (eq mail-directory-names t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
356 (let (directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
357 (and mail-directory-function |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
358 (eq mail-directory-names t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
359 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
360 (mail-directory (if mail-directory-requery pattern)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
361 (if (or directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
362 (eq mail-names t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
363 (setq mail-names |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
364 (sort (append (if (consp mail-aliases) mail-aliases) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
365 (if (consp mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
366 mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
367 directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
368 (lambda (a b) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
369 ;; should cache downcased strings |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
370 (string< (downcase (car a)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
371 (downcase (car b))))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
372 (or mail-directory-requery |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
373 (setq mail-directory-names directory)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
374 mail-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
375 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
376 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
377 (defun mail-directory (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
378 "Call directory to get names matching PATTERN or all if `nil'. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
379 Calls `mail-directory-function' and applies `mail-directory-parser' to output." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
380 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
381 (message "Querying directory...") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
382 (set-buffer (generate-new-buffer " *mail-directory*")) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
383 (funcall mail-directory-function pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
384 (goto-char 1) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
385 (let (directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
386 (if (stringp mail-directory-parser) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
387 (while (re-search-forward mail-directory-parser nil t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
388 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
389 `((,(match-string 1)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
390 ,@directory))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
391 (if mail-directory-parser |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
392 (setq directory (funcall mail-directory-parser)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
393 (while (not (eobp)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
394 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
395 `((,(buffer-substring (point) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
396 (progn |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
397 (forward-line) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
398 (if (bolp) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
399 (1- (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
400 (point))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
401 ,@directory))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
402 (kill-buffer (current-buffer)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
403 (message "Querying directory...done") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
404 directory))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
405 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
406 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
407 (defun mail-directory-process (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
408 "Call a Unix process to output names in directory. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
409 See `mail-directory-process'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
410 (apply 'call-process (eval (car mail-directory-process)) nil t nil |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
411 (mapcar 'eval (cdr mail-directory-process)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
412 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
413 ;; This should handle a dialog. Currently expects port to spit out names. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
414 (defun mail-directory-stream (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
415 "Open a stream to retrieve names in directory. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
416 See `mail-directory-stream'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
417 (let (mailalias-done) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
418 (set-process-sentinel |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
419 (apply 'open-network-stream "mailalias" (current-buffer) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
420 mail-directory-stream) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
421 (lambda (x x) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
422 (setq mailalias-done t))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
423 (while (not mailalias-done) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
424 (sit-for .1)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
425 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
426 (defun mail-sentto-newsgroups () |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
427 "Return all entries from Newsgroups: header as completion alist." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
428 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
429 (if (mail-position-on-field "newsgroups" t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
430 (let ((point (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
431 list) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
432 (while (< (skip-chars-backward "^:, \t\n") 0) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
433 (setq list `((,(buffer-substring (point) point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
434 ,@list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
435 (skip-chars-backward ", \t\n") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
436 (setq point (point))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
437 list)))) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
438 |
923 | 439 (provide 'mailalias) |
440 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
441 ;;; mailalias.el ends here |