Re: [RFC PATCH v2 3/3] emacs: support limiting the number of results shown in search...
authorJani Nikula <jani@nikula.org>
Sun, 6 Nov 2011 20:57:21 +0000 (22:57 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:00 +0000 (09:40 -0800)
6f/c696d856a9a337293ff747854042de39fdcff5 [new file with mode: 0644]

diff --git a/6f/c696d856a9a337293ff747854042de39fdcff5 b/6f/c696d856a9a337293ff747854042de39fdcff5
new file mode 100644 (file)
index 0000000..61653d8
--- /dev/null
@@ -0,0 +1,324 @@
+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 5B1C3429E21\r
+       for <notmuch@notmuchmail.org>; Sun,  6 Nov 2011 12:57:29 -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 xxLVia6Cp2nW for <notmuch@notmuchmail.org>;\r
+       Sun,  6 Nov 2011 12:57:28 -0800 (PST)\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 DC998431FB6\r
+       for <notmuch@notmuchmail.org>; Sun,  6 Nov 2011 12:57:27 -0800 (PST)\r
+Received: by faan15 with SMTP id n15so1732670faa.26\r
+       for <notmuch@notmuchmail.org>; Sun, 06 Nov 2011 12:57:26 -0800 (PST)\r
+Received: by 10.223.14.197 with SMTP id h5mr3488019faa.2.1320613046490;\r
+       Sun, 06 Nov 2011 12:57:26 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id f4sm19937162faj.1.2011.11.06.12.57.23\r
+       (version=SSLv3 cipher=OTHER); Sun, 06 Nov 2011 12:57:24 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [RFC PATCH v2 3/3] emacs: support limiting the number of results\r
+       shown in search results\r
+In-Reply-To: <20111104205415.GJ22935@mit.edu>\r
+References: <cover.1320093940.git.jani@nikula.org>\r
+       <0b937eb1103dbb24142a783eff599a7cb08f195e.1320093940.git.jani@nikula.org>\r
+       <20111104205415.GJ22935@mit.edu>\r
+User-Agent: Notmuch/0.9+32~gc0c32d1 (http://notmuchmail.org) Emacs/23.3.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sun, 06 Nov 2011 22:57:21 +0200\r
+Message-ID: <878vntgea6.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: notmuch@notmuchmail.org\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, 06 Nov 2011 20:57:29 -0000\r
+\r
+\r
+Hi Austin, and many thanks for your comments. Before hacking on notmuch\r
+my lisp was mostly limited to ~/.emacs, and unfortunately it shows...\r
+\r
+On Fri, 4 Nov 2011 16:54:15 -0400, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Quoth Jani Nikula on Oct 31 at 11:18 pm:\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
+> >  emacs/notmuch-hello.el |   17 ++++++++++++--\r
+> >  emacs/notmuch.el       |   53 +++++++++++++++++++++++++++++++++++++++++++----\r
+> >  2 files changed, 62 insertions(+), 8 deletions(-)\r
+> > \r
+> > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+> > index 65fde75..4ba13e3 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 maxitems target-thread target-line continuation))\r
+> >  (declare-function notmuch-poll "notmuch" ())\r
+> >  \r
+> >  (defvar notmuch-hello-search-bar-marker nil\r
+> > @@ -37,6 +37,17 @@\r
+> >    :type 'integer\r
+> >    :group 'notmuch)\r
+> >  \r
+> > +(defcustom notmuch-search-maxitems 0\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 not limit the\r
+> > +number of results. If non-zero, the search results will contain\r
+> > +push buttons to double the number (can be repeated) or show\r
+> > +unlimited number of results."\r
+> > +  :type 'integer\r
+> > +  :group 'notmuch)\r
+> > +\r
+> \r
+> It would be more lispy to use nil to indicate no limit, rather than 0.\r
+> The type could be something like\r
+>   (choice (const   :tag "Unlimited" nil)\r
+>           (integer :tag "Limit"))\r
+\r
+Definitely better.\r
+\r
+> >  (defcustom notmuch-show-empty-saved-searches nil\r
+> >    "Should saved searches with no messages be listed?"\r
+> >    :type 'boolean\r
+> > @@ -151,7 +162,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 notmuch-search-maxitems nil nil #'notmuch-hello-search-continuation)))\r
+> \r
+> It might make more sense of notmuch-search to use the value of\r
+> notmuch-search-maxitems directly, rather than feeding it in\r
+> everywhere, especially since it's buffer-local.  If there's really a\r
+> place that needs to override it, it would be easy to let-bind the\r
+> variable there.\r
+\r
+The only problem with that is that doubling the number of results is\r
+done using notmuch-search-refresh-view, which kills the buffer and\r
+performs a new search, which creates a new buffer. That loses the\r
+doubled buffer-local value, doesn't it?\r
+\r
+The Right Thing might be to use --first and --maxitems to only fetch the\r
+missing results while preserving the old, but I was hoping that could be\r
+a later improvement. It's not that trivial if new messages have been\r
+added to the db in between.\r
+\r
+> >  \r
+> >  (defun notmuch-hello-add-saved-search (widget)\r
+> >    (interactive)\r
+> > @@ -200,7 +211,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-maxitems\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 f11ec24..741ebe1 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
+> \r
+> Huh.  I thought widgets automatically had local keymaps, but maybe\r
+> that's only buttons (insert-button type buttons, that is).  A local\r
+> keymap is probably the right way to do this regardless.  Or use\r
+> buttons instead of widgets.\r
+\r
+I'll look into that, thanks.\r
+\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,11 @@ 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 (and notmuch-search-maxitems\r
+> > +                           (< 0 notmuch-search-maxitems)\r
+> > +                           (< notmuch-search-maxitems\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
+> > @@ -883,7 +897,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 maxitems target-thread target-line continuation)\r
+> >    "Run \"notmuch search\" with the given query string and display results.\r
+> >  \r
+> >  The optional parameters are used as follows:\r
+> > @@ -899,6 +913,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 +931,11 @@ The optional parameters are used as follows:\r
+> >                 (if oldest-first\r
+> >                     "--sort=oldest-first"\r
+> >                   "--sort=newest-first")\r
+> > +               (if (and maxitems (< 0 maxitems))\r
+> > +                   (if oldest-first\r
+> > +                       (format "--first=-%d" maxitems)\r
+> > +                     (format "--maxitems=%d" maxitems))\r
+> > +                 "")\r
+> >                 query)))\r
+> >      (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
+> >      (set-process-filter proc 'notmuch-search-process-filter))))\r
+> > @@ -932,13 +952,36 @@ 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 maxitems target-thread target-line continuation)\r
+> >      (goto-char (point-min))))\r
+> >  \r
+> > +(defun notmuch-search-double-results (&rest ignore)\r
+> > +  (if notmuch-search-maxitems\r
+> > +      (set 'notmuch-search-maxitems (* 2 notmuch-search-maxitems)))\r
+> > +  (notmuch-search-refresh-view))\r
+> > +\r
+> > +(defun notmuch-search-unlimited-results (&rest ignore)\r
+> > +  (set 'notmuch-search-maxitems nil)\r
+> > +  (notmuch-search-refresh-view))\r
+> \r
+> I would recommend setq instead of set, except in the weird local\r
+> places where `set' is clearly the prevailing style.\r
+\r
+There's actually quite a bit of set around, but not enough to make it\r
+the prevailing style. Will fix.\r
+\r
+> > + \r
+> > +(defun notmuch-search-setup-buttons ()\r
+> > +  (widget-insert "    ")\r
+> > +  (widget-create 'push-button \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
+> > +           :notify 'notmuch-search-unlimited-results\r
+> > +           :help-echo "Show all search results"\r
+> > +           "Show unlimited results")\r
+> > +  (widget-setup))\r
+> > +\r
+> \r
+> If you're limiting from the bottom, would it make more sense for these\r
+> widgets to be placed at the top of the buffer, since that's the\r
+> direction they'll expand the results?\r
+\r
+I'm always limiting from the oldest mails (regardless of the sort order)\r
+but having the buttons at the top or bottom depending on where the\r
+results are expanded does make sense.\r
+\r
+BR,\r
+Jani.\r
+\r
+> >  (defcustom notmuch-poll-script ""\r
+> >    "An external script to incorporate new mail into the notmuch database.\r
+> >  \r
+> > @@ -997,7 +1040,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 +1049,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
+> -- \r
+> Austin Clements                                      MIT/'06/PhD/CSAIL\r
+> amdragon@mit.edu                           http://web.mit.edu/amdragon\r
+>        Somewhere in the dream we call reality you will find me,\r
+>               searching for the reality we call dreams.\r