unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
@ 2021-11-11 20:31 Alan Mackenzie
  2021-11-11 20:37 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Mackenzie @ 2021-11-11 20:31 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

There doesn't appear to be an easy way in a Lisp program to determine if
a timer object is active.  Something like (active-timer-p TIMER), or
even (timerp TIMER t), where the t is an &optional argument meaning
"active" (a bit like the LIVE parameter in minibufferp).

Does such a function really not exist, or have I somehow not managed to
find it?

If it doesn't exist, what is the reason?  The command timer-list clearly
manages to know this.  The usefulness of active-timer-p is surely
obvious.  (Well, it is to me, at least.)

At the very least, there could be a section in the Elisp manual
documenting why the function doesn't exist.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
  2021-11-11 20:31 Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Alan Mackenzie
@ 2021-11-11 20:37 ` Eli Zaretskii
  2021-11-11 21:08   ` Alan Mackenzie
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2021-11-11 20:37 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

> Date: Thu, 11 Nov 2021 20:31:24 +0000
> From: Alan Mackenzie <acm@muc.de>
> 
> There doesn't appear to be an easy way in a Lisp program to determine if
> a timer object is active.

What is an "active timer", and how does it differ from a non-active
one?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
  2021-11-11 20:37 ` Eli Zaretskii
@ 2021-11-11 21:08   ` Alan Mackenzie
  2021-11-11 21:24     ` Óscar Fuentes
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Mackenzie @ 2021-11-11 21:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Hello, Eli.

On Thu, Nov 11, 2021 at 22:37:43 +0200, Eli Zaretskii wrote:
> > Date: Thu, 11 Nov 2021 20:31:24 +0000
> > From: Alan Mackenzie <acm@muc.de>

> > There doesn't appear to be an easy way in a Lisp program to determine if
> > a timer object is active.

> What is an "active timer", and how does it differ from a non-active
> one?

An active timer is one which will trigger its timer function at the
appropriate time.

A non-active timer is one which will not trigger any timer function -
for example, a non-repeating timer which has already triggered.

timerp returns t for both of these objects.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
  2021-11-11 21:08   ` Alan Mackenzie
@ 2021-11-11 21:24     ` Óscar Fuentes
  2021-11-12  2:49       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Óscar Fuentes @ 2021-11-11 21:24 UTC (permalink / raw)
  To: emacs-devel

Alan Mackenzie <acm@muc.de> writes:

> Hello, Eli.
>
> On Thu, Nov 11, 2021 at 22:37:43 +0200, Eli Zaretskii wrote:
>> > Date: Thu, 11 Nov 2021 20:31:24 +0000
>> > From: Alan Mackenzie <acm@muc.de>
>
>> > There doesn't appear to be an easy way in a Lisp program to determine if
>> > a timer object is active.
>
>> What is an "active timer", and how does it differ from a non-active
>> one?
>
> An active timer is one which will trigger its timer function at the
> appropriate time.
>
> A non-active timer is one which will not trigger any timer function -
> for example, a non-repeating timer which has already triggered.
>
> timerp returns t for both of these objects.

Following the implicit definition on the docstring of `cancel-timer', an
active timer is a timer object contained in the list of active timers
(actually, either in `timer-list' or in `timer-idle-list'.)

An implementation would be

(defun timer-active-p (timer)
  (timer--check timer)
  (or (memq timer timer-list))
      (memq timer timer-idle-list))




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
  2021-11-11 21:24     ` Óscar Fuentes
@ 2021-11-12  2:49       ` Lars Ingebrigtsen
  2021-11-12  7:55         ` ๊Unsubscribe Sakesun Roykiattisak
  2021-11-12 13:13         ` Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Rudolf Schlatte
  0 siblings, 2 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-12  2:49 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: emacs-devel

Óscar Fuentes <ofv@wanadoo.es> writes:

> An implementation would be
>
> (defun timer-active-p (timer)
>   (timer--check timer)
>   (or (memq timer timer-list))
>       (memq timer timer-idle-list))

Sounds useful to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 8+ messages in thread

* ๊Unsubscribe
  2021-11-12  2:49       ` Lars Ingebrigtsen
@ 2021-11-12  7:55         ` Sakesun Roykiattisak
  2021-11-12 13:13         ` Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Rudolf Schlatte
  1 sibling, 0 replies; 8+ messages in thread
From: Sakesun Roykiattisak @ 2021-11-12  7:55 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/html, Size: 3 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
  2021-11-12  2:49       ` Lars Ingebrigtsen
  2021-11-12  7:55         ` ๊Unsubscribe Sakesun Roykiattisak
@ 2021-11-12 13:13         ` Rudolf Schlatte
  2021-11-12 14:12           ` Filipp Gunbin
  1 sibling, 1 reply; 8+ messages in thread
From: Rudolf Schlatte @ 2021-11-12 13:13 UTC (permalink / raw)
  To: emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Óscar Fuentes <ofv@wanadoo.es> writes:
>
>> An implementation would be
>>
>> (defun timer-active-p (timer)
>>   (timer--check timer)
>>   (or (memq timer timer-list))
>>       (memq timer timer-idle-list))
>
> Sounds useful to me.

Of course, the form

(when (timer-active-p my-timer)
  (do-something-that-errors-when-timer-inactive my-timer))

can still throw an error, since the return value of `timer-active-p' is
outdated as soon as the function returns..  (Or can timers only fire
when Emacs is otherwise idle?)

Rudi




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
  2021-11-12 13:13         ` Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Rudolf Schlatte
@ 2021-11-12 14:12           ` Filipp Gunbin
  0 siblings, 0 replies; 8+ messages in thread
From: Filipp Gunbin @ 2021-11-12 14:12 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: emacs-devel

On 12/11/2021 14:13 +0100, Rudolf Schlatte wrote:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Óscar Fuentes <ofv@wanadoo.es> writes:
>>
>>> An implementation would be
>>>
>>> (defun timer-active-p (timer)
>>>   (timer--check timer)
>>>   (or (memq timer timer-list))
>>>       (memq timer timer-idle-list))
>>
>> Sounds useful to me.
>
> Of course, the form
>
> (when (timer-active-p my-timer)
>   (do-something-that-errors-when-timer-inactive my-timer))
>
> can still throw an error, since the return value of `timer-active-p' is
> outdated as soon as the function returns..  (Or can timers only fire
> when Emacs is otherwise idle?)

From (elisp) Timers:

--8<---------------cut here---------------start------------->8---
   Emacs cannot run timers at any arbitrary point in a Lisp program; it
can run them only when Emacs could accept output from a subprocess:
namely, while waiting or inside certain primitive functions such as
‘sit-for’ or ‘read-event’ which _can_ wait.  Therefore, a timer’s
execution may be delayed if Emacs is busy.  However, the time of
execution is very precise if Emacs is idle.
--8<---------------cut here---------------end--------------->8---

So it depends on what do-something-that-errors-when-timer-inactive does.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-12 14:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11 20:31 Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Alan Mackenzie
2021-11-11 20:37 ` Eli Zaretskii
2021-11-11 21:08   ` Alan Mackenzie
2021-11-11 21:24     ` Óscar Fuentes
2021-11-12  2:49       ` Lars Ingebrigtsen
2021-11-12  7:55         ` ๊Unsubscribe Sakesun Roykiattisak
2021-11-12 13:13         ` Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Rudolf Schlatte
2021-11-12 14:12           ` Filipp Gunbin

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