Search code examples
common-lispsbcl

How to set SBCL's current directory using slime?


In the past, i use the following script to start SBCL:

breakchars="(){}[],^%$#@\"\";:''|\\"
cd /media/E/work

exec rlwrap --remember -c -b "$breakchars"  -f "$HOME"/.sbcl_completions  sbcl --noinform --userinit "$HOME"/.sbclrc "$@"

Now when using slime in emacs, i doonot know how to set SBCL's current directory ?

Any suggestion is appreciated!


Solution

  • 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.