Skip to content

Instantly share code, notes, and snippets.

@kchanqvq
Created December 18, 2021 22:21
Show Gist options
  • Save kchanqvq/1e0cd7b0ec051f1a226182d0f001fbd0 to your computer and use it in GitHub Desktop.
Save kchanqvq/1e0cd7b0ec051f1a226182d0f001fbd0 to your computer and use it in GitHub Desktop.
Describe-all
(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
(delete-duplicates
(apply #'append (loop for package in (remove (find-package "KEYWORD") (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 (alexandria: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)))))
@kchanqvq
Copy link
Author

credit: @aartaka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment