unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search
@ 2022-09-18 13:05 Tomi Ollila
  2022-09-18 14:54 ` Jose A Ortega Ruiz
  2022-09-23 23:33 ` David Bremner
  0 siblings, 2 replies; 4+ messages in thread
From: Tomi Ollila @ 2022-09-18 13:05 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

...and bind these to "E" in their respective keymaps.

Expected to be called interactively, then using read-from-minibuffer
with current search string as initial contents for editing.
(Noninteractive use makes little sense, but is supported.)

With this one can expand (as an opposite to limit) their
query and have e.g. (some of their) saved searches as search
"templates".

While at it, removed `(defvar notmuch-search-query-string)` from
notmuch-tree.el; it is unused (`notmuch-tree-basic-query` is used
instead).

Thanks to Jose Antonio Ortega Ruiz for his example for notmuch-tree
code, and better interactive use.
---
 emacs/notmuch-tree.el | 19 ++++++++++++++++---
 emacs/notmuch.el      |  7 +++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 7ceddee2..b3c2c992 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -45,9 +45,6 @@
 (declare-function notmuch-search-previous-thread "notmuch" ())
 (declare-function notmuch-tree-from-search-thread "notmuch" ())
 
-;; the following variable is defined in notmuch.el
-(defvar notmuch-search-query-string)
-
 ;; this variable distinguishes the unthreaded display from the normal tree display
 (defvar-local notmuch-tree-unthreaded nil
   "A buffer local copy of argument unthreaded to the function notmuch-tree.")
@@ -399,6 +396,7 @@ (defvar notmuch-tree-mode-map
     (define-key map "V" 'notmuch-tree-view-raw-message)
     (define-key map "l" 'notmuch-tree-filter)
     (define-key map "t" 'notmuch-tree-filter-by-tag)
+    (define-key map "E" 'notmuch-tree-edit-search)
 
     ;; The main tree view bindings
     (define-key map (kbd "RET") 'notmuch-tree-show-message)
@@ -1265,6 +1263,21 @@ (defun notmuch-tree-filter-by-tag (tag)
 		  nil
 		  notmuch-search-oldest-first)))
 
+(defun notmuch-tree-edit-search (query)
+  "Edit the current search"
+  (interactive (list (read-from-minibuffer "Edit search: "
+					   notmuch-tree-basic-query)))
+  (let ((notmuch-show-process-crypto (notmuch-tree--message-process-crypto)))
+    (notmuch-tree-close-message-window)
+    (notmuch-tree query
+		  notmuch-tree-query-context
+		  nil
+		  nil
+		  nil
+		  notmuch-tree-unthreaded
+		  nil
+		  notmuch-search-oldest-first)))
+
 ;;; _
 
 (provide 'notmuch-tree)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 5cb7acd2..26181758 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -190,6 +190,7 @@ (defvar notmuch-search-mode-map
     (define-key map "c" 'notmuch-search-stash-map)
     (define-key map "t" 'notmuch-search-filter-by-tag)
     (define-key map "l" 'notmuch-search-filter)
+    (define-key map "E" 'notmuch-search-edit-search)
     (define-key map [mouse-1] 'notmuch-search-show-thread)
     (define-key map "k" 'notmuch-tag-jump)
     (define-key map "*" 'notmuch-search-tag-all)
@@ -1156,6 +1157,12 @@ (defun notmuch-search-by-tag (tag)
    (list (notmuch-select-tag-with-completion "Notmuch search tag: ")))
   (notmuch-search (concat "tag:" tag)))
 
+(defun notmuch-search-edit-search (query)
+  "Edit the current search"
+  (interactive (list (read-from-minibuffer "Edit search: "
+					   notmuch-search-query-string)))
+  (notmuch-search query notmuch-search-oldest-first))
+
 ;;;###autoload
 (defun notmuch ()
   "Run notmuch and display saved searches, known tags, etc."
-- 
2.34.1

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

* Re: [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search
  2022-09-18 13:05 [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search Tomi Ollila
@ 2022-09-18 14:54 ` Jose A Ortega Ruiz
  2022-09-23 23:35   ` David Bremner
  2022-09-23 23:33 ` David Bremner
  1 sibling, 1 reply; 4+ messages in thread
From: Jose A Ortega Ruiz @ 2022-09-18 14:54 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila


looks good, and very useful, to me, fwiw.

now i'll have to free E in my keymap, which i was using for something
else... i was thinking that, given how crowded those keymaps are
becoming, it might be worth considering two-key chords, with the first
grouping by "kind" (a la gnus); e.g. "/" could be a prefix for
query-related ones.  another option for recent emacsen which include
transient (the menu system used in magit, for instance) could be to
write one for notmuch-search-mode and notmuch-tree-search-mode.

(of course, that's also easily done as an external package (i actually
remember there is one such, but i didn't like its selection of
command/keys), or even in one's init file, but so is the case with
almost everything in emacs!)

cheers,
jao
-- 
Dealing with failure is easy: Work hard to improve. Success is also
easy to handle: You've solved the wrong problem. Work hard to improve.
  - Alan Perlis, Epigrams on Programming

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

* Re: [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search
  2022-09-18 13:05 [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search Tomi Ollila
  2022-09-18 14:54 ` Jose A Ortega Ruiz
@ 2022-09-23 23:33 ` David Bremner
  1 sibling, 0 replies; 4+ messages in thread
From: David Bremner @ 2022-09-23 23:33 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> ...and bind these to "E" in their respective keymaps.
>
> Expected to be called interactively, then using read-from-minibuffer
> with current search string as initial contents for editing.
> (Noninteractive use makes little sense, but is supported.)

applied to master.

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

* Re: [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search
  2022-09-18 14:54 ` Jose A Ortega Ruiz
@ 2022-09-23 23:35   ` David Bremner
  0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2022-09-23 23:35 UTC (permalink / raw)
  To: Jose A Ortega Ruiz, Tomi Ollila, notmuch; +Cc: tomi.ollila

Jose A Ortega Ruiz <jao@gnu.org> writes:

> looks good, and very useful, to me, fwiw.
>
> now i'll have to free E in my keymap, which i was using for something
> else... i was thinking that, given how crowded those keymaps are
> becoming, it might be worth considering two-key chords, with the first
> grouping by "kind" (a la gnus); e.g. "/" could be a prefix for
> query-related ones.  another option for recent emacsen which include
> transient (the menu system used in magit, for instance) could be to
> write one for notmuch-search-mode and notmuch-tree-search-mode.

At the risk of stating the obvious, we already sortof have this with
notmuch-tag-jump and notmuch-jump-search. Maybe that code can be
generalized / re-used? It might just be familiarity, but I actually
prefer the way our "hydras" work to those of magit.

d

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

end of thread, other threads:[~2022-09-23 23:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-18 13:05 [PATCH] emacs: add notmuch-search-edit-search and notmuch-tree-edit-search Tomi Ollila
2022-09-18 14:54 ` Jose A Ortega Ruiz
2022-09-23 23:35   ` David Bremner
2022-09-23 23:33 ` 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).