1 Return-Path: <jrollins@finestructure.net>
\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 64077431FD0
\r
6 for <notmuch@notmuchmail.org>; Fri, 5 Aug 2011 14:07:42 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id RJgM7-H679Rt for <notmuch@notmuchmail.org>;
\r
16 Fri, 5 Aug 2011 14:07:41 -0700 (PDT)
\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu
\r
19 by olra.theworths.org (Postfix) with ESMTP id CAE47431FB6
\r
20 for <notmuch@notmuchmail.org>; Fri, 5 Aug 2011 14:07:41 -0700 (PDT)
\r
21 Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])
\r
22 by earth-doxen-postvirus (Postfix) with ESMTP id EFCF866E01F2
\r
23 for <notmuch@notmuchmail.org>; Fri, 5 Aug 2011 14:03:29 -0700 (PDT)
\r
24 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new
\r
25 Received: from finestructure.net (gwave-176.ligo.caltech.edu
\r
26 [131.215.114.176]) (Authenticated sender: jrollins) by earth-doxen-submit
\r
27 (Postfix) with ESMTP id 26FEE66E0177 for <notmuch@notmuchmail.org>; Fri, 5
\r
28 Aug 2011 14:03:28 -0700 (PDT)
\r
29 Received: by finestructure.net (Postfix, from userid 1000)
\r
30 id 08A162F5; Fri, 5 Aug 2011 14:03:28 -0700 (PDT)
\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>
\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
33 Subject: [PATCH] emacs: Tab completion for notmuch-search and
\r
34 notmuch-search-filter
\r
35 Date: Fri, 5 Aug 2011 14:03:28 -0700
\r
36 Message-Id: <1312578208-16170-1-git-send-email-jrollins@finestructure.net>
\r
37 X-Mailer: git-send-email 1.7.5.4
\r
38 In-Reply-To: <87liv7r2u3.fsf@servo.factory.finestructure.net>
\r
39 References: <87liv7r2u3.fsf@servo.factory.finestructure.net>
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Fri, 05 Aug 2011 21:07:42 -0000
\r
54 From: Daniel Schoepe <daniel.schoepe@googlemail.com>
\r
56 This patch adds completion with <tab> in the minibuffer for
\r
57 notmuch-search and notmuch-search-filter.
\r
59 This is a slightly tweaked version of this original patch that removes
\r
60 an errant space and uses "search --output=tags" instead of the
\r
61 deprecated "search-tags".
\r
63 emacs/notmuch.el | 33 +++++++++++++++++++++++++++++++--
\r
64 1 files changed, 31 insertions(+), 2 deletions(-)
\r
66 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
67 index 6bf42e8..053f0be 100644
\r
68 --- a/emacs/notmuch.el
\r
69 +++ b/emacs/notmuch.el
\r
70 @@ -877,6 +877,35 @@ characters as well as `_.+-'.
\r
71 (concat "*notmuch-search-" query "*"))
\r
74 +(defun notmuch-read-query (prompt)
\r
75 + "Read a notmuch-query from the minibuffer with completion.
\r
77 +PROMPT is the string to prompt with."
\r
80 + (append (list "folder:" "thread:" "id:" "date:" "from:" "to:"
\r
81 + "subject:" "attachment:")
\r
82 + (mapcar (lambda (tag)
\r
83 + (concat "tag:" tag))
\r
84 + (process-lines "notmuch" "search" "--output=tags" "*")))))
\r
85 + (let ((keymap (copy-keymap minibuffer-local-map))
\r
86 + (minibuffer-completion-table
\r
87 + (completion-table-dynamic
\r
89 + ;; generate a list of possible completions for the current input
\r
91 + ;; this ugly regexp is used to get the last word of the input
\r
92 + ;; possibly preceded by a '('
\r
93 + ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
\r
94 + (mapcar (lambda (compl)
\r
95 + (concat (match-string-no-properties 1 string) compl))
\r
96 + (all-completions (match-string-no-properties 2 string)
\r
98 + (t (list string)))))))
\r
99 + ;; this was simpler than convincing completing-read to accept spaces:
\r
100 + (define-key keymap (kbd "<tab>") 'minibuffer-complete)
\r
101 + (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil))))
\r
104 (defun notmuch-search (query &optional oldest-first target-thread target-line continuation)
\r
105 "Run \"notmuch search\" with the given query string and display results.
\r
106 @@ -888,7 +917,7 @@ The optional parameters are used as follows:
\r
107 current if it appears in the search results.
\r
108 target-line: The line number to move to if the target thread does not
\r
109 appear in the search results."
\r
110 - (interactive "sNotmuch search: ")
\r
111 + (interactive (list (notmuch-read-query "Notmuch search: ")))
\r
112 (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))
\r
113 (switch-to-buffer buffer)
\r
114 (notmuch-search-mode)
\r
115 @@ -986,7 +1015,7 @@ search."
\r
117 Runs a new search matching only messages that match both the
\r
118 current search results AND the additional query string provided."
\r
119 - (interactive "sFilter search: ")
\r
120 + (interactive (list (notmuch-read-query "Filter search: ")))
\r
121 (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)
\r
122 (concat "( " query " )")
\r