From ada6ff6260564032e81a1221a5553c8ece75dd27 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 4 May 2023 00:01:30 +0300 Subject: [PATCH] mu4e/thread: only when available Fixes #2479. --- mu4e/mu4e-headers.el | 13 +++++-------- mu4e/mu4e-thread.el | 22 ++++++++++++++++++++-- mu4e/mu4e.texi | 14 +++++++++----- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 7c03b3f9..24b54b70 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -868,8 +868,11 @@ after the end of the search results." mu4e--search-msgid-target nil) (when (mu4e~headers-docid-at-point) (mu4e~headers-highlight (mu4e~headers-docid-at-point))))) - ;; run-hooks - (run-hooks 'mu4e-headers-found-hook)) + ;; maybe enable thread folding + (when mu4e-search-threads + (mu4e-thread-mode)) + ;; run-hooks + (run-hooks 'mu4e-headers-found-hook)) ;;; Marking @@ -932,12 +935,6 @@ after the end of the search results." (define-key map (kbd "") #'mu4e-headers-split-view-shrink) - ;; threads - (define-key map (kbd "") #'mu4e-thread-goto-root) - (define-key map (kbd "") #'mu4e-thread-fold-toggle-goto-next) - (define-key map (kbd "") #'mu4e-thread-fold-toggle-goto-next) - (define-key map (kbd "") #'mu4e-thread-fold-toggle-all) - ;; switching to view mode (if it's visible) (define-key map "y" #'mu4e-select-other-view) diff --git a/mu4e/mu4e-thread.el b/mu4e/mu4e-thread.el index ba452cb2..67419e33 100644 --- a/mu4e/mu4e-thread.el +++ b/mu4e/mu4e-thread.el @@ -32,10 +32,14 @@ ;; Similarly, when a thread has marked messages, the folding stops at the first ;; marked message. +;; Note, you can only use these functions when threads are available, roughly +;; when `mu4e-search-threads' in non-nil. + ;;; Usage example: ;; -;; This enforces folding after a new search -;; (add-hook 'mu4e-headers-found-hook #'mu4e-thread-fold-apply-all) +;; After a search, mu4e-thread-mode will be enable when threads +;; are available; so, to automatically sort them: +;; (add-hook 'mu4e-thread-mode-hook #'mu4e-thread-fold-apply-all) ;;; Code: @@ -273,5 +277,19 @@ Reset individual folding states." (mu4e-thread-unfold) (mu4e-thread-goto-next))) +(define-minor-mode mu4e-thread-mode + "Mode for thread-support." + :global nil + :init-value nil ;; disabled by default + :group 'mu4e + :lighter "" + :keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "") #'mu4e-thread-goto-root) + (define-key map (kbd "") #'mu4e-thread-fold-toggle-goto-next) + (define-key map (kbd "") #'mu4e-thread-fold-toggle-goto-next) + (define-key map (kbd "") #'mu4e-thread-fold-toggle-all) + map)) + (provide 'mu4e-thread) ;;; mu4e-thread.el ends here diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 9b60e6b5..dac17445 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -1118,15 +1118,19 @@ Folding stops at the @emph{first unread message}, unless you set the folding stops at the first marked message. Marking folded messages is not allowed as it is too error-prone. +Thread-mode functionality is only available with @code{mu4e-search-threads} +enabled; this triggers a minor mode @code{mu4e-thread-mode} in the headers-view. +For now, this functionality is not available in the message view, due to the +conflicting key bindings. + If you want to automatically fold all threads after a query, you can use a hook: @lisp - (add-hook 'mu4e-headers-found-hook #'mu4e-thread-fold-apply-all) + (add-hook 'mu4e-thread-mode-hook #'mu4e-thread-fold-apply-all) @end lisp -By default, single-child threads are @emph{not} collapsed, since it would simply -result in replacing a single line with the collapsed one. However, if, for -consistency you also want to fold those, you can use -@t{mu4e-thread-fold-single-children}. +By default, single-child threads are @emph{not} collapsed, since it would result +in replacing a single line with the collapsed one. However, if, for consistency, +you also want to fold those, you can use @t{mu4e-thread-fold-single-children}. @node HV Custom headers @section Custom headers