SLIME hints #3 – interactive completions and smart tabs

Today I want to address auto-completion. There are many different Emacs extensions for doing completions, but the basic functionality in SLIME is provided by the function slime-complete-symbol, which takes the symbol under the cursor and expands it, using whatever symbols are reachable at that point in the code1]. The way I have it set up is a bit tricky, though, so here’s how it works:

I really prefer expansions to be bound to the TAB key. But the TAB key is also used to indent code. It’s possible to have it “do what I mean”, and the easiest method I found for that is to use Smart Tabs (see also the github repo).

Smart tab determines the expansion function to use based on the major mode of the current buffer*. So I’ve got the following in my configuration:

Now, whenever I press TAB and the cursor is at the end of a symbol, it gets expanded. If I press TAB on any other place, that indents that line.

There’s a lot of stuff you can customize with expansions and auto completion, but this will give you the basics quickly and without too much hassle.

1] For Clojure code, at least, this boils down to; every symbol that is defined (or imported etc) in the current name space. This has two consequences:

It only applies to code that has already been loaded into the program, so you will want to compile stuff pretty much immediately once you’ve written or modified it.

It does not expand let bindings or function arguments, since those are lexically scoped and cannot be retrieved from the name space. There is probably a way to fix this, but I haven’t looked into the problem that far.

* Update: the smart tab configuration must be keyed off the MAJOR mode. So slime-mode . slime-complete-symbol will not work, since slime-mode isn’t a major mode. I replaced it here with clojure-mode.