Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-Complete with Emacs 24 doesn't work with Java, C or C++ modes

I installed auto-complete using the marmalade repo. Everything installed correctly and after moving stuff around I managed to start up and run auto-correct without any errors with the following code in my init.el:

;; auto-complete
(add-to-list 'load-path "~/.emacs.d/elpa/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete/dict")
(ac-config-default)

Now I can use auto-complete with no hick-ups with Emacs Lisp but whenever I use any other mode, like, Java, C, or C++ it doesn't work at all.

I have yasnippet installed too (it works perfectly), not sure if that might have anything to do with it. Here's the relevant code in my init.el:

;;yasnippet
(add-to-list 'load-path
              "~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)

I am in the process of learning Emacs and currently I'm still a noob. I've been looking all over the documentation and SO but haven't found anything. I'd really appreciate any help whatsoever on this.

like image 411
Nico Avatar asked Feb 03 '13 20:02

Nico


1 Answers

You may need to add completion sources. Here's what's in my config:

(set-default 'ac-sources
             '(ac-source-abbrev
               ac-source-dictionary
               ac-source-yasnippet
               ac-source-words-in-buffer
               ac-source-words-in-same-mode-buffers
               ac-source-semantic))

Update: ac-config-default should cover this, but if autocomplete isn't activating for those modes, try putting the following in your init.el:

(dolist (m '(c-mode c++-mode java-mode))
  (add-to-list 'ac-modes m))

(global-auto-complete-mode t)

Update2: I've posted a gist that adapts your init.el to pull autocomplete using package-install.

I can't tell what version of auto-complete you were referencing, but the latest is working fine for me.

C-mode with working auto-completions

like image 65
Chris Barrett Avatar answered Sep 29 '22 17:09

Chris Barrett