Function: eldoc-display-in-echo-area

eldoc-display-in-echo-area is a byte-compiled function defined in eldoc.el.gz.

Signature

(eldoc-display-in-echo-area DOCS INTERACTIVE)

Documentation

Display DOCS in echo area.

Honor eldoc-echo-area-use-multiline-p and eldoc-echo-area-prefer-doc-buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/eldoc.el.gz
(defun eldoc-display-in-echo-area (docs _interactive)
  "Display DOCS in echo area.
Honor `eldoc-echo-area-use-multiline-p' and
`eldoc-echo-area-prefer-doc-buffer'."
  (cond
   (;; Check if we have permission to mess with echo area at all.  For
    ;; example, if this-command is non-nil while running via an idle
    ;; timer, we're still in the middle of executing a command, e.g. a
    ;; query-replace where it would be annoying to overwrite the echo
    ;; area.
    (or
     (not (eldoc-display-message-no-interference-p))
     this-command
     (not (eldoc--message-command-p last-command))))
   (;; If we do but nothing to report, clear the echo area.
    (null docs)
    (eldoc--message nil))
   (t
    ;; Otherwise, establish some parameters.
    (let*
        ((width (1- (window-width (minibuffer-window))))
         (val (if (and (symbolp eldoc-echo-area-use-multiline-p)
                       eldoc-echo-area-use-multiline-p)
                  max-mini-window-height
                eldoc-echo-area-use-multiline-p))
         (available (cl-typecase val
                      (float (truncate (* (frame-height) val)))
                      (integer val)
                      (t 'just-one-line)))
         single-doc single-doc-sym)
      (let ((echo-area-message
             (cond
              (;; To output to the echo area, we handle the
               ;; `truncate-sym-name-if-fit' special case first, by
               ;; checking for a lot of special conditions.
               (and
                (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p)
                (null (cdr docs))
                (setq single-doc (caar docs))
                (setq single-doc-sym
                      (format "%s" (plist-get (cdar docs) :thing)))
                (< (length single-doc) width)
                (not (string-match "\n" single-doc))
                (> (+ (length single-doc) (length single-doc-sym) 2) width))
               single-doc)
              ((and (numberp available)
                    (cl-plusp available))
               ;; Else, given a positive number of logical lines, we
               ;; format the *eldoc* buffer, using as most of its
               ;; contents as we know will fit.
               (with-current-buffer (eldoc--format-doc-buffer docs)
                 (save-excursion
                   (eldoc--echo-area-substring available))))
              (t ;; this is the "truncate brutally" situation
               (let ((string
                      (with-current-buffer (eldoc--format-doc-buffer docs)
                        (buffer-substring (goto-char (point-min))
                                          (progn (end-of-visible-line)
                                                 (point))))))
                 (if (> (length string) width)  ; truncation to happen
                     (unless (eldoc--echo-area-prefer-doc-buffer-p t)
                       (truncate-string-to-width string width))
                   (unless (eldoc--echo-area-prefer-doc-buffer-p nil)
                     string)))))))
        (when echo-area-message
          (eldoc--message echo-area-message)))))))