Mercurial > emacs
annotate lisp/mail/rmailkwd.el @ 814:38b2499cb3e9
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 17 Jul 1992 20:24:00 +0000 |
parents | 4f28bd14272c |
children | 213978acbc1e |
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 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
3 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
4 ;; Last-Modified: 31 Oct 1989 |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
5 ;; Keywords: mail |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
6 |
36 | 7 ;; Copyright (C) 1985, 1988 Free Software Foundation, Inc. |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; 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
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
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 | |
37 (mapcar '(lambda (s) (intern s rmail-label-obarray)) | |
38 '("deleted" "answered" "filed" "forwarded" "unseen" "edited")))) | |
39 | |
40 (defconst rmail-deleted-label (intern "deleted" rmail-label-obarray)) | |
41 | |
42 ;; Named list of symbols representing valid message keywords in RMAIL. | |
43 | |
44 (defvar rmail-keywords nil) | |
45 | |
46 (defun rmail-add-label (string) | |
47 "Add LABEL to labels associated with current RMAIL message. | |
48 Completion is performed over known labels when reading." | |
49 (interactive (list (rmail-read-label "Add label"))) | |
50 (rmail-set-label string t)) | |
51 | |
52 (defun rmail-kill-label (string) | |
53 "Remove LABEL from labels associated with current RMAIL message. | |
54 Completion is performed over known labels when reading." | |
55 (interactive (list (rmail-read-label "Remove label"))) | |
56 (rmail-set-label string nil)) | |
57 | |
58 (defun rmail-read-label (prompt) | |
59 (if (not rmail-keywords) (rmail-parse-file-keywords)) | |
60 (let ((result | |
61 (completing-read (concat prompt | |
62 (if rmail-last-label | |
63 (concat " (default " | |
64 (symbol-name rmail-last-label) | |
65 "): ") | |
66 ": ")) | |
67 rmail-label-obarray | |
68 nil | |
69 nil))) | |
70 (if (string= result "") | |
71 rmail-last-label | |
72 (setq rmail-last-label (rmail-make-label result t))))) | |
73 | |
74 (defun rmail-set-label (l state &optional n) | |
75 (rmail-maybe-set-message-counters) | |
76 (if (not n) (setq n rmail-current-message)) | |
77 (aset rmail-summary-vector (1- n) nil) | |
78 (let* ((attribute (rmail-attribute-p l)) | |
79 (keyword (and (not attribute) | |
80 (or (rmail-keyword-p l) | |
81 (rmail-install-keyword l)))) | |
82 (label (or attribute keyword))) | |
83 (if label | |
84 (let ((omax (- (buffer-size) (point-max))) | |
85 (omin (- (buffer-size) (point-min))) | |
86 (buffer-read-only nil) | |
87 (case-fold-search t)) | |
88 (unwind-protect | |
89 (save-excursion | |
90 (widen) | |
91 (goto-char (rmail-msgbeg n)) | |
92 (forward-line 1) | |
93 (if (not (looking-at "[01],")) | |
94 nil | |
95 (let ((start (1+ (point))) | |
96 (bound)) | |
97 (narrow-to-region (point) (progn (end-of-line) (point))) | |
98 (setq bound (point-max)) | |
99 (search-backward ",," nil t) | |
100 (if attribute | |
101 (setq bound (1+ (point))) | |
102 (setq start (1+ (point)))) | |
103 (goto-char start) | |
104 ; (while (re-search-forward "[ \t]*,[ \t]*" nil t) | |
105 ; (replace-match ",")) | |
106 ; (goto-char start) | |
107 (if (re-search-forward | |
108 (concat ", " (rmail-quote-label-name label) ",") | |
109 bound | |
110 'move) | |
111 (if (not state) (replace-match ",")) | |
112 (if state (insert " " (symbol-name label) ","))) | |
113 (if (eq label rmail-deleted-label) | |
114 (rmail-set-message-deleted-p n state))))) | |
115 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)) | |
116 (if (= n rmail-current-message) (rmail-display-labels))))))) | |
117 | |
118 ;; Commented functions aren't used by RMAIL but might be nice for user | |
119 ;; packages that do stuff with RMAIL. Note that rmail-message-labels-p | |
195 | 120 ;; is in rmail.el now. |
36 | 121 |
122 ;(defun rmail-message-attribute-p (attribute &optional n) | |
123 ; "Returns t if ATTRIBUTE on NTH or current message." | |
124 ; (rmail-message-labels-p (rmail-make-label attribute t) n)) | |
125 | |
126 ;(defun rmail-message-keyword-p (keyword &optional n) | |
127 ; "Returns t if KEYWORD on NTH or current message." | |
128 ; (rmail-message-labels-p (rmail-make-label keyword t) n t)) | |
129 | |
130 ;(defun rmail-message-label-p (label &optional n) | |
131 ; "Returns symbol if LABEL (attribute or keyword) on NTH or current message." | |
132 ; (rmail-message-labels-p (rmail-make-label label t) n 'all)) | |
133 | |
134 ;; Not used by RMAIL but might be nice for user package. | |
135 | |
136 ;(defun rmail-parse-message-labels (&optional n) | |
137 ; "Returns labels associated with NTH or current RMAIL message. | |
138 ;Results is a list of two lists. The first is the message attributes | |
139 ;and the second is the message keywords. Labels are represented as symbols." | |
140 ; (let ((omin (- (buffer-size) (point-min))) | |
141 ; (omax (- (buffer-size) (point-max))) | |
142 ; (result)) | |
143 ; (unwind-protect | |
144 ; (save-excursion | |
145 ; (let ((beg (rmail-msgbeg (or n rmail-current-message)))) | |
146 ; (widen) | |
147 ; (goto-char beg) | |
148 ; (forward-line 1) | |
149 ; (if (looking-at "[01],") | |
150 ; (save-restriction | |
151 ; (narrow-to-region (point) (save-excursion (end-of-line) (point))) | |
152 ; (rmail-nuke-whitespace) | |
153 ; (goto-char (1+ (point-min))) | |
154 ; (list (mail-parse-comma-list) (mail-parse-comma-list)))))) | |
155 ; (narrow-to-region (- (buffer-size) omin) | |
156 ; (- (buffer-size) omax)) | |
157 ; nil))) | |
158 | |
159 (defun rmail-attribute-p (s) | |
160 (let ((symbol (rmail-make-label s))) | |
161 (if (memq symbol (cdr rmail-attributes)) symbol))) | |
162 | |
163 (defun rmail-keyword-p (s) | |
164 (let ((symbol (rmail-make-label s))) | |
165 (if (memq symbol (cdr (rmail-keywords))) symbol))) | |
166 | |
167 (defun rmail-make-label (s &optional forcep) | |
168 (cond ((symbolp s) s) | |
169 (forcep (intern (downcase s) rmail-label-obarray)) | |
170 (t (intern-soft (downcase s) rmail-label-obarray)))) | |
171 | |
172 (defun rmail-force-make-label (s) | |
173 (intern (downcase s) rmail-label-obarray)) | |
174 | |
175 (defun rmail-quote-label-name (label) | |
176 (regexp-quote (symbol-name (rmail-make-label label t)))) | |
177 | |
178 ;; Motion on messages with keywords. | |
179 | |
195 | 180 (defun rmail-previous-labeled-message (n labels) |
181 "Show previous message with one of the labels LABELS. | |
182 LABELS should be a comma-separated list of label names. | |
183 If LABELS is empty, the last set of labels specified is used. | |
36 | 184 With prefix argument N moves backward N messages with these labels." |
185 (interactive "p\nsMove to previous msg with labels: ") | |
195 | 186 (rmail-next-labeled-message (- n) labels)) |
36 | 187 |
188 (defun rmail-next-labeled-message (n labels) | |
195 | 189 "Show next message with one of the labels LABELS. |
190 LABELS should be a comma-separated list of label names. | |
191 If LABELS is empty, the last set of labels specified is used. | |
36 | 192 With prefix argument N moves forward N messages with these labels." |
193 (interactive "p\nsMove to next msg with labels: ") | |
194 (if (string= labels "") | |
195 (setq labels rmail-last-multi-labels)) | |
196 (or labels | |
197 (error "No labels to find have been specified previously")) | |
198 (setq rmail-last-multi-labels labels) | |
199 (rmail-maybe-set-message-counters) | |
200 (let ((lastwin rmail-current-message) | |
201 (current rmail-current-message) | |
202 (regexp (concat ", ?\\(" | |
203 (mail-comma-list-regexp labels) | |
204 "\\),"))) | |
205 (save-restriction | |
206 (widen) | |
207 (while (and (> n 0) (< current rmail-total-messages)) | |
208 (setq current (1+ current)) | |
209 (if (rmail-message-labels-p current regexp) | |
210 (setq lastwin current n (1- n)))) | |
211 (while (and (< n 0) (> current 1)) | |
212 (setq current (1- current)) | |
213 (if (rmail-message-labels-p current regexp) | |
214 (setq lastwin current n (1+ n))))) | |
215 (rmail-show-message lastwin) | |
216 (if (< n 0) | |
217 (message "No previous message with labels %s" labels)) | |
218 (if (> n 0) | |
219 (message "No following message with labels %s" labels)))) | |
220 | |
221 ;;; Manipulate the file's Labels option. | |
222 | |
223 ;; Return a list of symbols for all | |
224 ;; the keywords (labels) recorded in this file's Labels option. | |
225 (defun rmail-keywords () | |
226 (or rmail-keywords (rmail-parse-file-keywords))) | |
227 | |
228 ;; Set rmail-keywords to a list of symbols for all | |
229 ;; the keywords (labels) recorded in this file's Labels option. | |
230 (defun rmail-parse-file-keywords () | |
231 (save-restriction | |
232 (save-excursion | |
233 (widen) | |
234 (goto-char 1) | |
235 (setq rmail-keywords | |
236 (if (search-forward "\nLabels:" (rmail-msgbeg 1) t) | |
237 (progn | |
238 (narrow-to-region (point) (progn (end-of-line) (point))) | |
239 (goto-char (point-min)) | |
240 (cons 'rmail-keywords | |
241 (mapcar 'rmail-force-make-label | |
242 (mail-parse-comma-list))))))))) | |
243 | |
244 ;; Add WORD to the list in the file's Labels option. | |
245 ;; Any keyword used for the first time needs this done. | |
246 (defun rmail-install-keyword (word) | |
247 (let ((keyword (rmail-make-label word t)) | |
248 (keywords (rmail-keywords))) | |
249 (if (not (or (rmail-attribute-p keyword) | |
250 (rmail-keyword-p keyword))) | |
251 (let ((omin (- (buffer-size) (point-min))) | |
252 (omax (- (buffer-size) (point-max)))) | |
253 (unwind-protect | |
254 (save-excursion | |
255 (widen) | |
256 (goto-char 1) | |
257 (let ((case-fold-search t) | |
258 (buffer-read-only nil)) | |
259 (or (search-forward "\nLabels:" nil t) | |
260 (progn | |
261 (end-of-line) | |
262 (insert "\nLabels:"))) | |
263 (delete-region (point) (progn (end-of-line) (point))) | |
264 (setcdr keywords (cons keyword (cdr keywords))) | |
265 (while (setq keywords (cdr keywords)) | |
266 (insert (symbol-name (car keywords)) ",")) | |
267 (delete-char -1))) | |
268 (narrow-to-region (- (buffer-size) omin) | |
269 (- (buffer-size) omax))))) | |
270 keyword)) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
195
diff
changeset
|
271 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
195
diff
changeset
|
272 ;;; rmailkwd.el ends here |