1 Return-Path: <daniel.schoepe@googlemail.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 2A63D429E25
\r
6 for <notmuch@notmuchmail.org>; Sat, 4 Jun 2011 05:20:00 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id qgnQ9tu2iNoB for <notmuch@notmuchmail.org>;
\r
17 Sat, 4 Jun 2011 05:19:58 -0700 (PDT)
\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id CC2AA431FB6
\r
22 for <notmuch@notmuchmail.org>; Sat, 4 Jun 2011 05:19:57 -0700 (PDT)
\r
23 Received: by bwg12 with SMTP id 12so2599371bwg.26
\r
24 for <notmuch@notmuchmail.org>; Sat, 04 Jun 2011 05:19:56 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=googlemail.com; s=gamma;
\r
27 h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer;
\r
28 bh=s2B53WZvF2Pva98jaCYuZL7OMk7SF2x/GQZJnB4jK5A=;
\r
29 b=g6sFUpGMH+uZVMLJ/QgT0MDbWyIi6cd7eyg8YTTn5VABZ+kxbzGOWcEV/eiwzcbDWF
\r
30 R8LJxfD4HT80mnAvKQsFj41pzExEUXTV7XZJJcbpSQnBeQzBpI/f9V4Zn0zJkZ0wZUxS
\r
31 5Jj0i6z2jdwqyjNeiZ3uX+eQx+Oz0Vp/in6Rc=
\r
32 DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma;
\r
33 h=from:to:cc:subject:date:message-id:x-mailer;
\r
34 b=pCD17xYBJls8Qd609X6NKMmVMpLTdp56UsBpBePF/16cYe1K1YoECgJ6kdKdNUBq5Z
\r
35 NT8LxBj8RdY0e+MBhQ7dw03TuEsQp6B/9lGdCI0YuuXr7uE3DdwYXuSusOMIMCEkTLTw
\r
36 zHE3mL0CbS/qwNvnWYNL5fFLMI+GAIv8RodwM=
\r
37 Received: by 10.204.154.199 with SMTP id p7mr2838188bkw.114.1307189996132;
\r
38 Sat, 04 Jun 2011 05:19:56 -0700 (PDT)
\r
39 Received: from localhost (dslb-088-069-155-133.pools.arcor-ip.net
\r
41 by mx.google.com with ESMTPS id 16sm1929000bkm.2.2011.06.04.05.19.54
\r
42 (version=TLSv1/SSLv3 cipher=OTHER);
\r
43 Sat, 04 Jun 2011 05:19:54 -0700 (PDT)
\r
44 From: Daniel Schoepe <daniel.schoepe@googlemail.com>
\r
45 To: notmuch@notmuchmail.org
\r
46 Subject: [PATCH] emacs: Tab completion for notmuch-search and
\r
47 notmuch-search-filter
\r
48 Date: Sat, 4 Jun 2011 14:19:30 +0200
\r
49 Message-Id: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com>
\r
50 X-Mailer: git-send-email 1.7.5.3
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Sat, 04 Jun 2011 12:20:00 -0000
\r
65 This patch adds completion with <tab> in the minibuffer for
\r
66 notmuch-search and notmuch-search-filter.
\r
68 emacs/notmuch.el | 33 +++++++++++++++++++++++++++++++--
\r
69 1 files changed, 31 insertions(+), 2 deletions(-)
\r
71 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
72 index 3311fe8..49a82be 100644
\r
73 --- a/emacs/notmuch.el
\r
74 +++ b/emacs/notmuch.el
\r
75 @@ -882,6 +882,35 @@ characters as well as `_.+-'.
\r
76 (concat "*notmuch-search-" query "*"))
\r
79 +(defun notmuch-query-completions (compls string)
\r
80 + "Return possible completions for STRING.
\r
82 +COMPLS should be a list of possibilities for an individual word."
\r
84 + ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
\r
85 + (mapcar (lambda (compl)
\r
86 + (concat (match-string-no-properties 1 string) compl))
\r
87 + (all-completions (match-string-no-properties 2 string)
\r
89 + (t (list string))))
\r
91 +(defun notmuch-read-query (prompt)
\r
92 + "Read a notmuch-query from the minibuffer with completion.
\r
94 +PROMPT is the string to prompt with."
\r
95 + (let* ((keymap (copy-keymap minibuffer-local-map))
\r
96 + (all-compls (append (list "folder:" "thread:" "id:" "date:" "from:"
\r
97 + "to:" "subject:" "attachment:")
\r
98 + (mapcar (lambda (tag)
\r
99 + (concat "tag:" tag))
\r
100 + (process-lines "notmuch" "search-tags")))
\r
101 + (minibuffer-completion-table (completion-table-dynamic
\r
102 + `(lambda (s) (notmuch-query-completions
\r
103 + (quote ,all-compls) s)))))
\r
104 + ;; ^ emulate a closure to avoid recomputing the completion list each time
\r
105 + (define-key keymap (kbd "<tab>") 'minibuffer-complete)
\r
106 + (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil)))
\r
109 (defun notmuch-search (query &optional oldest-first target-thread target-line continuation)
\r
110 "Run \"notmuch search\" with the given query string and display results.
\r
111 @@ -893,7 +922,7 @@ The optional parameters are used as follows:
\r
112 current if it appears in the search results.
\r
113 target-line: The line number to move to if the target thread does not
\r
114 appear in the search results."
\r
115 - (interactive "sNotmuch search: ")
\r
116 + (interactive (notmuch-read-query "Notmuch search: "))
\r
117 (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))
\r
118 (switch-to-buffer buffer)
\r
119 (notmuch-search-mode)
\r
120 @@ -991,7 +1020,7 @@ search."
\r
122 Runs a new search matching only messages that match both the
\r
123 current search results AND the additional query string provided."
\r
124 - (interactive "sFilter search: ")
\r
125 + (interactive (notmuch-read-query "Filter search: "))
\r
126 (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)
\r
127 (concat "( " query " )")
\r