sly
sly copied to clipboard
[Q] How do I get the docstring for a symbol?
I want to display the docstring for symbols in company-counsel
using ivy-rich
. I don't know how I can get the docstring given a symbol though. Here is my function:
(defun night/ivy-docstring (candidate)
(let* (
(candidate-sym (intern-soft candidate))
(doc (cond
((equalp major-mode 'emacs-lisp-mode)
(or
(ignore-errors
(helpful--docstring candidate-sym (fboundp candidate-sym))
;; (helpful-symbol candidate-sym)
)
"")
)
((equalp major-mode 'lisp-mode)
;; (sly-eval `(slynk:describe-function ,candidate))
(sly-eval `(slynk:describe-symbol ,candidate)))
(t "Not implemented yet")
))
(doc (s-lines doc))
(doc (s-join "; " (identity doc))))
doc))
As you see, this documentation is mostly just the arglist and not a docstring, and it's suitable only for buffers.
Here is an example of this working correctly in elisp
, using helpful--docstring
(which uses documentation
under the hood):