3
votes

I've been working on making auto-complete-mode work with Semantic nicely but know I'm completely stuck. I've succesfully had semantic autocomplete through semantic-ia-complete-symbol (though for some reason it can't complete malloc(), which is weird).

Some .emacs snippets:

(add-to-list 'ac-dictionary-directories "~/emacs-src/auto-complete-1.3.1/")
(ac-config-default)
(ac-set-trigger-key "TAB")

(add-to-list 'ac-sources 'ac-source-semantic) 
(add-to-list 'ac-sources 'ac-source-gtags)



(add-hook 'c-mode-hook
          (defun my-c-mode-hook ()
            (auto-complete-mode)
            (setq ac-sources '(ac-source-semantic))
            (ac-complete-semantic)))

How do I make auto-complete-mode work together with Semantic?

2

2 Answers

5
votes

If I understand you correctly, Semantic is working and you're only struggling with setting up auto-complete. For doing the latter, simply start with

(require 'auto-complete-config)
(setq-default ac-sources '(ac-source-semantic-raw))

Note that you have to use "setq-default" for setting ac-sources. You should then be able to do

M-x auto-complete-mode

in a C/C++ buffer and auto-complete should query Semantic for completions.

1
votes

Try debugging the auto-completion failure by:

M-x semantic-analyze-debug-assist RET

and see what it says. Look at \include\stdlib.h to see what the parser thinks of the file. If while there you do:

M-x bovinate RET

then you can search to see if malloc is there. If not, there is probably a parsing bug, or some miscellaneous #define that isn't set up correctly. Using the above you can usually find at a header file to see where things start to break down.