[PATCH 2/5] emacs: allow the tag caller to specify possible completions.
authorMark Walters <markwalters1009@gmail.com>
Fri, 30 Nov 2012 08:21:28 +0000 (08:21 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:11 +0000 (09:51 -0800)
07/7afd140d5eeb527fc754f189ed6cb90a44a9e2 [new file with mode: 0644]

diff --git a/07/7afd140d5eeb527fc754f189ed6cb90a44a9e2 b/07/7afd140d5eeb527fc754f189ed6cb90a44a9e2
new file mode 100644 (file)
index 0000000..5e6fbec
--- /dev/null
@@ -0,0 +1,140 @@
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A631B431FC0\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 00:23:27 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id CdTiXX58HwRG for <notmuch@notmuchmail.org>;\r
+       Fri, 30 Nov 2012 00:23:25 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 95912431FBD\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 00:23:20 -0800 (PST)\r
+Received: by mail-we0-f181.google.com with SMTP id t11so77850wey.26\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 00:23:20 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=u8rN4bEUPi/AHwBU9koSVq66/aT0WL7fbyJgV8hVgro=;\r
+       b=DlPRn7QBiWeJWEZwmeU8UGORm6pBhE212fT9uqWnL2C1QbCWMd2C1PZQWkFBNkr208\r
+       mpqGuhvD32Fjmi5Utx442WMFn8yPseiw7qp2BWDL6QxGoKxX42qnD3DLTgMh3TgViNfX\r
+       q3dv+U6UHRtKYwNQtH0+nU/PpS06q/G7Wn8HqSUTS8d/3ReHVuBh/4VR1kl7+krYVwCJ\r
+       vxBwVEINeL9o0jxx2Badj9sqs7QPkp8+JKUccswLHJWFE4ZSAuST7eqWHzcnF9IR4pSA\r
+       cDGc8ltVAB5gcvdCDYW9cwKoGxefNoeiXnTxm9RC+ifh+HhlpCi69lBoSgBnjOe4bQIp\r
+       pBog==\r
+Received: by 10.216.90.11 with SMTP id d11mr166295wef.103.1354263800293;\r
+       Fri, 30 Nov 2012 00:23:20 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id gz3sm14294419wib.2.2012.11.30.00.23.19\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Fri, 30 Nov 2012 00:23:19 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/5] emacs: allow the tag caller to specify possible\r
+       completions.\r
+Date: Fri, 30 Nov 2012 08:21:28 +0000\r
+Message-Id: <1354263691-19715-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1354263691-19715-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1354263691-19715-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 30 Nov 2012 08:23:28 -0000\r
+\r
+From: markwalters1009 <markwalters1009@gmail.com>\r
+\r
+Previously notmuch tag would always query the database for possible\r
+tag completions (allowing all tags for + but only tags present in the\r
+messages being tagged for -). This allows the caller so specify these\r
+completion lists.\r
+---\r
+ emacs/notmuch-tag.el |   30 +++++++++++++++++++++++-------\r
+ 1 files changed, 23 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el\r
+index 1f3d8cf..c8508d1 100644\r
+--- a/emacs/notmuch-tag.el\r
++++ b/emacs/notmuch-tag.el\r
+@@ -68,13 +68,18 @@ the messages that were tagged"\r
+   (let ((tag-list (notmuch-tag-completions search-terms)))\r
+     (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))\r
\r
+-(defun notmuch-read-tag-changes (&optional initial-input search-terms)\r
++(defun notmuch-read-tag-changes (&optional initial-input\r
++                                         search-terms\r
++                                         negative-completions\r
++                                         positive-completions)\r
+   (let* ((all-tag-list (notmuch-tag-completions))\r
+-       (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))\r
++       (add-tag-list (mapcar (apply-partially 'concat "+")\r
++                             (or positive-completions all-tag-list)))\r
+        (remove-tag-list (mapcar (apply-partially 'concat "-")\r
+-                                (if search-terms\r
+-                                    (notmuch-tag-completions search-terms)\r
+-                                  all-tag-list)))\r
++                                (or negative-completions\r
++                                    (if search-terms\r
++                                        (notmuch-tag-completions search-terms)\r
++                                      all-tag-list))))\r
+        (tag-list (append add-tag-list remove-tag-list))\r
+        (crm-separator " ")\r
+        ;; By default, space is bound to "complete word" function.\r
+@@ -108,7 +113,7 @@ from TAGS if present."\r
+          (error "Changed tag must be of the form `+this_tag' or `-that_tag'")))))\r
+     (sort result-tags 'string<)))\r
\r
+-(defun notmuch-tag (query &optional tag-changes)\r
++(defun notmuch-tag (query &optional tag-changes negative-completions positive-completions)\r
+   "Add/remove tags in TAG-CHANGES to messages matching QUERY.\r
\r
+ QUERY should be a string containing the search-terms.\r
+@@ -119,6 +124,14 @@ interpreted as a single tag change.  If TAG-CHANGES is the string\r
+ \"-\" or \"+\", or null, then the user is prompted to enter the\r
+ tag changes.\r
\r
++NEGATIVE-COMPLETIONS and POSITIVE-COMPLETIONS should be lists of\r
++tags that should be used for tab-completion for\r
++removal (i.e. after a \"-\") and addition (i.e. after a\r
++\"+\") repectively. If either of these is nil the possible\r
++completions will be read from the notmuch database. This does not\r
++stop the removal or addition of a tag; it just changes which tags\r
++can be tag-completed.\r
++\r
+ Note: Other code should always use this function alter tags of\r
+ messages instead of running (notmuch-call-notmuch-process \"tag\" ..)\r
+ directly, so that hooks specified in notmuch-before-tag-hook and\r
+@@ -126,7 +139,10 @@ notmuch-after-tag-hook will be run."\r
+   ;; Perform some validation\r
+   (if (string-or-null-p tag-changes)\r
+       (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))\r
+-        (setq tag-changes (notmuch-read-tag-changes tag-changes query))\r
++        (setq tag-changes (notmuch-read-tag-changes tag-changes\r
++                                                    query\r
++                                                    negative-completions\r
++                                                    positive-completions))\r
+       (setq tag-changes (list tag-changes))))\r
+   (mapc (lambda (tag-change)\r
+         (unless (string-match-p "^[-+]\\S-+$" tag-change)\r
+-- \r
+1.7.9.1\r
+\r