Hi all,

I attach a tentative patch to make AUCTeX major mode names not overwrap
built-in TeX modes. In this patch, the new mode names (value of
`major-mode') are
 - plain-TeX-mode
 - LaTeX-mode
 - docTeX-mode
 - Texinfo-mode
 - ConTeXt-mode
 - AmSTeX-mode
(There are additional renamed modes
   + japanese-plain-TeX-mode
   + japanese-LaTeX-mode
   + ConTeXt-en-mode
   + ConTeXt-nl-mode
 but they don't have their own `major-mode' value.
The name and role of `TeX-tex-mode' doesn't change.)

I think that its core functionality works as
expected. If you are interested in this feature, please give it a try.

1. I'd like to push it to savannah server as a feature branch of AUCTeX
   repository (it isn't ready to merge into master branch yet.) Do you
   think it's OK? If so, I'm not sure how to do that so I'd like to
   confirm.
   Now I have the following entries in .git/config. The name of my local
   branch is "feature/distinct-mode-name". 
----------------------------------------------------------------------
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
...
[branch "feature/distinct-mode-name"]
        remote = .
        merge = refs/heads/master
----------------------------------------------------------------------
   Probably, I should, in Magit, type b p on the local feature branch
   and set "origin" as the value of pushRemote. Then is it ready to push
   by typing "P"? Or should I do something else/different?
   (By the way, I have come up with only a poor name
    "feature/distinct-mode-name". Please tell me another name if you find
     a better one.)

2. Incompatibility
   I'm currently aware of the following incompatibilities:
   a. Invoked mode
   b. Abbrev table
   c. desktop.el
   d. Directory local variables
   There may be other issues I don't realize.

   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'.

      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.

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

   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.

   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'.

      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.
----------------------------------------------------------------------
    (when enable-local-variables
      (setq major-mode 'japanese-LaTeX-mode)
      (add-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name
                nil t))))
...
(defun japanese-TeX-reset-mode-name ()
  (cond ((eq major-mode 'japanese-LaTeX-mode)
         (setq major-mode 'LaTeX-mode))
        ((eq major-mode 'japanese-plain-TeX-mode)
         (setq major-mode 'plain-TeX-mode)))
  (remove-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name t))

;; Hack for directory local variable entry of the form (LaTeX-mode (...)) .
(put 'japanese-LaTeX-mode 'derived-mode-parent 'LaTeX-mode)
(put 'japanese-plain-TeX-mode 'derived-mode-parent 'plain-TeX-mode)
----------------------------------------------------------------------

3. Future plan
   My current plan is to proceed as follows:
   (1) Clean up major mode definitions by `define-derived-mode'.
   (2) Think how to solve the incompatibilities and implement them if
       good ideas are found.

   (1) I'm thinking to make the following parent-child relationships by
       `define-derived-mode':
text-mode -- Texinfo-mode
          \- TeX-VirTeX-mode (new)
TeX-VirTeX-mode -- plain-TeX-mode (TeX-plain-TeX-mode)
                \- LaTeX-mode     (TeX-LaTeX-mode)
                \- ConTeXt-mode
plain-TeX-mode -- AmSTeX-mode
               \- japanese-TeX-mode
LaTeX-mode -- docTeX-mode
           \- japanese-LaTeX-mode
ConTeXt-mode -- ConTeXt-en-mode
             \- ConTeXt-nl-mode

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

       - The role of `VirTeX-mode-common-initialization' will be
         absorbed in `TeX-VirTeX-mode'. Current variables `TeX-mode-map',
         `TeX-mode-hook' and `TeX-mode-syntax-table' will belong to
         `TeX-VirTeX-mode'. (`TeX-mode-map' will also be a parent of
         `Texinfo-mode-map'.)

       - The role of `LaTeX-mode-common-initialization' will be absorbed
         in `(TeX-)LaTeX-mode'.

       - On the other hand, `plain-TeX-mode-common-initialization' will
         remain because context mode calls it.

       - `ConTeXt-mode-common-initialization' will remain since it is
         designed to run _after_ language interface ("en" or "nl") is
         determined.

       - `japanese-{plain-TeX,LaTeX}-mode-initialization' will be
         absorbed in corresponding major modes.

       - As a result of AmSTeX-mode being the derived mode of
         plain-TeX-mode, it will run plain-TeX-mode-hook as well and
         obtain tool bar inherited from plain-TeX-mode-map. The latter
         isn't ideal since the bar doesn't have AmSTeX button, but I
         think that wouldn't matter since amstex is quite obsolete and
         there seems no practial users of ams-tex-mode.

   (2) I'd like to discuss good solutions for these issues.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

Attachment: patches.tar.gz
Description: application/gzip

Reply via email to