Mercurial > emacs
annotate lisp/mail/rmailkwd.el @ 31495:1cec17cdcff1
(allocaobj) [!SYSTEM_MALLOC && REL_ALLOC_MMAP]:
Remove vm-limit.o.
author | Dave Love <fx@gnu.org> |
---|---|
date | Fri, 08 Sep 2000 13:14:07 +0000 |
parents | 22d0a2f6a374 |
children | 15fa3a1c6e88 |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
195
diff
changeset
|
1 ;;; rmailkwd.el --- part of the "RMAIL" mail reader for Emacs. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
195
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1985, 1988, 1994 Free Software Foundation, Inc. |
845 | 4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** 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:
658
diff
changeset
|
7 |
36 | 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:
658
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 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. | |
36 | 24 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
25 ;;; Code: |
36 | 26 |
27 ;; Global to all RMAIL buffers. It exists primarily for the sake of | |
28 ;; completion. It is better to use strings with the label functions | |
29 ;; and let them worry about making the label. | |
30 | |
31 (defvar rmail-label-obarray (make-vector 47 0)) | |
32 | |
33 ;; Named list of symbols representing valid message attributes in RMAIL. | |
34 | |
35 (defconst rmail-attributes | |
36 (cons 'rmail-keywords | |
11508
f04aa4cd5182
(rmail-attributes): Recognize "resent" attribute.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
37 (mapcar (function (lambda (s) (intern s rmail-label-obarray))) |
f04aa4cd5182
(rmail-attributes): Recognize "resent" attribute.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
38 '("deleted" "answered" "filed" "forwarded" "unseen" "edited" |
f04aa4cd5182
(rmail-attributes): Recognize "resent" attribute.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
39 "resent")))) |
36 | 40 |
41 (defconst rmail-deleted-label (intern "deleted" rmail-label-obarray)) | |
42 | |
43 ;; Named list of symbols representing valid message keywords in RMAIL. | |
44 | |
16289
38aee5b6ac73
(rmail-keywords): Don't initialize.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
45 (defvar rmail-keywords) |
36 | 46 |
16345
22d0a2f6a374
(rmail-read-label, rmail-add-label, rmail-kill-label)
Richard M. Stallman <rms@gnu.org>
parents:
16289
diff
changeset
|
47 ;;;###autoload |
36 | 48 (defun rmail-add-label (string) |
49 "Add LABEL to labels associated with current RMAIL message. | |
50 Completion is performed over known labels when reading." | |
51 (interactive (list (rmail-read-label "Add label"))) | |
52 (rmail-set-label string t)) | |
53 | |
16345
22d0a2f6a374
(rmail-read-label, rmail-add-label, rmail-kill-label)
Richard M. Stallman <rms@gnu.org>
parents:
16289
diff
changeset
|
54 ;;;###autoload |
36 | 55 (defun rmail-kill-label (string) |
56 "Remove LABEL from labels associated with current RMAIL message. | |
57 Completion is performed over known labels when reading." | |
58 (interactive (list (rmail-read-label "Remove label"))) | |
59 (rmail-set-label string nil)) | |
60 | |
16345
22d0a2f6a374
(rmail-read-label, rmail-add-label, rmail-kill-label)
Richard M. Stallman <rms@gnu.org>
parents:
16289
diff
changeset
|
61 ;;;###autoload |
36 | 62 (defun rmail-read-label (prompt) |
63 (if (not rmail-keywords) (rmail-parse-file-keywords)) | |
64 (let ((result | |
65 (completing-read (concat prompt | |
66 (if rmail-last-label | |
67 (concat " (default " | |
68 (symbol-name rmail-last-label) | |
69 "): ") | |
70 ": ")) | |
71 rmail-label-obarray | |
72 nil | |
73 nil))) | |
74 (if (string= result "") | |
75 rmail-last-label | |
76 (setq rmail-last-label (rmail-make-label result t))))) | |
77 | |
78 (defun rmail-set-label (l state &optional n) | |
79 (rmail-maybe-set-message-counters) | |
80 (if (not n) (setq n rmail-current-message)) | |
81 (aset rmail-summary-vector (1- n) nil) | |
82 (let* ((attribute (rmail-attribute-p l)) | |
83 (keyword (and (not attribute) | |
84 (or (rmail-keyword-p l) | |
85 (rmail-install-keyword l)))) | |
86 (label (or attribute keyword))) | |
87 (if label | |
88 (let ((omax (- (buffer-size) (point-max))) | |
89 (omin (- (buffer-size) (point-min))) | |
90 (buffer-read-only nil) | |
91 (case-fold-search t)) | |
92 (unwind-protect | |
93 (save-excursion | |
94 (widen) | |
95 (goto-char (rmail-msgbeg n)) | |
96 (forward-line 1) | |
97 (if (not (looking-at "[01],")) | |
98 nil | |
99 (let ((start (1+ (point))) | |
100 (bound)) | |
101 (narrow-to-region (point) (progn (end-of-line) (point))) | |
102 (setq bound (point-max)) | |
103 (search-backward ",," nil t) | |
104 (if attribute | |
105 (setq bound (1+ (point))) | |
106 (setq start (1+ (point)))) | |
107 (goto-char start) | |
108 ; (while (re-search-forward "[ \t]*,[ \t]*" nil t) | |
109 ; (replace-match ",")) | |
110 ; (goto-char start) | |
111 (if (re-search-forward | |
112 (concat ", " (rmail-quote-label-name label) ",") | |
113 bound | |
114 'move) | |
115 (if (not state) (replace-match ",")) | |
116 (if state (insert " " (symbol-name label) ","))) | |
117 (if (eq label rmail-deleted-label) | |
118 (rmail-set-message-deleted-p n state))))) | |
119 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)) | |
120 (if (= n rmail-current-message) (rmail-display-labels))))))) | |
121 | |
122 ;; Commented functions aren't used by RMAIL but might be nice for user | |
123 ;; packages that do stuff with RMAIL. Note that rmail-message-labels-p | |
195 | 124 ;; is in rmail.el now. |
36 | 125 |
126 ;(defun rmail-message-label-p (label &optional n) | |
127 ; "Returns symbol if LABEL (attribute or keyword) on NTH or current message." | |
6621
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
128 ; (rmail-message-labels-p (or n rmail-current-message) (regexp-quote label))) |
36 | 129 |
130 ;(defun rmail-parse-message-labels (&optional n) | |
131 ; "Returns labels associated with NTH or current RMAIL message. | |
6621
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
132 ;The result is a list of two lists of strings. The first is the |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
133 ;message attributes and the second is the message keywords." |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
134 ; (let (atts keys) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
135 ; (save-restriction |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
136 ; (widen) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
137 ; (goto-char (rmail-msgbeg (or n rmail-current-message))) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
138 ; (forward-line 1) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
139 ; (or (looking-at "[01],") (error "Malformed label line")) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
140 ; (forward-char 2) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
141 ; (while (looking-at "[ \t]*\\([^ \t\n,]+\\),") |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
142 ; (setq atts (cons (buffer-substring (match-beginning 1) (match-end 1)) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
143 ; atts)) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
144 ; (goto-char (match-end 0))) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
145 ; (or (looking-at ",") (error "Malformed label line")) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
146 ; (forward-char 1) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
147 ; (while (looking-at "[ \t]*\\([^ \t\n,]+\\),") |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
148 ; (setq keys (cons (buffer-substring (match-beginning 1) (match-end 1)) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
149 ; keys)) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
150 ; (goto-char (match-end 0))) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
151 ; (or (looking-at "[ \t]*$") (error "Malformed label line")) |
82404c81aac8
(rmail-message-label-p, rmail-parse-message-labels):
Karl Heuer <kwzh@gnu.org>
parents:
845
diff
changeset
|
152 ; (list (nreverse atts) (nreverse keys))))) |
36 | 153 |
154 (defun rmail-attribute-p (s) | |
155 (let ((symbol (rmail-make-label s))) | |
156 (if (memq symbol (cdr rmail-attributes)) symbol))) | |
157 | |
158 (defun rmail-keyword-p (s) | |
159 (let ((symbol (rmail-make-label s))) | |
160 (if (memq symbol (cdr (rmail-keywords))) symbol))) | |
161 | |
162 (defun rmail-make-label (s &optional forcep) | |
163 (cond ((symbolp s) s) | |
164 (forcep (intern (downcase s) rmail-label-obarray)) | |
165 (t (intern-soft (downcase s) rmail-label-obarray)))) | |
166 | |
167 (defun rmail-force-make-label (s) | |
168 (intern (downcase s) rmail-label-obarray)) | |
169 | |
170 (defun rmail-quote-label-name (label) | |
171 (regexp-quote (symbol-name (rmail-make-label label t)))) | |
172 | |
173 ;; Motion on messages with keywords. | |
174 | |
16345
22d0a2f6a374
(rmail-read-label, rmail-add-label, rmail-kill-label)
Richard M. Stallman <rms@gnu.org>
parents:
16289
diff
changeset
|
175 ;;;###autoload |
195 | 176 (defun rmail-previous-labeled-message (n labels) |
177 "Show previous message with one of the labels LABELS. | |
178 LABELS should be a comma-separated list of label names. | |
179 If LABELS is empty, the last set of labels specified is used. | |
36 | 180 With prefix argument N moves backward N messages with these labels." |
181 (interactive "p\nsMove to previous msg with labels: ") | |
195 | 182 (rmail-next-labeled-message (- n) labels)) |
36 | 183 |
16345
22d0a2f6a374
(rmail-read-label, rmail-add-label, rmail-kill-label)
Richard M. Stallman <rms@gnu.org>
parents:
16289
diff
changeset
|
184 ;;;###autoload |
36 | 185 (defun rmail-next-labeled-message (n labels) |
195 | 186 "Show next message with one of the labels LABELS. |
187 LABELS should be a comma-separated list of label names. | |
188 If LABELS is empty, the last set of labels specified is used. | |
36 | 189 With prefix argument N moves forward N messages with these labels." |
190 (interactive "p\nsMove to next msg with labels: ") | |
191 (if (string= labels "") | |
192 (setq labels rmail-last-multi-labels)) | |
193 (or labels | |
194 (error "No labels to find have been specified previously")) | |
195 (setq rmail-last-multi-labels labels) | |
196 (rmail-maybe-set-message-counters) | |
197 (let ((lastwin rmail-current-message) | |
198 (current rmail-current-message) | |
199 (regexp (concat ", ?\\(" | |
200 (mail-comma-list-regexp labels) | |
201 "\\),"))) | |
202 (save-restriction | |
203 (widen) | |
204 (while (and (> n 0) (< current rmail-total-messages)) | |
205 (setq current (1+ current)) | |
206 (if (rmail-message-labels-p current regexp) | |
207 (setq lastwin current n (1- n)))) | |
208 (while (and (< n 0) (> current 1)) | |
209 (setq current (1- current)) | |
210 (if (rmail-message-labels-p current regexp) | |
211 (setq lastwin current n (1+ n))))) | |
212 (rmail-show-message lastwin) | |
213 (if (< n 0) | |
214 (message "No previous message with labels %s" labels)) | |
215 (if (> n 0) | |
216 (message "No following message with labels %s" labels)))) | |
217 | |
218 ;;; Manipulate the file's Labels option. | |
219 | |
220 ;; Return a list of symbols for all | |
221 ;; the keywords (labels) recorded in this file's Labels option. | |
222 (defun rmail-keywords () | |
223 (or rmail-keywords (rmail-parse-file-keywords))) | |
224 | |
225 ;; Set rmail-keywords to a list of symbols for all | |
226 ;; the keywords (labels) recorded in this file's Labels option. | |
227 (defun rmail-parse-file-keywords () | |
228 (save-restriction | |
229 (save-excursion | |
230 (widen) | |
231 (goto-char 1) | |
232 (setq rmail-keywords | |
233 (if (search-forward "\nLabels:" (rmail-msgbeg 1) t) | |
234 (progn | |
235 (narrow-to-region (point) (progn (end-of-line) (point))) | |
236 (goto-char (point-min)) | |
237 (cons 'rmail-keywords | |
238 (mapcar 'rmail-force-make-label | |
239 (mail-parse-comma-list))))))))) | |
240 | |
241 ;; Add WORD to the list in the file's Labels option. | |
242 ;; Any keyword used for the first time needs this done. | |
243 (defun rmail-install-keyword (word) | |
244 (let ((keyword (rmail-make-label word t)) | |
245 (keywords (rmail-keywords))) | |
246 (if (not (or (rmail-attribute-p keyword) | |
247 (rmail-keyword-p keyword))) | |
248 (let ((omin (- (buffer-size) (point-min))) | |
249 (omax (- (buffer-size) (point-max)))) | |
250 (unwind-protect | |
251 (save-excursion | |
252 (widen) | |
253 (goto-char 1) | |
254 (let ((case-fold-search t) | |
255 (buffer-read-only nil)) | |
256 (or (search-forward "\nLabels:" nil t) | |
257 (progn | |
258 (end-of-line) | |
259 (insert "\nLabels:"))) | |
260 (delete-region (point) (progn (end-of-line) (point))) | |
261 (setcdr keywords (cons keyword (cdr keywords))) | |
262 (while (setq keywords (cdr keywords)) | |
263 (insert (symbol-name (car keywords)) ",")) | |
264 (delete-char -1))) | |
265 (narrow-to-region (- (buffer-size) omin) | |
266 (- (buffer-size) omax))))) | |
267 keyword)) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
195
diff
changeset
|
268 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
195
diff
changeset
|
269 ;;; rmailkwd.el ends here |