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
3 Answers
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).

- 64,967
- 9
- 133
- 163
-
3I hadn't seen this before. The documentation notes that this will raise an error if there is other loaded code which requires the feature, but you can force the unload by using a prefix arg. – phils Dec 06 '10 at 02:58
-
It's useful to be made aware of cases where other loaded code uses your module, because even if you reload your module, the other module may continue to refer to old function definitions. In this case you'd need to reload the other module too so that it refers to the new definitions. – Gareth Rees Dec 06 '10 at 14:56
-
+1, this did it for me, in combination with Trey Jackson's answer. – Adam Rosenfield Nov 01 '11 at 21:04
-
I've try `M-x unload-feature RET web-mode RET` but got error: `Loaded libraries (\"/home/kuba/.emacs\") depend on /home/kuba/projects/emacs-modes/web-mode/web-mode.el` I have `(require 'web-mode)` in my .emacs – jcubic Jun 15 '17 at 08:04
-
@jcubic `C-u M-x unload-feature RET web-mode RET` will do the trick. According to `C-h f unload-feature RET`, this forces the unload operation. – Winny Nov 20 '20 at 02:53
-
Another cool feature is you can script with `unload-feature` in conjunction with `feature-file` and `load` to *reload* the feature's file from one command. – Winny Nov 20 '20 at 02:53
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.

- 73,529
- 11
- 197
- 229
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.

- 17,016
- 4
- 46
- 70
-
For all the different ways of (re)evaluating elisp, see http://www.masteringemacs.org/articles/2010/11/29/evaluating-elisp-emacs/ – phils Dec 06 '10 at 03:01