Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An emacs plugin to complete C and C++ code using libclang
Emacs Lisp C
Branch: master

Merge pull request #69 from maxc01/master

fix error: unknown type name 'FILE'
latest commit 5d9c5cabbb
@Golevka authored


emacs-clang-complete-async is an emacs extension to complete C and C++ code, it uses libclang to parse the source code on the fly and provides completion candidates to auto-complete (

This extension is not implemented in pure elisp, it is made up of a client part (auto-complete-clang-async.el, written in elisp) and a server part (clang-complete binary, written in C), they work cooperately in asynchonous client-server fashion.

Experimental Feature - On the fly syntax checking

An experimental feature is added to this branch — running ac-clang-syntax-check to highlight errornous lines in your souce code.


Compile the server part (clang-complete binary) first, by executing make. The build process uses llvm-config to determine the location of libclang and the appropriate compile flags to use. If llvm-config is not in your path or has a different name, you can pass make an LLVM_CONFIG argument, e.g. make LLVM_CONFIG=llvm-config-3.4.

Copy auto-complete-clang-async.el and the previously compiled clang-complete executable to ~/.emacs.d/, and add the following code to your .emacs file.

(require 'auto-complete-clang-async)

(defun ac-cc-mode-setup ()
  (setq ac-clang-complete-executable "~/.emacs.d/clang-complete")
  (setq ac-sources '(ac-source-clang-async))

(defun my-ac-config ()
  (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
  (add-hook 'auto-complete-mode-hook 'ac-common-setup)
  (global-auto-complete-mode t))


Now emacs-clang-complete-async will show completion candidates automatically when you type as usual in C or C++ mode.


This extension fades in emacs C/C++ mode and provides candidates automatically while you typing code, if you want to add parameters to clang (libclang, actually), such as -Ipath, just call ac-clang-set-cflags interactively or set the value of ac-clang-flags in .emacs or .dir-locals.el, maybe you need an explicit call to ac-clang-update-cmdlineargs to make changes to cflags take effect, which is a niggling part of it T T


Most code of auto-complete-clang-async.el is taken from brainjcj’s auto-complete-clang.el, The only difference between this one and bj’s ac-clang-complete is: This one interacts with a process geared with libclang to retrieve completion candidates instead of calling clang process, which is way slower, and the asynchonous nature of our C-S based working model won’t block the editor while parsing source code and resolving completion candidates, which provides a “smooth” coding experience.

Something went wrong with that request. Please try again.