I want both autocomplete support for C++ keywords and C++ standard headers. In other words, I want
- A keyword like
whileto be autocompleted.
- An expression like
#include <iostream>to be autocompleted as well.
To achieve this, I have put the following code into my
(require 'auto-complete) (require 'auto-complete-config) (ac-config-default) ;; Function which initializes auto-complete-c-headers and gets called for ;; c/c++ hooks (defun my:ac-c-header-init () (add-to-list 'ac-sources 'ac-source-c-headers) ;; List of directories where c/c++ headers are located. This list ;; may change from machine to machine. Type the following command ;; in a terminal to see your list: ;; ;; >> gcc -xc++ -E -v - ;; ;; and add whatever paths come after '#include <...> search starts here:'. ;; (setq achead:include-directories (append '("/usr/include/c++/5" "/usr/include/x86_64-linux-gnu/c++/5" "/usr/include/c++/5/backward" "/usr/lib/gcc/x86_64-linux-gnu/5/include" "/usr/local/include" "/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed" "/usr/include/x86_64-linux-gnu") achead:include-directories))) ;; Call this function from c/c++ hooks (add-hook 'c++-mode-hook 'my:ac-c-header-init) (add-hook 'c-mode-hook 'my:ac-c-header-init)
The problem is that with this, autocompletes fails completely: keywords and
includes. If I comment out
ac-c-header-init function, C++ keywords are autocompleted, but not
What is wrong with my approach? I use Ubuntu 16.04, emacs24 and g++.