Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter
authorDaniel Schoepe <daniel.schoepe@googlemail.com>
Sat, 4 Jun 2011 22:54:38 +0000 (00:54 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:32 +0000 (09:38 -0800)
e9/7c609f04d871b8dd8869750dd1b8804fcead61 [new file with mode: 0644]

diff --git a/e9/7c609f04d871b8dd8869750dd1b8804fcead61 b/e9/7c609f04d871b8dd8869750dd1b8804fcead61
new file mode 100644 (file)
index 0000000..70171fb
--- /dev/null
@@ -0,0 +1,229 @@
+Return-Path: <daniel.schoepe@googlemail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 870C7429E2C\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Jun 2011 15:54:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id BRdK3rxAtbgO for <notmuch@notmuchmail.org>;\r
+       Sat,  4 Jun 2011 15:54:55 -0700 (PDT)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 32464431FB6\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Jun 2011 15:54:55 -0700 (PDT)\r
+Received: by bwg12 with SMTP id 12so2829274bwg.26\r
+       for <notmuch@notmuchmail.org>; Sat, 04 Jun 2011 15:54:53 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=googlemail.com; s=gamma;\r
+       h=domainkey-signature:from:to:cc:subject:in-reply-to:references\r
+       :user-agent:date:message-id:mime-version:content-type;\r
+       bh=PuCohA8+MnhAGfBOATMSRZyH+viURsTXEvfikpEIidM=;\r
+       b=OtdwxqlRVNOYw4d6uGfgsBsDsIt//lDpb7WxRIsc8pwFHOEgrXF2SQjFTtDI9oH267\r
+       VNgmKGx4bsu787fE6Md76km7h6L8joMDNwN3ao2sJr7k3/MMLe21l9UPH99ELhLRJ5Ji\r
+       OT/9xRH1mW56QGWqTsZDag2YRMBYviFwih1xw=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type;\r
+       b=AaZRJxQYyinpO5SHwuqdTcnRoU2qYFKjiL0bwkpgBiFp+JUPrJ7kmy+B8fwcqFZHRc\r
+       iIXcUvjOlrZSsx6MIV/apjqzrKNX3UcFaE1xknYO/N0RkH5uNQhJkv/7HVEbMsZbUngz\r
+       +lBhX4OqDyCdJ0C7oieay5azPDHouHb7Ob024=\r
+Received: by 10.204.82.224 with SMTP id c32mr3304890bkl.161.1307228093761;\r
+       Sat, 04 Jun 2011 15:54:53 -0700 (PDT)\r
+Received: from localhost (dslb-088-069-155-133.pools.arcor-ip.net\r
+       [88.69.155.133])\r
+       by mx.google.com with ESMTPS id ek1sm2237091bkb.9.2011.06.04.15.54.51\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 04 Jun 2011 15:54:52 -0700 (PDT)\r
+From: Daniel Schoepe <daniel.schoepe@googlemail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and\r
+       notmuch-search-filter\r
+In-Reply-To: <20110604215523.GF29861@mit.edu>\r
+References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com>\r
+       <BANLkTimudbqYy8JhGHu67WsOS04mCm0hfA@mail.gmail.com>\r
+       <87mxhxjrry.fsf@gilead.invalid> <20110604215523.GF29861@mit.edu>\r
+User-Agent: Notmuch/0.5-217-gd1f0224 (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sun, 05 Jun 2011 00:54:38 +0200\r
+Message-ID: <87hb85jjgx.fsf@gilead.invalid>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="==-=-=";\r
+       micalg=pgp-sha1; protocol="application/pgp-signature"\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 04 Jun 2011 22:54:56 -0000\r
+\r
+--==-=-=\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Sat, 4 Jun 2011 17:55:24 -0400, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Oh, sorry, I wasn't suggesting setq'ing a global.  I agree that that's\r
+> really ugly.  Rather, something like\r
+>=20\r
+> (defun notmuch-query-completions (string)\r
+>   ... as you have it now ...)\r
+>=20\r
+> (defun notmuch-read-query (prompt)\r
+>   (let ((notmuch-completions (append (list "folder:" ...)))\r
+>         (keymap ...)\r
+>         (minibuffer-completion-table ...))\r
+>     (read-from-minibuffer ...)))\r
+>=20\r
+> Unfortunately, you still need the global defvar to avoid compilation\r
+> warnings, but this at least avoids the side-effects, and is probably\r
+> how programmed completion was intended to be used.\r
+\r
+Both alternatives seem about equally ugly to me, since the one using\r
+dynamic scoping still uses side-effects, because it still passes the\r
+completion information around without using it as an argument to\r
+notmuch-query-completions. At least defvar-ing a global variable and\r
+then never actually using it, seems somewhat unclean as well.\r
+\r
+> Alternatively, here's a completely different way to structure this\r
+> that avoids globals and dynamic scoping entirely.  This is how some of\r
+> the standard completing read functions appear to work:\r
+\r
+Ah right, I forgot that using macros from cl is fine even in library\r
+code.\r
+\r
+\r
+--=-=-=\r
+Content-Type: text/x-diff\r
+Content-Disposition: inline;\r
+ filename=0001-emacs-Tab-completion-for-notmuch-search-and-notmuch-.patch\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+From=207768f41ac44213c5e2c1dc3b0f13e3edf1d97a26 Mon Sep 17 00:00:00 2001\r
+From: Daniel Schoepe <daniel.schoepe@googlemail.com>\r
+Date: Sat, 4 Jun 2011 14:17:44 +0200\r
+Subject: [PATCH] emacs: Tab completion for notmuch-search and\r
+ notmuch-search-filter\r
+\r
+This patch adds completion with <tab> in the minibuffer for\r
+notmuch-search and notmuch-search-filter.\r
+=2D--\r
+ emacs/notmuch.el |   36 ++++++++++++++++++++++++++++++++++--\r
+ 1 files changed, 34 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 3311fe8..33c34bd 100644\r
+=2D-- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -72,6 +72,9 @@ For example:\r
+   :type '(alist :key-type (string) :value-type (string))\r
+   :group 'notmuch)\r
+=20\r
++(defvar notmuch-completions nil\r
++  "List of completions used in notmuch-query-completions")\r
++\r
+ (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
+   (let ((tag-list\r
+        (with-output-to-string\r
+@@ -882,6 +885,35 @@ characters as well as `_.+-'.\r
+          (concat "*notmuch-search-" query "*"))\r
+         )))\r
+=20\r
++(defun notmuch-read-query (prompt)\r
++  "Read a notmuch-query from the minibuffer with completion.\r
++\r
++PROMPT is the string to prompt with."\r
++  (lexical-let\r
++      ((completions=20\r
++      (append (list "folder:" "thread:" "id:" "date:" "from:" "to:"\r
++                    "subject:" "attachment:")\r
++              (mapcar (lambda (tag)\r
++                        (concat "tag:" tag))\r
++                      (process-lines "notmuch" "search-tags")))))\r
++    (let ((keymap (copy-keymap minibuffer-local-map))\r
++        (minibuffer-completion-table\r
++         (completion-table-dynamic\r
++          (lambda (string)\r
++            ;; generate a list of possible completions for the current input\r
++            (cond\r
++             ;; this ugly regexp is used to get the last word of the input\r
++             ;; possibly preceded by a '('\r
++             ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)\r
++              (mapcar (lambda (compl)\r
++                        (concat (match-string-no-properties 1 string) compl))\r
++                      (all-completions (match-string-no-properties 2 string)\r
++                                       completions)))\r
++             (t (list string)))))))\r
++      ;; this was simpler than convincing completing-read to accept spaces:\r
++      (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
++      (read-from-minibuffer prompt nil keymap nil minibuffer-history nil n=\r
+il))))\r
++\r
+ ;;;###autoload\r
+ (defun notmuch-search (query &optional oldest-first target-thread target-l=\r
+ine continuation)\r
+   "Run \"notmuch search\" with the given query string and display results.\r
+@@ -893,7 +925,7 @@ The optional parameters are used as follows:\r
+                  current if it appears in the search results.\r
+   target-line: The line number to move to if the target thread does not\r
+                appear in the search results."\r
+=2D  (interactive "sNotmuch search: ")\r
++  (interactive (list (notmuch-read-query "Notmuch search: ")))\r
+   (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
+     (switch-to-buffer buffer)\r
+     (notmuch-search-mode)\r
+@@ -991,7 +1023,7 @@ search."\r
+=20\r
+ Runs a new search matching only messages that match both the\r
+ current search results AND the additional query string provided."\r
+=2D  (interactive "sFilter search: ")\r
++  (interactive (list (notmuch-read-query "Filter search: ")))\r
+   (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-rege=\r
+xp query)\r
+                          (concat "( " query " )")\r
+                        query)))\r
+=2D-=20\r
+1.7.5.3\r
+\r
+\r
+--=-=-=--\r
+\r
+--==-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.11 (GNU/Linux)\r
+\r
+iQIcBAEBAgAGBQJN6revAAoJEIaTAtce+Z+JOEwP/1sLQk12MjZ2+4TxZIgpQpri\r
+/2cZr5boUa128WDXFD7adLRQGoIPaYWkp5kNkHYqcc12Vo23fNRIh4dmchb0bdqL\r
+CVfW8aNID6rMrJ9XLQPuehTPo6IX2ixEpkARPC23XgYDDqEt5OJJzo07DDTOluwG\r
+LxLQ58vhu4B1yTm8OoD765ohHz89buDNchRblvPrlVVIaZ7nE2Jjd76J62Buayhc\r
+mv+f53n8sghK/k3m9nT2lOvuEK7ZvWpMPfe+O62HHhoE1bkSgxAV35Mo+eKjSWMT\r
+JIcdO7Pouflh2vleDhQcSxF7Sp5/3uC4nUnBRUbDUvDZkHPuzSLuG1ml2Z8yRanJ\r
+beegu6kuAVmrEb2HFDQbYjPOoh1lLYEZLXrWv2CbX5ouwDPa+HBHuc8xgXAmx1oH\r
+/BtrnW/dTK9COtm2PxwgRXpUqPnLr0iPvMwDP8tIrsHm3pl2+5Um3EhvfZ9bjPft\r
+qbE04XTm+ZNpOsnDOKOJYoTWYHHuvtoVo8iIrH6rNERVWKcdM5Dg559gDAuLREJd\r
+usDbjX0CmPhPS050CJWW8/tUbC0GRfEdJUpI10+jzNpS6nA6rr7MCkYHhg51kFID\r
+IuMXJsQ/y60pBbO3C0sDIJYxYhFWZ6OjiyMbfH/QNWftCSvBW6SQZW/pbdifKJnK\r
+1i5oO9nE72nR7egz9K41\r
+=sKyo\r
+-----END PGP SIGNATURE-----\r
+--==-=-=--\r