aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2020-07-10 21:23:06 +0100
committerJoão Távora2020-07-10 21:23:33 +0100
commit1198b03e558fccff745861396f3a7c705b4bbb49 (patch)
tree0e951e28c1e46548780ebb2c4f9609e01a9d84f2
parentc2599632b0d8b2ca9861806b2094e0de3849e931 (diff)
downloademacs-1198b03e558fccff745861396f3a7c705b4bbb49.tar.gz
emacs-1198b03e558fccff745861396f3a7c705b4bbb49.zip
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'."
459 ;; top-section of the `*eldoc' buffer. I'm pretty sure nicer 459 ;; top-section of the `*eldoc' buffer. I'm pretty sure nicer
460 ;; strategies can be used here, probably by splitting this 460 ;; strategies can be used here, probably by splitting this
461 ;; function into some `eldoc-display-functions' special hook. 461 ;; function into some `eldoc-display-functions' special hook.
462 (if (and (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p) 462 (let ((echo-area-message
463 (null (cdr docs)) 463 (cond
464 (setq single-sym-name 464 ((and
465 (format "%s" (plist-get (cdar docs) :thing))) 465 (eq 'truncate-sym-name-if-fit eldoc-echo-area-use-multiline-p)
466 (> (+ (length (caar docs)) (length single-sym-name) 2) width)) 466 (null (cdr docs))
467 (eldoc--message (caar docs)) 467 (setq single-sym-name
468 (with-current-buffer (eldoc-doc-buffer) 468 (format "%s" (plist-get (cdar docs) :thing)))
469 (goto-char (point-min)) 469 (> (+ (length (caar docs)) (length single-sym-name) 2) width))
470 (cond 470 (caar docs))
471 ;; Potentially truncate a long message into less lines, 471 ((> available 1)
472 ;; then display it in the echo area; 472 (with-current-buffer (eldoc-doc-buffer)
473 ((> available 1) 473 (cl-loop
474 (cl-loop 474 initially
475 initially (goto-char (line-end-position (1+ available))) 475 (goto-char (point-min))
476 for truncated = nil then t 476 (goto-char (line-end-position (1+ available)))
477 for needed 477 for truncated = nil then t
478 = (let ((truncate-lines message-truncate-lines)) 478 for needed
479 (count-screen-lines (point-min) (point) t (minibuffer-window))) 479 = (let ((truncate-lines message-truncate-lines))
480 while (> needed (if truncated (1- available) available)) 480 (count-screen-lines (point-min) (point) t
481 do (goto-char (line-end-position (if truncated 0 -1))) 481 (minibuffer-window)))
482 (while (and (not (bobp)) (bolp)) (goto-char (line-end-position 0))) 482 while (> needed (if truncated (1- available) available))
483 finally 483 do (goto-char (line-end-position (if truncated 0 -1)))
484 (unless (and truncated 484 (while (and (not (bobp)) (bolp)) (goto-char (line-end-position 0)))
485 eldoc-prefer-doc-buffer 485 finally
486 (get-buffer-window eldoc--doc-buffer)) 486 (unless (and truncated
487 (eldoc--message 487 eldoc-prefer-doc-buffer
488 (concat (buffer-substring (point-min) (point)) 488 (get-buffer-window eldoc--doc-buffer))
489 (and truncated 489 (cl-return
490 (format 490 (concat
491 "\n(Documentation truncated. Use `%s' to see rest)" 491 (buffer-substring (point-min) (point))
492 (substitute-command-keys "\\[eldoc-doc-buffer]")))))))) 492 (and truncated
493 ((= available 1) 493 (format
494 ;; Truncate "brutally." ; FIXME: use `eldoc-prefer-doc-buffer' too? 494 "\n(Documentation truncated. Use `%s' to see rest)"
495 (eldoc--message 495 (substitute-command-keys "\\[eldoc-doc-buffer]")))))))))
496 (truncate-string-to-width 496 ((= available 1)
497 (buffer-substring (point-min) (line-end-position 1)) width))))))))) 497 ;; Truncate "brutally." ; FIXME: use `eldoc-prefer-doc-buffer' too?
498 (truncate-string-to-width
499 (buffer-substring (point-min) (line-end-position 1)) width)))))
500 (when echo-area-message
501 (eldoc--message echo-area-message))))))
498 502
499(defun eldoc-documentation-default () 503(defun eldoc-documentation-default ()
500 "Show first doc string for item at point. 504 "Show first doc string for item at point.