Sunday 16 February 2020

Getting the compilation output of asdf:load-system into SLIME

Running (asdf:load-system "my-project") in the SLIME REPL causes warnings and/or errors to be printed to the REPL, which is difficult to go through. In this post we explore a solution that does not receive much attention in beginner tutorials.

Emacs is a great IDE for Common Lisp development, especially with its SLIME package. The SLIME setup instructions are here.

ASDF is a (the?) build system for Common Lisp.

Assuming everything has been set up (e.g. this) The workflow usually goes like this:
  1. Launch Emacs.
  2. M-x slime
  3. In the REPL, type (asdf:load-system "my-project")
For reloading the entire system into a clean image and starting over, the workflow usually goes like this:
  1. In the REPL, press ","
  2. In the Emacs minibuffer, type restart-inferior-lisp
  3. In the REPL, type (asdf:load-system "my-project")
Step 3 in both scenarios can produce compilation warnings and/or errors. The problem is that they appear as part of the REPL output and are extremely hard to go through. In addition, for compilation errors, the default is to drop to a restart, but the stack frames are from ASDF, which makes it pretty much useless.

How to get the compilation errors show up nicely in SLIME, just like when using C-c C-c and C-c C-k? The only relevant post I can find seems to be this, which has already been archived.

The solution is to use the SLIME contributed module slime-asdf, which wraps the compilation output into the *slime-compilation* buffer. The source files are even highlighted with notes.

To use the slime-asdf module, modify the setup instructions here from:

;; Set your lisp system and, optionally, some contribs
(setq inferior-lisp-program "/opt/sbcl/bin/sbcl")
(setq slime-contribs '(slime-fancy))

to:

;; Set your lisp system and, optionally, some contribs
(setq inferior-lisp-program "/opt/sbcl/bin/sbcl")
(setq slime-contribs '(slime-fancy slime-asdf))

Now, from the SLIME REPL, pressing "," typing "load-system", and finally "my-project" will trigger the corresponding ASDF operation. Any compilation output will be shown nicely in the *slime-compilation* buffer.

By default, the buffer does not go to the foreground. I've found that setting

(setf asdf:*compile-file-warnings-behaviour* :error)

has been useful. This variable is explained in the ASDF manual here.

1 comment:

  1. Nice. Many thanks :) these are just-in-time clarifications. Trying to set up my first system here.

    ReplyDelete