company-c-headers icon indicating copy to clipboard operation
company-c-headers copied to clipboard

Auto-completion for C/C++ headers using Company

#+TITLE: Auto-completion for C/C++ headers using Company #+AUTHOR: Alastair Rankine #+EMAIL: [email protected]

#+ATTR_HTML: :style float: right [[https://travis-ci.org/randomphrase/company-c-headers][https://travis-ci.org/randomphrase/company-c-headers.svg?branch=master]] [[https://coveralls.io/r/randomphrase/company-c-headers][https://img.shields.io/coveralls/randomphrase/company-c-headers.svg]] [[https://melpa.org/#/company-c-headers][https://melpa.org/packages/company-c-headers-badge.svg]]

This library enables the completion of C/C++ header file names using [[https://company-mode.github.io][Company mode]] for Emacs.

#+CAPTION: Screenshot of company-c-headers in action [[screenshot.png]]

When you type an ~#include~ declaration within a supported major mode (currently ~c-mode~, ~c++-mode~ and ~objc-mode~), company-c-headers will search for completion candidates within the defined include paths. There are "system" and "user" include paths, for @@html:@@#include <...>@@html:@@ and @@html:@@#include "..."@@html:@@ declarations, respectively.

During completion, the path to the current candidate can be seen in the minibuffer, such as in the screenshot above. Also during completion, you can use @@html:@@C-w@@html:@@ to temporarily display the currently-selected header file.

This library is inspired by [[https://github.com/mooz/auto-complete-c-headers][auto-complete-c-headers]].

** Installation

The best way to install this package is via [[https://melpa.org/#/][MELPA]].

** Setup

With the company-c-headers library added to the ~load-path~, all you need to do to initialize it is:

#+BEGIN_SRC emacs-lisp (add-to-list 'company-backends 'company-c-headers) #+END_SRC

Typically you would want to customize the search paths, which you can do using @@html:@@M-x customize-group@@html:@@, @@html:@@company-c-headers@@html:@@.

Alternatively, you can bind the =company-c-headers-path-system= and =company-c-headers-path-user= variables to functions which return the corresponding paths. For example, if you are using [[http://cedet.sourceforge.net/ede.shtml][EDE]], you can use the following:

#+BEGIN_SRC emacs-lisp (defun ede-object-system-include-path () "Return the system include path for the current buffer." (when ede-object (ede-system-include-path ede-object)))

(setq company-c-headers-path-system 'ede-object-system-include-path) #+END_SRC