1

I want to load emacs init files faster, so I use the 'eval-after-load.
For example, when I load clojure file, I just put

(eval-after-load 'clojure-mode
    'do-something)

It works.
But when I try

(eval-after-load 'emacs-lisp-mode
    'do-something)

It doesn't work. I wonder to know the right major mode name of emacs-lisp.
Thanks.

Alex Miller
  • 69,183
  • 25
  • 122
  • 167
  • 1
    When Emacs starts it automatically opens a *scratch* buffer which is in lisp-interaction-mode. This mode is defined in lisp-mode.el. Which means that lisp-mode is *always* loaded when you start emacs, so `do-something` will run whether or not you wrap it in `eval-after-load`. – Tyler Oct 01 '13 at 19:55

3 Answers3

4

Please read the documentation of eval-after-load:

eval-after-load LIBRARY FORM

This function arranges to evaluate form at the end of loading the file LIBRARY, each time LIBRARY is loaded. If LIBRARY is already loaded, it evaluates form right away. Don't forget to quote form!

[…] LIBRARY can also be a feature (i.e., a symbol), in which case form is evaluated at the end of any file where (provide LIBRARY) is called.

You have to pass the name of the file or library, which defines the major mode, as argument.

While some modes are defined in files of the same name (e.g. clojure-mode in clojure-mode.el), many files a different name, especially if the actually define multiple major modes.

emacs-lisp-mode is defined in lisp-mode.el, along with some other modes for Emacs Lisp editing (e.g. lisp-mode as a generic Lisp language mode, or lisp-interaction-mode for *scratch* buffers).

Hence, use (eval-after-load 'lisp-mode …)

Also, you have to give a single sexp as second argument, so you'll likely want to use (eval-after-load 'lisp-mode '(do-something)), to call the function do-something.

If you are using a snapshot build of Emacs, use with-eval-after-load, i.e. (with-eval-after-load 'lisp-mode (do-something)). It allows for more than a single form, and doesn't require quoting.

Community
  • 1
  • 1
2

Just eval with M-: the variable major-mode. It actually is emacs-lisp-mode. Note that *scratch* is actually in lisp-interaction-mode.

As to what you're trying to do, use (eval-after-load "lisp-mode").

abo-abo
  • 20,038
  • 3
  • 50
  • 71
1

As explained by @lunaryom, the arg passed to eval-after-load is not a function name but a feature name, which is basically a file name. So you need to find the name of the file from which the function is loaded. We could provide a feature like eval-after-defun, and indeed it might be a good idea to do so. If you'd like such a thing, ask for it via M-x report-emacs-bug.

Stefan
  • 27,908
  • 4
  • 53
  • 82