* mu4e-mark: fix thread-based marking for marks with targets

This commit is contained in:
djcb 2012-10-13 22:13:17 +03:00
parent d5ebb74f6b
commit f0caaa6e7c
1 changed files with 24 additions and 25 deletions

View File

@ -118,7 +118,7 @@ The following marks are available, and the corresponding props:
(trash `("d" . ,target)) (trash `("d" . ,target))
(unflag '("-" . "unflag")) (unflag '("-" . "unflag"))
(unmark '(" " . nil)) (unmark '(" " . nil))
(unread '("?" . "unread")) (unread '("?" . "unread"))
(otherwise (mu4e-error "Invalid mark %S" mark)))) (otherwise (mu4e-error "Invalid mark %S" mark))))
(markkar (car markcell)) (markkar (car markcell))
(target (cdr markcell))) (target (cdr markcell)))
@ -153,7 +153,7 @@ The following marks are available, and the corresponding props:
the region, for moving to maildir TARGET. If target is not the region, for moving to maildir TARGET. If target is not
provided, function asks for it." provided, function asks for it."
(interactive) (interactive)
(mu4e-message-at-point) ;; raises error if there is none ;; (mu4e-message-at-point) ;; raises error if there is none
(let* ((target (or target (mu4e-ask-maildir "Move message to: "))) (let* ((target (or target (mu4e-ask-maildir "Move message to: ")))
(target (if (string= (substring target 0 1) "/") (target (if (string= (substring target 0 1) "/")
target target
@ -165,28 +165,29 @@ provided, function asks for it."
(mu4e~proc-mkdir fulltarget))) (mu4e~proc-mkdir fulltarget)))
target))) target)))
(defun mu4e~mark-get-target (mark &optional target)
"Get the target for MARK, if it is a mark that has a target;
otherwise return nil."
(case mark
(refile (mu4e-get-refile-folder (mu4e-message-at-point)))
(move (mu4e~mark-get-move-target target))
(trash (mu4e-get-trash-folder (mu4e-message-at-point)))))
(defun mu4e-mark-set (mark &optional target) (defun mu4e-mark-set (mark &optional target)
"Mark the header at point, or, if region is active, mark all "Mark the header at point, or, if region is active, mark all
headers in the region. Optionally, provide TARGET (for moves)." headers in the region. Optionally, provide TARGET (for moves)."
(let ((get-target (if (not (use-region-p))
(lambda (target) ;; single message
(or target ;; ask or check the target if it's a move (mu4e-mark-at-point mark (or target (mu4e~mark-get-target mark target)))
(case mark ;; mark all messages in the region.
(refile (mu4e-get-refile-folder (mu4e-message-at-point))) (save-excursion
(move (mu4e~mark-get-move-target target)) (let ((cant-go-further) (eor (region-end)))
(trash (mu4e-get-trash-folder (mu4e-message-at-point)))))))) (goto-char (region-beginning))
(if (not (use-region-p)) (while (and (<= (point) eor) (not cant-go-further))
;; single message (mu4e-mark-at-point mark (or target (mu4e~mark-get-target mark target)))
(mu4e-mark-at-point mark (funcall get-target target)) (setq cant-go-further (not (mu4e-headers-next))))))))
;; mark all messages in the region.
(save-excursion
(let ((cant-go-further) (eor (region-end)))
(goto-char (region-beginning))
(while (and (<= (point) eor) (not cant-go-further))
(mu4e-mark-at-point mark (funcall get-target target))
(setq cant-go-further (not (mu4e-headers-next)))))))))
(defun mu4e-mark-restore (docid) (defun mu4e-mark-restore (docid)
"Restore the visual mark for the message with DOCID." "Restore the visual mark for the message with DOCID."
(let ((markcell (gethash docid mu4e~mark-map))) (let ((markcell (gethash docid mu4e~mark-map)))
@ -198,7 +199,7 @@ headers in the region. Optionally, provide TARGET (for moves)."
(defun mu4e~mark-get-markpair (prompt &optional allow-something) (defun mu4e~mark-get-markpair (prompt &optional allow-something)
"Ask user for a mark; return (MARK . TARGET). If ALLOW-SOMETHING "Ask user for a mark; return (MARK . TARGET). If ALLOW-SOMETHING
is non-nil, allow the 'something' pseudo mark as well." is non-nil, allow the 'something' pseudo mark as well."
(let* ((marks '( ("refile" . refile) (let* ((marks '( ("refile" . refile)
("move" . move) ("move" . move)
("dtrash" . trash) ("dtrash" . trash)
("Delete" . delete) ("Delete" . delete)
@ -212,9 +213,7 @@ is non-nil, allow the 'something' pseudo mark as well."
(append marks (list '("something" . something))) (append marks (list '("something" . something)))
marks)) marks))
(mark (mu4e-read-option prompt marks)) (mark (mu4e-read-option prompt marks))
(target (target (mu4e~mark-get-target mark)))
(when (eq mark 'move)
(mu4e-ask-maildir-check-exists "Move message to: "))))
(cons mark target))) (cons mark target)))
@ -297,7 +296,7 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
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?"
(when (gethash docid mu4e~mark-map) t)) (when (gethash docid mu4e~mark-map) t))