Play nice with further customizations of eldoc-message-function

Uses a :before-until advice on the local value of
eldoc-message-function instead of setting it directly.  Thus, when we
give up because of eldoc-box-only-multi-line (or some other future
criteria), other :before-until handlers can kick in.

* eldoc-box.el (eldoc-box--eldoc-message-function): Control return of
t or nil.
(eldoc-box-hover-mode): Use add-function and
remove-function.
This commit is contained in:
João Távora 2018-12-12 13:53:33 +00:00
parent fcfd701f57
commit c9693eddb0

View File

@ -212,10 +212,10 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
"Frontend for eldoc. Display STR in childframe and ARGS works like `message'." "Frontend for eldoc. Display STR in childframe and ARGS works like `message'."
(if (stringp str) (if (stringp str)
(let ((doc (apply #'format str args))) (let ((doc (apply #'format str args)))
(if (and eldoc-box-only-multi-line (eq (cl-count ?\n doc) 0)) (unless (and eldoc-box-only-multi-line (eq (cl-count ?\n doc) 0))
(apply #'eldoc-minibuffer-message str args)
(eldoc-box--display (apply #'format str args)))) (eldoc-box--display (apply #'format str args))))
(eldoc-box-quit-frame))) (eldoc-box-quit-frame)
t))
(define-minor-mode eldoc-box-hover-mode (define-minor-mode eldoc-box-hover-mode
"Displays hover documentations in a childframe. This mode is buffer local." "Displays hover documentations in a childframe. This mode is buffer local."
@ -228,8 +228,9 @@ Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
(unless eldoc-box--cleanup-timer (unless eldoc-box--cleanup-timer
(setq eldoc-box--cleanup-timer (run-with-idle-timer 1 t #'eldoc-box--maybe-cleanup))) (setq eldoc-box--cleanup-timer (run-with-idle-timer 1 t #'eldoc-box--maybe-cleanup)))
(add-to-list 'eldoc-box--enabled-buffer-list (current-buffer)) (add-to-list 'eldoc-box--enabled-buffer-list (current-buffer))
(setq-local eldoc-message-function #'eldoc-box--eldoc-message-function)) (add-function :before-until (local 'eldoc-message-function)
(setq-local eldoc-message-function #'eldoc-minibuffer-message) #'eldoc-box--eldoc-message-function))
(remove-function (local 'eldoc-message-function) #'eldoc-box--eldoc-message-function)
(delete (current-buffer) eldoc-box--enabled-buffer-list) (delete (current-buffer) eldoc-box--enabled-buffer-list)
;; this function has to be called after the current buffer is ;; this function has to be called after the current buffer is
;; removed from buffer list ;; removed from buffer list