[PATCH] emacs: support limiting the number of results shown in search results
authorJani Nikula <jani@nikula.org>
Fri, 27 Jan 2012 19:35:00 +0000 (21:35 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:25 +0000 (09:43 -0800)
3f/4dff3c01677a1ce2cb936d5c1376744dc9cd8f [new file with mode: 0644]

diff --git a/3f/4dff3c01677a1ce2cb936d5c1376744dc9cd8f b/3f/4dff3c01677a1ce2cb936d5c1376744dc9cd8f
new file mode 100644 (file)
index 0000000..4924002
--- /dev/null
@@ -0,0 +1,276 @@
+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 610E1431FBC\r
+       for <notmuch@notmuchmail.org>; Fri, 27 Jan 2012 11:35:10 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 KZGBpkgrRpv3 for <notmuch@notmuchmail.org>;\r
+       Fri, 27 Jan 2012 11:35:08 -0800 (PST)\r
+Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
+       [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id BAE62431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 27 Jan 2012 11:35:07 -0800 (PST)\r
+Received: by lahd3 with SMTP id d3so1401443lah.26\r
+       for <notmuch@notmuchmail.org>; Fri, 27 Jan 2012 11:35:04 -0800 (PST)\r
+Received: by 10.112.23.229 with SMTP id p5mr2089168lbf.21.1327692904776;\r
+       Fri, 27 Jan 2012 11:35:04 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
+       [84.248.80.253])\r
+       by mx.google.com with ESMTPS id w8sm6611795lbm.8.2012.01.27.11.35.01\r
+       (version=SSLv3 cipher=OTHER); Fri, 27 Jan 2012 11:35:03 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: support limiting the number of results shown in search\r
+       results\r
+Date: Fri, 27 Jan 2012 21:35:00 +0200\r
+Message-Id: <1327692900-22926-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\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, 27 Jan 2012 19:35:10 -0000\r
+\r
+Add support for limiting the maximum number of results initially displayed\r
+in search results. When enabled, the search results will contain push\r
+buttons to double the number of results displayed or to show unlimited\r
+results.\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
+---\r
+\r
+Rebased since id:"1321560458-32010-1-git-send-email-jani@nikula.org",\r
+and added option to limit results to window height. Limiting does not\r
+work through the 's' key binding in search view, and some of the\r
+issues reported by Austin in id:"20111104205415.GJ22935@mit.edu" and\r
+Aneesh in id:"87hb1gu643.fsf@linux.vnet.ibm.com" are unfortunately\r
+still there.\r
+\r
+If anyone wants to pick this up from here, I'd be delighted. I use\r
+this, but don't have the time to polish. This is just to share the\r
+rebased patch as Aneesh was asking for it on IRC.\r
+---\r
+ emacs/notmuch-hello.el |   21 +++++++++++++--\r
+ emacs/notmuch.el       |   64 +++++++++++++++++++++++++++++++++++++++--------\r
+ 2 files changed, 71 insertions(+), 14 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index d17a30f..9ed68e2 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 limit target-thread target-line continuation))\r
+ (declare-function notmuch-poll "notmuch" ())\r
\r
+ (defcustom notmuch-hello-recent-searches-max 10\r
+@@ -34,6 +34,21 @@\r
+   :type 'integer\r
+   :group 'notmuch-hello)\r
\r
++(defcustom notmuch-search-limit nil\r
++  "The maximum number of results to show in search results.\r
++\r
++This variables controls the maximum number of results to\r
++initially show in search results. Set to 0 to limit to window\r
++height. The search results will contain push buttons to double\r
++the number (can be repeated) or show unlimited number of results.\r
++\r
++If set to nil, the number of results is not limited."\r
++  :type '(choice (const :tag "Unlimited" nil)\r
++               (const :tag "Window height" 0)\r
++               (integer :tag "Limit"))\r
++  :group 'notmuch-search\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
+@@ -178,7 +193,7 @@ International Bureau of Weights and Measures."\r
+     (setq search (notmuch-hello-trim search))\r
+     (let ((history-delete-duplicates t))\r
+       (add-to-history 'notmuch-search-history search)))\r
+-  (notmuch-search search notmuch-search-oldest-first nil nil\r
++  (notmuch-search search notmuch-search-oldest-first notmuch-search-limit nil nil\r
+                 #'notmuch-hello-search-continuation))\r
\r
+ (defun notmuch-hello-add-saved-search (widget)\r
+@@ -228,7 +243,7 @@ diagonal."\r
+ (defun notmuch-hello-widget-search (widget &rest ignore)\r
+   (notmuch-search (widget-get widget\r
+                             :notmuch-search-terms)\r
+-                notmuch-search-oldest-first\r
++                notmuch-search-oldest-first notmuch-search-limit\r
+                 nil nil #'notmuch-hello-search-continuation))\r
\r
+ (defun notmuch-saved-search-count (search)\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 72f78ed..b3fef88 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -231,6 +231,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
+@@ -277,6 +278,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-limit)\r
\r
+ (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")\r
\r
+@@ -418,6 +420,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-limit)\r
+   (set (make-local-variable 'notmuch-search-continuation) nil)\r
+   (set (make-local-variable 'scroll-preserve-screen-position) t)\r
+   (add-to-invisibility-spec (cons 'ellipsis t))\r
+@@ -680,6 +683,11 @@ This function advances the next thread when finished."\r
+                       (insert "End of search results.")\r
+                       (unless (= exit-status 0)\r
+                         (insert (format " (process returned %d)" exit-status)))\r
++                      (if (and notmuch-search-limit\r
++                               (< 0 notmuch-search-limit)\r
++                               (< notmuch-search-limit\r
++                                  (count-lines (point-min) (point-max))))\r
++                          (notmuch-search-setup-buttons))\r
+                       (insert "\n")\r
+                       (if (and atbob\r
+                                (not (string= notmuch-search-target-thread "found")))\r
+@@ -957,7 +965,7 @@ PROMPT is the string to prompt with."\r
+                             'notmuch-search-history nil nil)))))\r
\r
+ ;;;###autoload\r
+-(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
++(defun notmuch-search (&optional query oldest-first limit target-thread target-line continuation)\r
+   "Run \"notmuch search\" with the given `query' and display results.\r
\r
+ If `query' is nil, it is read interactively from the minibuffer.\r
+@@ -978,6 +986,9 @@ Other optional parameters are used as follows:\r
+     (set 'buffer-undo-list t)\r
+     (set 'notmuch-search-query-string query)\r
+     (set 'notmuch-search-oldest-first oldest-first)\r
++    (if (and limit (= limit 0))\r
++      (setq limit (- (window-body-height) 1)))\r
++    (set 'notmuch-search-limit limit)\r
+     (set 'notmuch-search-target-thread target-thread)\r
+     (set 'notmuch-search-target-line target-line)\r
+     (set 'notmuch-search-continuation continuation)\r
+@@ -989,13 +1000,19 @@ Other optional parameters are used as follows:\r
+       (erase-buffer)\r
+       (goto-char (point-min))\r
+       (save-excursion\r
+-      (let ((proc (start-process\r
+-                   "notmuch-search" buffer\r
+-                   notmuch-command "search"\r
+-                   (if oldest-first\r
+-                       "--sort=oldest-first"\r
+-                     "--sort=newest-first")\r
+-                   query)))\r
++      (let* ((args (append\r
++                    (if oldest-first\r
++                        (list "--sort=oldest-first")\r
++                      (list "--sort=newest-first"))\r
++                    (if (and limit (< 0 limit))\r
++                        (if oldest-first\r
++                            (list (format "--offset=-%d" limit))\r
++                          (list (format "--limit=%d" limit))))\r
++                    (list query)))\r
++             (proc (apply 'start-process\r
++                          "notmuch-search" buffer\r
++                          notmuch-command "search"\r
++                          args)))\r
+         (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
+         (set-process-filter proc 'notmuch-search-process-filter)\r
+         (set-process-query-on-exit-flag proc nil))))\r
+@@ -1012,13 +1029,38 @@ 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
++      (limit notmuch-search-limit)\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 limit target-thread target-line continuation)\r
+     (goto-char (point-min))))\r
\r
++(defun notmuch-search-double-results (&rest ignore)\r
++  (if notmuch-search-limit\r
++      (setq notmuch-search-limit (* 2 notmuch-search-limit)))\r
++  (notmuch-search-refresh-view))\r
++\r
++(defun notmuch-search-unlimited-results (&rest ignore)\r
++  (setq notmuch-search-limit nil)\r
++  (notmuch-search-refresh-view))\r
++\r
++(defun notmuch-search-setup-buttons ()\r
++  (widget-insert "    ")\r
++  (widget-create 'push-button\r
++               :keymap widget-keymap\r
++               :notify 'notmuch-search-double-results\r
++               :help-echo "Double the number of results shown"\r
++               "Show 2X results")\r
++  (widget-insert "    ")\r
++  (widget-create 'push-button\r
++               :keymap widget-keymap\r
++               :notify 'notmuch-search-unlimited-results\r
++               :help-echo "Show all search results"\r
++               "Show unlimited results")\r
++  (widget-setup))\r
++\r
+ (defcustom notmuch-poll-script nil\r
+   "An external script to incorporate new mail into the notmuch database.\r
\r
+@@ -1092,7 +1134,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-limit)))\r
\r
+ (defun notmuch-search-filter-by-tag (tag)\r
+   "Filter the current search results based on a single tag.\r
+@@ -1101,7 +1143,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-limit))\r
\r
+ ;;;###autoload\r
+ (defun notmuch ()\r
+-- \r
+1.7.5.4\r
+\r