I have simple timer which makes sure a function is executed for every 10 seconds.

(setq interval 10)

(defun run-every-ten-seconds ()

(defun start-timer ()
  (setq timer
    (run-at-time (current-time)  interval

Everything works fine.

Now instead of saving it for every 10 seconds, i want to increment 1 second every time it saves. So i need to save it after 10 seconds, then 11 seconds, 12 seconds and so on.

But when I try to cancel & start a new timer with the function, it is getting into infinite loop.

(defun run-every-ten-seconds ()
    (cancel-timer timer) 
    (setq interval (1+ interval))
    (setq timer
      (run-at-time (current-time)  interval

Any ideas to solve this?


Your function is saying run-at-time NOW, and passing itself as the callback.

I think you want (run-at-time interval nil ...), and you doubtless won't need to cancel a non-repeating timer which has already triggered.

  • thank you. i was looking if there is any function update timer. – ChillarAnand Feb 2 '15 at 10:21

i ended up using time-add, seconds-to-time to modify the time interval

 (time-add (current-time) (seconds-to-time interval))
   interval 'run-every-ten-seconds)))
  • That's the same result as (run-at-time interval interval) (and if the interval isn't going to be consistent, then I think you ought to be using interval nil, as I had suggested -- a repeating timer which you always cancel before the second iteration shouldn't be a repeating timer). – phils Feb 2 '15 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.