Enable cl-annot for all files in an asdf project

Tagged as lisp

Written on 2020-02-21

Quick lisp tip for enabling cl-annot reader macros across an entire asdf project.

cl-annot enables @ annotation syntax for some Common Lisp operations.

For example, using cl-annot you can export a function like so:

@export
(defun foo ()
  "foo")

;; expands to ->
(progn
  (export 'foo)
  (defun foo ()
    "foo"))

Using cl-annot requires adding this code to the header of each .lisp file:

(annot:enable-annot-syntax)

This can be cumbersome for large asdf projects, which have many files. If you'd like to avoid pasting that header everywhere, you can use asdf's :around-compile hook:

(defsystem your-project
  :name "your-project"
  :components
  (...)
  :around-compile "(lambda (compile-fn)
                     (annot:enable-annot-syntax)
                     (funcall compile-fn))")

The string defining the lambda will enable annotations before each file in your project is compiled.

Now you can use cl-annot for any file in your project.


If you'd like to follow my indie game, Syn, please consider Wishlisting on Steam or Subscribing to Syn's email list.
comments powered by Disqus

Unless otherwise credited all blog material Creative Commons License by Ark