2

According to this:

The built-in completion logic in CIDER relies on the library clojure-complete, so you'll have to have it your classpath for completion to work. If you're connecting to an nREPL server started from lein (e.g. you invoked M-x cider-jack-in) - there's nothing for you to do.

So -- I'm using an nREPL jack in with Emacs 24.3, so I would guess that there is "nothing for me to do." However, I am not getting any autocompletion in my Clojure source files.

I uninstalled and reinstalled Cider via Elpa to be safe. Apparently it is not necessary to manually install any other autocompletion packages from what I've read, but I must admit that getting autocompletion to work seems to be quite a task, can anyone point out what I'm missing?

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • Did you check if your auto-complete mode is on? M-x auto-complete-mode. If yes, then try M-x auto-complete to see if you get any pop=up help. – grdvnl Apr 23 '14 at 02:41
  • 1
    @GuruDevanla `auto-complete` mode is something different than `company-mode` which is what Cider uses, I believer. So I don't think it would make sense to combine the two. Maybe someone else will confirm. But also `company-mode` is not an available mode when I try it, yet it is also supposedly not something you need to manually installed, so my confusion on this continues. – johnbakers Apr 23 '14 at 02:45
  • I suggested since, I usually turn it on whenever I need to use auto-complete for Clojure+Cider. It has never worked for me without that. – grdvnl Apr 23 '14 at 03:04
  • 1
    `completion` is not the same as `auto-completion`... If you get completion suggestion when pressing `TAB` everything is working for you. If you want inline completion suggestions you'll have to install `company-mode` and enable its `company-capf` completion backend. – Bozhidar Batsov Apr 23 '14 at 07:11

3 Answers3

1

Here's my old config. I haven't been using Clojure for a while, but I've checked that it still works:

(require 'ac-nrepl)
(defun clojure-auto-complete ()
  (interactive)
  (let ((ac-sources
         `(ac-source-nrepl-ns
           ac-source-nrepl-vars
           ac-source-nrepl-ns-classes
           ac-source-nrepl-all-classes
           ac-source-nrepl-java-methods
           ac-source-nrepl-static-methods
           ,@ac-sources)))
    (auto-complete)))

(defun my-clojure-hook ()
  (auto-complete-mode 1)
  (define-key clojure-mode-map
      (kbd "β") 'clojure-auto-complete))

(add-hook 'clojure-mode-hook 'my-clojure-hook)

I'm pretty sure that I went for the separate function instead of modifying ac-sources for performance reasons (I have ac-delay at 0.4).

abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • Yup, after installing `ac-nrepl` this did it. I'm not sure if this what the `company-mode` does natively with `cider` but at least I have completion working ow. – johnbakers Apr 23 '14 at 09:14
  • actually, in this piece of code, auto-complete-mode is getting turned on too. – grdvnl Apr 23 '14 at 16:16
1

Confirmation: abo-abo answer of Apr 23 at 6:57 works.

Just change "ac-nrepl" into "ac-cider" of course.

(GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.9) of 2014-06-06 on brownie, modified by Debian)

user1614113
  • 85
  • 2
  • 9
1
(require 'auto-complete-config)
(require 'clojure-mode)
(require 'cider-mode)
(require 'ac-cider)

(ac-config-default)
;(add-hook 'cider-repl-mode-hook 'ac-cider-setup)                                                                                                                                             
(add-hook 'cider-mode-hook 'ac-cider-setup)
(eval-after-load "auto-complete"
  '(add-to-list 'ac-modes 'cider-repl-mode))

(add-hook 'clojure-mode-hook 'paredit-mode)
;(add-hook 'clojurescript-mode-hook 'paredit-mode)                                                                                                                                            
(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)
(setq cider-repl-pop-to-buffer-on-connect nil)

(require 'highlight-parentheses)
(add-hook 'clojure-mode-hook
          (lambda ()
            (highlight-parentheses-mode t)))

(defun set-auto-complete-as-completion-at-point-function ()
  (setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
;(add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                                          
(add-hook 'cider-mode-hook 'set-auto-complete-as-completion-at-point-function)
(eval-after-load "cider"
  '(define-key cider-mode-map (kbd "C-c C-d") 'ac-cider-popup-doc))

My packages are:

ac-cider
auto-complete
auto-indent
cider
clojure-mode
highlight-parentheses
parendit
popup
rainbow-delimiters

I do not want to use auto-completion for repl and script so I commented them.

You may not need them all but they are all useful. If you do not want to change the init.el file, you would better go with all packages listed.

Once you're done, make a project with Lein, then add

:plugins [[cider/cider-nrepl "0.8.2"]]

to project.clj file.

Now, it is almost done. Open a sourcefile with Emacs, then run

M-x cider-jack-in

Then you must be able to use auto-completion feature for code!

ghchoi
  • 4,812
  • 4
  • 30
  • 53