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 81B20429E25 for ; Sat, 4 Jun 2011 06:15:11 -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 kaJDeFiK82Ts for ; Sat, 4 Jun 2011 06:15:06 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-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 81E45431FB6 for ; Sat, 4 Jun 2011 06:15:06 -0700 (PDT) Received: by bwg12 with SMTP id 12so2621111bwg.26 for ; Sat, 04 Jun 2011 06:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=dd6JGytPvxkO9QBHDnbfmlM/OMiweP6B6H1osWct8xc=; b=ZPpPBq0iQA+OIxx8XQ9yLaMKqxa7RgyuMlskeiTSi0mF0dqkZ68Yb+Ea4BovjPpiXB Ciy0HhyMKkgdduNEmf+NCAzVNozOq4PRQ1FEbaeklMqytJ4k8OvRcKyTpyKYwb0vVjSF wNLqUtl+jJ4M+2uq74E6dgasaFjwXyTuf6iOc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=cDqQWTHYCW19CX1pVO4BMr3kP/njsr8jq39gySXILkpTN+ySYjCucLrUJeWtDNHbB6 I7wBujJvkxoZ88xYYeodDDAxxGGVBBTg7egBu9NDWsj1RVZkL4lw+ELhB5eJsgiQSAid T045MAgplBgdMIG3fveFLrkvQnGrW+t+e+Vlo= Received: by 10.204.19.19 with SMTP id y19mr2859411bka.164.1307193305120; Sat, 04 Jun 2011 06:15:05 -0700 (PDT) Received: from localhost (dslb-088-069-155-133.pools.arcor-ip.net [88.69.155.133]) by mx.google.com with ESMTPS id t23sm1950926bkf.16.2011.06.04.06.15.02 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2011 06:15:03 -0700 (PDT) From: Daniel Schoepe To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter Date: Sat, 4 Jun 2011 15:14:54 +0200 Message-Id: <1307193294-14051-1-git-send-email-daniel.schoepe@googlemail.com> X-Mailer: git-send-email 1.7.5.3 In-Reply-To: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com> References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.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: Sat, 04 Jun 2011 13:15:11 -0000 This patch adds completion with in the minibuffer for notmuch-search and notmuch-search-filter. --- emacs/notmuch.el | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..7b63dc9 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -882,6 +882,35 @@ characters as well as `_.+-'. (concat "*notmuch-search-" query "*")) ))) +(defun notmuch-query-completions (compls string) + "Return possible completions for STRING. + +COMPLS should be a list of possibilities for an individual word." + (cond + ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string) + (mapcar (lambda (compl) + (concat (match-string-no-properties 1 string) compl)) + (all-completions (match-string-no-properties 2 string) + compls))) + (t (list string)))) + +(defun notmuch-read-query (prompt) + "Read a notmuch-query from the minibuffer with completion. + +PROMPT is the string to prompt with." + (let* ((keymap (copy-keymap minibuffer-local-map)) + (all-compls (append (list "folder:" "thread:" "id:" "date:" "from:" + "to:" "subject:" "attachment:") + (mapcar (lambda (tag) + (concat "tag:" tag)) + (process-lines "notmuch" "search-tags")))) + (minibuffer-completion-table (completion-table-dynamic + `(lambda (s) (notmuch-query-completions + (quote ,all-compls) s))))) + ;; ^ emulate a closure to avoid recomputing the completion list each time + (define-key keymap (kbd "") 'minibuffer-complete) + (read-from-minibuffer prompt nil keymap nil minibuffer-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 +922,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 (notmuch-read-query "Notmuch search: ")) (let ((buffer (get-buffer-create (notmuch-search-buffer-title query)))) (switch-to-buffer buffer) (notmuch-search-mode) @@ -991,7 +1020,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 (notmuch-read-query "Filter search: ")) (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query) (concat "( " query " )") query))) -- 1.7.5.3