unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/3] emacs: use a single history for all searches
@ 2011-12-24  3:47 Dmitry Kurochkin
  2011-12-24  3:47 ` [PATCH 2/3] emacs: reindent `notmuch-hello' function Dmitry Kurochkin
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dmitry Kurochkin @ 2011-12-24  3:47 UTC (permalink / raw)
  To: notmuch

There are two ways to do search in Emacs UI: search widget in
notmuch-hello buffer and `notmuch-search' function bound to "s".
Before the change, these search mechanisms used different history
lists.  The patch makes notmuch-hello search use the same history list
as `notmuch-search' function.
---
 emacs/notmuch-hello.el |   35 +++++++++++++++--------------------
 emacs/notmuch.el       |    8 +++-----
 2 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 333d4c1..ba34ac5 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -32,8 +32,11 @@
 (defvar notmuch-hello-search-bar-marker nil
   "The position of the search bar within the notmuch-hello buffer.")
 
-(defcustom notmuch-recent-searches-max 10
-  "The number of recent searches to store and display."
+(defvar notmuch-query-history nil
+  "Variable to store history for notmuch queries.")
+
+(defcustom notmuch-hello-recent-searches-max 10
+  "The number of recent searches to display."
   :type 'integer
   :group 'notmuch)
 
@@ -154,15 +157,9 @@ International Bureau of Weights and Measures."
 (defvar notmuch-hello-url "http://notmuchmail.org"
   "The `notmuch' web site.")
 
-(defvar notmuch-hello-recent-searches nil)
-
 (defun notmuch-hello-remember-search (search)
-  (setq notmuch-hello-recent-searches
-	(delete search notmuch-hello-recent-searches))
-  (push search notmuch-hello-recent-searches)
-  (if (> (length notmuch-hello-recent-searches)
-	 notmuch-recent-searches-max)
-      (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches))))
+  (let ((history-delete-duplicates t))
+    (add-to-history 'notmuch-query-history search)))
 
 (defun notmuch-hello-nice-number (n)
   (let (result)
@@ -512,18 +509,18 @@ Complete list of currently available key bindings:
 	(put-text-property (1- (point)) (point) 'invisible t)
 	(widget-insert "\n")
 
-	(when notmuch-hello-recent-searches
+	(when notmuch-query-history
 	  (widget-insert "\nRecent searches: ")
 	  (widget-create 'push-button
 			 :notify (lambda (&rest ignore)
-				   (setq notmuch-hello-recent-searches nil)
+				   (setq notmuch-query-history nil)
 				   (notmuch-hello-update))
 			 "clear")
 	  (widget-insert "\n\n")
-	  (let ((start (point))
-		(nth 0))
-	    (mapc (lambda (search)
-		    (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))
+	  (let ((start (point)))
+	    (loop for i from 1 to notmuch-hello-recent-searches-max
+		  for search in notmuch-query-history do
+		    (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
 		      (set widget-symbol
 			   (widget-create 'editable-field
 					  ;; Don't let the search boxes be
@@ -550,9 +547,7 @@ Complete list of currently available key bindings:
 					       (notmuch-hello-add-saved-search widget))
 				     :notmuch-saved-search-widget widget-symbol
 				     "save"))
-		    (widget-insert "\n")
-		    (setq nth (1+ nth)))
-		  notmuch-hello-recent-searches)
+		    (widget-insert "\n"))
 	    (indent-rigidly start (point) notmuch-hello-indent)))
 
 	(when alltags-alist
@@ -581,7 +576,7 @@ Complete list of currently available key bindings:
       (let ((start (point)))
 	(widget-insert "\n\n")
 	(widget-insert "Type a search query and hit RET to view matching threads.\n")
-	(when notmuch-hello-recent-searches
+	(when notmuch-query-history
 	  (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")
 	  (widget-insert "Save recent searches with the `save' button.\n"))
 	(when notmuch-saved-searches
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 270f983..546f306 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -72,9 +72,6 @@ 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
@@ -902,8 +899,9 @@ PROMPT is the string to prompt with."
 	       (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))))
+      (let ((history-delete-duplicates t))
+	(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)
-- 
1.7.7.3

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

* [PATCH 2/3] emacs: reindent `notmuch-hello' function
  2011-12-24  3:47 [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
@ 2011-12-24  3:47 ` Dmitry Kurochkin
  2011-12-24  3:47 ` [PATCH 3/3] emacs: hide recent searches if `notmuch-hello-recent-searches-max' is zero Dmitry Kurochkin
  2011-12-24 18:32 ` [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
  2 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kurochkin @ 2011-12-24  3:47 UTC (permalink / raw)
  To: notmuch

Reindent `notmuch-hello' function after the search history changes.
---
 emacs/notmuch-hello.el |   56 ++++++++++++++++++++++++------------------------
 1 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index ba34ac5..0922821 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -520,34 +520,34 @@ Complete list of currently available key bindings:
 	  (let ((start (point)))
 	    (loop for i from 1 to notmuch-hello-recent-searches-max
 		  for search in notmuch-query-history do
-		    (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
-		      (set widget-symbol
-			   (widget-create 'editable-field
-					  ;; Don't let the search boxes be
-					  ;; less than 8 characters wide.
-					  :size (max 8
-						     (- (window-width)
-							;; Leave some space
-							;; at the start and
-							;; end of the
-							;; boxes.
-							(* 2 notmuch-hello-indent)
-							;; 1 for the space
-							;; before the
-							;; `[save]' button. 6
-							;; for the `[save]'
-							;; button.
-							1 6))
-					  :action (lambda (widget &rest ignore)
-						    (notmuch-hello-search (widget-value widget)))
-					  search))
-		      (widget-insert " ")
-		      (widget-create 'push-button
-				     :notify (lambda (widget &rest ignore)
-					       (notmuch-hello-add-saved-search widget))
-				     :notmuch-saved-search-widget widget-symbol
-				     "save"))
-		    (widget-insert "\n"))
+		  (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
+		    (set widget-symbol
+			 (widget-create 'editable-field
+					;; Don't let the search boxes be
+					;; less than 8 characters wide.
+					:size (max 8
+						   (- (window-width)
+						      ;; Leave some space
+						      ;; at the start and
+						      ;; end of the
+						      ;; boxes.
+						      (* 2 notmuch-hello-indent)
+						      ;; 1 for the space
+						      ;; before the
+						      ;; `[save]' button. 6
+						      ;; for the `[save]'
+						      ;; button.
+						      1 6))
+					:action (lambda (widget &rest ignore)
+						  (notmuch-hello-search (widget-value widget)))
+					search))
+		    (widget-insert " ")
+		    (widget-create 'push-button
+				   :notify (lambda (widget &rest ignore)
+					     (notmuch-hello-add-saved-search widget))
+				   :notmuch-saved-search-widget widget-symbol
+				   "save"))
+		  (widget-insert "\n"))
 	    (indent-rigidly start (point) notmuch-hello-indent)))
 
 	(when alltags-alist
-- 
1.7.7.3

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

* [PATCH 3/3] emacs: hide recent searches if `notmuch-hello-recent-searches-max' is zero
  2011-12-24  3:47 [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
  2011-12-24  3:47 ` [PATCH 2/3] emacs: reindent `notmuch-hello' function Dmitry Kurochkin
@ 2011-12-24  3:47 ` Dmitry Kurochkin
  2011-12-24 18:32 ` [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
  2 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kurochkin @ 2011-12-24  3:47 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-hello.el |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 0922821..821ef22 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -36,7 +36,10 @@
   "Variable to store history for notmuch queries.")
 
 (defcustom notmuch-hello-recent-searches-max 10
-  "The number of recent searches to display."
+  "The number of recent searches to display.
+
+Recent searches section is not shown if
+`notmuch-hello-recent-searches-max' is set to 0."
   :type 'integer
   :group 'notmuch)
 
@@ -161,6 +164,10 @@ International Bureau of Weights and Measures."
   (let ((history-delete-duplicates t))
     (add-to-history 'notmuch-query-history search)))
 
+(defun notmuch-hello-show-recent-searches ()
+  (and (> notmuch-hello-recent-searches-max 0)
+       notmuch-query-history))
+
 (defun notmuch-hello-nice-number (n)
   (let (result)
     (while (> n 0)
@@ -509,7 +516,7 @@ Complete list of currently available key bindings:
 	(put-text-property (1- (point)) (point) 'invisible t)
 	(widget-insert "\n")
 
-	(when notmuch-query-history
+	(when (notmuch-hello-show-recent-searches)
 	  (widget-insert "\nRecent searches: ")
 	  (widget-create 'push-button
 			 :notify (lambda (&rest ignore)
@@ -576,7 +583,7 @@ Complete list of currently available key bindings:
       (let ((start (point)))
 	(widget-insert "\n\n")
 	(widget-insert "Type a search query and hit RET to view matching threads.\n")
-	(when notmuch-query-history
+	(when (notmuch-hello-show-recent-searches)
 	  (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")
 	  (widget-insert "Save recent searches with the `save' button.\n"))
 	(when notmuch-saved-searches
-- 
1.7.7.3

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

* Re: [PATCH 1/3] emacs: use a single history for all searches
  2011-12-24  3:47 [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
  2011-12-24  3:47 ` [PATCH 2/3] emacs: reindent `notmuch-hello' function Dmitry Kurochkin
  2011-12-24  3:47 ` [PATCH 3/3] emacs: hide recent searches if `notmuch-hello-recent-searches-max' is zero Dmitry Kurochkin
@ 2011-12-24 18:32 ` Dmitry Kurochkin
  2011-12-26 10:58   ` David Edmondson
  2 siblings, 1 reply; 8+ messages in thread
From: Dmitry Kurochkin @ 2011-12-24 18:32 UTC (permalink / raw)
  To: notmuch

I got some positive feedback for replacing notmuch-hello search input
with a button wich would call `notmuch-search' and read input from
minibuffer as usual.  This way we do not have to maintain 2 search
interfaces and get history, tab completions and other minibuffer
features in notmuch-hello search without having to reinvent the wheel.

So I plan to go with this approach and this patch series is obsolete.

Regards,
  Dmitry

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

* Re: [PATCH 1/3] emacs: use a single history for all searches
  2011-12-24 18:32 ` [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
@ 2011-12-26 10:58   ` David Edmondson
  2011-12-26 11:02     ` Dmitry Kurochkin
  0 siblings, 1 reply; 8+ messages in thread
From: David Edmondson @ 2011-12-26 10:58 UTC (permalink / raw)
  To: Dmitry Kurochkin, notmuch

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

On Sat, 24 Dec 2011 22:32:27 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:
> I got some positive feedback for replacing notmuch-hello search input
> with a button wich would call `notmuch-search' and read input from
> minibuffer as usual.  This way we do not have to maintain 2 search
> interfaces and get history, tab completions and other minibuffer
> features in notmuch-hello search without having to reinvent the wheel.

There's be no 'search' box in notmuch-hello?

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

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

* Re: [PATCH 1/3] emacs: use a single history for all searches
  2011-12-26 10:58   ` David Edmondson
@ 2011-12-26 11:02     ` Dmitry Kurochkin
  2011-12-26 22:02       ` David Edmondson
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Kurochkin @ 2011-12-26 11:02 UTC (permalink / raw)
  To: David Edmondson, notmuch

On Mon, 26 Dec 2011 10:58:02 +0000, David Edmondson <dme@dme.org> wrote:
> On Sat, 24 Dec 2011 22:32:27 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:
> > I got some positive feedback for replacing notmuch-hello search input
> > with a button wich would call `notmuch-search' and read input from
> > minibuffer as usual.  This way we do not have to maintain 2 search
> > interfaces and get history, tab completions and other minibuffer
> > features in notmuch-hello search without having to reinvent the wheel.
> 
> There's be no 'search' box in notmuch-hello?

No box, just a button.

Regards,
  Dmitry

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

* Re: [PATCH 1/3] emacs: use a single history for all searches
  2011-12-26 11:02     ` Dmitry Kurochkin
@ 2011-12-26 22:02       ` David Edmondson
  2011-12-26 22:31         ` Jameson Graef Rollins
  0 siblings, 1 reply; 8+ messages in thread
From: David Edmondson @ 2011-12-26 22:02 UTC (permalink / raw)
  To: Dmitry Kurochkin, notmuch

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

On Mon, 26 Dec 2011 15:02:14 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:
> On Mon, 26 Dec 2011 10:58:02 +0000, David Edmondson <dme@dme.org> wrote:
> > On Sat, 24 Dec 2011 22:32:27 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:
> > > I got some positive feedback for replacing notmuch-hello search input
> > > with a button wich would call `notmuch-search' and read input from
> > > minibuffer as usual.  This way we do not have to maintain 2 search
> > > interfaces and get history, tab completions and other minibuffer
> > > features in notmuch-hello search without having to reinvent the wheel.
> > 
> > There's be no 'search' box in notmuch-hello?
> 
> No box, just a button.

That seems to move away from the original intent - a user-friendly
frontend.

It's also simpler to have a global keybinding for `notmuch-search' than
to run `notmuch' and then click on the "search" button.

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

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

* Re: [PATCH 1/3] emacs: use a single history for all searches
  2011-12-26 22:02       ` David Edmondson
@ 2011-12-26 22:31         ` Jameson Graef Rollins
  0 siblings, 0 replies; 8+ messages in thread
From: Jameson Graef Rollins @ 2011-12-26 22:31 UTC (permalink / raw)
  To: David Edmondson, Dmitry Kurochkin, notmuch

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

On Mon, 26 Dec 2011 22:02:55 +0000, David Edmondson <dme@dme.org> wrote:
> It's also simpler to have a global keybinding for `notmuch-search' than
> to run `notmuch' and then click on the "search" button.

We actually have that everywhere else *but* notmuch-hello; notmuch-hello
is actually the odd man out in this case.  It seems like Dmitry's
proposal will actually bring it back in line.

But I never actually use notmuch-hello, though, so my comments in this
regard are pretty meaningless.

jamie.

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

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

end of thread, other threads:[~2011-12-26 22:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-24  3:47 [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
2011-12-24  3:47 ` [PATCH 2/3] emacs: reindent `notmuch-hello' function Dmitry Kurochkin
2011-12-24  3:47 ` [PATCH 3/3] emacs: hide recent searches if `notmuch-hello-recent-searches-max' is zero Dmitry Kurochkin
2011-12-24 18:32 ` [PATCH 1/3] emacs: use a single history for all searches Dmitry Kurochkin
2011-12-26 10:58   ` David Edmondson
2011-12-26 11:02     ` Dmitry Kurochkin
2011-12-26 22:02       ` David Edmondson
2011-12-26 22:31         ` Jameson Graef Rollins

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).