comparison lisp/mail/rmailkwd.el @ 88127:9c783aa2b379

Attempt to eliminate some byte compiler warnings. (rmail-add-label): Force the display of the labels. (rmail-read-label): Remove call to rmail-parse-file-keywords which is no longer used. (rmail-set-label): Rewrite. (rmail-keywords): Use (rmail-keyword-init). (rmail-keyword-init, rmail-keyword-register-keywords): New function. (rmail-install-keyword): Rewrite.
author Paul Reilly <pmr@pajato.com>
date Sat, 15 Feb 2003 15:12:08 +0000
parents 253f761ad37b
children abff0bc9014b
comparison
equal deleted inserted replaced
88126:eefd09a79efd 88127:9c783aa2b379
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; This library manages keywords (labels). Labels are stored in the
28 ;; variable `rmail-keywords'.
29
27 ;;; Code: 30 ;;; Code:
28 31
29 ;; Global to all RMAIL buffers. It exists primarily for the sake of 32 ;; Global to all RMAIL buffers. It exists primarily for the sake of
30 ;; completion. It is better to use strings with the label functions 33 ;; completion. It is better to use strings with the label functions
31 ;; and let them worry about making the label. 34 ;; and let them worry about making the label.
35
36 (provide 'rmailkwd)
37
38 (eval-when-compile
39 (require 'mail-utils)
40 (require 'rmail))
32 41
33 (defvar rmail-label-obarray (make-vector 47 0)) 42 (defvar rmail-label-obarray (make-vector 47 0))
34 43
35 ;; Named list of symbols representing valid message attributes in RMAIL. 44 ;; Named list of symbols representing valid message attributes in RMAIL.
36 45
49 ;;;###autoload 58 ;;;###autoload
50 (defun rmail-add-label (string) 59 (defun rmail-add-label (string)
51 "Add LABEL to labels associated with current RMAIL message. 60 "Add LABEL to labels associated with current RMAIL message.
52 Completion is performed over known labels when reading." 61 Completion is performed over known labels when reading."
53 (interactive (list (rmail-read-label "Add label"))) 62 (interactive (list (rmail-read-label "Add label")))
54 (rmail-set-label string t)) 63 (rmail-set-label string t)
64 (rmail-display-labels))
55 65
56 ;;;###autoload 66 ;;;###autoload
57 (defun rmail-kill-label (string) 67 (defun rmail-kill-label (string)
58 "Remove LABEL from labels associated with current RMAIL message. 68 "Remove LABEL from labels associated with current RMAIL message.
59 Completion is performed over known labels when reading." 69 Completion is performed over known labels when reading."
60 (interactive (list (rmail-read-label "Remove label"))) 70 (interactive (list (rmail-read-label "Remove label")))
61 (rmail-set-label string nil)) 71 (rmail-set-label string nil))
62 72
73 ;;; mbox: not ready
63 ;;;###autoload 74 ;;;###autoload
64 (defun rmail-read-label (prompt) 75 (defun rmail-read-label (prompt)
65 (with-current-buffer rmail-buffer 76 (with-current-buffer rmail-buffer
66 (if (not rmail-keywords) (rmail-parse-file-keywords))
67 (let ((result 77 (let ((result
68 (completing-read (concat prompt 78 (completing-read (concat prompt
69 (if rmail-last-label 79 (if rmail-last-label
70 (concat " (default " 80 (concat " (default "
71 (symbol-name rmail-last-label) 81 (symbol-name rmail-last-label)
76 nil))) 86 nil)))
77 (if (string= result "") 87 (if (string= result "")
78 rmail-last-label 88 rmail-last-label
79 (setq rmail-last-label (rmail-make-label result t)))))) 89 (setq rmail-last-label (rmail-make-label result t))))))
80 90
91 ;;; mbox: not ready
81 (defun rmail-set-label (l state &optional n) 92 (defun rmail-set-label (l state &optional n)
93 "Add (STATE is non-nil) or remove (STATE is nil) label L in message N.
94 If N is nil then use the current Rmail message. The current buffer,
95 possibly narrowed, displays a message."
82 (with-current-buffer rmail-buffer 96 (with-current-buffer rmail-buffer
83 (rmail-maybe-set-message-counters)
84 (if (not n) (setq n rmail-current-message)) 97 (if (not n) (setq n rmail-current-message))
85 (aset rmail-summary-vector (1- n) nil) 98
86 (let* ((attribute (rmail-attribute-p l)) 99 ;; Make message N the curent message.
87 (keyword (and (not attribute) 100 (save-restriction
88 (or (rmail-keyword-p l) 101 (widen)
89 (rmail-install-keyword l)))) 102 (narrow-to-region (rmail-desc-get-start n) (rmail-desc-get-end n))
90 (label (or attribute keyword))) 103
91 (if label 104 (if (rmail-attribute-p l)
92 (let ((omax (- (buffer-size) (point-max))) 105
93 (omin (- (buffer-size) (point-min))) 106 ;; Handle the case where the label is one of the predefined
94 (buffer-read-only nil) 107 ;; attributes by using rmail code to set the attribute.
95 (case-fold-search t)) 108 (rmail-set-attribute l state n)
96 (unwind-protect 109
97 (save-excursion 110 ;; Handle the case where the label is a keyword. Make sure the
98 (widen) 111 ;; keyword is registered.
99 (goto-char (rmail-msgbeg n)) 112 (or (rmail-keyword-p l) (rmail-install-keyword l))
100 (forward-line 1) 113
101 (if (not (looking-at "[01],")) 114 ;; Determine if we are adding or removing the keyword.
102 nil 115 (let ((keyword (symbol-name l)))
103 (let ((start (1+ (point))) 116 (if state
104 (bound)) 117
105 (narrow-to-region (point) (progn (end-of-line) (point))) 118 ;; Add the keyword to this message.
106 (setq bound (point-max)) 119 (rmail-desc-add-keyword keyword n)
107 (search-backward ",," nil t) 120
108 (if attribute 121 ;; Remove the keyword from the keyword header.
109 (setq bound (1+ (point))) 122 (rmail-desc-remove-keyword keyword n)))))))
110 (setq start (1+ (point)))) 123
111 (goto-char start)
112 ; (while (re-search-forward "[ \t]*,[ \t]*" nil t)
113 ; (replace-match ","))
114 ; (goto-char start)
115 (if (re-search-forward
116 (concat ", " (rmail-quote-label-name label) ",")
117 bound
118 'move)
119 (if (not state) (replace-match ","))
120 (if state (insert " " (symbol-name label) ",")))
121 (if (eq label rmail-deleted-label)
122 (rmail-set-message-deleted-p n state)))))
123 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax))
124 (if (= n rmail-current-message) (rmail-display-labels))))))))
125 124
126 ;; Commented functions aren't used by RMAIL but might be nice for user 125 ;; Commented functions aren't used by RMAIL but might be nice for user
127 ;; packages that do stuff with RMAIL. Note that rmail-message-labels-p 126 ;; packages that do stuff with RMAIL. Note that rmail-message-labels-p
128 ;; is in rmail.el now. 127 ;; is in rmail.el now.
129 128
218 (if (< n 0) 217 (if (< n 0)
219 (message "No previous message with labels %s" labels)) 218 (message "No previous message with labels %s" labels))
220 (if (> n 0) 219 (if (> n 0)
221 (message "No following message with labels %s" labels)))) 220 (message "No following message with labels %s" labels))))
222 221
223 ;;; Manipulate the file's Labels option. 222 ;;;; Manipulate the file's Labels option.
224 223
225 ;; Return a list of symbols for all 224 ;; Return a list of symbols for all the keywords (labels) recorded in
226 ;; the keywords (labels) recorded in this file's Labels option. 225 ;; this file's Labels.
227 (defun rmail-keywords () 226 (defun rmail-keywords ()
228 (or rmail-keywords (rmail-parse-file-keywords))) 227 "Return a list of all known keywords."
229 228 (or rmail-keywords (rmail-keyword-init)))
229
230 (defun rmail-keyword-init ()
231 "Initialize the variable `rmail-keywords' to an empty list."
232 (setq rmail-keywords (cons 'rmail-keywords nil)))
233
234 ;;;###autoload
235 (defun rmail-keyword-register-keywords (keyword-list)
236 "Add the strings in KEYWORD-LIST to `rmail-keywords'.
237 If a symbol already exists, then ignore that string.
238 Return a list of the keywords added."
239 (delq nil (mapcar 'rmail-install-keyword keyword-list)))
240
241 ;;; mbox: deprecated
230 ;; Set rmail-keywords to a list of symbols for all 242 ;; Set rmail-keywords to a list of symbols for all
231 ;; the keywords (labels) recorded in this file's Labels option. 243 ;; the keywords (labels) recorded in this file's Labels option.
232 (defun rmail-parse-file-keywords () 244 (defun rmail-parse-file-keywords ()
233 (save-restriction 245 (save-restriction
234 (save-excursion 246 (save-excursion
241 (goto-char (point-min)) 253 (goto-char (point-min))
242 (cons 'rmail-keywords 254 (cons 'rmail-keywords
243 (mapcar 'rmail-force-make-label 255 (mapcar 'rmail-force-make-label
244 (mail-parse-comma-list))))))))) 256 (mail-parse-comma-list)))))))))
245 257
258 ;;; mbox: ready
246 ;; Add WORD to the list in the file's Labels option. 259 ;; Add WORD to the list in the file's Labels option.
247 ;; Any keyword used for the first time needs this done. 260 ;; Any keyword used for the first time needs this done.
248 (defun rmail-install-keyword (word) 261 (defun rmail-install-keyword (word)
262 "Append WORD to the global list of keywords. Ignore duplicates.
263 Return WORD if it is a new entry, nil otherwise."
249 (let ((keyword (rmail-make-label word t)) 264 (let ((keyword (rmail-make-label word t))
250 (keywords (rmail-keywords))) 265 (keywords (rmail-keywords)))
251 (if (not (or (rmail-attribute-p keyword) 266 (if (not (or (rmail-attribute-p keyword)
252 (rmail-keyword-p keyword))) 267 (rmail-keyword-p keyword)))
253 (let ((omin (- (buffer-size) (point-min))) 268 (progn
254 (omax (- (buffer-size) (point-max)))) 269 (setcdr keywords (cons keyword (cdr keywords)))
255 (unwind-protect 270 keyword))))
256 (save-excursion
257 (widen)
258 (goto-char 1)
259 (let ((case-fold-search t)
260 (buffer-read-only nil))
261 (or (search-forward "\nLabels:" nil t)
262 (progn
263 (end-of-line)
264 (insert "\nLabels:")))
265 (delete-region (point) (progn (end-of-line) (point)))
266 (setcdr keywords (cons keyword (cdr keywords)))
267 (while (setq keywords (cdr keywords))
268 (insert (symbol-name (car keywords)) ","))
269 (delete-char -1)))
270 (narrow-to-region (- (buffer-size) omin)
271 (- (buffer-size) omax)))))
272 keyword))
273 271
274 ;;; rmailkwd.el ends here 272 ;;; rmailkwd.el ends here