How can I print a message for a period of time to the mode line and restore the default format afterwards?
Temporarily change mode-line-format
or any of its constituent variables.
See the Elisp manual, node Mode Line Format and its subnodes.
For example (taken from icicle-show-in-mode-line
):
(defun my-show-in-mode-line (text &optional buffer delay)
"Display TEXT in BUFFER's mode line.
The text is shown for DELAY seconds (default 2), or until a user event.
So call this last in a sequence of user-visible actions."
(message nil) ; Remove any current msg
(with-current-buffer (or buffer (current-buffer))
(make-local-variable 'mode-line-format) ; Needed for Emacs 21+.
(let ((mode-line-format text))
(force-mode-line-update) (sit-for (or delay 2)))
(force-mode-line-update)))
You can save the current value of mode-line-format
(elisp manual) before changing it, then use a timer (manual) to set it back to the saved value.
(defun temporary-mode-line (text time)
"Display TEXT in mode line for TIME seconds."
(let ((old mode-line-format)
(buf (current-buffer)))
(setq mode-line-format text)
(run-at-time time nil
(lambda (v b)
(with-current-buffer b
(setq mode-line-format v)
(force-mode-line-update)))
old buf)))
-
I accepted the answer from Drew because he was first although yours is a good answer as well, thanks. – clemera Nov 29 '15 at 15:12