[PATCH 3/7] emacs/tree: command to toggle search sort order in tree mode

Subject: [PATCH 3/7] emacs/tree: command to toggle search sort order in tree mode

Date: Sat, 26 Jun 2021 03:28:42 +0100

To: notmuch@notmuchmail.org

Cc: jao

From: jao

New command notmuch-tree-toggle-order for switching the sort order (by
reissuing the search with a different flag) in a notmuch-tree buffer.
 emacs/notmuch-tree.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 6ef8e439..c23dacfc 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -322,6 +322,7 @@ then NAME behaves like CMD."
     ;; that additionally close the message window.
     (define-key map [remap notmuch-bury-or-kill-this-buffer] 'notmuch-tree-quit)
     (define-key map [remap notmuch-search]       'notmuch-tree-to-search)
+    (define-key map [remap notmuch-search]       'notmuch-tree-toggle-order)
     (define-key map [remap notmuch-help]         'notmuch-tree-help)
     (define-key map [remap notmuch-mua-new-mail] 'notmuch-tree-new-mail)
     (define-key map [remap notmuch-jump-search]  'notmuch-tree-jump-search)
@@ -749,7 +750,8 @@ nil otherwise."
-			 unthreaded)))
+			 unthreaded
+			 notmuch-search-oldest-first)))
 (defun notmuch-tree-thread-top ()
   (when (notmuch-tree-get-message-properties)
@@ -1071,6 +1073,7 @@ the same as for the function notmuch-tree."
   (add-hook 'post-command-hook #'notmuch-tree-command-hook t t)
+  (setq notmuch-search-oldest-first oldest-first)
   (setq notmuch-tree-unthreaded unthreaded)
   (setq notmuch-tree-basic-query basic-query)
   (setq notmuch-tree-query-context (if (or (string= query-context "")
@@ -1115,6 +1118,15 @@ the same as for the function notmuch-tree."
+(defun notmuch-tree-toggle-order ()
+  "Toggle the current search order.
+This command toggles the sort order for the current search. The
+default sort order is defined by `notmuch-search-oldest-first'."
+  (interactive)
+  (setq notmuch-search-oldest-first (not notmuch-search-oldest-first))
+  (notmuch-tree-refresh-view))
 (defun notmuch-tree (&optional query query-context target buffer-name
 			       open-target unthreaded parent-buffer oldest-first)
   "Display threads matching QUERY in tree view.
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org