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 ; Much of notmuch.el was written by looking at the implementation of
23 ; compile.el from the emacs distribution source which has the
24 ; following copyright and authorsip (and the identical license as
27 ; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
28 ; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
29 ; Free Software Foundation, Inc.
31 ; Authors: Roland McGrath <roland@gnu.org>,
32 ; Daniel Pfeiffer <occitan@esperanto.org>
34 (defvar notmuch-show-mode-map
35 (let ((map (make-sparse-keymap)))
36 (define-key map "x" 'kill-this-buffer)
38 "Keymap for \"notmuch show\" buffers.")
39 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
42 (defun notmuch-show-mode ()
43 "Major mode for handling the output of \"notmuch show\""
45 (kill-all-local-variables)
46 (use-local-map notmuch-show-mode-map)
47 (setq major-mode 'notmuch-show-mode
48 mode-name "notmuch-show")
49 (setq buffer-read-only t))
51 (defun notmuch-show (thread-id)
52 "Run \"notmuch show\" with the given thread ID and display results."
53 (interactive "sNotmuch show: ")
54 (let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"))))
55 (switch-to-buffer buffer)
57 (let ((proc (get-buffer-process (current-buffer)))
58 (inhibit-read-only t))
60 (error "notmuch search process already running for query `%s'" query)
65 (call-process "notmuch" nil t nil "show" thread-id)
69 (defvar notmuch-search-mode-map
70 (let ((map (make-sparse-keymap)))
71 (define-key map "n" 'next-line)
72 (define-key map "p" 'previous-line)
73 (define-key map "\r" 'notmuch-search-show-thread)
75 "Keymap for \"notmuch search\" buffers.")
76 (fset 'notmuch-search-mode-map notmuch-search-mode-map)
79 (defun notmuch-search-mode ()
80 "Major mode for handling the output of \"notmuch search\""
82 (kill-all-local-variables)
83 (use-local-map notmuch-search-mode-map)
84 (setq major-mode 'notmuch-search-mode
85 mode-name "notmuch-search")
86 (setq buffer-read-only t))
88 (defun notmuch-search-find-thread-id ()
92 (re-search-forward "[a-fA-F0-9]*")
93 (filter-buffer-substring beg (point)))))
95 (defun notmuch-search-show-thread ()
97 (notmuch-show (notmuch-search-find-thread-id)))
99 (defun notmuch-search-archive-thread ()
101 (if (eq (call-process "notmuch" nil (get-buffer-create "*Messages*") nil "tag" "-inbox" (concat "thread:" (notmuch-search-find-thread-id))) 0)
102 (let ((inhibit-read-only t))
105 (defun notmuch-search (query)
106 "Run \"notmuch search\" with the given query string and display results."
107 (interactive "sNotmuch search: ")
108 (let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*"))))
109 (switch-to-buffer buffer)
110 (notmuch-search-mode)
111 (let ((proc (get-buffer-process (current-buffer)))
112 (inhibit-read-only t))
114 (error "notmuch search process already running for query `%s'" query)
117 (beginning-of-buffer)
119 (call-process "notmuch" nil t nil "search" query)
124 "Run notmuch to display all mail with tag of 'inbox'"
126 (notmuch-search "tag:inbox"))