Mercurial > emacs
annotate lisp/mail/mailalias.el @ 15013:aad88afa6a0c libc-960413 libc-960414 libc-960415 libc-960416 libc-960417 libc-960418 libc-960419 libc-960420 libc-960421 libc-960422 libc-960423 libc-960424 libc-960425 libc-960426 libc-960427 libc-960428 libc-960429 libc-960430 libc-960501 libc-960502 libc-960503 libc-960504 libc-960505 libc-960506 libc-960507 libc-960508 libc-960509 libc-960510 libc-960511 libc-960512 libc-960513 libc-960514 libc-960515 libc-960516 libc-960517 libc-960518 libc-960519 libc-960520
* config.guess: Combine two OSF1 rules.
Also recognize field test versions. From mjr@zk3.dec.com.
* config.guess (dgux): Use /usr/bin/uname rather than uname,
because GNU uname does not support -p. From pmr@pajato.com.
author | Per Bothner <bothner@cygnus.com> |
---|---|
date | Sat, 13 Apr 1996 00:06:54 +0000 |
parents | 619266555aec |
children | 3cc16244b779 |
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") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
292 (let ((list mail-complete-alist)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
293 (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
|
294 (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
|
295 nil t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
296 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
297 (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
|
298 (while list |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
299 (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
|
300 (setq arg (cdr (car list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
301 list ()) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
302 (setq list (cdr list))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
303 arg)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
304 (let* ((end (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
305 (beg (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
306 (skip-chars-backward "^ \t<,:") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
307 (point))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
308 (pattern (buffer-substring beg end)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
309 completion) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
310 (setq list (eval arg) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
311 completion (try-completion pattern list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
312 (cond ((eq completion t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
313 ((null completion) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
314 (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
|
315 (ding)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
316 ((not (string= pattern completion)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
317 (delete-region beg end) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
318 (insert completion)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
319 (t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
320 (message "Making completion list...") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
321 (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
|
322 (display-completion-list |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
323 (all-completions pattern list))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
324 (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
|
325 (funcall mail-complete-function arg)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
326 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
327 (defun mail-get-names (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
328 "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
|
329 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
|
330 `mail-directory-function'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
331 (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
|
332 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
333 (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
|
334 (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
|
335 (setq mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
336 (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
|
337 ;;Recognize lines like |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
338 ;; nobody:*:65534:65534::/: |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
339 ;; +demo::::::/bin/csh |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
340 ;; +ethanb |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
341 ;;while skipping |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
342 ;; +@SOFTWARE |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
343 (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
|
344 (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
|
345 (beginning-of-line 2)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
346 (kill-buffer (current-buffer)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
347 (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
|
348 (eq mail-directory-names t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
349 (let (directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
350 (and mail-directory-function |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
351 (eq mail-directory-names t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
352 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
353 (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
|
354 (if (or directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
355 (eq mail-names t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
356 (setq mail-names |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
357 (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
|
358 (if (consp mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
359 mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
360 directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
361 (lambda (a b) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
362 ;; should cache downcased strings |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
363 (string< (downcase (car a)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
364 (downcase (car b))))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
365 (or mail-directory-requery |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
366 (setq mail-directory-names directory)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
367 mail-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
368 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
369 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
370 (defun mail-directory (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
371 "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
|
372 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
|
373 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
374 (message "Querying directory...") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
375 (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
|
376 (funcall mail-directory-function pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
377 (goto-char 1) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
378 (let (directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
379 (if (stringp mail-directory-parser) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
380 (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
|
381 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
382 `((,(match-string 1)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
383 ,@directory))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
384 (if mail-directory-parser |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
385 (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
|
386 (while (not (eobp)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
387 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
388 `((,(buffer-substring (point) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
389 (progn |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
390 (forward-line) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
391 (if (bolp) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
392 (1- (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
393 (point))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
394 ,@directory))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
395 (kill-buffer (current-buffer)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
396 (message "Querying directory...done") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
397 directory))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
398 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
399 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
400 (defun mail-directory-process (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
401 "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
|
402 See `mail-directory-process'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
403 (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
|
404 (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
|
405 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
406 ;; 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
|
407 (defun mail-directory-stream (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
408 "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
|
409 See `mail-directory-stream'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
410 (let (mailalias-done) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
411 (set-process-sentinel |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
412 (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
|
413 mail-directory-stream) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
414 (lambda (x x) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
415 (setq mailalias-done t))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
416 (while (not mailalias-done) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
417 (sit-for .1)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
418 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
419 (defun mail-sentto-newsgroups () |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
420 "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
|
421 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
422 (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
|
423 (let ((point (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
424 list) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
425 (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
|
426 (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
|
427 ,@list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
428 (skip-chars-backward ", \t\n") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
429 (setq point (point))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
430 list)))) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
431 |
923 | 432 (provide 'mailalias) |
433 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
434 ;;; mailalias.el ends here |