Emacs auto complete

I've just discovered auto complete for Emacs to allow as you type suggestions a la Visual Studio. Download auto-complete.el from here and add it to your site-lisp directory. Add something like the following to your .emacs file to enable a drop down list of completions:
(require 'auto-complete)
(global-auto-complete-mode t)
(setq ac-auto-start 2)
(setq-default ac-sources '(ac-source-abbrev ac-source-words-in-all-buffer))
(setq ac-candidate-menu-height 4)
(setq ac-candidate-max 4)
(push 'text-mode ac-modes)
(push 'html-mode ac-modes)

  • global-auto-complete-mode sets auto-complete-mode to be on by default.

  • ac-auto-start determines how many characters you want to type before the auto complete is displayed. You can set this to nil if you want auto complete to be activated using a command.

  • ac-sources indicates where you want auto complete to look when deciding what to be included in the possible list of completions. There are many options here including etags and yasnippet. Have a look at the auto-complete.el for more options.

  • ac-candidate-menu-height ac-candidate-max sets how large the auto complete list displayed on screen is. The default value is 10 which is a bit excessive. I set ac-candidate-max to the same value as the behaviour seems a bit glitchy otherwise.

  • ac-modes is the list of modes that auto complete is enabled for. I've added a couple of my favourite modes that aren't in the default list.


Props to Matsuyama Tomohiro for this excellent addition to Emacs.

Comments

Popular Posts