0

I installed the auto-complete-c-headers package and added the following in my Emacs configuration file

; start auto-complete with emacs
(require 'auto-complete)
; do default config for auto-complete
(require 'auto-complete-config)
(ac-config-default)
; let's define a function which initializes auto-complete-c-headers and gets called for c/c++ hooks
(defun my:ac-c-header-init ()
(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '"/usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
"))
; now let's call this funcion from c/c++ hooks
(add-hook 'c++-mode-hook 'my:ac-c-header-init)
(add-hook 'c-mode-hook 'my:ac-c-header-init)

I included the directories listed by the command gcc -xc++ -E -v -.

The autocomplete works fine with C header files, but does nothing with the C++ ones.

doltes
  • 567
  • 2
  • 11

1 Answers1

0

It looks like you are incorrectly adding the C++ headers to achead:include-directories. Each header should be a separate item in the list, not the Heredoc-like syntax you're using. You are prepending just one string with embedded newlines, which of course does not exist on disk. Instead of:

(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '"/usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
"))

Try this:

(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (setq achead:include-directories
   (append '("/usr/include/c++/4.8"
             "/usr/include/x86_64-linux-gnu/c++/4.8"
             "/usr/include/c++/4.8/backward"
             "/usr/lib/gcc/x86_64-linux-gnu/4.8/include"
             "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed"
             "/usr/include/x86_64-linux-gnu")
             achead:include-directories)))

The C header files probably work because by default, the package adds /usr/include and /usr/local/include to achead:include-directories.

doltes
  • 567
  • 2
  • 11
InHarmsWay
  • 1,309
  • 7
  • 8
  • What does M-: achead:include-directories show in a c-++-mode buffer? – InHarmsWay May 27 '16 at 12:47
  • ("/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu" "/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu" ...) –  May 27 '16 at 13:04
  • Looks OK. What doesn't work? Pressing in a #include (where x is some character that is a prefix to a file name that exists in one of those directories, and | represents the cursor) completes only c headers? What does evaluating ac-sources in that buffer show? – InHarmsWay May 27 '16 at 13:38
  • Without reason the things started to work. I don't know what I did. That evaluate command may have solved the problem? –  May 27 '16 at 14:53
  • The evaluate command should have had no effect. Perhaps you were debugging in an intermediate state wherein all changes to the setup code had not yet propagated to your testing environment. Happens to me sometimes when I forget to evaluate the latest elisp code. – InHarmsWay May 27 '16 at 18:20