24

As far as I understand, the following sequence of commands

M-x load-file ENTER
~/.emacs
ENTER

would re-load my .emacs file. However, from what I have read on other forums, they are not guaranteed to give me a totally revised configuration, i.e. they would force Emacs to parse the new configuration file and reload modified variable and function definitions, but they would not remove previously loaded definitions.

With this, my questions are:

  1. Is it possible to clear ups Emacs's definitions in memory and re-load .emacs without having to fully restart Emacs?
  2. If the above is not possible, is there a way to restart Emacs (so that I parses my .emacs file from scratch) asking it to re-open all buffers that I have open?
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • 2
    +1 to counter the (strange) downvote... what's wrong with this question? – Dervin Thunk Oct 04 '11 at 20:45
  • Why are you trying to reload the whole file? Parts of the file that you know have changed can be re run with eval-region – Andrew Cox Oct 04 '11 at 21:03
  • 3
    Let's say you have `(setq config-var t)` for some variable whose default value is `nil`. If you delete this line from the file you can't reproduce the default behavior by reloading just that part of the file (which is now empty), or even the whole file. You have to keep track of each change you make and undo it somehow, which is fraught with peril and may not even be possible. – Michael Hoffman Oct 04 '11 at 21:21
  • possible duplicate of [Reload .emacs for all active buffers](http://stackoverflow.com/questions/7211615/reload-emacs-for-all-active-buffers) – phils Oct 04 '11 at 21:58

2 Answers2

13

Undoing everything that might have been done in your .emacs is impossible.

You can save and restore an emacs session with desktop. Quit with M-x desktop-save RET C-x C-c and then restore with emacs -f desktop-read.

See (info "(emacs) Saving Emacs Sessions") for more information. (You can also customize desktop-save-mode so that this behavior is the default.)

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
  • 1
    See also http://porkmail.org/elisp/recover-buffers/ which allows you to revisit all the buffers you had open when Emacs quit or crashed. Disclosure: I wrote that. – tripleee Oct 15 '11 at 11:43
6

This question is a duplicate, but as it has an accepted answer I'll repeat my comments about the Desktop library which is that it stores a certain amount of state (modes and local variables) with each buffer that it saves, and it then restores that same state when it reloads those files.

In your case, of course, this is exactly what you don't want to happen.

See Reload .emacs for all active buffers for a simple way to revert (reload) all the buffers.

Combining the two approaches would let you restart Emacs, with Desktop restoring the files, at which point you could revert all the files.

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198