Hi Jean, sorry for late response. I just came back from my summer vacation.
>>>>> jfbu <j...@free.fr> writes: > when I open a buffer on this file > ---- > \def\foo{bar} > \documentclass{foobar} > \begin{document} > hello > \end{document} > ---- > there is no activation of latex-mode. > I have to manually type-in M-x latex-mode. [...] > Any hint to make my life less miserable? Actually, AUCTeX is able to activate latex mode correctly, but emacs built-in tex-mode.el interferes with it, due to the change installed in emacs 28. :-( For the time being, you can work around by (let (entry) (while (setq entry (rassq 'tex-mode auto-mode-alist)) (setcdr entry #'TeX-tex-mode))) in your personal init file. > But IMHO, should'nt \documentclass by itself trigger latex-mode? > It is relatively frequent to have to put code before the > \documentclass. Yes. As I wrote above, there was no problem until emacs 27. [To developpers] In emacs 28, tex-mode.el changed `tex-mode' activation like this: ---------------------------------------------------------------------- (define-derived-mode tex-mode text-mode "generic-TeX" "...doc string..." (tex-common-initialization)) (advice-add 'tex-mode :around #'tex--redirect-to-submode) (defvar tex-mode--recursing nil) (defun tex--redirect-to-submode (orig-fun) "Redirect to one of the submodes when called directly." ;; The file may have "mode: tex" in the local variable ;; block, in which case we'll be called recursively ;; infinitely. Inhibit that. (let ((tex-mode--recursing tex-mode--recursing)) (funcall (if (or delay-mode-hooks tex-mode--recursing) ;; We're called from one of the children already. orig-fun (setq tex-mode--recursing t) (tex--guess-mode))))) ---------------------------------------------------------------------- This around advice for `tex-mode' broke AUCTeX's intention. At emacs startup, AUCTeX adds override advice `TeX-tex-mode' to `tex-mode' in tex-site.el. However, when tex-mode.el is autoloaded, it futher adds around advice `tex--redirect-to-submode'. By the nature of around advice, it bypasses the `orig-fun' (which is essentially `TeX-tex-mode' by the override advice) and calls `tex--guess-mode'. `tex--guess-mode' in tex-mode.el is not smart enough to guess that Jean's example is latex document, ending up with calling `plain-tex-mode'. Why on earth does tex-mode.el use advice for its own function? The whole above piece of code can just be composed up as ---------------------------------------------------------------------- (defvar tex-mode--recursing nil) (define-derived-mode tex-mode text-mode "generic-TeX" "...doc string..." ;; The file may have "mode: tex" in the local variable ;; block, in which case we'll be called recursively ;; infinitely. Inhibit that. (let ((tex-mode--recursing tex-mode--recursing)) (if (or delay-mode-hooks tex-mode--recursing) ;; We're called from one of the children already. (tex-common-initialization) (setq tex-mode--recursing t) (tex--guess-mode)))) ---------------------------------------------------------------------- without any advice, if I understand correctly. I think we should file bug report for tex-mode.el. What do others think? Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine