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