Subject: 28.0.50; "mode: conf" and "mode: tex" get unbounded recursion

From: Bob Rogers <[email-masked]>
Date: Thu, 19 Aug 2021 13:11:45 -0400

In "emacs -Q" in master rebuilt a few hours ago, when I open the file
shown below with "# -*- mode: conf; -*-" I get a "Lisp nesting exceeds
 max-lisp-eval-depth " error because conf-mode is trying to dispatch to
one of its submodes, but the submode then calls run-mode-hooks which
ends up back in conf-mode, ad inf.  Using this minimal broken.conf file:

	# -*- mode: conf; -*-

is sufficient; here's the top of the backtrace:

	Debugger entered--Lisp error: (error "Lisp nesting exceeds  max-lisp-eval-depth ")
	  apply(#f(compiled-function (orig-fun) "Redirect to one of the submodes when called directly." #<bytecode -0xe6df0765af3b07>) #f(compiled-function () (interactive nil) #<bytecode 0xdf70887525b4bad>) nil)
	  conf-mode()
	  conf-unix-mode()
	  #f(compiled-function (orig-fun) "Redirect to one of the submodes when called directly." #<bytecode -0xe6df0765af3b07>)(#f(compiled-function () (interactive nil) #<bytecode 0xdf70887525b4bad>))
	  apply(#f(compiled-function (orig-fun) "Redirect to one of the submodes when called directly." #<bytecode -0xe6df0765af3b07>) #f(compiled-function () (interactive nil) #<bytecode 0xdf70887525b4bad>) nil)
	  conf-mode()
	  hack-one-local-variable(mode conf)
	  hack-local-variables-apply()
	  hack-local-variables(no-mode)
	  run-mode-hooks(conf-unix-mode-hook)
	  conf-unix-mode()
	  #f(compiled-function (orig-fun) "Redirect to one of the submodes when called directly." #<bytecode -0xe6df0765af3b07>)(#f(compiled-function () (interactive nil) #<bytecode 0xdf70887525b4bad>))
	  apply(#f(compiled-function (orig-fun) "Redirect to one of the submodes when called directly." #<bytecode -0xe6df0765af3b07>) #f(compiled-function () (interactive nil) #<bytecode 0xdf70887525b4bad>) nil)
	  conf-mode()
	  hack-one-local-variable(mode conf)
	  . . .

It fails with conf-unix-mode in the simple case of the configuration
file above; unsurprisingly, I've also seen it fail with conf-space-mode.
And "mode: tex;" has the same general problem, since it uses the same
dispatch logic.

   I would attempt a patch, but I have no clue what TRT would be here.
It would seem cleanest to keep conf-mode and tex-mode as user-visible
modes, and make new generic-conf-mode and generic-tex-mode parents for
their submodes, but that seems like it could be a fairly large change.
Using delay-mode-hooks might be simpler, but I have no idea how that
would work.

					-- Bob Rogers
					   http://www.rgrjr.com/

------------------------------------------------------------------------
In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2021-08-19 built on orion
Repository revision: a44432a773f7e131692e3f5c9d765cffeef0739a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description: openSUSE Leap 15.3

Configured using:
 'configure --with-dbus=no --with-gsettings=no --with-gif=ifavailable
 --with-tiff=no --with-gnutls=yes --with-gconf=no'

Configured features:
ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ JPEG LIBSELINUX LIBXML2
MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix