emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible support for buffer local idle timers?


From: Campbell Barton
Subject: Re: Possible support for buffer local idle timers?
Date: Tue, 21 Sep 2021 20:19:44 +1000

On Tue, Sep 21, 2021 at 4:07 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Date: Tue, 21 Sep 2021 10:36:05 +1000
> > From: Campbell Barton <ideasman42@gmail.com>
> >
> > >    . 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?

I assume that the the act of switching the buffer will cause Emacs not
to be idle, so after switching buffers idle timers will begin to run
again as their deadlines are met.
>
> > >    . 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.

Yes, but as with buffer-local-variables and buffer-local-hooks it can
be useful to have buffer-local-timers (or have the functionality even
if they have to be implemented with global timers).

> > >    . 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?

I would assume just once, although if it's important that a timer runs
for a buffer - as opposed to the buffer loosing focus and not running
the timer at all, this could be performed.
>
> > 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.

It may be better to consider all visible buffers instead of the active buffer.
...

>
> > 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?

Recently I referenced idle-highlight-mode, didn't write this package
so I can only guess,
I would assume this adds a global timer and never removes it's awkward
to know if the global timer is still needed by any open buffers. From
a quick check I suppose this could use buffer-list-update-hook,
although even in that case it's a little odd to be continuously
running a timer to highlight something for a buffer that might not be
visible.


> > 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?

This is often used for calculating more computationally intensive
highlighting information that's associated with a buffer-local minor
mode.

--
- Campbell



reply via email to

[Prev in Thread] Current Thread [Next in Thread]