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 5296C429E34 for ; Tue, 22 Oct 2013 12:51:18 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 FbcMHZGpI7nK for ; Tue, 22 Oct 2013 12:51:12 -0700 (PDT) Received: from dmz-mailsec-scanner-7.mit.edu (dmz-mailsec-scanner-7.mit.edu [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 4B553431FDE for ; Tue, 22 Oct 2013 12:51:07 -0700 (PDT) X-AuditID: 12074424-b7f528e0000009aa-96-5266d7286083 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id C7.D9.02474.827D6625; Tue, 22 Oct 2013 15:51:05 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r9MJp3AB015068; Tue, 22 Oct 2013 15:51:04 -0400 Received: from drake.dyndns.org (31-33-57.wireless.csail.mit.edu [128.31.33.57]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9MJp1no005192 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Tue, 22 Oct 2013 15:51:03 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1VYhym-0006yf-NX; Tue, 22 Oct 2013 15:51:00 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 2/8] emacs: Take prompt and current tags in `notmuch-read-tag-changes' Date: Tue, 22 Oct 2013 15:50:51 -0400 Message-Id: <1382471457-26056-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1382471457-26056-1-git-send-email-amdragon@mit.edu> References: <1382471457-26056-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrKt5PS3IYP8uRovrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEro7/pFHPBP8mKFT83MTYwLhftYuTkkBAwkfi/p50dwhaTuHBv PVsXIxeHkMA+RolnO+czQzgbGSXWdl+GyhxjkpjZcJQJwpnLKPHw6QywfjYBDYlt+5czgtgi AtISO+/OZu1i5OBgFlCT+NOlAhIWFgiTeHB0DlgJi4CqxIal38BaeQUcJF51rGGGOENJYuGp bawgNqeAo8T0ff/YQMYIAdWcusMxgZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl1zvdzM Er3UlNJNjKCgYXdR2cHYfEjpEKMAB6MSD++DlrQgIdbEsuLK3EOMkhxMSqK8EVeBQnxJ+SmV GYnFGfFFpTmpxYcYJTiYlUR4m32BcrwpiZVVqUX5MClpDhYlcd5bHPZBQgLpiSWp2ampBalF MFkZDg4lCV6ha0CNgkWp6akVaZk5JQhpJg5OkOE8QMOPgSzmLS5IzC3OTIfIn2JUlBLnFQZp FgBJZJTmwfXCovoVozjQK8K8DiBVPMCEANf9CmgwE9DgKUvABpckIqSkGhi1PD67b+Qq9hfo /FrZeifReEZF5bKynutdq60mC15SmOctcp6xPWCbgA3XB+/7c/IsrvvcvL1q2/nP6tKbctJ1 Dhoeq+SQOv5430vVgy84fI5WX4tOOKTOdb+5rUho5ZqbocsbX7FIxX370aOZslukm7nlgu4t 6bm5TKX10vkGUy3eK93if6jEUpyRaKjFXFScCADGglDCxQIAAA== 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: Tue, 22 Oct 2013 19:51:18 -0000 This modifies the interface of `notmuch-read-tag-changes' to take an optional prompt string as well as a list of existing tags instead of a query. This list of tags is used to populate the tag removal completions and lets the caller compute these in a more efficient/consistent manner than performing a potentially large or complex query. This patch also updates the sole current caller of `notmuch-read-tag-changes'. --- emacs/notmuch-tag.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index 064cfa8..f9c1740 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -188,7 +188,7 @@ the messages that were tagged" "Variable to store minibuffer history for `notmuch-read-tag-changes' function.") -(defun notmuch-tag-completions (&optional search-terms) +(defun notmuch-tag-completions (&rest search-terms) (if (null search-terms) (setq search-terms (list "*"))) (split-string @@ -202,14 +202,21 @@ 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 &rest search-terms) +(defun notmuch-read-tag-changes (current-tags &optional prompt initial-input) + "Prompt for tag changes in the minibuffer. + +CURRENT-TAGS is a list of tags that are present on the message or +messages to be changed. These are offered as tag removal +completions. CURRENT-TAGS may contain duplicates. PROMPT, if +non-nil, is the query string to present in the minibuffer. It +defaults to \"Tags\". INITIAL-INPUT, if non-nil, will be the +initial input in the minibuffer." + (let* ((all-tag-list (notmuch-tag-completions)) (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list)) - (remove-tag-list (mapcar (apply-partially 'concat "-") - (if (null search-terms) - all-tag-list - (notmuch-tag-completions search-terms)))) + (remove-tag-list (mapcar (apply-partially 'concat "-") current-tags)) (tag-list (append add-tag-list remove-tag-list)) + (prompt (concat (or prompt "Tags") " (+add -drop): ")) (crm-separator " ") ;; By default, space is bound to "complete word" function. ;; Re-bind it to insert a space instead. Note that @@ -219,7 +226,7 @@ the messages that were tagged" (set-keymap-parent map crm-local-completion-map) (define-key map " " 'self-insert-command) map))) - (delete "" (completing-read-multiple "Tags (+add -drop): " + (delete "" (completing-read-multiple prompt tag-list nil nil initial-input 'notmuch-read-tag-changes-history)))) @@ -260,7 +267,8 @@ 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 + (notmuch-tag-completions query) nil tag-changes)) (setq tag-changes (list tag-changes)))) (mapc (lambda (tag-change) (unless (string-match-p "^[-+]\\S-+$" tag-change) -- 1.8.4.rc3