unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Daniel Schoepe <daniel.schoepe@googlemail.com>
To: Austin Clements <amdragon@MIT.EDU>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter
Date: Mon, 06 Jun 2011 18:32:41 +0200	[thread overview]
Message-ID: <87lixevs2e.fsf@gilead.invalid> (raw)
In-Reply-To: <87hb85jjgx.fsf@gilead.invalid>


[-- Attachment #1.1: Type: text/plain, Size: 154 bytes --]

I accidentally left a, now unnecessary, defvar in the patch from one of
the previous attempts, here is the updated version (thanks Austin for
noticing).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-emacs-Tab-completion-for-notmuch-search-and-notmuch-.patch --]
[-- Type: text/x-diff, Size: 3038 bytes --]

From f3bc7376edc66e947d8fdf5931a9aa697b9be5cf Mon Sep 17 00:00:00 2001
From: Daniel Schoepe <daniel.schoepe@googlemail.com>
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 <tab> 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..7ffbc3a 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -882,6 +882,35 @@ characters as well as `_.+-'.
 	   (concat "*notmuch-search-" query "*"))
 	  )))
 
+(defun notmuch-read-query (prompt)
+  "Read a notmuch-query from the minibuffer with completion.
+
+PROMPT is the string to prompt with."
+  (lexical-let
+      ((completions 
+	(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 "<tab>") '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 (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 +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 (list (notmuch-read-query "Filter search: ")))
   (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)
 			   (concat "( " query " )")
 			 query)))
-- 
1.7.5.3


[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

  reply	other threads:[~2011-06-06 16:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-04 12:19 [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter Daniel Schoepe
2011-06-04 13:14 ` Daniel Schoepe
2011-06-04 15:32 ` Austin Clements
2011-06-04 19:55   ` Daniel Schoepe
2011-06-04 20:39     ` Daniel Schoepe
2011-06-04 21:55     ` Austin Clements
2011-06-04 22:54       ` Daniel Schoepe
2011-06-06 16:32         ` Daniel Schoepe [this message]
2011-08-05 15:17           ` Daniel Schoepe
2011-08-05 21:00             ` Jameson Graef Rollins
2011-08-05 21:03               ` Jameson Graef Rollins
2011-08-06  6:09                 ` Jameson Graef Rollins
2011-08-09 17:31                   ` Daniel Schoepe
2011-08-09 21:41                     ` Jameson Graef Rollins
2011-08-09 17:32                   ` Daniel Schoepe
2011-11-03  1:19                     ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lixevs2e.fsf@gilead.invalid \
    --to=daniel.schoepe@googlemail.com \
    --cc=amdragon@MIT.EDU \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).