X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.el;h=872397646857956e1a8f67db2077e689a6f704a3;hp=d20c85ea8528be3f1fc4f4c7732b945a06ef855c;hb=8561c7463a5de3bd0990d8244abb1c67ca4f4a7d;hpb=e530910ae2f4a25ddf0a45bb9eb0402561d46686 diff --git a/notmuch.el b/notmuch.el index d20c85ea..87239764 100644 --- a/notmuch.el +++ b/notmuch.el @@ -615,6 +615,7 @@ thread from that buffer can be show when done with this one)." (define-key map "b" 'notmuch-search-scroll-down) (define-key map "f" 'notmuch-search-filter) (define-key map "n" 'next-line) + (define-key map "o" 'notmuch-search-toggle-order) (define-key map "p" 'previous-line) (define-key map "q" 'kill-this-buffer) (define-key map "s" 'notmuch-search) @@ -684,6 +685,7 @@ global search. (interactive) (kill-all-local-variables) (make-local-variable 'notmuch-search-query-string) + (make-local-variable 'notmuch-search-oldest-first) (set (make-local-variable 'scroll-preserve-screen-position) t) (add-to-invisibility-spec 'notmuch-search) (use-local-map notmuch-search-mode-map) @@ -777,13 +779,14 @@ This function advances point to the next line when finished." (notmuch-search-remove-tag "inbox") (forward-line)) -(defun notmuch-search (query) +(defun notmuch-search (query &optional oldest-first) "Run \"notmuch search\" with the given query string and display results." (interactive "sNotmuch search: ") (let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*")))) (switch-to-buffer buffer) (notmuch-search-mode) (set 'notmuch-search-query-string query) + (set 'notmuch-search-oldest-first oldest-first) (let ((proc (get-buffer-process (current-buffer))) (inhibit-read-only t)) (if proc @@ -792,7 +795,9 @@ This function advances point to the next line when finished." (erase-buffer) (goto-char (point-min)) (save-excursion - (call-process "notmuch" nil t nil "search" query) + (if oldest-first + (call-process "notmuch" nil t nil "search" query) + (call-process "notmuch" nil t nil "search" "--reverse" query)) (notmuch-search-markup-thread-ids) )))) @@ -806,22 +811,41 @@ thread. Otherwise, point will be moved to attempt to be in the same relative position within the new buffer." (interactive) (let ((here (point)) + (oldest-first notmuch-search-oldest-first) (thread (notmuch-search-find-thread-id)) (query notmuch-search-query-string)) (kill-this-buffer) - (notmuch-search query) + (notmuch-search query oldest-first) (goto-char (point-min)) (if (re-search-forward (concat "^" thread) nil t) (beginning-of-line) (goto-char here)))) +(defun notmuch-search-toggle-order () + "Toggle the current search order. + +By default, the \"inbox\" view created by `notmuch' is displayed +in chronological order (oldest thread at the beginning of the +buffer), while any global searches created by `notmuch-search' +are displayed in reverse-chronological order (newest thread at +the beginning of the buffer). + +This command toggles the sort order for the current search. + +Note that any fitlered searches created by +`notmuch-search-filter' retain the search order of the parent +search." + (interactive) + (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first)) + (notmuch-search-refresh-view)) + (defun notmuch-search-filter (query) "Filter the current search results based on an additional query string. Runs a new search matching only messages that match both the current search results AND the additional query string provided." (interactive "sFilter search: ") - (notmuch-search (concat notmuch-search-query-string " and " query))) + (notmuch-search (concat notmuch-search-query-string " and " query) notmuch-search-oldest-first)) (defun notmuch-search-filter-by-tag (tag) "Filter the current search results based on a single tag. @@ -829,11 +853,11 @@ current search results AND the additional query string provided." Runs a new search matching only messages that match both the current search results AND that are tagged with the given tag." (interactive "sFilter by tag: ") - (notmuch-search (concat notmuch-search-query-string " and tag:" tag))) + (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first)) (defun notmuch () "Run notmuch to display all mail with tag of 'inbox'" (interactive) - (notmuch-search "tag:inbox")) + (notmuch-search "tag:inbox" t)) (provide 'notmuch)