1 ; notmuch.el --- run notmuch within emacs
3 ; Copyright © Carl Worth
5 ; This file is part of Notmuch.
7 ; Notmuch is free software: you can redistribute it and/or modify it
8 ; under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
12 ; Notmuch is distributed in the hope that it will be useful, but
13 ; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ; General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
20 ; Authors: Carl Worth <cworth@cworth.org>
22 (defvar notmuch-show-mode-map
23 (let ((map (make-sparse-keymap)))
24 ; I don't actually want all of these toggle commands occupying
25 ; keybindings. They steal valuable key-binding space, are hard
26 ; to remember, and act globally rather than locally.
28 ; Will be much preferable to switch to direct manipulation for
29 ; toggling visibility of these components. Probably using
30 ; overlays-at to query and manipulate the current overlay.
31 (define-key map "a" 'notmuch-show-archive-thread)
32 (define-key map "b" 'notmuch-show-toggle-body-read-visible)
33 (define-key map "c" 'notmuch-show-toggle-citations-visible)
34 (define-key map "h" 'notmuch-show-toggle-headers-visible)
35 (define-key map "n" 'notmuch-show-next-message)
36 (define-key map "p" 'notmuch-show-previous-message)
37 (define-key map (kbd "C-n") 'notmuch-show-next-line)
38 (define-key map (kbd "C-p") 'notmuch-show-previous-line)
39 (define-key map "q" 'kill-this-buffer)
40 (define-key map "s" 'notmuch-show-toggle-signatures-visible)
41 (define-key map "x" 'kill-this-buffer)
42 (define-key map "+" 'notmuch-show-add-tag)
43 (define-key map "-" 'notmuch-show-remove-tag)
44 (define-key map " " 'notmuch-show-advance-marking-read-and-archiving)
46 "Keymap for \"notmuch show\" buffers.")
47 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
49 (defvar notmuch-show-signature-lines-max 6
50 "Maximum length of signature that will be hidden by default.")
52 (set 'notmuch-show-message-begin-regexp "
\fmessage{")
53 (set 'notmuch-show-message-end-regexp "
\fmessage}")
54 (set 'notmuch-show-header-begin-regexp "
\fheader{")
55 (set 'notmuch-show-header-end-regexp "
\fheader}")
56 (set 'notmuch-show-body-begin-regexp "
\fbody{")
57 (set 'notmuch-show-body-end-regexp "
\fbody}")
58 (set 'notmuch-show-attachment-begin-regexp "
\fattachment{")
59 (set 'notmuch-show-attachment-end-regexp "
\fattachment}")
60 (set 'notmuch-show-part-begin-regexp "
\fpart{")
61 (set 'notmuch-show-part-end-regexp "
\fpart}")
62 (set 'notmuch-show-marker-regexp "
\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
64 (set 'notmuch-show-id-regexp "ID: \\(.*\\)$")
65 (set 'notmuch-show-tags-regexp "(\\([^)]*\\))$")
67 ; XXX: This should be a generic function in emacs somewhere, not here
68 (defun point-invisible-p ()
69 "Return whether the character at point is invisible.
71 Here visibility is determined by `buffer-invisibility-spec' and
72 the invisible property of any overlays for point. It doesn't have
73 anything to do with whether point is currently being displayed
74 within the current window."
75 (let ((prop (get-char-property (point) 'invisible)))
76 (if (eq buffer-invisibility-spec t)
78 (or (memq prop buffer-invisibility-spec)
79 (assq prop buffer-invisibility-spec)))))
81 (defun notmuch-show-next-line ()
82 "Like builtin `next-line' but ensuring we end on a visible character.
84 By advancing forward until reaching a visible character.
86 Unlike builtin `next-line' this version accepts no arguments."
88 (set 'this-command 'next-line)
89 (call-interactively 'next-line)
90 (while (point-invisible-p)
93 (defun notmuch-show-previous-line ()
94 "Like builtin `previous-line' but ensuring we end on a visible character.
96 By advancing forward until reaching a visible character.
98 Unlike builtin `next-line' this version accepts no arguments."
100 (set 'this-command 'previous-line)
101 (call-interactively 'previous-line)
102 (while (point-invisible-p)
105 (defun notmuch-show-get-message-id ()
108 (if (not (looking-at notmuch-show-message-begin-regexp))
109 (re-search-backward notmuch-show-message-begin-regexp))
110 (re-search-forward notmuch-show-id-regexp)
111 (buffer-substring (match-beginning 1) (match-end 1))))
113 (defun notmuch-show-set-tags (tags)
116 (if (not (looking-at notmuch-show-message-begin-regexp))
117 (re-search-backward notmuch-show-message-begin-regexp))
118 (re-search-forward notmuch-show-tags-regexp)
119 (let ((inhibit-read-only t)
120 (beg (match-beginning 1))
122 (delete-region beg end)
124 (insert (mapconcat 'identity tags " ")))))
126 (defun notmuch-show-get-tags ()
129 (if (not (looking-at notmuch-show-message-begin-regexp))
130 (re-search-backward notmuch-show-message-begin-regexp))
131 (re-search-forward notmuch-show-tags-regexp)
132 (split-string (buffer-substring (match-beginning 1) (match-end 1)))))
134 (defun notmuch-show-add-tag (tag)
135 (interactive "sTag to add: ")
136 (notmuch-call-notmuch-process "tag" (concat "+" tag) (concat "id:" (notmuch-show-get-message-id)))
137 (notmuch-show-set-tags (delete-dups (sort (cons tag (notmuch-show-get-tags)) 'string<))))
139 (defun notmuch-show-remove-tag (tag)
140 (interactive "sTag to remove: ")
141 (let ((tags (notmuch-show-get-tags)))
142 (if (member tag tags)
144 (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "id:" (notmuch-show-get-message-id)))
145 (notmuch-show-set-tags (delete tag tags))))))
147 (defun notmuch-show-archive-thread ()
148 "Archive each message in thread, and show next thread from search.
150 Archive each message currrently shown by removing the \"inbox\"
151 tag from each. Then kill this buffer and show the next thread
152 from the search from which this thread was originally shown.
154 Note: This command is safe from any race condition of new messages
155 being delivered to the same thread. It does not archive the
156 entire thread, but only the messages shown in the current
160 (goto-char (point-min))
162 (notmuch-show-remove-tag "inbox")
165 (if (not (re-search-forward notmuch-show-message-begin-regexp nil t))
166 (goto-char (point-max)))))
167 (let ((parent-buffer notmuch-show-parent-buffer))
171 (switch-to-buffer parent-buffer)
172 (notmuch-search-show-thread)))))
174 (defun notmuch-show-move-to-current-message-summary-line ()
175 "Move to the beginning of the one-line summary of the current message.
177 This gives us a stable place to move to and work from since the
178 summary line is always visible. This is important since moving to
179 an invisible location is unreliable, (the main command loop moves
180 point either forward or backward to the next visible character
181 when a command ends with point on an invisible character).
183 Emits an error if point is not within a valid message, (that is
184 not pattern of `notmuch-show-message-begin-regexp' could be found
185 by searching backward)."
187 (if (not (looking-at notmuch-show-message-begin-regexp))
188 (if (re-search-backward notmuch-show-message-begin-regexp nil t)
190 (error "Not within a valid message."))
193 (defun notmuch-show-last-message-p ()
194 "Predicate testing whether point is within the last message."
195 (save-window-excursion
197 (notmuch-show-move-to-current-message-summary-line)
198 (not (re-search-forward notmuch-show-message-begin-regexp nil t)))))
200 (defun notmuch-show-message-unread-p ()
201 "Preficate testing whether current message is unread."
202 (member "unread" (notmuch-show-get-tags)))
204 (defun notmuch-show-next-message ()
205 "Advance to the beginning of the next message in the buffer.
207 Moves to the last visible character of the current message if
208 already on the last message in the buffer."
210 (notmuch-show-move-to-current-message-summary-line)
211 (if (re-search-forward notmuch-show-message-begin-regexp nil t)
212 (notmuch-show-move-to-current-message-summary-line)
213 (goto-char (- (point-max) 1))
214 (while (point-invisible-p)
218 (defun notmuch-show-find-next-message ()
219 "Returns the position of the next message in the buffer.
221 Or the position of the last visible character of the current
222 message if already within the last message in the buffer."
223 ; save-excursion doesn't save our window position
224 ; save-window-excursion doesn't save point
225 ; Looks like we have to use both.
227 (save-window-excursion
228 (notmuch-show-next-message)
231 (defun notmuch-show-next-unread-message ()
232 "Advance to the beginning of the next unread message in the buffer.
234 Moves to the last visible character of the current message if
235 there are no more unread messages past the current point."
236 (notmuch-show-next-message)
237 (while (and (not (notmuch-show-last-message-p))
238 (not (notmuch-show-message-unread-p)))
239 (notmuch-show-next-message))
240 (if (not (notmuch-show-message-unread-p))
241 (notmuch-show-next-message)))
243 (defun notmuch-show-previous-message ()
244 "Backup to the beginning of the previous message in the buffer.
246 If within a message rather than at the beginning of it, then
247 simply move to the beginning of the current message."
249 (let ((start (point)))
250 (notmuch-show-move-to-current-message-summary-line)
251 (if (not (< (point) start))
252 ; Go backward twice to skip the current message's marker
254 (re-search-backward notmuch-show-message-begin-regexp nil t)
255 (re-search-backward notmuch-show-message-begin-regexp nil t)
256 (notmuch-show-move-to-current-message-summary-line)
260 (defun notmuch-show-mark-read-then-next-unread-message ()
261 "Remove unread tag from current message, then advance to next unread message."
263 (notmuch-show-remove-tag "unread")
264 (notmuch-show-next-unread-message))
266 (defun notmuch-show-advance-marking-read-and-archiving ()
267 "Advance through buffer, marking read and archiving.
269 This command is intended to be one of the simplest ways to
270 process a thread of email. It does the following:
272 If the current message in the thread is not yet fully visible,
273 scroll by a near screenful to read more of the message.
275 Otherwise, (the end of the current message is already within the
276 current window), remove the \"unread\" tag (if present) from the
277 current message and advance to the next message.
279 Finally, if there is no further message to advance to, and this
280 last message is already read, then archive the entire current
281 thread, (remove the \"inbox\" tag from each message). Also kill
282 this buffer, and display the next thread from the search from
283 which this thread was originally shown."
285 (let ((next (notmuch-show-find-next-message))
286 (unread (notmuch-show-message-unread-p)))
287 (if (> next (window-end))
290 (notmuch-show-mark-read-then-next-unread-message)
291 (if (notmuch-show-last-message-p)
292 (notmuch-show-archive-thread)
293 (notmuch-show-next-unread-message))))))
295 (defun notmuch-show-markup-citations-region (beg end)
298 (while (< (point) end)
299 (let ((beg-sub (point)))
302 (while (looking-at ">")
304 (let ((overlay (make-overlay beg-sub (point))))
305 (overlay-put overlay 'invisible 'notmuch-show-citation)
306 (overlay-put overlay 'before-string
307 (concat "[" (number-to-string (count-lines beg-sub (point)))
308 " quoted lines.]\n")))))
309 (if (looking-at "--[ ]?$")
310 (let ((sig-lines (count-lines beg-sub end)))
311 (if (<= sig-lines notmuch-show-signature-lines-max)
313 (overlay-put (make-overlay beg-sub (+ beg-sub 1))
315 (concat "[" (number-to-string sig-lines)
316 "-line signature.]"))
317 (overlay-put (make-overlay (+ beg-sub 2) end)
318 'invisible 'notmuch-show-signature)
322 (defun notmuch-show-markup-body ()
323 (re-search-forward notmuch-show-body-begin-regexp)
327 (re-search-forward notmuch-show-body-end-regexp)
328 (let ((end (match-beginning 0)))
329 (notmuch-show-markup-citations-region beg end)
330 (if (not (notmuch-show-message-unread-p))
331 (overlay-put (make-overlay beg end)
332 'invisible 'notmuch-show-body-read)))))
334 (defun notmuch-show-markup-header ()
335 (re-search-forward notmuch-show-header-begin-regexp)
339 (re-search-forward notmuch-show-header-end-regexp)
340 (overlay-put (make-overlay beg (match-beginning 0))
341 'invisible 'notmuch-show-header)))
343 (defun notmuch-show-markup-message ()
344 (if (re-search-forward notmuch-show-message-begin-regexp nil t)
346 (notmuch-show-markup-header)
347 (notmuch-show-markup-body))
348 (goto-char (point-max))))
350 (defun notmuch-show-hide-markers ()
352 (goto-char (point-min))
354 (if (re-search-forward notmuch-show-marker-regexp nil t)
356 (overlay-put (make-overlay (match-beginning 0) (+ (match-end 0) 1))
357 'invisible 'notmuch-show-marker))
358 (goto-char (point-max))))))
360 (defun notmuch-show-markup-messages ()
362 (goto-char (point-min))
364 (notmuch-show-markup-message)))
365 (notmuch-show-hide-markers))
367 (defun notmuch-show-toggle-citations-visible ()
368 "Toggle visibility of citations"
370 (if notmuch-show-citations-visible
371 (add-to-invisibility-spec 'notmuch-show-citation)
372 (remove-from-invisibility-spec 'notmuch-show-citation))
373 (set 'notmuch-show-citations-visible (not notmuch-show-citations-visible))
374 ; Need to force the redisplay for some reason
375 (force-window-update)
378 (defun notmuch-show-toggle-signatures-visible ()
379 "Toggle visibility of signatures"
381 (if notmuch-show-signatures-visible
382 (add-to-invisibility-spec 'notmuch-show-signature)
383 (remove-from-invisibility-spec 'notmuch-show-signature))
384 (set 'notmuch-show-signatures-visible (not notmuch-show-signatures-visible))
385 ; Need to force the redisplay for some reason
386 (force-window-update)
389 (defun notmuch-show-toggle-headers-visible ()
390 "Toggle visibility of header fields"
392 (if notmuch-show-headers-visible
393 (add-to-invisibility-spec 'notmuch-show-header)
394 (remove-from-invisibility-spec 'notmuch-show-header))
395 (set 'notmuch-show-headers-visible (not notmuch-show-headers-visible))
396 ; Need to force the redisplay for some reason
397 (force-window-update)
400 (defun notmuch-show-toggle-body-read-visible ()
401 "Toggle visibility of message bodies of read messages"
403 (if notmuch-show-body-read-visible
404 (add-to-invisibility-spec 'notmuch-show-body-read)
405 (remove-from-invisibility-spec 'notmuch-show-body-read))
406 (set 'notmuch-show-body-read-visible (not notmuch-show-body-read-visible))
407 ; Need to force the redisplay for some reason
408 (force-window-update)
412 (defun notmuch-show-mode ()
413 "Major mode for viewing a thread with notmuch.
415 This buffer contains the results of the \"notmuch show\" command
416 for displaying a single thread of email from your email archives.
418 By default, various components of email messages, (citations,
419 signatures, already-read messages), are invisible to help you
420 focus on the most important things, (new text from unread
421 messages). See the various commands below for toggling the
422 visibility of hidden components.
424 The `notmuch-show-next-message' and
425 `notmuch-show-previous-message' commands, (bound to 'n' and 'p by
426 default), allow you to navigate to the next and previous
427 messages. Each time you navigate away from a message with
428 `notmuch-show-next-message' the current message will have its
429 \"unread\" tag removed.
431 You can add or remove tags from the current message with '+' and
432 '-'. You can also archive all messages in the current
433 view, (remove the \"inbox\" tag from each), with
434 `notmuch-show-archive-thread' (bound to 'a' by default).
436 \\{notmuch-show-mode-map}"
438 (kill-all-local-variables)
439 (set (make-local-variable 'notmuch-show-headers-visible) t)
440 (notmuch-show-toggle-headers-visible)
441 (set (make-local-variable 'notmuch-show-body-read-visible) t)
442 (notmuch-show-toggle-body-read-visible)
443 (set (make-local-variable 'notmuch-show-citations-visible) t)
444 (notmuch-show-toggle-citations-visible)
445 (set (make-local-variable 'notmuch-show-signatures-visible) t)
446 (notmuch-show-toggle-signatures-visible)
447 (add-to-invisibility-spec 'notmuch-show-marker)
448 (use-local-map notmuch-show-mode-map)
449 (setq major-mode 'notmuch-show-mode
450 mode-name "notmuch-show")
451 (setq buffer-read-only t))
453 (defun notmuch-show (thread-id &optional parent-buffer)
454 "Run \"notmuch show\" with the given thread ID and display results.
456 The optional PARENT-BUFFER is the notmuch-search buffer from
457 which this notmuch-show command was executed, (so that the next
458 thread from that buffer can be show when done with this one)."
459 (interactive "sNotmuch show: ")
460 (let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"))))
461 (switch-to-buffer buffer)
463 (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
464 (let ((proc (get-buffer-process (current-buffer)))
465 (inhibit-read-only t))
467 (error "notmuch search process already running for query `%s'" query)
470 (goto-char (point-min))
472 (call-process "notmuch" nil t nil "show" thread-id)
473 (notmuch-show-markup-messages)
475 ; Move straight to the first unread message
476 (if (not (notmuch-show-message-unread-p))
478 (notmuch-show-next-unread-message)
479 ; But if there are no unread messages, go back to the
480 ; beginning of the buffer, and open up the bodies of all
482 (if (not (notmuch-show-message-unread-p))
484 (goto-char (point-min))
485 (notmuch-show-toggle-body-read-visible)))))
488 (defvar notmuch-search-mode-map
489 (let ((map (make-sparse-keymap)))
490 (define-key map "a" 'notmuch-search-archive-thread)
491 (define-key map "b" 'notmuch-search-scroll-down)
492 (define-key map "f" 'notmuch-search-filter)
493 (define-key map "n" 'next-line)
494 (define-key map "p" 'previous-line)
495 (define-key map "q" 'kill-this-buffer)
496 (define-key map "s" 'notmuch-search)
497 (define-key map "t" 'notmuch-search-filter-by-tag)
498 (define-key map "x" 'kill-this-buffer)
499 (define-key map (kbd "RET") 'notmuch-search-show-thread)
500 (define-key map "+" 'notmuch-search-add-tag)
501 (define-key map "-" 'notmuch-search-remove-tag)
502 (define-key map "<" 'beginning-of-buffer)
503 (define-key map ">" 'notmuch-search-goto-last-thread)
504 (define-key map "=" 'notmuch-search-refresh-view)
505 (define-key map "\M->" 'notmuch-search-goto-last-thread)
506 (define-key map " " 'notmuch-search-scroll-up)
507 (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
509 "Keymap for \"notmuch search\" buffers.")
510 (fset 'notmuch-search-mode-map notmuch-search-mode-map)
512 (defun notmuch-search-scroll-up ()
513 "Scroll up, moving point to last message in thread if at end."
517 ((end-of-buffer) (notmuch-search-goto-last-thread))))
519 (defun notmuch-search-scroll-down ()
520 "Scroll down, moving point to first message in thread if at beginning."
522 ; I don't know why scroll-down doesn't signal beginning-of-buffer
523 ; the way that scroll-up signals end-of-buffer, but c'est la vie.
525 ; So instead of trapping a signal we instead check whether the
526 ; window begins on the first line of the buffer and if so, move
527 ; directly to that position. (We have to count lines since the
528 ; window-start position is not the same as point-min due to the
529 ; invisible thread-ID characters on the first line.
530 (if (equal (count-lines (point-min) (window-start)) 1)
531 (goto-char (window-start))
534 (defun notmuch-search-goto-last-thread (&optional arg)
535 "Move point to the last thread in the buffer."
541 (defun notmuch-search-mode ()
542 "Major mode for searching mail with notmuch.
544 This buffer contains the results of a \"notmuch search\" of your
545 email archives. Each line in the buffer represents a single
546 thread giving a relative date for the thread and a subject.
548 Pressing RET on any line displays that thread. The '+' and '-'
549 keys can be used to add or remove tags from a thread. The 'a' key
550 is a convenience key for archiving a thread (removing the
553 Other useful commands are `notmuch-search-filter' for filtering
554 the current search based on an additional query string,
555 `notmuch-search-filter-by-tag' for filtering to include only
556 messages with a given tag, and `notmuch-search' to execute a new,
559 \\{notmuch-search-mode-map}"
561 (kill-all-local-variables)
562 (make-local-variable 'notmuch-search-query-string)
563 (set (make-local-variable 'scroll-preserve-screen-position) t)
564 (add-to-invisibility-spec 'notmuch-search)
565 (use-local-map notmuch-search-mode-map)
566 (setq major-mode 'notmuch-search-mode
567 mode-name "notmuch-search")
568 (setq buffer-read-only t))
570 (defun notmuch-search-find-thread-id ()
574 (re-search-forward "[a-fA-F0-9]*")
575 (filter-buffer-substring beg (point)))))
577 (defun notmuch-search-markup-this-thread-id ()
580 (re-search-forward "[a-fA-F0-9]*")
582 (overlay-put (make-overlay beg (point)) 'invisible 'notmuch-search)))
584 (defun notmuch-search-markup-thread-ids ()
586 (goto-char (point-min))
588 (notmuch-search-markup-this-thread-id)
591 (defun notmuch-search-hide-thread-ids ()
593 (add-to-invisibility-spec 'notmuch-search)
594 (force-window-update)
597 (defun notmuch-search-show-thread-ids ()
599 (remove-from-invisibility-spec 'notmuch-search)
600 (force-window-update)
603 (defun notmuch-search-show-thread ()
605 (let ((thread-id (notmuch-search-find-thread-id)))
607 (if (> (length thread-id) 0)
608 (notmuch-show thread-id (current-buffer))
609 (error "End of search results"))))
611 (defun notmuch-call-notmuch-process (&rest args)
612 (let ((error-buffer (get-buffer-create "*Notmuch errors*")))
613 (with-current-buffer error-buffer
615 (if (eq (apply 'call-process "notmuch" nil error-buffer nil args) 0)
618 (with-current-buffer error-buffer
619 (let ((beg (point-min))
620 (end (- (point-max) 1)))
621 (error (buffer-substring beg end))
624 (defun notmuch-search-set-tags (tags)
627 (re-search-backward "(")
630 (inhibit-read-only t))
631 (re-search-forward ")")
634 (delete-region beg end)
635 (insert (mapconcat 'identity tags " "))))))
637 (defun notmuch-search-get-tags ()
640 (re-search-backward "(")
641 (let ((beg (+ (point) 1)))
642 (re-search-forward ")")
643 (let ((end (- (point) 1)))
644 (split-string (buffer-substring beg end))))))
646 (defun notmuch-search-add-tag (tag)
647 (interactive "sTag to add: ")
648 (notmuch-call-notmuch-process "tag" (concat "+" tag) (concat "thread:" (notmuch-search-find-thread-id)))
649 (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<))))
651 (defun notmuch-search-remove-tag (tag)
652 (interactive "sTag to remove: ")
653 (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "thread:" (notmuch-search-find-thread-id)))
654 (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))))
656 (defun notmuch-search-archive-thread ()
657 "Archive the current thread (remove its \"inbox\" tag).
659 This function advances point to the next line when finished."
661 (notmuch-search-remove-tag "inbox")
664 (defun notmuch-search (query)
665 "Run \"notmuch search\" with the given query string and display results."
666 (interactive "sNotmuch search: ")
667 (let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*"))))
668 (switch-to-buffer buffer)
669 (notmuch-search-mode)
670 (set 'notmuch-search-query-string query)
671 (let ((proc (get-buffer-process (current-buffer)))
672 (inhibit-read-only t))
674 (error "notmuch search process already running for query `%s'" query)
677 (goto-char (point-min))
679 (call-process "notmuch" nil t nil "search" query)
680 (notmuch-search-markup-thread-ids)
683 (defun notmuch-search-refresh-view ()
684 "Refresh the current view.
686 Kills the current buffer and runs a new search with the same
687 query string as the current search. If the current thread is in
688 the new search results, then point will be placed on the same
689 thread. Otherwise, point will be moved to attempt to be in the
690 same relative position within the new buffer."
693 (thread (notmuch-search-find-thread-id))
694 (query notmuch-search-query-string))
696 (notmuch-search query)
697 (goto-char (point-min))
698 (if (re-search-forward (concat "^" thread) nil t)
702 (defun notmuch-search-filter (query)
703 "Filter the current search results based on an additional query string.
705 Runs a new search matching only messages that match both the
706 current search results AND the additional query string provided."
707 (interactive "sFilter search: ")
708 (notmuch-search (concat notmuch-search-query-string " and " query)))
710 (defun notmuch-search-filter-by-tag (tag)
711 "Filter the current search results based on a single tag.
713 Runs a new search matching only messages that match both the
714 current search results AND that are tagged with the given tag."
715 (interactive "sFilter by tag: ")
716 (notmuch-search (concat notmuch-search-query-string " and tag:" tag)))
719 "Run notmuch to display all mail with tag of 'inbox'"
721 (notmuch-search "tag:inbox"))