tags:

views:

116

answers:

1

Is there a difference between setting things for a mode using eval-after-load and using the mode hook?

I've seen some code where define-key is used inside a major mode hook, and some other code where define-key is used in eval-after-load form.

+6  A: 

Code wrapped in eval-after-load will be executed only once, so it is typically used to perform one-time setup such as setting default global values and behaviour. An example might be setting up a default keymap for a particular mode. In eval-after-load code, there's no notion of the "current buffer".

Mode hooks execute once for every buffer in which the mode is enabled, so they're used for per-buffer configuration. Mode hooks are therefore run later than eval-after-load code; this lets them take actions based upon such information as whether other modes are enabled in the current buffer.

sanityinc