123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- (require 'rmail)
- (defvar rmail-label-obarray (make-vector 47 0)
- "Obarray of labels used by Rmail.
- `rmail-read-label' uses this to offer completion.")
- (mapc (lambda (s) (intern (cadr s) rmail-label-obarray))
- rmail-attr-array)
- (defun rmail-make-label (s)
- "Intern string S as a downcased symbol in `rmail-label-obarray'."
- (intern (downcase s) rmail-label-obarray))
- (defun rmail-add-label (label)
- "Add LABEL to labels associated with current RMAIL message.
- Completes (see `rmail-read-label') over known labels when reading.
- LABEL may be a symbol or string. Only one label is allowed."
- (interactive (list (rmail-read-label "Add label")))
- (rmail-set-label label t))
- (defun rmail-kill-label (label)
- "Remove LABEL from labels associated with current RMAIL message.
- Completes (see `rmail-read-label') over known labels when reading.
- LABEL may be a symbol or string. Only one label is allowed."
- (interactive (list (rmail-read-label "Remove label")))
- (rmail-set-label label nil))
- (defun rmail-read-label (prompt)
- "Read a label with completion, prompting with PROMPT.
- Completions are chosen from `rmail-label-obarray'. The default
- is `rmail-last-label', if that is non-nil. Updates `rmail-last-label'
- according to the choice made, and returns a symbol."
- (let* ((old nil)
- (result
- (progn
-
-
- (or (eq major-mode 'rmail-summary-mode)
- (rmail-summary-exists)
- (and (setq old (rmail-get-keywords))
- (mapc 'rmail-make-label (split-string old ", "))))
- (completing-read (concat prompt
- (if rmail-last-label
- (concat " (default "
- (symbol-name rmail-last-label)
- "): ")
- ": "))
- rmail-label-obarray
- nil
- nil))))
- (if (string= result "")
- rmail-last-label
- (setq rmail-last-label (rmail-make-label result)))))
- (declare-function rmail-summary-update-line "rmailsum" (n))
- (defun rmail-set-label (label state &optional msg)
- "Set LABEL as present or absent according to STATE in message MSG.
- LABEL may be a symbol or string."
- (or (stringp label) (setq label (symbol-name label)))
- (if (string-match "," label)
- (error "More than one label specified"))
- (with-current-buffer rmail-buffer
- (rmail-maybe-set-message-counters)
- (if (zerop (or msg (setq msg rmail-current-message)))
- (error "No message"))
-
- (aset rmail-summary-vector (1- msg) nil)
- (let (attr-index)
-
- (dotimes (i (length rmail-attr-array))
- (if (string= (cadr (aref rmail-attr-array i)) label)
- (setq attr-index i)))
- (if attr-index
-
- (rmail-set-attribute attr-index state msg)
-
- (let* ((header (rmail-get-keywords msg))
- (regexp (concat ", " (regexp-quote label) ","))
- (present (not (null
- (string-match regexp (concat ", " header ","))))))
-
- (unless (eq present state)
-
- (rmail-set-header
- rmail-keyword-header msg
- (if state
-
- (if (and header (not (string= header "")))
- (concat header ", " label)
- label)
-
- (let ((before (substring header 0
- (max 0 (- (match-beginning 0) 2))))
- (after (substring header
- (min (length header)
- (- (match-end 0) 1)))))
- (cond ((string= before "")
-
- (unless (string= after "")
- after))
- ((string= after "")
- before)
- (t (concat before ", " after))))))))))
- (if (rmail-summary-exists)
- (rmail-select-summary (rmail-summary-update-line msg)))
- (if (= msg rmail-current-message)
- (rmail-display-labels))))
- (defun rmail-previous-labeled-message (n labels)
- "Show previous message with one of the labels LABELS.
- LABELS should be a comma-separated list of label names.
- If LABELS is empty, the last set of labels specified is used.
- With prefix argument N moves backward N messages with these labels."
- (interactive "p\nsMove to previous msg with labels: ")
- (rmail-next-labeled-message (- n) labels))
- (declare-function mail-comma-list-regexp "mail-utils" (labels))
- (defun rmail-next-labeled-message (n labels)
- "Show next message with one of the labels LABELS.
- LABELS should be a comma-separated list of label names.
- If LABELS is empty, the last set of labels specified is used.
- With prefix argument N moves forward N messages with these labels."
-
- (interactive "p\nsMove to next msg with labels: ")
- (if (string= labels "")
- (setq labels rmail-last-multi-labels))
- (or labels
- (error "No labels to find have been specified previously"))
- (set-buffer rmail-buffer)
- (setq rmail-last-multi-labels labels)
- (rmail-maybe-set-message-counters)
- (let ((lastwin rmail-current-message)
- (current rmail-current-message)
- (regexp (concat " \\("
- (mail-comma-list-regexp labels)
- "\\)\\(,\\|\\'\\)")))
- (while (and (> n 0) (< current rmail-total-messages))
- (setq current (1+ current))
- (if (string-match regexp (rmail-get-labels current))
- (setq lastwin current n (1- n))))
- (while (and (< n 0) (> current 1))
- (setq current (1- current))
- (if (string-match regexp (rmail-get-labels current))
- (setq lastwin current n (1+ n))))
- (if (< n 0)
- (error "No previous message with labels %s" labels)
- (if (> n 0)
- (error "No following message with labels %s" labels)
- (rmail-show-message-1 lastwin)))))
- (provide 'rmailkwd)
|