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 5743F431FAF for ; Wed, 25 Jan 2012 18:46:21 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.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 eVlZHLhR8EyI for ; Wed, 25 Jan 2012 18:46:20 -0800 (PST) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 366B6431FAE for ; Wed, 25 Jan 2012 18:46:20 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so92251bkb.26 for ; Wed, 25 Jan 2012 18:46:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=UNvhxVoM5IGvXycrX8QL5mC1md562khPLwutApwzDFg=; b=YlkMgjxvP4NS9ozqRrQWoMBCXbPdHkBDus2lvVVp+XeUnUu7Lvu4AnJfAljgjCOfrR 4SrAdzJq8dTPDzDoh5OngopMH+025f220IhuIkzIUSNYBq8f6niyt5HSb8rM0IyxK0kr 8iES0AvRwVp1FeBGLInze9woKT6T8Y4YlhIHE= Received: by 10.204.130.28 with SMTP id q28mr131388bks.10.1327545978824; Wed, 25 Jan 2012 18:46:18 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id ek9sm5324251bkb.10.2012.01.25.18.46.17 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jan 2012 18:46:18 -0800 (PST) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH v3] emacs: add completion to "tag all" operation ("*" binding) Date: Thu, 26 Jan 2012 06:45:12 +0400 Message-Id: <1327545912-16754-1-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com> References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@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: Thu, 26 Jan 2012 02:46:21 -0000 The patch adds completion to "tag all" operation bound to "*" (`notmuch-search-operate-all' function). --- Changes: v3: * fixed comments from Austin's review [1] v2: * s/thistag/this_tag/ for consistency with "that_tag", since we touch the line anyway Regards, Dmitry [1] id:"20120126013727.GB1176@mit.edu" emacs/notmuch-show.el | 4 +- emacs/notmuch.el | 55 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index e6a5b31..b23a981 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -38,7 +38,7 @@ (declare-function notmuch-call-notmuch-process "notmuch" (&rest args)) (declare-function notmuch-fontify-headers "notmuch" nil) -(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms)) +(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &optional prefixes &rest search-terms)) (declare-function notmuch-search-show-thread "notmuch" nil) (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") @@ -1474,7 +1474,7 @@ the result." "Remove a tag from the current message." (interactive (list (notmuch-select-tag-with-completion - "Tag to remove: " (notmuch-show-get-message-id)))) + "Tag to remove: " nil (notmuch-show-get-message-id)))) (let* ((current-tags (notmuch-show-get-tags)) (new-tags (notmuch-show-del-tags-worker current-tags toremove))) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index e02966f..ba8f8e1 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -48,6 +48,7 @@ ;; required, but is available from http://notmuchmail.org). (eval-when-compile (require 'cl)) +(require 'crm) (require 'mm-view) (require 'message) @@ -75,12 +76,36 @@ For example: (defvar notmuch-query-history nil "Variable to store minibuffer history for notmuch queries") -(defun notmuch-select-tag-with-completion (prompt &rest search-terms) +(defun notmuch-tag-completions (&optional prefixes search-terms) (let ((tag-list (with-output-to-string (with-current-buffer standard-output (apply 'call-process notmuch-command nil t nil "search-tags" search-terms))))) - (completing-read prompt (split-string tag-list "\n+" t) nil nil nil))) + (setq tag-list (split-string tag-list "\n+" t)) + (if (null prefixes) + tag-list + (apply #'append + (mapcar (lambda (tag) + (mapcar (lambda (prefix) + (concat prefix tag)) prefixes)) + tag-list))))) + +(defun notmuch-select-tag-with-completion (prompt &optional prefixes &rest search-terms) + (let ((tag-list (notmuch-tag-completions prefixes search-terms))) + (completing-read prompt tag-list))) + +(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms) + (let ((tag-list (notmuch-tag-completions prefixes search-terms)) + (crm-separator " ") + (crm-local-completion-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map crm-local-completion-map) + map))) + ;; By default, space is bound to "complete word" function. + ;; Re-bind it to insert a space instead. Note that still + ;; does the completion. + (define-key crm-local-completion-map " " 'self-insert-command) + (completing-read-multiple prompt tag-list))) (defun notmuch-foreach-mime-part (function mm-handle) (cond ((stringp (car mm-handle)) @@ -606,7 +631,7 @@ The tag is removed from all messages in the currently selected thread or threads in the current region." (interactive (list (notmuch-select-tag-with-completion - "Tag to remove: " + "Tag to remove: " nil (if (region-active-p) (mapconcat 'identity (notmuch-search-find-thread-id-region (region-beginning) (region-end)) @@ -849,7 +874,7 @@ non-authors is found, assume that all of the authors match." (goto-char found-target))) (delete-process proc)))) -(defun notmuch-search-operate-all (action) +(defun notmuch-search-operate-all (&rest actions) "Add/remove tags from all matching messages. This command adds or removes tags from all messages matching the @@ -860,16 +885,18 @@ will prompt for tags to be added or removed. Tags prefixed with Each character of the tag name may consist of alphanumeric characters as well as `_.+-'. " - (interactive "sOperation (+add -drop): notmuch tag ") - (let ((action-split (split-string action " +"))) - ;; Perform some validation - (let ((words action-split)) - (when (null words) (error "No operation given")) - (while words - (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words)) - (error "Action must be of the form `+thistag -that_tag'")) - (setq words (cdr words)))) - (apply 'notmuch-tag notmuch-search-query-string action-split))) + (interactive (notmuch-select-tags-with-completion + "Operations (+add -drop): notmuch tag " + '("+" "-"))) + (setq actions (delete "" actions)) + ;; Perform some validation + (let ((words actions)) + (when (null words) (error "No operations given")) + (while words + (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words)) + (error "Action must be of the form `+this_tag' or `-that_tag'")) + (setq words (cdr words)))) + (apply 'notmuch-tag notmuch-search-query-string actions)) (defun notmuch-search-buffer-title (query) "Returns the title for a buffer with notmuch search results." -- 1.7.8.3