Using CL library functions in config.lisp


I’m trying to create convenience commands for some simple web scraping (eg: get ISBN from an Amazon page for a book). I managed to hack together a solution in an SBCL repl using a bunch of CL libraries (loaded through ql:quickload), but now I don’t know how to load the libraries for usage in my config file. How should I do this?

PS: FWIW, here’s my code if you’re curious. Feel free to tear it apart and point me toward better solutions :sweat_smile:

(ql:quickload '("dexador" "plump" "lquery" "lparallel" "str" "Serapeum"))

(defun get-isbn-from-amazon (url)
    ;; TODO: Validate that the URL is Amazon?
  (let* ((request (dex:get url))
         (parsed-content (lquery:$ (initialize request)))
           (subseq (lquery:$ parsed-content "#detailBulletsWrapper_feature_div li" (text)) 0 7))
         (isbn-13 (str:words (coerce (svref product-details 4) 'string))))

(define-command-global show-isbn ()
  "Get ISBN-13 from an Amazon page"
    (buf-url (quri:render-uri (url (current-buffer))))
    (isbn-13 (get-isbn-from-amazon buf-url)))
  (echo (isbn-13)))


Good news: dexador, serapeum, plump, lparallel, ans str are all available to you without loading, due to being Nyxt dependencies.

Bad news: lquery is not included as Nyxt dependency, so you’d have to load it yourself. Here’re the ways:

  • Add library sources to your extensions directory (usually ~/.local/share/nyxt/extensions/) and load them with asdf:load-system.
  • Install quicklisp, allow using non-Nyxt ASDF registries (reset-asdf-registries), and then simply do ql:quickload. I have this code in my config:
;;; Reset ASDF registries to allow loading Lisp systems from
;;; everywhere.
#+nyxt-3 (reset-asdf-registries)

;;; Load quicklisp. Not sure it works. Copied from the result of `ql:add-to-init`.
(let ((quicklisp-init
       (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))
  • Load files one by one with (load #p"/path/to/file.lisp") :stuck_out_tongue:

Given that the config file is a plain Lisp file, you can hack any type of library loading (the only downside being that it slows Nyxt startup by some second or two), given the registries, unlocked with reset-asdf-registries.

1 Like

Thanks! The second option seems to work smoothly for me :tada: :slightly_smiling_face: