joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.26k stars 142 forks source link

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

Open NightMachinery opened 3 years ago

NightMachinery commented 3 years ago

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