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 75251429E29 for ; Sat, 4 Jun 2011 12:55:30 -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 OWp0STL1zwxw for ; Sat, 4 Jun 2011 12:55:29 -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 25F86431FB6 for ; Sat, 4 Jun 2011 12:55:29 -0700 (PDT) Received: by bwg12 with SMTP id 12so2773598bwg.26 for ; Sat, 04 Jun 2011 12:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=BTlj07blQ/QXJfujq6KIr7J5aT0V/qbVb+pZjdb/svU=; b=SFBlq4Z9QDurh54XNNOQWphbgtwwAHyZfJZLszZjxxjQNHmD12uEYMrhw+OW+vF+gB g31pSCaQAj9b2AnDZm5Lcd+HttXKF76Mcw2N88BUmxjtveoG+xdhYvMMq0C/bhIIYAsV 9VBYpN/c0jdw7fdBkWtKpABjP8GDM6PpI7NTc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; b=G6UDTYqi4MEAToOtSXEaE6yKNQA3KQgV05lZZmOKvbWTxk0+iIso7dLZTkLsFKompd S1Mn+AtIhU0owcEqU2N869ZevrWGVarx5PiCW/rtL2Eq53ykRWqYPjOCvdJj+14VFh+Y 4ojiXDhO+mBqdIM8eK2UfvZvEpJDvdRrE6Tvg= Received: by 10.204.7.88 with SMTP id c24mr1250533bkc.61.1307217327448; Sat, 04 Jun 2011 12:55:27 -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 k16sm2158983bks.1.2011.06.04.12.55.25 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2011 12:55:26 -0700 (PDT) From: Daniel Schoepe To: Austin Clements Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter In-Reply-To: References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com> User-Agent: Notmuch/0.5-217-gd1f0224 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Sat, 04 Jun 2011 21:55:13 +0200 Message-ID: <87mxhxjrry.fsf@gilead.invalid> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Cc: notmuch@notmuchmail.org 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 19:55:30 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, 4 Jun 2011 11:32:15 -0400, Austin Clements wrote: > Dynamic scoping is obnoxious, but I think programmed completion is > steeped in the assumption that you'll use it. This code would be much > simpler if notmuch-query-completions took only `string' and used the > dynamically-bound all-compls (which should probably be renamed > notmuch-completions or something if you do this). Then this could be > just > (minibuffer-completion-table (completion-table-dynamic > #'notmuch-query-completions))) > and there'd be no need for quasiquoting, comments, and fake lexical scopi= ng. Sounds reasonable, I guess I really should stop fighting all those ugly parts of elisp with unreadable constructs like that. I made it a global variable though to avoid compilation warnings about notmuch-completion being a free variable. Since it's contents are not dependent on how/where notmuch-read-query is called, this shouldn't cause any problems, except my personal discomfort arising from the use of side effects for something as simple as this. :) > > + (define-key keymap (kbd "") 'minibuffer-complete) >=20 > This probably deserves a comment about why you're doing so much work > to avoid completing-read (which I assume is because it also binds SPC, > even if require-match is nil, which is unfortunate). Yes, that was the reason. Another thing that bugs me, is that I did not find a better way of doing the completion: Ideally I'd like to just specify a list of completions for individual words and have emacs handle separating the input string into individual words, but I couldn't find any options to accomplish that. An updated patch is attached. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-emacs-Tab-completion-for-notmuch-search-and-notmuch-.patch Content-Transfer-Encoding: quoted-printable From=2070642aecbf63428d9bcedc108c55f65574a792e7 Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Sat, 4 Jun 2011 14:17:44 +0200 Subject: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter This patch adds completion with in the minibuffer for notmuch-search and notmuch-search-filter. =2D-- emacs/notmuch.el | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..17c214c 100644 =2D-- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) =20 +(defvar notmuch-completions nil + "List of completions used in notmuch-query-completions") + (defun notmuch-select-tag-with-completion (prompt &rest search-terms) (let ((tag-list (with-output-to-string @@ -882,6 +885,34 @@ characters as well as `_.+-'. (concat "*notmuch-search-" query "*")) ))) =20 +(defun notmuch-query-completions (string) + "Return possible completions for STRING." + (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) + notmuch-completions))) + (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)) + (minibuffer-completion-table (completion-table-dynamic #'notmuch-query-co= mpletions))) + ;; this was simpler than convincing completing-read to accept spaces: + (define-key keymap (kbd "") 'minibuffer-complete) + (setq notmuch-completions + (append (list "folder:" "thread:" "id:" "date:" "from:" "to:" + "subject:" "attachment:") + (mapcar (lambda (tag) + (concat "tag:" tag)) + (process-lines "notmuch" "search-tags")))) + (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil= ))) + ;;;###autoload (defun notmuch-search (query &optional oldest-first target-thread target-l= ine continuation) "Run \"notmuch search\" with the given query string and display results. @@ -893,7 +924,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." =2D (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 +1022,7 @@ search." =20 Runs a new search matching only messages that match both the current search results AND the additional query string provided." =2D (interactive "sFilter search: ") + (interactive (notmuch-read-query "Filter search: ")) (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-rege= xp query) (concat "( " query " )") query))) =2D-=20 1.7.5.3 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJN6o2iAAoJEIaTAtce+Z+JJBkP/jJtzFb/DDMBD1loU9a/vdUg X7GJRZwIijPoT59bsjlwwI+ArsPzAWcRK2fulyEiEjXcK+SQqThoUNR+9PuW8s8/ ym5e/+lDiGFxk7txUUfNzUpY9/I3tc773C6f2xkRHPN2fPdAi9wOPMJNYm1ckp3F XpMAX0xYb/ebXNFulbpEnyVB9hsXlQXOyQVhomWdIdf+LULlyLkD9nVWx+sXNiQS ksB9GdwfuWdQY8A5Wf18Y/7RBYdkrZTB36nG3ZTDe+ARBLyvwLFQNwr2io6wF7IS dd+GciK2EnpvX8hB1B83g+1Nc/nsuT5fvn7YDIGGnnE4ILOm5hPvTpZqcEE2jbXN X7ST0NRQiDhmsEqIHx01hbzWl1+FXG0vDECTfZyq8dF5nKR8ea+Ry36q8JQa4/Xc Lth8PDQTehkrLleTtUtjtiO/AbH165frPA+UlZkltSEFiApWeTUJU+BKOT78BV+U oJgwLrdHMKdgjjHhiZyViJwXV2WSj4wvN2u+Pa5UrYtxq6gtQ6cG81S9pQENXf0g ZtQfbGPjvYdBEwCpDAxBe4oXM+K4x2zGe4v58A+p7NmPTQBr741yHz9CqoY7ASDl 55LZ8H1pw7gzIATLXwrpcL0OqghJas1Mp3UXNzQ6gn5/5I2X6NS0d4ThSXTg9Eif k1FdFpHwlAvRqqae781K =FOTO -----END PGP SIGNATURE----- --==-=-=--