31

I just install auto-complete-mode, however everytime I start emacs I have to M-x auto-complete-mode. Is there anyway to have it loaded automatically ?

My .emacs is as follows:

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

Thanks

w00d
  • 5,416
  • 12
  • 53
  • 85
  • I think there is a solution suggested in the [Emacs Wiki](http://www.emacswiki.org/emacs/AutoComplete). Search for real-global-auto-complete-mode and see if this works for you. – alexurba Nov 11 '11 at 18:00

2 Answers2

52

I think you can do it in various ways. To enable it globally you should use

(global-auto-complete-mode t)

But it uses auto-complete-mode-maybe, which turn AC on only those listed in ac-modes. You can add them manually just like this

(add-to-list 'ac-modes 'sql-mode)

You can make your own list if you wish AC be active only for few modes

(setq ac-modes '(c++-mode sql-mode))

Or rewrite it to have AC everywhere.

(defun auto-complete-mode-maybe ()
  "No maybe for you. Only AC!"
  (auto-complete-mode 1))

edited:

Autocomplete in minibuffer is bad. I think this will be better.

(defun auto-complete-mode-maybe ()
  "No maybe for you. Only AC!"
  (unless (minibufferp (current-buffer))
    (auto-complete-mode 1)))
desudesudesu
  • 2,185
  • 1
  • 15
  • 20
  • 2
    It may be helpful to point out that you need a `(require 'auto-complete)` somewhere before `(global-auto-complete-mode t)` is executed. – William Everett Mar 18 '14 at 00:27
  • I found `(setq ac-modes '(c++-mode sql-mode))` to be the easiest way (and least ambiguous) to accomplish what I wanted. – Mike Vella Apr 15 '14 at 12:48
  • None of these options work for me on emacs 24.3.1 on Ubuntu x86. I see that the status on the modeline (`AC`) but none of the AC features work, and I know they do because I used to turn it on manually using `M-x auto-complete-mode`. What worked for me was in https://emacs.stackexchange.com/questions/18982/how-do-i-make-auto-complete-enabled-by-default – Sonny Oct 03 '17 at 13:01
  • How could I assign a key-binding for `auto-complete-mode-maybe` ? @desudesudesu – alper Aug 01 '18 at 14:17
21

I just needed this:

(require 'auto-complete)
(global-auto-complete-mode t)

added to my .emacs.d/init.el file.

I installed auto-complete with the package manager. I'm using Emacs 24.

Frank Henard
  • 3,638
  • 3
  • 28
  • 41
  • 1
    Please alert even with this setting, AC mode will not be turned on for every mode. For instance, AC mode will not work in ReST mode without rewrite ``auto-complete-mode-maybe ()`` like the accepted answer. – xxks-kkk Mar 19 '16 at 03:33
  • Should I press TAB ? @Frank Henard – alper Aug 01 '18 at 13:54