]> git.notmuchmail.org Git - notmuch/blob - notmuch.el
747f60c4dad7c0cddce7bd2ff33801eefa527e49
[notmuch] / notmuch.el
1 ; notmuch.el --- run notmuch within emacs
2 ;
3 ; Copyright © Carl Worth
4 ;
5 ; This file is part of Notmuch.
6 ;
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.
11 ;
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.
16 ;
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/>.
19 ;
20 ; Authors: Carl Worth <cworth@cworth.org>
21
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.
27     ;
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-mark-read-then-next-message)
36     (define-key map "p" 'notmuch-show-previous-message)
37     (define-key map "q" 'kill-this-buffer)
38     (define-key map "s" 'notmuch-show-toggle-signatures-visible)
39     (define-key map "x" 'kill-this-buffer)
40     (define-key map "+" 'notmuch-show-add-tag)
41     (define-key map "-" 'notmuch-show-remove-tag)
42     (define-key map " " 'notmuch-show-advance-marking-read-and-archiving)
43     map)
44   "Keymap for \"notmuch show\" buffers.")
45 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
46
47 (defvar notmuch-show-message-begin-regexp    "\fmessage{")
48 (defvar notmuch-show-message-end-regexp      "\fmessage}")
49 (defvar notmuch-show-header-begin-regexp     "\fheader{")
50 (defvar notmuch-show-header-end-regexp       "\fheader}")
51 (defvar notmuch-show-body-begin-regexp       "\fbody{")
52 (defvar notmuch-show-body-end-regexp         "\fbody}")
53 (defvar notmuch-show-attachment-begin-regexp "\fattachment{")
54 (defvar notmuch-show-attachment-end-regexp   "\fattachment}")
55 (defvar notmuch-show-part-begin-regexp       "\fpart{")
56 (defvar notmuch-show-part-end-regexp         "\fpart}")
57 (defvar notmuch-show-marker-regexp "\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
58
59 (defvar notmuch-show-id-regexp "ID: \\(.*\\)$")
60 (defvar notmuch-show-tags-regexp "(\\([^)]*\\))$")
61
62 (defun notmuch-show-get-message-id ()
63   (save-excursion
64     (beginning-of-line)
65     (if (not (looking-at notmuch-show-message-begin-regexp))
66         (re-search-backward notmuch-show-message-begin-regexp))
67     (re-search-forward notmuch-show-id-regexp)
68     (buffer-substring (match-beginning 1) (match-end 1))))
69
70 (defun notmuch-show-set-tags (tags)
71   (save-excursion
72     (beginning-of-line)
73     (if (not (looking-at notmuch-show-message-begin-regexp))
74         (re-search-backward notmuch-show-message-begin-regexp))
75     (re-search-forward notmuch-show-tags-regexp)
76     (let ((inhibit-read-only t)
77           (beg (match-beginning 1))
78           (end (match-end 1)))
79       (delete-region beg end)
80       (goto-char beg)
81       (insert (mapconcat 'identity tags " ")))))
82
83 (defun notmuch-show-get-tags ()
84   (save-excursion
85     (beginning-of-line)
86     (if (not (looking-at notmuch-show-message-begin-regexp))
87         (re-search-backward notmuch-show-message-begin-regexp))
88     (re-search-forward notmuch-show-tags-regexp)
89     (split-string (buffer-substring (match-beginning 1) (match-end 1)))))
90
91 (defun notmuch-show-add-tag (tag)
92   (interactive "sTag to add: ")
93   (notmuch-call-notmuch-process "tag" (concat "+" tag) (concat "id:" (notmuch-show-get-message-id)))
94   (notmuch-show-set-tags (delete-dups (sort (cons tag (notmuch-show-get-tags)) 'string<))))
95
96 (defun notmuch-show-remove-tag (tag)
97   (interactive "sTag to remove: ")
98   (let ((tags (notmuch-show-get-tags)))
99     (if (member tag tags)
100         (progn
101           (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "id:" (notmuch-show-get-message-id)))
102           (notmuch-show-set-tags (delete tag tags))))))
103
104 (defun notmuch-show-archive-thread ()
105   "Archive each message currrently shown by removing the \"inbox\" tag from each.
106
107 This command is safe from any race condition of new messages
108 being delivered to the same thread. It does not archive the
109 entire thread, but only the messages shown in the current
110 buffer."
111   (interactive)
112   (save-excursion
113     (goto-char (point-min))
114     (while (not (eobp))
115       (notmuch-show-remove-tag "inbox")
116       (if (not (eobp))
117           (forward-char))
118       (if (not (re-search-forward notmuch-show-message-begin-regexp nil t))
119           (goto-char (point-max))))))
120
121 (defun notmuch-show-move-to-current-message-summary-line ()
122   "Move to the beginning of the one-line summary of the current message.
123
124 This gives us a stable place to move to and work from since the
125 summary line is always visible. This is important since moving to
126 an invisible location is unreliable, (the main command loop moves
127 point either forward or backward to the next visible character
128 when a command ends with point on an invisible character).
129
130 Emits an error if point is not within a valid message, (that is
131 not pattern of `notmuch-show-message-begin-regexp' could be found
132 by searching backward)."
133   (beginning-of-line)
134   (if (not (looking-at notmuch-show-message-begin-regexp))
135       (if (re-search-backward notmuch-show-message-begin-regexp nil t)
136           (forward-line 2)
137         (error "Not within a valid message."))
138     (forward-line 2)))
139
140 (defun notmuch-show-next-message ()
141   "Advance to the beginning of the next message in the buffer.
142
143 Moves to the beginning of the current message if already on the
144 last message in the buffer."
145   (interactive)
146   (notmuch-show-move-to-current-message-summary-line)
147   (re-search-forward notmuch-show-message-begin-regexp nil t)
148   (notmuch-show-move-to-current-message-summary-line)
149   (recenter 0))
150
151 (defun notmuch-show-find-next-message ()
152   "Returns the position of the next message in the buffer.
153
154 Or the beginning of the current message if already within the last
155 message in the buffer."
156   ; save-excursion doesn't save our window position
157   ; save-window-excursion doesn't save point
158   ; Looks like we have to use both.
159   (save-excursion
160     (save-window-excursion
161       (notmuch-show-next-message)
162       (point))))
163
164 (defun notmuch-show-previous-message ()
165   "Backup to the beginning of the previous message in the buffer.
166
167 If within a message rather than at the beginning of it, then
168 simply move to the beginning of the current message."
169   (interactive)
170   (let ((start (point)))
171     (notmuch-show-move-to-current-message-summary-line)
172     (if (not (< (point) start))
173         ; Go backward twice to skip the current message's marker
174         (progn
175           (re-search-backward notmuch-show-message-begin-regexp nil t)
176           (re-search-backward notmuch-show-message-begin-regexp nil t)
177           (notmuch-show-move-to-current-message-summary-line)
178           ))
179     (recenter 0)))
180
181 (defun notmuch-show-mark-read-then-next-message ()
182   "Remove unread tag from current message, then advance to next message."
183   (interactive)
184   (notmuch-show-remove-tag "unread")
185   (notmuch-show-next-message))
186
187 (defun notmuch-show-advance-marking-read-and-archiving ()
188   "Advance through buffer, marking read and archiving.
189
190 This command is intended to be one of the simplest ways to
191 process a thread of email. It does the following:
192
193 If the current message in the thread is not yet fully visible,
194 scroll by a near screenful to read more of the message.
195
196 Otherwise, (the end of the current message is already within the
197 current window), remove the \"unread\" tag from the current
198 message and advance to the next message.
199
200 Finally, if there is no further message to advance to, and this
201 last message is already read, then archive the entire current
202 thread, (remove the \"inbox\" tag from each message). Also kill
203 this buffer, and display the next thread from the search from
204 which this thread was originally shown."
205   (interactive)
206   (let ((next (notmuch-show-find-next-message))
207         (unread (member "unread" (notmuch-show-get-tags))))
208     (if (and (not unread)
209              (equal next (point)))
210         (progn
211           (notmuch-show-archive-thread)
212           (let ((parent-buffer notmuch-show-parent-buffer))
213             (kill-this-buffer)
214             (if parent-buffer
215                 (progn
216                   (switch-to-buffer parent-buffer)
217                   (notmuch-search-show-thread)))))
218       (if (< (notmuch-show-find-next-message) (window-end))
219           (notmuch-show-mark-read-then-next-message)
220         (scroll-up nil)))))
221
222 (defun notmuch-show-markup-citations-region (beg end)
223   (goto-char beg)
224   (beginning-of-line)
225   (while (< (point) end)
226     (let ((beg-sub (point)))
227       (if (looking-at ">")
228           (progn
229             (while (looking-at ">")
230               (next-line))
231             (let ((overlay (make-overlay beg-sub (point))))
232               (overlay-put overlay 'invisible 'notmuch-show-citation)
233               (overlay-put overlay 'before-string
234                            (concat "[" (number-to-string (count-lines beg-sub (point)))
235                                    " quoted lines.]")))))
236       (if (looking-at "--[ ]?$")
237           (let ((overlay (make-overlay beg-sub end)))
238             (overlay-put overlay 'invisible 'notmuch-show-signature)
239             (overlay-put overlay 'before-string
240                          (concat "[" (number-to-string (count-lines beg-sub (point)))
241                                  "-line signature.]"))
242             (goto-char end)))
243       (next-line))))
244
245 (defun notmuch-show-markup-body ()
246   (re-search-forward notmuch-show-body-begin-regexp)
247   (next-line 1)
248   (beginning-of-line)
249   (let ((beg (point)))
250     (re-search-forward notmuch-show-body-end-regexp)
251     (let ((end (match-beginning 0)))
252       (notmuch-show-markup-citations-region beg end)
253       (if (not (member "unread" (notmuch-show-get-tags)))
254           (overlay-put (make-overlay beg end)
255                        'invisible 'notmuch-show-body-read)))))
256
257 (defun notmuch-show-markup-header ()
258   (re-search-forward notmuch-show-header-begin-regexp)
259   (next-line 2)
260   (beginning-of-line)
261   (let ((beg (point)))
262     (re-search-forward notmuch-show-header-end-regexp)
263     (overlay-put (make-overlay beg (match-beginning 0))
264                  'invisible 'notmuch-show-header)))
265
266 (defun notmuch-show-markup-message ()
267   (if (re-search-forward notmuch-show-message-begin-regexp nil t)
268       (progn
269         (notmuch-show-markup-header)
270         (notmuch-show-markup-body))
271     (goto-char (point-max))))
272
273 (defun notmuch-show-hide-markers ()
274   (save-excursion
275     (goto-char (point-min))
276     (while (not (eobp))
277       (if (re-search-forward notmuch-show-marker-regexp nil t)
278           (progn
279             (overlay-put (make-overlay (match-beginning 0) (+ (match-end 0) 1))
280                          'invisible 'notmuch-show-marker))
281         (goto-char (point-max))))))
282
283 (defun notmuch-show-markup-messages ()
284   (save-excursion
285     (goto-char (point-min))
286     (while (not (eobp))
287       (notmuch-show-markup-message)))
288   (notmuch-show-hide-markers))
289
290 (defun notmuch-show-toggle-citations-visible ()
291   "Toggle visibility of citations"
292   (interactive)
293   (if notmuch-show-citations-visible
294       (add-to-invisibility-spec 'notmuch-show-citation)
295     (remove-from-invisibility-spec 'notmuch-show-citation))
296   (set 'notmuch-show-citations-visible (not notmuch-show-citations-visible))
297   ; Need to force the redisplay for some reason
298   (force-window-update)
299   (redisplay t))
300
301 (defun notmuch-show-toggle-signatures-visible ()
302   "Toggle visibility of signatures"
303   (interactive)
304   (if notmuch-show-signatures-visible
305       (add-to-invisibility-spec 'notmuch-show-signature)
306     (remove-from-invisibility-spec 'notmuch-show-signature))
307   (set 'notmuch-show-signatures-visible (not notmuch-show-signatures-visible))
308   ; Need to force the redisplay for some reason
309   (force-window-update)
310   (redisplay t))
311
312 (defun notmuch-show-toggle-headers-visible ()
313   "Toggle visibility of header fields"
314   (interactive)
315   (if notmuch-show-headers-visible
316       (add-to-invisibility-spec 'notmuch-show-header)
317     (remove-from-invisibility-spec 'notmuch-show-header))
318   (set 'notmuch-show-headers-visible (not notmuch-show-headers-visible))
319   ; Need to force the redisplay for some reason
320   (force-window-update)
321   (redisplay t))
322
323 (defun notmuch-show-toggle-body-read-visible ()
324   "Toggle visibility of message bodies of read messages"
325   (interactive)
326   (if notmuch-show-body-read-visible
327       (add-to-invisibility-spec 'notmuch-show-body-read)
328     (remove-from-invisibility-spec 'notmuch-show-body-read))
329   (set 'notmuch-show-body-read-visible (not notmuch-show-body-read-visible))
330   ; Need to force the redisplay for some reason
331   (force-window-update)
332   (redisplay t))
333
334 ;;;###autoload
335 (defun notmuch-show-mode ()
336   "Major mode for viewing a thread with notmuch.
337
338 This buffer contains the results of the \"notmuch show\" command
339 for displaying a single thread of email from your email archives.
340
341 By default, various components of email messages, (citations,
342 signatures, already-read messages), are invisible to help you
343 focus on the most important things, (new text from unread
344 messages). See the various commands below for toggling the
345 visibility of hidden components.
346
347 The `notmuch-show-next-message' and
348 `notmuch-show-previous-message' commands, (bound to 'n' and 'p by
349 default), allow you to navigate to the next and previous
350 messages. Each time you navigate away from a message with
351 `notmuch-show-next-message' the current message will have its
352 \"unread\" tag removed.
353
354 You can add or remove tags from the current message with '+' and
355 '-'.  You can also archive all messages in the current
356 view, (remove the \"inbox\" tag from each), with
357 `notmuch-show-archive-thread' (bound to 'a' by default).
358
359 \\{notmuch-show-mode-map}"
360   (interactive)
361   (kill-all-local-variables)
362   (set (make-local-variable 'notmuch-show-headers-visible) t)
363   (notmuch-show-toggle-headers-visible)
364   (set (make-local-variable 'notmuch-show-body-read-visible) t)
365   (notmuch-show-toggle-body-read-visible)
366   (set (make-local-variable 'notmuch-show-citations-visible) t)
367   (notmuch-show-toggle-citations-visible)
368   (set (make-local-variable 'notmuch-show-signatures-visible) t)
369   (notmuch-show-toggle-signatures-visible)
370   (add-to-invisibility-spec 'notmuch-show-marker)
371   (use-local-map notmuch-show-mode-map)
372   (setq major-mode 'notmuch-show-mode
373         mode-name "notmuch-show")
374   (setq buffer-read-only t))
375
376 (defun notmuch-show (thread-id &optional parent-buffer)
377   "Run \"notmuch show\" with the given thread ID and display results.
378
379 The optional PARENT-BUFFER is the notmuch-search buffer from
380 which this notmuch-show command was executed, (so that the next
381 thread from that buffer can be show when done with this one)."
382   (interactive "sNotmuch show: ")
383   (let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"))))
384     (switch-to-buffer buffer)
385     (notmuch-show-mode)
386     (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
387     (let ((proc (get-buffer-process (current-buffer)))
388           (inhibit-read-only t))
389       (if proc
390           (error "notmuch search process already running for query `%s'" query)
391         )
392       (erase-buffer)
393       (goto-char (point-min))
394       (save-excursion
395         (call-process "notmuch" nil t nil "show" thread-id)
396         (notmuch-show-markup-messages)
397         )
398       )))
399
400 (defvar notmuch-search-mode-map
401   (let ((map (make-sparse-keymap)))
402     (define-key map "a" 'notmuch-search-archive-thread)
403     (define-key map "b" 'scroll-down)
404     (define-key map "f" 'notmuch-search-filter)
405     (define-key map "n" 'next-line)
406     (define-key map "p" 'previous-line)
407     (define-key map "q" 'kill-this-buffer)
408     (define-key map "s" 'notmuch-search)
409     (define-key map "t" 'notmuch-search-filter-by-tag)
410     (define-key map "x" 'kill-this-buffer)
411     (define-key map (kbd "RET") 'notmuch-search-show-thread)
412     (define-key map "+" 'notmuch-search-add-tag)
413     (define-key map "-" 'notmuch-search-remove-tag)
414     (define-key map "<" 'beginning-of-buffer)
415     (define-key map ">" 'notmuch-search-goto-last-thread)
416     (define-key map "=" 'notmuch-search-refresh-view)
417     (define-key map "\M->" 'notmuch-search-goto-last-thread)
418     (define-key map " " 'scroll-up)
419     (define-key map (kbd "<DEL>") 'scroll-down)
420     map)
421   "Keymap for \"notmuch search\" buffers.")
422 (fset 'notmuch-search-mode-map notmuch-search-mode-map)
423
424 (defun notmuch-search-goto-last-thread (&optional arg)
425   "Move point to the last thread in the buffer."
426   (interactive "^P")
427   (end-of-buffer arg)
428   (beginning-of-line))
429
430 ;;;###autoload
431 (defun notmuch-search-mode ()
432   "Major mode for searching mail with notmuch.
433
434 This buffer contains the results of a \"notmuch search\" of your
435 email archives. Each line in the buffer represents a single
436 thread giving a relative date for the thread and a subject.
437
438 Pressing RET on any line displays that thread. The '+' and '-'
439 keys can be used to add or remove tags from a thread. The 'a' key
440 is a convenience key for archiving a thread (removing the
441 \"inbox\" tag).
442
443 Other useful commands are `notmuch-search-filter' for filtering
444 the current search based on an additional query string,
445 `notmuch-search-filter-by-tag' for filtering to include only
446 messages with a given tag, and `notmuch-search' to execute a new,
447 global search.
448
449 \\{notmuch-search-mode-map}"
450   (interactive)
451   (kill-all-local-variables)
452   (make-local-variable 'notmuch-search-query-string)
453   (set (make-local-variable 'scroll-preserve-screen-position) t)
454   (add-to-invisibility-spec 'notmuch-search)
455   (use-local-map notmuch-search-mode-map)
456   (setq major-mode 'notmuch-search-mode
457         mode-name "notmuch-search")
458   (setq buffer-read-only t))
459
460 (defun notmuch-search-find-thread-id ()
461   (save-excursion
462     (beginning-of-line)
463     (let ((beg (point)))
464       (re-search-forward "[a-fA-F0-9]*")
465       (filter-buffer-substring beg (point)))))
466
467 (defun notmuch-search-markup-this-thread-id ()
468   (beginning-of-line)
469   (let ((beg (point)))
470     (re-search-forward "[a-fA-F0-9]*")
471     (forward-char)
472     (overlay-put (make-overlay beg (point)) 'invisible 'notmuch-search)))
473
474 (defun notmuch-search-markup-thread-ids ()
475   (save-excursion
476     (goto-char (point-min))
477     (while (not (eobp))
478       (notmuch-search-markup-this-thread-id)
479       (next-line))))
480
481 (defun notmuch-search-hide-thread-ids ()
482   (interactive)
483   (add-to-invisibility-spec 'notmuch-search)
484   (force-window-update)
485   (redisplay t))
486
487 (defun notmuch-search-show-thread-ids ()
488   (interactive)
489   (remove-from-invisibility-spec 'notmuch-search)
490   (force-window-update)
491   (redisplay t))
492
493 (defun notmuch-search-show-thread ()
494   (interactive)
495   (let ((thread-id (notmuch-search-find-thread-id)))
496     (forward-line)
497     (notmuch-show thread-id (current-buffer))))
498
499 (defun notmuch-call-notmuch-process (&rest args)
500   (let ((error-buffer (get-buffer-create "*Notmuch errors*")))
501     (with-current-buffer error-buffer
502         (erase-buffer))
503     (if (eq (apply 'call-process "notmuch" nil error-buffer nil args) 0)
504         (point)
505       (progn
506         (with-current-buffer error-buffer
507           (let ((beg (point-min))
508                 (end (- (point-max) 1)))
509             (error (buffer-substring beg end))
510             ))))))
511
512 (defun notmuch-search-set-tags (tags)
513   (save-excursion
514     (end-of-line)
515     (re-search-backward "(")
516     (forward-char)
517     (let ((beg (point))
518           (inhibit-read-only t))
519       (re-search-forward ")")
520       (backward-char)
521       (let ((end (point)))
522         (delete-region beg end)
523         (insert (mapconcat  'identity tags " "))))))
524
525 (defun notmuch-search-get-tags ()
526   (save-excursion
527     (end-of-line)
528     (re-search-backward "(")
529     (let ((beg (+ (point) 1)))
530       (re-search-forward ")")
531       (let ((end (- (point) 1)))
532         (split-string (buffer-substring beg end))))))
533
534 (defun notmuch-search-add-tag (tag)
535   (interactive "sTag to add: ")
536   (notmuch-call-notmuch-process "tag" (concat "+" tag) (concat "thread:" (notmuch-search-find-thread-id)))
537   (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<))))
538
539 (defun notmuch-search-remove-tag (tag)
540   (interactive "sTag to remove: ")
541   (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "thread:" (notmuch-search-find-thread-id)))
542   (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))))
543
544 (defun notmuch-search-archive-thread ()
545   "Archive the current thread (remove its \"inbox\" tag).
546
547 This function advances point to the next line when finished."
548   (interactive)
549   (notmuch-search-remove-tag "inbox")
550   (forward-line))
551
552 (defun notmuch-search (query)
553   "Run \"notmuch search\" with the given query string and display results."
554   (interactive "sNotmuch search: ")
555   (let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*"))))
556     (switch-to-buffer buffer)
557     (notmuch-search-mode)
558     (set 'notmuch-search-query-string query)
559     (let ((proc (get-buffer-process (current-buffer)))
560           (inhibit-read-only t))
561       (if proc
562           (error "notmuch search process already running for query `%s'" query)
563         )
564       (erase-buffer)
565       (goto-char (point-min))
566       (save-excursion
567         (call-process "notmuch" nil t nil "search" query)
568         (notmuch-search-markup-thread-ids)
569         ; A well-behaved program ends its output with a newline, but we
570         ; don't actually want the blank line at the end of the file.
571         (goto-char (point-max))
572         (if (looking-at "^$")
573             (delete-backward-char 1)
574           )
575         ))))
576
577 (defun notmuch-search-refresh-view ()
578   "Refresh the current view.
579
580 Kills the current buffer and runs a new search with the same
581 query string as the current search. If the current thread is in
582 the new search results, then point will be placed on the same
583 thread. Otherwise, point will be moved to attempt to be in the
584 same relative position within the new buffer."
585   (interactive)
586   (let ((here (point))
587         (thread (notmuch-search-find-thread-id))
588         (query notmuch-search-query-string))
589     (kill-this-buffer)
590     (notmuch-search query)
591     (goto-char (point-min))
592     (if (re-search-forward (concat "^" thread) nil t)
593         (beginning-of-line)
594       (goto-char here))))
595
596 (defun notmuch-search-filter (query)
597   "Filter the current search results based on an additional query string.
598
599 Runs a new search matching only messages that match both the
600 current search results AND the additional query string provided."
601   (interactive "sFilter search: ")
602   (notmuch-search (concat notmuch-search-query-string " and " query)))
603
604 (defun notmuch-search-filter-by-tag (tag)
605   "Filter the current search results based on a single tag.
606
607 Runs a new search matching only messages that match both the
608 current search results AND that are tagged with the given tag."
609   (interactive "sFilter by tag: ")
610   (notmuch-search (concat notmuch-search-query-string " and tag:" tag)))
611
612 (defun notmuch ()
613   "Run notmuch to display all mail with tag of 'inbox'"
614   (interactive)
615   (notmuch-search "tag:inbox"))
616
617 (provide 'notmuch)