]> git.notmuchmail.org Git - notmuch/blob - notmuch.el
32c2887bed5410853f5701e6ce4c422b867c2a5f
[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 ; 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
25 ; above):
26 ;
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.
30
31 ; Authors: Roland McGrath <roland@gnu.org>,
32 ;           Daniel Pfeiffer <occitan@esperanto.org>
33
34 (defvar notmuch-search-mode-map
35   (let ((map (make-sparse-keymap)))
36     (define-key map "n" 'next-line)
37     (define-key map "p" 'previous-line)
38     map)
39   "Keymap for \"notmuch search\" buffers.")
40 (fset 'notmuch-search-mode-map notmuch-search-mode-map)
41
42 ;;;###autoload
43 (defun notmuch-search-mode ()
44   "Major mode for handling the output of notmuch search"
45   (interactive)
46   (kill-all-local-variables)
47   (use-local-map notmuch-search-mode-map)
48   (setq major-mode 'notmuch-search-mode
49         mode-name "notmuch-search")
50   (setq buffer-read-only t))
51
52 (defun notmuch-search (query)
53   "Run \"notmuch search\" with the given query string and display results."
54   (interactive "sNotmuch search: ")
55   (let ((buffer (get-buffer-create (concat "*notmuch-search-" query))))
56     (switch-to-buffer buffer)
57     (notmuch-search-mode)
58     (let ((proc (get-buffer-process (current-buffer)))
59           (inhibit-read-only t))
60       (if proc
61           (error "notmuch search process already running for query `%s'" query)
62         )
63       (erase-buffer)
64       (beginning-of-buffer)
65       (save-excursion
66         (call-process "notmuch" nil t nil "search" query)
67         )
68       )))
69
70 (defun notmuch ()
71   "Run notmuch to display all mail with tag of 'inbox'"
72   (interactive)
73   (notmuch-search "tag:inbox"))
74
75 (provide 'notmuch)