Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

lisp

elisp

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?

like image 977
incandescentman Avatar asked Feb 25 '13 18:02

incandescentman


People also ask

How do you evaluate a Lisp?

Typing C-x C-e in any buffer evaluates the Lisp form immediately before point and prints its value in the echo area.

Is Emacs Lisp the same as Lisp?

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.


2 Answers

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.

like image 55
Rainer Joswig Avatar answered Sep 21 '22 22:09

Rainer Joswig


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.

like image 45
lunaryorn Avatar answered Sep 24 '22 22:09

lunaryorn