Emacs-lisp eldoc: fix error if symbol unbound

`+emacs-lisp-append-value-to-eldoc-a' `error's if the symbol isn't
bound, because `symbol-value' errors in that case. Fix that bug by only
modifying the result of `elisp-get-var-docstring' if the symbol is
bound.
This commit is contained in:
Nikita Bloshchanevich 2021-01-02 12:24:31 +01:00
parent 0c9256411d
commit b12df73cc1

View file

@ -99,15 +99,17 @@ employed so that flycheck still does *some* helpful linting.")
"Display variable value next to documentation in eldoc." "Display variable value next to documentation in eldoc."
:around #'elisp-get-var-docstring :around #'elisp-get-var-docstring
(when-let (ret (funcall orig-fn sym)) (when-let (ret (funcall orig-fn sym))
(concat ret " " (if (fboundp sym)
(let* ((truncated " [...]") (concat ret " "
(print-escape-newlines t) (let* ((truncated " [...]")
(str (symbol-value sym)) (print-escape-newlines t)
(str (prin1-to-string str)) (str (symbol-value sym))
(limit (- (frame-width) (length ret) (length truncated) 1))) (str (prin1-to-string str))
(format (format "%%0.%ds%%s" (max limit 0)) (limit (- (frame-width) (length ret) (length truncated) 1)))
(propertize str 'face 'warning) (format (format "%%0.%ds%%s" (max limit 0))
(if (< (length str) limit) "" truncated)))))) (propertize str 'face 'warning)
(if (< (length str) limit) "" truncated))))
ret)))
(map! :localleader (map! :localleader
:map emacs-lisp-mode-map :map emacs-lisp-mode-map