One of Lisp’s features that seem like magic to those of us brought up with C-like languages is the ability to change the code of a running process, reload it, and continue running with the new code. The amazing thing is that the process is not restarted. It simply continues running but with the new code.
Emacers do this all the time, often without realizing what they’re doing. They make a change, to their init.el, say, evaluate it, and continue executing their current Emacs instance. Sometimes, this is simply changing a parameter value but you can also change a function definition in the same way.
If you’re new to Emacs you may wonder how this magical spell is invoked even though you’ve done it several times. It’s simply a matter of evaluating the new code and continuing. Except when it isn’t. There are some edge cases that can trip you up. In Lisp it’s devar values. Emacs adds defface and defcustom. The values defined by these commands are not changed by a code update. This is on purpose. The idea is that you don’t want to mess with a user’s, say, custom values when you change the code.
Bozhidar Batsov has a nice post that discusses all this with particular attention on how to deal with devar and the other edge cases. For example, I always thought the the way to change devar variables was to evaluate a setq of the variable with the new value but you can also simple invoke eval-defun (Ctrl+Meta+x) to the devar to update the value. This also works for defcustom and defface.
The other nice thing I didn’t know about is the restart-emacs command that restarts Emacs and—with desktop-save-mode—reloads everything, including the new defvar etc. values. Take a look at Batsov’s post for more details.