The ReadLine Wrapper (rlwrap) utility is actually a must have when you want to run SBCL from the command line, because by default, SBCL in the terminal:
- doesn't offer symbol completion
- doesn't offer a history of commands
- doesn't even understand the arrow keys, left and right (they input
[[[A
instead), nor any default readline keybindings, the ones we find in bash et all: C-e, C-a, C-u, C-k, Alt-b, Alt-f etc.
We can actually fix this with rlwrap options.
We won't have intelligent code completion, that's for your editor that you will setup for proper CL development. Those settings are here to help when you want to run a code snippet at the terminal.
The default terminal REPL of the CLISP implementation is way more user friendly, but this implementation is lagging behind, and not recommended for production or serious development. SBCL does much more.
Use --remember / -r
. This allows to TAB-complete whatever you already typed. So, let's define a hello
function:
$ rlwrap --remember sbcl
* (defun hello () :hello)
HELLO
* (hell <TAB> <= completes "hello"
you can now TAB-complete "hell" to "hello". Awesome.
I made years before discovering that O_o RTFD, I know.
Provide a list of symbols in a file and use -f / --file completions.txt
.
Here's a list with all Common Lisp built-in symbols, with ASDF and UIOP symbols, as well as Alexandria's: https://gist.github.com/alejandrogallo/d36a4b3b37586d19e54ce4cda8a7c47b
A multi-line input is tedious to write in readline. What if we called an external editor, so that when we close it, the code is entered as if it was the prompt?
We can configure readline
itself. Add in its ~/.inputrc
config file:
# in ~/.inputrc
"\C-xe": rlwrap-call-editor # CTRL-x e
It only works in conjunction with --multi-line
.
Now use C-x e
to call your editor defined in RLWRAP_EDITOR
.
$ RLWRAP_EDITOR=vim/emacs/nano/gedit
$ rlwrap --multi-line=' ' sbcl
Use -c / --complete-filenames
. Nice.
-i
: completion is case insensitive.
-b '()'
: parentheses delimit words. Or:
--break-chars "(){}[],'#\";|\\"
--quote-characters "\""
Use C-q C-j
to enter a newline and write a multi-line input.
Lisp forms will be evaluated one after the other.
In a sbcl.sh file:
#!/bin/bash
rlwrap -i -b '()' -f completions.txt [all options here] sbcl $*
At that point, let's try: cl-repl, sbcli, CIEL's repl, Lem… https://lispcookbook.github.io/cl-cookbook/editor-support.html
This was written for my Udemy students: https://www.udemy.com/course/common-lisp-programming/?referralCode=2F3D698BBC4326F94358
I'd suggest Linedit too. See https://github.com/quil-lang/qvm/blob/master/doc/lisp-setup.md#optional-install-linedit