auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: \documentclass does not activate latex-mode


From: jfbu
Subject: Re: \documentclass does not activate latex-mode
Date: Thu, 18 Aug 2022 20:03:53 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0) Gecko/20100101 Thunderbird/91.12.0

Hi Keita,

Le 18/08/2022 à 09:40, Ikumi Keita a écrit :
Hi Jean, sorry for late response. I just came back from my summer
vacation.

no worries whatsoever
thanks for all your volunteer work on AUCTeX !


jfbu <jfbu@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. :-(



oh well... yes indeed I am currently using a build of GNU Emacs 28.1...

in retrospect it is easy for me to say that somewhere inside me a little voice 
was telling me that in the past I had been working under same circumstances and 
didn't experience the reported problems... but your detective work is much more 
accurate!

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.

wow it does work! Now that's quite magic to me. I have delayed for two decades 
learning e-Lisp...


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.


I knew it! (subconsciously ;-))

Thanks for your help!

Best,

Jean-François

[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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]