reddit / emacs
max-lisp-eval-depth error with beancount files
sigur_ · 2022-09-10 09:07
Hi all! Whenever I try to load a .beancount file (plain text accounting, similar to ledger) I get this error: `error "Lisp nesting exceeds ‘max-lisp-eval-depth’"`. Here is my usual workflow: first of all I load the beancont.el file (the mode isn't available on melpa) with `load-file`, and I get this: `Loading /home/sgrc31/personal/finanze/beancount-mode/beancount.el (source)...done` ,then if I try to load my "main.beancount" file i get the aforementioned error.
Here is the backtrace: https://pastebin.com/pQ9c5MA2
\
I already tried to start emacs without my config (with the -q switch), but the problem persisted. It may also help to say that I used beancount mode without any issue for several months, and all of a sudden this problem occured 3 weeks ago.
This morning I updated all my packages and cloned the beancount mode repo afresh, but nothing changed.
How can I fix this? Thanks for your time
piethesailor · 2022-09-10 14:47
I am not sure what exactly is causing the problem, but this usually(for me) means a recursive function somewhere has iterated over itself too many times. You could go to the ielm buffer and type “max-lisp-eval-depth” and see if you get something like 100. If so then setq that variable to 200 and try again. Regardless of whether that works, be sure to return that variable to its original number. This will at least get you going.
Edit: Never mind. Don’t do that. You have an infinite loop going, extending the variable might lock up your machine. Do you have any configurations for bean count in your .emacs.d/init.el or .emacs?
lebensterben · 2022-09-10 15:05
increasing the value is generally safe in my experience. because there's other max-* variables that you will hit lol
piethesailor · 2022-09-10 15:09
It is generally safe! I like to not change too many things from their normal state if it’s not necessary. Also setq ing it in the repl only applies the change for the continuing session, so yeah it’s not really a big deal. In this case the op is calling org-mode and then beancount-mode which is calling org-mode which is calling bean....
Walheimat · 2022-09-10 15:32
Can you check the hooks for `org-mode` and `beancount-mode` looks like one is hooking into the other. Maybe beancount either calls org-mode or is derived from it. Are you adding any hooks?
sigur_ · 2022-09-11 13:45
Thank for your suggestions!
I already tried setting “max-lisp-eval-depth” to 1000 in my config.el, just to see what would happen, but nothing changed. So I tried with 10000, and as @lebensterben said I hit another "max-somithing" error.
I tried deleting my whole .emacs.d folder and the problem persisted, can I assume that the problem isn't caused by my configuration? I'm trying to understand if I should open an issue on github over this matter.
sigur_ · 2022-09-11 13:49
I tried deleting my whole .emacs.d folder, so I'm inclined to say that, as far as I know, I'm not adding any hooks.
For the sake of completeness here is my whole config: https://pastebin.com/77GWhLZc
and here are the lines relative to Org: https://pastebin.com/ms0u7rXZ
piethesailor · 2022-09-11 15:55
To Walheimats point, how about go to your ielm and type “org-mode-hook” return it, and see if inside is a call to “beancount-mode”. I think it is fine that beancount is looking for org-mode, but org-mode shouldn’t always be looking for beancount. If this is true, you’ll want to setq org-mode-hook to everything that was in it except “beancount-mode”. Hopefully this does it. I’ll give your code a glance and see if the issue is somewhere in there.
Tip for the future: in the original debug pastebin you posted, you can see that it is stuck in a loop calling beancount, the org-mode, then beancount, then org-mode... If a recursive function is to terminate, there needs to be a variable that changes closer to the termination point. In your case nothing was changing, that’s your clue that no amount of extending “max-eval” will get you anywhere. Just something to think about in the future :).
sigur_ · 2022-09-12 10:24
Ok, I had no idea what the ielm was, and how to use it, sorry.
Here is the output:
```
ELISP> org-mode-hook
(#f(compiled-function
()
#<bytecode 0xa5a161c574212>)
#f(compiled-function
()
#<bytecode -0x1db2e727825f82a0>)
#f(compiled-function
()
#<bytecode -0x1db2e726a3af9ea0>)
org-babel-result-hide-spec org-babel-hide-all-hashes)
ELISP>
```
If I click on each bytecode from top to bottom here is what I get:
```
byte code:
args: nil
0 constant org-imenu-get-tree
1 dup
2 varset imenu-create-index-function
3 retur
```
```
byte code:
args: nil
0 constant add-hook
1 constant change-major-mode-hook
2 constant org-show-all
3 constant append
4 constant local
5 call 4
6 return
```
```
byte code:
args: nil
0 constant add-hook
1 constant change-major-mode-hook
2 constant org-babel-show-result-all
3 constant append
4 constant local
5 call 4
6 return
```
sigur_ · 2022-09-13 11:28
SOLVED: The culprit was my .beancount file, which had the following header:
;; -*- mode: org; mode: beancount; coding: utf-8; fill-column: 400; -*-
no wonder my emacs was confused on which major mode to use. I deleted the `mode: org` part and everything is working. Thanks to all the people that took their time to solve my problem!
I probably took that header from an outdated doc, back when beancount-mode was still a minor mode...