Providing better editing support for sbcl via readline

Posted by Steve on Mon 13 Apr 2009 at 11:45

The readline library is used by many programs which need to provide a pleasant environment for performing text entry, offering completion, history, and advanced editing facilities. There are applications which, for various reasons, do not use it, but this is something that may be fixed with the addition of the rlwrap readline wrapper.

Over the past few months I've been slowly getting to grips with coding in Lisp. The are several lisp environments availabe to users of Debian GNU/Linux and I have been alternating between two of them (clisp, & sbcl).

The first package, clisp, provides a nice environment with history, line editing and similar, by contrast the sbcl package has no history support, no editing support, and is less pleasant to use interactively. In short when I'm in the sbcl environment and I press "Up" to recall my previous line of entry I see nothing - which is often frustrating!

To solve this problem I installed the rlwrap package which wraps readline support around other programs:

skx@gold:~$ aptitude install rlwrap
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
  rlwrap
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 37.7kB of archives.
After this operation, 139kB of additional disk space will be used.
Get: 1 http://ftp.uk.debian.org sid/main rlwrap 0.28-2 [37.7kB]
Fetched 37.7kB in 0s (143kB/s)
Selecting previously deselected package rlwrap.
(Reading database ... 194601 files and directories currently installed.)
Unpacking rlwrap (from .../rlwrap_0.28-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up rlwrap (0.28-2) ...
skx@gold:~$

Once this is done I can invoke "rlwrap sbcl" to launch the sbcl environment with the readline wrapper around it. Suddenly the arrow keys work, I have persistant history, and command line editing works as it should.

It is hard to demonstrate this offline, but suffice it to say that I can run sbcl under rlwrap and I have persistant history - to the extent that I can load the environment and press "Up" a few times to repeat the things I entered last time round:

skx@gold:~$ rlwrap sbcl
This is SBCL 1.0.25.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at .

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (defvar test "Some text.  Mixed case")

TEST
* (string-downcase test)

"some text.  mixed case"
* (quit)
skx@gold:~$

While using rlwrap in this environment doesn't provide a great deal of difference it does make the work more pleasant, and I'm sure now I've experimented with it there will be more situations I'll use it.

rlwrap has several options which can be used to tweak the behaviour, the most useful of which I've found is the -c option (or "--complete-filenames") this allows the tool to keep track of the working directory and complete filenames appropriately, as you would see inside shells such as bash.

If you'd like to learn more about the provided options please see "man rlwrap", or view the file /usr/share/doc/rlwrap/README.


This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):

This article is copyright 2009 Steve - please ask for permission to republish or translate.