Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / da / 3e3f54dfe2c6236292419aa3f61dc4e7d6302b
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 8B9BF429E36\r
6         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:27: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 RuO7CbP5X9Jw for <notmuch@notmuchmail.org>;\r
17         Wed, 25 Jan 2012 17:27: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 A61BE431FBC\r
22         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:27:41 -0800 (PST)\r
23 Received: by bkbzt19 with SMTP id zt19so47449bkb.26\r
24         for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:27:40 -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:in-reply-to:references;\r
27         bh=c7W7zR09RLIxlkJR8yK5He/WUVJ6lXceNk3DHrrwEYE=;\r
28         b=j+BV8lQrOEvWWtxeoHsLjtQo6FKt/ji/P2SVWmXbwxjvSc9Z3kxeU7qumPPq91fFjI\r
29         W8f4dddzezR2SH30b6xKR4Cpz5+JnXm6jr8zbOnv+isUmZ5vNIWTQwI/hzdcIqeSqzur\r
30         sJggDfbd+b7g/LUZrfIU2JZm+RhxSv5JvjkIs=\r
31 Received: by 10.204.150.81 with SMTP id x17mr29879bkv.27.1327541260311;\r
32         Wed, 25 Jan 2012 17:27:40 -0800 (PST)\r
33 Received: from localhost ([91.144.186.21])\r
34         by mx.google.com with ESMTPS id iu2sm5094284bkb.0.2012.01.25.17.27.39\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Wed, 25 Jan 2012 17:27:39 -0800 (PST)\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v2] emacs: add completion to "tag all" operation ("*" binding)\r
40 Date: Thu, 26 Jan 2012 05:26:34 +0400\r
41 Message-Id: <1327541194-9722-1-git-send-email-dmitry.kurochkin@gmail.com>\r
42 X-Mailer: git-send-email 1.7.8.3\r
43 In-Reply-To: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>\r
44 References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Thu, 26 Jan 2012 01:27:42 -0000\r
58 \r
59 The patch adds <tab> completion to "tag all" operation bound to "*"\r
60 (`notmuch-search-operate-all' function).\r
61 ---\r
62 \r
63 Changes in v2:\r
64 \r
65 * s/thistag/this_tag/ for consistency with "that_tag", since we touch\r
66   the line anyway\r
67 \r
68 Regards,\r
69   Dmitry\r
70 \r
71  emacs/notmuch.el |   48 ++++++++++++++++++++++++++++++++++++------------\r
72  1 files changed, 36 insertions(+), 12 deletions(-)\r
73 \r
74 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
75 index e02966f..a57bf70 100644\r
76 --- a/emacs/notmuch.el\r
77 +++ b/emacs/notmuch.el\r
78 @@ -48,6 +48,7 @@\r
79  ;; required, but is available from http://notmuchmail.org).\r
80  \r
81  (eval-when-compile (require 'cl))\r
82 +(require 'crm)\r
83  (require 'mm-view)\r
84  (require 'message)\r
85  \r
86 @@ -75,12 +76,33 @@ For example:\r
87  (defvar notmuch-query-history nil\r
88    "Variable to store minibuffer history for notmuch queries")\r
89  \r
90 -(defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
91 +(defun notmuch-tag-completions (&optional search-terms prefixes)\r
92    (let ((tag-list\r
93          (with-output-to-string\r
94            (with-current-buffer standard-output\r
95              (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))\r
96 -    (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))\r
97 +    (setq tag-list (split-string tag-list "\n+" t))\r
98 +    (if (null prefixes)\r
99 +       tag-list\r
100 +      (apply #'append\r
101 +            (mapcar (lambda (tag)\r
102 +                      (mapcar (lambda (prefix)\r
103 +                                (concat prefix tag)) prefixes))\r
104 +                    tag-list)))))\r
105 +\r
106 +(defun notmuch-select-tag-with-completion (prompt &optional search-terms prefixes)\r
107 +  (let ((tag-list (notmuch-tag-completions search-terms prefixes)))\r
108 +    (completing-read prompt tag-list)))\r
109 +\r
110 +(defun notmuch-select-tags-with-completion (prompt &optional search-terms prefixes)\r
111 +  (let ((tag-list (notmuch-tag-completions search-terms prefixes))\r
112 +       (crm-separator " ")\r
113 +       (crm-local-completion-map (copy-keymap crm-local-completion-map)))\r
114 +    ;; By default, space is bound to "complete word" function.\r
115 +    ;; Re-bind it to insert a space instead.  Note that <tab> still\r
116 +    ;; does the completion.\r
117 +    (define-key crm-local-completion-map " " 'self-insert-command)\r
118 +    (completing-read-multiple prompt tag-list)))\r
119  \r
120  (defun notmuch-foreach-mime-part (function mm-handle)\r
121    (cond ((stringp (car mm-handle))\r
122 @@ -860,16 +882,18 @@ will prompt for tags to be added or removed. Tags prefixed with\r
123  Each character of the tag name may consist of alphanumeric\r
124  characters as well as `_.+-'.\r
125  "\r
126 -  (interactive "sOperation (+add -drop): notmuch tag ")\r
127 -  (let ((action-split (split-string action " +")))\r
128 -    ;; Perform some validation\r
129 -    (let ((words action-split))\r
130 -      (when (null words) (error "No operation given"))\r
131 -      (while words\r
132 -       (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))\r
133 -         (error "Action must be of the form `+thistag -that_tag'"))\r
134 -       (setq words (cdr words))))\r
135 -    (apply 'notmuch-tag notmuch-search-query-string action-split)))\r
136 +  (interactive (list (notmuch-select-tags-with-completion\r
137 +                     "Operation (+add -drop): notmuch tag " nil\r
138 +                     '("+" "-"))))\r
139 +  (setq action (delete "" action))\r
140 +  ;; Perform some validation\r
141 +  (let ((words action))\r
142 +    (when (null words) (error "No operation given"))\r
143 +    (while words\r
144 +      (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))\r
145 +       (error "Action must be of the form `+this_tag -that_tag'"))\r
146 +      (setq words (cdr words))))\r
147 +  (apply 'notmuch-tag notmuch-search-query-string action))\r
148  \r
149  (defun notmuch-search-buffer-title (query)\r
150    "Returns the title for a buffer with notmuch search results."\r
151 -- \r
152 1.7.8.3\r
153 \r