[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: |
Mon, 28 Aug 2023 01:25:03 +0900 |
Hi all,
I pushed a commit, to the feature branch, that uses
`define-derived-mode' for major modes such as LaTeX-mode. I chose
`TeX--VirTeX-mode' as the name of base modes except Texinfo mode.
Here are some related issues I'd like to hear thoughts of those
interested in this topic.
1. Ugly defvaralias'es
Contrary to my expectation, `define-derived-mode' doesn't allow to
configure the names for the keymap and hook. Thus I have to include
very ugly defvaralias'es like
(defvaralias 'TeX-LaTeX-mode-map 'LaTeX-mode-map)
and
(defvaralias 'TeX-LaTeX-mode-hook 'LaTeX-mode-hook)
in order to keep compatibility. Similar aliases are injected for
TeX-plain-TeX-mode and TeX--VirTeX-mode as well.
This is much unsatisfactory. I'm currently thinking to apply the
attached patch to sort out the disorders of mode names. It works as
follows:
(a) It uses the names without `TeX-' prefix for LaTeX-mode,
plain-TeX-mode and TeX-mode.
(b) Those mode definitions are overwritten, prior to emacs 29, when
tex-mode.el is loaded. So the patch saves the function
definitions of AUCTeX major modes in the symbol property
`auctex-function-definition', and restores them after tex-mode.el
is loaded via `with-eval-after-load'.
I confirmed that this idea works as expected, although it's rather
tricky.
2. ConTeXt modes
The design of ConTeXt modes doesn't match well with
`define-derived-mode' as explained below.
ConTeXt modes consist of "primary" mode `ConTeXt-mode' and "sub"
modes such as `ConTeXt-en-mode' and `ConTeXt-nl-mode'. Sub modes are
expected to work when they are called explicitly as well.
At first sight, it seems natural to implement the sub modes as
derived modes of the primary mode. However, simple implementation
doesn't work because the primary `ConTeXt-mode' is supposed to
detect the document's language (english, dutch...) and call the sub
mode according to the detected language. Thus simple implementation
leads to loop of the primary mode and duplication of hook calls.
I chose to implement the sub modes as derived modes of the primary
mode and move the "detecting the language and calling the sub mode"
phase of the primary mode into `change-major-mode-after-body-hook'.
In addition, the phase now bypasses call to the sub mode and calls
the "body" part of the sub mode independently. Hence the sub mode's
keymap and hook are ignored in that case. This might be considered as
a bad behavior.
In addition, I'm not sure whether such usage is suitable for
`change-major-mode-after-body-hook' or not.
3. Additional menu item
I chose `text-mode' as the parent of the base mode
`TeX--VirTeX-mode' and `Texinfo-mode'. This is reasonable because
those modes called `text-mode-hook' so far. On the other hand, there
is a side effect that "Text" menu appears in the menu bar in all
AUCTeX major modes, which may be distracting for some users.
4. Directory local variables
(a) I simplified the way to have `LaTeX-mode' as the value of
`major-mode' of `japanese-LaTeX-mode' while it can read directory
local variables prepared for japanese-LaTeX-mode. Now there is a
line
:after-hook (setq major-mode 'LaTeX-mode)
in the definition of `(define-derived-mode japanese-LaTeX-mode...'
and cumbersome interaction with `hack-local-variables' is
discarded.
This solution works for most cases, but would break if the mode
hooks contain user codes which assume mode name without
`japanese-' prefix.
If it turns out that such breakage does exist and no workaround
is found, we'd have to go back to the former approach.
(b) The discrepancy between directory local variable and
`major-mode-remap-alist' (bug#61210) still remains.
Best regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
0001-canonicalize-mode-name.gz
Description: Avoid defvaralias
- Re: AUCTeX and "builtin latex mode" integration,
Ikumi Keita <=