[notmuch] [PATCH] Add notmuch-folder mode to provide an overview of search matches
[notmuch-archives.git] / ee / 362bf638fee32f6f46fb221f2c70ff1d752797
1 Return-Path: <keithp@keithp.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 0B9E0431FC2\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 11:59:17 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id YFwVhgBzhxjs for <notmuch@notmuchmail.org>;\r
11         Sat, 21 Nov 2009 11:59:16 -0800 (PST)\r
12 Received: from keithp.com (home.keithp.com [63.227.221.253])\r
13         by olra.theworths.org (Postfix) with ESMTP id 0CE6C431FBF\r
14         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 11:59:16 -0800 (PST)\r
15 Received: from localhost (localhost [127.0.0.1])\r
16         by keithp.com (Postfix) with ESMTP id 39C9576012C\r
17         for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 11:59:15 -0800 (PST)\r
18 X-Virus-Scanned: Debian amavisd-new at keithp.com\r
19 Received: from keithp.com ([127.0.0.1])\r
20         by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024)\r
21         with LMTP id xyQakEznsSqE; Sat, 21 Nov 2009 11:59:12 -0800 (PST)\r
22 Received: by keithp.com (Postfix, from userid 1033)\r
23         id 0E13C76012B; Sat, 21 Nov 2009 11:59:12 -0800 (PST)\r
24 Received: from koto.keithp.com (localhost [127.0.0.1])\r
25         by keithp.com (Postfix) with ESMTP id 095B876012A;\r
26         Sat, 21 Nov 2009 11:59:12 -0800 (PST)\r
27 Received: by koto.keithp.com (Postfix, from userid 1488)\r
28         id AA2051581B7; Sat, 21 Nov 2009 11:59:11 -0800 (PST)\r
29 From: Keith Packard <keithp@keithp.com>\r
30 To: notmuch@notmuchmail.org\r
31 Date: Sat, 21 Nov 2009 11:59:00 -0800\r
32 Message-Id: <1258833540-32299-1-git-send-email-keithp@keithp.com>\r
33 X-Mailer: git-send-email 1.6.5.2\r
34 In-Reply-To: <1258787708-21121-3-git-send-email-keithp@keithp.com>\r
35 References: <1258787708-21121-3-git-send-email-keithp@keithp.com>\r
36 Subject: [notmuch] [PATCH] Add notmuch-folder mode to provide an overview of\r
37         search matches\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.12\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sat, 21 Nov 2009 19:59:17 -0000\r
51 \r
52 Folder mode takes a (user-configurable) list of search patterns and\r
53 produces a list of those patterns and the count of messages that they\r
54 match. When an entry in this list is selected, a search window with\r
55 the defined search is opened.  The set of folders is defined as a\r
56 list, each element contains the name of the folder and the query string\r
57 to count.\r
58 \r
59 Signed-off-by: Keith Packard <keithp@keithp.com>\r
60 ---\r
61  notmuch.el |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
62  1 files changed, 81 insertions(+), 0 deletions(-)\r
63 \r
64 diff --git a/notmuch.el b/notmuch.el\r
65 index 4f369de..7cab3c1 100644\r
66 --- a/notmuch.el\r
67 +++ b/notmuch.el\r
68 @@ -1046,4 +1046,85 @@ current search results AND that are tagged with the given tag."\r
69  \r
70  (setq mail-user-agent 'message-user-agent)\r
71  \r
72 +(defvar notmuch-folder-mode-map\r
73 +  (let ((map (make-sparse-keymap)))\r
74 +    (define-key map "n" 'next-line)\r
75 +    (define-key map "p" 'previous-line)\r
76 +    (define-key map "x" 'kill-this-buffer)\r
77 +    (define-key map "q" 'kill-this-buffer)\r
78 +    (define-key map "s" 'notmuch-search)\r
79 +    (define-key map (kbd "RET") 'notmuch-folder-show-search)\r
80 +    (define-key map "<" 'beginning-of-buffer)\r
81 +    (define-key map "=" 'notmuch-folder)\r
82 +    (define-key map "?" 'describe-mode)\r
83 +    (define-key map [mouse-1] 'notmuch-folder-show-search)\r
84 +    map)\r
85 +  "Keymap for \"notmuch folder\" buffers.")\r
86 +\r
87 +(fset 'notmuch-folder-mode-map notmuch-folder-mode-map)\r
88 +\r
89 +(defcustom notmuch-folders (quote (("inbox" . "tag:inbox") ("unread" . "tag:unread")))\r
90 +  "List of searches for the notmuch folder view"\r
91 +  :type '(alist :key-type (string) :value-type (string))\r
92 +  :group 'notmuch)\r
93 +  \r
94 +(defun notmuch-folder-mode ()\r
95 +  "Major mode for showing notmuch 'folders'.\r
96 +\r
97 +This buffer contains a list of messages counts returned by a\r
98 +customizable set of searches of your email archives. Each line\r
99 +in the buffer shows the search terms and the resulting message count.\r
100 +\r
101 +Pressing RET on any line opens a search window containing the\r
102 +results for the search terms in that line.\r
103 +\r
104 +\\{notmuch-folder-mode-map}"\r
105 +  (interactive)\r
106 +  (kill-all-local-variables)\r
107 +  (use-local-map 'notmuch-folder-mode-map)\r
108 +  (setq truncate-lines t)\r
109 +  (hl-line-mode 1)\r
110 +  (setq major-mode 'notmuch-folder-mode\r
111 +       mode-name "notmuch-folder")\r
112 +  (setq buffer-read-only t))\r
113 +\r
114 +(defun notmuch-folder-add (folders)\r
115 +  (if folders\r
116 +      (let ((name (car (car folders)))\r
117 +           (inhibit-read-only t)\r
118 +           (search (cdr (car folders))))\r
119 +       (insert name)\r
120 +       (indent-to 16 1)\r
121 +       (call-process notmuch-command nil t nil "count" search)\r
122 +       (notmuch-folder-add (cdr folders)))))\r
123 +\r
124 +(defun notmuch-folder-find-name ()\r
125 +  (save-excursion\r
126 +    (beginning-of-line)\r
127 +    (let ((beg (point)))\r
128 +      (forward-word)\r
129 +      (filter-buffer-substring beg (point)))))\r
130 +\r
131 +(defun notmuch-folder-show-search (&optional folder)\r
132 +  "Show a search window for the search related to the specified folder."\r
133 +  (interactive)\r
134 +  (if (null folder)\r
135 +      (setq folder (notmuch-folder-find-name)))\r
136 +  (let ((search (assoc folder notmuch-folders)))\r
137 +    (if search\r
138 +       (notmuch-search (cdr search) t))))\r
139 +\r
140 +(defun notmuch-folder ()\r
141 +  "Show the notmuch folder view and update the displayed counts."\r
142 +  (interactive)\r
143 +  (let ((buffer (get-buffer-create "*notmuch-folders*")))\r
144 +    (switch-to-buffer buffer)\r
145 +    (let ((inhibit-read-only t)\r
146 +         (n (line-number-at-pos)))\r
147 +      (erase-buffer)\r
148 +      (notmuch-folder-mode)\r
149 +      (notmuch-folder-add notmuch-folders)\r
150 +      (goto-char (point-min))\r
151 +      (goto-line n))))\r
152 +\r
153  (provide 'notmuch)\r
154 -- \r
155 1.6.5.2\r
156 \r