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

@ -385,7 +385,7 @@ work well.
If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
(interactive "P")
(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?"
marknum (if (> marknum 1) "s" ""))))
(if (zerop marknum)
@ -409,15 +409,19 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
docid msg target))
(mu4e-error "Unrecognized mark %S" mark))))
mu4e--mark-map))
(mu4e-mark-unmark-all)
(mu4e-mark-unmark-all 'no-confirm)
(message nil)))))
(defun mu4e-mark-unmark-all ()
(defun mu4e-mark-unmark-all (&optional no-confirmation)
"Unmark all marked messages."
(interactive)
(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"))
(let* ((marknum (hash-table-count mu4e--mark-map))
(prompt (format "Are you sure you want to unmark %d message%s?"
marknum (if (> marknum 1) "s" ""))))
(when (or no-confirmation (y-or-n-p prompt))
(maphash
(lambda (docid _val)
(save-excursion
@ -425,13 +429,12 @@ 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?"
(when (gethash docid mu4e--mark-map) t))
(defun mu4e-mark-marks-num ()
"Return the number of mark-instances in the current buffer."
(mu4e--mark-in-context