Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

emacs run-with-timer

30 views
Skip to first unread message

David Hume

unread,
Apr 23, 2014, 12:09:22 PM4/23/14
to
I have this code:

(defun timeless ()
(interactive)
(run-with-timer 10 10 (message "Hello Time"))
(sit-for 120)
)

I was expecting that I would be able to type "timeless" and it would
output the message "Hello Time" every 10 seconds. But it seems to output
it only once. (Removing the sit-for line makes no difference).

What I am really trying to do is write something which will check for
new news periodically, and then perhaps notify me if there is any. My
attempts with run-with-idle-timer didn't seem to work either.

How is this function meant to be used? Am I using it in the wrong way?

a.daniel...@gmail.com

unread,
Oct 1, 2019, 9:24:19 AM10/1/19
to
On Wednesday, April 23, 2014 at 6:09:22 PM UTC+2, David Hume wrote:
> ...
> (defun timeless ()
> (interactive)
> (run-with-timer 10 10 (message "Hello Time"))
> (sit-for 120)
> )
>
> I was expecting that I would be able to type "timeless" and it would
> output the message "Hello Time" every 10 seconds. But it seems to output
> it only once. (Removing the sit-for line makes no difference).
> ...

Holy cow this is an old message, and no answer! (Not any visible on Google, anyway.) This group is not so active, apparently.. Here's a for-the-record response.

Two things: 1) after all these years the function is now called "run-at-time"; 2) you need to pass it a function, and "(message ...)" does not evaluate to a function. What has happened is "(message ...)" was evaluated once while putting together the call to "run-with-timer".

Instead, you need to maybe put "(lambda () (message ...))", which evaluates to a nameless function that will in turn call "message" in its body.

(run-at-time 10 10 (lambda () (message "Hello Time)))

You could defun:

(defun my-message () (message "Hello Time"))

(run-at-time 10 10 (function my-message))

"run-at-time" can accept arguments to pass on to the scheduled function, so if you just want to (in this example) print a constant string, you specify the "message" function as the argument rather than writing a lambda:

(run-at-time 10 10 (function message) "Hello Time")

or, using the #' reader syntax:

(run-at-time 10 10 #'message "Hello Time")
0 new messages