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: Ikumi Keita
Subject: Re: AUCTeX and "builtin latex mode" integration
Date: Tue, 09 May 2023 15:50:29 +0900

Hi Stefan and all,

>>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
> FWIW, here's how I'd do it (using the command line):

>     git push --set-upstream origin HEAD:feature/fix-mode-names-overlap

Thanks, it worked well.

>> a. Invoked mode
>> a-1
>> Suppose that Alice prefers built-in plain-tex-mode over AUCTeX and
>> customized `TeX-modes' to remove `plain-tex-mode' from it. She
>> also want AUCTeX-style auto-detection for files with .tex
>> extension so leave `tex-mode' in `TeX-modes'. After my patch is
>> applied, when she openes a plain tex file without mode: tag in the
>> File Local Variables section, it's opened in AUCTeX plain TeX mode
>> against her expectation.
>> The reason is that `TeX-tex-mode' calls AUCTeX mode names
>> according to the change in `TeX-format-list'.

> Maybe `TeX-format-list` should stay as it is, and `TeX-tex-mode` should
> instead rely on `TeX-modes` or `major-mode-remap-alist` to decide which
> function to call?

It's a possible way, indeed. I'll ponder further.

>> a-2
>> Suppose that a site admin sets up AUCTeX as the default TeX modes
>> in site-start.el but Bob disabled them by (unload-feature
>> 'tex-site) in his init.el because he prefers built-in modes. In
>> addition, Bob has some latex files annotated with -*- LaTeX -*-,
>> which he recieved from someone else. After my patch is applied,
>> when he opens such a file, it results in File mode specification
>> error.
>> The reason is that tex-site.el is changed to delete the aliases
>> plain-TeX-mode -> plain-tex-mode, LaTeX-mode -> latex-mode.
>> 
>> I think these are corner cases and am not sure whether we should
>> keep compatibility.

> Not sure either, but we can arrange to re-instate the aliases (they're
> not autoloads) upon unload, if so desired (actually, I think all it
> takes (in Emacs-29) is to use `(defalias 'LaTeX-mode nil)` instead of
> `(fset 'LaTeX-mode nil)`.  Also, while I'm here, I think we should check
> that they are aliases before removing them).

Thanks, I didn't know that `defalias' allows an argument which isn't a
function. I'll check later.

>> b. Abbrev table
>> User abbrevs in, say, latex-mode-abbrev-table aren't inherited to
>> AUCTeX LaTeX mode.

> Is there a particular reason why `LaTeX-mode-abbrev-table` isn't made to
> inherit from `latex-mode-abbrev-table`?

No, I think we can manipulate the abbrev table property by
`abbrev-table-get' and `abbrev-table-put'.
(Or maybe we should add an optional argument to the elisp macro
`TeX-abbrev-mode-setup' for such an additional parent table.)

>> c. desktop.el records the major mode name in the saved sessions. When
>> users have saved sessions with the name, say, latex-mode and
>> install this patch before the next session, desktop.el restores
>> them in wrong mode in the next session if `major-mode-remap-alist'
>> is available.

> Indeed, I hadn't thought about that use case.  I can't think of a good
> way to "fix" it since it seems hard/impossible to reliably detect if
> that desktop was saved with an Emacs using the "old AUCTeX names" or the
> "new AUCTeX names".

> The best might be to accept the breakage and add a clear "release note"
> about it?

Doesn't it help to modify `desktop-restore-file-buffer' to look up
`major-mode-map-alist' around here?:
----------------------------------------------------------------------
(defun desktop-restore-file-buffer (buffer-filename
[...]
          (and (not (eq major-mode desktop-buffer-major-mode))
               (functionp desktop-buffer-major-mode)
               (funcall desktop-buffer-major-mode))
----------------------------------------------------------------------

>> d. Directory local variables
>> d-1
>> Directory local variables prepared for, say, `latex-mode' aren't
>> picked up by AUCTeX LaTeX-mode when `major-mode-remap-alist' is
>> available.
>> The reason is that `hack-local-variables' doesn't understand
>> that `LaTeX-mode' is redirected from `latex-mode'.

> This is something that we need to fix before this can make it into
> a release, I think.  IIRC there's an open bug report on Debbugs
> about it.

I think you mean bug#61211[1], but it's for type d-2. For type d-1, I
briefly mentioned in bug#61210[2] as just a subsidary topic.

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61211
[2] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61210

> But it's not even clear what should be a good solution (from
> Emacs's point of view).

Indeed.

> Maybe in the mean time AUCTeX can "fix" it on its side by adding some
> clever piece of advice on the directory-local-vars code or by setting
> `derived-mode-parent`?

I'll try.

>> d-2
>> Similar issue related to "superficial major modes" such as
>> japanese-LaTeX-mode still persists for directory local
>> variables[1] regardless whether `major-mode-remap-alist' is
>> available or not.
>> I'm still relying on ugly hack currently used for
>> japanese-{plain-tex,latex}-mode[2].
>> 
>> [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61211
>> [2] The following code in tex-jp.el.

> I hope whichever fix we use for `d-1` will be applicable for `d-2`.

OK.

>> - TeX-tex-mode is an exception. It doesn't need
>> `define-derived-mode' in my opinion.

> Agreed (luckily: making it use `define-derived-mode` would be painful,
> as you can see in `tex-mode`).

How about separating the two role of `tex-mode'?
----------------------------------------------------------------------
(define-derived-mode tex-base-mode text-mode "generic-TeX"
[...]
  (tex-common-initialization))

(define-derived-mode plain-tex-mode tex-base-mode "TeX"
[...]

(define-derived-mode latex-mode tex-base-mode "LaTeX"
[...]

(defun tex-mode ()
  (funcall (tex--guess-mode)))
----------------------------------------------------------------------
I see this approach has two apparent incompatibilities, but I expect
those doesn't matter practically:
1. Users can't have buffers of `tex-mode', not intended for a particular
   TeX variant. (They have to use `tex-base-mode' instead for that
   purpose.)
2. Directory local variable entry for `tex-mode' is no longer effective.
   (Users have to rewrite the entry to `tex-base-mode', but that isn't
   possible for read-only filesystem such as CD-ROM.)

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



reply via email to

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