[PATCH] emacs: add completion to "tag all" operation ("*" binding)
[notmuch-archives.git] / a6 / 297b966519c30b54996c11f91131a9f95c1eb0
1 Return-Path: <dmitry.kurochkin@gmail.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 0FCCB429E36\r
6         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:13:42 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \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 wXaXj3RCCzoS for <notmuch@notmuchmail.org>;\r
17         Wed, 25 Jan 2012 17:13:41 -0800 (PST)\r
18 Received: from mail-bk0-f53.google.com (mail-bk0-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 1B90D431FBC\r
22         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:13:40 -0800 (PST)\r
23 Received: by bkbzt19 with SMTP id zt19so39603bkb.26\r
24         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:13:39 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:subject:date:message-id:x-mailer;\r
27         bh=B+fiWPQtxg1wFUgF/Rb8pDmAWN8mlmeliprC4VZ+MNE=;\r
28         b=cA/N4mSkEXB/opKpmRKt9WbFr8UUvKmWMYlNTfIz7htk2pFgPBukMePS14HeWdTWmh\r
29         bkgbkpAs3lgVDpwBvqQX1YFoz9N488gg4G0zksWCtRol7jdsrzfpZk5J8h4i16LOsRV1\r
30         Fmkc2AKNHxMbpwP/P6407In7cpLm/pkr8ehuA=\r
31 Received: by 10.204.153.208 with SMTP id l16mr5726262bkw.116.1327540418153;\r
32         Wed, 25 Jan 2012 17:13:38 -0800 (PST)\r
33 Received: from localhost ([91.144.186.21])\r
34         by mx.google.com with ESMTPS id iu2sm5024285bkb.0.2012.01.25.17.13.37\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Wed, 25 Jan 2012 17:13:37 -0800 (PST)\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH] emacs: add completion to "tag all" operation ("*" binding)\r
40 Date: Thu, 26 Jan 2012 05:12:31 +0400\r
41 Message-Id: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>\r
42 X-Mailer: git-send-email 1.7.8.3\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Thu, 26 Jan 2012 01:13:42 -0000\r
56 \r
57 The patch adds <tab> completion to "tag all" operation bound to "*"\r
58 (`notmuch-search-operate-all' function).\r
59 ---\r
60  emacs/notmuch.el |   48 ++++++++++++++++++++++++++++++++++++------------\r
61  1 files changed, 36 insertions(+), 12 deletions(-)\r
62 \r
63 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
64 index e02966f..71b0221 100644\r
65 --- a/emacs/notmuch.el\r
66 +++ b/emacs/notmuch.el\r
67 @@ -48,6 +48,7 @@\r
68  ;; required, but is available from http://notmuchmail.org).\r
69  \r
70  (eval-when-compile (require 'cl))\r
71 +(require 'crm)\r
72  (require 'mm-view)\r
73  (require 'message)\r
74  \r
75 @@ -75,12 +76,33 @@ For example:\r
76  (defvar notmuch-query-history nil\r
77    "Variable to store minibuffer history for notmuch queries")\r
78  \r
79 -(defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
80 +(defun notmuch-tag-completions (&optional search-terms prefixes)\r
81    (let ((tag-list\r
82          (with-output-to-string\r
83            (with-current-buffer standard-output\r
84              (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))\r
85 -    (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))\r
86 +    (setq tag-list (split-string tag-list "\n+" t))\r
87 +    (if (null prefixes)\r
88 +       tag-list\r
89 +      (apply #'append\r
90 +            (mapcar (lambda (tag)\r
91 +                      (mapcar (lambda (prefix)\r
92 +                                (concat prefix tag)) prefixes))\r
93 +                    tag-list)))))\r
94 +\r
95 +(defun notmuch-select-tag-with-completion (prompt &optional search-terms prefixes)\r
96 +  (let ((tag-list (notmuch-tag-completions search-terms prefixes)))\r
97 +    (completing-read prompt tag-list)))\r
98 +\r
99 +(defun notmuch-select-tags-with-completion (prompt &optional search-terms prefixes)\r
100 +  (let ((tag-list (notmuch-tag-completions search-terms prefixes))\r
101 +       (crm-separator " ")\r
102 +       (crm-local-completion-map (copy-keymap crm-local-completion-map)))\r
103 +    ;; By default, space is bound to "complete word" function.\r
104 +    ;; Re-bind it to insert a space instead.  Note that <tab> still\r
105 +    ;; does the completion.\r
106 +    (define-key crm-local-completion-map " " 'self-insert-command)\r
107 +    (completing-read-multiple prompt tag-list)))\r
108  \r
109  (defun notmuch-foreach-mime-part (function mm-handle)\r
110    (cond ((stringp (car mm-handle))\r
111 @@ -860,16 +882,18 @@ will prompt for tags to be added or removed. Tags prefixed with\r
112  Each character of the tag name may consist of alphanumeric\r
113  characters as well as `_.+-'.\r
114  "\r
115 -  (interactive "sOperation (+add -drop): notmuch tag ")\r
116 -  (let ((action-split (split-string action " +")))\r
117 -    ;; Perform some validation\r
118 -    (let ((words action-split))\r
119 -      (when (null words) (error "No operation given"))\r
120 -      (while words\r
121 -       (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))\r
122 -         (error "Action must be of the form `+thistag -that_tag'"))\r
123 -       (setq words (cdr words))))\r
124 -    (apply 'notmuch-tag notmuch-search-query-string action-split)))\r
125 +  (interactive (list (notmuch-select-tags-with-completion\r
126 +                     "Operation (+add -drop): notmuch tag " nil\r
127 +                     '("+" "-"))))\r
128 +  (setq action (delete "" action))\r
129 +  ;; Perform some validation\r
130 +  (let ((words action))\r
131 +    (when (null words) (error "No operation given"))\r
132 +    (while words\r
133 +      (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))\r
134 +       (error "Action must be of the form `+thistag -that_tag'"))\r
135 +      (setq words (cdr words))))\r
136 +  (apply 'notmuch-tag notmuch-search-query-string action))\r
137  \r
138  (defun notmuch-search-buffer-title (query)\r
139    "Returns the title for a buffer with notmuch search results."\r
140 -- \r
141 1.7.8.3\r
142 \r