From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 870C7429E2C for ; Sat, 4 Jun 2011 15:54:56 -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 BRdK3rxAtbgO for ; Sat, 4 Jun 2011 15:54:55 -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 32464431FB6 for ; Sat, 4 Jun 2011 15:54:55 -0700 (PDT) Received: by bwg12 with SMTP id 12so2829274bwg.26 for ; Sat, 04 Jun 2011 15:54:53 -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=PuCohA8+MnhAGfBOATMSRZyH+viURsTXEvfikpEIidM=; b=OtdwxqlRVNOYw4d6uGfgsBsDsIt//lDpb7WxRIsc8pwFHOEgrXF2SQjFTtDI9oH267 VNgmKGx4bsu787fE6Md76km7h6L8joMDNwN3ao2sJr7k3/MMLe21l9UPH99ELhLRJ5Ji OT/9xRH1mW56QGWqTsZDag2YRMBYviFwih1xw= 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=AaZRJxQYyinpO5SHwuqdTcnRoU2qYFKjiL0bwkpgBiFp+JUPrJ7kmy+B8fwcqFZHRc iIXcUvjOlrZSsx6MIV/apjqzrKNX3UcFaE1xknYO/N0RkH5uNQhJkv/7HVEbMsZbUngz +lBhX4OqDyCdJ0C7oieay5azPDHouHb7Ob024= Received: by 10.204.82.224 with SMTP id c32mr3304890bkl.161.1307228093761; Sat, 04 Jun 2011 15:54:53 -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 ek1sm2237091bkb.9.2011.06.04.15.54.51 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2011 15:54:52 -0700 (PDT) From: Daniel Schoepe To: Austin Clements Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter In-Reply-To: <20110604215523.GF29861@mit.edu> References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com> <87mxhxjrry.fsf@gilead.invalid> <20110604215523.GF29861@mit.edu> User-Agent: Notmuch/0.5-217-gd1f0224 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Sun, 05 Jun 2011 00:54:38 +0200 Message-ID: <87hb85jjgx.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 22:54:56 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, 4 Jun 2011 17:55:24 -0400, Austin Clements wrote: > Oh, sorry, I wasn't suggesting setq'ing a global. I agree that that's > really ugly. Rather, something like >=20 > (defun notmuch-query-completions (string) > ... as you have it now ...) >=20 > (defun notmuch-read-query (prompt) > (let ((notmuch-completions (append (list "folder:" ...))) > (keymap ...) > (minibuffer-completion-table ...)) > (read-from-minibuffer ...))) >=20 > Unfortunately, you still need the global defvar to avoid compilation > warnings, but this at least avoids the side-effects, and is probably > how programmed completion was intended to be used. Both alternatives seem about equally ugly to me, since the one using dynamic scoping still uses side-effects, because it still passes the completion information around without using it as an argument to notmuch-query-completions. At least defvar-ing a global variable and then never actually using it, seems somewhat unclean as well. > Alternatively, here's a completely different way to structure this > that avoids globals and dynamic scoping entirely. This is how some of > the standard completing read functions appear to work: Ah right, I forgot that using macros from cl is fine even in library code. --=-=-= 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=207768f41ac44213c5e2c1dc3b0f13e3edf1d97a26 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 | 36 ++++++++++++++++++++++++++++++++++-- 1 files changed, 34 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..33c34bd 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,35 @@ characters as well as `_.+-'. (concat "*notmuch-search-" query "*")) ))) =20 +(defun notmuch-read-query (prompt) + "Read a notmuch-query from the minibuffer with completion. + +PROMPT is the string to prompt with." + (lexical-let + ((completions=20 + (append (list "folder:" "thread:" "id:" "date:" "from:" "to:" + "subject:" "attachment:") + (mapcar (lambda (tag) + (concat "tag:" tag)) + (process-lines "notmuch" "search-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 minibuffer-history nil n= il)))) + ;;;###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 +925,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 (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 +1023,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 (list (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) iQIcBAEBAgAGBQJN6revAAoJEIaTAtce+Z+JOEwP/1sLQk12MjZ2+4TxZIgpQpri /2cZr5boUa128WDXFD7adLRQGoIPaYWkp5kNkHYqcc12Vo23fNRIh4dmchb0bdqL CVfW8aNID6rMrJ9XLQPuehTPo6IX2ixEpkARPC23XgYDDqEt5OJJzo07DDTOluwG LxLQ58vhu4B1yTm8OoD765ohHz89buDNchRblvPrlVVIaZ7nE2Jjd76J62Buayhc mv+f53n8sghK/k3m9nT2lOvuEK7ZvWpMPfe+O62HHhoE1bkSgxAV35Mo+eKjSWMT JIcdO7Pouflh2vleDhQcSxF7Sp5/3uC4nUnBRUbDUvDZkHPuzSLuG1ml2Z8yRanJ beegu6kuAVmrEb2HFDQbYjPOoh1lLYEZLXrWv2CbX5ouwDPa+HBHuc8xgXAmx1oH /BtrnW/dTK9COtm2PxwgRXpUqPnLr0iPvMwDP8tIrsHm3pl2+5Um3EhvfZ9bjPft qbE04XTm+ZNpOsnDOKOJYoTWYHHuvtoVo8iIrH6rNERVWKcdM5Dg559gDAuLREJd usDbjX0CmPhPS050CJWW8/tUbC0GRfEdJUpI10+jzNpS6nA6rr7MCkYHhg51kFID IuMXJsQ/y60pBbO3C0sDIJYxYhFWZ6OjiyMbfH/QNWftCSvBW6SQZW/pbdifKJnK 1i5oO9nE72nR7egz9K41 =sKyo -----END PGP SIGNATURE----- --==-=-=--