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 7D9D6431FD0 for ; Tue, 9 Aug 2011 10:34:43 -0700 (PDT) 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 KAl9dnxikMTp for ; Tue, 9 Aug 2011 10:34:43 -0700 (PDT) Received: from mail-ey0-f175.google.com (mail-ey0-f175.google.com [209.85.215.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id AA7DC431FB6 for ; Tue, 9 Aug 2011 10:34:42 -0700 (PDT) Received: by eyh6 with SMTP id 6so248106eyh.20 for ; Tue, 09 Aug 2011 10:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=ptmIPWCKa9be69fWZVFUqZvtZ3P/2QUXXuAFuaNuTcI=; b=MKI1W4U8bmOAitXIXTu+phg5KFJAn48bt8OEcWQ89kpjrZdtk1OHX6+WkSVbVdr712 kxBpB1PJN8ukScADrjjDqxitXMZn9jLlQmzEcevtooGTjP2nRsJs1rIIZOMvRYZ7pe7m wrV3xIr5KiJBKG5Sk57GMvZD3hN5vCRQHe+xo= Received: by 10.204.51.208 with SMTP id e16mr2215189bkg.121.1312911175205; Tue, 09 Aug 2011 10:32:55 -0700 (PDT) Received: from localhost (dslb-088-069-159-153.pools.arcor-ip.net [88.69.159.153]) by mx.google.com with ESMTPS id q1sm3159630faa.1.2011.08.09.10.32.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 09 Aug 2011 10:32:53 -0700 (PDT) From: Daniel Schoepe To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter Date: Tue, 9 Aug 2011 19:32:49 +0200 Message-Id: <1312911169-23054-1-git-send-email-daniel.schoepe@googlemail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <87aabnqdf0.fsf@servo.factory.finestructure.net> References: <87aabnqdf0.fsf@servo.factory.finestructure.net> 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, 09 Aug 2011 17:34:43 -0000 This patch adds completion with in the minibuffer for notmuch-search and notmuch-search-filter. --- emacs/notmuch.el | 37 +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f11ec24..bb7565c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) +(defvar notmuch-query-history nil + "Variable to store minibuffer history for notmuch queries") + (defun notmuch-select-tag-with-completion (prompt &rest search-terms) (let ((tag-list (with-output-to-string @@ -882,6 +885,36 @@ characters as well as `_.+-'. (concat "*notmuch-search-" query "*")) ))) +(defun notmuch-read-query (prompt) + "Read a notmuch-query from the minibuffer with completion. + +PROMPT is the string to prompt with." + (lexical-let + ((completions + (append (list "folder:" "thread:" "id:" "date:" "from:" "to:" + "subject:" "attachment:") + (mapcar (lambda (tag) + (concat "tag:" tag)) + (process-lines "notmuch" "search" "--output=tags" "*"))))) + (let ((keymap (copy-keymap minibuffer-local-map)) + (minibuffer-completion-table + (completion-table-dynamic + (lambda (string) + ;; generate a list of possible completions for the current input + (cond + ;; this ugly regexp is used to get the last word of the input + ;; possibly preceded by a '(' + ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string) + (mapcar (lambda (compl) + (concat (match-string-no-properties 1 string) compl)) + (all-completions (match-string-no-properties 2 string) + completions))) + (t (list string))))))) + ;; this was simpler than convincing completing-read to accept spaces: + (define-key keymap (kbd "") 'minibuffer-complete) + (read-from-minibuffer prompt nil keymap nil + 'notmuch-query-history nil nil)))) + ;;;###autoload (defun notmuch-search (query &optional oldest-first target-thread target-line continuation) "Run \"notmuch search\" with the given query string and display results. @@ -893,7 +926,7 @@ The optional parameters are used as follows: current if it appears in the search results. target-line: The line number to move to if the target thread does not appear in the search results." - (interactive "sNotmuch search: ") + (interactive (list (notmuch-read-query "Notmuch search: "))) (let ((buffer (get-buffer-create (notmuch-search-buffer-title query)))) (switch-to-buffer buffer) (notmuch-search-mode) @@ -991,7 +1024,7 @@ search." Runs a new search matching only messages that match both the current search results AND the additional query string provided." - (interactive "sFilter search: ") + (interactive (list (notmuch-read-query "Filter search: "))) (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query) (concat "( " query " )") query))) -- 1.7.5.4