mu4e-mark: add confirmation for mu4e-mark-unmark-all

Fixes #1234
This commit is contained in:
Dirk-Jan C. Binnema 2023-01-19 00:36:53 +02:00
parent 3dd7cf80d3
commit 87187d15d6
1 changed files with 20 additions and 17 deletions

View File

@ -99,8 +99,8 @@ is the target directory (for \"move\")")
(defun mu4e--mark-find-headers-buffer () (defun mu4e--mark-find-headers-buffer ()
"Find the headers buffer, if any." "Find the headers buffer, if any."
(seq-find (lambda (_) (seq-find (lambda (_)
(mu4e-current-buffer-type-p 'headers)) (mu4e-current-buffer-type-p 'headers))
(buffer-list))) (buffer-list)))
(defmacro mu4e--mark-in-context (&rest body) (defmacro mu4e--mark-in-context (&rest body)
"Evaluate BODY in the context of the headers buffer. "Evaluate BODY in the context of the headers buffer.
@ -150,7 +150,7 @@ The current buffer must be either a headers or view buffer."
:prompt "dtrash" :prompt "dtrash"
:dyn-target (lambda (target msg) (mu4e-get-trash-folder msg)) :dyn-target (lambda (target msg) (mu4e-get-trash-folder msg))
:action (lambda (docid msg target) :action (lambda (docid msg target)
(mu4e--server-move docid (mu4e--server-move docid
(mu4e--mark-check-target target) "+T-N"))) (mu4e--mark-check-target target) "+T-N")))
(unflag (unflag
:char ("-" . "") :char ("-" . "")
@ -259,7 +259,7 @@ The following marks are available, and the corresponding props:
(remhash docid mu4e--mark-map) (remhash docid mu4e--mark-map)
;; remove possible mark overlays ;; remove possible mark overlays
(remove-overlays (line-beginning-position) (line-end-position) (remove-overlays (line-beginning-position) (line-end-position)
'mu4e-mark t) 'mu4e-mark t)
;; now, let's set a mark (unless we were unmarking) ;; now, let's set a mark (unless we were unmarking)
(unless (eql mark 'unmark) (unless (eql mark 'unmark)
(puthash docid (cons mark target) mu4e--mark-map) (puthash docid (cons mark target) mu4e--mark-map)
@ -385,7 +385,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 "P") (interactive "P")
(mu4e--mark-in-context (mu4e--mark-in-context
(let* ((marknum (hash-table-count mu4e--mark-map)) (let* ((marknum (mu4e-mark-marks-num))
(prompt (format "Are you sure you want to execute %d mark%s?" (prompt (format "Are you sure you want to execute %d mark%s?"
marknum (if (> marknum 1) "s" "")))) marknum (if (> marknum 1) "s" ""))))
(if (zerop marknum) (if (zerop marknum)
@ -409,29 +409,32 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
docid msg target)) docid msg target))
(mu4e-error "Unrecognized mark %S" mark)))) (mu4e-error "Unrecognized mark %S" mark))))
mu4e--mark-map)) mu4e--mark-map))
(mu4e-mark-unmark-all) (mu4e-mark-unmark-all 'no-confirm)
(message nil))))) (message nil)))))
(defun mu4e-mark-unmark-all () (defun mu4e-mark-unmark-all (&optional no-confirmation)
"Unmark all marked messages." "Unmark all marked messages."
(interactive) (interactive)
(mu4e--mark-in-context (mu4e--mark-in-context
(when (or (null mu4e--mark-map) (zerop (hash-table-count mu4e--mark-map))) (when (zerop (mu4e-mark-marks-num))
(mu4e-warn "Nothing is marked")) (mu4e-warn "Nothing is marked"))
(maphash (let* ((marknum (hash-table-count mu4e--mark-map))
(lambda (docid _val) (prompt (format "Are you sure you want to unmark %d message%s?"
(save-excursion marknum (if (> marknum 1) "s" ""))))
(when (mu4e~headers-goto-docid docid) (when (or no-confirmation (y-or-n-p prompt))
(mu4e-mark-set 'unmark)))) (maphash
mu4e--mark-map) (lambda (docid _val)
;; in any case, clear the marks map (save-excursion
(mu4e--mark-clear))) (when (mu4e~headers-goto-docid docid)
(mu4e-mark-set 'unmark))))
mu4e--mark-map)
;; in any case, clear the marks map
(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))
(defun mu4e-mark-marks-num () (defun mu4e-mark-marks-num ()
"Return the number of mark-instances in the current buffer." "Return the number of mark-instances in the current buffer."
(mu4e--mark-in-context (mu4e--mark-in-context