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: Sat, 25 Sep 2021 17:26:52 +1000

On Tue, Sep 21, 2021 at 8:44 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Campbell Barton <ideasman42@gmail.com>
> > Date: Tue, 21 Sep 2021 20:19:44 +1000
> > Cc: emacs-devel@gnu.org
> >
> > 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.
>
> No, that is not necessarily true.  "Idle" means there's no input for
> Emacs to process, but it doesn't mean Emacs is not doing anything.  It
> could run some timer-related code which switches buffers, for example.

Thanks for the info, I have the impression that it would be difficult
to implement a buffer local timer that provides the kind of guarantees
script authors may expect from a built-in library.

Nevertheless I have found a solution for buffer-local-idle-timers,
where the global idle timer is created/destroyed as needed.

A summary of the solution:

- A buffer local window-state-change-hook is used to detect changes to
the buffer
  (enabling the global-idle-timer if the local mode is enabled).
- the global-idle-timer will remove itself if it runs on a buffer that
doesn't have the minor mode active.
- Buffers use a buffer local "dirty" tag so buffers that are activated
and lose focus before the idle timer runs
  will still be refreshed (if they are visible) next time the idle
timer is triggered.

This is a small package that demonstrates the solution:
https://emacs.stackexchange.com/a/68662/2418

-- 
- Campbell



reply via email to

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