Function: minibuffer-message

minibuffer-message is a byte-compiled function defined in minibuffer.el.gz.

Signature

(minibuffer-message MESSAGE &rest ARGS)

Documentation

Temporarily display MESSAGE at the end of minibuffer text.

This function is designed to be called from the minibuffer, i.e., when Emacs prompts the user for some input, and the user types into the minibuffer. If called when the current buffer is not the minibuffer, this function just calls message, and thus displays MESSAGE in the echo-area. When called from the minibuffer, this function displays MESSAGE at the end of minibuffer text for minibuffer-message-timeout seconds, or until the next input event arrives, whichever comes first. It encloses MESSAGE in [...] if it is not yet enclosed. The intent is to show the message without hiding what the user typed. If ARGS are provided, then the function first passes MESSAGE through format-message. If some of the minibuffer text has the minibuffer-message text property, MESSAGE is shown at that position instead of EOB.

View in manual

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun minibuffer-message (message &rest args)
  "Temporarily display MESSAGE at the end of minibuffer text.
This function is designed to be called from the minibuffer, i.e.,
when Emacs prompts the user for some input, and the user types
into the minibuffer.  If called when the current buffer is not
the minibuffer, this function just calls `message', and thus
displays MESSAGE in the echo-area.
When called from the minibuffer, this function displays MESSAGE
at the end of minibuffer text for `minibuffer-message-timeout'
seconds, or until the next input event arrives, whichever comes first.
It encloses MESSAGE in [...] if it is not yet enclosed.
The intent is to show the message without hiding what the user typed.
If ARGS are provided, then the function first passes MESSAGE
through `format-message'.
If some of the minibuffer text has the `minibuffer-message' text
property, MESSAGE is shown at that position instead of EOB."
  (if (not (minibufferp (current-buffer) t))
      (progn
        (if args
            (apply #'message message args)
          (message "%s" message))
        (prog1 (sit-for (or minibuffer-message-timeout 1000000))
          (message nil)))
    ;; Clear out any old echo-area message to make way for our new thing.
    (message nil)
    (setq message (if (and (null args)
                           (string-match-p "\\` *\\[.+\\]\\'" message))
                      ;; Make sure we can put-text-property.
                      (copy-sequence message)
                    (concat " [" message "]")))
    (when args (setq message (apply #'format-message message args)))
    (unless (or (null minibuffer-message-properties)
                ;; Don't overwrite the face properties the caller has set
                (text-properties-at 0 message))
      (setq message (apply #'propertize message minibuffer-message-properties)))
    ;; Put overlay either on `minibuffer-message' property, or at EOB.
    (let* ((ovpos (minibuffer--message-overlay-pos))
           (ol (make-overlay ovpos ovpos nil t t))
           ;; A quit during sit-for normally only interrupts the sit-for,
           ;; but since minibuffer-message is used at the end of a command,
           ;; at a time when the command has virtually finished already, a C-g
           ;; should really cause an abort-recursive-edit instead (i.e. as if
           ;; the C-g had been typed at top-level).  Binding inhibit-quit here
           ;; is an attempt to get that behavior.
           (inhibit-quit t))
      (unwind-protect
          (progn
            (unless (zerop (length message))
              ;; The current C cursor code doesn't know to use the overlay's
              ;; marker's stickiness to figure out whether to place the cursor
              ;; before or after the string, so let's spoon-feed it the pos.
              (put-text-property 0 1 'cursor t message))
            (overlay-put ol 'after-string message)
            ;; Make sure the overlay with the message is displayed before
            ;; any other overlays in that position, in case they have
            ;; resize-mini-windows set to nil and the other overlay strings
            ;; are too long for the mini-window width.  This makes sure the
            ;; temporary message will always be visible.
            (overlay-put ol 'priority 1100)
            (sit-for (or minibuffer-message-timeout 1000000)))
        (delete-overlay ol)))))