My computer system and set up are

OS: Arch Linux 64bit
emacs version: 24.4
alias emacs='emacsclient -t -s server --alternate-editor='


auto complete is working with yasnippet occasionally now but not as expected. I changed the line

(add-to-list 'achead:include-directories

If I type #include <io and hit tab, I get back #include <#include <iostream>. Therefore, I then tried just typing <io and tab which produces <#include <iostream>. If I type ios and hit type, the desired result is achieved. I then tested this with float.h. No iteration works.

I then tried re-testing io and tab. This doesn't work 100% of the time. 50% of the time I get #include <iostream> and the other 50% nothing happens. Needless to say, I have no idea what is going on with this package or feature.

I am trying to get auto complete to work with C/C++ headers; however, I have been unable to do so. I executed the following command in the terminal to locate the C/C++ headers:

[dustin@dustin ~]$ g++ -print-prog-name=cc1plus -v
Using built-in specs.

but using /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/cc1plus does not produce the desired outcome. I have also ran a search looking for float.h just to determine locations as well and came up with

[dustin@dustin ~]$ sudo find / -name float.h
[sudo] password for dustin: 

So I also tried /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include. I am not to sure about /usr/include/c++/4.9.2/tr1 though.

Below is the relevant information in my .emacs. All packages were downloaded and install from melpa are up-to-date. If I run 'emacs' --debug-init, there are no error messages. The ' ' around emacs is so that emacs will open without options for debugging only.

;; Start server and set directory
(setq server-socket-dir (format "/tmp/emacs1000"))

;; Package list M-x package-list-packages
(require 'package)
(add-to-list 'package-archives 
         '("melpa" . "http://melpa.milkbox.net/packages/"))

;; Package initialize

;; C/C++ configuration
(require 'cc-mode)

;; auto complete for C/C++
(require 'auto-complete)
;; default config for auto-complete
(require 'auto-complete-config)

;; start yasnippets
(require 'yasnippet)
(yas-global-mode 1)

;; auto complete C++-headers
(defun my:ac-c-header-init ()
  (require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-header)
  (add-to-list 'achead:include-directories

;; call ac-c-headers from c/c++ hooks
(add-hook 'c++-mode-hook 'my:ac-c-header-init)
(add-hook 'c-mode-hook 'my:ac-c-header-init)
  • Seems like you are new to Emacs. If so, my C/C++ guide may help you get a good development environment with IDE like features like navigate around large project with 30k files.
    – Tu Do
    Apr 15 '15 at 16:38

You can use hippie-expand and avoid all this key binding conflict headache altogether:

  (global-set-key (kbd "M-/") 'hippie-expand) ;; replace dabbrev-expand
  (setq hippie-expand-try-functions-list
          ;; Try to expand yasnippet
          ;; Try to expand word "dynamically", searching the current buffer.
          ;; Try to expand word "dynamically", searching all other buffers.
          ;; Try to expand word "dynamically", searching the kill ring.
          ;; Try to complete text as a file name, as many characters as unique.
          ;; Try to complete text as a file name.
          ;; Try to expand word before point according to all abbrev tables.
          ;; Try to complete the current line to an entire line in the buffer.
          ;; Try to complete the current line to an entire line in the buffer.
          ;; Try to complete as an Emacs Lisp symbol, as many characters as
          ;; unique.
          ;; Try to complete word as an Emacs Lisp symbol.

Now, whenever you want to expand a snippet, press M-/ and want to complete, press <tab>.

  • It only expands to float not float.h. Is that intended?
    – dustin
    Apr 15 '15 at 16:59
  • @dustin I added the function for expanding yasnippet snippets yas-hippie-try-expand. Sorry about that. It should expand snippets properly now. As for completing headers, I'm not sure about it. I only use company-c-header. As for hippie-expand, it only expands from the candidates generated by functions in the list, so it won't complete your header files.
    – Tu Do
    Apr 15 '15 at 17:27

I found on SO the following answer that works by abdimuna:

First locate C/C++ headers on your computer by running the following command.

gcc -xc++ -E -v - 

On my ArchLinux they are located here


Then the complete C/C++ auto-completion which works for me is this.

;; C++ auto completion mode
(require 'auto-complete)
(require 'auto-complete-config)
;a function which initializes auto-complete-c-headers and get called for c/c++ hooks
(defun my:acc-c-header-init ()
  (require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '" /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/../../../../include/c++/4.9.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.