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

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