[PATCH 2/9] emacs: Refresh hello whenever the user switches to the buffer
authorAustin Clements <amdragon@MIT.EDU>
Thu, 29 Aug 2013 16:25:50 +0000 (12:25 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:56:45 +0000 (09:56 -0800)
86/8c1c4adab5e1e670148cd234e419e120688c98 [new file with mode: 0644]

diff --git a/86/8c1c4adab5e1e670148cd234e419e120688c98 b/86/8c1c4adab5e1e670148cd234e419e120688c98
new file mode 100644 (file)
index 0000000..dd12739
--- /dev/null
@@ -0,0 +1,178 @@
+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 3679E431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Aug 2013 09:26:17 -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 ngprB3rWJp5I for <notmuch@notmuchmail.org>;\r
+       Thu, 29 Aug 2013 09:26:11 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id AF8C4431FC9\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Aug 2013 09:26:05 -0700 (PDT)\r
+X-AuditID: 12074423-b7f168e00000095a-c9-521f761d7688\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id BB.9E.02394.D167F125; Thu, 29 Aug 2013 12:26:05 -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 r7TGQ3uZ025416; \r
+       Thu, 29 Aug 2013 12:26:04 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (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 r7TGQ1UJ014991\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 29 Aug 2013 12:26:02 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1VF52m-0007Wk-VE; Thu, 29 Aug 2013 12:26:00 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/9] emacs: Refresh hello whenever the user switches to the\r
+       buffer\r
+Date: Thu, 29 Aug 2013 12:25:50 -0400\r
+Message-Id: <1377793557-28878-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1377793557-28878-1-git-send-email-amdragon@mit.edu>\r
+References: <1377793557-28878-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixG6noitbJh9k0NvEb3H95kxmB0aPZ6tu\r
+       MQcwRnHZpKTmZJalFunbJXBl7Fn8mqVgmmLFsvv/2BoYW6W7GDk5JARMJJqOXWGEsMUkLtxb\r
+       z9bFyMUhJLCPUeLVtynsEM5GRon5VxdAZe4wSexbcIQRwpnLKHF3+wZWkH42AQ2JbfuXg80S\r
+       EZCW2Hl3NlCcg4NZQE3iT5cKSFhYIEjiRNt8dhCbRUBV4vTs42wgNq+Ag8Sj7e+YIc5QlOh+\r
+       NgEszingKNF/9y0LiC0EVPPn4lP2CYz8CxgZVjHKpuRW6eYmZuYUpybrFicn5uWlFuma6eVm\r
+       luilppRuYgSHjYvyDsY/B5UOMQpwMCrx8HYEygcJsSaWFVfmHmKU5GBSEuUNLAEK8SXlp1Rm\r
+       JBZnxBeV5qQWH2KU4GBWEuF9ywmU401JrKxKLcqHSUlzsCiJ8z57ejZQSCA9sSQ1OzW1ILUI\r
+       JivDwaEkwXsfZKhgUWp6akVaZk4JQpqJgxNkOA/Q8H8gNbzFBYm5xZnpEPlTjIpS4rw/QRIC\r
+       IImM0jy4Xlhcv2IUB3pFmPcOSBUPMCXAdb8CGswENHhCvhzI4JJEhJRUA2P4warprYF5H5lq\r
+       E5uqT4heVVwQGdqVmdZjvLRJ+cLe0Ou/+5zq7UK0Kye0XH991bo6rmrXg1Z37vztLBtVIhq5\r
+       1fWz9RYo13xrt+Oda8h/V5xtktWJk3+4HJU3pMf7+Mx6I1zNJupT2fSp29wh49rWNOtovuNO\r
+       qyVz10bo3cxs27CwN+GQEktxRqKhFnNRcSIAM24LHMYCAAA=\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: Thu, 29 Aug 2013 16:26:17 -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 |   52 ++++++++++++++++++++++++++++++++++++++----------\r
+ 1 file changed, 42 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 9db8c99..c4f102f 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -263,8 +263,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 +321,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 +474,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 +486,36 @@ Such a list can be computed with `notmuch-hello-query-counts'."\r
+   (notmuch-poll)\r
+   (notmuch-hello-update))\r
\r
++(defvar notmuch-hello-inhibit-auto-refresh nil\r
++  "Don't refresh notmuch-hello on window configuration changes.")\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 (not notmuch-hello-inhibit-auto-refresh))\r
++      (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 +790,16 @@ 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-inhibit-auto-refresh t))\r
++    (if no-display\r
++      (set-buffer "*notmuch-hello*")\r
++      (switch-to-buffer "*notmuch-hello*")))\r
++\r
++  ;; Install auto-refresh hook\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