Search code examples
emacsechominibuffer

How to clear Emacs echo area in my program?


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?


Solution

  • 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.