unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: notmuch@dima.secretsauce.net
To: notmuch@notmuchmail.org
Subject: [PATCH] Added C-up and C-down to cycle through previous searches
Date: Sun, 29 May 2011 01:56:28 -0700	[thread overview]
Message-ID: <1306659388-21809-1-git-send-email-notmuch@dima.secretsauce.net> (raw)

From: Dima Kogan <dima@secretsauce.net>

---

 Hi.

 I made a few improvements to the emacs UI. This patch allows the user to scroll
 through the most recent searches with C-up and C-down while in the search box.

 dima

 emacs/notmuch-hello.el |   49 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 916cda1..56f853f 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -123,6 +123,12 @@ Typically \",\" in the US and UK and \".\" in Europe."
 
 (defvar notmuch-hello-recent-searches nil)
 
+(defvar notmuch-hello-cyclerecent-index 0
+  "The current index of the most-recent searches" )
+
+(defvar notmuch-hello-search-widget nil
+  "The search widget")
+
 (defun notmuch-hello-remember-search (search)
   (if (not (member search notmuch-hello-recent-searches))
       (push search notmuch-hello-recent-searches))
@@ -148,6 +154,28 @@ Typically \",\" in the US and UK and \".\" in Europe."
       (match-string 1 search)
     search))
 
+(defun notmuch-hello-cyclerecent-next ()
+  "Cycle through the most recently-searched queries, going forwards"
+  (interactive)
+  (notmuch-hello-cyclerecent 1))
+
+(defun notmuch-hello-cyclerecent-prev ()
+  "Cycle through the most recently-searched queries, going backwards"
+  (interactive)
+  (notmuch-hello-cyclerecent -1))
+
+(defun notmuch-hello-cyclerecent (d) ()
+
+  (when notmuch-hello-recent-searches ; if no recent searches, do nothing
+    (let ((N (length notmuch-hello-recent-searches)))
+      (setq notmuch-hello-cyclerecent-index
+            (% (+ notmuch-hello-cyclerecent-index d N) N))) ; update the index
+
+    (widget-value-set notmuch-hello-search-widget
+                      (nth notmuch-hello-cyclerecent-index notmuch-hello-recent-searches))
+    (widget-setup))
+)
+
 (defun notmuch-hello-search (search)
   (let ((search (notmuch-hello-trim search)))
     (notmuch-hello-remember-search search)
@@ -455,13 +483,19 @@ Complete list of currently available key bindings:
 
 	(widget-insert "\nSearch: ")
 	(setq notmuch-hello-search-bar-marker (point-marker))
-	(widget-create 'editable-field
-		       ;; Leave some space at the start and end of the
-		       ;; search boxes.
-		       :size (max 8 (- (window-width) notmuch-hello-indent
-				       (length "Search: ")))
-		       :action (lambda (widget &rest ignore)
-				 (notmuch-hello-search (widget-value widget))))
+	(setq notmuch-hello-search-widget
+              (widget-create 'editable-field
+                             ;; Leave some space at the start and end of the
+                             ;; search boxes.
+                             :size (max 8 (- (window-width) notmuch-hello-indent
+                                             (length "Search: ")))
+                             :action (lambda (widget &rest ignore)
+                                       (notmuch-hello-search (widget-value widget)))
+                             :keymap (let ((map (make-sparse-keymap)))
+                                       (set-keymap-parent map widget-field-keymap)
+                                       (define-key map (kbd "<C-up>")   'notmuch-hello-cyclerecent-prev)
+                                       (define-key map (kbd "<C-down>") 'notmuch-hello-cyclerecent-next)
+                                       map)))
 	(widget-insert "\n")
 
 	(when notmuch-hello-recent-searches
@@ -535,6 +569,7 @@ Complete list of currently available key bindings:
 	(widget-insert "Type a search query and hit RET to view matching threads.\n")
 	(when notmuch-hello-recent-searches
 	  (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")
+	  (widget-insert "In the search box, C-up/C-down cycles through the recent searches.\n")
 	  (widget-insert "Save recent searches with the `save' button.\n"))
 	(when notmuch-saved-searches
 	  (widget-insert "Edit saved searches with the `edit' button.\n"))
-- 
1.7.4.4

             reply	other threads:[~2011-05-29  8:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-29  8:56 notmuch [this message]
2011-05-29 16:04 ` [PATCH] Added C-up and C-down to cycle through previous searches Dmitry Kurochkin
2011-06-04 20:07   ` Dima Kogan
2011-06-05  7:28     ` Dmitry Kurochkin
2011-06-07  6:26       ` Dima Kogan
2011-06-05  7:25   ` Xavier Maillard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1306659388-21809-1-git-send-email-notmuch@dima.secretsauce.net \
    --to=notmuch@dima.secretsauce.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).