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 2A63D429E25 for ; Sat, 4 Jun 2011 05:20:00 -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 qgnQ9tu2iNoB for ; Sat, 4 Jun 2011 05:19:58 -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 CC2AA431FB6 for ; Sat, 4 Jun 2011 05:19:57 -0700 (PDT) Received: by bwg12 with SMTP id 12so2599371bwg.26 for ; Sat, 04 Jun 2011 05:19:56 -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; bh=s2B53WZvF2Pva98jaCYuZL7OMk7SF2x/GQZJnB4jK5A=; b=g6sFUpGMH+uZVMLJ/QgT0MDbWyIi6cd7eyg8YTTn5VABZ+kxbzGOWcEV/eiwzcbDWF R8LJxfD4HT80mnAvKQsFj41pzExEUXTV7XZJJcbpSQnBeQzBpI/f9V4Zn0zJkZ0wZUxS 5Jj0i6z2jdwqyjNeiZ3uX+eQx+Oz0Vp/in6Rc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=pCD17xYBJls8Qd609X6NKMmVMpLTdp56UsBpBePF/16cYe1K1YoECgJ6kdKdNUBq5Z NT8LxBj8RdY0e+MBhQ7dw03TuEsQp6B/9lGdCI0YuuXr7uE3DdwYXuSusOMIMCEkTLTw zHE3mL0CbS/qwNvnWYNL5fFLMI+GAIv8RodwM= Received: by 10.204.154.199 with SMTP id p7mr2838188bkw.114.1307189996132; Sat, 04 Jun 2011 05:19:56 -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 16sm1929000bkm.2.2011.06.04.05.19.54 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2011 05:19:54 -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 14:19:30 +0200 Message-Id: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com> X-Mailer: git-send-email 1.7.5.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: Sat, 04 Jun 2011 12:20:00 -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..49a82be 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