> 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'.
Looks good to me (I mean: it doesn't literally look good, but given what we have, this seems about as clean as it gets). Only detail, I'd move the (if (eq (symbol-function 'plain-TeX-mode) #'plain-tex-mode) (defalias 'plain-TeX-mode nil)) (if (eq (symbol-function 'LaTeX-mode) #'latex-mode) (defalias 'LaTeX-mode nil)) (if (eq (symbol-function 'TeX-mode) #'tex-mode) (defalias 'TeX-mode nil)) into a function and merge it with the similar code which uses `auctex-function-definition`. > 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. That's not very pretty, indeed. The fundamental problem you're trying to solve is the same as the one we have with `tex-mode` since that function is used both as "parent mode" and as "dispatch to the appropriate child-mode". In `tex-mode` we've tried various approaches over the years, none of which are elegant :-( What have now is: (define-derived-mode tex-mode text-mode "generic-TeX" [...] (tex-common-initialization)) (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) [...] (if (or delay-mode-hooks tex-mode--recursing) [...])) In the case of `ConTeXt-mode`, maybe the better option is to make the submodes be minor modes? If at all possible, I recommend to use different names for the parent mode and the dispatch function :-) > 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. Maybe `nil` (a.k.a. `fundamental-mode`) is a better parent, which more closely matches the historical behavior of AUCTeX? TeX is one of those formats that sits halfway between `text-mode` and `prog-mode` (like (SG|X)ML, as well). > 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. FWIW, that's a cleaner solution than what I had come up when I looked at it. Stefan