Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling autocomplete in sbcl

I have recently started to learn lisp, and have mainly bin using clisp and vim. I wanted to try sbcl as well, since this is often recommended as one of the best, free lisp compilers. There is one thing, though, which makes sbcl more difficult to use for me: I can not get autocomplete in the REPL, which I do have in clisp. That is, when I start sbcl and type the following (as an example),

* (requi<tab>

where <tab> is the literal tab character, I do not get a list of completions, but rather a verbose tab character. In clisp, <tab> will complete the previous line to * (require.

As I am fairly new to lisp, the autocomplete functionality in clisp is really handy, so it would really be very convenient if anyone could explain how to get it in sbcl as well.

like image 929
Karl Yngve Lervåg Avatar asked Mar 21 '11 14:03

Karl Yngve Lervåg


3 Answers

One way of getting an autocompleting repl in SBCL is to use linedit, from http://common-lisp.net/project/linedit/. A second is to use rlwrap, a readline wrapper, with a suitable completions file. (I think it's fair to say that neither of these is as commonly used as emacs, which of course also provides a completing REPL with a number of other useful features.)

like image 196
Christophe Avatar answered Nov 19 '22 09:11

Christophe


I don't know of a way to get an auto-completing REPL in SBCL, but I find that interfacing with my lisp environment from within SLIME is quite handy and at that point, you can use C-c C-i for auto-completion.

like image 30
Vatine Avatar answered Nov 19 '22 08:11

Vatine


Actually it's completely possible. Yes, You want to work with Common Lisp via Emacs and Slime (I prefer SLY). But it's another wall beginners hit.

You want to just play from the REPL? The following instructions allow autocomplete in SBCL with rlwrap.

https://www.cliki.net/CMUCL%20Hints

1) install rlwrap

2) create shell alias, for example putting text like

alias rs="rlwrap sbcl"

into your ~/.bashrc (or ~/.profile or whatever). (or you can continue calling sbcl rlwrapped via "rlwrap sbcl")

3)Edi Weitz created a completion list file that is now gone from his website, so i'm linking to the Internet Archive. save this wordlist into a file "sbcl" https://web.archive.org/web/20031207221537/http://weitz.de/files/cmucl_completions

4)You can try putting the file according to the instructions on Cliki, this will only apply for the user you are logged in under. I wanted it to work for all users, so I put the "sbcl" file into my rlwrap completion directory, which is in /usr/share/rlwrap/completions/

So now I have a file /usr/share/rlwrap/completions/sbcl That contains the words.

5)Create / adjust ~/.inputrc file add the line

TAB: complete

5) Done, now in a new terminal (or after reloading .bashrc) I can launch SBCL via rlwrap with the alias "rs" start typing (def (or whatever) and hit TAB, and get auto-completion suggestions.

Beginner Bonus - if you want to edit lisp in the terminal, from the REPL, in say, vim with parinfer, try magic-ed, which will allow you to edit files from the repl. Configuring SBCL to use ED is esoteric. This solves that issue for You. https://github.com/sanel/magic-ed With tab auto-completion and convenient way to edit lisp from the terminal, one can start learning Common Lisp in the terminal.

like image 3
REPL Avatar answered Nov 19 '22 09:11

REPL