[PATCH 1/4] emacs: unify search mechanisms
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Sun, 25 Dec 2011 04:14:52 +0000 (08:14 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:16 +0000 (09:41 -0800)
ba/fe1b46b56c36b9698d420c2d82a54f5135e22f [new file with mode: 0644]

diff --git a/ba/fe1b46b56c36b9698d420c2d82a54f5135e22f b/ba/fe1b46b56c36b9698d420c2d82a54f5135e22f
new file mode 100644 (file)
index 0000000..aaacb3e
--- /dev/null
@@ -0,0 +1,323 @@
+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 5A34D431FD0\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Dec 2011 20:15:44 -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 JUJTB9AWfiXu for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Dec 2011 20:15:43 -0800 (PST)\r
+Received: from mail-ww0-f41.google.com (mail-ww0-f41.google.com\r
+ [74.125.82.41])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 0C1D8431FB6   for <notmuch@notmuchmail.org>; Sat, 24 Dec 2011 20:15:42 -0800\r
+ (PST)\r
+Received: by wgbdt12 with SMTP id dt12so13853151wgb.2\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Dec 2011 20:15:41 -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;\r
+       bh=VL7Hio/hj4qJxsagobWOhX44OFZvli/fB/OimXpjcIo=;\r
+       b=WU4t5QhWvAXI1v1Jg9D67ZDIwuPuXN6aVjR+2fjl43IWlw5Tk+Fa4Goet+/q+GYmKh\r
+       u7VRpIqNn7lIeJXQDYai8aNbZMSNj8Eh5+B9NaUKY5Zi+/bL9SEXDTGRF3eXMlyTgInF\r
+       Jl/5x/vslN8AasY222ZIhSqW8wl9wEctEvaGY=\r
+Received: by 10.216.139.153 with SMTP id c25mr16806285wej.25.1324786541657;\r
+       Sat, 24 Dec 2011 20:15:41 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id z5sm45488534wix.5.2011.12.24.20.15.40\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 24 Dec 2011 20:15:41 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/4] emacs: unify search mechanisms\r
+Date: Sun, 25 Dec 2011 08:14:52 +0400\r
+Message-Id: <1324786495-14221-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.7.3\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: Sun, 25 Dec 2011 04:15:44 -0000\r
+\r
+Before the change, there were two ways to do search in Emacs UI:\r
+search widget in notmuch-hello buffer and `notmuch-search'\r
+function bound to "s".  Internally, notmuch-hello search widget\r
+uses `notmuch-search' function.  But it uses widget field input\r
+instead of minibuffer.  Such duplication is a major issue for\r
+notmuch-hello usability: search interface is inconsistent and\r
+lacks features that are available in minibuffer (e.g. history and\r
+auto completion).  Some of these features may be relatively easy\r
+to implement for notmuch-hello search, others would be much more\r
+tricky.  So to avoid duplication, make UI more consistent, bring\r
+notmuch-hello search to feature parity with the minibuffer\r
+search, the patch replaces notmuch-hello search widget and with a\r
+button that works the same way as "s" key binding.\r
+---\r
+ emacs/notmuch-hello.el |   84 +++++++++++++++---------------------------------\r
+ emacs/notmuch-lib.el   |    9 +++++\r
+ emacs/notmuch.el       |   20 ++++++-----\r
+ 3 files changed, 46 insertions(+), 67 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 333d4c1..eb08a09 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -29,11 +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
+-(defvar notmuch-hello-search-bar-marker nil\r
+-  "The position of the search bar within the notmuch-hello buffer.")\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)\r
\r
+@@ -154,16 +151,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 +163,10 @@ 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
++(defun notmuch-hello-search (&optional search)\r
++  (interactive)\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
+@@ -319,11 +300,6 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+       (widget-insert "\n"))\r
+     found-target-pos))\r
\r
+-(defun notmuch-hello-goto-search ()\r
+-  "Put point inside the `search' widget."\r
+-  (interactive)\r
+-  (goto-char notmuch-hello-search-bar-marker))\r
+-\r
+ (defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))\r
\r
+ (defun notmuch-hello-search-continuation()\r
+@@ -353,7 +329,7 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+     (define-key map "G" 'notmuch-hello-poll-and-update)\r
+     (define-key map (kbd "<C-tab>") 'widget-backward)\r
+     (define-key map "m" 'notmuch-mua-new-mail)\r
+-    (define-key map "s" 'notmuch-hello-goto-search)\r
++    (define-key map "s" 'notmuch-hello-search)\r
+     map)\r
+   "Keymap for \"notmuch hello\" buffers.")\r
+ (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)\r
+@@ -466,7 +442,8 @@ Complete list of currently available key bindings:\r
+       (widget-insert " messages.\n"))\r
\r
+     (let ((found-target-pos nil)\r
+-        (final-target-pos nil))\r
++        (final-target-pos nil)\r
++        (default-pos))\r
+       (let* ((saved-alist\r
+             ;; Filter out empty saved searches if required.\r
+             (if notmuch-show-empty-saved-searches\r
+@@ -497,33 +474,26 @@ Complete list of currently available key bindings:\r
+               (setq final-target-pos found-target-pos))\r
+           (indent-rigidly start (point) notmuch-hello-indent)))\r
\r
+-      (widget-insert "\nSearch: ")\r
+-      (setq notmuch-hello-search-bar-marker (point-marker))\r
+-      (widget-create 'editable-field\r
+-                     ;; Leave some space at the start and end of the\r
+-                     ;; search boxes.\r
+-                     :size (max 8 (- (window-width) notmuch-hello-indent\r
+-                                     (length "Search: ")))\r
+-                     :action (lambda (widget &rest ignore)\r
+-                               (notmuch-hello-search (widget-value widget))))\r
+-      ;; add an invisible space to make `widget-end-of-line' ignore\r
+-      ;; trailine spaces in the search widget field\r
+-      (widget-insert " ")\r
+-      (put-text-property (1- (point)) (point) 'invisible t)\r
++      (widget-insert "\n")\r
++      (setq default-pos (point-marker))\r
++      (widget-create 'push-button\r
++                     :notify (lambda (&rest ignore)\r
++                               (notmuch-hello-search))\r
++                     " Search! ")\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
+@@ -550,9 +520,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
+@@ -580,14 +548,14 @@ Complete list of currently available key bindings:\r
\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
++      (widget-insert "Use the `search' button or hit `s' to enter search query.\n")\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
+         (widget-insert "Edit saved searches with the `edit' button.\n"))\r
+       (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")\r
+-      (widget-insert "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n")\r
++      (widget-insert "`=' refreshes this screen. `s' to search messages. `q' to quit.\n")\r
+       (let ((fill-column (- (window-width) notmuch-hello-indent)))\r
+         (center-region start (point))))\r
\r
+@@ -599,7 +567,7 @@ Complete list of currently available key bindings:\r
+         (widget-forward 1)))\r
\r
+       (unless (widget-at)\r
+-      (notmuch-hello-goto-search))))\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 0f856bf..a2cb6f2 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -35,6 +35,9 @@\r
\r
+ ;;\r
\r
++(defvar notmuch-search-history nil\r
++  "Variable to store minibuffer history for notmuch searches.")\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
+@@ -114,6 +117,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 fde2377..938a149 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -72,9 +72,6 @@ For example:\r
+   :type '(alist :key-type (string) :value-type (string))\r
+   :group 'notmuch)\r
\r
+-(defvar notmuch-query-history nil\r
+-  "Variable to store minibuffer history for notmuch queries")\r
+-\r
+ (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
+   (let ((tag-list\r
+        (with-output-to-string\r
+@@ -902,21 +899,26 @@ 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 ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
+     (switch-to-buffer buffer)\r
+     (notmuch-search-mode)\r
+-- \r
+1.7.7.3\r
+\r