unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: put current query as default value in notmuch-read-query
@ 2014-05-03 16:12 Mark Walters
  2014-05-06  6:35 ` David Edmondson
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Walters @ 2014-05-03 16:12 UTC (permalink / raw)
  To: notmuch

This adds the current query as a "default value" to
notmuch-read-qeury. The default value is available via a down-arrow as
opposed to history which is available from the up arrow.

Note if a user presses return in the minibuffer this value is not
returned.

The implementation is simple but notmuch-read-query could via
notmuch-search/notmuch-tree etc from any buffer so it makes sense to
put the logic extracting the current query in notmuch-read-query
rather than in each of the callers.
---

This is another approach to
id:1397713404-3089-1-git-send-email-markwalters1009@gmail.com which is
closer in spirit to Austin's suggestion in his reply and comments on
irc and is based on Jani's suggestion on irc.

The basic idea is to add the current query to the completing read as a
default-value so it accessible via down-arrow.

The implementation is slightly unnatural as the function calling
notmuch-read-query is normally the function which perform the new
search (ie the new mode) so it does not know how to extract the
current query from the current mode. Thus we put the logic to that in
notmuch-read-query rather than the caller.

The other subtlety is that notmuch-show (and notmuch tree) have a more
complicated form for the query. In notmuch show this is thread-id and
context; notmuch-show tries the query "thread-id and context" and if
that gives no results it drops back to just "thread-id". In this
version we always return "thread-id and context" as the query. This is
not obviously correct, but not obviously wrong either.

An alternative to putting the logic in notmuch-read-query would be to
store the query in a consistently named buffer local variable in all
the modes. If we want to show the actually run query in notmuch-show
above then this is probably the neatest solution.


Best wishes

Mark





 emacs/notmuch.el |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6c0bc1b..1b6bde1 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -860,6 +860,20 @@ (defun notmuch-read-query (prompt)
 			  (concat "tag:" (notmuch-escape-boolean-term tag)))
 			(process-lines notmuch-command "search" "--output=tags" "*")))))
     (let ((keymap (copy-keymap minibuffer-local-map))
+	  (current-query (case major-mode
+			   (notmuch-search-mode notmuch-search-query-string)
+			   (notmuch-show-mode (if notmuch-show-query-context
+						  (concat notmuch-show-thread-id
+							  " and ("
+							  notmuch-show-query-context
+							  ")")
+						notmuch-show-thread-id))
+			   (notmuch-tree-mode (if notmuch-tree-query-context
+						  (concat notmuch-tree-basic-query
+							  " and ("
+							  notmuch-tree-query-context
+							  ")")
+						notmuch-tree-basic-query))))
 	  (minibuffer-completion-table
 	   (completion-table-dynamic
 	    (lambda (string)
@@ -877,7 +891,7 @@ (defun notmuch-read-query (prompt)
       (define-key keymap (kbd "TAB") 'minibuffer-complete)
       (let ((history-delete-duplicates t))
 	(read-from-minibuffer prompt nil keymap nil
-			      'notmuch-search-history nil nil)))))
+			      'notmuch-search-history current-query nil)))))
 
 ;;;###autoload
 (put 'notmuch-search 'notmuch-doc "Search for messages.")
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] emacs: put current query as default value in notmuch-read-query
  2014-05-03 16:12 [PATCH] emacs: put current query as default value in notmuch-read-query Mark Walters
@ 2014-05-06  6:35 ` David Edmondson
  2014-05-06  7:26   ` Mark Walters
  0 siblings, 1 reply; 6+ messages in thread
From: David Edmondson @ 2014-05-06  6:35 UTC (permalink / raw)
  To: Mark Walters, notmuch

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

On Sat, May 03 2014, Mark Walters wrote:
> An alternative to putting the logic in notmuch-read-query would be to
> store the query in a consistently named buffer local variable in all
> the modes. If we want to show the actually run query in notmuch-show
> above then this is probably the neatest solution.

Could per-mode query functions not simply pass the default as an
optional second argument to `notmuch-read-query'?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 310 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] emacs: put current query as default value in notmuch-read-query
  2014-05-06  6:35 ` David Edmondson
@ 2014-05-06  7:26   ` Mark Walters
  2014-05-06  7:44     ` David Edmondson
  2014-06-23 21:06     ` [PATCH v2] emacs: set default " Mark Walters
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Walters @ 2014-05-06  7:26 UTC (permalink / raw)
  To: David Edmondson, notmuch


Hi

On Tue, 06 May 2014, David Edmondson <dme@dme.org> wrote:
> On Sat, May 03 2014, Mark Walters wrote:
>> An alternative to putting the logic in notmuch-read-query would be to
>> store the query in a consistently named buffer local variable in all
>> the modes. If we want to show the actually run query in notmuch-show
>> above then this is probably the neatest solution.
>
> Could per-mode query functions not simply pass the default as an
> optional second argument to `notmuch-read-query'?

They could but at the moment notmuch-search and notmuch-tree are both
bound in the global key map and they in turn call notmuch-read-query. 

I guess we could add an argument to notmuch-search and notmuch-tree
for the default argument (which they would pass to
notmuch-read-query). Then calling modes which know a search value
(show,search and tree) could override the global keymap (probably using
remap or something to mean that they keep any customised binding) to
link into something which passes the default value through.

One variant which might be nicer than the current version would be to
have something like
(let ((current-query (case major-mode
                           (notmuch-show-mode (notmuch-show-get-current-query))
                           (notmuch-tree-mode (notmuch-tree-get-current-query))
                           (notmuch-search-mode (notmuch-search-get-current-query))))))

so at least all the logic for calculating the current query can live in
the relevant file.

What do you think?

Best wishes

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] emacs: put current query as default value in notmuch-read-query
  2014-05-06  7:26   ` Mark Walters
@ 2014-05-06  7:44     ` David Edmondson
  2014-06-23 21:06     ` [PATCH v2] emacs: set default " Mark Walters
  1 sibling, 0 replies; 6+ messages in thread
From: David Edmondson @ 2014-05-06  7:44 UTC (permalink / raw)
  To: Mark Walters, notmuch

[-- Attachment #1: Type: text/plain, Size: 1766 bytes --]

On Tue, May 06 2014, Mark Walters wrote:
> Hi
>
> On Tue, 06 May 2014, David Edmondson <dme@dme.org> wrote:
>> On Sat, May 03 2014, Mark Walters wrote:
>>> An alternative to putting the logic in notmuch-read-query would be to
>>> store the query in a consistently named buffer local variable in all
>>> the modes. If we want to show the actually run query in notmuch-show
>>> above then this is probably the neatest solution.
>>
>> Could per-mode query functions not simply pass the default as an
>> optional second argument to `notmuch-read-query'?
>
> They could but at the moment notmuch-search and notmuch-tree are both
> bound in the global key map and they in turn call notmuch-read-query. 
>
> I guess we could add an argument to notmuch-search and notmuch-tree
> for the default argument (which they would pass to
> notmuch-read-query). Then calling modes which know a search value
> (show,search and tree) could override the global keymap (probably using
> remap or something to mean that they keep any customised binding) to
> link into something which passes the default value through.

I would probably replace the global keymap bindings, but others should
chime in.

> One variant which might be nicer than the current version would be to
> have something like
> (let ((current-query (case major-mode
>                            (notmuch-show-mode (notmuch-show-get-current-query))
>                            (notmuch-tree-mode (notmuch-tree-get-current-query))
>                            (notmuch-search-mode (notmuch-search-get-current-query))))))
>
> so at least all the logic for calculating the current query can live in
> the relevant file.
>
> What do you think?

This is nicer than the current patch.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 310 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] emacs: set default in notmuch-read-query
  2014-05-06  7:26   ` Mark Walters
  2014-05-06  7:44     ` David Edmondson
@ 2014-06-23 21:06     ` Mark Walters
  2014-07-16  9:38       ` David Bremner
  1 sibling, 1 reply; 6+ messages in thread
From: Mark Walters @ 2014-06-23 21:06 UTC (permalink / raw)
  To: notmuch

This adds the current query as a "default value" to
notmuch-read-qeury. The default value is available via a down-arrow as
opposed to history which is available from the up arrow.

Note if a user presses return in the minibuffer this value is not
returned.

The implementation is simple but notmuch-read-query could be called
via notmuch-search/notmuch-tree etc from any buffer so it makes sense
to put the decision of how to extract the current query in
notmuch-read-query rather than in each of the callers.
---

v2 keeps the logic for extracting a query in the relevant file
(show/tree etc) so notmuch-read-query just needs to choose which one
to call.

Best wishes

Mark



 emacs/notmuch-show.el |    9 +++++++++
 emacs/notmuch-tree.el |    9 +++++++++
 emacs/notmuch.el      |   10 +++++++++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index df10d4b..313952f 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1186,6 +1186,15 @@ (defun notmuch-show-capture-state ()
  - the current message."
   (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages)))
 
+(defun notmuch-show-get-query ()
+  "Return the current query in this show buffer"
+  (if notmuch-show-query-context
+      (concat notmuch-show-thread-id
+	      " and ("
+	      notmuch-show-query-context
+	      ")")
+    notmuch-show-thread-id))
+
 (defun notmuch-show-apply-state (state)
   "Apply STATE to the current buffer.
 
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 7d5f475..e9249da 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -897,6 +897,15 @@ (defun notmuch-tree-worker (basic-query &optional query-context target open-targ
       (set-process-filter proc 'notmuch-tree-process-filter)
       (set-process-query-on-exit-flag proc nil))))
 
+(defun notmuch-tree-get-query ()
+  "Return the current query in this tree buffer"
+  (if notmuch-tree-query-context
+      (concat notmuch-tree-basic-query
+	      " and ("
+	      notmuch-tree-query-context
+	      ")")
+    notmuch-tree-basic-query))
+
 (defun notmuch-tree (&optional query query-context target buffer-name open-target)
   "Display threads matching QUERY in Tree View.
 
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6c0bc1b..5339a64 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -860,6 +860,10 @@ (defun notmuch-read-query (prompt)
 			  (concat "tag:" (notmuch-escape-boolean-term tag)))
 			(process-lines notmuch-command "search" "--output=tags" "*")))))
     (let ((keymap (copy-keymap minibuffer-local-map))
+	  (current-query (case major-mode
+			   (notmuch-search-mode (notmuch-search-get-query))
+			   (notmuch-show-mode (notmuch-show-get-query))
+			   (notmuch-tree-mode (notmuch-tree-get-query))))
 	  (minibuffer-completion-table
 	   (completion-table-dynamic
 	    (lambda (string)
@@ -877,7 +881,11 @@ (defun notmuch-read-query (prompt)
       (define-key keymap (kbd "TAB") 'minibuffer-complete)
       (let ((history-delete-duplicates t))
 	(read-from-minibuffer prompt nil keymap nil
-			      'notmuch-search-history nil nil)))))
+			      'notmuch-search-history current-query nil)))))
+
+(defun notmuch-search-get-query ()
+  "Return the current query in this search buffer"
+  notmuch-search-query-string)
 
 ;;;###autoload
 (put 'notmuch-search 'notmuch-doc "Search for messages.")
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] emacs: set default in notmuch-read-query
  2014-06-23 21:06     ` [PATCH v2] emacs: set default " Mark Walters
@ 2014-07-16  9:38       ` David Bremner
  0 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2014-07-16  9:38 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> This adds the current query as a "default value" to
> notmuch-read-qeury. The default value is available via a down-arrow as
> opposed to history which is available from the up arrow.
>
> Note if a user presses return in the minibuffer this value is not
> returned.
>

pushed. It would be great if you could update doc/notmuch-emacs.rst.

d

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-16  9:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-03 16:12 [PATCH] emacs: put current query as default value in notmuch-read-query Mark Walters
2014-05-06  6:35 ` David Edmondson
2014-05-06  7:26   ` Mark Walters
2014-05-06  7:44     ` David Edmondson
2014-06-23 21:06     ` [PATCH v2] emacs: set default " Mark Walters
2014-07-16  9:38       ` 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).