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 5C86B6DE1104 for ; Thu, 6 Oct 2016 13:59:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.156 X-Spam-Level: X-Spam-Status: No, score=-0.156 tagged_above=-999 required=5 tests=[AWL=-0.135, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] 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 QFg6QJS_PC37 for ; Thu, 6 Oct 2016 13:59:09 -0700 (PDT) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id B60046DE10E8 for ; Thu, 6 Oct 2016 13:59:08 -0700 (PDT) Received: by mail-wm0-f67.google.com with SMTP id f193so5223331wmg.2 for ; Thu, 06 Oct 2016 13:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adirat-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=jy5quXCSUMCo8ZN2pQU9RIgm0sKyiGZLKMwf+JSPPQQ=; b=o4MW3IvdBdrY3XdyhUSV89JGAanjwSjRAEht3zwQPYaVlemTf3WnAgOtUUs1hd5uji v4OYlQXTm/tNrqxr6IRKlcobODzHkgTgj9G8YPAOMSGrO+zcejuNuYOBiHM3Km1XtLAn v3+tbBS9ZLotyNAHlYIxSzUuuGrigcVB3FLB1KRET2+f9bmQTbiYVjW70BdqEq8pJza5 rc9XKIRbPkW0OjIyHX1DdEcgFqjyzQdSfjYzaIDScm+YUyCPHEtz8kX0GTqn2FFnvN3O ZhHVJ9aUbMSPY2F2VC+GMfzYeTN8eRqFNITKFJU4exXtopjXSFuWS0dxImuttHQABTnQ Fd3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=jy5quXCSUMCo8ZN2pQU9RIgm0sKyiGZLKMwf+JSPPQQ=; b=O+mM/X6Trp+nvpLPXkFRTDoMmAmjyteu41I4iCC2N7JJRDq++VC2ZNvyIivShmy/Xo Y4n9aNwYBRBNHfmAWizg6eSWi3UyDdLLkIWk3NLE/AF54ezWEn0/VNfZjO9tIGsffw9c xctZhE/a3deH1ErgepkRGakwMyci+oCgn4xxNz8wLnpjni+ZIjj8GMDLeQPg1nhOzdEd IxOe03ZtK1zXmcGSrKh7vk4F0+Ca/60EuKZSh6eTUR9aRRzi1c0B1hlrw7s90735r4cy uGmt0SU/CMTsw+EvSuFhtXoDqAIJag+/e41PpqGbNc1AaIKD40aVf9HaAURQy6RSC6o0 whPw== X-Gm-Message-State: AA6/9RlJEIfRJNVjrRPJNKpNZybewfRW1ZO49laEMmjmANwEUmOhW5mX97BokjoZLjW/iQ== X-Received: by 10.194.150.206 with SMTP id uk14mr14024076wjb.139.1475787546713; Thu, 06 Oct 2016 13:59:06 -0700 (PDT) Received: from adiPC ([188.24.54.197]) by smtp.gmail.com with ESMTPSA id u78sm6835892wmd.4.2016.10.06.13.59.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Oct 2016 13:59:06 -0700 (PDT) From: Ioan-Adrian Ratiu To: Mark Walters , notmuch@notmuchmail.org Subject: Re: [PATCH v3 3/4] emacs: add refresh buffer optional no-display arg In-Reply-To: <87bmyxfl1l.fsf@qmul.ac.uk> References: <20161006134227.17194-1-adi@adirat.com> <20161006134227.17194-4-adi@adirat.com> <87bmyxfl1l.fsf@qmul.ac.uk> Date: Thu, 06 Oct 2016 23:59:13 +0300 Message-ID: <87twcpb3dq.fsf@adiPC.i-did-not-set--mail-host-address--so-tickle-me> MIME-Version: 1.0 Content-Type: text/plain 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 20:59:13 -0000 On Thu, 06 Oct 2016, Mark Walters wrote: > On Thu, 06 Oct 2016, Ioan-Adrian Ratiu wrote: >> 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)))) > > Hi > > I think this is very fragile -- it relies on the fact that the refresh > functions in show and tree mode are interactive, so get called but the > call-interactive line (which doesn't have the no-display argument) > whereas the refresh functions in hello and search mode are not > interactive so get called by the funcall line and so do get the > no-display argument. > > [In fact the notmuch-tree seems to bind "=" to notmuch-tree-refresh-view > whereas it could use the generic framework, which would mean it would > plausibly lose the interactive.] > > However, I am not sure what the correct solution is. I agree it's messy, but I don't know if adding the no-display arg to notmuch-show and notmuch-tree makes any sense because they don't force the buffer to become visible (like how notmuch-search/hello do by using switch-to-buffer). notmuch-show and tree assume the current buffer and don't change it's visibility. This is how to current code works. If it does make sense to add to them the no-display arg then we either have to make all refresh functions interactive or non-interactive. By doing this we can call all functions using a single code path and pass the no-display arg to all in one call. For notmuch-hello-update the situation looks pretty simple, it calls notmuch-hello which is interactive. It already has the no-display arg, we make it interactive and we're done. With notmuch-search-refresh-view the situation is similar. Then call-interactively all and pass no-display. Making them all non-interactive seems much harder and I think will likely break stuff. So I prefer 1. using the code as is or 2. making all interactive. Any other ideas, everyone? I'm open to any kind of sugestions on this. Ionel > > Best wishes > > Mark > > > >> >> (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