X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-tree.el;h=28c9372e8e197f37febc0948398b5c3b7c8145cd;hb=ac8a117a84c8af8a27325b706e0b68a6ada8e478;hp=b498db0723e2aae2126b63ba0268636f89789a4c;hpb=99b6e780c8714f90f476e989e2d1cd973cf5bbb9;p=notmuch diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index b498db07..28c9372e 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -1,4 +1,4 @@ -;;; notmuch-tree.el --- displaying notmuch forests. +;;; notmuch-tree.el --- displaying notmuch forests ;; ;; Copyright © Carl Worth ;; Copyright © David Edmondson @@ -33,6 +33,7 @@ (require 'notmuch-show) (require 'notmuch-tag) (require 'notmuch-parser) +(require 'notmuch-jump) (declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line)) @@ -41,6 +42,11 @@ (declare-function notmuch-search-find-thread-id "notmuch" (&optional bare)) (declare-function notmuch-search-find-subject "notmuch" ()) +;; For `notmuch-tree-next-thread-from-search'. +(declare-function notmuch-search-next-thread "notmuch" ()) +(declare-function notmuch-search-previous-thread "notmuch" ()) +(declare-function notmuch-tree-from-search-thread "notmuch" ()) + ;; the following variable is defined in notmuch.el (defvar notmuch-search-query-string) @@ -221,6 +227,9 @@ For example: "A buffer local copy of argument open-target to the function notmuch-tree.") (make-variable-buffer-local 'notmuch-tree-open-target) +(defvar notmuch-tree-parent-buffer nil) +(make-variable-buffer-local 'notmuch-tree-parent-buffer) + (defvar notmuch-tree-message-window nil "The window of the message pane. @@ -334,7 +343,7 @@ FUNC." (define-key map [mouse-1] 'notmuch-tree-show-message) (define-key map "x" 'notmuch-tree-archive-message-then-next-or-exit) (define-key map "X" 'notmuch-tree-archive-thread-then-exit) - (define-key map "A" 'notmuch-tree-archive-thread) + (define-key map "A" 'notmuch-tree-archive-thread-then-next) (define-key map "a" 'notmuch-tree-archive-message-then-next) (define-key map "z" 'notmuch-tree-to-tree) (define-key map "n" 'notmuch-tree-next-matching-message) @@ -350,8 +359,8 @@ FUNC." (define-key map " " 'notmuch-tree-scroll-or-next) (define-key map (kbd "DEL") 'notmuch-tree-scroll-message-window-back) (define-key map "e" 'notmuch-tree-resume-message) - map)) -(fset 'notmuch-tree-mode-map notmuch-tree-mode-map) + map) + "Keymap for \"notmuch tree\" buffers.") (defun notmuch-tree-get-message-properties () "Return the properties of the current message as a plist. @@ -493,6 +502,12 @@ NOT change the database." (notmuch-tree-close-message-window) (notmuch-tree query))) +(defun notmuch-tree-archive-thread-then-next () + "Archive all messages in the current buffer, then show next thread from search." + (interactive) + (notmuch-tree-archive-thread) + (notmuch-tree-next-thread)) + (defun notmuch-unthreaded-from-tree-current-query () "Switch from tree view to unthreaded view." (interactive) @@ -516,9 +531,10 @@ NOT change the database." (let ((buffer (current-buffer))) (when (and (window-live-p notmuch-tree-message-window) (eq (window-buffer notmuch-tree-message-window) buffer)) - ;; We do not want an error if this is the sole window in the - ;; frame and I do not know how to test for that in emacs pre - ;; 24. Hence we just ignore-errors. + ;; We could check whether this is the only window in its frame, + ;; but simply ignoring the error that is thrown otherwise is + ;; what we had to do for Emacs 24 and we stick to that because + ;; it is still the simplest approach. (ignore-errors (delete-window notmuch-tree-message-window))))) @@ -542,9 +558,14 @@ NOT change the database." (setq notmuch-tree-message-window (split-window-vertically (/ (window-height) 4))) (with-selected-window notmuch-tree-message-window - ;; Since we are only displaying one message do not indent. - (let ((notmuch-show-indent-messages-width 0) - (notmuch-show-only-matching-messages t)) + (let (;; Since we are only displaying one message do not indent. + (notmuch-show-indent-messages-width 0) + (notmuch-show-only-matching-messages t) + ;; Ensure that `pop-to-buffer-same-window' uses the + ;; window we want it to use. + (display-buffer-overriding-action + '((display-buffer-same-window) + (inhibit-same-window . nil)))) (setq buffer (notmuch-show id)))) ;; We need the `let' as notmuch-tree-message-window is buffer local. (let ((window notmuch-tree-message-window)) @@ -587,7 +608,7 @@ Shows in split pane or whole window according to value of (scroll-up))))) (defun notmuch-tree-scroll-message-window-back () - "Scroll the message window back(if it exists)." + "Scroll the message window back (if it exists)." (interactive) (when (window-live-p notmuch-tree-message-window) (with-selected-window notmuch-tree-message-window @@ -596,7 +617,8 @@ Shows in split pane or whole window according to value of (scroll-down))))) (defun notmuch-tree-scroll-or-next () - "Scroll the message window. If it at end go to next message." + "Scroll the message window. +If it at end go to next message." (interactive) (when (notmuch-tree-scroll-message-window) (notmuch-tree-next-matching-message))) @@ -720,12 +742,14 @@ nil otherwise." (while (not (or (notmuch-tree-get-prop :first) (eobp))) (forward-line -1)))) -(defun notmuch-tree-prev-thread () +(defun notmuch-tree-prev-thread-in-tree () + "Move to the previous thread in the current tree" (interactive) (forward-line -1) - (notmuch-tree-thread-top)) + (notmuch-tree-thread-top) + (not (bobp))) -(defun notmuch-tree-next-thread () +(defun notmuch-tree-next-thread-in-tree () "Get the next thread in the current tree. Returns t if a thread was found or nil if not." (interactive) @@ -734,6 +758,38 @@ found or nil if not." (forward-line 1)) (not (eobp))) +(defun notmuch-tree-next-thread-from-search (&optional previous) + "Move to the next thread in the parent search results, if any. + +If PREVIOUS is non-nil, move to the previous item in the +search results instead." + (interactive "P") + (let ((parent-buffer notmuch-tree-parent-buffer)) + (notmuch-tree-quit t) + (when (buffer-live-p parent-buffer) + (switch-to-buffer parent-buffer) + (if previous + (notmuch-search-previous-thread) + (notmuch-search-next-thread)) + (notmuch-tree-from-search-thread)))) + +(defun notmuch-tree-next-thread (&optional previous) + "Move to the next thread in the current tree or parent search +results + +If PREVIOUS is non-nil, move to the previous thread in the tree or +search results instead." + (interactive) + (unless (if previous (notmuch-tree-prev-thread-in-tree) + (notmuch-tree-next-thread-in-tree)) + (notmuch-tree-next-thread-from-search previous))) + +(defun notmuch-tree-prev-thread () + "Move to the previous thread in the current tree or parent search +results" + (interactive) + (notmuch-tree-next-thread t)) + (defun notmuch-tree-thread-mapcar (function) "Iterate through all messages in the current thread and call FUNCTION for side effects." @@ -1048,7 +1104,7 @@ the same as for the function notmuch-tree." ")") notmuch-tree-basic-query)) -(defun notmuch-tree (&optional query query-context target buffer-name open-target unthreaded) +(defun notmuch-tree (&optional query query-context target buffer-name open-target unthreaded parent-buffer) "Display threads matching QUERY in tree view. The arguments are: @@ -1074,10 +1130,11 @@ The arguments are: (if unthreaded "unthreaded-" "tree-") query "*"))))) (inhibit-read-only t)) - (switch-to-buffer buffer)) + (pop-to-buffer-same-window buffer)) ;; Don't track undo information for this buffer (set 'buffer-undo-list t) (notmuch-tree-worker query query-context target open-target unthreaded) + (setq notmuch-tree-parent-buffer parent-buffer) (setq truncate-lines t)) (defun notmuch-unthreaded (&optional query query-context target buffer-name open-target)