York Zhao <gtdplatf...@gmail.com> writes:
> First goes .emacs file: > > (add-to-list 'load-path "path/to/org-mode") > (add-to-list 'load-path "path/to/org-mode/lisp") ; this line is the key > (add-to-list 'load-path "path/to/yhj-mode") > (require 'yhj-mode) > > Second goes yhj-mode.el: > > (require 'org) > (define-derived-mode yhj-mode org-mode "yhj") > (provide 'yhj-mode) > > Finally, file test.yz: > > # -*- mode:yhj -*- > > Open file "test.yz" and note the comment line not fortified, open "*message*" > buffer and note the following error: > > File local-variables error: (error "Lisp nesting exceeds > `max-lisp-eval-depth'") > > There are three keys to reproduce, first, you have to make two files, .emacs > and > "yhj-mode.el". Second, this line must be present: > > (add-to-list 'load-path "path/to/org-mode/lisp") ; this line is the key > > Third, file "yhj-mode.el" has to be byte-compiled. > Thank you for the reproducer. I get the same result (and I don't need to byte compile yhj-mode.el - the mention of the necessity of byte-compilation led me to suspect the compiler, but since it happens with uncompiled code, that theory went out the window.) The problem is the following sequence of calls: find-file -> normal-mode -> set-auto-mode (nil) -> set-auto-mode-0 (nil) yhj-mode -> org-mode -> hack-local-variables -> hack-local-variables-apply(mode yhj) -> yhj-mode -> org-mode -> hack-local-variables -> ... Setting the mode in a local variable section leads to this scenario, something I did not test for my original "fix". The best solution I can think of so far: revert commit 5ea0228, and change org-mode-restart to call normal-mode, instead of org-mode. normal-mode splits the setting of the mode from the setting of local variables, so it would avoid the recursion. I think (but I have not verified yet) that this would fix both the problem that gave rise to commit 5ea0228 in the first place and this bottomless recursion, without causing any other problems. I'll try it out tomorrow if I find the time and submit a patch. -- Nick