unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Campbell Barton <ideasman42@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Possible support for buffer local idle timers?
Date: Sat, 25 Sep 2021 17:26:52 +1000	[thread overview]
Message-ID: <CAEcf3Nz9fFzsEHe+7qz5VgtX7EUQOwgRhf0=ccyS47g_AWFPiw@mail.gmail.com> (raw)
In-Reply-To: <838rzqyzrk.fsf@gnu.org>

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	other threads:[~2021-09-25  7:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 13:49 Possible support for buffer local idle timers? Campbell Barton
2021-09-20 15:30 ` Eli Zaretskii
2021-09-20 15:50   ` Campbell Barton
2021-09-20 16:08     ` Eli Zaretskii
2021-09-21  0:36       ` Campbell Barton
2021-09-21  6:07         ` Eli Zaretskii
2021-09-21  6:16           ` Lars Ingebrigtsen
2021-09-21 10:19           ` Campbell Barton
2021-09-21 10:43             ` Eli Zaretskii
2021-09-25  7:26               ` Campbell Barton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEcf3Nz9fFzsEHe+7qz5VgtX7EUQOwgRhf0=ccyS47g_AWFPiw@mail.gmail.com' \
    --to=ideasman42@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).