From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 3D6206DE1151 for ; Thu, 6 Oct 2016 07:41:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.546 X-Spam-Level: X-Spam-Status: No, score=0.546 tagged_above=-999 required=5 tests=[AWL=-0.425, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_SOFTFAIL=0.972] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G3vBfXJ4-fqX for ; Thu, 6 Oct 2016 07:41:47 -0700 (PDT) Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by arlo.cworth.org (Postfix) with ESMTPS id E79DB6DE0FA5 for ; Thu, 6 Oct 2016 07:41:46 -0700 (PDT) Received: from us-aus-mgwout1.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod2.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id u96Di1ZM022413; Thu, 6 Oct 2016 08:44:01 -0500 Received: from adi-pc-linux.iotechamer.corp.natinst.com ([130.164.14.198]) by us-aus-mgwout1.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6 HF1218) with ESMTP id 2016100608440139-645271 ; Thu, 6 Oct 2016 08:44:01 -0500 From: Ioan-Adrian Ratiu To: notmuch@notmuchmail.org Subject: [PATCH v3 3/4] emacs: add refresh buffer optional no-display arg Date: Thu, 6 Oct 2016 16:42:26 +0300 Message-Id: <20161006134227.17194-4-adi@adirat.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161006134227.17194-1-adi@adirat.com> References: <20161006134227.17194-1-adi@adirat.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6 HF1218|December 12, 2014) at 10/06/2016 08:44:01 AM, Serialize by Router on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6 HF1218|December 12, 2014) at 10/06/2016 08:44:01 AM, Serialize complete at 10/06/2016 08:44:01 AM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-06_06:, , signatures=0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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, 06 Oct 2016 14:41:50 -0000 Add an optional no-display arg to the generic buffer refresh function, notmuch-refresh-this-buffer, which works the same way as notmuch-hello mode's notmuch-hello-update no-display arg. The idea is for the generic notmuch-refresh-this-buffer to pass down this arg to the "mode-specific" refresh functions to be able to update buffers without bringing them to the foreground (if they are already foregrounded, i.e. displayed in a window, this has no effect). When updating a search buffer, notmuch currently always brings results in a window to the foreground. Perhaps counter-intuitively, we do not want this behaviour necessarily, because we want to auto-refresh any kind of search buffers, even those backgrounded (not displayed in any window/frame) from previous searches. This is why we add a no-display arg to notmuch-search. We do this to show which mails have appeard or dissapeared since the last search refresh and have this information updated in real time even when switching buffers. The ultimate goal of this is to have all notmuch buffers auto-refresh when the email client syncs (this function is added in the next commit). Signed-off-by: Ioan-Adrian Ratiu --- emacs/notmuch-lib.el | 10 +++++++--- emacs/notmuch.el | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index b2cdace..af6a8f4 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -413,14 +413,18 @@ of its command symbol." "Function to call to refresh the current buffer.") (make-variable-buffer-local 'notmuch-buffer-refresh-function) -(defun notmuch-refresh-this-buffer () - "Refresh the current buffer." +(defun notmuch-refresh-this-buffer (&optional no-display) + "Refresh the current buffer. + +If no-display is non-nil do not try to bring the buffer to the +foreground. If the buffer is already foregrounded i.e. displayed +in a window on screen, no-display has no effect." (interactive) (when notmuch-buffer-refresh-function (if (commandp notmuch-buffer-refresh-function) ;; Pass prefix argument, etc. (call-interactively notmuch-buffer-refresh-function) - (funcall notmuch-buffer-refresh-function)))) + (funcall notmuch-buffer-refresh-function no-display)))) (defun notmuch-poll-and-refresh-this-buffer () "Invoke `notmuch-poll' to import mail, then refresh the current buffer." diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 586c84e..f3912d4 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -925,7 +925,7 @@ PROMPT is the string to prompt with." ;;;###autoload (put 'notmuch-search 'notmuch-doc "Search for messages.") -(defun notmuch-search (&optional query oldest-first target-thread target-line) +(defun notmuch-search (&optional query oldest-first target-thread target-line no-display) "Display threads matching QUERY in a notmuch-search buffer. If QUERY is nil, it is read interactively from the minibuffer. @@ -936,6 +936,9 @@ Other optional parameters are used as follows: current if it appears in the search results. TARGET-LINE: The line number to move to if the target thread does not appear in the search results. + NO-DISPLAY: Do not try to foreground the search results buffer. If it is + already foregrounded i.e. displayed in a window, this has no + effect, meaning the buffer will remain visible. When called interactively, this will prompt for a query and use the configured default sort order." @@ -949,7 +952,9 @@ the configured default sort order." (let* ((query (or query (notmuch-read-query "Notmuch search: "))) (buffer (get-buffer-create (notmuch-search-buffer-title query)))) - (switch-to-buffer buffer) + (if no-display + (set-buffer buffer) + (switch-to-buffer buffer)) (notmuch-search-mode) ;; Don't track undo information for this buffer (set 'buffer-undo-list t) @@ -982,14 +987,16 @@ the configured default sort order." (set-process-query-on-exit-flag proc nil)))) (run-hooks 'notmuch-search-hook))) -(defun notmuch-search-refresh-view () +(defun notmuch-search-refresh-view (&optional no-display) "Refresh the current view. Erases the current buffer and runs a new search with the same query string as the current search. If the current thread is in the new search results, then point will be placed on the same thread. Otherwise, point will be moved to attempt to be in the -same relative position within the new buffer." +same relative position within the new buffer. If no-display is +non-nil, the search results buffer will not be foregrounded, if +it already is displayed in a window, then no-display has no effect." (let ((target-line (line-number-at-pos)) (oldest-first notmuch-search-oldest-first) (target-thread (notmuch-search-find-thread-id 'bare)) @@ -997,7 +1004,7 @@ same relative position within the new buffer." (inhibit-read-only t)) (remove-overlays) (erase-buffer) - (notmuch-search query oldest-first target-thread target-line) + (notmuch-search query oldest-first target-thread target-line no-display) (goto-char (point-min)))) (defun notmuch-search-toggle-order () -- 2.10.0