yuk
yuk

Reputation: 221

How to reload an emacs major mode?

I have a buffer in some major-mode, and in another buffer the mode file itself (*.el). After I edit the *.el file I want to see the changes reflected in the first buffer, without restarting emacs. I tried to run the -mode function but it didn't change the buffer. Thanks

Upvotes: 22

Views: 9446

Answers (3)

Gareth Rees
Gareth Rees

Reputation: 65854

If your mode provides a feature (as it should!) using (provide 'foo-mode) then you can

M-x unload-feature RET foo-mode RET

and then load the mode again as normal (using foo-mode if you have an appropriate autoload, or using load-library or load-file otherwise).

Upvotes: 35

Trey Jackson
Trey Jackson

Reputation: 74480

M-x load-file your-mode.el

or

M-x eval-buffer

Then toggle the behavior on and off in the buffer, presumably by doing

M-x your-mode
M-x your-mode

Or, if your mode recognizes the prefix argument

C-u 1 M-x your-mode

Note: When you're loading a file, defvar doesn't override existing values, so if you change the values in the call to defvar, you'll need to evaluate those specifically, either by doing C-M-x when your cursor is in the devfar expression, or using M-x : and typing in the expression. See this page for documentation on evaluating lisp in Emacs.

Upvotes: 16

Thomas
Thomas

Reputation: 17422

When you edit the source of a mode, you have to make sure that you evaluate the functions you change -- saving them to file alone will not be enough, because internally Emacs will still use the old code.

For instance, you could jump to the end of the function definition you work on with M-C-e and evaluate the function with C-x C-e. From that point on, Emacs will then use the current definition.

This works for mode definition, too, but often times invoking a mode with M-x mode-name is implemented as a toggle: you call it once, it activates the mode, you call it again, it de-activates the mode. So you may have to do M-x mode-name twice.

Upvotes: 1

Related Questions