sly icon indicating copy to clipboard operation
sly copied to clipboard

[Q] How do I get the docstring for a symbol?

Open NightMachinery opened this issue 3 years ago • 0 comments

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. image

Here is an example of this working correctly in elisp, using helpful--docstring (which uses documentation under the hood): image

NightMachinery avatar May 15 '21 08:05 NightMachinery