diff options
| author | Richard M. Stallman | 2009-01-05 15:48:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2009-01-05 15:48:15 +0000 |
| commit | 4e756c2469a097ca1edffc6bbe9caac16447c4c3 (patch) | |
| tree | ca280582a1f22347a430cdd1e76c653bb786d5f3 | |
| parent | 91552da9ad303cb4ed6b8efeb79c39cbe425f673 (diff) | |
| download | emacs-4e756c2469a097ca1edffc6bbe9caac16447c4c3.tar.gz emacs-4e756c2469a097ca1edffc6bbe9caac16447c4c3.zip | |
Require pmail; delete compiler defvars.
Delete most declare-function calls.
(pmail-keywords, pmail-deleted-label, pmail-attributes): Vars deleted.
(pmail-attribute-p, pmail-keyword-p): Fns deleted.
(pmail-keywords, pmail-parse-file-keywords, pmail-install-keyword):
(pmail-force-make-label, pmail-quote-label-name): Fns deleted.
(pmail-last-label, pmail-last-multi-labels): Vars moved from pmail.el.
(pmail-read-label): Don't switch buffers, don't parse file keywords.
(pmail-set-label): Major rewrite.
(pmail-next-labeled-message): Call pmail-get-labels and match it.
| -rw-r--r-- | lisp/mail/pmailkwd.el | 285 |
1 files changed, 82 insertions, 203 deletions
diff --git a/lisp/mail/pmailkwd.el b/lisp/mail/pmailkwd.el index 7f746613eaa..1becc43e629 100644 --- a/lisp/mail/pmailkwd.el +++ b/lisp/mail/pmailkwd.el | |||
| @@ -25,12 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | ;;; Code: | 26 | ;;; Code: |
| 27 | 27 | ||
| 28 | (defvar pmail-buffer) | 28 | (require 'pmail) |
| 29 | (defvar pmail-current-message) | ||
| 30 | (defvar pmail-last-label) | ||
| 31 | (defvar pmail-last-multi-labels) | ||
| 32 | (defvar pmail-summary-vector) | ||
| 33 | (defvar pmail-total-messages) | ||
| 34 | 29 | ||
| 35 | ;; Global to all PMAIL buffers. It exists primarily for the sake of | 30 | ;; Global to all PMAIL buffers. It exists primarily for the sake of |
| 36 | ;; completion. It is better to use strings with the label functions | 31 | ;; completion. It is better to use strings with the label functions |
| @@ -38,156 +33,91 @@ | |||
| 38 | 33 | ||
| 39 | (defvar pmail-label-obarray (make-vector 47 0)) | 34 | (defvar pmail-label-obarray (make-vector 47 0)) |
| 40 | 35 | ||
| 41 | ;; Named list of symbols representing valid message attributes in PMAIL. | 36 | (mapc (function (lambda (s) (intern s pmail-label-obarray))) |
| 37 | '("deleted" "answered" "filed" "forwarded" "unseen" "edited" | ||
| 38 | "resent")) | ||
| 42 | 39 | ||
| 43 | (defconst pmail-attributes | 40 | (defun pmail-make-label (s) |
| 44 | (cons 'pmail-keywords | 41 | (intern (downcase s) pmail-label-obarray)) |
| 45 | (mapcar (function (lambda (s) (intern s pmail-label-obarray))) | ||
| 46 | '("deleted" "answered" "filed" "forwarded" "unseen" "edited" | ||
| 47 | "resent")))) | ||
| 48 | |||
| 49 | (defconst pmail-deleted-label (intern "deleted" pmail-label-obarray)) | ||
| 50 | |||
| 51 | ;; Named list of symbols representing valid message keywords in PMAIL. | ||
| 52 | |||
| 53 | (defvar pmail-keywords) | ||
| 54 | 42 | ||
| 55 | ;;;###autoload | 43 | ;;;###autoload |
| 56 | (defun pmail-add-label (string) | 44 | (defun pmail-add-label (string) |
| 57 | "Add LABEL to labels associated with current PMAIL message. | 45 | "Add LABEL to labels associated with current PMAIL message. |
| 58 | Completion is performed over known labels when reading." | 46 | Performs completion over known labels when reading." |
| 59 | (interactive (list (pmail-read-label "Add label"))) | 47 | (interactive (list (pmail-read-label "Add label"))) |
| 60 | (pmail-set-label string t)) | 48 | (pmail-set-label string t)) |
| 61 | 49 | ||
| 62 | ;;;###autoload | 50 | ;;;###autoload |
| 63 | (defun pmail-kill-label (string) | 51 | (defun pmail-kill-label (string) |
| 64 | "Remove LABEL from labels associated with current PMAIL message. | 52 | "Remove LABEL from labels associated with current PMAIL message. |
| 65 | Completion is performed over known labels when reading." | 53 | Performs completion over known labels when reading." |
| 66 | (interactive (list (pmail-read-label "Remove label"))) | 54 | (interactive (list (pmail-read-label "Remove label"))) |
| 67 | (pmail-set-label string nil)) | 55 | (pmail-set-label string nil)) |
| 68 | 56 | ||
| 69 | ;;;###autoload | 57 | ;; Last individual label specified to a or k. |
| 70 | (defun pmail-read-label (prompt) | 58 | (defvar pmail-last-label nil) |
| 71 | (with-current-buffer pmail-buffer | ||
| 72 | (if (not pmail-keywords) (pmail-parse-file-keywords)) | ||
| 73 | (let ((result | ||
| 74 | (completing-read (concat prompt | ||
| 75 | (if pmail-last-label | ||
| 76 | (concat " (default " | ||
| 77 | (symbol-name pmail-last-label) | ||
| 78 | "): ") | ||
| 79 | ": ")) | ||
| 80 | pmail-label-obarray | ||
| 81 | nil | ||
| 82 | nil))) | ||
| 83 | (if (string= result "") | ||
| 84 | pmail-last-label | ||
| 85 | (setq pmail-last-label (pmail-make-label result t)))))) | ||
| 86 | 59 | ||
| 87 | (declare-function pmail-maybe-set-message-counters "pmail" ()) | 60 | ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l. |
| 88 | (declare-function pmail-display-labels "pmail" ()) | 61 | (defvar pmail-last-multi-labels nil) |
| 89 | (declare-function pmail-msgbeg "pmail" (n)) | ||
| 90 | (declare-function pmail-set-message-deleted-p "pmail" (n state)) | ||
| 91 | (declare-function pmail-message-labels-p "pmail" (msg labels)) | ||
| 92 | (declare-function pmail-show-message "pmail" (&optional n no-summary)) | ||
| 93 | (declare-function mail-comma-list-regexp "mail-utils" (labels)) | ||
| 94 | (declare-function mail-parse-comma-list "mail-utils.el" ()) | ||
| 95 | 62 | ||
| 96 | (defun pmail-set-label (l state &optional n) | 63 | ;;;###autoload |
| 64 | (defun pmail-read-label (prompt) | ||
| 65 | (let ((result | ||
| 66 | (completing-read (concat prompt | ||
| 67 | (if pmail-last-label | ||
| 68 | (concat " (default " | ||
| 69 | (symbol-name pmail-last-label) | ||
| 70 | "): ") | ||
| 71 | ": ")) | ||
| 72 | pmail-label-obarray | ||
| 73 | nil | ||
| 74 | nil))) | ||
| 75 | (if (string= result "") | ||
| 76 | pmail-last-label | ||
| 77 | (setq pmail-last-label (pmail-make-label result))))) | ||
| 78 | |||
| 79 | (defun pmail-set-label (label state &optional msg) | ||
| 80 | "Set LABEL as present or absent according to STATE in message MSG." | ||
| 97 | (with-current-buffer pmail-buffer | 81 | (with-current-buffer pmail-buffer |
| 98 | (pmail-maybe-set-message-counters) | 82 | (pmail-maybe-set-message-counters) |
| 99 | (if (not n) (setq n pmail-current-message)) | 83 | (if (not msg) (setq msg pmail-current-message)) |
| 100 | (aset pmail-summary-vector (1- n) nil) | 84 | ;; Force recalculation of summary for this message. |
| 101 | (let* ((attribute (pmail-attribute-p l)) | 85 | (aset pmail-summary-vector (1- msg) nil) |
| 102 | (keyword (and (not attribute) | 86 | (let (attr-index) |
| 103 | (or (pmail-keyword-p l) | 87 | ;; Is this label an attribute? |
| 104 | (pmail-install-keyword l)))) | 88 | (dotimes (i (length pmail-attr-array)) |
| 105 | (label (or attribute keyword))) | 89 | (if (string= (cadr (aref pmail-attr-array i)) label) |
| 106 | (if label | 90 | (setq attr-index i))) |
| 107 | (let ((omax (- (buffer-size) (point-max))) | 91 | (if attr-index |
| 108 | (omin (- (buffer-size) (point-min))) | 92 | ;; If so, set it as an attribute. |
| 109 | (buffer-read-only nil) | 93 | (pmail-set-attribute attr-index state msg) |
| 110 | (case-fold-search t)) | 94 | ;; Is this keyword already present in msg's keyword list? |
| 111 | (unwind-protect | 95 | (let* ((header (pmail-get-header pmail-keyword-header msg)) |
| 112 | (save-excursion | 96 | (regexp (concat ", " (regexp-quote (symbol-name label)) ",")) |
| 113 | (widen) | 97 | (present (string-match regexp (concat ", " header ",")))) |
| 114 | (goto-char (pmail-msgbeg n)) | 98 | ;; If current state is not correct, |
| 115 | (forward-line 1) | 99 | (unless (eq present state) |
| 116 | (if (not (looking-at "[01],")) | 100 | ;; either add it or delete it. |
| 117 | nil | 101 | (pmail-set-header |
| 118 | (let ((start (1+ (point))) | 102 | pmail-keyword-header msg |
| 119 | (bound)) | 103 | (if state |
| 120 | (narrow-to-region (point) (progn (end-of-line) (point))) | 104 | ;; Add this keyword at the end. |
| 121 | (setq bound (point-max)) | 105 | (if (and header (not (string= header ""))) |
| 122 | (search-backward ",," nil t) | 106 | (concat header ", " (symbol-name label)) |
| 123 | (if attribute | 107 | (symbol-name label)) |
| 124 | (setq bound (1+ (point))) | 108 | ;; Delete this keyword. |
| 125 | (setq start (1+ (point)))) | 109 | (let ((before (substring header 0 |
| 126 | (goto-char start) | 110 | (max 0 (- (match-beginning 0) 2)))) |
| 127 | ; (while (re-search-forward "[ \t]*,[ \t]*" nil t) | 111 | (after (substring header |
| 128 | ; (replace-match ",")) | 112 | (min (length header) |
| 129 | ; (goto-char start) | 113 | (- (match-end 0) 1))))) |
| 130 | (if (re-search-forward | 114 | (cond ((string= before "") |
| 131 | (concat ", " (pmail-quote-label-name label) ",") | 115 | after) |
| 132 | bound | 116 | ((string= after "") |
| 133 | 'move) | 117 | before) |
| 134 | (if (not state) (replace-match ",")) | 118 | (t (concat before ", " after))))))))) |
| 135 | (if state (insert " " (symbol-name label) ","))) | 119 | (if (= msg pmail-current-message) |
| 136 | (if (eq label pmail-deleted-label) | 120 | (pmail-display-labels))))) |
| 137 | (pmail-set-message-deleted-p n state))))) | ||
| 138 | (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)) | ||
| 139 | (if (= n pmail-current-message) (pmail-display-labels)))))))) | ||
| 140 | |||
| 141 | ;; Commented functions aren't used by PMAIL but might be nice for user | ||
| 142 | ;; packages that do stuff with PMAIL. Note that pmail-message-labels-p | ||
| 143 | ;; is in pmail.el now. | ||
| 144 | |||
| 145 | ;(defun pmail-message-label-p (label &optional n) | ||
| 146 | ; "Returns symbol if LABEL (attribute or keyword) on NTH or current message." | ||
| 147 | ; (pmail-message-labels-p (or n pmail-current-message) (regexp-quote label))) | ||
| 148 | |||
| 149 | ;(defun pmail-parse-message-labels (&optional n) | ||
| 150 | ; "Returns labels associated with NTH or current PMAIL message. | ||
| 151 | ;The result is a list of two lists of strings. The first is the | ||
| 152 | ;message attributes and the second is the message keywords." | ||
| 153 | ; (let (atts keys) | ||
| 154 | ; (save-restriction | ||
| 155 | ; (widen) | ||
| 156 | ; (goto-char (pmail-msgbeg (or n pmail-current-message))) | ||
| 157 | ; (forward-line 1) | ||
| 158 | ; (or (looking-at "[01],") (error "Malformed label line")) | ||
| 159 | ; (forward-char 2) | ||
| 160 | ; (while (looking-at "[ \t]*\\([^ \t\n,]+\\),") | ||
| 161 | ; (setq atts (cons (buffer-substring (match-beginning 1) (match-end 1)) | ||
| 162 | ; atts)) | ||
| 163 | ; (goto-char (match-end 0))) | ||
| 164 | ; (or (looking-at ",") (error "Malformed label line")) | ||
| 165 | ; (forward-char 1) | ||
| 166 | ; (while (looking-at "[ \t]*\\([^ \t\n,]+\\),") | ||
| 167 | ; (setq keys (cons (buffer-substring (match-beginning 1) (match-end 1)) | ||
| 168 | ; keys)) | ||
| 169 | ; (goto-char (match-end 0))) | ||
| 170 | ; (or (looking-at "[ \t]*$") (error "Malformed label line")) | ||
| 171 | ; (list (nreverse atts) (nreverse keys))))) | ||
| 172 | |||
| 173 | (defun pmail-attribute-p (s) | ||
| 174 | (let ((symbol (pmail-make-label s))) | ||
| 175 | (if (memq symbol (cdr pmail-attributes)) symbol))) | ||
| 176 | |||
| 177 | (defun pmail-keyword-p (s) | ||
| 178 | (let ((symbol (pmail-make-label s))) | ||
| 179 | (if (memq symbol (cdr (pmail-keywords))) symbol))) | ||
| 180 | |||
| 181 | (defun pmail-make-label (s &optional forcep) | ||
| 182 | (cond ((symbolp s) s) | ||
| 183 | (forcep (intern (downcase s) pmail-label-obarray)) | ||
| 184 | (t (intern-soft (downcase s) pmail-label-obarray)))) | ||
| 185 | |||
| 186 | (defun pmail-force-make-label (s) | ||
| 187 | (intern (downcase s) pmail-label-obarray)) | ||
| 188 | |||
| 189 | (defun pmail-quote-label-name (label) | ||
| 190 | (regexp-quote (symbol-name (pmail-make-label label t)))) | ||
| 191 | 121 | ||
| 192 | ;; Motion on messages with keywords. | 122 | ;; Motion on messages with keywords. |
| 193 | 123 | ||
| @@ -200,6 +130,8 @@ With prefix argument N moves backward N messages with these labels." | |||
| 200 | (interactive "p\nsMove to previous msg with labels: ") | 130 | (interactive "p\nsMove to previous msg with labels: ") |
| 201 | (pmail-next-labeled-message (- n) labels)) | 131 | (pmail-next-labeled-message (- n) labels)) |
| 202 | 132 | ||
| 133 | (declare-function mail-comma-list-regexp "mail-utils" (labels)) | ||
| 134 | |||
| 203 | ;;;###autoload | 135 | ;;;###autoload |
| 204 | (defun pmail-next-labeled-message (n labels) | 136 | (defun pmail-next-labeled-message (n labels) |
| 205 | "Show next message with one of the labels LABELS. | 137 | "Show next message with one of the labels LABELS. |
| @@ -219,72 +151,19 @@ With prefix argument N moves forward N messages with these labels." | |||
| 219 | (regexp (concat ", ?\\(" | 151 | (regexp (concat ", ?\\(" |
| 220 | (mail-comma-list-regexp labels) | 152 | (mail-comma-list-regexp labels) |
| 221 | "\\),"))) | 153 | "\\),"))) |
| 222 | (save-restriction | 154 | (while (and (> n 0) (< current pmail-total-messages)) |
| 223 | (widen) | 155 | (setq current (1+ current)) |
| 224 | (while (and (> n 0) (< current pmail-total-messages)) | 156 | (if (string-match regexp (pmail-get-labels current)) |
| 225 | (setq current (1+ current)) | 157 | (setq lastwin current n (1- n)))) |
| 226 | (if (pmail-message-labels-p current regexp) | 158 | (while (and (< n 0) (> current 1)) |
| 227 | (setq lastwin current n (1- n)))) | 159 | (setq current (1- current)) |
| 228 | (while (and (< n 0) (> current 1)) | 160 | (if (string-match regexp (pmail-get-labels current)) |
| 229 | (setq current (1- current)) | 161 | (setq lastwin current n (1+ n)))) |
| 230 | (if (pmail-message-labels-p current regexp) | ||
| 231 | (setq lastwin current n (1+ n))))) | ||
| 232 | (pmail-show-message lastwin) | ||
| 233 | (if (< n 0) | 162 | (if (< n 0) |
| 234 | (message "No previous message with labels %s" labels)) | 163 | (error "No previous message with labels %s" labels) |
| 235 | (if (> n 0) | 164 | (if (> n 0) |
| 236 | (message "No following message with labels %s" labels)))) | 165 | (error "No following message with labels %s" labels) |
| 237 | 166 | (pmail-show-message lastwin))))) | |
| 238 | ;;; Manipulate the file's Labels option. | ||
| 239 | |||
| 240 | ;; Return a list of symbols for all | ||
| 241 | ;; the keywords (labels) recorded in this file's Labels option. | ||
| 242 | (defun pmail-keywords () | ||
| 243 | (or pmail-keywords (pmail-parse-file-keywords))) | ||
| 244 | |||
| 245 | ;; Set pmail-keywords to a list of symbols for all | ||
| 246 | ;; the keywords (labels) recorded in this file's Labels option. | ||
| 247 | (defun pmail-parse-file-keywords () | ||
| 248 | (save-restriction | ||
| 249 | (save-excursion | ||
| 250 | (widen) | ||
| 251 | (goto-char 1) | ||
| 252 | (setq pmail-keywords | ||
| 253 | (if (search-forward "\nLabels:" (pmail-msgbeg 1) t) | ||
| 254 | (progn | ||
| 255 | (narrow-to-region (point) (progn (end-of-line) (point))) | ||
| 256 | (goto-char (point-min)) | ||
| 257 | (cons 'pmail-keywords | ||
| 258 | (mapcar 'pmail-force-make-label | ||
| 259 | (mail-parse-comma-list))))))))) | ||
| 260 | |||
| 261 | ;; Add WORD to the list in the file's Labels option. | ||
| 262 | ;; Any keyword used for the first time needs this done. | ||
| 263 | (defun pmail-install-keyword (word) | ||
| 264 | (let ((keyword (pmail-make-label word t)) | ||
| 265 | (keywords (pmail-keywords))) | ||
| 266 | (if (not (or (pmail-attribute-p keyword) | ||
| 267 | (pmail-keyword-p keyword))) | ||
| 268 | (let ((omin (- (buffer-size) (point-min))) | ||
| 269 | (omax (- (buffer-size) (point-max)))) | ||
| 270 | (unwind-protect | ||
| 271 | (save-excursion | ||
| 272 | (widen) | ||
| 273 | (goto-char 1) | ||
| 274 | (let ((case-fold-search t) | ||
| 275 | (buffer-read-only nil)) | ||
| 276 | (or (search-forward "\nLabels:" nil t) | ||
| 277 | (progn | ||
| 278 | (end-of-line) | ||
| 279 | (insert "\nLabels:"))) | ||
| 280 | (delete-region (point) (progn (end-of-line) (point))) | ||
| 281 | (setcdr keywords (cons keyword (cdr keywords))) | ||
| 282 | (while (setq keywords (cdr keywords)) | ||
| 283 | (insert (symbol-name (car keywords)) ",")) | ||
| 284 | (delete-char -1))) | ||
| 285 | (narrow-to-region (- (buffer-size) omin) | ||
| 286 | (- (buffer-size) omax))))) | ||
| 287 | keyword)) | ||
| 288 | 167 | ||
| 289 | (provide 'pmailkwd) | 168 | (provide 'pmailkwd) |
| 290 | 169 | ||