--- emacs/notmuch-tree.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index 8b6cd51..6afed76 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -194,6 +194,10 @@ (defvar notmuch-tree-message-buffer nil (make-variable-buffer-local 'notmuch-tree-message-buffer) (put 'notmuch-tree-message-buffer 'permanent-local t) +(defvar notmuch-tree-oldest-first nil + "Controls whether to sort oldest-first or not") +(make-variable-buffer-local 'notmuch-tree-oldest-first) + (defun notmuch-tree-to-message-pane (func) "Execute FUNC in message pane. @@ -265,6 +269,7 @@ (defvar notmuch-tree-mode-map (define-key map "A" 'notmuch-tree-archive-thread) (define-key map "a" 'notmuch-tree-archive-message-then-next) (define-key map "=" 'notmuch-tree-refresh-view) + (define-key map "o" 'notmuch-tree-toggle-order) (define-key map "z" 'notmuch-tree-to-tree) (define-key map "n" 'notmuch-tree-next-matching-message) (define-key map "p" 'notmuch-tree-prev-matching-message) @@ -562,6 +567,18 @@ (defun notmuch-tree-refresh-view () query-context target))) +(defun notmuch-tree-toggle-order () + "Toggle the current search order. + +By default, the threads in `notmuch-tree' are displayed +reverse-chronological order (newest thread at the beginning of +the buffer). + +This command toggles the sort order for the current search." + (interactive) + (setq notmuch-tree-oldest-first (not notmuch-tree-oldest-first)) + (notmuch-tree-refresh-view)) + (defun notmuch-tree-thread-top () (when (notmuch-tree-get-message-properties) (while (not (or (notmuch-tree-get-prop :first) (eobp))) @@ -872,7 +889,11 @@ (defun notmuch-tree-worker (basic-query &optional query-context target open-targ (let ((proc (notmuch-start-notmuch "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel "show" "--body=false" "--format=sexp" - message-arg search-args)) + message-arg + (if oldest-first + "--sort=oldest-first" + "--sort=newest-first") + search-args)) ;; Use a scratch buffer to accumulate partial output. ;; This buffer will be killed by the sentinel, which ;; should be called no matter how the process dies. -- 2.1.4