From d91e4b2483178227e12a9c414a7cdf3eef8f8dfd Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 30 Aug 2013 12:25:50 +2000 Subject: [PATCH] [PATCH 2/9] emacs: Refresh hello whenever the user switches to the buffer --- 86/8c1c4adab5e1e670148cd234e419e120688c98 | 178 ++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 86/8c1c4adab5e1e670148cd234e419e120688c98 diff --git a/86/8c1c4adab5e1e670148cd234e419e120688c98 b/86/8c1c4adab5e1e670148cd234e419e120688c98 new file mode 100644 index 000000000..dd1273948 --- /dev/null +++ b/86/8c1c4adab5e1e670148cd234e419e120688c98 @@ -0,0 +1,178 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 3679E431FAE + for ; Thu, 29 Aug 2013 09:26:17 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id ngprB3rWJp5I for ; + Thu, 29 Aug 2013 09:26:11 -0700 (PDT) +Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu + [18.7.68.35]) + by olra.theworths.org (Postfix) with ESMTP id AF8C4431FC9 + for ; Thu, 29 Aug 2013 09:26:05 -0700 (PDT) +X-AuditID: 12074423-b7f168e00000095a-c9-521f761d7688 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id BB.9E.02394.D167F125; Thu, 29 Aug 2013 12:26:05 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r7TGQ3uZ025416; + Thu, 29 Aug 2013 12:26:04 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r7TGQ1UJ014991 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 29 Aug 2013 12:26:02 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1VF52m-0007Wk-VE; Thu, 29 Aug 2013 12:26:00 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 2/9] emacs: Refresh hello whenever the user switches to the + buffer +Date: Thu, 29 Aug 2013 12:25:50 -0400 +Message-Id: <1377793557-28878-3-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1377793557-28878-1-git-send-email-amdragon@mit.edu> +References: <1377793557-28878-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixG6noitbJh9k0NvEb3H95kxmB0aPZ6tu + MQcwRnHZpKTmZJalFunbJXBl7Fn8mqVgmmLFsvv/2BoYW6W7GDk5JARMJJqOXWGEsMUkLtxb + z9bFyMUhJLCPUeLVtynsEM5GRon5VxdAZe4wSexbcIQRwpnLKHF3+wZWkH42AQ2JbfuXg80S + EZCW2Hl3NlCcg4NZQE3iT5cKSFhYIEjiRNt8dhCbRUBV4vTs42wgNq+Ag8Sj7e+YIc5QlOh+ + NgEszingKNF/9y0LiC0EVPPn4lP2CYz8CxgZVjHKpuRW6eYmZuYUpybrFicn5uWlFuma6eVm + luilppRuYgSHjYvyDsY/B5UOMQpwMCrx8HYEygcJsSaWFVfmHmKU5GBSEuUNLAEK8SXlp1Rm + JBZnxBeV5qQWH2KU4GBWEuF9ywmU401JrKxKLcqHSUlzsCiJ8z57ejZQSCA9sSQ1OzW1ILUI + JivDwaEkwXsfZKhgUWp6akVaZk4JQpqJgxNkOA/Q8H8gNbzFBYm5xZnpEPlTjIpS4rw/QRIC + IImM0jy4Xlhcv2IUB3pFmPcOSBUPMCXAdb8CGswENHhCvhzI4JJEhJRUA2P4warprYF5H5lq + E5uqT4heVVwQGdqVmdZjvLRJ+cLe0Ou/+5zq7UK0Kye0XH991bo6rmrXg1Z37vztLBtVIhq5 + 1fWz9RYo13xrt+Oda8h/V5xtktWJk3+4HJU3pMf7+Mx6I1zNJupT2fSp29wh49rWNOtovuNO + qyVz10bo3cxs27CwN+GQEktxRqKhFnNRcSIAM24LHMYCAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 29 Aug 2013 16:26:17 -0000 + +Previously, we refreshed hello when the user quit a search that was +started from hello. This is fine assuming purely stack-oriented +buffer use, but is quite fragile and requires hacks to search. + +This replaces that logic with a new approach that refreshes hello +whenever the user switches to the hello buffer, regardless of how this +happens. +--- + emacs/notmuch-hello.el | 52 ++++++++++++++++++++++++++++++++++++++---------- + 1 file changed, 42 insertions(+), 10 deletions(-) + +diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el +index 9db8c99..c4f102f 100644 +--- a/emacs/notmuch-hello.el ++++ b/emacs/notmuch-hello.el +@@ -263,8 +263,7 @@ afterwards.") + (setq search (notmuch-hello-trim search)) + (let ((history-delete-duplicates t)) + (add-to-history 'notmuch-search-history search))) +- (notmuch-search search notmuch-search-oldest-first nil nil +- #'notmuch-hello-search-continuation)) ++ (notmuch-search search notmuch-search-oldest-first)) + + (defun notmuch-hello-add-saved-search (widget) + (interactive) +@@ -322,8 +321,7 @@ diagonal." + (defun notmuch-hello-widget-search (widget &rest ignore) + (notmuch-search (widget-get widget + :notmuch-search-terms) +- notmuch-search-oldest-first +- nil nil #'notmuch-hello-search-continuation)) ++ notmuch-search-oldest-first)) + + (defun notmuch-saved-search-count (search) + (car (process-lines notmuch-command "count" search))) +@@ -476,9 +474,6 @@ Such a list can be computed with `notmuch-hello-query-counts'." + + (defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png"))) + +-(defun notmuch-hello-search-continuation() +- (notmuch-hello-update t)) +- + (defun notmuch-hello-update (&optional no-display) + "Update the current notmuch view." + ;; Lazy - rebuild everything. +@@ -491,6 +486,36 @@ Such a list can be computed with `notmuch-hello-query-counts'." + (notmuch-poll) + (notmuch-hello-update)) + ++(defvar notmuch-hello-inhibit-auto-refresh nil ++ "Don't refresh notmuch-hello on window configuration changes.") ++ ++(defun notmuch-hello-window-configuration-change () ++ "Hook function to update the hello buffer when it is switched to." ++ (let ((hello-buf (get-buffer "*notmuch-hello*")) ++ (do-refresh nil)) ++ ;; Consider all windows in the currently selected frame, since ++ ;; that's where the configuration change happened. This also ++ ;; refreshes our snapshot of all windows, so we have to do this ++ ;; even if we know we won't refresh (e.g., hello-buf is null). ++ (dolist (window (window-list)) ++ (let ((last-buf (window-parameter window 'notmuch-hello-last-buffer)) ++ (cur-buf (window-buffer window))) ++ (when (not (eq last-buf cur-buf)) ++ ;; This window changed or is new. Update recorded buffer ++ ;; for next time. ++ (set-window-parameter window 'notmuch-hello-last-buffer cur-buf) ++ (when (and (eq cur-buf hello-buf) last-buf) ++ ;; The user just switched to hello in this window (hello ++ ;; is currently visible, was not visible on the last ++ ;; configuration change, and this is not a new window) ++ (setq do-refresh t))))) ++ (when (and do-refresh (not notmuch-hello-inhibit-auto-refresh)) ++ (notmuch-hello t)) ++ (when (null hello-buf) ++ ;; Clean up hook ++ (remove-hook 'window-configuration-change-hook ++ #'notmuch-hello-window-configuration-change)))) ++ + + (defvar notmuch-hello-mode-map + (let ((map (make-sparse-keymap))) +@@ -765,9 +790,16 @@ following: + "Run notmuch and display saved searches, known tags, etc." + (interactive) + +- (if no-display +- (set-buffer "*notmuch-hello*") +- (switch-to-buffer "*notmuch-hello*")) ++ ;; This may cause a window configuration change, so if the ++ ;; auto-refresh hook is already installed, avoid recursive refresh. ++ (let ((notmuch-hello-inhibit-auto-refresh t)) ++ (if no-display ++ (set-buffer "*notmuch-hello*") ++ (switch-to-buffer "*notmuch-hello*"))) ++ ++ ;; Install auto-refresh hook ++ (add-hook 'window-configuration-change-hook ++ #'notmuch-hello-window-configuration-change) + + (let ((target-line (line-number-at-pos)) + (target-column (current-column)) +-- +1.7.10.4 + -- 2.26.2