ANN: Emacs auto-complete plugin for slime users

436 views
Skip to first unread message

Steve Purcell

unread,
Aug 14, 2010, 6:19:33 AM8/14/10
to clo...@googlegroups.com
Hi all,

A while ago I hooked Slime's completion and documentation features into the popular Emacs auto-completion framework "auto-complete" (http://www.emacswiki.org/emacs/AutoComplete).

Since it may be of interest to others, I've released the completion plugin on github: http://github.com/purcell/ac-slime

Here's a screenshot of the plugin in action in a clojure-mode buffer, showing the (very handy) pop-up documentation:


Screen shot 2010-08-14 at 09.50.40.png

David Nolen

unread,
Aug 14, 2010, 12:14:31 PM8/14/10
to clo...@googlegroups.com
Excellent. Seems to work quite well.

-Steve
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Michał Marczyk

unread,
Aug 15, 2010, 3:45:01 AM8/15/10
to clo...@googlegroups.com
This is absolutely awesome! I notice it also works perfectly with
Common Lisp... I'm in a state of blissful exaltation. :-)

Sincerely,
Michał

Steve Purcell

unread,
Aug 15, 2010, 3:57:55 AM8/15/10
to clo...@googlegroups.com
On 15 Aug 2010, at 08:45, Michał Marczyk wrote:

> This is absolutely awesome! I notice it also works perfectly with
> Common Lisp... I'm in a state of blissful exaltation. :-)


Excellent - so if there are any quirks with this plugin, at least there'll be a couple more users to help fix it up now!

(For instance, it doesn't work perfectly if you type "some-namespace/" and then try to start completion, but that might be something related to my slime completion settings. And also, I haven't managed to bind it to TAB in the REPL yet...)

Incidentally, I've also got a hippie-expand source for SLIME somewhere in my emacs config: http://github.com/purcell/emacs.d

-Steve

Heinz N. Gies

unread,
Aug 15, 2010, 4:18:18 AM8/15/10
to clo...@googlegroups.com
Steve,
this is awesome!

Regards,
Heinz

Michał Marczyk

unread,
Aug 15, 2010, 5:13:58 AM8/15/10
to clo...@googlegroups.com
On 15 August 2010 09:57, Steve Purcell <st...@sanityinc.com> wrote:
> Excellent - so if there are any quirks with this plugin, at least there'll be a couple more users to help fix it up now!

Definitely. :-)

> (For instance, it doesn't work perfectly if you type "some-namespace/" and then try to start completion, but that might be something related to my slime completion settings.

It seems to work for me. I'd gist the relevant part of my config for
you, except I'm not sure which is the relevant part... I'll have to
look closer.

On the other hand, I'm having mixed luck with fuzzy completion...
slime-fuzzy-complete-symbol offers 'with-bindings and 'with-bindings*
as completions for 'wi-bi, but so far I haven't been able to provoke
ac + ac-slime to do the same (with (lambda () (set-up-slime-ac t)) in
my slime-mode-hook and slime-repl-mode-hook).

> And also, I haven't managed to bind it to TAB in the REPL yet...)

(add-hook 'slime-connected-hook
(lambda ()
(define-key slime-mode-map (kbd "TAB") 'auto-complete)
(define-key slime-repl-mode-map (kbd "TAB") 'auto-complete)))

I also put (lambda () (auto-complete-mode t)) in the hooks for
slime-mode and slime-repl-mode.

> Incidentally, I've also got a hippie-expand source for SLIME somewhere in my emacs config: http://github.com/purcell/emacs.d

Cool! I'll look around. :-)

Sincerely,
Michał

pmh

unread,
Aug 14, 2010, 11:42:03 AM8/14/10
to Clojure
Great work, thank you for sharing.

- Patrik
>  Screen shot 2010-08-14 at 09.50.40.png
> 44KViewDownload
>
>
>
> -Steve

Matthias Schneider

unread,
Aug 14, 2010, 5:51:50 PM8/14/10
to Clojure
Really usefull, nice work! And a perfect time to finally update my old
auto-complete installation to version 1.3.

On Aug 14, 12:19 pm, Steve Purcell <st...@sanityinc.com> wrote:
> Hi all,
>
> A while ago I hooked Slime's completion and documentation features into the popular Emacs auto-completion framework "auto-complete" (http://www.emacswiki.org/emacs/AutoComplete).
>
> Since it may be of interest to others, I've released the completion plugin on github:http://github.com/purcell/ac-slime
> -Steve

sponge bob

unread,
Aug 15, 2010, 5:43:05 AM8/15/10
to Clojure
Could you share your nice color theme, please?

Steve Purcell

unread,
Aug 15, 2010, 3:18:06 PM8/15/10
to clo...@googlegroups.com


Sure:

http://github.com/purcell/emacs.d/blob/master/site-lisp/color-theme-sanityinc/color-theme-sanityinc.el

There are light and dark versions, and I switch between them with "M-x light" and "M-x dark" depending on how my eyes feel: http://github.com/purcell/emacs.d/blob/master/init-themes.el

I'll willingly split the theme out into a separate git repo if it makes a difference to anyone.

-Steve

Steve Purcell

unread,
Aug 15, 2010, 3:29:17 PM8/15/10
to clo...@googlegroups.com
On 15 Aug 2010, at 10:13, Michał Marczyk wrote:

> On the other hand, I'm having mixed luck with fuzzy completion...
> slime-fuzzy-complete-symbol offers 'with-bindings and 'with-bindings*
> as completions for 'wi-bi, but so far I haven't been able to provoke
> ac + ac-slime to do the same (with (lambda () (set-up-slime-ac t)) in
> my slime-mode-hook and slime-repl-mode-hook).
>
>> And also, I haven't managed to bind it to TAB in the REPL yet...)
>
> (add-hook 'slime-connected-hook
> (lambda ()
> (define-key slime-mode-map (kbd "TAB") 'auto-complete)
> (define-key slime-repl-mode-map (kbd "TAB") 'auto-complete)))
>
> I also put (lambda () (auto-complete-mode t)) in the hooks for
> slime-mode and slime-repl-mode.


Ah, yes, that would work. Using 'slime-connected-hook was the bit I was missing.

Thanks!

-Steve

sponge bob

unread,
Aug 16, 2010, 12:18:25 PM8/16/10
to Clojure
On 15 авг, 23:18, Steve Purcell <st...@sanityinc.com> wrote:

> > Could you share your nice color theme, please?
>
> Sure:
>
> http://github.com/purcell/emacs.d/blob/master/site-lisp/color-theme-s...
>
> There are light and dark versions, and I switch between them with "M-x light" and "M-x dark" depending on how my eyes feel:http://github.com/purcell/emacs.d/blob/master/init-themes.el
>
> I'll willingly split the theme out into a separate git repo if it makes a difference to anyone.

Thanks a lot! Great work!

Stefan Kamphausen

unread,
Aug 17, 2010, 4:38:43 AM8/17/10
to Clojure
Hi,

just yesterday I took a first look at auto-complete together with your
slime auto completion sources.

I'm encountering some Exceptions, though,

If I'm in a .clj-buffer and start typing

(clojure.

and then wait for the auto completion to popup I see a list of
possible completions like, e.g., clojure.set, clojure.xml and more,
and then an Exception pops up:

clojure.set
[Thrown class java.lang.ClassNotFoundException]

Restarts:
0: [QUIT] Quit to the SLIME top level
1: [ABORT] ABORT to SLIME level 0

Backtrace:
0: java.net.URLClassLoader$1.run(URLClassLoader.java:202)
1: java.security.AccessController.doPrivileged(Native Method)
2: java.net.URLClassLoader.findClass(URLClassLoader.java:190)
3: clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:
58)
4: java.lang.ClassLoader.loadClass(ClassLoader.java:307)
5: java.lang.ClassLoader.loadClass(ClassLoader.java:248)
6: java.lang.Class.forName0(Native Method)
7: java.lang.Class.forName(Class.java:247)
8: clojure.lang.RT.classForName(RT.java:1566)
9: clojure.lang.Compiler.maybeResolveIn(Compiler.java:5700)
10: clojure.core$ns_resolve.invoke(core.clj:3380)
11: swank.commands.basic$describe_symbol_STAR_.invoke(basic.clj:184)
12: swank.commands.basic
$eval880$documentation_symbol__881.invoke(basic.clj:201)
13: clojure.lang.Var.invoke(Var.java:365)
14: user$eval1927.invoke(NO_SOURCE_FILE)
15: clojure.lang.Compiler.eval(Compiler.java:5424)
16: clojure.lang.Compiler.eval(Compiler.java:5391)
17: clojure.core$eval.invoke(core.clj:2382)
18: swank.core$eval_in_emacs_package.invoke(core.clj:94)
19: swank.core$eval_for_emacs.invoke(core.clj:241)
20: clojure.lang.Var.invoke(Var.java:373)
21: clojure.lang.AFn.applyToHelper(AFn.java:169)
22: clojure.lang.Var.applyTo(Var.java:482)
23: clojure.core$apply.invoke(core.clj:540)
24: swank.core$eval_from_control.invoke(core.clj:101)
25: swank.core$sldb_loop$fn__401.invoke(core.clj:203)
26: swank.core$sldb_loop.invoke(core.clj:200)
27: swank.core$invoke_debugger.invoke(core.clj:216)
28: swank.core$sldb_debug.invoke(core.clj:220)
29: swank.core$eval_for_emacs.invoke(core.clj:279)
30: clojure.lang.Var.invoke(Var.java:373)
31: clojure.lang.AFn.applyToHelper(AFn.java:169)
32: clojure.lang.Var.applyTo(Var.java:482)
33: clojure.core$apply.invoke(core.clj:540)
34: swank.core$eval_from_control.invoke(core.clj:101)
35: swank.core$spawn_worker_thread$fn__455$fn__456.invoke(core.clj:
300)
36: clojure.lang.AFn.applyToHelper(AFn.java:159)
37: clojure.lang.AFn.applyTo(AFn.java:151)
38: clojure.core$apply.invoke(core.clj:540)
39: swank.core$spawn_worker_thread$fn__455.doInvoke(core.clj:296)
40: clojure.lang.RestFn.invoke(RestFn.java:398)
41: clojure.lang.AFn.run(AFn.java:24)
42: java.lang.Thread.run(Thread.java:619)


Another one shows up if I hit TAB (bound to indent-for-tab-command)
before the completion shows up I get a


No message.
[Thrown class java.lang.NullPointerException]

Restarts:
0: [QUIT] Quit to the SLIME top level

Backtrace:
0: clojure.lang.Compiler$FnMethod.parse(Compiler.java:4290)
1: clojure.lang.Compiler$FnExpr.parse(Compiler.java:3173)
2: clojure.lang.Compiler.analyzeSeq(Compiler.java:5367)
3: clojure.lang.Compiler.analyze(Compiler.java:5190)
4: clojure.lang.Compiler.analyze(Compiler.java:5151)
5: clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3057)
6: clojure.lang.Compiler.analyzeSeq(Compiler.java:5371)
7: clojure.lang.Compiler.analyze(Compiler.java:5190)
8: clojure.lang.Compiler.analyze(Compiler.java:5151)
9: clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:4670)
10: clojure.lang.Compiler$FnMethod.parse(Compiler.java:4328)
11: clojure.lang.Compiler$FnExpr.parse(Compiler.java:3173)
12: clojure.lang.Compiler.analyzeSeq(Compiler.java:5367)
13: clojure.lang.Compiler.analyze(Compiler.java:5190)
14: clojure.lang.Compiler.eval(Compiler.java:5421)
15: clojure.lang.Compiler.eval(Compiler.java:5391)
16: clojure.core$eval.invoke(core.clj:2382)
17: swank.core$eval_in_emacs_package.invoke(core.clj:94)
18: swank.core$eval_for_emacs.invoke(core.clj:241)
19: clojure.lang.Var.invoke(Var.java:373)
20: clojure.lang.AFn.applyToHelper(AFn.java:169)
21: clojure.lang.Var.applyTo(Var.java:482)
22: clojure.core$apply.invoke(core.clj:540)
23: swank.core$eval_from_control.invoke(core.clj:101)
24: swank.core$spawn_worker_thread$fn__455$fn__456.invoke(core.clj:
300)
25: clojure.lang.AFn.applyToHelper(AFn.java:159)
26: clojure.lang.AFn.applyTo(AFn.java:151)
27: clojure.core$apply.invoke(core.clj:540)
28: swank.core$spawn_worker_thread$fn__455.doInvoke(core.clj:296)
29: clojure.lang.RestFn.invoke(RestFn.java:398)
30: clojure.lang.AFn.run(AFn.java:24)
31: java.lang.Thread.run(Thread.java:619)


Did anybody else see this? I can reproduce this at will and can
easily test things if you want.

Kind regards,
Stefan

Steve Purcell

unread,
Aug 17, 2010, 8:00:39 AM8/17/10
to clo...@googlegroups.com
On 17 Aug 2010, at 09:38, Stefan Kamphausen wrote:

> Hi,
>
> just yesterday I took a first look at auto-complete together with your
> slime auto completion sources.
>
> I'm encountering some Exceptions, though,
>
> If I'm in a .clj-buffer and start typing
>
> (clojure.
>
> and then wait for the auto completion to popup I see a list of
> possible completions like, e.g., clojure.set, clojure.xml and more,
> and then an Exception pops up:


That seems to be a slime/swank problem, related to accessing the documentation for a symbol corresponding to a namespace. In a clojure-mode buffer, use M-: to execute the following expression:

(slime-eval '(swank:documentation-symbol "clojure.set"))

This results in the same error. I'll cross-post to the swank-clojure list to see if anyone knows what might be going wrong.

-Steve

Steve Purcell

unread,
Aug 17, 2010, 8:28:46 AM8/17/10
to clo...@googlegroups.com
On 17 Aug 2010, at 13:00, Steve Purcell wrote:

> That seems to be a slime/swank problem, related to accessing the documentation for a symbol corresponding to a namespace. In a clojure-mode buffer, use M-: to execute the following expression:
>
> (slime-eval '(swank:documentation-symbol "clojure.set"))
>
> This results in the same error. I'll cross-post to the swank-clojure list to see if anyone knows what might be going wrong.

Underlying all this, the following clojure function call produces the error:

(find-doc clojure.set)

-Steve

Steve Molitor

unread,
Aug 17, 2010, 4:17:19 PM8/17/10
to clo...@googlegroups.com
This is great, thanks!

Fuzzy completion (ac-source-slime-fuzzy) isn't working for me.  It complains that slime-fuzzy-comp

Steve Molitor

unread,
Aug 17, 2010, 4:21:45 PM8/17/10
to clo...@googlegroups.com
Sorry my message got truncated.  Let's try again:

Fuzzy completion (ac-source-slime-fuzzy) isn't working for me.  It complains that the function slime-fuzzy-completions is not defined.  I'm using slime.el version 2010404, which does not define that function, although it does define slime-simple-completions.  Not sure if there's a newer version of slime.el out there but I did install fresh about a week or two ago.

Not to worry; I'm very happy with ac-source-slime-simple.

Steve

Steve Purcell

unread,
Aug 18, 2010, 3:27:14 AM8/18/10
to clo...@googlegroups.com
On 17 Aug 2010, at 21:21, Steve Molitor wrote:

> Sorry my message got truncated. Let's try again:
>
> Fuzzy completion (ac-source-slime-fuzzy) isn't working for me. It complains that the function slime-fuzzy-completions is not defined. I'm using slime.el version 2010404, which does not define that function, although it does define slime-simple-completions. Not sure if there's a newer version of slime.el out there but I did install fresh about a week or two ago.
>
> Not to worry; I'm very happy with ac-source-slime-simple.


To use fuzzy completions you need to have and require slime-fuzzy.el, which comes with the full slime, but not with the version in ELPA.

-Steve

MHOOO

unread,
Aug 18, 2010, 8:51:49 AM8/18/10
to Clojure
I'm experiencing the exact same problem. Haven't found a way to fix
this yet.

Steve Purcell

unread,
Aug 18, 2010, 9:34:57 AM8/18/10
to clo...@googlegroups.com
On 18 Aug 2010, at 13:51, MHOOO wrote:

> I'm experiencing the exact same problem. Haven't found a way to fix
> this yet.

I've fixed the problem in my fork of swank-clojure and requested that Phil pull the commit into the master repo:

http://github.com/purcell/swank-clojure/commit/7172c275f390c59d0b532ec3dc2994b2b9f72167

-Steve

MHOOO

unread,
Aug 18, 2010, 1:44:05 PM8/18/10
to Clojure
I can get rid of those errors by evaling this in the repl. Does this
work for you as well?:
(do
(require 'clojure.contrib.with-ns)
(clojure.contrib.with-ns/with-ns
'swank.commands.basic
(defn- describe-to-string [var]
{:pre [(var? var)]}
(with-out-str
(print-doc var)))

(defn- describe-symbol* [symbol-name]
(with-emacs-package
(let [v (try (ns-resolve (maybe-ns *current-package*) (symbol
symbol-name))
(catch ClassNotFoundException e
nil))]
(if (and v (var? v))
(describe-to-string v)
(str "Unknown symbol " symbol-name)))))))

doug

unread,
Aug 18, 2010, 10:39:06 PM8/18/10
to Clojure
Great plugin- thanks steve
i applied your patch but still throws on clojure.main and on some
(import '(java.util.concurrent....

MHOOO's code above seems to resolve my errors.

thanks -doug

Steve Purcell

unread,
Aug 19, 2010, 9:21:08 AM8/19/10
to clo...@googlegroups.com
Odd. My patch works for me, and MHOOO's code simply applies a very similar patch at runtime, so I'd guess that your swank code is getting loaded from a location other than the one you patched.

I guess Phil's very busy, but if he can apply this patch, then the regular swank-clojure 1.3.0-SNAPSHOT on clojars should end up containing the fix.

-Steve

Phil Hagelberg

unread,
Aug 19, 2010, 10:46:40 AM8/19/10
to clo...@googlegroups.com
On Thu, Aug 19, 2010 at 6:21 AM, Steve Purcell <st...@sanityinc.com> wrote:
> I guess Phil's very busy, but if he can apply this patch, then the regular swank-clojure 1.3.0-SNAPSHOT on clojars should end up containing the fix.

Just applied this patch and pushed to github and clojars. Thanks!

-Phil

Jarl Haggerty

unread,
Oct 16, 2010, 12:27:13 AM10/16/10
to Clojure
Should autocomplete work in the swank repl? It works perfectly in a
clj buffer but nothing happens in the repl.

Scott Jaderholm

unread,
Oct 16, 2010, 12:43:32 AM10/16/10
to clo...@googlegroups.com
Works for me in repl. I have too much slime/clojure customization code, not really sure what does what :)

Maybe this:

(defun slime-clojure-repl-setup ()
  (when (string-equal "clojure" (slime-connection-name))
    (message "Setting up repl for clojure")
    (when (slime-inferior-process)
      (slime-redirect-inferior-output))

    (set-syntax-table clojure-mode-syntax-table)
    (clojure-mode-font-lock-setup)

    (setq lisp-indent-function 'clojure-indent-function)

    (when (and (featurep 'paredit) paredit-mode (>= paredit-version 21))
      (define-key slime-repl-mode-map "{" 'paredit-open-curly)
      (define-key slime-repl-mode-map "}" 'paredit-close-curly))
    (slime-setup '(slime-fancy))))

(add-hook 'slime-repl-mode-hook 'slime-clojure-repl-setup)

Scott


Preecha P

unread,
Oct 17, 2010, 1:00:37 PM10/17/10
to Clojure
Same here. It seems like auto-complete-mode doesn't fire up
correctly. I tried to hook it using (add-hook 'slime-repl-mode-hook
(lambda () (auto-complete-mode t) but it doesn't seems to do anything.
I have to open the mode manually.

On Oct 16, 11:27 am, Jarl Haggerty <fictivela...@gmail.com> wrote:
> Should autocomplete work in the swankrepl?  It works perfectly in a

Paul Mooser

unread,
Oct 20, 2010, 9:55:00 PM10/20/10
to Clojure
I was having this problem, and what solved it for me was to customize
the ac-modes variable (using M-x customize-variable RET ac-modes RET)
and adding slime-repl-mode to the list. Once I added this, auto-
complete gets automatically enabled on my repl buffers as well. Give
it a try!

looselytyped

unread,
Oct 24, 2010, 3:36:38 PM10/24/10
to Clojure
This is awesome! Thank you. After installing auto-complete and
following the instructions on your github page, works like a charm.

Brilliant work.

Regards,

Raju

Preecha P

unread,
Oct 25, 2010, 4:42:33 AM10/25/10
to Clojure
Excellent, I still wonder why hook doesn't work but your solution work
perfectly here, thanks.

Andreas Liljeqvist

unread,
Jun 8, 2011, 6:25:26 PM6/8/11
to clo...@googlegroups.com
This is great stuff for sure!

I have a problem though:
If I press 'tab' before the doc strings show up I get a Nullpointerexception.
Any ideas?

2010/8/14 Steve Purcell <st...@sanityinc.com>
Hi all,

A while ago I hooked Slime's completion and documentation features into the popular Emacs auto-completion framework "auto-complete" (http://www.emacswiki.org/emacs/AutoComplete).

Since it may be of interest to others, I've released the completion plugin on github: http://github.com/purcell/ac-slime

Here's a screenshot of the plugin in action in a clojure-mode buffer, showing the (very handy) pop-up documentation:






-Steve

Andreas Liljeqvist

unread,
Jun 9, 2011, 5:39:11 PM6/9/11
to clo...@googlegroups.com
I did state my problem wrong. The error is if I tab before the menu appears.

I did some digging around..
Turns out a weird string gets passed to slime-simple-completions via ac-prefix.
Suppose it's a bug in auto-complete-mode.

#("mapcat" 0 6 (selection-face ac-slime-selection-face popup-face ac-slime-menu-face document ac-slime-documentation symbol "l")))

My first thought was to do a stringp check in ac-source-slime-simple-candidates.
But apparently that is a string, I would have guessed set...

Any proficient elispers out there?


2011/6/9 Andreas Liljeqvist <bon...@gmail.com>
Reply all
Reply to author
Forward
0 new messages