From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0FCCB429E36 for ; Wed, 25 Jan 2012 17:13:42 -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 wXaXj3RCCzoS for ; Wed, 25 Jan 2012 17:13:41 -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 1B90D431FBC for ; Wed, 25 Jan 2012 17:13:40 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so39603bkb.26 for ; Wed, 25 Jan 2012 17:13:39 -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; bh=B+fiWPQtxg1wFUgF/Rb8pDmAWN8mlmeliprC4VZ+MNE=; b=cA/N4mSkEXB/opKpmRKt9WbFr8UUvKmWMYlNTfIz7htk2pFgPBukMePS14HeWdTWmh bkgbkpAs3lgVDpwBvqQX1YFoz9N488gg4G0zksWCtRol7jdsrzfpZk5J8h4i16LOsRV1 Fmkc2AKNHxMbpwP/P6407In7cpLm/pkr8ehuA= Received: by 10.204.153.208 with SMTP id l16mr5726262bkw.116.1327540418153; Wed, 25 Jan 2012 17:13:38 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id iu2sm5024285bkb.0.2012.01.25.17.13.37 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jan 2012 17:13:37 -0800 (PST) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH] emacs: add completion to "tag all" operation ("*" binding) Date: Thu, 26 Jan 2012 05:12:31 +0400 Message-Id: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.8.3 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 01:13:42 -0000 The patch adds completion to "tag all" operation bound to "*" (`notmuch-search-operate-all' function). --- emacs/notmuch.el | 48 ++++++++++++++++++++++++++++++++++++------------ 1 files changed, 36 insertions(+), 12 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index e02966f..71b0221 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,33 @@ 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 search-terms prefixes) (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 search-terms prefixes) + (let ((tag-list (notmuch-tag-completions search-terms prefixes))) + (completing-read prompt tag-list))) + +(defun notmuch-select-tags-with-completion (prompt &optional search-terms prefixes) + (let ((tag-list (notmuch-tag-completions search-terms prefixes)) + (crm-separator " ") + (crm-local-completion-map (copy-keymap crm-local-completion-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)) @@ -860,16 +882,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 (list (notmuch-select-tags-with-completion + "Operation (+add -drop): notmuch tag " nil + '("+" "-")))) + (setq action (delete "" action)) + ;; Perform some validation + (let ((words action)) + (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)) (defun notmuch-search-buffer-title (query) "Returns the title for a buffer with notmuch search results." -- 1.7.8.3