* [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter @ 2011-06-04 12:19 Daniel Schoepe 2011-06-04 13:14 ` Daniel Schoepe 2011-06-04 15:32 ` Austin Clements 0 siblings, 2 replies; 16+ messages in thread From: Daniel Schoepe @ 2011-06-04 12:19 UTC (permalink / raw) To: notmuch 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..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 "<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 (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 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 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 1 sibling, 0 replies; 16+ messages in thread From: Daniel Schoepe @ 2011-06-04 13:14 UTC (permalink / raw) To: notmuch 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..7b63dc9 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 "<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 (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 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 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 1 sibling, 1 reply; 16+ messages in thread From: Austin Clements @ 2011-06-04 15:32 UTC (permalink / raw) To: Daniel Schoepe; +Cc: notmuch Nifty! On Sat, Jun 4, 2011 at 8:19 AM, Daniel Schoepe <daniel.schoepe@googlemail.com> wrote: > + (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 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 scoping. > + (define-key keymap (kbd "<tab>") 'minibuffer-complete) 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). ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 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 0 siblings, 2 replies; 16+ messages in thread From: Daniel Schoepe @ 2011-06-04 19:55 UTC (permalink / raw) To: Austin Clements; +Cc: notmuch [-- Attachment #1.1: Type: text/plain, Size: 1713 bytes --] On Sat, 4 Jun 2011 11:32:15 -0400, Austin Clements <amdragon@mit.edu> 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 scoping. 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 "<tab>") 'minibuffer-complete) > > 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. [-- 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: 3349 bytes --] From 70642aecbf63428d9bcedc108c55f65574a792e7 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 | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..17c214c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) +(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 "*")) ))) +(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-completions))) + ;; this was simpler than convincing completing-read to accept spaces: + (define-key keymap (kbd "<tab>") '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-line 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." - (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." 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 [-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-06-04 19:55 ` Daniel Schoepe @ 2011-06-04 20:39 ` Daniel Schoepe 2011-06-04 21:55 ` Austin Clements 1 sibling, 0 replies; 16+ messages in thread From: Daniel Schoepe @ 2011-06-04 20:39 UTC (permalink / raw) To: Austin Clements; +Cc: notmuch [-- Attachment #1.1: Type: text/plain, Size: 101 bytes --] Sorry, forgot to actually test notmuch-search entirely with this change and not just the completion. [-- 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: 3363 bytes --] From cb172efc1dea2507566db587f960c073373e0159 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 | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..a2db852 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) +(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 "*")) ))) +(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-completions))) + ;; this was simpler than convincing completing-read to accept spaces: + (define-key keymap (kbd "<tab>") '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-line 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." - (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 +1022,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 --] ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 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 1 sibling, 1 reply; 16+ messages in thread From: Austin Clements @ 2011-06-04 21:55 UTC (permalink / raw) To: Daniel Schoepe; +Cc: notmuch Quoth Daniel Schoepe on Jun 04 at 9:55 pm: > On Sat, 4 Jun 2011 11:32:15 -0400, Austin Clements <amdragon@mit.edu> 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 scoping. > > 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. :) Oh, sorry, I wasn't suggesting setq'ing a global. I agree that that's really ugly. Rather, something like (defun notmuch-query-completions (string) ... as you have it now ...) (defun notmuch-read-query (prompt) (let ((notmuch-completions (append (list "folder:" ...))) (keymap ...) (minibuffer-completion-table ...)) (read-from-minibuffer ...))) 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. 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: (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 ((minibuffer-completion-table (completion-table-dynamic (lambda (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) completions))) (t (list string)))))) (keymap (copy-keymap minibuffer-local-map))) ;; 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)))) > > > + (define-key keymap (kbd "<tab>") 'minibuffer-complete) > > > > 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. Yeah, I futzed with it for a bit, swearing that there had to be a better way, but didn't find one either. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-06-04 21:55 ` Austin Clements @ 2011-06-04 22:54 ` Daniel Schoepe 2011-06-06 16:32 ` Daniel Schoepe 0 siblings, 1 reply; 16+ messages in thread From: Daniel Schoepe @ 2011-06-04 22:54 UTC (permalink / raw) To: Austin Clements; +Cc: notmuch [-- Attachment #1.1: Type: text/plain, Size: 1313 bytes --] On Sat, 4 Jun 2011 17:55:24 -0400, Austin Clements <amdragon@MIT.EDU> wrote: > Oh, sorry, I wasn't suggesting setq'ing a global. I agree that that's > really ugly. Rather, something like > > (defun notmuch-query-completions (string) > ... as you have it now ...) > > (defun notmuch-read-query (prompt) > (let ((notmuch-completions (append (list "folder:" ...))) > (keymap ...) > (minibuffer-completion-table ...)) > (read-from-minibuffer ...))) > > 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. [-- 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: 3373 bytes --] From 7768f41ac44213c5e2c1dc3b0f13e3edf1d97a26 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 | 36 ++++++++++++++++++++++++++++++++++-- 1 files changed, 34 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..33c34bd 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) +(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 "*")) ))) +(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 +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." - (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." 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 --] ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-06-04 22:54 ` Daniel Schoepe @ 2011-06-06 16:32 ` Daniel Schoepe 2011-08-05 15:17 ` Daniel Schoepe 0 siblings, 1 reply; 16+ messages in thread From: Daniel Schoepe @ 2011-06-06 16:32 UTC (permalink / raw) To: Austin Clements; +Cc: notmuch [-- 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 --] ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-06-06 16:32 ` Daniel Schoepe @ 2011-08-05 15:17 ` Daniel Schoepe 2011-08-05 21:00 ` Jameson Graef Rollins 0 siblings, 1 reply; 16+ messages in thread From: Daniel Schoepe @ 2011-08-05 15:17 UTC (permalink / raw) To: Austin Clements; +Cc: notmuch [-- Attachment #1: Type: text/plain, Size: 256 bytes --] On Mon, 06 Jun 2011 18:32:41 +0200, Daniel Schoepe <daniel.schoepe@googlemail.com> wrote: > [..] I've been using this patch for the past two months now and it has been working fine. Are there any more suggestions or criticisms about this? Cheers, Daniel [-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-08-05 15:17 ` Daniel Schoepe @ 2011-08-05 21:00 ` Jameson Graef Rollins 2011-08-05 21:03 ` Jameson Graef Rollins 0 siblings, 1 reply; 16+ messages in thread From: Jameson Graef Rollins @ 2011-08-05 21:00 UTC (permalink / raw) To: Daniel Schoepe, Austin Clements; +Cc: notmuch [-- Attachment #1: Type: text/plain, Size: 1615 bytes --] On Fri, 05 Aug 2011 17:17:56 +0200, Daniel Schoepe <daniel.schoepe@googlemail.com> wrote: > On Mon, 06 Jun 2011 18:32:41 +0200, Daniel Schoepe <daniel.schoepe@googlemail.com> wrote: > I've been using this patch for the past two months now and it has been > working fine. Are there any more suggestions or criticisms about this? Hey, Daniel. This is a really great patch. I've been looking for this functionality for a while. Thanks for implementing it. Following this email I am sending a slightly-tweaked and signed-off version of this patch that includes a couple of minor tweaks (diff below). The first tweak removes an errant white space, and the other modifies the tag-retrieval command to use the "search --output=tags" command instead of the "search-tags" command which was recently deprecated. jamie. diff --git a/emacs/notmuch.el b/emacs/notmuch.el index e9b0ef8..053f0be 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -882,12 +882,12 @@ characters as well as `_.+-'. PROMPT is the string to prompt with." (lexical-let - ((completions + ((completions (append (list "folder:" "thread:" "id:" "date:" "from:" "to:" "subject:" "attachment:") (mapcar (lambda (tag) (concat "tag:" tag)) - (process-lines "notmuch" "search-tags"))))) + (process-lines "notmuch" "search" "--output=tags" "*"))))) (let ((keymap (copy-keymap minibuffer-local-map)) (minibuffer-completion-table (completion-table-dynamic [-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-08-05 21:00 ` Jameson Graef Rollins @ 2011-08-05 21:03 ` Jameson Graef Rollins 2011-08-06 6:09 ` Jameson Graef Rollins 0 siblings, 1 reply; 16+ messages in thread From: Jameson Graef Rollins @ 2011-08-05 21:03 UTC (permalink / raw) To: Notmuch Mail From: Daniel Schoepe <daniel.schoepe@googlemail.com> This patch adds completion with <tab> in the minibuffer for notmuch-search and notmuch-search-filter. --- This is a slightly tweaked version of this original patch that removes an errant space and uses "search --output=tags" instead of the deprecated "search-tags". emacs/notmuch.el | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 6bf42e8..053f0be 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -877,6 +877,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" "--output=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. @@ -888,7 +917,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) @@ -986,7 +1015,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.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 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 17:32 ` Daniel Schoepe 0 siblings, 2 replies; 16+ messages in thread From: Jameson Graef Rollins @ 2011-08-06 6:09 UTC (permalink / raw) To: Notmuch Mail [-- Attachment #1: Type: text/plain, Size: 559 bytes --] Hey, Daniel. I actually just ran into a little bug with this patch. After applying this patch, if I try to scroll/search through my mini-buffer history after a search I get the following error: previous-history-element: Wrong type argument: symbolp, "tag:signed" I get this error no matter what my search terms were. Unfortunately I've always found these error messages confusing, so I'm not quite sure where it's coming from. I clearly has something to do with how searches are now stored in the mini-buffer history (symbol instead of string?). jamie. [-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 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 1 sibling, 1 reply; 16+ messages in thread From: Daniel Schoepe @ 2011-08-09 17:31 UTC (permalink / raw) To: Jameson Graef Rollins, Notmuch Mail [-- Attachment #1: Type: text/plain, Size: 773 bytes --] On Fri, 05 Aug 2011 23:09:23 -0700, Jameson Graef Rollins <jrollins@finestructure.net> wrote: > Hey, Daniel. I actually just ran into a little bug with this patch. > After applying this patch, if I try to scroll/search through my > mini-buffer history after a search I get the following error: > > previous-history-element: Wrong type argument: symbolp, "tag:signed" > > I get this error no matter what my search terms were. > > Unfortunately I've always found these error messages confusing, so I'm > not quite sure where it's coming from. I clearly has something to do > with how searches are now stored in the mini-buffer history (symbol > instead of string?). Turns out, I just used `read-from-minibuffer' incorrectly, here's an updated version. [-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-08-09 17:31 ` Daniel Schoepe @ 2011-08-09 21:41 ` Jameson Graef Rollins 0 siblings, 0 replies; 16+ messages in thread From: Jameson Graef Rollins @ 2011-08-09 21:41 UTC (permalink / raw) To: Daniel Schoepe, Notmuch Mail On Tue, 09 Aug 2011 19:31:44 +0200, Daniel Schoepe <daniel.schoepe@googlemail.com> wrote: > Turns out, I just used `read-from-minibuffer' incorrectly, here's an > updated version. Hey, Daniel. Thanks so much for the quick fix! This new patch seems to work great. Signed-off-by: Jameson Graef Rollins <jrollins@finestructure.net> jamie. ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-08-06 6:09 ` Jameson Graef Rollins 2011-08-09 17:31 ` Daniel Schoepe @ 2011-08-09 17:32 ` Daniel Schoepe 2011-11-03 1:19 ` David Bremner 1 sibling, 1 reply; 16+ messages in thread From: Daniel Schoepe @ 2011-08-09 17:32 UTC (permalink / raw) To: notmuch This patch adds completion with <tab> in the minibuffer for notmuch-search and notmuch-search-filter. --- emacs/notmuch.el | 37 +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f11ec24..bb7565c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) +(defvar notmuch-query-history nil + "Variable to store minibuffer history for notmuch queries") + (defun notmuch-select-tag-with-completion (prompt &rest search-terms) (let ((tag-list (with-output-to-string @@ -882,6 +885,36 @@ 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" "--output=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 + 'notmuch-query-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 +926,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 +1024,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.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter 2011-08-09 17:32 ` Daniel Schoepe @ 2011-11-03 1:19 ` David Bremner 0 siblings, 0 replies; 16+ messages in thread From: David Bremner @ 2011-11-03 1:19 UTC (permalink / raw) To: Daniel Schoepe, notmuch On Tue, 9 Aug 2011 19:32:49 +0200, Daniel Schoepe <daniel.schoepe@googlemail.com> wrote: > This patch adds completion with <tab> in the minibuffer for > notmuch-search and notmuch-search-filter. Finally pushed. d ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2011-11-03 1:19 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).