From 92ac6de09cf84aea4e196d494a726bf06299bd77 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 12 Feb 2023 12:55:34 +0200 Subject: [PATCH] mu4e: support jumping to previous/next thread in headers view, message view with '{' and '}. Also update documentation. Fixes #1523 --- mu4e/mu4e-headers.el | 25 ++++++++++++++++++++++++- mu4e/mu4e-view.el | 23 ++++++++++++++++++----- mu4e/mu4e.texi | 6 ++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 92abaebb..c21c83d7 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -923,6 +923,9 @@ after the end of the search results." (define-key map (kbd "[") #'mu4e-headers-prev-unread) (define-key map (kbd "]") #'mu4e-headers-next-unread) + (define-key map (kbd "{") #'mu4e-headers-prev-thread) + (define-key map (kbd "}") #'mu4e-headers-next-thread) + ;; change the number of headers (define-key map (kbd "C-+") #'mu4e-headers-split-view-grow) (define-key map (kbd "C--") #'mu4e-headers-split-view-shrink) @@ -1467,7 +1470,7 @@ previous header." (defun mu4e~headers-prev-or-next-unread (backwards) "Move point to the next message that is unread (and untrashed). If BACKWARDS is non-`nil', move backwards." - (interactive) + (interactive "P") (or (mu4e-headers-find-if-next (lambda (msg) (let ((flags (mu4e-message-field msg :flags))) @@ -1488,6 +1491,26 @@ untrashed)." (interactive) (mu4e~headers-prev-or-next-unread nil)) + +(defun mu4e~headers-prev-or-next-thread (backwards) + "Move point to the top of the next thread. +If BACKWARDS is non-`nil', move backwards." + (interactive "P") + (or (mu4e-headers-find-if-next + (lambda (msg) + (eq 0 (plist-get (plist-get msg :meta) :level))) + backwards) + (mu4e-message (format "No %s thread found" + (if backwards "previous" "next"))))) + +(defun mu4e-headers-prev-thread () + "Move point to the previous thread." + (interactive) (mu4e~headers-prev-or-next-thread t)) + +(defun mu4e-headers-next-thread () + "Move point to the previous thread." + (interactive) (mu4e~headers-prev-or-next-thread nil)) + (defun mu4e-headers-split-view-grow (&optional n) "In split-view, grow the headers window. In horizontal split-view, increase the number of lines shown by N. diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 776f71fa..38ea62a3 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -193,14 +193,13 @@ previous header." (mu4e--view-in-headers-context (mu4e~headers-move (- (or n 1))))) -(defun mu4e--view-prev-or-next-unread (backwards) +(defun mu4e--view-prev-or-next (func backwards) "Move point to the next or previous message. Go to the previous message if BACKWARDS is non-nil. unread message header in the headers buffer connected with this message view. If this succeeds, return the new docid. Otherwise, return nil." - (mu4e--view-in-headers-context - (mu4e~headers-prev-or-next-unread backwards)) + (mu4e--view-in-headers-context (funcall func backwards)) (mu4e-select-other-view) (mu4e-headers-view-message)) @@ -208,13 +207,25 @@ return nil." "Move point to the previous unread message header. If this succeeds, return the new docid. Otherwise, return nil." (interactive) - (mu4e--view-prev-or-next-unread t)) + (mu4e--view-prev-or-next #'mu4e~headers-prev-or-next-unread t)) (defun mu4e-view-headers-next-unread () "Move point to the next unread message header. If this succeeds, return the new docid. Otherwise, return nil." (interactive) - (mu4e--view-prev-or-next-unread nil)) + (mu4e--view-prev-or-next #'mu4e~headers-prev-or-next-unread nil)) + +(defun mu4e-view-headers-prev-thread() + "Move point to the previous thread. +If this succeeds, return the new docid. Otherwise, return nil." + (interactive) + (mu4e--view-prev-or-next #'mu4e~headers-prev-or-next-thread t)) + +(defun mu4e-view-headers-next-thread() + "Move point to the previous thread. +If this succeeds, return the new docid. Otherwise, return nil." + (interactive) + (mu4e--view-prev-or-next #'mu4e~headers-prev-or-next-thread nil)) ;;; Interactive functions @@ -907,6 +918,8 @@ This is useful for advising some Gnus-functionality that does not work in mu4e." (define-key map (kbd "[") #'mu4e-view-headers-prev-unread) (define-key map (kbd "]") #'mu4e-view-headers-next-unread) + (define-key map (kbd "{") #'mu4e-view-headers-prev-thread) + (define-key map (kbd "}") #'mu4e-view-headers-next-thread) ;; switching from view <-> headers (when visible) (define-key map "y" #'mu4e-select-other-view) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index e4fbe7a8..ad4e67ce 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -978,7 +978,8 @@ key description =========================================================== n,p view the next, previous message ],[ move to the next, previous unread message -y select the message view (if it's visible) +},{ move to the next, previous thread +y select the message view (if visible) RET open the message at point in the message view searching @@ -1304,7 +1305,8 @@ key description ============================================================== n,p view the next, previous message ],[ move to the next, previous unread message -y select the headers view (if it's visible) +},{ move to the next, previous thread +y select the headers view (if visible) RET scroll down M-RET open URL at point / attachment at point