Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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)

(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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top