[PATCH v3 2/3] emacs: use a single history for all searches
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Mon, 23 Jan 2012 23:48:56 +0000 (03:48 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:05 +0000 (09:43 -0800)
d4/925d5b853a4c99e60101b0c814c2964833dbb7 [new file with mode: 0644]

diff --git a/d4/925d5b853a4c99e60101b0c814c2964833dbb7 b/d4/925d5b853a4c99e60101b0c814c2964833dbb7
new file mode 100644 (file)
index 0000000..550398c
--- /dev/null
@@ -0,0 +1,262 @@
+Return-Path: <dmitry.kurochkin@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5A3AE429E54\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:50:15 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 2lPc1Ecq+DQp for <notmuch@notmuchmail.org>;\r
+       Mon, 23 Jan 2012 15:50:14 -0800 (PST)\r
+Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 14F58429E21\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:50:13 -0800 (PST)\r
+Received: by mail-bk0-f53.google.com with SMTP id zt19so1828294bkb.26\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:50:13 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=4EiKU3AGAv7JwLi7JWbgf0NYp+1YsEjGaS3DwkrAI/0=;\r
+       b=MbrYKJBEu/hLvmtf6ymjTUYep7MGXCYGPcqz0xgfOJGZIR52v/HKxK2QZ2g331SI0Z\r
+       sQNRcFAN3Pd1AHAEbx/MFkw0uo0MvWWpbq6IRqzo9T3CmIJi/E6lYEIPByOEzhxsdunA\r
+       8fBC/ryNQz9n0wBYV3PHWP9YpXe9E0y+cNbWw=\r
+Received: by 10.204.149.220 with SMTP id u28mr4150501bkv.100.1327362613719;\r
+       Mon, 23 Jan 2012 15:50:13 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id sp6sm31934209bkb.2.2012.01.23.15.50.12\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 23 Jan 2012 15:50:13 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/3] emacs: use a single history for all searches\r
+Date: Tue, 24 Jan 2012 03:48:56 +0400\r
+Message-Id: <1327362537-9607-3-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1327362537-9607-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1326918176-20352-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1327362537-9607-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 23 Jan 2012 23:50:15 -0000\r
+\r
+There are two ways to do search in Emacs UI: search widget in\r
+notmuch-hello buffer and `notmuch-search' function bound to "s".\r
+Before the change, these search mechanisms used different history\r
+lists.  The patch makes notmuch-hello search use the same history list\r
+as `notmuch-search' function.\r
+---\r
+ emacs/notmuch-hello.el |   49 ++++++++++++++---------------------------------\r
+ emacs/notmuch-lib.el   |    9 ++++++++\r
+ emacs/notmuch.el       |   19 ++++++++++++-----\r
+ 3 files changed, 37 insertions(+), 40 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index d88a870..004287a 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -29,8 +29,8 @@\r
+ (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
+ (declare-function notmuch-poll "notmuch" ())\r
\r
+-(defcustom notmuch-recent-searches-max 10\r
+-  "The number of recent searches to store and display."\r
++(defcustom notmuch-hello-recent-searches-max 10\r
++  "The number of recent searches to display."\r
+   :type 'integer\r
+   :group 'notmuch-hello)\r
\r
+@@ -154,16 +154,6 @@ International Bureau of Weights and Measures."\r
+ (defvar notmuch-hello-url "http://notmuchmail.org"\r
+   "The `notmuch' web site.")\r
\r
+-(defvar notmuch-hello-recent-searches nil)\r
+-\r
+-(defun notmuch-hello-remember-search (search)\r
+-  (setq notmuch-hello-recent-searches\r
+-      (delete search notmuch-hello-recent-searches))\r
+-  (push search notmuch-hello-recent-searches)\r
+-  (if (> (length notmuch-hello-recent-searches)\r
+-       notmuch-recent-searches-max)\r
+-      (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches))))\r
+-\r
+ (defun notmuch-hello-nice-number (n)\r
+   (let (result)\r
+     (while (> n 0)\r
+@@ -176,16 +166,9 @@ International Bureau of Weights and Measures."\r
+             (format "%s%03d" notmuch-hello-thousands-separator elem))\r
+            (cdr result)))))\r
\r
+-(defun notmuch-hello-trim (search)\r
+-  "Trim whitespace."\r
+-  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)\r
+-      (match-string 1 search)\r
+-    search))\r
+-\r
+ (defun notmuch-hello-search (search)\r
+-  (let ((search (notmuch-hello-trim search)))\r
+-    (notmuch-hello-remember-search search)\r
+-    (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))\r
++  (notmuch-search search notmuch-search-oldest-first nil nil\r
++                #'notmuch-hello-search-continuation))\r
\r
+ (defun notmuch-hello-add-saved-search (widget)\r
+   (interactive)\r
+@@ -464,7 +447,7 @@ Complete list of currently available key bindings:\r
\r
+     (let ((found-target-pos nil)\r
+         (final-target-pos nil)\r
+-        (search-bar-pos))\r
++        (default-pos))\r
+       (let* ((saved-alist\r
+             ;; Filter out empty saved searches if required.\r
+             (if notmuch-show-empty-saved-searches\r
+@@ -496,7 +479,7 @@ Complete list of currently available key bindings:\r
+           (indent-rigidly start (point) notmuch-hello-indent)))\r
\r
+       (widget-insert "\nSearch: ")\r
+-      (setq search-bar-pos (point-marker))\r
++      (setq default-pos (point-marker))\r
+       (widget-create 'editable-field\r
+                      ;; Leave some space at the start and end of the\r
+                      ;; search boxes.\r
+@@ -513,18 +496,18 @@ Complete list of currently available key bindings:\r
+       (put-text-property (1- (point)) (point) 'invisible t)\r
+       (widget-insert "\n")\r
\r
+-      (when notmuch-hello-recent-searches\r
++      (when notmuch-search-history\r
+         (widget-insert "\nRecent searches: ")\r
+         (widget-create 'push-button\r
+                        :notify (lambda (&rest ignore)\r
+-                                 (setq notmuch-hello-recent-searches nil)\r
++                                 (setq notmuch-search-history nil)\r
+                                  (notmuch-hello-update))\r
+                        "clear")\r
+         (widget-insert "\n\n")\r
+-        (let ((start (point))\r
+-              (nth 0))\r
+-          (mapc (lambda (search)\r
+-                  (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))\r
++        (let ((start (point)))\r
++          (loop for i from 1 to notmuch-hello-recent-searches-max\r
++                for search in notmuch-search-history do\r
++                  (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))\r
+                     (set widget-symbol\r
+                          (widget-create 'editable-field\r
+                                         ;; Don't let the search boxes be\r
+@@ -551,9 +534,7 @@ Complete list of currently available key bindings:\r
+                                              (notmuch-hello-add-saved-search widget))\r
+                                    :notmuch-saved-search-widget widget-symbol\r
+                                    "save"))\r
+-                  (widget-insert "\n")\r
+-                  (setq nth (1+ nth)))\r
+-                notmuch-hello-recent-searches)\r
++                  (widget-insert "\n"))\r
+           (indent-rigidly start (point) notmuch-hello-indent)))\r
\r
+       (when alltags-alist\r
+@@ -582,7 +563,7 @@ Complete list of currently available key bindings:\r
+       (let ((start (point)))\r
+       (widget-insert "\n\n")\r
+       (widget-insert "Type a search query and hit RET to view matching threads.\n")\r
+-      (when notmuch-hello-recent-searches\r
++      (when notmuch-search-history\r
+         (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")\r
+         (widget-insert "Save recent searches with the `save' button.\n"))\r
+       (when notmuch-saved-searches\r
+@@ -600,7 +581,7 @@ Complete list of currently available key bindings:\r
+         (widget-forward 1)))\r
\r
+       (unless (widget-at)\r
+-      (goto-char search-bar-pos))))\r
++      (goto-char default-pos))))\r
\r
+   (run-hooks 'notmuch-hello-refresh-hook))\r
\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 241fe8c..36b895c 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -69,6 +69,9 @@\r
\r
+ ;;\r
\r
++(defvar notmuch-search-history nil\r
++  "Variable to store notmuch searches history.")\r
++\r
+ (defcustom notmuch-saved-searches nil\r
+   "A list of saved searches to display."\r
+   :type '(alist :key-type string :value-type string)\r
+@@ -148,6 +151,12 @@ the user hasn't set this variable with the old or new value."\r
+       (setq list (cdr list)))\r
+     (nreverse out)))\r
\r
++(defun notmuch-trim (search)\r
++  "Trim whitespaces."\r
++  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)\r
++      (match-string 1 search)\r
++    search))\r
++\r
+ ;; This lets us avoid compiling these replacement functions when emacs\r
+ ;; is sufficiently new enough to supply them alone. We do the macro\r
+ ;; treatment rather than just wrapping our defun calls in a when form\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 6b2c252..e9e5dc1 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -925,21 +925,28 @@ PROMPT is the string to prompt with."\r
+              (t (list string)))))))\r
+       ;; this was simpler than convincing completing-read to accept spaces:\r
+       (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
+-      (read-from-minibuffer prompt nil keymap nil\r
+-                          'notmuch-query-history nil nil))))\r
++      (let ((history-delete-duplicates t))\r
++      (read-from-minibuffer prompt nil keymap nil\r
++                            'notmuch-search-history nil nil)))))\r
\r
+ ;;;###autoload\r
+-(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
+-  "Run \"notmuch search\" with the given query string and display results.\r
++(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
++  "Run \"notmuch search\" with the given `query' and display results.\r
\r
+-The optional parameters are used as follows:\r
++If `query' is nil, it is read interactively from the minibuffer.\r
++Other optional parameters are used as follows:\r
\r
+   oldest-first: A Boolean controlling the sort order of returned threads\r
+   target-thread: A thread ID (with the thread: prefix) that will be made\r
+                  current if it appears in the search results.\r
+   target-line: The line number to move to if the target thread does not\r
+                appear in the search results."\r
+-  (interactive (list (notmuch-read-query "Notmuch search: ")))\r
++  (interactive)\r
++  (if (null query)\r
++      (setq query (notmuch-read-query "Notmuch search: "))\r
++    (setq query (notmuch-trim query))\r
++    (let ((history-delete-duplicates t))\r
++      (add-to-history 'notmuch-search-history query)))\r
+   (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
+     (switch-to-buffer buffer)\r
+     (notmuch-search-mode)\r
+-- \r
+1.7.8.3\r
+\r