2009-01-22 17:09:23 +00:00
|
|
|
|
;;; rmailkwd.el --- part of the "RMAIL" mail reader for Emacs
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 1985, 1988, 1994, 2001, 2002, 2003, 2004, 2005, 2006,
|
2010-01-13 08:35:10 +00:00
|
|
|
|
;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
;; Maintainer: FSF
|
|
|
|
|
;; Keywords: mail
|
2010-08-29 16:17:13 +00:00
|
|
|
|
;; Package: rmail
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'rmail)
|
|
|
|
|
|
2009-02-03 04:07:02 +00:00
|
|
|
|
;; Global to all RMAIL buffers. It exists for the sake of completion.
|
|
|
|
|
;; It is better to use strings with the label functions and let them
|
|
|
|
|
;; worry about making the label.
|
|
|
|
|
(defvar rmail-label-obarray (make-vector 47 0)
|
|
|
|
|
"Obarray of labels used by Rmail.
|
|
|
|
|
`rmail-read-label' uses this to offer completion.")
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
2009-02-03 04:07:02 +00:00
|
|
|
|
;; Initialize with the standard labels.
|
|
|
|
|
(mapc (lambda (s) (intern (cadr s) rmail-label-obarray))
|
|
|
|
|
rmail-attr-array)
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
(defun rmail-make-label (s)
|
2009-02-11 04:01:35 +00:00
|
|
|
|
"Intern string S as a downcased symbol in `rmail-label-obarray'."
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(intern (downcase s) rmail-label-obarray))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(defun rmail-add-label (label)
|
2009-01-22 17:09:23 +00:00
|
|
|
|
"Add LABEL to labels associated with current RMAIL message.
|
2009-02-03 04:07:02 +00:00
|
|
|
|
Completes (see `rmail-read-label') over known labels when reading.
|
2009-04-09 16:50:36 +00:00
|
|
|
|
LABEL may be a symbol or string. Only one label is allowed."
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(interactive (list (rmail-read-label "Add label")))
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(rmail-set-label label t))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(defun rmail-kill-label (label)
|
2009-01-22 17:09:23 +00:00
|
|
|
|
"Remove LABEL from labels associated with current RMAIL message.
|
2009-02-03 04:07:02 +00:00
|
|
|
|
Completes (see `rmail-read-label') over known labels when reading.
|
2009-04-09 16:50:36 +00:00
|
|
|
|
LABEL may be a symbol or string. Only one label is allowed."
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(interactive (list (rmail-read-label "Remove label")))
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(rmail-set-label label nil))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun rmail-read-label (prompt)
|
2009-02-03 04:07:02 +00:00
|
|
|
|
"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."
|
2009-02-12 03:28:53 +00:00
|
|
|
|
(let* ((old nil)
|
|
|
|
|
(result
|
|
|
|
|
(progn
|
|
|
|
|
;; If the summary exists, we've already read all the
|
|
|
|
|
;; existing labels. If not, read the ones in this message.
|
|
|
|
|
(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))))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(if (string= result "")
|
|
|
|
|
rmail-last-label
|
|
|
|
|
(setq rmail-last-label (rmail-make-label result)))))
|
|
|
|
|
|
2009-01-29 03:41:38 +00:00
|
|
|
|
(declare-function rmail-summary-update-line "rmailsum" (n))
|
|
|
|
|
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(defun rmail-set-label (label state &optional msg)
|
2009-02-03 04:07:02 +00:00
|
|
|
|
"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)))
|
2009-04-09 16:50:36 +00:00
|
|
|
|
(if (string-match "," label)
|
|
|
|
|
(error "More than one label specified"))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(with-current-buffer rmail-buffer
|
|
|
|
|
(rmail-maybe-set-message-counters)
|
2009-02-11 04:01:35 +00:00
|
|
|
|
(or msg (setq msg rmail-current-message))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
;; Force recalculation of summary for this message.
|
|
|
|
|
(aset rmail-summary-vector (1- msg) nil)
|
|
|
|
|
(let (attr-index)
|
|
|
|
|
;; Is this label an attribute?
|
|
|
|
|
(dotimes (i (length rmail-attr-array))
|
|
|
|
|
(if (string= (cadr (aref rmail-attr-array i)) label)
|
|
|
|
|
(setq attr-index i)))
|
|
|
|
|
(if attr-index
|
|
|
|
|
;; If so, set it as an attribute.
|
|
|
|
|
(rmail-set-attribute attr-index state msg)
|
|
|
|
|
;; Is this keyword already present in msg's keyword list?
|
2009-02-12 06:55:43 +00:00
|
|
|
|
(let* ((header (rmail-get-keywords msg))
|
2009-02-12 07:52:02 +00:00
|
|
|
|
(regexp (concat ", " (regexp-quote label) ","))
|
2009-02-12 07:53:11 +00:00
|
|
|
|
(present (not (null
|
|
|
|
|
(string-match regexp (concat ", " header ","))))))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
;; If current state is not correct,
|
|
|
|
|
(unless (eq present state)
|
|
|
|
|
;; either add it or delete it.
|
|
|
|
|
(rmail-set-header
|
|
|
|
|
rmail-keyword-header msg
|
|
|
|
|
(if state
|
|
|
|
|
;; Add this keyword at the end.
|
|
|
|
|
(if (and header (not (string= header "")))
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(concat header ", " label)
|
|
|
|
|
label)
|
2009-01-22 17:09:23 +00:00
|
|
|
|
;; Delete this keyword.
|
|
|
|
|
(let ((before (substring header 0
|
|
|
|
|
(max 0 (- (match-beginning 0) 2))))
|
|
|
|
|
(after (substring header
|
|
|
|
|
(min (length header)
|
|
|
|
|
(- (match-end 0) 1)))))
|
|
|
|
|
(cond ((string= before "")
|
2009-02-13 03:44:30 +00:00
|
|
|
|
;; If before and after both empty, delete the header.
|
|
|
|
|
(unless (string= after "")
|
|
|
|
|
after))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
((string= after "")
|
|
|
|
|
before)
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(t (concat before ", " after))))))))))
|
|
|
|
|
(if (rmail-summary-exists)
|
2009-02-11 04:01:35 +00:00
|
|
|
|
(rmail-select-summary (rmail-summary-update-line msg)))
|
2009-02-03 04:07:02 +00:00
|
|
|
|
(if (= msg rmail-current-message)
|
|
|
|
|
(rmail-display-labels))))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
;; Motion on messages with keywords.
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(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))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(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."
|
2009-09-10 06:18:23 +00:00
|
|
|
|
;; FIXME show the default in the prompt.
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(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)
|
2009-01-23 19:09:55 +00:00
|
|
|
|
(regexp (concat " \\("
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(mail-comma-list-regexp labels)
|
2009-01-23 19:19:05 +00:00
|
|
|
|
"\\)\\(,\\|\\'\\)")))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
(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)
|
2009-02-13 07:44:18 +00:00
|
|
|
|
(rmail-show-message-1 lastwin)))))
|
2009-01-22 17:09:23 +00:00
|
|
|
|
|
|
|
|
|
(provide 'rmailkwd)
|
|
|
|
|
|
2009-09-10 06:18:23 +00:00
|
|
|
|
;; Local Variables:
|
|
|
|
|
;; generated-autoload-file: "rmail.el"
|
|
|
|
|
;; End:
|
|
|
|
|
|
2009-01-22 17:09:23 +00:00
|
|
|
|
;; arch-tag: 1149979c-8e47-4333-9629-cf3dc887a6a7
|
|
|
|
|
;;; rmailkwd.el ends here
|