mirror of https://github.com/djcb/mu.git
* mu4e: check marks in headers context (fixes issue #200)
This commit is contained in:
parent
7180b30a21
commit
74feeded3b
|
@ -1,6 +1,6 @@
|
|||
;; 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>
|
||||
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
|
@ -82,6 +82,24 @@ where
|
|||
"Clear the marks subsystem."
|
||||
(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)
|
||||
"Mark (or unmark) message at point.
|
||||
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
|
||||
user which one)."
|
||||
(interactive)
|
||||
(mu4e~mark-in-context
|
||||
(let ((markpair))
|
||||
(maphash
|
||||
(lambda (docid val)
|
||||
|
@ -240,7 +259,7 @@ user which one)."
|
|||
(save-excursion
|
||||
(when (mu4e~headers-goto-docid docid)
|
||||
(mu4e-mark-set (car markpair) (cdr markpair)))))))
|
||||
mu4e~mark-map)))
|
||||
mu4e~mark-map))))
|
||||
|
||||
|
||||
(defun mu4e~mark-check-target (target)
|
||||
|
@ -264,6 +283,7 @@ work well.
|
|||
|
||||
If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
||||
(interactive)
|
||||
(mu4e~mark-in-context
|
||||
(let ((marknum (hash-table-count mu4e~mark-map)))
|
||||
(if (zerop marknum)
|
||||
(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)))))
|
||||
mu4e~mark-map))
|
||||
(mu4e-mark-unmark-all)
|
||||
(message nil))))
|
||||
(message nil)))))
|
||||
|
||||
(defun mu4e-mark-unmark-all ()
|
||||
"Unmark all marked messages."
|
||||
(interactive)
|
||||
(mu4e~mark-in-context
|
||||
(when (or (null mu4e~mark-map) (zerop (hash-table-count mu4e~mark-map)))
|
||||
(mu4e-warn "Nothing is marked"))
|
||||
(maphash
|
||||
|
@ -303,7 +324,7 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
|
|||
(mu4e-mark-set 'unmark))))
|
||||
mu4e~mark-map)
|
||||
;; in any case, clear the marks map
|
||||
(mu4e~mark-clear))
|
||||
(mu4e~mark-clear)))
|
||||
|
||||
(defun mu4e-mark-docid-marked-p (docid)
|
||||
"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."
|
||||
(if mu4e~mark-map (hash-table-count mu4e~mark-map) 0))
|
||||
|
||||
|
||||
(defun mu4e-mark-handle-when-leaving ()
|
||||
"If there are any marks in the current buffer, handle those
|
||||
according to the value of `mu4e-headers-leave-behavior'. This
|
||||
function is to be called before any further action (like searching,
|
||||
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))
|
||||
(what mu4e-headers-leave-behavior))
|
||||
(unless (zerop marknum) ;; nothing to do?
|
||||
|
@ -330,7 +353,7 @@ action', return nil means 'don't do anything'"
|
|||
("ignore marks?" . ignore)))))
|
||||
;; we determined what to do... now do it
|
||||
(when (eq what 'apply)
|
||||
(mu4e-mark-execute-all t)))))
|
||||
(mu4e-mark-execute-all t))))))
|
||||
|
||||
|
||||
(provide 'mu4e-mark)
|
||||
|
|
Loading…
Reference in New Issue