I want to debug my init file, by exiting from loading the file in the middle so if something is wrong after that place it will not be loaded. How can I exit from .emacs file?
You can use this to exit from your init file:
(with-current-buffer " *load*" (goto-char (point-max)))
Emacs uses the
load function to execute lisp file through a temporary buffer, that's
" *load*", if the name is not already taken. The above code moves the point to the end of the buffer, thus the
read function will not read further code.
For example, the last sexp of
foo.el is unbalanced, but there is no error when running it, since Emacs can't go that far, it exits early:
~$ cat foo.el (message "Loading %s..." load-file-name) (with-current-buffer " *load*" (goto-char (point-max))) (this line does not matter ~$ emacs --batch --load foo.el Loading /home/xcy/foo.el... ~$