Fix eldoc-box-only-multi-line behavior

Prior to this change, single line eldoc messages were just ignored
completely when eldoc-box-only-multi-line was non-nil, though they
should have been displayed in the minibuffer.

* eldoc-box.el (eldoc-box--enable): Change :before-until to :before-while.
(eldoc-box--eldoc-message-function): Return nil if the message is not
multi-line, so that the default eldoc message function picks up the
message.
This commit is contained in:
sm2n 2021-03-12 00:48:14 -05:00 committed by Yuan Fu
parent c1a1b77ec0
commit d4574ee392
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -145,7 +145,7 @@ See `eldoc-box-inhibit-display-when-moving'.")
(defun eldoc-box--enable () (defun eldoc-box--enable ()
"Enable eldoc-box hover. "Enable eldoc-box hover.
Intended for internal use." Intended for internal use."
(add-function :before-until (local 'eldoc-message-function) (add-function :before-while (local 'eldoc-message-function)
#'eldoc-box--eldoc-message-function) #'eldoc-box--eldoc-message-function)
(when eldoc-box-clear-with-C-g (when eldoc-box-clear-with-C-g
(advice-add #'keyboard-quit :before #'eldoc-box-quit-frame))) (advice-add #'keyboard-quit :before #'eldoc-box-quit-frame)))
@ -405,8 +405,10 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
(defun eldoc-box--eldoc-message-function (str &rest args) (defun eldoc-box--eldoc-message-function (str &rest args)
"Front-end for eldoc. Display STR in childframe and ARGS works like `message'." "Front-end for eldoc. Display STR in childframe and ARGS works like `message'."
(when (and (stringp str) (not (equal str ""))) (when (and (stringp str) (not (equal str "")))
(let ((doc (apply #'format str args))) (let* ((doc (apply #'format str args))
(unless (and eldoc-box-only-multi-line (eq (cl-count ?\n doc) 0)) (multi-line-p (and eldoc-box-only-multi-line
(eq (cl-count ?\n doc) 0))))
(unless multi-line-p
(eldoc-box--display doc) (eldoc-box--display doc)
(setq eldoc-box--last-point (point)) (setq eldoc-box--last-point (point))
;; Why a timer? ElDoc is mainly used in minibuffer, ;; Why a timer? ElDoc is mainly used in minibuffer,
@ -417,8 +419,8 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
;; in `pre-command-hook', which means the timer is reset before every ;; in `pre-command-hook', which means the timer is reset before every
;; command if `eldoc-box-hover-mode' is on and `eldoc-last-message' is not nil. ;; command if `eldoc-box-hover-mode' is on and `eldoc-last-message' is not nil.
(setq eldoc-box--cleanup-timer (setq eldoc-box--cleanup-timer
(run-with-timer eldoc-box-cleanup-interval nil #'eldoc-box--maybe-cleanup)))) (run-with-timer eldoc-box-cleanup-interval nil #'eldoc-box--maybe-cleanup)))
t)) multi-line-p)))
;;;; Eglot helper ;;;; Eglot helper