mu4e: do not allow marking folded message

Safety first!
This commit is contained in:
Dirk-Jan C. Binnema 2023-04-23 12:04:26 +03:00
parent 0fdc64ad1a
commit 50d559deb4
2 changed files with 21 additions and 28 deletions

View File

@ -1588,6 +1588,8 @@ argument."
"Set mark MARK on the message at point or on all messages in the "Set mark MARK on the message at point or on all messages in the
region if there is a region, then move to the next message." region if there is a region, then move to the next message."
(interactive) (interactive)
(when (mu4e-thread-message-folded-p)
(mu4e-warn "Cannot mark folded messages"))
(mu4e-mark-set mark) (mu4e-mark-set mark)
(when mu4e-headers-advance-after-mark (mu4e-headers-next))) (when mu4e-headers-advance-after-mark (mu4e-headers-next)))

View File

@ -20,30 +20,26 @@
;;; Commentary: ;;; Commentary:
;; mu4e-thread.el is a library that allows to fold and unfold threads ;; mu4e-thread.el is a library that allows to fold and unfold threads in mu4e
;; in mu4e headers mode. Folding works by creating an overlay over ;; headers mode. Folding works by creating an overlay over thread children that
;; thread children that display a summary (number of hidden messages ;; display a summary (number of hidden messages and possibly number of unread
;; and possibly number of unread messages). Folding is perform just in ;; messages).
;; time such that it is quite fast to fold/unfold threads. When a
;; thread has unread messages, the folding stops at the first unread ;; Folding is performed just-in-time such that it is quite fast to
;; message unless `mu4e-thread-fold-unread` has been set to t. ;; fold/unfold threads. When a thread has unread messages, the folding stops at
;; Similarly, when a thread has marked messages, the folding stops at ;; the first unread message unless `mu4e-thread-fold-unread` has been set to t.
;; the first marked message and it is strongly advised to disable marking
;; on folded messages as explained in usage example. ;; Similarly, when a thread has marked messages, the folding stops at the first
;; marked message.
;;; Usage example: ;;; Usage example:
;; ;;
;; This enforces folding after a new search ;; This enforces folding after a new search
;; (add-hook 'mu4e-headers-found-hook #'mu4e-thread-fold-apply-all) ;; (add-hook 'mu4e-headers-found-hook #'mu4e-thread-fold-apply-all)
;;
;; This prevents marking messages when folded
;; (advice-add #'mu4e-headers-mark-and-next :around #'mu4e-thread/mark-and-next)
;;; Code: ;;; Code:
(require 'mu4e-vars) (require 'mu4e-vars)
(require 'mu4e-message) (require 'mu4e-message)
(require 'mu4e-mark) (require 'mu4e-mark)
@ -64,10 +60,10 @@ hide the single child."
"Face for the information line of a folded thread." "Face for the information line of a folded thread."
:group 'mu4e-faces) :group 'mu4e-faces)
(defvar mu4e-thread--fold-status nil (defvar-local mu4e-thread--fold-status nil
"Global folding status.") "Global folding status.")
(defvar mu4e-thread--docids nil (defvar-local mu4e-thread--docids nil
"Thread list whose folding has been set individually.") "Thread list whose folding has been set individually.")
(defvar mu4e-headers-fields) ;; defined in mu4e-headers.el (defvar mu4e-headers-fields) ;; defined in mu4e-headers.el
@ -82,15 +78,12 @@ There are COUNT hidden and UNREAD messages overall."
""))))) "")))))
(propertize (concat " " (make-string size ?•) " " msg)))) (propertize (concat " " (make-string size ?•) " " msg))))
(defun mu4e-thread/mark-and-next (orig-fun &rest args) (defun mu4e-thread-message-folded-p ()
"Advice function to prevent marking of folded messages. "Is point in a folded area?"
ORIG-FUN is the original functions, taking ARGS." (when-let* ((overlay (mu4e-thread-is-folded))
(if-let* ((overlay (mu4e-thread-is-folded))
(beg (overlay-start overlay)) (beg (overlay-start overlay))
(end (overlay-end overlay)) (end (overlay-end overlay)))
(folded (and (>= (point) beg) (< (point) end)))) (and (>= (point) beg) (< (point) end))))
(mu4e-warn "Cannot mark when folded")
(apply orig-fun args)))
(declare-function 'mu4e~headers-thread-root-p "mu4e-headers") (declare-function 'mu4e~headers-thread-root-p "mu4e-headers")
(defalias 'mu4e-thread-is-root 'mu4e~headers-thread-root-p) (defalias 'mu4e-thread-is-root 'mu4e~headers-thread-root-p)
@ -141,7 +134,6 @@ ORIG-FUN is the original functions, taking ARGS."
(when (overlay-get overlay 'mu4e-thread-folded) (when (overlay-get overlay 'mu4e-thread-folded)
(throw 'folded overlay)))))) (throw 'folded overlay))))))
(defun mu4e-thread-fold-toggle-all () (defun mu4e-thread-fold-toggle-all ()
"Toggle all threads folding unconditionally. "Toggle all threads folding unconditionally.
Reset individual folding states." Reset individual folding states."
@ -275,7 +267,6 @@ Reset individual folding states."
(defun mu4e-thread-unfold-goto-next () (defun mu4e-thread-unfold-goto-next ()
"Unfold the thread at point and go to next thread." "Unfold the thread at point and go to next thread."
(interactive) (interactive)
(unless (eq (line-end-position) (point-max)) (unless (eq (line-end-position) (point-max))
(mu4e-thread-unfold) (mu4e-thread-unfold)