From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Possible support for buffer local idle timers? Date: Tue, 21 Sep 2021 09:07:09 +0300 Message-ID: <834kae1mya.fsf@gnu.org> References: <83fstz1cyj.fsf@gnu.org> <83ee9j1b7z.fsf@gnu.org> <45045c06-9595-e106-890f-74a25c945876@gmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7983"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Campbell Barton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 21 08:08:10 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mSYws-0001x7-5q for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Sep 2021 08:08:10 +0200 Original-Received: from localhost ([::1]:42990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSYwq-0004L7-FY for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Sep 2021 02:08:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSYwE-0003fj-LO for emacs-devel@gnu.org; Tue, 21 Sep 2021 02:07:30 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:59140) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSYwD-0005OO-9H; Tue, 21 Sep 2021 02:07:29 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2761 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSYw1-0004tz-F4; Tue, 21 Sep 2021 02:07:29 -0400 In-Reply-To: <45045c06-9595-e106-890f-74a25c945876@gmail.com> (message from Campbell Barton on Tue, 21 Sep 2021 10:36:05 +1000) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275195 Archived-At: > Date: Tue, 21 Sep 2021 10:36:05 +1000 > From: Campbell Barton > > > . does the timer start measuring idle time only when the buffer is > > the current buffer, or regardless of that? > > would just go with default behavior of global idle timers since a user > switching buffers will typically reset idle timers. What do you mean by "reset timers" here? > > . what to do when the timer expired but the buffer wasn't current, > > and then the buffer became current? does the callback gets called > > right away, or do we "miss" the timer in that case? > > default behavior could be to run timers on the previously active buffer > (instead of missing them), although tracking this information could get > more involved. > > It may be useful for callers to request not to run in the case the > buffer becomes inactive. I don't understand what you mean by "acting on a buffer". The timer function can do anything it wants in any buffer. > > . how to handle repeated timers? > > As far as I can see repeated timers would be the primary use-case, for > this feature. > > I'm not sure what you mean by "how to handle", all callbacks registered > to run a repeated buffer local timer could share a timer, this would > store a list of callbacks which would run each time. It's related to the second question: if timers don't fire when "their" buffer is not the current buffer, then repeating timers will accumulate. Then it becomes an issue what to do when the buffer eventually becomes the current one: do we run the timer function N times or just once? > It may be that all things considered - there are too many ambiguities > and corner cases for this to be implemented cleanly. Indeed, I think the idea is not clear enough, and in general timers do not interact cleanly with the notion of the current buffer, which in Emacs is very ephemeral. Emacs switches momentarily to other buffers, including temporary buffers, a lot, so you could miss a timer tick very easily due to that. > Again, this is meant to be an alternative to packages registering their > global repeating idle timers that are never removed. Never removed why? because of bugs? > If there are better alternatives to this (such as starting/stopping > global-idle-timers on switching buffers, perhaps using: > window-state-change-hook, then that might be better, although even then, > it may be worth presenting this as a buffer-local-idle-timer API. I find the notion of stopping a timer when Emacs switches buffers strange. A timer runs with the time, and time does not stop when you switch buffers. There's no such notion in Emacs as "buffer-local time", and if there were, I wouldn't know how to explain its semantics. Why does it matter how long was a buffer the current buffer?