Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Using and initializing CEDET

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?

like image 885
phimuemue Avatar asked Jun 19 '10 15:06

phimuemue


1 Answers

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.

like image 194
Eric Avatar answered Sep 19 '22 14:09

Eric