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 "w" 'notmuch-show-view-raw-message)
42 (define-key map "x" 'kill-this-buffer)
43 (define-key map "+" 'notmuch-show-add-tag)
44 (define-key map "-" 'notmuch-show-remove-tag)
45 (define-key map " " 'notmuch-show-advance-marking-read-and-archiving)
47 "Keymap for \"notmuch show\" buffers.")
48 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
50 (defvar notmuch-show-signature-lines-max 6
51 "Maximum length of signature that will be hidden by default.")
53 (set 'notmuch-show-message-begin-regexp "
\fmessage{")
54 (set 'notmuch-show-message-end-regexp "
\fmessage}")
55 (set 'notmuch-show-header-begin-regexp "
\fheader{")
56 (set 'notmuch-show-header-end-regexp "
\fheader}")
57 (set 'notmuch-show-body-begin-regexp "
\fbody{")
58 (set 'notmuch-show-body-end-regexp "
\fbody}")
59 (set 'notmuch-show-attachment-begin-regexp "
\fattachment{")
60 (set 'notmuch-show-attachment-end-regexp "
\fattachment}")
61 (set 'notmuch-show-part-begin-regexp "
\fpart{")
62 (set 'notmuch-show-part-end-regexp "
\fpart}")
63 (set 'notmuch-show-marker-regexp "
\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
65 (set 'notmuch-show-id-regexp "ID: \\([^ ]*\\)")
66 (set 'notmuch-show-filename-regexp "Filename: \\(.*\\)$")
67 (set 'notmuch-show-tags-regexp "(\\([^)]*\\))$")
69 ; XXX: This should be a generic function in emacs somewhere, not here
70 (defun point-invisible-p ()
71 "Return whether the character at point is invisible.
73 Here visibility is determined by `buffer-invisibility-spec' and
74 the invisible property of any overlays for point. It doesn't have
75 anything to do with whether point is currently being displayed
76 within the current window."
77 (let ((prop (get-char-property (point) 'invisible)))
78 (if (eq buffer-invisibility-spec t)
80 (or (memq prop buffer-invisibility-spec)
81 (assq prop buffer-invisibility-spec)))))
83 (defun notmuch-show-next-line ()
84 "Like builtin `next-line' but ensuring we end on a visible character.
86 By advancing forward until reaching a visible character.
88 Unlike builtin `next-line' this version accepts no arguments."
90 (set 'this-command 'next-line)
91 (call-interactively 'next-line)
92 (while (point-invisible-p)
95 (defun notmuch-show-previous-line ()
96 "Like builtin `previous-line' but ensuring we end on a visible character.
98 By advancing forward until reaching a visible character.
100 Unlike builtin `next-line' this version accepts no arguments."
102 (set 'this-command 'previous-line)
103 (call-interactively 'previous-line)
104 (while (point-invisible-p)
107 (defun notmuch-show-get-message-id ()
110 (if (not (looking-at notmuch-show-message-begin-regexp))
111 (re-search-backward notmuch-show-message-begin-regexp))
112 (re-search-forward notmuch-show-id-regexp)
113 (buffer-substring (match-beginning 1) (match-end 1))))
115 (defun notmuch-show-get-filename ()
118 (if (not (looking-at notmuch-show-message-begin-regexp))
119 (re-search-backward notmuch-show-message-begin-regexp))
120 (re-search-forward notmuch-show-filename-regexp)
121 (buffer-substring (match-beginning 1) (match-end 1))))
123 (defun notmuch-show-set-tags (tags)
126 (if (not (looking-at notmuch-show-message-begin-regexp))
127 (re-search-backward notmuch-show-message-begin-regexp))
128 (re-search-forward notmuch-show-tags-regexp)
129 (let ((inhibit-read-only t)
130 (beg (match-beginning 1))
132 (delete-region beg end)
134 (insert (mapconcat 'identity tags " ")))))
136 (defun notmuch-show-get-tags ()
139 (if (not (looking-at notmuch-show-message-begin-regexp))
140 (re-search-backward notmuch-show-message-begin-regexp))
141 (re-search-forward notmuch-show-tags-regexp)
142 (split-string (buffer-substring (match-beginning 1) (match-end 1)))))
144 (defun notmuch-show-add-tag (tag)
145 (interactive "sTag to add: ")
146 (notmuch-call-notmuch-process "tag" (concat "+" tag) (concat "id:" (notmuch-show-get-message-id)))
147 (notmuch-show-set-tags (delete-dups (sort (cons tag (notmuch-show-get-tags)) 'string<))))
149 (defun notmuch-show-remove-tag (tag)
150 (interactive "sTag to remove: ")
151 (let ((tags (notmuch-show-get-tags)))
152 (if (member tag tags)
154 (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "id:" (notmuch-show-get-message-id)))
155 (notmuch-show-set-tags (delete tag tags))))))
157 (defun notmuch-show-archive-thread ()
158 "Archive each message in thread, and show next thread from search.
160 Archive each message currrently shown by removing the \"inbox\"
161 tag from each. Then kill this buffer and show the next thread
162 from the search from which this thread was originally shown.
164 Note: This command is safe from any race condition of new messages
165 being delivered to the same thread. It does not archive the
166 entire thread, but only the messages shown in the current
170 (goto-char (point-min))
172 (notmuch-show-remove-tag "inbox")
175 (if (not (re-search-forward notmuch-show-message-begin-regexp nil t))
176 (goto-char (point-max)))))
177 (let ((parent-buffer notmuch-show-parent-buffer))
181 (switch-to-buffer parent-buffer)
182 (notmuch-search-show-thread)))))
184 (defun notmuch-show-view-raw-message ()
185 "View the raw email of the current message."
187 (view-file (notmuch-show-get-filename)))
189 (defun notmuch-show-move-to-current-message-summary-line ()
190 "Move to the beginning of the one-line summary of the current message.
192 This gives us a stable place to move to and work from since the
193 summary line is always visible. This is important since moving to
194 an invisible location is unreliable, (the main command loop moves
195 point either forward or backward to the next visible character
196 when a command ends with point on an invisible character).
198 Emits an error if point is not within a valid message, (that is
199 not pattern of `notmuch-show-message-begin-regexp' could be found
200 by searching backward)."
202 (if (not (looking-at notmuch-show-message-begin-regexp))
203 (if (re-search-backward notmuch-show-message-begin-regexp nil t)
205 (error "Not within a valid message."))
208 (defun notmuch-show-last-message-p ()
209 "Predicate testing whether point is within the last message."
210 (save-window-excursion
212 (notmuch-show-move-to-current-message-summary-line)
213 (not (re-search-forward notmuch-show-message-begin-regexp nil t)))))
215 (defun notmuch-show-message-unread-p ()
216 "Preficate testing whether current message is unread."
217 (member "unread" (notmuch-show-get-tags)))
219 (defun notmuch-show-next-message ()
220 "Advance to the beginning of the next message in the buffer.
222 Moves to the last visible character of the current message if
223 already on the last message in the buffer."
225 (notmuch-show-move-to-current-message-summary-line)
226 (if (re-search-forward notmuch-show-message-begin-regexp nil t)
227 (notmuch-show-move-to-current-message-summary-line)
228 (goto-char (- (point-max) 1))
229 (while (point-invisible-p)
233 (defun notmuch-show-find-next-message ()
234 "Returns the position of the next message in the buffer.
236 Or the position of the last visible character of the current
237 message if already within the last message in the buffer."
238 ; save-excursion doesn't save our window position
239 ; save-window-excursion doesn't save point
240 ; Looks like we have to use both.
242 (save-window-excursion
243 (notmuch-show-next-message)
246 (defun notmuch-show-next-unread-message ()
247 "Advance to the beginning of the next unread message in the buffer.
249 Moves to the last visible character of the current message if
250 there are no more unread messages past the current point."
251 (notmuch-show-next-message)
252 (while (and (not (notmuch-show-last-message-p))
253 (not (notmuch-show-message-unread-p)))
254 (notmuch-show-next-message))
255 (if (not (notmuch-show-message-unread-p))
256 (notmuch-show-next-message)))
258 (defun notmuch-show-previous-message ()
259 "Backup to the beginning of the previous message in the buffer.
261 If within a message rather than at the beginning of it, then
262 simply move to the beginning of the current message."
264 (let ((start (point)))
265 (notmuch-show-move-to-current-message-summary-line)
266 (if (not (< (point) start))
267 ; Go backward twice to skip the current message's marker
269 (re-search-backward notmuch-show-message-begin-regexp nil t)
270 (re-search-backward notmuch-show-message-begin-regexp nil t)
271 (notmuch-show-move-to-current-message-summary-line)
275 (defun notmuch-show-mark-read-then-next-unread-message ()
276 "Remove unread tag from current message, then advance to next unread message."
278 (notmuch-show-remove-tag "unread")
279 (notmuch-show-next-unread-message))
281 (defun notmuch-show-advance-marking-read-and-archiving ()
282 "Advance through buffer, marking read and archiving.
284 This command is intended to be one of the simplest ways to
285 process a thread of email. It does the following:
287 If the current message in the thread is not yet fully visible,
288 scroll by a near screenful to read more of the message.
290 Otherwise, (the end of the current message is already within the
291 current window), remove the \"unread\" tag (if present) from the
292 current message and advance to the next message.
294 Finally, if there is no further message to advance to, and this
295 last message is already read, then archive the entire current
296 thread, (remove the \"inbox\" tag from each message). Also kill
297 this buffer, and display the next thread from the search from
298 which this thread was originally shown."
300 (let ((next (notmuch-show-find-next-message))
301 (unread (notmuch-show-message-unread-p)))
302 (if (> next (window-end))
305 (notmuch-show-mark-read-then-next-unread-message)
306 (if (notmuch-show-last-message-p)
307 (notmuch-show-archive-thread)
308 (notmuch-show-next-unread-message))))))
310 (defun notmuch-show-markup-citations-region (beg end)
313 (while (< (point) end)
314 (let ((beg-sub (point)))
317 (while (looking-at ">")
319 (let ((overlay (make-overlay beg-sub (point))))
320 (overlay-put overlay 'invisible 'notmuch-show-citation)
321 (overlay-put overlay 'before-string
322 (concat "[" (number-to-string (count-lines beg-sub (point)))
323 " quoted lines.]\n")))))
324 (if (looking-at "--[ ]?$")
325 (let ((sig-lines (count-lines beg-sub end)))
326 (if (<= sig-lines notmuch-show-signature-lines-max)
328 (overlay-put (make-overlay beg-sub (+ beg-sub 1))
330 (concat "[" (number-to-string sig-lines)
331 "-line signature.]"))
332 (overlay-put (make-overlay (+ beg-sub 2) end)
333 'invisible 'notmuch-show-signature)
337 (defun notmuch-show-markup-body ()
338 (re-search-forward notmuch-show-body-begin-regexp)
342 (re-search-forward notmuch-show-body-end-regexp)
343 (let ((end (match-beginning 0)))
344 (notmuch-show-markup-citations-region beg end)
345 (if (not (notmuch-show-message-unread-p))
346 (overlay-put (make-overlay beg end)
347 'invisible 'notmuch-show-body-read)))))
349 (defun notmuch-show-markup-header ()
350 (re-search-forward notmuch-show-header-begin-regexp)
354 (re-search-forward notmuch-show-header-end-regexp)
355 (overlay-put (make-overlay beg (match-beginning 0))
356 'invisible 'notmuch-show-header)))
358 (defun notmuch-show-markup-message ()
359 (if (re-search-forward notmuch-show-message-begin-regexp nil t)
361 (notmuch-show-markup-header)
362 (notmuch-show-markup-body))
363 (goto-char (point-max))))
365 (defun notmuch-show-hide-markers ()
367 (goto-char (point-min))
369 (if (re-search-forward notmuch-show-marker-regexp nil t)
371 (overlay-put (make-overlay (match-beginning 0) (+ (match-end 0) 1))
372 'invisible 'notmuch-show-marker))
373 (goto-char (point-max))))))
375 (defun notmuch-show-markup-messages ()
377 (goto-char (point-min))
379 (notmuch-show-markup-message)))
380 (notmuch-show-hide-markers))
382 (defun notmuch-show-toggle-citations-visible ()
383 "Toggle visibility of citations"
385 (if notmuch-show-citations-visible
386 (add-to-invisibility-spec 'notmuch-show-citation)
387 (remove-from-invisibility-spec 'notmuch-show-citation))
388 (set 'notmuch-show-citations-visible (not notmuch-show-citations-visible))
389 ; Need to force the redisplay for some reason
390 (force-window-update)
393 (defun notmuch-show-toggle-signatures-visible ()
394 "Toggle visibility of signatures"
396 (if notmuch-show-signatures-visible
397 (add-to-invisibility-spec 'notmuch-show-signature)
398 (remove-from-invisibility-spec 'notmuch-show-signature))
399 (set 'notmuch-show-signatures-visible (not notmuch-show-signatures-visible))
400 ; Need to force the redisplay for some reason
401 (force-window-update)
404 (defun notmuch-show-toggle-headers-visible ()
405 "Toggle visibility of header fields"
407 (if notmuch-show-headers-visible
408 (add-to-invisibility-spec 'notmuch-show-header)
409 (remove-from-invisibility-spec 'notmuch-show-header))
410 (set 'notmuch-show-headers-visible (not notmuch-show-headers-visible))
411 ; Need to force the redisplay for some reason
412 (force-window-update)
415 (defun notmuch-show-toggle-body-read-visible ()
416 "Toggle visibility of message bodies of read messages"
418 (if notmuch-show-body-read-visible
419 (add-to-invisibility-spec 'notmuch-show-body-read)
420 (remove-from-invisibility-spec 'notmuch-show-body-read))
421 (set 'notmuch-show-body-read-visible (not notmuch-show-body-read-visible))
422 ; Need to force the redisplay for some reason
423 (force-window-update)
427 (defun notmuch-show-mode ()
428 "Major mode for viewing a thread with notmuch.
430 This buffer contains the results of the \"notmuch show\" command
431 for displaying a single thread of email from your email archives.
433 By default, various components of email messages, (citations,
434 signatures, already-read messages), are invisible to help you
435 focus on the most important things, (new text from unread
436 messages). See the various commands below for toggling the
437 visibility of hidden components.
439 The `notmuch-show-next-message' and
440 `notmuch-show-previous-message' commands, (bound to 'n' and 'p by
441 default), allow you to navigate to the next and previous
442 messages. Each time you navigate away from a message with
443 `notmuch-show-next-message' the current message will have its
444 \"unread\" tag removed.
446 You can add or remove tags from the current message with '+' and
447 '-'. You can also archive all messages in the current
448 view, (remove the \"inbox\" tag from each), with
449 `notmuch-show-archive-thread' (bound to 'a' by default).
451 \\{notmuch-show-mode-map}"
453 (kill-all-local-variables)
454 (set (make-local-variable 'notmuch-show-headers-visible) t)
455 (notmuch-show-toggle-headers-visible)
456 (set (make-local-variable 'notmuch-show-body-read-visible) t)
457 (notmuch-show-toggle-body-read-visible)
458 (set (make-local-variable 'notmuch-show-citations-visible) t)
459 (notmuch-show-toggle-citations-visible)
460 (set (make-local-variable 'notmuch-show-signatures-visible) t)
461 (notmuch-show-toggle-signatures-visible)
462 (add-to-invisibility-spec 'notmuch-show-marker)
463 (use-local-map notmuch-show-mode-map)
464 (setq major-mode 'notmuch-show-mode
465 mode-name "notmuch-show")
466 (setq buffer-read-only t))
468 (defun notmuch-show (thread-id &optional parent-buffer)
469 "Run \"notmuch show\" with the given thread ID and display results.
471 The optional PARENT-BUFFER is the notmuch-search buffer from
472 which this notmuch-show command was executed, (so that the next
473 thread from that buffer can be show when done with this one)."
474 (interactive "sNotmuch show: ")
475 (let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"))))
476 (switch-to-buffer buffer)
478 (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
479 (let ((proc (get-buffer-process (current-buffer)))
480 (inhibit-read-only t))
482 (error "notmuch search process already running for query `%s'" query)
485 (goto-char (point-min))
487 (call-process "notmuch" nil t nil "show" thread-id)
488 (notmuch-show-markup-messages)
490 ; Move straight to the first unread message
491 (if (not (notmuch-show-message-unread-p))
493 (notmuch-show-next-unread-message)
494 ; But if there are no unread messages, go back to the
495 ; beginning of the buffer, and open up the bodies of all
497 (if (not (notmuch-show-message-unread-p))
499 (goto-char (point-min))
500 (notmuch-show-toggle-body-read-visible)))))
503 (defvar notmuch-search-mode-map
504 (let ((map (make-sparse-keymap)))
505 (define-key map "a" 'notmuch-search-archive-thread)
506 (define-key map "b" 'notmuch-search-scroll-down)
507 (define-key map "f" 'notmuch-search-filter)
508 (define-key map "n" 'next-line)
509 (define-key map "p" 'previous-line)
510 (define-key map "q" 'kill-this-buffer)
511 (define-key map "s" 'notmuch-search)
512 (define-key map "t" 'notmuch-search-filter-by-tag)
513 (define-key map "x" 'kill-this-buffer)
514 (define-key map (kbd "RET") 'notmuch-search-show-thread)
515 (define-key map "+" 'notmuch-search-add-tag)
516 (define-key map "-" 'notmuch-search-remove-tag)
517 (define-key map "<" 'beginning-of-buffer)
518 (define-key map ">" 'notmuch-search-goto-last-thread)
519 (define-key map "=" 'notmuch-search-refresh-view)
520 (define-key map "\M->" 'notmuch-search-goto-last-thread)
521 (define-key map " " 'notmuch-search-scroll-up)
522 (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
524 "Keymap for \"notmuch search\" buffers.")
525 (fset 'notmuch-search-mode-map notmuch-search-mode-map)
527 (defun notmuch-search-scroll-up ()
528 "Scroll up, moving point to last message in thread if at end."
532 ((end-of-buffer) (notmuch-search-goto-last-thread))))
534 (defun notmuch-search-scroll-down ()
535 "Scroll down, moving point to first message in thread if at beginning."
537 ; I don't know why scroll-down doesn't signal beginning-of-buffer
538 ; the way that scroll-up signals end-of-buffer, but c'est la vie.
540 ; So instead of trapping a signal we instead check whether the
541 ; window begins on the first line of the buffer and if so, move
542 ; directly to that position. (We have to count lines since the
543 ; window-start position is not the same as point-min due to the
544 ; invisible thread-ID characters on the first line.
545 (if (equal (count-lines (point-min) (window-start)) 1)
546 (goto-char (window-start))
549 (defun notmuch-search-goto-last-thread (&optional arg)
550 "Move point to the last thread in the buffer."
556 (defun notmuch-search-mode ()
557 "Major mode for searching mail with notmuch.
559 This buffer contains the results of a \"notmuch search\" of your
560 email archives. Each line in the buffer represents a single
561 thread giving a relative date for the thread and a subject.
563 Pressing RET on any line displays that thread. The '+' and '-'
564 keys can be used to add or remove tags from a thread. The 'a' key
565 is a convenience key for archiving a thread (removing the
568 Other useful commands are `notmuch-search-filter' for filtering
569 the current search based on an additional query string,
570 `notmuch-search-filter-by-tag' for filtering to include only
571 messages with a given tag, and `notmuch-search' to execute a new,
574 \\{notmuch-search-mode-map}"
576 (kill-all-local-variables)
577 (make-local-variable 'notmuch-search-query-string)
578 (set (make-local-variable 'scroll-preserve-screen-position) t)
579 (add-to-invisibility-spec 'notmuch-search)
580 (use-local-map notmuch-search-mode-map)
581 (setq major-mode 'notmuch-search-mode
582 mode-name "notmuch-search")
583 (setq buffer-read-only t))
585 (defun notmuch-search-find-thread-id ()
589 (re-search-forward "[a-fA-F0-9]*")
590 (filter-buffer-substring beg (point)))))
592 (defun notmuch-search-markup-this-thread-id ()
595 (re-search-forward "[a-fA-F0-9]*")
597 (overlay-put (make-overlay beg (point)) 'invisible 'notmuch-search)))
599 (defun notmuch-search-markup-thread-ids ()
601 (goto-char (point-min))
603 (notmuch-search-markup-this-thread-id)
606 (defun notmuch-search-hide-thread-ids ()
608 (add-to-invisibility-spec 'notmuch-search)
609 (force-window-update)
612 (defun notmuch-search-show-thread-ids ()
614 (remove-from-invisibility-spec 'notmuch-search)
615 (force-window-update)
618 (defun notmuch-search-show-thread ()
620 (let ((thread-id (notmuch-search-find-thread-id)))
622 (if (> (length thread-id) 0)
623 (notmuch-show thread-id (current-buffer))
624 (error "End of search results"))))
626 (defun notmuch-call-notmuch-process (&rest args)
627 (let ((error-buffer (get-buffer-create "*Notmuch errors*")))
628 (with-current-buffer error-buffer
630 (if (eq (apply 'call-process "notmuch" nil error-buffer nil args) 0)
633 (with-current-buffer error-buffer
634 (let ((beg (point-min))
635 (end (- (point-max) 1)))
636 (error (buffer-substring beg end))
639 (defun notmuch-search-set-tags (tags)
642 (re-search-backward "(")
645 (inhibit-read-only t))
646 (re-search-forward ")")
649 (delete-region beg end)
650 (insert (mapconcat 'identity tags " "))))))
652 (defun notmuch-search-get-tags ()
655 (re-search-backward "(")
656 (let ((beg (+ (point) 1)))
657 (re-search-forward ")")
658 (let ((end (- (point) 1)))
659 (split-string (buffer-substring beg end))))))
661 (defun notmuch-search-add-tag (tag)
662 (interactive "sTag to add: ")
663 (notmuch-call-notmuch-process "tag" (concat "+" tag) (concat "thread:" (notmuch-search-find-thread-id)))
664 (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<))))
666 (defun notmuch-search-remove-tag (tag)
667 (interactive "sTag to remove: ")
668 (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "thread:" (notmuch-search-find-thread-id)))
669 (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))))
671 (defun notmuch-search-archive-thread ()
672 "Archive the current thread (remove its \"inbox\" tag).
674 This function advances point to the next line when finished."
676 (notmuch-search-remove-tag "inbox")
679 (defun notmuch-search (query)
680 "Run \"notmuch search\" with the given query string and display results."
681 (interactive "sNotmuch search: ")
682 (let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*"))))
683 (switch-to-buffer buffer)
684 (notmuch-search-mode)
685 (set 'notmuch-search-query-string query)
686 (let ((proc (get-buffer-process (current-buffer)))
687 (inhibit-read-only t))
689 (error "notmuch search process already running for query `%s'" query)
692 (goto-char (point-min))
694 (call-process "notmuch" nil t nil "search" query)
695 (notmuch-search-markup-thread-ids)
698 (defun notmuch-search-refresh-view ()
699 "Refresh the current view.
701 Kills the current buffer and runs a new search with the same
702 query string as the current search. If the current thread is in
703 the new search results, then point will be placed on the same
704 thread. Otherwise, point will be moved to attempt to be in the
705 same relative position within the new buffer."
708 (thread (notmuch-search-find-thread-id))
709 (query notmuch-search-query-string))
711 (notmuch-search query)
712 (goto-char (point-min))
713 (if (re-search-forward (concat "^" thread) nil t)
717 (defun notmuch-search-filter (query)
718 "Filter the current search results based on an additional query string.
720 Runs a new search matching only messages that match both the
721 current search results AND the additional query string provided."
722 (interactive "sFilter search: ")
723 (notmuch-search (concat notmuch-search-query-string " and " query)))
725 (defun notmuch-search-filter-by-tag (tag)
726 "Filter the current search results based on a single tag.
728 Runs a new search matching only messages that match both the
729 current search results AND that are tagged with the given tag."
730 (interactive "sFilter by tag: ")
731 (notmuch-search (concat notmuch-search-query-string " and tag:" tag)))
734 "Run notmuch to display all mail with tag of 'inbox'"
736 (notmuch-search "tag:inbox"))