How can I get Emacs to reload all my definitions that I have updated in .emacs
without restarting Emacs?
C-x C-e ;; current line
M-x eval-region ;; region
M-x eval-buffer ;; whole buffer
M-x load-file ~/.emacs.d/init.el
You can usually just re-evaluate the changed region. Mark the region of ~/.emacs that you've changed, and then use M-x eval-region RET
. This is often safer than re-evaluating the entire file since it's easy to write a .emacs file that doesn't work quite right after being loaded twice.
I suggest that you don't do this, initially. Instead, start a new emacs session and test whatever changes you made to see if they work correctly. The reason to do it this way is to avoid leaving you in a state where you have an inoperable .emacs file, which fails to load or fails to load cleanly. If you do all of your editing in the original session, and all of your testing in a new session, you'll always have something reliable to comment out offending code.
When you are finally happy with your changes, then go ahead and use one of the other answers to re-load. My personal preference is to eval
just the section you've added/changed, and to do that just highlight the region of added/changed code and call M-x eval-region
. Doing that minimizes the code that's evaluated, minimizing any unintentional side-effects, as luapyad points out.
Others already answered your question as stated, but I find that I usually want to execute the lines that I just wrote. for that, CtrlAltx in the lisp works just fine.
Define it in your init file and call by M-x reload-user-init-file
(defun reload-user-init-file()
(interactive)
(load-file user-init-file))
The following should do it...
M-x load-file