auctex-devel
[Top][All Lists]
Advanced

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

Re: AUCTeX and "builtin latex mode" integration


From: Stefan Monnier
Subject: Re: AUCTeX and "builtin latex mode" integration
Date: Tue, 20 Sep 2022 10:10:33 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>> You may have seen an on-going discussion about the annoyance of the
>> mixups between latex-mode and LaTeX-mode and such.
> Could you tell us where that discussion takes place?

I think it's on gnu.emacs.help, aka help-gnu-emacs.

It started with someone complaining that rainbow-delimiters doesn't work
with LaTeX's braces, derived into AUCTeX-vs-plain because IIUC the
problem was that they enabled the mode via `latex-mode-hook` which their
AUCTeX doesn't run even though the mode describes itself as `latex-mode`.

>> I do think it would be good to try and "integrate" the two modes, for
>> some definition of "integrate".  The question being indeed what
>> "integration" is the best way forward.
>
> I also want some improvements with regard to the "integration" because I
> recently realized that emacs built-in `tex-mode' (accidentally?) shadows
> AUCTeX `TeX-tex-mode' since emacs 28.1, to fail to enter LaTeX mode for
> some cases[1][2]. (I'm not sure that the above discussion involves this
> issue.)
>
> [1] thread beginning with
> https://lists.gnu.org/r/auctex/2022-08/msg00001.html

Oh, I wasn't aware of regression.  We can workaround the problem
using the `depth` property on `advice-add`, to make sure AUCTeX's advice
takes precedence over that of `tex-mode.el` even if it's
installed before.

E.g. if you add the patch below to Emacs, can you confirm that it fixes
the problem on your end?

    diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
    index f624b604aac..77c0d234206 100644
    --- a/lisp/textmodes/tex-mode.el
    +++ b/lisp/textmodes/tex-mode.el
    @@ -1014,7 +1014,10 @@ tex-mode
     says which mode to use."
       (tex-common-initialization))
     
    -(advice-add 'tex-mode :around #'tex--redirect-to-submode)
    +(advice-add 'tex-mode :around #'tex--redirect-to-submode
    +            ;; Give it lower precedence than normal advice, so
    +            ;; AUCTeX's advice takes precedence over it.
    +            '((depth . 50)))
     (defvar tex-mode--recursing nil)
     (defun tex--redirect-to-submode (orig-fun)
       "Redirect to one of the submodes when called directly."

I pushed this to `emacs-28` so it will be fixed in the next Emacs
release (but that may be Emacs-29.1).  In the mean time, you can use
a `((depth . -10))` in AUCTeX to make it work with Emacs-28.1.

The dual use of `tex-mode` (as both a major mode and a dispatch
function) is very messy :-(

>> I'm wondering if it would be possible to turn AUCTeX into a minor mode.
>> E.g. `LaTeX-mode` would then be redefined as
>
>>     (define-derived-mode TeX-latex-mode latex-mode ...
>>       (AUCTeX-mode 1))
>
>> and `TeX-modes-set` would add/remove `AUCTeX-mode` from the hooks like
>> `latex-mode-hook`.
>
> It basically looks reasonable. I assume that you are thinking that
> `AUCTeX-mode' actually chooses suitable behavior according to the value
> of `major-mode' between `latex-mode', `plain-tex-mode', `doctex-mode'
> and `texinfo-mode'.

That'd be the idea, yes.

> 1. There will be some overheads because it first runs initialization
> codes of emacs built-in mode and then runs AUCTeX minor mode; I expect
> that the associated cost is cheap enough.

I'm assuming it would be cheap, yes.

> 2. AUCTeX still must retain some major modes, i.e., ConTeXt mode,
> AmS-TeX mode, Japanese LaTeX mode and Japanese plain TeX mode because
> there are no counterparts in emacs built-in modes.

In the short term at least it will also keep `(TeX-)LaTeX-mode` and
friends, I think.  And maybe even in the long term.

> 3. Currently, there is defect in handling doc strings of AUCTeX LaTeX
> mode, plain TeX mode and docTeX mode; C-h m and C-h f show doc string
> of built-in modes, not AUCTeX modes.

Maybe the help facility should be more careful in how it builds the
docstring when a function has an `:override` advice, indeed.
Could you `M-x report-emacs-bug` for that?

Maybe the `latex-mode` docstring would need some tweaking, but `C-h m`
would show the docstring of `AUCTeX-mode` as well.

> `AUCTeX-mode' should put suitable `function-documentation' property
> for the respective major mode symbol.

I think that would be exactly the kind of messing around I'd like to
move away from.

> 4. `TeX-tex-mode' and `tex-mode' would need some special treatment.

Special care, that's for sure, yes.

>> To be honest, I haven't looked very much at the code to see how
>> realistic this is, but I think this could help clarify the situation
>> for users. E.g. it would eliminate "lies" such as (setq major-mode
>> 'latex-mode) in `latex.el`.
>
> From the users' point of view, I don't think it matters much. They just
> specify
> %%% mode: latex
> as the file local variable and think that they are using `latex-mode'.
> I think that it would be only Elisp programmers that care about the
> "lies".

There's regularly discussion (among (AUC)TeX Emacs users) about which
major mode runs which hook.  I think it's an important issue not just
for ELisp programmers.


        Stefan




reply via email to

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