Discussion:
run-with-timer
(too old to reply)
David Hume
2014-04-25 09:54:27 UTC
Permalink
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. (I pressed
keys to reset the idle timer).

How is this function meant to be used? Am I using it in the wrong way?
Michael Heerdegen
2014-04-25 17:28:17 UTC
Permalink
Post by David Hume
(defun timeless ()
(interactive)
(run-with-timer 10 10 (message "Hello Time"))
(sit-for 120)
)
Am I using it in the wrong way?
Yes. The third argument of `run-with-timer' must be a
function. Note that `run-with-timer' is a function, and not a special
form!

You can write

(run-with-timer 10 10 (lambda () (message "Hello Time")))

or

(run-with-timer 10 10 #'message "Hello Time")


Michael.
David Hume
2014-04-25 18:16:12 UTC
Permalink
Post by Michael Heerdegen
Yes. The third argument of `run-with-timer' must be a
function. Note that `run-with-timer' is a function, and not a special
form!
You can write
(run-with-timer 10 10 (lambda () (message "Hello Time")))
or
(run-with-timer 10 10 #'message "Hello Time")
Thanks! I was puzzling over that one for ages.

Continue reading on narkive:
Loading...