Reputation: 1530
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?
Upvotes: 1
Views: 926
Reputation: 53694
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
.
Upvotes: 3
Reputation: 19721
You could do it like this:
(add-hook 'c-mode-common-hook (lambda ()
(load-file "~/.emacs.d/plugins/cedet/common/cedet.el")
;; any code dependent on having this file loaded
))
If loading the file (or doing the other commands) several times is a problem, you should of course first check whether this file was already loaded (either test for something defined in cedet.el, or maintain an is-loaded flag yourself).
Edit: Such a flag might look like this:
(setq need-to-load-cedet-p t)
(add-hook 'c-mode-common-hook (lambda ()
(if need-to-load-cedet-p
(progn (load-file "~/.emacs.d/plugins/cedet/common/cedet.el")
(setq need-to-load-cedet-p nil))
;; code that should only be executed once after cedet is loaded goes here
)
;; code that should be executed every time a new buffer is opened goes here
))
Upvotes: 0