How to set SBCL's current directory using slime?

SLIME starts the Lisp system with the current directory taken from the directory where the file associated with the current buffer is. Typically you would open a file where you want SLIME to start first.

If you want to change the current directory a running Lisp then the best way is to use ,cd shortcut. This assumes you have a proper slime-repl set up, since current Slime installations are very minimal by default. See contributed packages, you probably want at least slime-fancy metapackage.


Why do you need to change the current directory from SLIME? I assume it's not because you want to visit a Lisp source file from the system you're currently writing, but because you want write code that reads or writes a file that contains data.

If so, it's probably better to try local-projects in Quicklisp. Together with quickproject, it allows you to easily create systems, which you can then load using (ql:quickload 'my-system) or even (require 'my-system).

If you need to refer to a data file located relative to the root of system my-system (just using the name from the last paragraph to keep examples consistent), you could use asdf:system-relative-pathname. For instance, (asdf:system-relative-pathname 'my-system "files/data.txt").

Sure, deployment is a completely different business. My solution is to look at how the running executable was called to determine if the code is deployed or in development. If in development, I use asdf:system-relative-pathname. If deployed, I determine the path of the files based on the path of the executable (my 'build script' copies these files next to the executables when building the project).

Since I started using this approach, my need for cd-ing in SBCL dropped to zero. cd-ing around wasn't hard, but it's nice to have less things to worry about.