0

I have this code:

(defun do-repeated-work (args)
"some work that need executed repeatedly"
(message nil) 
(message "doing some repeated work, arg = %s, current time = %s" args (format-time-string "%H:%M:%S")))

(setq timer (run-with-idle-timer 3 t 'do-repeated-work (list "arg1" "arg2" "arg3")))

The purpose of the code above is: print a line of message in minibuffer repeatedly every three seconds. But I found that, when the function do-repeated-work works again, the old message in emacs minibuffer cannot be cleared, so the new message cannot be displayed. I have already tried the way mentioned in this question: how to empty or clear the emacs minibuffer?, but it doesn't work.

My Emacs version is 25.3

How to cope with this problem?

tripleee
  • 175,061
  • 34
  • 275
  • 318
dnxbjyj
  • 23
  • 3
  • 1
    `(message nil)` works for me, Emacs 25.3.50.1 on MacOS High Sierra. Demo: `(progn (message "Hello ...") (sit-for 1) (message nil) (sit-for 1) (message "Hello ... done."))` – tripleee Jan 08 '19 at 12:36
  • 1
    And as noted in the other question, that's the "echo area", not properly the "minibuffer". – tripleee Jan 08 '19 at 12:38
  • `(message nil)` works well in your case, it's actually a good solution in those cases like that. But in my case, the root cause is I wrongly use the `idle` function. Anyhow, thank you. – dnxbjyj Jan 09 '19 at 01:35

1 Answers1

1

You've made an incorrect assumption, and consequently your problem isn't what you think it is.

The purpose of the code above is: print a line of message in minibuffer repeatedly every three seconds.

That's not what it does.

You've used run-with-idle-timer which will run one time once Emacs has been idle for 3 (in this case) seconds, and will not repeat until some non-idle activity has taken place -- after which it will again run once Emacs has become idle for 3 seconds.

See C-hf run-with-idle-timer

If you want something which repeats at a consistent interval, use run-with-timer.

phils
  • 71,335
  • 11
  • 153
  • 198
  • Thank you for your answer:) My understanding for the usage of `run-with-idle-timer` is wrong. `run-with-timer` solve my problem, great! – dnxbjyj Jan 09 '19 at 01:27