In Emacs, company-mode (short for "complete anything") is a framework for performing completion in buffers. It's an alternative to the popular auto-complete-mode . company-mode supports extension via backends which provide the framework with lists of possible completions in various contexts. So, for example, there's a backend th(at provides completion support for Emacs lisp and one that does the same for Python. Backends can use very different technologies as long as they conform to the backend interface specified by the mode.

I recently decided to write a company-mode backend for ycmd, a completion server for languages including C/C++/Objective-C and Python. All in all it was a relatively pain-free experience, but the process isn't as well documented as I would have liked. So I want to use this series to describe how it's done with the hope of making it easier for others and of helping me remember how to do it in the future.

I won't be covering all of the details of company-mode backends (partially because I don't know them all), but this series should tell you what you need to know to create your own fully-armed and operational backend. In this article we'll define the simplest possible backend in order to familiarize you with the concepts and infrastructure involved. In the next article we'll add some sophistication to that backend to improve the user experience.

The simplest possible backend For our example we need to define a source of completion candidates. Ultimately, any completion source is just a sequence of strings that meet some criteria. Examples might include: A list of English words starting with some prefix

Methods for a particular object in Java

Modules available for import in Python program company-mode doesn't care about the nature of these strings. It just takes them and makes it easy for the user to select from the available options. In this case, we'll just define a fixed list of strings: ( defconst sample-completions ' ( "alan" "john" "ada" "don" )) That's it. Completion sources don't need to (though they generally will) be more complex than that.