views:

173

answers:

1

Hi,

I'm using Emacs with CEDET and auto complete for code completion. Originally I set up CEDET so it loads at Emacs start up every time.

However, this took quite a long time, so i thought it would be clever to load it just if needed, i.e. - in my case - when entering C++-Mode.

So I moved the original function into a lambda that is called when entering C++-mode:

; cscope for c(++) programming (finding symbols, etc.)
(require 'xcscope)

; C++ stuff
(add-hook 'c++-mode-hook
      (lambda ()
        (load-file "/usr/share/emacs/site-lisp/cedet-common/cedet.el")
        (global-ede-mode 1) ; enable project management system
        (semantic-load-enable-code-helpers) ; enable prototype help and smart completion
        (require 'auto-complete-config)
        (add-to-list 'ac-dictionary-directories "~/elisp/ac-dict")
        (add-to-list 'ac-sources 'ac-source-semantic)
        (local-set-key (kbd "C-:") 'semantic-ia-complete-symbol-menu) ; set shortcut for auto completion.
        (local-set-key (kbd "C-.") 'ac-complete-semantic)
        (ac-config-default)
        )
      )

There are no errors, but I have the following problem: When Emacs enters C++-mode for the first time, code completion does not work properly. But if Emacs enters C++-mode the second time, everything works just fine.

Does anybody know what I'm doing wrong?

+3  A: 

CEDET initialization sets up C and C++ mode hooks of it's own. If it installs it's hook while it is running the same hook, then it won't run, and your first buffer won't have initialized.

What you could do is load CEDET at startup, but then init the code helpers in the C mode hook. That way C++ mode will initialize with mode-local, but the extra functions will be installed after the hook runs, so that may work. I hadn't tried it myself.

I think EDE mode isn't slow, so it is probably ok to do that at init time too.

Eric
Thank you for the answer. So CEDET replaces the original C++-mode-hook, right?
phimuemue