9

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!

z_axis
  • 8,272
  • 7
  • 41
  • 61

2 Answers2

12

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.

Michele Piccolini
  • 2,634
  • 16
  • 29
Ramarren
  • 2,510
  • 1
  • 15
  • 11
  • 2
    slime-cd is an interactive compiled Lisp function in `slime.el'. (slime-cd DIRECTORY) Make DIRECTORY become Lisp's current directory. Return whatever swank:set-default-directory returns. – z_axis Feb 24 '12 at 08:28
  • 1
    This was helpful. However, the link to "cd shortcut" is dead. What did you have in mind? – MadPhysicist Dec 11 '17 at 22:14
6

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.

Miron Brezuleanu
  • 2,989
  • 2
  • 22
  • 33