Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: nesting exceeds `max-lisp-eval-depth'

Tags:

emacs

From time to time I get a "nesting exceeds `max-lisp-eval-depth'" error.

  • What does it mean?
  • When I get one, is there something I can do, other than "killall emacs"?

Edit:

You can get the error if you evaluate:

(defun func ()
  (func))
(func)

However, in this case emacs remains responsive.

like image 565
sabof Avatar asked Aug 04 '12 08:08

sabof


2 Answers

An immediate remedy can be to simply increase the maximum. Its default value is 500, but you could set it to, say, 10000 like this:

(setq max-lisp-eval-depth 10000)

But that's generally not a great idea, because the fact that you run into a nesting exceeds `max-lisp-eval-depth' error in the first place is a sign that some part of your code is taking up too much stack space. But at least increasing the maximum temporarily can help you analyze the problem without getting the same error message over and over again.

like image 191
Thomas Avatar answered Sep 21 '22 05:09

Thomas


Basically, it means that some Lisp code used up more stack than Emacs was compiled to permit.

In practice, it's a sign of a bug in Lisp code. Correctly written code should avoid nesting this deeply, even if the algorithm and the input data were "correct"; but more frequently, it happens because of an unhandled corner case or unexpected input.

If you are lucky, repeated control-G keypresses could get you out of the conundrum without killing Emacs.

If you are developing Emacs Lisp code, you might want to tweak down the value of max-lisp-eval-depth artifically to help find spots where your code might need hardening or bug fixing. And of course, having debug-on-error set to t should help by showing you a backtrace of the stack.

like image 32
tripleee Avatar answered Sep 20 '22 05:09

tripleee