Nyxt as a universal documentation viewer

Hello fellow Nyxt hackers!

I’ve just hacked up a universal documentation function relying on Nyxt introspection abilities. Nothing mind-blowing, though – it’s just a copy of describe-any without a lock on Nyxt symbols.

The code can use some improvements, but I thought it could be immediately useful even in this state. Here you go:

(define-command-global describe-all ()
  "Prompt for a symbol in any Nyxt-accessible package and describe it in the best way Nyxt can."
  (let* ((all-symbols (apply #'append (loop for package in (list-all-packages)
                                            collect (loop for sym being the external-symbols in package
                                                          collect sym))))
         ;; All copied from /nyxt/source/help.lisp with `describe-any' as a reference.
         (classes (remove-if (lambda (sym)
                               (not (and (find-class sym nil)
                                         (mopu:subclassp (find-class sym) (find-class 'standard-object)))))
                             all-symbols))
         (slots (alex:mappend (lambda (class-sym)
                                (mapcar (lambda (slot) (make-instance 'nyxt::slot
                                                                      :name slot
                                                                      :class-sym class-sym))
                                        (nyxt::class-public-slots class-sym)))
                              classes))
         (functions (remove-if (complement #'fboundp) all-symbols))
         (variables (remove-if (complement #'boundp) all-symbols)))
    (prompt
     :prompt "Describe:"
     :sources (list (make-instance 'nyxt::variable-source :constructor variables)
                    (make-instance 'nyxt::function-source :constructor functions)
                    (make-instance 'nyxt::user-command-source
                                   :actions (list (make-unmapped-command describe-command)))
                    (make-instance 'nyxt::class-source :constructor classes)
                    (make-instance 'nyxt::slot-source :constructor slots)))))

EDIT: symbolsexternal-symbols so that only exported symbols are shown. Otherwise it’s extremely cluttered.

4 Likes

Could you explain a bit what this does? I may be misunderstanding the purpose. As far as I can tell this displays code and documentation from available Lisp code? But if that’s the case how is it a universal /document/ viewer? I understand “universal document viewer” to be something that’ll display like PDFs, Epubs, HTML, etc.

I may have been unclear here, sorry. What I mean is not document (something containing information in an arbitrary form and layout), but documentation (the clarifying text coming with the software).

The regular describe-* functions of Nyxt allow you to look at the documentation (the clarifying text) and some other properties of the entities that Nyxt uses – classes, functions, slots etc. What this piece of code does is expanding this ability to not only Nyxt entities, but also all the Nyxt-accessible Lisp entities, which means that Nyxt can be used to look at the documentation and information of any Lisp library/system/piece of code – be it a regular expression library cl-ppcre, an HTML parser plump, or any other library used in Nyxt.

1 Like

Oh that makes sense! That’s kinda cool. :slight_smile:

UPD: Nyxt 3.* has universal-describe-* command counterparts to regular describe-* commands. So, if you like this post, then you are likely to have the universal documentation access real soon :slight_smile: