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: Mon, 20 Sep 2021 19:08:16 +0300 Message-ID: <83ee9j1b7z.fsf@gnu.org> References: <83fstz1cyj.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35180"; 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 Mon Sep 20 18:09:36 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 1mSLrL-0008ra-0R for ged-emacs-devel@m.gmane-mx.org; Mon, 20 Sep 2021 18:09:35 +0200 Original-Received: from localhost ([::1]:56726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSLrJ-0001zq-E5 for ged-emacs-devel@m.gmane-mx.org; Mon, 20 Sep 2021 12:09:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSLqE-0000c1-4J for emacs-devel@gnu.org; Mon, 20 Sep 2021 12:08:26 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:36788) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSLqD-0000Rf-Kf; Mon, 20 Sep 2021 12:08:25 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3354 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 1mSLqD-0006l2-4Y; Mon, 20 Sep 2021 12:08:25 -0400 In-Reply-To: (message from Campbell Barton on Tue, 21 Sep 2021 01:50:47 +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:275150 Archived-At: > From: Campbell Barton > Date: Tue, 21 Sep 2021 01:50:47 +1000 > Cc: emacs-devel@gnu.org > > > I'm not sure I understand how would that work. Timers run as part of > > the Emacs main command loop, so they are by their nature global. How > > did you imagine that a buffer-local timer would express its "locality"? > > Yes, the idle timers themselves would be global, but only some buffers > would have call-backs registered to run with these timers. > > Exactly how this works internally is an implementation detail, for the > purpose of discussion it could work like this: > > ;; Setup might look like this. > (setq-local my-timer-handle (run-with-idle-timer-local delay t 'my-fn)) > > Internally a pool of repeating timers would be kept, one for each > unique delay used by one or more handles, this handle would be created > and added to a list of handles associated with this timer. > Running the timer would loop over callbacks running them if their > buffer matches the current buffer. So you want such a "buffer-local" timer call its timer function only if/when the buffer is the current buffer? That raises some issues that I think would need to be figured out: . does the timer start measuring idle time only when the buffer is the current buffer, or regardless of that? . 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? . how to handle repeated timers?