[RFC PATCH 3/3] emacs: support limiting the number of messages shown in search results
authorJani Nikula <jani@nikula.org>
Fri, 28 Oct 2011 20:59:31 +0000 (23:59 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:50 +0000 (09:39 -0800)
fb/b641fc2653b87fd17ce047077c9b8b28f755f4 [new file with mode: 0644]

diff --git a/fb/b641fc2653b87fd17ce047077c9b8b28f755f4 b/fb/b641fc2653b87fd17ce047077c9b8b28f755f4
new file mode 100644 (file)
index 0000000..a1a40e8
--- /dev/null
@@ -0,0 +1,254 @@
+Return-Path: <jani@nikula.org>\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 02B77429E26\r
+       for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:54 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 A0XWRPRnd0lj for <notmuch@notmuchmail.org>;\r
+       Fri, 28 Oct 2011 13:59:52 -0700 (PDT)\r
+Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
+       [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id B9E10429E21\r
+       for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:50 -0700 (PDT)\r
+Received: by mail-fx0-f53.google.com with SMTP id i28so4419077faa.26\r
+       for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:50 -0700 (PDT)\r
+Received: by 10.223.91.143 with SMTP id n15mr8562643fam.23.1319835590481;\r
+       Fri, 28 Oct 2011 13:59:50 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id v19sm19448615faa.13.2011.10.28.13.59.48\r
+       (version=SSLv3 cipher=OTHER); Fri, 28 Oct 2011 13:59:49 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 3/3] emacs: support limiting the number of messages shown\r
+       in search results\r
+Date: Fri, 28 Oct 2011 23:59:31 +0300\r
+Message-Id:\r
+ <0290050284e4cb3a6f5ef0eb3582319f8d52ccf2.1319833617.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1319833617.git.jani@nikula.org>\r
+References: <cover.1319833617.git.jani@nikula.org>\r
+In-Reply-To: <cover.1319833617.git.jani@nikula.org>\r
+References: <cover.1319833617.git.jani@nikula.org>\r
+Cc: amdragon@mit.edu\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: Fri, 28 Oct 2011 20:59:54 -0000\r
+\r
+Add support for limiting the maximum number of messages initially displayed\r
+in search results. When enabled, the search results will contain push\r
+buttons to double the number of messages displayed or to show unlimited\r
+messages.\r
+\r
+The approach is inspired by vc-print-log in Emacs vc.el.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ emacs/notmuch-hello.el |   19 ++++++++++++++++---\r
+ emacs/notmuch.el       |   43 ++++++++++++++++++++++++++++++++++++++-----\r
+ 2 files changed, 54 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 65fde75..16eecb6 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -26,7 +26,7 @@\r
+ (require 'notmuch-lib)\r
+ (require 'notmuch-mua)\r
\r
+-(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
++(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation maxitems))\r
+ (declare-function notmuch-poll "notmuch" ())\r
\r
+ (defvar notmuch-hello-search-bar-marker nil\r
+@@ -37,6 +37,18 @@\r
+   :type 'integer\r
+   :group 'notmuch)\r
\r
++(defcustom notmuch-search-maxitems 100\r
++  "The maximum number of messages to show in search results.\r
++\r
++This variables controls the maximum number of messages to\r
++initially show in search results. Set to 0 to unlimited. If\r
++non-zero, the search results will contain push buttons to double\r
++the number (can be repeated) or show unlimited number of\r
++messages. Note that this controls the number of messages; in a\r
++threaded view this is not the number of lines to show."\r
++  :type 'integer\r
++  :group 'notmuch)\r
++\r
+ (defcustom notmuch-show-empty-saved-searches nil\r
+   "Should saved searches with no messages be listed?"\r
+   :type 'boolean\r
+@@ -151,7 +163,7 @@ Typically \",\" in the US and UK and \".\" in Europe."\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 #'notmuch-hello-search-continuation notmuch-search-maxitems)))\r
\r
+ (defun notmuch-hello-add-saved-search (widget)\r
+   (interactive)\r
+@@ -201,7 +213,8 @@ diagonal."\r
+   (notmuch-search (widget-get widget\r
+                             :notmuch-search-terms)\r
+                 notmuch-search-oldest-first\r
+-                nil nil #'notmuch-hello-search-continuation))\r
++                nil nil #'notmuch-hello-search-continuation\r
++                notmuch-search-maxitems))\r
\r
+ (defun notmuch-saved-search-count (search)\r
+   (car (process-lines notmuch-command "count" search)))\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index f11ec24..bb805da 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -193,6 +193,7 @@ For a mouse binding, return nil."\r
\r
+ (defvar notmuch-search-mode-map\r
+   (let ((map (make-sparse-keymap)))\r
++    (set-keymap-parent map widget-keymap)\r
+     (define-key map "?" 'notmuch-help)\r
+     (define-key map "q" 'notmuch-search-quit)\r
+     (define-key map "x" 'notmuch-search-quit)\r
+@@ -217,7 +218,13 @@ For a mouse binding, return nil."\r
+     (define-key map "a" 'notmuch-search-archive-thread)\r
+     (define-key map "-" 'notmuch-search-remove-tag)\r
+     (define-key map "+" 'notmuch-search-add-tag)\r
+-    (define-key map (kbd "RET") 'notmuch-search-show-thread)\r
++    ; Some hackery to allow RET both on buttons and messages. There's probably a\r
++    ; better way to do this...\r
++    (define-key map (kbd "RET") '(lambda (pos)\r
++                                 (interactive "@d")\r
++                                 (if (get-char-property pos 'button)\r
++                                     (widget-button-press pos)\r
++                                   (notmuch-search-show-thread))))\r
+     (define-key map (kbd "M-RET") 'notmuch-search-show-thread-crypto-switch)\r
+     map)\r
+   "Keymap for \"notmuch search\" buffers.")\r
+@@ -239,6 +246,7 @@ For a mouse binding, return nil."\r
+ (defvar notmuch-search-target-thread)\r
+ (defvar notmuch-search-target-line)\r
+ (defvar notmuch-search-continuation)\r
++(defvar notmuch-search-maxitems)\r
\r
+ (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")\r
\r
+@@ -373,6 +381,7 @@ Complete list of currently available key bindings:\r
+   (make-local-variable 'notmuch-search-oldest-first)\r
+   (make-local-variable 'notmuch-search-target-thread)\r
+   (make-local-variable 'notmuch-search-target-line)\r
++  (make-local-variable 'notmuch-search-maxitems)\r
+   (set (make-local-variable 'notmuch-search-continuation) nil)\r
+   (set (make-local-variable 'scroll-preserve-screen-position) t)\r
+   (add-to-invisibility-spec 'notmuch-search)\r
+@@ -633,6 +642,8 @@ This function advances the next thread when finished."\r
+                       (insert "End of search results.")\r
+                       (if (not (= exit-status 0))\r
+                           (insert (format " (process returned %d)" exit-status)))\r
++                      (if notmuch-search-maxitems\r
++                          (notmuch-search-setup-buttons))\r
+                       (insert "\n")\r
+                       (if (and atbob\r
+                                (not (string= notmuch-search-target-thread "found")))\r
+@@ -883,7 +894,7 @@ characters as well as `_.+-'.\r
+         )))\r
\r
+ ;;;###autoload\r
+-(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
++(defun notmuch-search (query &optional oldest-first target-thread target-line continuation maxitems)\r
+   "Run \"notmuch search\" with the given query string and display results.\r
\r
+ The optional parameters are used as follows:\r
+@@ -899,6 +910,7 @@ The optional parameters are used as follows:\r
+     (notmuch-search-mode)\r
+     (set 'notmuch-search-query-string query)\r
+     (set 'notmuch-search-oldest-first oldest-first)\r
++    (set 'notmuch-search-maxitems maxitems)\r
+     (set 'notmuch-search-target-thread target-thread)\r
+     (set 'notmuch-search-target-line target-line)\r
+     (set 'notmuch-search-continuation continuation)\r
+@@ -916,6 +928,8 @@ The optional parameters are used as follows:\r
+                    (if oldest-first\r
+                        "--sort=oldest-first"\r
+                      "--sort=newest-first")\r
++                   (if maxitems\r
++                       (format "--maxitems=%d" maxitems))\r
+                    query)))\r
+         (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
+         (set-process-filter proc 'notmuch-search-process-filter))))\r
+@@ -932,13 +946,32 @@ same relative position within the new buffer."\r
+   (interactive)\r
+   (let ((target-line (line-number-at-pos))\r
+       (oldest-first notmuch-search-oldest-first)\r
++      (maxitems notmuch-search-maxitems)\r
+       (target-thread (notmuch-search-find-thread-id))\r
+       (query notmuch-search-query-string)\r
+       (continuation notmuch-search-continuation))\r
+     (notmuch-kill-this-buffer)\r
+-    (notmuch-search query oldest-first target-thread target-line continuation)\r
++    (notmuch-search query oldest-first target-thread target-line continuation maxitems)\r
+     (goto-char (point-min))))\r
\r
++(defun notmuch-search-setup-buttons ()\r
++  (widget-insert "    ")\r
++  (widget-create 'push-button\r
++               :notify (lambda (&rest ignore)\r
++                         (set 'notmuch-search-maxitems\r
++                              (* 2 notmuch-search-maxitems))\r
++                         (notmuch-search-refresh-view))\r
++               :help-echo "Double the number of messages shown"\r
++               "Show 2X messages")\r
++  (widget-insert "    ")\r
++  (widget-create 'push-button\r
++               :notify (lambda (&rest ignore)\r
++                         (set 'notmuch-search-maxitems 0)\r
++                         (notmuch-search-refresh-view))\r
++               :help-echo "Show all search results"\r
++               "Show unlimited messages")\r
++  (widget-setup))\r
++\r
+ (defcustom notmuch-poll-script ""\r
+   "An external script to incorporate new mail into the notmuch database.\r
\r
+@@ -997,7 +1030,7 @@ current search results AND the additional query string provided."\r
+                        query)))\r
+     (notmuch-search (if (string= notmuch-search-query-string "*")\r
+                       grouped-query\r
+-                    (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))\r
++                    (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first notmuch-search-maxitems)))\r
\r
+ (defun notmuch-search-filter-by-tag (tag)\r
+   "Filter the current search results based on a single tag.\r
+@@ -1006,7 +1039,7 @@ Runs a new search matching only messages that match both the\r
+ current search results AND that are tagged with the given tag."\r
+   (interactive\r
+    (list (notmuch-select-tag-with-completion "Filter by tag: ")))\r
+-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))\r
++  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first notmuch-search-maxitems))\r
\r
+ ;;;###autoload\r
+ (defun notmuch ()\r
+-- \r
+1.7.5.4\r
+\r