incandescentman
incandescentman

Reputation: 6378

How do I locate the error in a lisp file in Emacs?

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?

Upvotes: 8

Views: 2860

Answers (2)

user355252
user355252

Reputation:

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 face
  • paredit-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.

Upvotes: 4

Rainer Joswig
Rainer Joswig

Reputation: 139321

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.

Upvotes: 20

Related Questions