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 8B9BF429E36 for ; Wed, 25 Jan 2012 17:27: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 RuO7CbP5X9Jw for ; Wed, 25 Jan 2012 17:27: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 A61BE431FBC for ; Wed, 25 Jan 2012 17:27:41 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so47449bkb.26 for ; Wed, 25 Jan 2012 17:27:40 -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=c7W7zR09RLIxlkJR8yK5He/WUVJ6lXceNk3DHrrwEYE=; b=j+BV8lQrOEvWWtxeoHsLjtQo6FKt/ji/P2SVWmXbwxjvSc9Z3kxeU7qumPPq91fFjI W8f4dddzezR2SH30b6xKR4Cpz5+JnXm6jr8zbOnv+isUmZ5vNIWTQwI/hzdcIqeSqzur sJggDfbd+b7g/LUZrfIU2JZm+RhxSv5JvjkIs= Received: by 10.204.150.81 with SMTP id x17mr29879bkv.27.1327541260311; Wed, 25 Jan 2012 17:27:40 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id iu2sm5094284bkb.0.2012.01.25.17.27.39 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jan 2012 17:27:39 -0800 (PST) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: add completion to "tag all" operation ("*" binding) Date: Thu, 26 Jan 2012 05:26:34 +0400 Message-Id: <1327541194-9722-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 01:27:42 -0000 The patch adds completion to "tag all" operation bound to "*" (`notmuch-search-operate-all' function). --- Changes in v2: * s/thistag/this_tag/ for consistency with "that_tag", since we touch the line anyway Regards, Dmitry emacs/notmuch.el | 48 ++++++++++++++++++++++++++++++++++++------------ 1 files changed, 36 insertions(+), 12 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index e02966f..a57bf70 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 `+this_tag -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