Search code examples
c++emacselispcedet

How to load cedet, semantic et. al only when .cxx,.h .cpp files are open


Because I use Emacs for many things these days I would like to only load cedet.el when I open a c/C++ source or header and not everytime emacs starts since it takes a significant toll on the startup time.

Right now the beginning of my init file looks like this:

  (load-file "~/.emacs.d/plugins/cedet/common/cedet.el")

(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)

(setq senator-minor-mode-name "SN")
(setq semantic-imenu-auto-rebuild-directory-indexes nil)
(global-srecode-minor-mode 1)
(global-semantic-mru-bookmark-mode 1)

And it keeps going. Is there a way to do this?


Solution

  • my emacs startup improved dramatically after i learned to use eval-after-load and autoload.

    if you have a mode you only want loaded when you open a file of the type, add something like this to your .emacs (assuming foo-mode is defined in foo-mode.el on your load path):

    (autoload 'foo-mode "foo-mode" nil t)
    (add-to-list 'auto-mode-alist '("\\.foo\\'" . foo-mode))
    

    if you have some helper libraries which you only want loaded after you load a "main" library, add something like this to your .emacs (assuming bar-mode is a secondary mode which enhances foo-mode):

    (eval-after-load "foo-mode"
      '(progn
        (require 'bar-mode)
        ;; ... do other bar-mode setup here ...
        ))
    

    so, in your case, you probably want to setup cedet using eval-after-load c++-mode.