10

I'm running GNU Emacs 24.4.1 on a clean install of Debian 8.1. I've installed auto-complete using the package manager. It is installed and if I type M-x auto-complete-mode I get a working auto-complete. I would like to have it enabled by default. I added the following to my .emacs file:

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

However, that resulted in the error:

Warning (initialization): An error occurred while loading `/home/greg/.emacs':

File error: Cannot open load file, no such file or directory, auto-complete

So, I tried adding to the load path with a bunch of different attempts like:

(add-to-list 'load-path' ("~/.emacs.d/elpa/")

OR

(add-to-list 'load-path (file-name-as-directory
                     (expand-file-name "~/.emacs.d/elpa/auto-complete-20151211.227/auto-complete"))
                     )

But nothing seems to do the trick. If I use C-h v load-path when I run emacs with --debug-init, I can see what I've added to the load path, but even when it looks correctly I still get the same can't load file error.

I've read other similar questions but these are all the things their answers said to try and I still can't get it to work. How do I get auto-complete to load automatically?

Gregory Arenius
  • 247
  • 2
  • 4
  • 12
  • I guess it's just a typo: `(require'autocomplete)`. – Nsukami _ Dec 21 '15 at 07:03
  • @Nsukami_ The typo was somehow made copying things over for the question. I sometime type emacs commands into the edit box out of habit...The .emacs file has the correct hyphenation. – Gregory Arenius Dec 21 '15 at 07:25
  • I have never had this issue, so I was looking at my config to see what I had that you didn't, and the only thing is `(require 'auto-complete-config)`. You can try adding that to see if it makes a difference. – elethan Dec 21 '15 at 15:05
  • @elethan It still doesn't seem to be finding auto-complete. I think it is a problem with the load-path but I'm not sure it is and I just can't seem to nail it down. Thank you for the suggestion though. – Gregory Arenius Dec 21 '15 at 19:03
  • @GregoryArenius, you also have a few typos in the line `(add-to-list 'load-path' ("~/.emacs.d/elpa/")` this should be `(add-to-list 'load-path "~/.emacs.d/elpa/")` – elethan Dec 21 '15 at 19:39

1 Answers1

11

I tried to create a minimal config that would have a working auto-complete and this is what I came up with.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)

(package-initialize)  ;load and activate packages, including auto-complete

(ac-config-default)

(global-auto-complete-mode t)

Try that out and see if it works.

Additionally, you can use:

(add-to-list 'ac-modes 'name-of-mode)

If auto-complete doesn't work by default with a given mode. E.g., (add-to-list 'ac-modes 'sql-mode). Also, see the manual for more details on configuration, etc.

elethan
  • 4,755
  • 3
  • 29
  • 56
  • This doesn't return any error messages but it also doesn't seem to make it so that auto-complete is auto-enabled. When this is in my .emacs and I open a file and type `M-x auto-complete` it tells me that auto-complete is not enabled. Which is strange because `(global-auto-complete-mode t)` should do that... – Gregory Arenius Dec 21 '15 at 19:55
  • Alright. So I played around with it some more. This will auto-load auto-complete for some files and not others. For instance if I open a new file test.py it open in Python AC mode with working auto-complete. If I open test.sql however I don't get any auto-complete. I think it has to do with what modes are in the dict directory where auto-complete is installed. If I have test.sql open however and manually start auto-complete it does work. – Gregory Arenius Dec 21 '15 at 20:04
  • I have updated my answer a bit, but as far as I know, without further configuration, `global-auto-complete-mode` will only offer completions for text that already in the buffer. If you won't better completions and completions specific to certain languages, you will have to configure things a bit more. Also, you might check out `company-mode`http://company-mode.github.io/ I have had better luck with that for auto-completion personally. – elethan Dec 21 '15 at 20:20
  • What does the (ac-config-default) line do? – Gregory Arenius Dec 22 '15 at 12:08
  • `(ac-config-default)` sets up some default auto-complete sources, and adds hooks to a few major modes. To see exactly what it does you can use `C-h f` to get help with a function, enter `ac-config-default`, and then, where it says "ac-config-default is an autoloaded Lisp function in \`auto-complete-config.el'." click/hit return on the file name `auto-complete-config.el` and it should take you directly to the source where the function is defined. This is a generally useful way to look up function info. – elethan Dec 22 '15 at 14:53