Monolune

Configuring Company Mode in Emacs

Company Mode is a useful Emacs package for autosuggestions and autocompletions. It provides drop-down suggestions as you type, and all you need to do is to select the appropriate suggestion, and that suggestion will be inserted. This increases productivity dramatically, and reduces that chance of making typing mistakes. Out of the box, Company Mode works with a huge number of modes. However, the default configuration is lacking in terms of usability (slow response, unintuitive selections, etc.). In this article, I will list the settings I use in my Emacs configuration file (~/.emacs).

The rest of this article assumes that you have already installed Company Mode, and that you have enabled it (by adding (add-hook 'after-init-hook 'global-company-mode) into your ~/.emacs).

What most of us want is instant suggestions. That is, suggestions that appear immediately after one starts typing. By default, Company Mode does not immediately show suggestions. To show suggestions without delay:

; No delay in showing suggestions.
(setq company-idle-delay 0)

By default, suggestions only appear after you have typed a few characters. That introduces an unacceptable delay, and wastes keystrokes. Suggestions should appear right after the first letter is entered. To achieve this:

; Show suggestions after entering one character.
(setq company-minimum-prefix-length 1)

When the list of suggestions is shown, and you go through the list of suggestions and reach the end of the list, the end of the list of suggestions does not wrap around to the top of the list again. This is a minor inconvenience that can be solved:

(setq company-selection-wrap-around t)

Instead of using Meta + n and Meta + p to navigate the list of suggestions, using the tab key may be more intuitive. The tab method may be more familiar to those who use other programs that use the tab key for autocompletions. To use Tab to cycle through the suggestions list that pops up:

; Use tab key to cycle through suggestions.
; ('tng' means 'tab and go')
(company-tng-configure-default)

The settings above are the only ones I have used so far. They have served quite well for the purpose of reducing typing in Emacs. Overall, I am happy with Company Mode and the reliable autosuggestions and autocompletions that it provides.