[Top][All Lists]

[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: Wed, 01 Feb 2023 00:52:32 +0900

Hi all, I at last began to work on this issue and would like to share

There are three topics 1.-3. below.

Two approaches were proposed before:
[A] Turn AUCTeX modes into minor mode.
[B] AUCTeX modes stay major modes but use `major-mode' values dictinct
from those of emacs built-in modes.

1. I first tried [A] because [B] wouldn't be easy to retain
compatibility for users who have
   - a lot of files with "mode: latex" tag in the file local variables
   - hard-coded mode names in their personal customized codes.
However, I hit upon an obstacle explained below:

>>>>> Stefan Monnier <> writes:
>>>>>> Ikumi Keita <> writes:
>> Then the idea of turning AUCTeX into minor mode itself does not help.

> Not necessarily, but it could if we can arrange for latex-mode and
> auctex-mode not to collide in their keymaps (and syntax table, ...), so
> that entries added to `latex-mode-map` wouldn't be hidden by the
> auctex-mode-map (e.g. if that map was added with lower priority than
> latex-mode-map).

The keymaps of AUCTeX LaTeX mode and built-in latex mode have a lot of
overlaps. It seems difficult to me to separate all of them. In
tex-mode.el, we see:
(defun tex-define-common-keys (keymap)
  "Define the keys that we want defined both in TeX mode and in the TeX shell."
  (define-key keymap "\C-c\C-k" #'tex-kill-job)
  (define-key keymap "\C-c\C-l" #'tex-recenter-output-buffer)
  (define-key keymap "\C-c\C-q" #'tex-show-print-queue)
  (define-key keymap "\C-c\C-v" #'tex-view)
(defvar tex-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "\"" #'tex-insert-quote)
    (define-key map "\n" #'tex-handle-newline)
    (define-key map "\M-\r" #'latex-insert-item)
    (define-key map "\C-c{" #'tex-insert-braces)
    (define-key map "\C-c\C-c" #'tex-compile)
    (define-key map "\C-c\C-i" #'tex-bibtex-file)
    (define-key map "\C-c\C-o" #'latex-insert-block)

    ;; Redundant keybindings, for consistency with SGML mode.
    (define-key map "\C-c\C-t" #'latex-insert-block)
    (define-key map "\C-c/" #'latex-close-block)

    (define-key map "\C-c\C-e" #'latex-close-block)
    (define-key map "\C-c\C-m" #'tex-feed-input)
(defvar latex-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "\C-c\C-s" #'latex-split-block)
All these key sequences have different binding in AUCTeX (+RefTeX).
Thus I don't see a clean way to meet the assumption "if we can arrange
for latex-mode and auctex-mode not to collide in their keymaps".

In addition, I'm afraid that menus and tool bars are intermixed if we
use `make-composed-keymap' for these two keymaps.

Of course it is still possible to proceed if AUCTeX mode uses
independent keymap such as LaTeX-mode-map, but it wouldn't help the case
that some AUCTeX user is tempted to customize latex-mode-map because of
the mode name being lower case `latex-mode'.

2. Thus I tried [B] next, in the hope that we can circumvent the above
mentioned difficulties by similar workarounds employed in the current
startup codes and announcement to the users.

If we are to take this approach, I think that the new mode name should
be, e.g., "LaTeX-mode" because the user-exposed functions and variables
have that prefix now. In my opinion, it doesn't make sense to choose
another name and rename all such occurences in AUCTeX source.

However, we can't do that in natural ways like
(define-derived-mode LaTeX-mode text-mode "LaTeX" ...
(defun LaTeX-mode () ...)
because tex-mode.el has these lines:
(defalias 'TeX-mode #'tex-mode)
(defalias 'plain-TeX-mode #'plain-tex-mode)
(defalias 'LaTeX-mode #'latex-mode)
These defalias'es overwrite the AUCTeX definition unconditionally if
tex-mode.el are loaded after AUCTeX. So AUCTeX has to do workarounds
(define-derived-mode TeX-latex-mode text-mode "LaTeX"
  (setq major-mode 'LaTeX-mode)
(defalias 'LaTeX-mode #'TeX-latex-mode)
and advertise `LaTeX-mode' as its official name. (Additionally, we need
some gotchas so that directory local variable entry like
should work.)

Hence I'd like to request to modify the built-in tex-modes.el to delete
those lines, or at least to do fboundp test like
(unless (fboundp 'LaTeX-mode)
  (defalias 'LaTeX-mode #'latex-mode))
in, say, emacs-30.

If that is accepted, we can clean up the above workarounds in the
future, when the least supported emacsen becomes emacs 30.

3. This topic is independent of [A] and [B]. Here is a correspondence
table of major modes:
|                  | built-in        | AUCTeX                      |
| LaTeX            | latex-mode      | latex-mode                  |
| plain TeX        | plain-tex-mode  | plain-tex-mode              |
| Texinfo          | texinfo-mode    | texinfo-mode (2)            |
| docTeX           | doctex-mode     | doctex-mode                 |
| ConTeXt          | NA              | context-mode                |
| ConTeXt (EN)     | NA              | context-en-mode (3)         |
| ConTeXt (NL)     | NA              | context-nl-mode (3)         |
| AmSTeX           | NA              | ams-tex-mode                |
| SliTeX           | slitex-mode     | NA                          |
| LaTeX     (JA)   | NA              | japanese-latex-mode     (3) |
| plain TeX (JA)   | NA              | japanese-plain-tex-mode (3) |
| (base)           | tex-mode        | NA (1)                      |
| (guess)          | tex--guess-mode | TeX-tex-mode                |

(1) There are `TeX-mode-map', `TeX-mode-syntax-table' and
`TeX-mode-hook' without associated major mode instead. The former two
are used as common parents of various keymaps and syntax tables. In
addition, AUCTeX has `VirTeX-common-initialization'.
(2) Doesn't run `TeX-mode-hook'.
(3) Dispatch function rather than a proper major mode.

I'd like to discuss dispatch functions context-**-mode and
japanese-**-mode here. They only do language-specific set-ups and turn
into context-mode, latex-mode and plain-tex-mode eventually. In some
aspects, they are similar with guess functions `tex--guess-mode' and
- They can be specified as `mode' tag of file local variable and entry
  of `auto-mode-alist'.
- They never hold their own `major-mode' value.
- When called, they eventually turn into another proper major mode.
Note that it isn't enough to do as
(define-derived-mode japanese-latex-mode latex-mode "LaTeX"
  (setq major-mode 'latex-mode)
because it doesn't respond to directory local variable entry of the form
in that case. In addition, they don't need their own keymaps and syntax
tables created by define-derived-mode. (Own hooks and abbrev tables may
be useful, though.)

So I hope emacs to have functionality to handle such dispatch functions
in a clean way. Is there any possibility?

Ikumi Keita
#StandWithUkraine #StopWarInUkraine

reply via email to

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