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