When working with my .emacs init file, I sometimes make a mistake. When I do eval-buffer, I get the message "end of file during parsing."
How do I ask Emacs to tell me the exact location of the error?
Typing C-x C-e in any buffer evaluates the Lisp form immediately before point and prints its value in the echo area.
Emacs Lisp is a dialect of the Lisp programming language used as a scripting language by Emacs (a text editor family most commonly associated with GNU Emacs and XEmacs). It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C, as is the Lisp interpreter.
The first thing is to check the balancing of parentheses and string quotes.
For Emacs Lisp In GNU Emacs use M-x check-parens
.
Other Emacs-like editors have similar commands. In LispWorks for example one can use M-x Find Unbalanced Parentheses
.
These errors are very hard to actually locate.
Better try hard to avoid mismatching parenthesis at all. There are several built-in and 3rd-party minor modes that help you in this:
electric-pair-mode
: Insert matching closing parenthesis automatically (built-in)show-paren-mode
: When point is over a parenthesis, highlight the matching one (built-in)rainbow-delimiters-mode
: Highlight each level of parenthesis in a different faceparedit-mode
: Keep parenthesis balanced at all time. Generally, focus editing on Sexps instead of characters and words.I'd recommend to enable all of these. A reasonable configuration to defeat mismatched parenthesis is thus:
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
(show-paren-mode 1)
(electric-pair-mode 1)
Paredit and Rainbow Delimiters are available from MELPA.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With