7

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.

Karl Yngve Lervåg
  • 1,714
  • 3
  • 18
  • 34

4 Answers4

8

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

Christophe
  • 131
  • 1
5

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.

Vatine
  • 20,782
  • 4
  • 54
  • 70
  • 1
    I can't find anything in the SBCL manual about it, so I suppose there is no built-in completion support. I can only second the recommendation to use SLIME, it even has multiple completion systems to choose from. Especially the fuzzy completion is great. And you can also complete with `` in the SLIME REPL. (It does at least work for me, and I didn't have to configure anything to achieve that.) EDIT: I just see that C-c C-i is now the right completion key binding in non-repl SLIME buffers. That's new to me, it used to be M-C-i. – Rörd Mar 21 '11 at 17:23
  • 1
    Well, a problem is that I use vim, not emacs. I have tried to swap, but there is just a little bit too much work to setup emacs with vipermode (or similar) and to tune it to my liking to make it work for me. Thus, at least for now, slime is not an option. I do use a slime-inspired plugin for vim, but it is not nearly as powerful. Anyway, this is why I'm interested in completion for the standard REPL of SBCL. Anyway, thanks for the answer. It makes me a little more inspired to make a new try at emacs. – Karl Yngve Lervåg Mar 24 '11 at 07:11
4

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.

REPL
  • 41
  • 2
  • Instead of creating `/usr/share/rlwrap/completions/sbcl` (which likely requires superuser privileges to create), a regular user could create `~/.sbcl_completions` instead. – Flux Dec 29 '21 at 13:54
0

If you want to use sbcl, emacs and slime, follow this Modern Common Lisp on Linux tutorial. The tutorial mentions installing quicklisp and especially (ql:quickload "quicklisp-slime-helper"), an elispscript which getting slime to do autocomplete and more.

claj
  • 5,172
  • 2
  • 27
  • 30