Function: with-temp-message

with-temp-message is a macro defined in subr.el.gz.

Signature

(with-temp-message MESSAGE &rest BODY)

Documentation

Display MESSAGE temporarily if non-nil while BODY is evaluated.

The original message is restored to the echo area after BODY has finished. The value returned is the value of the last form in BODY. MESSAGE is written to the message log buffer if message-log-max is non-nil. If MESSAGE is nil, the echo area and message log buffer are unchanged. Use a MESSAGE of "" to temporarily clear the echo area.

View in manual

Probably introduced at or before Emacs version 20.4.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro with-temp-message (message &rest body)
  "Display MESSAGE temporarily if non-nil while BODY is evaluated.
The original message is restored to the echo area after BODY has finished.
The value returned is the value of the last form in BODY.
MESSAGE is written to the message log buffer if `message-log-max' is non-nil.
If MESSAGE is nil, the echo area and message log buffer are unchanged.
Use a MESSAGE of \"\" to temporarily clear the echo area."
  (declare (debug t) (indent 1))
  (let ((current-message (make-symbol "current-message"))
	(temp-message (make-symbol "with-temp-message")))
    `(let ((,temp-message ,message)
	   (,current-message))
       (unwind-protect
	   (progn
	     (when ,temp-message
	       (setq ,current-message (current-message))
	       (message "%s" ,temp-message))
	     ,@body)
	 (and ,temp-message
	      (if ,current-message
		  (message "%s" ,current-message)
		(message nil)))))))