Search code examples
c++emacsautocompletecedet

Setting up autocomplete to work with semantic


I have a problem with auto-complete package in Emacs. Currently I have up and running cedet with proper autocompletion, but auto-complete package has some weird behaviour. It doesn't use semantic's (senator's?) database until I explicitly visit include file and make "C-u M-x bovinate". Then I can return to the source file and auto-complete's completion list will look exactly as the semantic's one.

Another point is if I edit my source file, for example, in c++-mode and try to "bovinate" header in c-mode, auto-complete won't get any additional points in it's completion list.

Any ideas how to get auto-complete work automatically?

My .emacs file is (Major parts of it were taken from Alex Ott's article)

(load "~/.emacs.d/cedet/cedet-devel-load.el")
(add-to-list 'semantic-default-submodes 'global-semanticdb-minor-mode)
(add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-mru-bookmark-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-local-symbol-highlight-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-scheduler-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-decoration-mode)

(require 'semantic/ia)
(semantic-mode 1)

(require 'semantic/bovine/gcc)

(semantic-add-system-include "/usr/include/mpi/" 'c++-mode)

;; ;; Imenu integration
(defun my-semantic-hook ()
  (imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)

;; Class suggest improvement
(defun my-c-mode-cedet-hook ()
 (local-set-key "." 'semantic-complete-self-insert)
 (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

;;;; Semantic and auto-config integration
(require 'auto-complete-config)
(ac-config-default)
(add-to-list 'ac-dictionary-directories "/home/zvord/.emacs.d/ac-dict")
(define-key ac-mode-map [(meta return)] 'auto-complete)

(defun my-cedet-hook ()
  (add-to-list 'ac-sources 'ac-source-semantic))
(add-hook 'c-mode-common-hook 'my-cedet-hook)

From all I've read this should be enough to get auto-complete work, but it isn't.


Solution

  • Try to change:

    (defun my-cedet-hook () (add-to-list 'ac-sources 'ac-source-semantic))

    into:

    (defun my-cedet-hook () (add-to-list 'ac-sources 'ac-source-semantic-raw))

    It should work.