]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.el
notmuch.el: Preserve current thread when refreshing search results.
[notmuch] / notmuch.el
index 545b09c68b8c9cf1938ff025ffa0282f90adc699..a7e334e45ef7106855c34901151c28c927320e60 100644 (file)
@@ -286,6 +286,7 @@ Before moving, also remove the \"unread\" tag from the current message."
     (define-key map "-" 'notmuch-search-remove-tag)
     (define-key map "<" 'beginning-of-buffer)
     (define-key map ">" 'notmuch-search-goto-last-thread)
+    (define-key map "=" 'notmuch-search-refresh-view)
     (define-key map "\M->" 'notmuch-search-goto-last-thread)
     map)
   "Keymap for \"notmuch search\" buffers.")
@@ -415,6 +416,25 @@ Before moving, also remove the \"unread\" tag from the current message."
          )
        ))))
 
+(defun notmuch-search-refresh-view ()
+  "Refresh the current view.
+
+Kills the current buffer and runs a new search with the same
+query string as the current search. If the current thread is in
+the new search results, then point will be placed on the same
+thread. Otherwise, point will be moved to attempt to be in the
+same relative position within the new buffer."
+  (interactive)
+  (let ((here (point))
+       (thread (notmuch-search-find-thread-id))
+       (query notmuch-search-query-string))
+    (kill-this-buffer)
+    (notmuch-search query)
+    (goto-char (point-min))
+    (if (re-search-forward (concat "^" thread) nil t)
+       (beginning-of-line)
+      (goto-char here))))
+
 (defun notmuch-search-filter (query)
   "Run \"notmuch search\" to refine the current search results.