summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Távora <joaotavora@gmail.com>2020-07-10 21:23:06 +0100
committerJoão Távora <joaotavora@gmail.com>2020-07-10 21:23:33 +0100
commit1198b03e558fccff745861396f3a7c705b4bbb49 (patch)
tree0e951e28c1e46548780ebb2c4f9609e01a9d84f2
parentc2599632b0d8b2ca9861806b2094e0de3849e931 (diff)
downloademacs-1198b03e558fccff745861396f3a7c705b4bbb49.tar.gz
Fix placement of Eldoc docs during eval-expression (bug#42309)
* lisp/emacs-lisp/eldoc.el (eldoc--handle-docs): Rework.
-rw-r--r--lisp/emacs-lisp/eldoc.el76
1 files changed, 40 insertions, 36 deletions
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 7964c4c45ab..faf02aa0079 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -459,42 +459,46 @@ Honor most of `eldoc-echo-area-use-multiline-p'."
;; top-section of the `*eldoc' buffer. I'm pretty sure nicer
;; strategies can be used here, probably by splitting this
;; function into some `eldoc-display-functions' special hook.
- (if (and (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p)
- (null (cdr docs))
- (setq single-sym-name
- (format "%s" (plist-get (cdar docs) :thing)))
- (> (+ (length (caar docs)) (length single-sym-name) 2) width))
- (eldoc--message (caar docs))
- (with-current-buffer (eldoc-doc-buffer)
- (goto-char (point-min))
- (cond
- ;; Potentially truncate a long message into less lines,
- ;; then display it in the echo area;
- ((> available 1)
- (cl-loop
- initially (goto-char (line-end-position (1+ available)))
- for truncated = nil then t
- for needed
- = (let ((truncate-lines message-truncate-lines))
- (count-screen-lines (point-min) (point) t (minibuffer-window)))
- while (> needed (if truncated (1- available) available))
- do (goto-char (line-end-position (if truncated 0 -1)))
- (while (and (not (bobp)) (bolp)) (goto-char (line-end-position 0)))
- finally
- (unless (and truncated
- eldoc-prefer-doc-buffer
- (get-buffer-window eldoc--doc-buffer))
- (eldoc--message
- (concat (buffer-substring (point-min) (point))
- (and truncated
- (format
- "\n(Documentation truncated. Use `%s' to see rest)"
- (substitute-command-keys "\\[eldoc-doc-buffer]"))))))))
- ((= available 1)
- ;; Truncate "brutally." ; FIXME: use `eldoc-prefer-doc-buffer' too?
- (eldoc--message
- (truncate-string-to-width
- (buffer-substring (point-min) (line-end-position 1)) width)))))))))
+ (let ((echo-area-message
+ (cond
+ ((and
+ (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p)
+ (null (cdr docs))
+ (setq single-sym-name
+ (format "%s" (plist-get (cdar docs) :thing)))
+ (> (+ (length (caar docs)) (length single-sym-name) 2) width))
+ (caar docs))
+ ((> available 1)
+ (with-current-buffer (eldoc-doc-buffer)
+ (cl-loop
+ initially
+ (goto-char (point-min))
+ (goto-char (line-end-position (1+ available)))
+ for truncated = nil then t
+ for needed
+ = (let ((truncate-lines message-truncate-lines))
+ (count-screen-lines (point-min) (point) t
+ (minibuffer-window)))
+ while (> needed (if truncated (1- available) available))
+ do (goto-char (line-end-position (if truncated 0 -1)))
+ (while (and (not (bobp)) (bolp)) (goto-char (line-end-position 0)))
+ finally
+ (unless (and truncated
+ eldoc-prefer-doc-buffer
+ (get-buffer-window eldoc--doc-buffer))
+ (cl-return
+ (concat
+ (buffer-substring (point-min) (point))
+ (and truncated
+ (format
+ "\n(Documentation truncated. Use `%s' to see rest)"
+ (substitute-command-keys "\\[eldoc-doc-buffer]")))))))))
+ ((= available 1)
+ ;; Truncate "brutally." ; FIXME: use `eldoc-prefer-doc-buffer' too?
+ (truncate-string-to-width
+ (buffer-substring (point-min) (line-end-position 1)) width)))))
+ (when echo-area-message
+ (eldoc--message echo-area-message))))))
(defun eldoc-documentation-default ()
"Show first doc string for item at point.