* mu4e: check marks in headers context (fixes issue #200)
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
;; mu4e-mark.el -- part of mu4e, the mu mail user agent
|
;; mu4e-mark.el -- part of mu4e, the mu mail user agent
|
||||||
;;
|
;;
|
||||||
;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema
|
;; Copyright (C) 2011-2013 Dirk-Jan C. Binnema
|
||||||
|
|
||||||
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
@ -82,6 +82,24 @@ where
|
|||||||
"Clear the marks subsystem."
|
"Clear the marks subsystem."
|
||||||
(clrhash mu4e~mark-map))
|
(clrhash mu4e~mark-map))
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro mu4e~mark-in-context (&rest body)
|
||||||
|
"Evaluate BODY in the context of the headers buffer in case this
|
||||||
|
is either a headers or view buffer, and "
|
||||||
|
`(cond
|
||||||
|
((eq major-mode 'mu4e-headers-mode) ,@body)
|
||||||
|
((eq major-mode 'mu4e-view-mode)
|
||||||
|
(if (buffer-live-p mu4e~view-headers-buffer)
|
||||||
|
(let* ((msg (mu4e-message-at-point))
|
||||||
|
(docid (mu4e-message-field msg :docid)))
|
||||||
|
(with-current-buffer mu4e~view-headers-buffer
|
||||||
|
(if (mu4e~headers-goto-docid docid)
|
||||||
|
,@body
|
||||||
|
(mu4e-error "cannot find message in headers buffer."))))
|
||||||
|
(mu4e-error "no headers buffer connected to view")))
|
||||||
|
(t (progn (mu4e-message "%S" major-mode) ,@body))))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-mark-at-point (mark &optional target)
|
(defun mu4e-mark-at-point (mark &optional target)
|
||||||
"Mark (or unmark) message at point.
|
"Mark (or unmark) message at point.
|
||||||
MARK specifies the mark-type. For `move'-marks and `trash'-marks
|
MARK specifies the mark-type. For `move'-marks and `trash'-marks
|
||||||
@ -229,6 +247,7 @@ as well."
|
|||||||
If there are such marks, replace them with a _real_ mark (ask the
|
If there are such marks, replace them with a _real_ mark (ask the
|
||||||
user which one)."
|
user which one)."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mu4e~mark-in-context
|
||||||
(let ((markpair))
|
(let ((markpair))
|
||||||
(maphash
|
(maphash
|
||||||
(lambda (docid val)
|
(lambda (docid val)
|
||||||
@ -240,7 +259,7 @@ user which one)."
|
|||||||
(save-excursion
|
(save-excursion
|
||||||
(when (mu4e~headers-goto-docid docid)
|
(when (mu4e~headers-goto-docid docid)
|
||||||
(mu4e-mark-set (car markpair) (cdr markpair)))))))
|
(mu4e-mark-set (car markpair) (cdr markpair)))))))
|
||||||
mu4e~mark-map)))
|
mu4e~mark-map))))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e~mark-check-target (target)
|
(defun mu4e~mark-check-target (target)
|
||||||
@ -264,6 +283,7 @@ work well.
|
|||||||
|
|
||||||
If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mu4e~mark-in-context
|
||||||
(let ((marknum (hash-table-count mu4e~mark-map)))
|
(let ((marknum (hash-table-count mu4e~mark-map)))
|
||||||
(if (zerop marknum)
|
(if (zerop marknum)
|
||||||
(message "Nothing is marked")
|
(message "Nothing is marked")
|
||||||
@ -289,11 +309,12 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
|||||||
(otherwise (mu4e-error "Unrecognized mark %S" mark)))))
|
(otherwise (mu4e-error "Unrecognized mark %S" mark)))))
|
||||||
mu4e~mark-map))
|
mu4e~mark-map))
|
||||||
(mu4e-mark-unmark-all)
|
(mu4e-mark-unmark-all)
|
||||||
(message nil))))
|
(message nil)))))
|
||||||
|
|
||||||
(defun mu4e-mark-unmark-all ()
|
(defun mu4e-mark-unmark-all ()
|
||||||
"Unmark all marked messages."
|
"Unmark all marked messages."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mu4e~mark-in-context
|
||||||
(when (or (null mu4e~mark-map) (zerop (hash-table-count mu4e~mark-map)))
|
(when (or (null mu4e~mark-map) (zerop (hash-table-count mu4e~mark-map)))
|
||||||
(mu4e-warn "Nothing is marked"))
|
(mu4e-warn "Nothing is marked"))
|
||||||
(maphash
|
(maphash
|
||||||
@ -303,7 +324,7 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
|||||||
(mu4e-mark-set 'unmark))))
|
(mu4e-mark-set 'unmark))))
|
||||||
mu4e~mark-map)
|
mu4e~mark-map)
|
||||||
;; in any case, clear the marks map
|
;; in any case, clear the marks map
|
||||||
(mu4e~mark-clear))
|
(mu4e~mark-clear)))
|
||||||
|
|
||||||
(defun mu4e-mark-docid-marked-p (docid)
|
(defun mu4e-mark-docid-marked-p (docid)
|
||||||
"Is the given docid marked?"
|
"Is the given docid marked?"
|
||||||
@ -314,12 +335,14 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
|||||||
"Return the number of marks in the current buffer."
|
"Return the number of marks in the current buffer."
|
||||||
(if mu4e~mark-map (hash-table-count mu4e~mark-map) 0))
|
(if mu4e~mark-map (hash-table-count mu4e~mark-map) 0))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-mark-handle-when-leaving ()
|
(defun mu4e-mark-handle-when-leaving ()
|
||||||
"If there are any marks in the current buffer, handle those
|
"If there are any marks in the current buffer, handle those
|
||||||
according to the value of `mu4e-headers-leave-behavior'. This
|
according to the value of `mu4e-headers-leave-behavior'. This
|
||||||
function is to be called before any further action (like searching,
|
function is to be called before any further action (like searching,
|
||||||
quiting the buffer) is taken; returning t means 'take the following
|
quiting the buffer) is taken; returning t means 'take the following
|
||||||
action', return nil means 'don't do anything'"
|
action', return nil means 'don't do anything'."
|
||||||
|
(mu4e~mark-in-context
|
||||||
(let ((marknum (mu4e-mark-marks-num))
|
(let ((marknum (mu4e-mark-marks-num))
|
||||||
(what mu4e-headers-leave-behavior))
|
(what mu4e-headers-leave-behavior))
|
||||||
(unless (zerop marknum) ;; nothing to do?
|
(unless (zerop marknum) ;; nothing to do?
|
||||||
@ -330,7 +353,7 @@ action', return nil means 'don't do anything'"
|
|||||||
("ignore marks?" . ignore)))))
|
("ignore marks?" . ignore)))))
|
||||||
;; we determined what to do... now do it
|
;; we determined what to do... now do it
|
||||||
(when (eq what 'apply)
|
(when (eq what 'apply)
|
||||||
(mu4e-mark-execute-all t)))))
|
(mu4e-mark-execute-all t))))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'mu4e-mark)
|
(provide 'mu4e-mark)
|
||||||
|
|||||||
Reference in New Issue
Block a user