[PATCH v2 2/9] emacs: Refresh hello whenever the user switches to the buffer
authorAustin Clements <amdragon@MIT.EDU>
Tue, 3 Sep 2013 21:45:18 +0000 (17:45 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:56:53 +0000 (09:56 -0800)
e3/c11d8892952b0fc3a77957f3d95d9cb7abe322 [new file with mode: 0644]

diff --git a/e3/c11d8892952b0fc3a77957f3d95d9cb7abe322 b/e3/c11d8892952b0fc3a77957f3d95d9cb7abe322
new file mode 100644 (file)
index 0000000..be72f61
--- /dev/null
@@ -0,0 +1,190 @@
+Return-Path: <amdragon@mit.edu>\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 1A122429E56\r
+       for <notmuch@notmuchmail.org>; Tue,  3 Sep 2013 14:46:10 -0700 (PDT)\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 oeCQnyX7fwwh for <notmuch@notmuchmail.org>;\r
+       Tue,  3 Sep 2013 14:46:04 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+       [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id 350A1431FD8\r
+       for <notmuch@notmuchmail.org>; Tue,  3 Sep 2013 14:45:42 -0700 (PDT)\r
+X-AuditID: 12074425-b7f0c8e000000953-c5-52265885fcd2\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 48.EF.02387.58856225; Tue,  3 Sep 2013 17:45:41 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r83LjU4s019872; \r
+       Tue, 3 Sep 2013 17:45:30 -0400\r
+Received: from drake.dyndns.org (26-4-182.dynamic.csail.mit.edu [18.26.4.182])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r83LjRvf026852\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 3 Sep 2013 17:45:28 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1VGyPe-0004xq-Su; Tue, 03 Sep 2013 17:45:26 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/9] emacs: Refresh hello whenever the user switches to the\r
+       buffer\r
+Date: Tue,  3 Sep 2013 17:45:18 -0400\r
+Message-Id: <1378244725-18846-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1378244725-18846-1-git-send-email-amdragon@mit.edu>\r
+References: <1378244725-18846-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6notsaoRZkcP6LkUXTdGeL1XN5LK7f\r
+       nMnswOyxc9Zddo9b91+zezxbdYs5gDmKyyYlNSezLLVI3y6BK+PDjWmsBXtUK3ovXmZvYFwp\r
+       18XIySEhYCLxuv8ME4QtJnHh3nq2LkYuDiGBfYwSV7c/ZoRwNjBK3N/fwQ7hHGaSmHzpO1Rm\r
+       LqPEi7PzwfrZBDQktu1fzghiiwhIS+y8O5sVxGYWiJY4cnkGG4gtLBAqcf7sTWYQm0VAVeLv\r
+       oalgNbwCDhIPd/6FukNRovvZBLB6TgFHid4Fi9hBbCGgmqaVl9knMPIvYGRYxSibklulm5uY\r
+       mVOcmqxbnJyYl5dapGuhl5tZopeaUrqJERxcLqo7GCccUjrEKMDBqMTDu+K+apAQa2JZcWXu\r
+       IUZJDiYlUd4joWpBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4E3yAcrwpiZVVqUX5MClpDhYl\r
+       cd7nT88GCgmkJ5akZqemFqQWwWRlODiUJHjfhwM1ChalpqdWpGXmlCCkmTg4QYbzAA1/CVLD\r
+       W1yQmFucmQ6RP8WoKCXOexskIQCSyCjNg+uFRf8rRnGgV4R5j4NU8QATB1z3K6DBTECD0z6r\r
+       ggwuSURISTUw5vPIMvdnL/2r/rmlKLtbPucPe2bH1/ud9n0HuqXdmvbquZ8p83g818zLXdpA\r
+       7stkRkbrL+3Kt4pbXvj+Nuz6Yjpli49wt9m0n37Cbzc++MKwLIllUqK29sd2z8s9zmx2atd0\r
+       DvCHdH511Xh769GsHxOq6oXig//U7Jw52+vFNt8yY5OyzR1KLMUZiYZazEXFiQAO0JLa2QIA        AA==\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: Tue, 03 Sep 2013 21:46:10 -0000\r
+\r
+Previously, we refreshed hello when the user quit a search that was\r
+started from hello.  This is fine assuming purely stack-oriented\r
+buffer use, but is quite fragile and requires hacks to search.\r
+\r
+This replaces that logic with a new approach that refreshes hello\r
+whenever the user switches to the hello buffer, regardless of how this\r
+happens.\r
+---\r
+ emacs/notmuch-hello.el |   58 +++++++++++++++++++++++++++++++++++++++---------\r
+ 1 file changed, 48 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 9db8c99..24ac1c6 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -232,6 +232,11 @@ supported for \"Customized queries section\" items."\r
+           notmuch-hello-query-section\r
+           (function :tag "Custom section"))))\r
\r
++(defcustom notmuch-hello-auto-refresh t\r
++  "Automatically refresh when returning to the notmuch-hello buffer."\r
++  :group 'notmuch-hello\r
++  :type 'boolean)\r
++\r
+ (defvar notmuch-hello-hidden-sections nil\r
+   "List of sections titles whose contents are hidden")\r
\r
+@@ -263,8 +268,7 @@ afterwards.")\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-hello-search-continuation))\r
++  (notmuch-search search notmuch-search-oldest-first))\r
\r
+ (defun notmuch-hello-add-saved-search (widget)\r
+   (interactive)\r
+@@ -322,8 +326,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
+-                nil nil #'notmuch-hello-search-continuation))\r
++                notmuch-search-oldest-first))\r
\r
+ (defun notmuch-saved-search-count (search)\r
+   (car (process-lines notmuch-command "count" search)))\r
+@@ -476,9 +479,6 @@ Such a list can be computed with `notmuch-hello-query-counts'."\r
\r
+ (defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))\r
\r
+-(defun notmuch-hello-search-continuation()\r
+-  (notmuch-hello-update t))\r
+-\r
+ (defun notmuch-hello-update (&optional no-display)\r
+   "Update the current notmuch view."\r
+   ;; Lazy - rebuild everything.\r
+@@ -491,6 +491,36 @@ Such a list can be computed with `notmuch-hello-query-counts'."\r
+   (notmuch-poll)\r
+   (notmuch-hello-update))\r
\r
++(defun notmuch-hello-window-configuration-change ()\r
++  "Hook function to update the hello buffer when it is switched to."\r
++  (let ((hello-buf (get-buffer "*notmuch-hello*"))\r
++      (do-refresh nil))\r
++    ;; Consider all windows in the currently selected frame, since\r
++    ;; that's where the configuration change happened.  This also\r
++    ;; refreshes our snapshot of all windows, so we have to do this\r
++    ;; even if we know we won't refresh (e.g., hello-buf is null).\r
++    (dolist (window (window-list))\r
++      (let ((last-buf (window-parameter window 'notmuch-hello-last-buffer))\r
++          (cur-buf (window-buffer window)))\r
++      (when (not (eq last-buf cur-buf))\r
++        ;; This window changed or is new.  Update recorded buffer\r
++        ;; for next time.\r
++        (set-window-parameter window 'notmuch-hello-last-buffer cur-buf)\r
++        (when (and (eq cur-buf hello-buf) last-buf)\r
++          ;; The user just switched to hello in this window (hello\r
++          ;; is currently visible, was not visible on the last\r
++          ;; configuration change, and this is not a new window)\r
++          (setq do-refresh t)))))\r
++    (when (and do-refresh notmuch-hello-auto-refresh)\r
++      ;; Refresh hello as soon as we get back to redisplay.  On Emacs\r
++      ;; 24, we can't do it right here because something in this\r
++      ;; hook's call stack overrides hello's point placement.\r
++      (run-at-time nil nil #'notmuch-hello t))\r
++    (when (null hello-buf)\r
++      ;; Clean up hook\r
++      (remove-hook 'window-configuration-change-hook\r
++                 #'notmuch-hello-window-configuration-change))))\r
++\r
\r
+ (defvar notmuch-hello-mode-map\r
+   (let ((map (make-sparse-keymap)))\r
+@@ -765,9 +795,17 @@ following:\r
+   "Run notmuch and display saved searches, known tags, etc."\r
+   (interactive)\r
\r
+-  (if no-display\r
+-      (set-buffer "*notmuch-hello*")\r
+-    (switch-to-buffer "*notmuch-hello*"))\r
++  ;; This may cause a window configuration change, so if the\r
++  ;; auto-refresh hook is already installed, avoid recursive refresh.\r
++  (let ((notmuch-hello-auto-refresh nil))\r
++    (if no-display\r
++      (set-buffer "*notmuch-hello*")\r
++      (switch-to-buffer "*notmuch-hello*")))\r
++\r
++  ;; Install auto-refresh hook\r
++  (when notmuch-hello-auto-refresh\r
++    (add-hook 'window-configuration-change-hook\r
++            #'notmuch-hello-window-configuration-change))\r
\r
+   (let ((target-line (line-number-at-pos))\r
+       (target-column (current-column))\r
+-- \r
+1.7.10.4\r
+\r