tags:

views:

201

answers:

2

I need CEDET for eassist (eassist-list-methods is quite handy). In eassist.el there's the line

(require 'semantic)

which fails if CEDET isn't loaded. The thing is that I don't need CEDET all the time and it takes a long time to load so I want to defer loading it until I call eassist-list-methods.

Is there a way to run

(load "cedet")

when semantic (or something else that is provided by CEDET) is required?

I'm looking for a simple solution that doesn't change eassist.el.

+3  A: 

Genehack is probably right; I'm being too literal in answering the question. The best way to handle something like this is to figure out which function(s) are required by external code, and add autoloads for them.

But if autoload won't work in your case, the normal way to do something when a file is loaded is to do

(eval-after-load "semantic" '(load "cedet"))

But I just noticed that you say that semantic.el fails to load if CEDET hasn't been loaded first. As implied by the name, eval-after-load runs the code after the specified file is loaded.

You can try finding a different file to trigger loading, instead of using semantic.el. (Perhaps some other file that semantic.el requires.)

If necessary, you could hook into require:

(defadvice require (before CEDET-require activate)
  (if (eq 'semantic (ad-get-arg 0))
      (load "cedet")))

Although (load "cedet") should probably be (require 'cedet), or you'll wind up reloading it every time. (I'm not sure if CEDET has a (provide 'cedet), so I didn't do it that way in my example.)

Note that putting advice on require will not do anything if semantic has already been loaded, so you may need to check (featurep 'semantic) first and load cedet.el immediately if necessary.

cjm
Hooking into require does work. I had to remove the apostrophe before CEDET-require. The problem is that even though eassist-list-methods loads, it has nothing to display. I have to revert the buffer so all the Semantic parsing stuff kicks in. That wasn't really the idea, though. Too complicated. I guess I'll just stick with loading CEDET when I start Emacs. That doesn't happen very often anyway. Well, now I know more about defadvice ;).
Eisen
+1  A: 

Assuming you have all the CEDET stuff in your load-path something like:

(autoload 'eassist-list-methods "cedet" nil t)

in your .emacs.d/init.el (or other init file) should do the trick.

genehack
You don't normally use the ".el" extension with `autoload` or `load`, so I've taken the liberty of removing it.
cjm
Ah, right, thanks -- silly copy-n-paste from the 'load cedet.el' in the question... 8^)
genehack
Wouldn't this cause problems if `eassist-list-methods` wasn't defined in cedet.el?
seth
I already tried that. The problem is that I also have (autoload 'eassist-list-methods "eassist" nil t) in my .emacs and it doesn't work with two autoloads for the same function.
Eisen
seth, for me, eassist is a separate library. I read on EmacsWiki that it's part of CEDET now. I haven't upgraded CEDET in a while because of other dependencies, though.
Eisen
I don't think it's a requirement that `eassist-list-methods` be defun'd in 'cedet.el', but if loading `cedet.el' doesn't also load the file that defines that function, yeah, this isn't going to work. I don't use CEDET; I was assuming that since the eassist stuff came with CEDET, that loading it all up would do the trick.
genehack
Okay, @Eisen, how about if instead you make a file -- call it 'load-eassist-and-cedet.el' -- put `(load "cedet.el")` and `(load eassist.el)` in there, then have the autoload be `(autolad 'eassist-list-methods "load-eassist-and-cedet" nil t)`.Yes, that's incredibly ugly.
genehack