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