branch: externals/auctex
commit 48cc5069988ea1e278f184c236821179e2914a40
Merge: d7f1d28159 f06778a7ae
Author: Ikumi Keita <ik...@ikumi.que.jp>
Commit: Ikumi Keita <ik...@ikumi.que.jp>

    Merge branch 'feature/fix-mode-names-overlap'
---
 .dir-locals.el                 |   2 +-
 context-en.el                  |  19 +--
 context-nl.el                  |  20 +--
 context.el                     |  52 ++++----
 doc/auctex.texi                |  50 +++----
 doc/changes.texi               | 167 ++++++++++++++++++++++-
 doc/install.texi               |   2 +-
 doc/preview-faq.texi           |   5 +
 doc/preview-problems.texi      |   5 +
 doc/preview-readme.texi        |   5 +
 doc/preview-todo.texi          |   5 +
 doc/quickstart.texi            |   2 +-
 doc/todo.texi                  |   2 +-
 font-latex.el                  |  22 ++--
 latex.el                       | 205 ++++++++++++++--------------
 latex/preview.dtx              |   2 +-
 plain-tex.el                   | 110 +++++++++-------
 preview.el.in                  |  14 +-
 style/amstex.el                |   2 +-
 tests/japanese/parse-timing.el |   3 +-
 tests/latex/latex-test.el      |  14 +-
 tests/tex/command-expansion.el |   2 +-
 tex-bar.el                     |   4 +-
 tex-fold.el                    |  20 +--
 tex-info.el                    |  33 ++---
 tex-jp.el                      | 150 ++++++++++-----------
 tex-site.el.in                 |  73 +++++++---
 tex.el                         | 293 +++++++++++++++++++++++++----------------
 texmathp.el                    |   2 +-
 29 files changed, 773 insertions(+), 512 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
index 58cf88a2aa..2e19675b51 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -12,7 +12,7 @@
                      (electric-quote-comment . nil)
                      (electric-quote-string . nil)
                      (indent-tabs-mode . nil)))
- (texinfo-mode . ((mode . bug-reference-prog)
+ (Texinfo-mode . ((mode . bug-reference-prog)
                   (electric-quote-comment . nil)
                   (electric-quote-string . nil)
                   (fill-column . 74))))
diff --git a/context-en.el b/context-en.el
index 62394206ce..c63a4fd1d4 100644
--- a/context-en.el
+++ b/context-en.el
@@ -188,8 +188,6 @@ That is, besides the section(-block) commands.")
 
 (defun ConTeXt-en-mode-initialization ()
   "ConTeXt english interface specific initialization."
-  ;; FIXME: Move to `ConTeXt-mode-common-initialization' replacing
-  ;; `ConTeXt-environment-list-en' with `ConTeXt-environment-list'?
   (mapc #'ConTeXt-add-environments (reverse ConTeXt-environment-list-en))
 
   (TeX-add-symbols
@@ -202,17 +200,10 @@ That is, besides the section(-block) commands.")
    '("sub" ConTeXt-arg-define-ref (TeX-arg-literal " "))
    '("sym" (TeX-arg-string "Symbol") (TeX-arg-literal " "))))
 
-;;;###autoload
-(defun context-en-mode ()
-  "Major mode for editing files for ConTeXt using its english interface.
+(defun ConTeXt--mode-en ()
+  "Set up ConTeXt mode for editing files under english interface.
+Helper function of `ConTeXt-mode'.  Don't use."
 
-Special commands:
-\\{ConTeXt-mode-map}
-
-Entering `context-mode' calls the value of `text-mode-hook',
-then the value of `TeX-mode-hook', and then the value
-of `ConTeXt-mode-hook'."
-  (interactive)
   ;; set the ConTeXt interface
   (setq ConTeXt-current-interface "en")
 
@@ -220,9 +211,7 @@ of `ConTeXt-mode-hook'."
   (ConTeXt-mode-common-initialization)
   (ConTeXt-en-mode-initialization)
 
-  ;; set mode line
-  (setq TeX-base-mode-name "ConTeXt-en")
-  (TeX-set-mode-name))
+  (setq mode-name "ConTeXt-en"))
 
 (provide 'context-en)
 
diff --git a/context-nl.el b/context-nl.el
index 825ee9fa74..721b127f61 100644
--- a/context-nl.el
+++ b/context-nl.el
@@ -166,8 +166,6 @@ That is, besides the section(-block) commands.")
 
 (defun ConTeXt-nl-mode-initialization ()
   "ConTeXt dutch interface specific initialization."
-  ;; FIXME: Move to `ConTeXt-mode-common-initialization' replacing
-  ;; `ConTeXt-environment-list-nl' with `ConTeXt-environment-list'?
   (mapc #'ConTeXt-add-environments (reverse ConTeXt-environment-list-nl))
 
   (TeX-add-symbols
@@ -180,17 +178,9 @@ That is, besides the section(-block) commands.")
    '("sub" ConTeXt-arg-define-ref (TeX-arg-literal " "))
    '("sym" (TeX-arg-string "Symbol") (TeX-arg-literal " "))))
 
-;;;###autoload
-(defun context-nl-mode ()
-  "Major mode for editing files for ConTeXt using its dutch interface.
-
-Special commands:
-\\{ConTeXt-mode-map}
-
-Entering `context-mode' calls the value of `text-mode-hook',
-then the value of `TeX-mode-hook', and then the value
-of `ConTeXt-mode-hook'."
-  (interactive)
+(defun ConTeXt--mode-nl ()
+  "Set up ConTeXt mode for editing files under dutch interface.
+Helper function of `ConTeXt-mode'.  Don't use."
 
   ;; set the ConTeXt interface
   (setq ConTeXt-current-interface "nl")
@@ -199,9 +189,7 @@ of `ConTeXt-mode-hook'."
   (ConTeXt-mode-common-initialization)
   (ConTeXt-nl-mode-initialization)
 
-  ;; set mode line
-  (setq TeX-base-mode-name "ConTeXt-nl")
-  (TeX-set-mode-name))
+  (setq mode-name "ConTeXt-nl"))
 
 (provide 'context-nl)
 
diff --git a/context.el b/context.el
index c219237dda..5ee0217d91 100644
--- a/context.el
+++ b/context.el
@@ -942,7 +942,7 @@ An entry looks like: (\"environment\" . function)")
   (metapost-mode)
   (message "Type `M-x exit-recursive-edit' to get back")
   (recursive-edit)
-  (context-mode)
+  (ConTeXt-mode)
   (widen))
 
 ;; find smarter name.  Suggestions welcome
@@ -1593,7 +1593,7 @@ else.  There might be text before point."
 (easy-menu-define ConTeXt-mode-command-menu
   ConTeXt-mode-map
   "Command menu used in ConTeXt mode."
-  (TeX-mode-specific-command-menu 'context-mode))
+  (TeX-mode-specific-command-menu 'ConTeXt-mode))
 
 ;; it seems the menu is evaluated at compile/load-time
 ;; we don't have ConTeXt-current-interface at that time
@@ -1656,7 +1656,7 @@ else.  There might be text before point."
 
 (defun ConTeXt-menu-update (&optional menu)
   "Update entries on AUCTeX menu."
-  (or (not (memq major-mode '(context-mode)))
+  (or (not (memq major-mode '(ConTeXt-mode)))
       (null ConTeXt-menu-changed)
       (progn
         (TeX-update-style)
@@ -1816,20 +1816,12 @@ that is, you do _not_ have to cater for this yourself 
by adding \\\\\\=' or $."
   :type '(repeat regexp)
   :group 'TeX-command)
 
-(TeX-abbrev-mode-setup context-mode)
+(TeX-abbrev-mode-setup ConTeXt-mode context-mode-abbrev-table)
 
 (defun ConTeXt-mode-common-initialization ()
   "Initialization code that is common for all ConTeXt interfaces."
-  ;; `plain-TeX-common-initialization' kills all local variables, but
-  ;; we need to keep ConTeXt-current-interface, so save and restore
-  ;; it.
-  (let (save-ConTeXt-current-interface)
-    (setq save-ConTeXt-current-interface ConTeXt-current-interface)
-    (plain-TeX-common-initialization)
-    (setq ConTeXt-current-interface save-ConTeXt-current-interface))
-  (setq major-mode 'context-mode)
-
-  (setq local-abbrev-table context-mode-abbrev-table)
+  (plain-TeX-common-initialization)
+
   (set (make-local-variable 'TeX-style-hook-dialect) ConTeXt-dialect)
 
   (require (intern (concat "context-" ConTeXt-current-interface)))
@@ -1846,9 +1838,6 @@ that is, you do _not_ have to cater for this yourself by 
adding \\\\\\=' or $."
   (or ConTeXt-largest-level
       (setq ConTeXt-largest-level 2))
 
-  ;; keybindings
-  (use-local-map ConTeXt-mode-map)
-
   ;; Indenting
   (set (make-local-variable 'indent-line-function) #'ConTeXt-indent-line)
   (set (make-local-variable 'fill-indent-according-to-mode) t)
@@ -1875,7 +1864,6 @@ that is, you do _not_ have to cater for this yourself by 
adding \\\\\\=' or $."
          "\\|$\\)"))
 
   ;; Keybindings and menu
-  (use-local-map ConTeXt-mode-map)
   (setq ConTeXt-menu-changed t)
 
   ;; FIXME: Isn't `activate-menubar-hook' obsolete?
@@ -1900,11 +1888,12 @@ that is, you do _not_ have to cater for this yourself 
by adding \\\\\\=' or $."
   (set (make-local-variable 'imenu-create-index-function)
        #'ConTeXt-imenu-create-index-function)
 
-  ;; run hooks
   (setq TeX-command-default "ConTeXt")
-  (setq TeX-sentinel-default-function #'TeX-ConTeXt-sentinel)
-  (run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'ConTeXt-mode-hook)
+  (setq TeX-sentinel-default-function #'TeX-ConTeXt-sentinel))
 
+(defun ConTeXt-mode-cleanup ()
+  "Cleanup function for `ConTeXt-mode'.
+Run after mode hooks and file local variables application."
   ;; Create certain regular expressions based on language.
   ;; Don't overwrite the value the user set by hooks or file
   ;; (directory) variables.
@@ -1947,22 +1936,27 @@ that is, you do _not_ have to cater for this yourself 
by adding \\\\\\=' or $."
                  ConTeXt-default-interface)))))
 
 ;;;###autoload
-(defalias 'ConTeXt-mode #'context-mode)
+(defalias 'context-mode #'ConTeXt-mode)
 
 ;;;###autoload
-(defun context-mode ()
+(define-derived-mode ConTeXt-mode TeX-mode "ConTeXt"
   "Major mode in AUCTeX for editing ConTeXt files.
 
-Special commands:
-\\{ConTeXt-mode-map}
-
-Entering `context-mode' calls the value of `text-mode-hook',
+Entering `ConTeXt-mode' calls the value of `text-mode-hook',
 then the value of `TeX-mode-hook', and then the value
 of `ConTeXt-mode-hook'."
-  (interactive)
+  :after-hook (ConTeXt-mode-cleanup)
   (context-guess-current-interface)
   (require (intern (concat "context-" ConTeXt-current-interface)))
-  (funcall (intern (concat "context-" ConTeXt-current-interface "-mode"))))
+  (funcall (intern (concat "ConTeXt--mode-" ConTeXt-current-interface)))
+
+  ;; set mode line
+  (setq TeX-base-mode-name mode-name))
+
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `context-mode' continue to be valid for
+;; `ConTeXt-mode'.
+(TeX-derived-mode-add-parents 'ConTeXt-mode '(context-mode))
 
 (provide 'context)
 
diff --git a/doc/auctex.texi b/doc/auctex.texi
index c8bfbb5575..c4cd025761 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -3302,7 +3302,7 @@ Another possibility is to use file local additions at the 
end of your
 @TeX{} file, e.g.:
 @example
 %%% Local Variables:
-%%% mode: latex
+%%% mode: LaTeX
 %%% TeX-master: t
 %%% eval: (TeX-ispell-skip-setcar '(("\\\\mymacro" . "@{[-0-9]+@}")))
 %%% End:
@@ -4107,7 +4107,7 @@ documents and all files in a multifile document.  For 
example,
 
 @example
 %%% Local Variables:
-%%% mode: latex
+%%% mode: LaTeX
 %%% TeX-output-dir: "build"
 %%% End:
 @end example
@@ -4236,26 +4236,26 @@ order.  (As an exception, Texinfo mode does not run 
@code{TeX-mode-hook}.)
 The following table provides an overview of the respective mode
 functions and hooks.
 
-@multitable {Plain @TeX{}} {@code{plain-tex-mode}} {@code{plain-TeX-mode-hook}}
+@multitable {Plain @TeX{}} {@code{plain-TeX-mode}} {@code{plain-TeX-mode-hook}}
 @headitem Type @tab Mode function @tab Hook
-@item Plain @TeX{} @tab @code{plain-tex-mode} @tab @code{plain-TeX-mode-hook}
-@item @LaTeX{}     @tab @code{latex-mode}     @tab @code{LaTeX-mode-hook}
-@item AMS-@TeX{}   @tab @code{ams-tex-mode}   @tab @code{AmS-TeX-mode-hook}
-@item @ConTeXt{}   @tab @code{context-mode}   @tab @code{ConTeXt-mode-hook}
-@item Texinfo      @tab @code{texinfo-mode}   @tab @code{Texinfo-mode-hook}
-@item Doc@TeX{}    @tab @code{doctex-mode}    @tab @code{docTeX-mode-hook}
+@item Plain @TeX{} @tab @code{plain-TeX-mode} @tab @code{plain-TeX-mode-hook}
+@item @LaTeX{}     @tab @code{LaTeX-mode}     @tab @code{LaTeX-mode-hook}
+@item AMS-@TeX{}   @tab @code{AmSTeX-mode}    @tab @code{AmSTeX-mode-hook}
+@item @ConTeXt{}   @tab @code{ConTeXt-mode}   @tab @code{ConTeXt-mode-hook}
+@item Texinfo      @tab @code{Texinfo-mode}   @tab @code{Texinfo-mode-hook}
+@item Doc@TeX{}    @tab @code{docTeX-mode}    @tab @code{docTeX-mode-hook}
 @end multitable
-@findex plain-tex-mode
+@findex plain-TeX-mode
 @vindex plain-TeX-mode-hook
-@findex latex-mode
+@findex LaTeX-mode
 @vindex LaTeX-mode-hook
-@findex ams-tex-mode
-@vindex AmS-TeX-mode-hook
-@findex context-mode
+@findex AmSTeX-mode
+@vindex AmSTeX-mode-hook
+@findex ConTeXt-mode
 @vindex ConTeXt-mode-hook
-@findex texinfo-mode
+@findex Texinfo-mode
 @vindex Texinfo-mode-hook
-@findex doctex-mode
+@findex docTeX-mode
 @vindex docTeX-mode-hook
 
 If you need to make a customization via a hook which is only relevant
@@ -4264,6 +4264,10 @@ if it is relevant for any @AUCTeX{} mode, add it to 
@code{TeX-mode-hook}
 and if it is relevant for all text modes, append it to
 @code{text-mode-hook}.
 
+Now doc@TeX{} mode is child of @LaTeX{} mode, so doc@TeX{} mode runs
+@code{LaTeX-mode-hook} as well.  Similarly, AmS@TeX{} mode is child of plain
+@TeX{} mode and runs @code{plain-TeX-mode-hook} as well.
+
 Other useful hooks are listed below.
 
 @defvr Variable TeX-after-compilation-finished-functions
@@ -4866,15 +4870,15 @@ press.  If @code{nil} do it the other way round.
 @vindex TeX-engine
 @vindex TeX-engine-alist
 @vindex japanese-TeX-mode
-@findex japanese-plain-tex-mode
-@findex japanese-latex-mode
+@findex japanese-plain-TeX-mode
+@findex japanese-LaTeX-mode
 
 To write Japanese text with @AUCTeX{}, you need the versions of
 @TeX{} and Emacs that support Japanese.  @AUCTeX{} supports three
 Japanese @TeX{} engines by default: NTT j@TeX{}, ASCII p@TeX{} and
 up@TeX{}.
 
-Activate @code{japanese-plain-tex-mode} or @code{japanese-latex-mode} to
+Activate @code{japanese-plain-TeX-mode} or @code{japanese-LaTeX-mode} to
 use the Japanese @TeX{} engines.  If it doesn't work, send mail to
 Masayuki Ataka @email{masayuki.ataka@@gmail.com} or Ikumi Keita
 @email{ikumikeita@@jcom.home.ne.jp}, who currently concern with stuff
@@ -4882,7 +4886,7 @@ related to Japanese in @AUCTeX{}.  None of the primary 
@AUCTeX{}
 maintainers understand Japanese, so they cannot help you.
 
 It is recommended to enable @code{TeX-parse-self} for typical Japanese
-@LaTeX{} users.  When enabled, @code{japanese-latex-mode} selects the
+@LaTeX{} users.  When enabled, @code{japanese-LaTeX-mode} selects the
 suitable Japanese @TeX{} engine automatically based on the class file
 name (such as @code{jbook}, @code{jsarticle} and @code{tjreport}) and
 its option.  @xref{Parsing Files}.
@@ -4916,7 +4920,7 @@ Here is a sample code to set @code{TeX-engine} to 
@samp{uptex}:
 
 @example
 %%% Local Variables:
-%%% mode: japanese-latex
+%%% mode: japanese-LaTeX
 %%% TeX-engine: uptex
 %%% End:
 @end example
@@ -4947,7 +4951,7 @@ file is plain @TeX{} or @LaTeX{} or what.
 If you want to enter Japanese @LaTeX{} mode whenever this may happen,
 set the variable like this:
 @lisp
-(setq TeX-default-mode 'japanese-latex-mode)
+(setq TeX-default-mode 'japanese-LaTeX-mode)
 @end lisp
 @end defopt
 
@@ -6323,7 +6327,7 @@ used by @AUCTeX{} for inserting @samp{@@node}.
 @bye
 
 @c Local Variables:
-@c mode: texinfo
+@c mode: Texinfo
 @c coding: utf-8
 @c TeX-master: t
 @c End:
diff --git a/doc/changes.texi b/doc/changes.texi
index ef79775706..63eb4ccf85 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -8,6 +8,171 @@
 
 @end ifset
 
+@heading News in 14.1
+
+@itemize @bullet
+@item
+@AUCTeX{} changes major mode names.  Its primary purpose is to avoid
+conflicts with Emacs built-in @TeX{} major modes.  It also improves
+consistency of the source code.
+
+@itemize @minus
+@item
+The overview of the former names and new names are:
+
+@multitable {@code{japanese-plain-tex-mode}} {@code{japanese-plain-TeX-mode}}
+@headitem Former name @tab New name
+@item @code{plain-tex-mode} @tab @code{plain-TeX-mode}
+@item @code{latex-mode} @tab @code{LaTeX-mode}
+@item @code{doctex-mode} @tab @code{docTeX-mode}
+@item @code{context-mode} @tab @code{ConTeXt-mode}
+@item @code{texinfo-mode} @tab @code{Texinfo-mode}
+@item @code{ams-tex-mode} @tab @code{AmSTeX-mode}
+@item @code{japanese-plain-tex-mode} @tab @code{japanese-plain-TeX-mode}
+@item @code{japanese-latex-mode} @tab @code{japanese-LaTeX-mode}
+@end multitable
+
+The undocumented modes @code{context-en-mode} and @code{context-nl-mode}
+were deleted.
+
+@item
+We paid much attention to the compatibility and expect that almost no
+particular treatment on the user side is needed.  For example, the names
+of the keymaps and mode hooks remain unchanged, and the @samp{mode:} tag
+in the file local variables in the existing files works with old mode
+names.  See below for more details.
+
+@item
+If your Emacs is 29 or newer and you use @file{desktop.el} to save and
+restore Emacs sessions, be careful before you update @AUCTeX{}; You should
+attempt to update only after
+@enumerate
+@item
+you kill all buffer under former @AUCTeX{} modes which have overlapped
+name with Emacs built-in @TeX{} modes, and
+@item
+you terminate the current Emacs session.
+@end enumerate
+The modes with such overlapped name are @code{plain-tex-mode},
+@code{latex-mode}, @code{doctex-mode} and @code{texinfo-mode}. (The above
+prescription ensures no buffer of such modes is recorded in the desktop
+file.  Otherwise those buffers would be restored in the built-in modes,
+not @AUCTeX{} modes, after the update of @AUCTeX{}.)
+
+@item
+New mode names are chosen to match the existing variables, so most user
+customizations as well as the third party libraries would continue to work
+without modification.  For example, names of keymaps and hooks don't
+change as stated above.  (@code{AmS-TeX-mode-hook} is renamed to
+@code{AmSTeX-mode-hook}, but compatibility alias is provided.)
+
+@item
+Now @code{TeX-add-local-master} adds entry of new mode names such as
+
+@example
+%%% Local Variables:
+%%% mode: LaTeX      <-- not `latex'
+%%% End:
+@end example
+
+@item
+The compatibility with the former mode names with respect to invoking the
+major mode are retained.
+
+@enumerate
+@item
+Former modes which overlap with built-in modes, namely
+@code{plain-tex-mode}, @code{latex-mode}, @code{doctex-mode},
+@code{texinfo-mode} and @code{tex-mode} are handled by redirections; the
+same override advices as before are continued to used for Emacs @math{<29}
+while @code{major-mode-remap-alist} is used for Emacs 29 and later.
+(Therefore, if there are user codes which call @code{latex-mode}
+directly, built-in @code{latex-mode} runs instead of @AUCTeX{}
+@code{LaTeX-mode} in Emacs 29 and later.)
+
+These redirections still honor your customization to @code{TeX-modes}
+option.  Thus you are served by built-in @code{plain-tex-mode} and
+@AUCTeX{} @code{LaTeX-mode} if you exclude @code{plain-tex-mode} from
+@code{TeX-modes}.
+
+@item
+Other former names, e.g.@: @code{context-mode} and
+@code{japanese-latex-mode}, are handled by aliases such as
+
+@lisp
+(defalias 'context-mode #'ConTeXt-mode)
+@end lisp
+@end enumerate
+
+@item
+New modes recognize directory local variables prepaired for the former
+mode name.  For example, directory local variables for @code{latex-mode}
+are valid in @code{LaTeX-mode} as well.  So you don't have to rewrite
+every former mode name to the new one in @file{.dir-locals.el}.
+
+@item
+Your abbrevs are preserved.  For example, @code{latex-mode-abbrev-table},
+if exists, is automatically included as a parent of
+@code{LaTeX-mode-abbrev-table}.
+
+@item
+Now all major modes are defined by @code{define-derived-mode}, so standard
+inheritance of keymaps, syntax tables etc.@: takes place.  The inheritance
+relations are:
+@verbatim
+text-mode      --+-- TeX-mode
+                 +-- Texinfo-mode
+
+TeX-mode       --+-- plain-TeX-mode
+                 +-- LaTeX-mode
+                 +-- ConTeXt-mode
+
+plain-TeX-mode --+-- AmSTeX-mode
+                 +-- japanese-plain-TeX-mode
+
+LaTeX-mode     --+-- docTeX-mode
+                 +-- japanese-LaTeX-mode
+@end verbatim
+
+These inheritance relations are taken into account for directory local
+variables in the standard way.  For example, directory local variables for
+@code{LaTeX-mode} are applied to @code{docTeX-mode} now.
+
+Note that @code{TeX-mode} isn't meant for use for end users.  It is only
+meant for the base mode for other major modes.  Its role is to provide
+base keymap, hook and syntax table under the same name with the former
+@AUCTeX{} and run the common initialization code.
+
+Now that all modes have @code{text-mode} as their ancestor, they inherit
+its keymap and syntax table.  In addition, dir local vars for
+@code{text-mode} are applied to all @AUCTeX{} major mode.
+
+However, @code{Texinfo-mode} is exceptional in the following two aspects:
+@enumerate
+@item
+It doesn't inherit @code{text-mode-syntax-table} because it simply uses
+built-in mode's @code{texinfo-mode-syntax-table}, which is independent of
+@code{text-mode-syntax-table}.  This situation is the same with the former
+@AUCTeX{} Texinfo mode.
+
+@item
+@code{Texinfo-mode-map} has @code{TeX-mode-map} as its direct parent.
+This is the same with the former @AUCTeX{} Texinfo mode.  Now it inherits
+@code{text-mode-map} indirectly through @code{TeX-mode-map}.
+@end enumerate
+
+@c Need to mention AmSTeX-mode as well?
+
+@item
+There are new keymaps, hooks and abbrev tables:
+@code{Texinfo-mode-abbrev-table}, @code{japanese-plain-TeX-mode-map},
+@code{japanese-LaTeX-mode-map}, @code{japanese-plain-TeX-mode-hook},
+@code{japanese-LaTeX-mode-hook},
+@code{japanese-plain-TeX-mode-abbrev-table},
+@code{japanese-LaTeX-mode-abbrev-table}
+@end itemize
+@end itemize
+
 @heading News since last release
 
 @itemize @bullet
@@ -1773,6 +1938,6 @@ Bug fixes.
 @end itemize
 
 @c Local Variables:
-@c mode: texinfo
+@c mode: Texinfo
 @c TeX-master: "auctex"
 @c End:
diff --git a/doc/install.texi b/doc/install.texi
index 29b176358c..52be62f932 100644
--- a/doc/install.texi
+++ b/doc/install.texi
@@ -623,6 +623,6 @@ set the variable for you if it could use the program 
@command{kpsewhich}.
 In this case you normally don't have to alter anything.
 
 @c Local Variables:
-@c mode: texinfo
+@c mode: Texinfo
 @c TeX-master: "auctex"
 @c End:
diff --git a/doc/preview-faq.texi b/doc/preview-faq.texi
index 0323a0bd9c..95d70f05de 100644
--- a/doc/preview-faq.texi
+++ b/doc/preview-faq.texi
@@ -304,3 +304,8 @@ file looking like the following:
 \end@{plain@}
 \end@{document@}
 @end example
+
+@c Local Variables:
+@c mode: Texinfo
+@c TeX-master: "preview-latex"
+@c End:
diff --git a/doc/preview-problems.texi b/doc/preview-problems.texi
index 0f1518bfa5..57a1a18579 100644
--- a/doc/preview-problems.texi
+++ b/doc/preview-problems.texi
@@ -204,3 +204,8 @@ rendered as black in the preview images, so it's almost 
impossible to read
 them on dark background.  Hence Xe@LaTeX{} users who like dark background
 in Emacs frame should customize @code{preview-pdf-adjust-color-method} to
 @code{nil}.
+
+@c Local Variables:
+@c mode: Texinfo
+@c TeX-master: "preview-latex"
+@c End:
diff --git a/doc/preview-readme.texi b/doc/preview-readme.texi
index 8d4c5651a1..079fe08919 100644
--- a/doc/preview-readme.texi
+++ b/doc/preview-readme.texi
@@ -227,3 +227,8 @@ to show your appreciation with a donation to the main 
developer, you can
 do so via PayPal to @email{dak@@gnu.org}, and of course you can arrange
 for service contracts or for added functionality.  Take a look at the
 @file{TODO} list for suggestions in that area.
+
+@c Local Variables:
+@c mode: Texinfo
+@c TeX-master: "preview-latex"
+@c End:
diff --git a/doc/preview-todo.texi b/doc/preview-todo.texi
index 485373ee0c..ce2236b116 100644
--- a/doc/preview-todo.texi
+++ b/doc/preview-todo.texi
@@ -116,3 +116,8 @@ replace the whole color and image handling with 
@acronym{GDK} routines
 when this library is available, since it has been optimized for it.
 
 @end itemize
+
+@c Local Variables:
+@c mode: Texinfo
+@c TeX-master: "preview-latex"
+@c End:
diff --git a/doc/quickstart.texi b/doc/quickstart.texi
index d0fdf78e1a..8f5f7ac00c 100644
--- a/doc/quickstart.texi
+++ b/doc/quickstart.texi
@@ -322,6 +322,6 @@ files.  It will run @command{latex} only on the current 
buffer, using the
 preamble from the master file.
 
 @c Local Variables: 
-@c mode: texinfo
+@c mode: Texinfo
 @c TeX-master: "auctex"
 @c End: 
diff --git a/doc/todo.texi b/doc/todo.texi
index 6819ce1718..a09313078c 100644
--- a/doc/todo.texi
+++ b/doc/todo.texi
@@ -341,6 +341,6 @@ Correct indentation for tabbing, table, and math 
environments.
 @end itemize
 
 @c Local Variables:
-@c mode: texinfo
+@c mode: Texinfo
 @c TeX-master: "auctex"
 @c End:
diff --git a/font-latex.el b/font-latex.el
index 45ef8dd967..6e06d481bb 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -1301,7 +1301,7 @@ triggers Font Lock to recognize the change."
 
 (defun font-latex--make-syntax-propertize-function ()
   "Return a `syntax-propertize-function' for (La|Doc)TeX documents."
-  (let ((kws ;; (if (derived-mode-p 'doctex-mode)
+  (let ((kws ;; (if (derived-mode-p 'docTeX-mode)
              ;;     font-latex-doctex-syntactic-keywords
                font-latex-syntactic-keywords)) ;; )
     (syntax-propertize-via-font-lock kws)))
@@ -1316,10 +1316,10 @@ triggers Font Lock to recognize the change."
 
   ;; The test for `major-mode' currently only works with docTeX mode
   ;; because `TeX-install-font-lock' is called explicitly in
-  ;; `doctex-mode'.  In case other modes have to be distinguished as
-  ;; well, remove the call to `TeX-install-font-lock' from
-  ;; `VirTeX-common-initialization' and place it in the different
-  ;; `xxx-mode' calls instead, but _after_ `major-mode' is set.
+  ;; `docTeX-mode'.  In case other modes have to be distinguished as
+  ;; well, remove the call to `TeX-install-font-lock' from `TeX-mode'
+  ;; and place it in the different `xxx-mode' calls instead, but
+  ;; _after_ `major-mode' is set.
   (let ((defaults
          `((font-latex-keywords font-latex-keywords-1 font-latex-keywords-2)
            nil nil ,font-latex-syntax-alist nil))
@@ -1340,7 +1340,7 @@ triggers Font Lock to recognize the change."
             syntax-propertize-wholelines
             font-latex-sp-extend-region-backwards-verb-env))))
     ;; Add the mode-dependent stuff to the basic variables defined above.
-    (if (eq major-mode 'doctex-mode)
+    (if (eq major-mode 'docTeX-mode)
         (progn
           (setcar defaults (append (car defaults)
                                    '(font-latex-doctex-keywords)))
@@ -1455,7 +1455,7 @@ OPENCHAR is the opening character and CLOSECHAR is the 
closing
 character.  Character pairs are usually { } or [ ].  Comments are
 ignored during the search."
   (let ((parse-sexp-ignore-comments
-         (not (eq major-mode 'doctex-mode))) ; scan-sexps ignores comments
+         (not (eq major-mode 'docTeX-mode))) ; scan-sexps ignores comments
         (init-point (point))
         (mycount 1)
         (esc-char (or (and (boundp 'TeX-esc) TeX-esc) "\\"))
@@ -1508,7 +1508,7 @@ ignored during the search."
       (forward-line 0)
       (if (and (eq (char-after) ?\%)
                (not (font-latex-faces-present-p 'font-latex-verbatim-face)))
-          (not (eq major-mode 'doctex-mode))
+          (not (eq major-mode 'docTeX-mode))
         (catch 'found
           (while (progn (skip-chars-forward "^%" limit)
                         (< (point) limit))
@@ -1536,7 +1536,7 @@ If POS is omitted, the current position of point is used."
 (defun font-latex-forward-comment ()
   "Like `forward-comment' but with special provisions for docTeX mode.
 In docTeX mode \"%\" at the start of a line will be treated as whitespace."
-  (if (eq major-mode 'doctex-mode)
+  (if (eq major-mode 'docTeX-mode)
       ;; XXX: We should probably cater for ^^A as well.
       (progn
         (while (progn (if (bolp) (skip-chars-forward "%"))
@@ -1563,7 +1563,7 @@ Set this to nil if verification of command syntax is 
unwanted.")
   '((?\[ . ?\]) (?< . ?>) (?\( . ?\)))
   "List character pairs used as delimiters for optional arguments.")
 
-(defvar font-latex-syntax-error-modes '(latex-mode)
+(defvar font-latex-syntax-error-modes '(LaTeX-mode)
   "List of modes where syntax errors in macros should be indicated.")
 
 (defun font-latex-match-command-with-arguments (regexp keywords face limit)
@@ -1792,7 +1792,7 @@ cases.")
          (pos (funcall search)))
     (while (and pos
                 (member (match-string 1)
-                        (if (eq major-mode 'doctex-mode)
+                        (if (eq major-mode 'docTeX-mode)
                             (remove "_" font-latex-match-simple-exclude-list)
                           font-latex-match-simple-exclude-list)))
       (setq pos (funcall search)))
diff --git a/latex.el b/latex.el
index 6da12d457b..e385934b6f 100644
--- a/latex.el
+++ b/latex.el
@@ -117,7 +117,7 @@ This depends on `LaTeX-insert-into-comments'."
 
 ;;; Syntax Table
 
-(defvar LaTeX-mode-syntax-table (copy-syntax-table TeX-mode-syntax-table)
+(defvar LaTeX-mode-syntax-table (make-syntax-table TeX-mode-syntax-table)
   "Syntax table used in LaTeX mode.")
 
 (progn ; set [] to match for LaTeX.
@@ -938,7 +938,7 @@ Assume the current point is on neither \"begin{foo}\" nor 
\"end{foo}\"."
                 ;; comment-prefix.  Hence, the next check just looks
                 ;; if we're inside such a group and returns non-nil to
                 ;; recognize such a situation.
-                (and (eq major-mode 'doctex-mode)
+                (and (eq major-mode 'docTeX-mode)
                      (looking-at-p (concat (regexp-quote TeX-esc)
                                    "\\(?:begin\\|end\\) *{macrocode\\*?}"))))
         (setq arg (if (= (char-after (match-beginning 1)) ?e)
@@ -4104,7 +4104,7 @@ consideration just as is in the non-commented source 
code."
 ;;
 ;; Comments can be filled syntax-aware or not.
 ;;
-;; In `doctex-mode' line comments should always be indented
+;; In `docTeX-mode' line comments should always be indented
 ;; syntax-aware and the comment character has to be anchored at the
 ;; first column (unless the appear in a macrocode environment).  Other
 ;; comments not in the documentation parts always start after the
@@ -4115,7 +4115,7 @@ consideration just as is in the non-commented source 
code."
 ;; `LaTeX-syntactic-comments' disabled, line comments should still be
 ;; indented syntax-aware.
 ;;
-;; In `latex-mode' comments starting in different columns don't have
+;; In `LaTeX-mode' comments starting in different columns don't have
 ;; to be handled differently.  They don't have to be anchored in
 ;; column one.  That means that in any case indentation before and
 ;; after the comment characters has to be checked and adjusted.
@@ -4339,7 +4339,7 @@ the regexp's which are stored in
 `LaTeX-indent-mid-regexp-local' and
 `LaTeX-indent-end-regexp-local' accordingly.  Some standard
 macros are added to the regexp's.  This function is called in
-`LaTeX-common-initialization' to set the regexp's."
+`LaTeX-mode-cleanup' to set the regexp's."
   (let* (cmds
          symbs
          (func (lambda (in regexp out)
@@ -4393,9 +4393,9 @@ Lines starting with an item is given an extra indentation 
of
                  (concat (match-string 0) (TeX-comment-padding-string))))))
     (save-excursion
       (cond ((and fill-prefix
-                  (eq major-mode 'doctex-mode)
+                  (eq major-mode 'docTeX-mode)
                   (TeX-in-line-comment))
-             ;; If point is in a line comment in `doctex-mode' we only
+             ;; If point is in a line comment in `docTeX-mode' we only
              ;; consider the inner indentation.  An exception is when
              ;; we're inside a verbatim environment where we don't
              ;; want to touch the indentation, notably with a
@@ -4469,7 +4469,7 @@ outer indentation in case of a commented line.  The 
symbols
           entry
           found)
       (cond ((save-excursion (beginning-of-line) (bobp)) 0)
-            ((and (eq major-mode 'doctex-mode)
+            ((and (eq major-mode 'docTeX-mode)
                   fill-prefix
                   (TeX-in-line-comment)
                   (progn
@@ -4585,7 +4585,7 @@ outer indentation in case of a commented line.  The 
symbols
         comment-current-flag
         comment-last-flag
         (indent-across-comments (or docTeX-indent-across-comments
-                                    (not (eq major-mode 'doctex-mode)))))
+                                    (not (eq major-mode 'docTeX-mode)))))
     (beginning-of-line)
     (setq line-comment-current-flag (TeX-in-line-comment)
           comment-current-flag (TeX-in-commented-line))
@@ -4614,7 +4614,7 @@ outer indentation in case of a commented line.  The 
symbols
     ;; code comments).  Additionally we don't want to compute inner
     ;; indentation when a commented and a non-commented line are
     ;; compared.
-    (cond ((or (and (eq major-mode 'doctex-mode)
+    (cond ((or (and (eq major-mode 'docTeX-mode)
                     (or (and line-comment-current-flag
                              (not line-comment-last-flag))
                         (and (not line-comment-current-flag)
@@ -4635,7 +4635,7 @@ outer indentation in case of a commented line.  The 
symbols
               ;; Some people have opening braces at the end of the
               ;; line, e.g. in case of `\begin{letter}{%'.
               (TeX-brace-count-line)))
-          ((and (eq major-mode 'doctex-mode)
+          ((and (eq major-mode 'docTeX-mode)
                 (looking-at (concat (regexp-quote TeX-esc)
                                     "end[ \t]*{macrocode\\*?}"))
                 fill-prefix
@@ -4724,11 +4724,11 @@ outer indentation in case of a commented line.  The 
symbols
                      ;; If `LaTeX-syntactic-comments' is not enabled,
                      ;; do conventional indentation
                      LaTeX-syntactic-comments
-                     ;; Line comments in `doctex-mode' are always
+                     ;; Line comments in `docTeX-mode' are always
                      ;; indented syntax-aware so we need their inner
                      ;; indentation.
                      (and (TeX-in-line-comment)
-                          (eq major-mode 'doctex-mode))))))
+                          (eq major-mode 'docTeX-mode))))))
       ;; INNER indentation
       (save-excursion
         (beginning-of-line)
@@ -4752,7 +4752,7 @@ recognized."
                (eq force-type 'inner))
           (and (not force-type)
                (or (and (TeX-in-line-comment)
-                        (eq major-mode 'doctex-mode))
+                        (eq major-mode 'docTeX-mode))
                    (and (TeX-in-commented-line)
                         ;; Only move after the % if we're not
                         ;; performing a newline command (bug#47757).
@@ -5357,11 +5357,11 @@ depends on the value of `LaTeX-syntactic-comments'."
        ;; Syntax-aware filling:
        ;; * `LaTeX-syntactic-comments' enabled: Everything.
        ;; * `LaTeX-syntactic-comments' disabled: Uncommented code and
-       ;;   line comments in `doctex-mode'.
+       ;;   line comments in `docTeX-mode'.
        ((or (or LaTeX-syntactic-comments
                 (and (not LaTeX-syntactic-comments)
                      (not has-comment)))
-            (and (eq major-mode 'doctex-mode)
+            (and (eq major-mode 'docTeX-mode)
                  (TeX-in-line-comment)))
         (let ((fill-prefix comment-fill-prefix))
           (save-excursion
@@ -5535,7 +5535,7 @@ environment in commented regions with the same comment 
prefix."
                 ;; comment-prefix.  Hence, the next check just looks
                 ;; if we're inside such a group and returns non-nil to
                 ;; recognize such a situation.
-                (and (eq major-mode 'doctex-mode)
+                (and (eq major-mode 'docTeX-mode)
                      (looking-at-p " *{macrocode\\*?}")))
         (setq level
               (if (= (char-after (match-beginning 1)) ?b) ;;begin
@@ -6589,6 +6589,7 @@ commands are defined:
   :lighter nil
   :keymap (list (cons (LaTeX-math-abbrev-prefix) LaTeX-math-keymap))
   (TeX-set-mode-name))
+;; FIXME: Is this still necessary?
 (defalias 'latex-math-mode #'LaTeX-math-mode)
 
 (easy-menu-define LaTeX-math-mode-menu
@@ -6888,7 +6889,7 @@ corresponds to the variables 
`LaTeX-environment-menu-name' and
 (easy-menu-define LaTeX-mode-command-menu
     LaTeX-mode-map
     "Command menu used in LaTeX mode."
-    (TeX-mode-specific-command-menu 'latex-mode))
+    (TeX-mode-specific-command-menu 'LaTeX-mode))
 
 (easy-menu-define LaTeX-mode-menu
   LaTeX-mode-map
@@ -8146,33 +8147,37 @@ This happens when \\left is inserted."
   :type 'hook
   :group 'LaTeX)
 
-(TeX-abbrev-mode-setup latex-mode)
+(TeX-abbrev-mode-setup LaTeX-mode latex-mode-abbrev-table)
 
 ;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.drv\\'" . latex-mode) t) ;; append to the 
end of `auto-mode-alist' to give higher priority to Guix/Nix's derivation modes
+(add-to-list 'auto-mode-alist '("\\.drv\\'" . LaTeX-mode) t) ;; append to the 
end of `auto-mode-alist' to give higher priority to Guix/Nix's derivation modes
 
 ;; HeVeA files (LaTeX -> HTML converter: http://hevea.inria.fr/)
 ;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.hva\\'" . latex-mode))
+(add-to-list 'auto-mode-alist '("\\.hva\\'" . LaTeX-mode))
+
+(defvar semantic-symref-filepattern-alist) ; Silence compiler
+(with-eval-after-load 'semantic/symref/grep
+  ;; This entry is necessary for M-? to work.
+  ;; <URL:https://lists.gnu.org/r/auctex-devel/2023-09/msg00002.html>
+  ;; <URL:https://lists.gnu.org/r/auctex-devel/2023-09/msg00005.html>
+  (push '(LaTeX-mode "*.ltx" "*.sty" "*.cls" "*.clo" "*.bbl" "*.drv" "*.hva")
+        semantic-symref-filepattern-alist))
 
 (declare-function LaTeX-preview-setup "preview")
 
 ;;;###autoload
-(defun TeX-latex-mode ()
-  ;; FIXME: Use `define-derived-mode'.
+(define-derived-mode LaTeX-mode TeX-mode "LaTeX"
   "Major mode in AUCTeX for editing LaTeX files.
 See info under AUCTeX for full documentation.
 
-Special commands:
-\\{LaTeX-mode-map}
-
 Entering LaTeX mode calls the value of `text-mode-hook',
 then the value of `TeX-mode-hook', and then the value
 of `LaTeX-mode-hook'."
-  (interactive)
+  :after-hook (LaTeX-mode-cleanup)
+
   (LaTeX-common-initialization)
-  (setq TeX-base-mode-name "LaTeX")
-  (setq major-mode 'latex-mode)
+  (setq TeX-base-mode-name mode-name)
   (setq TeX-command-default "LaTeX")
   (setq TeX-sentinel-default-function #'TeX-LaTeX-sentinel)
   (add-hook 'tool-bar-mode-hook #'LaTeX-maybe-install-toolbar nil t)
@@ -8198,7 +8203,18 @@ of `LaTeX-mode-hook'."
                        (apply #'append
                               (mapcar #'cdr LaTeX-provided-class-options)))))
             nil t)
-  (run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'LaTeX-mode-hook)
+
+  (when (fboundp 'LaTeX-preview-setup)
+    (LaTeX-preview-setup))
+  ;; Set up flymake backend, see latex-flymake.el
+  (add-hook 'flymake-diagnostic-functions #'LaTeX-flymake nil t))
+
+(defun LaTeX-mode-cleanup ()
+  "Cleanup function for `LaTeX-mode'.
+Run after mode hooks and file local variables application."
+  ;; Defeat filladapt
+  (if (bound-and-true-p filladapt-mode)
+      (turn-off-filladapt-mode))
 
   ;; Don't overwrite the value the user set by hooks or file
   ;; (directory) local variables.
@@ -8229,35 +8245,61 @@ of `LaTeX-mode-hook'."
   ;; `LaTeX-indent-begin-list' and so on instead.
   (LaTeX-indent-commands-regexp-make)
 
-  (when (fboundp 'LaTeX-preview-setup)
-    (LaTeX-preview-setup))
-  (TeX-set-mode-name)
-  ;; Defeat filladapt
-  (if (and (boundp 'filladapt-mode)
-           filladapt-mode)
-      (turn-off-filladapt-mode))
-  ;; Set up flymake backend, see latex-flymake.el
-  (add-hook 'flymake-diagnostic-functions #'LaTeX-flymake nil t)
+  (setq TeX-complete-list
+        (append '(("\\\\cite\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
+                   1 LaTeX-bibitem-list "}")
+                  ("\\\\cite{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-bibitem-list "}")
+                  ("\\\\cite{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
+                   2 LaTeX-bibitem-list)
+                  ("\\\\nocite{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-bibitem-list "}")
+                  ("\\\\nocite{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
+                   2 LaTeX-bibitem-list)
+                  ("\\\\[Rr]ef{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
+                  ("\\\\eqref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
+                  ("\\\\pageref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
+                  ("\\\\\\(index\\|glossary\\){\\([^{}\n\r\\%]*\\)"
+                   2 LaTeX-index-entry-list "}")
+                  ("\\\\begin{\\([A-Za-z]*\\)" 1 
LaTeX-environment-list-filtered "}")
+                  ("\\\\end{\\([A-Za-z]*\\)" 1 LaTeX-environment-list-filtered 
"}")
+                  ("\\\\renewcommand\\*?{\\\\\\([A-Za-z]*\\)"
+                   1 TeX-symbol-list-filtered "}")
+                  ("\\\\renewenvironment\\*?{\\([A-Za-z]*\\)"
+                   1 LaTeX-environment-list-filtered "}")
+                  ("\\\\\\(this\\)?pagestyle{\\([A-Za-z]*\\)"
+                   2 LaTeX-pagestyle-list "}")
+                  (LaTeX--after-math-macro-prefix-p
+                   1 (lambda ()
+                       (seq-filter #'stringp
+                                   (append (mapcar #'cadr LaTeX-math-list)
+                                           (mapcar #'cadr 
LaTeX-math-default))))
+                   (if TeX-insert-braces "{}")))
+                TeX-complete-list)))
 
-  ;; Complete style initialization in buffers which don't visit files
-  ;; and which are therefore missed by the setting of `find-file-hook'
-  ;; in `VirTeX-common-initialization'.  This is necessary for
-  ;; `xref-find-references', for example. (bug#65912)
-  (unless buffer-file-truename
-    (TeX-update-style)))
+;; COMPATIBILITY for Emacs<29
+;;;###autoload
+(put 'LaTeX-mode 'auctex-function-definition (symbol-function 'LaTeX-mode))
 
-(TeX-abbrev-mode-setup doctex-mode)
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `latex-mode' continue to be valid for `LaTeX-mode'.
+(TeX-derived-mode-add-parents 'LaTeX-mode '(latex-mode))
 
-;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.dtx\\'" . doctex-mode))
+(with-eval-after-load 'semantic/symref/grep
+  (push '(docTeX-mode "*.dtx") semantic-symref-filepattern-alist))
+
+;; Enable LaTeX abbrevs in docTeX mode buffer.
+;; No need to include text mode abbrev table as parents because LaTeX
+;; mode abbrev table inherits it.
+(let ((p (list LaTeX-mode-abbrev-table)))
+  ;; Inherit abbrev table of the former name, if it exists.
+  (if (boundp 'doctex-mode-abbrev-table)
+      (push doctex-mode-abbrev-table p))
+  (define-abbrev-table 'docTeX-mode-abbrev-table nil nil :parents p))
 
 ;;;###autoload
-(define-derived-mode docTeX-mode TeX-latex-mode "docTeX"
+(define-derived-mode docTeX-mode LaTeX-mode "docTeX"
   "Major mode in AUCTeX for editing .dtx files derived from `LaTeX-mode'.
 Runs `LaTeX-mode', sets a few variables and
 runs the hooks in `docTeX-mode-hook'."
-  :abbrev-table doctex-mode-abbrev-table
-  (setq major-mode 'doctex-mode)
   (set (make-local-variable 'LaTeX-insert-into-comments) t)
   (set (make-local-variable 'LaTeX-syntactic-comments) t)
   (setq TeX-default-extension docTeX-default-extension)
@@ -8265,31 +8307,18 @@ runs the hooks in `docTeX-mode-hook'."
   (setq paragraph-start (concat paragraph-start "\\|%<")
         paragraph-separate (concat paragraph-separate "\\|%<")
         TeX-comment-start-regexp "\\(?:%\\(?:<[^>]+>\\)?\\)")
-  (setq TeX-base-mode-name "docTeX")
-  (TeX-set-mode-name)
+  (setq TeX-base-mode-name mode-name)
   ;; We can remove the next `setq' when syntax propertization
   ;; decouples font lock and `font-latex-setup' stops calling
   ;; `font-lock-set-defaults'.
   (setq font-lock-set-defaults nil)
   (funcall TeX-install-font-lock))
 
-;; Enable LaTeX abbrevs in docTeX mode buffer.
-(let ((p (abbrev-table-get doctex-mode-abbrev-table :parents)))
-  (or (memq latex-mode-abbrev-table p)
-      (abbrev-table-put doctex-mode-abbrev-table :parents
-                        (cons latex-mode-abbrev-table p))))
-
-;;This is actually a mess: to fit the scheme properly, our derived
-;;mode definition would have had to be made for TeX-doctex-mode in the
-;;first place, but then we could not have used define-derived-mode, or
-;;all mode-specific variables would have gotten non-AUCTeX names.
-;;This solution has the advantage that documentation strings are
-;;provided in the autoloads, and has the disadvantage that docTeX-mode
-;;is not aliased to doctex-mode (not even when the AUCTeX version is
-;;disabled) as would be normal for our scheme.
-
-;;;###autoload
-(defalias 'TeX-doctex-mode #'docTeX-mode)
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `doctex-mode' continue to be valid for `docTeX-mode'.
+;; In addition, dir local vars for `latex-mode' are now valid for
+;; `docTeX-mode' as well.
+(TeX-derived-mode-add-parents 'docTeX-mode '(doctex-mode latex-mode))
 
 (defcustom docTeX-clean-intermediate-suffixes
   TeX-clean-default-intermediate-suffixes
@@ -8336,12 +8365,8 @@ function would return non-nil and `(match-string 1)' 
would return
 
 (defun LaTeX-common-initialization ()
   "Common initialization for LaTeX derived modes."
-  (VirTeX-common-initialization)
-  (set-syntax-table LaTeX-mode-syntax-table)
   (set (make-local-variable 'indent-line-function) #'LaTeX-indent-line)
 
-  (setq local-abbrev-table latex-mode-abbrev-table)
-
   ;; Filling
   (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
   (set (make-local-variable 'fill-paragraph-function) #'LaTeX-fill-paragraph)
@@ -8406,36 +8431,6 @@ function would return non-nil and `(match-string 1)' 
would return
                                                 ("tabular" . LaTeX-item-array)
                                                 ("tabular*" . 
LaTeX-item-tabular*)))
 
-  (setq TeX-complete-list
-        (append '(("\\\\cite\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
-                   1 LaTeX-bibitem-list "}")
-                  ("\\\\cite{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-bibitem-list "}")
-                  ("\\\\cite{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
-                   2 LaTeX-bibitem-list)
-                  ("\\\\nocite{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-bibitem-list "}")
-                  ("\\\\nocite{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
-                   2 LaTeX-bibitem-list)
-                  ("\\\\[Rr]ef{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
-                  ("\\\\eqref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
-                  ("\\\\pageref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
-                  ("\\\\\\(index\\|glossary\\){\\([^{}\n\r\\%]*\\)"
-                   2 LaTeX-index-entry-list "}")
-                  ("\\\\begin{\\([A-Za-z]*\\)" 1 
LaTeX-environment-list-filtered "}")
-                  ("\\\\end{\\([A-Za-z]*\\)" 1 LaTeX-environment-list-filtered 
"}")
-                  ("\\\\renewcommand\\*?{\\\\\\([A-Za-z]*\\)"
-                   1 TeX-symbol-list-filtered "}")
-                  ("\\\\renewenvironment\\*?{\\([A-Za-z]*\\)"
-                   1 LaTeX-environment-list-filtered "}")
-                  ("\\\\\\(this\\)?pagestyle{\\([A-Za-z]*\\)"
-                   2 LaTeX-pagestyle-list "}")
-                  (LaTeX--after-math-macro-prefix-p
-                   1 (lambda ()
-                       (seq-filter #'stringp
-                                   (append (mapcar #'cadr LaTeX-math-list)
-                                           (mapcar #'cadr 
LaTeX-math-default))))
-                   (if TeX-insert-braces "{}")))
-                TeX-complete-list))
-
   (LaTeX-add-environments
    '("document" LaTeX-env-document)
    '("enumerate" LaTeX-env-item)
@@ -9096,8 +9091,6 @@ function would return non-nil and `(match-string 1)' 
would return
   (set (make-local-variable 'imenu-create-index-function)
        #'LaTeX-imenu-create-index-function)
 
-  (use-local-map LaTeX-mode-map)
-
   ;; Initialization of `add-log-current-defun-function':
   (set (make-local-variable 'add-log-current-defun-function)
        #'TeX-current-defun-name)
diff --git a/latex/preview.dtx b/latex/preview.dtx
index f8b72e0522..23f5b2da2a 100644
--- a/latex/preview.dtx
+++ b/latex/preview.dtx
@@ -1891,7 +1891,7 @@ Please complain to your document class author}%
 % \Finale{}
 % \iffalse
 % Local Variables: 
-% mode: doctex
+% mode: docTeX
 % TeX-master: "preview.drv"
 % End: 
 % \fi
diff --git a/plain-tex.el b/plain-tex.el
index b4c78fe489..779c30a0d9 100644
--- a/plain-tex.el
+++ b/plain-tex.el
@@ -92,7 +92,7 @@ Install tool bar if `plain-TeX-enable-toolbar' and
 (easy-menu-define plain-TeX-mode-command-menu
     plain-TeX-mode-map
     "Command menu used in TeX mode."
-    (TeX-mode-specific-command-menu 'plain-tex-mode))
+    (TeX-mode-specific-command-menu 'plain-TeX-mode))
 
 (easy-menu-define plain-TeX-mode-menu
     plain-TeX-mode-map
@@ -113,41 +113,48 @@ plain-TeX file, or any mode derived thereof.  See variable
   :type 'hook
   :group 'TeX-misc)
 
-(TeX-abbrev-mode-setup plain-tex-mode)
+(TeX-abbrev-mode-setup plain-TeX-mode plain-tex-mode-abbrev-table)
 
 ;;;###autoload
-(defun TeX-plain-tex-mode ()
+(define-derived-mode plain-TeX-mode TeX-mode
+  ;; The mode name can be "plain-TeX", but in that case, we have to
+  ;; change the "TeX" in the above call to `easy-menu-define' as well.
+  ;; See what "Extend this Menu" entry does in
+  ;; `TeX-common-menu-entries'.
+  "TeX"
   "Major mode in AUCTeX for editing plain TeX files.
 See info under AUCTeX for documentation.
 
-Special commands:
-\\{plain-TeX-mode-map}
-
-Entering `plain-tex-mode' calls the value of `text-mode-hook',
+Entering `plain-TeX-mode' calls the value of `text-mode-hook',
 then the value of `TeX-mode-hook', and then the value
 of `plain-TeX-mode-hook'."
-  (interactive)
+  :syntax-table nil
+  :after-hook (plain-TeX-mode-cleanup)
+
   (plain-TeX-common-initialization)
-  (setq major-mode 'plain-tex-mode)
-  (use-local-map plain-TeX-mode-map)
-  (setq TeX-base-mode-name "TeX")
-  (setq TeX-command-default "TeX")
-  (add-hook 'tool-bar-mode-hook #'plain-TeX-maybe-install-toolbar nil t)
-  (plain-TeX-maybe-install-toolbar)
-  (run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'plain-TeX-mode-hook)
-  (TeX-set-mode-name)
-  ;; Complete style initialization in buffers which don't visit files
-  ;; and which are therefore missed by the setting of `find-file-hook'
-  ;; in `VirTeX-common-initialization'.  This is necessary for
-  ;; `xref-find-references', for example. (bug#65912)
-  (unless buffer-file-truename
-    (TeX-update-style)))
+  (setq TeX-base-mode-name mode-name)
+  (setq TeX-command-default "TeX"))
+
+(defun plain-TeX-mode-cleanup ()
+  "Cleanup function for `plain-TeX-mode'.
+Run after mode hooks and file local variables application."
+  ;; Don't install tool bar in AmSTeX mode.
+  (unless (derived-mode-p 'AmSTeX-mode)
+    (add-hook 'tool-bar-mode-hook
+              #'plain-TeX-maybe-install-toolbar nil t)
+    (plain-TeX-maybe-install-toolbar)))
+
+;; COMPATIBILITY for Emacs<29
+;;;###autoload
+(put 'plain-TeX-mode 'auctex-function-definition (symbol-function 
'plain-TeX-mode))
+
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `plain-tex-mode' continue to be valid for
+;; `plain-TeX-mode'.
+(TeX-derived-mode-add-parents 'plain-TeX-mode '(plain-tex-mode))
 
 (defun plain-TeX-common-initialization ()
   "Common initialization for plain TeX like modes."
-  (VirTeX-common-initialization)
-  (set-syntax-table TeX-mode-syntax-table)
-  (setq local-abbrev-table plain-tex-mode-abbrev-table)
   (set (make-local-variable 'TeX-style-hook-dialect) plain-TeX-dialect)
   (setq TeX-sentinel-default-function #'TeX-TeX-sentinel)
   (setq paragraph-start
@@ -275,6 +282,11 @@ that is, you do _not_ have to cater for this yourself by 
adding \\\\\\=' or $."
 
 (defvar AmSTeX-mode-map
   (let ((map (make-sparse-keymap)))
+    ;; Don't use `plain-TeX-mode-map' as parent.  That would corrupt
+    ;; the menu bar in the following two ways. :-(
+    ;;  - "TeX" entry appears in addition to "AmS-TeX", with
+    ;;    duplicated content.
+    ;;  - "Command" entry disappears.
     (set-keymap-parent map TeX-mode-map)
     map)
   "Keymap used in `AmSTeX-mode'.")
@@ -283,44 +295,42 @@ that is, you do _not_ have to cater for this yourself by 
adding \\\\\\=' or $."
 (easy-menu-define AmSTeX-mode-command-menu
     AmSTeX-mode-map
     "Command menu used in AmSTeX mode."
-    (TeX-mode-specific-command-menu 'ams-tex-mode))
+    (TeX-mode-specific-command-menu 'AmSTeX-mode))
 
 (easy-menu-define AmSTeX-mode-menu
   AmSTeX-mode-map
   "Menu used in AmSTeX mode."
   (cons "AmS-TeX" plain-TeX-menu-entries))
 
-(defcustom AmS-TeX-mode-hook nil
-  "A hook run in AmS-TeX mode buffers."
+(define-obsolete-variable-alias
+  'AmS-TeX-mode-hook 'AmSTeX-mode-hook "AUCTeX 14")
+(defcustom AmSTeX-mode-hook nil
+  "A hook run in AmSTeX mode buffers."
   :type 'hook
   :group 'TeX-misc)
 
 ;;;###autoload
-(defun ams-tex-mode ()
-  "Major mode in AUCTeX for editing AmS-TeX files.
+(define-derived-mode AmSTeX-mode plain-TeX-mode "AmS-TeX"
+  "Major mode in AUCTeX for editing AmSTeX files.
 See info under AUCTeX for documentation.
 
-Special commands:
-\\{AmSTeX-mode-map}
+Entering `AmSTeX-mode' calls the value of `text-mode-hook', then
+the value of `TeX-mode-hook', `plain-TeX-mode-hook' and then the
+value of `AmSTeX-mode-hook'."
+  :syntax-table nil
+  :abbrev-table nil
 
-Entering `ams-tex-mode' calls the value of `text-mode-hook',
-then the value of `TeX-mode-hook', and then the value
-of `AmS-TeX-mode-hook'."
-  (interactive)
-  (plain-TeX-common-initialization)
-  (setq major-mode 'ams-tex-mode)
-  (use-local-map AmSTeX-mode-map)
-
-  (setq TeX-base-mode-name "AmS-TeX")
-  (setq TeX-command-default "AmSTeX")
-  (run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'AmS-TeX-mode-hook)
-  (TeX-set-mode-name)
-  ;; Complete style initialization in buffers which don't visit files
-  ;; and which are therefore missed by the setting of `find-file-hook'
-  ;; in `VirTeX-common-initialization'.  This is necessary for
-  ;; `xref-find-references', for example. (bug#65912)
-  (unless buffer-file-truename
-    (TeX-update-style)))
+  (setq TeX-base-mode-name mode-name)
+  (setq TeX-command-default "AmSTeX"))
+
+;;;###autoload
+(defalias 'ams-tex-mode #'AmSTeX-mode)
+
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `ams-tex-mode' continue to be valid for `AmSTeX-mode'.
+;; In addition, dir local vars for `plain-tex-mode' are now valid for
+;; `AmSTeX-mode' as well.
+(TeX-derived-mode-add-parents 'AmSTeX-mode '(ams-tex-mode plain-tex-mode))
 
 (defcustom AmSTeX-clean-intermediate-suffixes
   TeX-clean-default-intermediate-suffixes
diff --git a/preview.el.in b/preview.el.in
index 0fa211ccfc..211159e7f9 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -2260,7 +2260,7 @@ has FUNC called with its current buffer being set to it."
       (with-current-buffer (pop buffers)
         (when
             (or (memq (current-buffer) default-buffers)
-                (and (memq major-mode '(plain-tex-mode latex-mode))
+                (and (memq major-mode '(plain-TeX-mode LaTeX-mode))
                      (or (stringp TeX-master)
                          (eq TeX-master t))
                      (string= (expand-file-name (TeX-master-file t))
@@ -2373,16 +2373,14 @@ BUFFER-MISC is the appropriate data to be used."
                    buffer-misc))))))
 
 ;; Add autoload cookies explicitly for desktop.el.
-;; <Background> preview-latex doesn't conform to the following
-;; assumptions of desktop.el:
+;; <Background> desktop.el assumes the following two:
 ;; (1) The file associated with the major mode by autoload has defun
 ;;     of handler, which restores the state of the buffer.
 ;; (2) The file has suitable `add-to-list' form also for
 ;;     `desktop-buffer-mode-handlers' to register the entry of the
 ;;     handler.
-;; This isn't the case here because the file associated with
-;; `latex-mode' is tex-mode.el, neither preview.el nor latex.el.  Thus
-;; we include both of them as explicit autoloads in preview-latex.el.
+;; This isn't the case for preview-latex.  Thus we register both of
+;; them as autoload cookies in AUCTeX initialzation code.
 ;;;###autoload
 (defun desktop-buffer-preview (file-name _buffer-name misc)
   "Hook function for restoring persistent previews into a buffer."
@@ -2396,7 +2394,7 @@ BUFFER-MISC is the appropriate data to be used."
 
 ;;;###autoload
 (add-to-list 'desktop-buffer-mode-handlers
-             '(latex-mode . desktop-buffer-preview))
+             '(LaTeX-mode . desktop-buffer-preview))
 
 (defcustom preview-auto-cache-preamble 'ask
   "Whether to generate a preamble cache format automatically.
@@ -3092,7 +3090,7 @@ to add the preview functionality."
            (customize-menu-create 'preview))])
         ["Read documentation" preview-goto-info-page]
         ["Report Bug" preview-report-bug]))
-    (if (eq major-mode 'latex-mode)
+    (if (eq major-mode 'LaTeX-mode)
         (preview-mode-setup))
     (unless preview-tb-icon
       (setq preview-tb-icon (preview-filter-specs preview-tb-icon-specs)))
diff --git a/style/amstex.el b/style/amstex.el
index 75889353e4..702159b373 100644
--- a/style/amstex.el
+++ b/style/amstex.el
@@ -46,7 +46,7 @@
 (TeX-add-style-hook
  "amstex"
  (lambda ()
-   (unless (memq major-mode '(plain-tex-mode ams-tex-mode))
+   (unless (memq major-mode '(plain-TeX-mode AmSTeX-mode))
      (TeX-run-style-hooks "amsmath")))
  TeX-dialect)
 
diff --git a/tests/japanese/parse-timing.el b/tests/japanese/parse-timing.el
index 15051bcd5a..63df735350 100644
--- a/tests/japanese/parse-timing.el
+++ b/tests/japanese/parse-timing.el
@@ -41,8 +41,7 @@
   "Test style hooks are not called too early."
   (let ((TeX-parse-self t)
         (TeX-master t)
-        (LaTeX-mode-hook '(japanese-latex-mode-initialization
-                           turn-on-reftex)))
+        (LaTeX-mode-hook '(turn-on-reftex)))
     (find-file parse-timing)
     (should (memq 'AMSTeX
                   (get reftex-docstruct-symbol
diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el
index 28187b0571..eae951f115 100644
--- a/tests/latex/latex-test.el
+++ b/tests/latex/latex-test.el
@@ -271,7 +271,7 @@ Test against RequirePackage."
 backend=biber % here is a comment
 ]{biblatex}
 ")
-    (latex-mode)
+    (LaTeX-mode)
     (let ((TeX-parse-self t))
       (TeX-update-style t))
     (should (member "biblatex" (TeX-style-list)))
@@ -387,7 +387,7 @@ backend=biber % here is a comment
       ;;                        (setq TeX-PDF-from-DVI "Dvips"))
       ;;                      :classopt)
       (insert "\\documentclass[dvips]{article}\n")
-      (latex-mode)
+      (LaTeX-mode)
       (TeX-update-style)
       (should (equal (TeX-PDF-from-DVI) "Dvips"))
       (should (not (member "dvips" TeX-active-styles)))
@@ -404,7 +404,7 @@ backend=biber % here is a comment
       ;;                          (setq TeX-PDF-from-DVI "Dvipdfmx")))
       ;;                      :classopt)
       (insert "\\documentclass[dvipdfmx]{article}\n")
-      (latex-mode)
+      (LaTeX-mode)
       (TeX-update-style)
       (should TeX-PDF-mode)
       (should (equal (TeX-PDF-from-DVI) "Dvipdfmx"))
@@ -423,7 +423,7 @@ backend=biber % here is a comment
       ;; This depends on the following code in latex.el:
       ;; (TeX-add-style-hook "pdftricks" #'TeX-PDF-mode-on :classopt)
       (insert "\\documentclass[pdftricks]{article}\n")
-      (latex-mode)
+      (LaTeX-mode)
       (TeX-update-style)
       (should TeX-PDF-mode)
       (should (not (member "pdftricks" TeX-active-styles)))
@@ -433,7 +433,7 @@ backend=biber % here is a comment
       ;; This depends on the following code in latex.el:
       ;; (TeX-add-style-hook "psfrag" #'TeX-PDF-mode-off :classopt)
       (insert "\\documentclass[psfrag]{article}\n")
-      (latex-mode)
+      (LaTeX-mode)
       (TeX-update-style)
       (should (not TeX-PDF-mode))
       (should (not (member "psfrag" TeX-active-styles))))))
@@ -447,7 +447,7 @@ backend=biber % here is a comment
   (with-temp-buffer
     (let ((transient-mark-mode t)
           (LaTeX-insert-into-comments t))
-      (latex-mode)
+      (LaTeX-mode)
       (auto-fill-mode 1)
 
       ;; test 1: for bug#35284
@@ -657,7 +657,7 @@ ghi"))
           ;; already.
           (or orig-mode
               (electric-pair-mode 1))
-          (latex-mode)
+          (LaTeX-mode)
 
           ;; When `LaTeX-insert-left-brace' supplies right brace,
           ;; `electric-pair-mode' shouldn't come into play.
diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index 9834487fa4..a89a12e95d 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -88,7 +88,7 @@
   ;; Skip on w32 because the quoting style of `shell-quote-argument'
   ;; is different.
   (skip-unless (not (eq system-type 'windows-nt)))
-  (let ((major-mode 'latex-mode)
+  (let ((major-mode 'LaTeX-mode)
         (TeX-engine 'default)
         (TeX-command-extra-options " \"\\foo\"")
         TeX-master)
diff --git a/tex-bar.el b/tex-bar.el
index a6804e1862..a0bf9311d0 100644
--- a/tex-bar.el
+++ b/tex-bar.el
@@ -83,7 +83,7 @@ If there is no help, the empty string is returned."
 (defcustom TeX-bar-TeX-buttons
   '(new-file open-file dired kill-buffer save-buffer cut copy paste undo
              separator tex next-error view bibtex spell)
-  "List of buttons available in `tex-mode'.
+  "List of buttons available in `plain-TeX-mode'.
 It should be a list in the same format of the BUTTONS parameter
 in function `toolbarx-install-toolbar', often a symbol that
 labels a button.
@@ -223,7 +223,7 @@ format of the argument MEANING-ALIST in the mentioned 
function."
 (defcustom TeX-bar-LaTeX-buttons
   '(new-file open-file dired kill-buffer save-buffer cut copy paste undo
              separator latex next-error view bibtex spell)
-  "List of buttons available in `latex-mode'.
+  "List of buttons available in `LaTeX-mode'.
 It should be a list in the same format of the BUTTONS parameter
 in function `toolbarx-install-toolbar', often a symbol that
 labels a button.
diff --git a/tex-fold.el b/tex-fold.el
index a48e4f8429..a1fd48be51 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -300,7 +300,7 @@ and `TeX-fold-math-spec-list', and environments in 
`TeX-fold-env-spec-list'."
   "Fold all items in region from START to END."
   (interactive "r")
   (when (and (memq 'env TeX-fold-type-list)
-             (not (eq major-mode 'plain-tex-mode)))
+             (not (eq major-mode 'plain-TeX-mode)))
     (TeX-fold-region-macro-or-env start end 'env))
   (when (memq 'macro TeX-fold-type-list)
     (TeX-fold-region-macro-or-env start end 'macro))
@@ -323,11 +323,11 @@ for macros and `math' for math macros."
           (cl-pushnew i item-list :test #'equal)))
       (when item-list
         (setq regexp (cond ((and (eq type 'env)
-                                 (eq major-mode 'context-mode))
+                                 (eq major-mode 'ConTeXt-mode))
                             (concat (regexp-quote TeX-esc)
                                     "start" (regexp-opt item-list t)))
                            ((and (eq type 'env)
-                                 (eq major-mode 'texinfo-mode))
+                                 (eq major-mode 'Texinfo-mode))
                             (concat (regexp-quote TeX-esc)
                                     (regexp-opt item-list t)))
                            ((eq type 'env)
@@ -418,15 +418,15 @@ TYPE specifies the type of item and can be one of the 
symbols
 macros.
 Return non-nil if an item was found and folded, nil otherwise."
   (if (and (eq type 'env)
-           (eq major-mode 'plain-tex-mode))
+           (eq major-mode 'plain-TeX-mode))
       (message
        "Folding of environments is not supported in current mode")
     (let ((item-start (cond ((and (eq type 'env)
-                                  (eq major-mode 'context-mode))
+                                  (eq major-mode 'ConTeXt-mode))
                              (save-excursion
                                (ConTeXt-find-matching-start) (point)))
                             ((and (eq type 'env)
-                                  (eq major-mode 'texinfo-mode))
+                                  (eq major-mode 'Texinfo-mode))
                              (save-excursion
                                (Texinfo-find-env-start) (point)))
                             ((eq type 'env)
@@ -441,11 +441,11 @@ Return non-nil if an item was found and folded, nil 
otherwise."
                             (goto-char item-start)
                             (looking-at
                              (cond ((and (eq type 'env)
-                                         (eq major-mode 'context-mode))
+                                         (eq major-mode 'ConTeXt-mode))
                                     (concat (regexp-quote TeX-esc)
                                             "start\\([A-Za-z]+\\)"))
                                    ((and (eq type 'env)
-                                         (eq major-mode 'texinfo-mode))
+                                         (eq major-mode 'Texinfo-mode))
                                     (concat (regexp-quote TeX-esc)
                                             "\\([A-Za-z]+\\)"))
                                    ((eq type 'env)
@@ -530,12 +530,12 @@ TYPE can be either `env' for environments, `macro' for 
macros or
 `math' for math macros."
   (save-excursion
     (cond ((and (eq type 'env)
-                (eq major-mode 'context-mode))
+                (eq major-mode 'ConTeXt-mode))
            (goto-char start)
            (ConTeXt-find-matching-stop)
            (point))
           ((and (eq type 'env)
-                (eq major-mode 'texinfo-mode))
+                (eq major-mode 'Texinfo-mode))
            (goto-char (1+ start))
            (Texinfo-find-env-end)
            (point))
diff --git a/tex-info.el b/tex-info.el
index 9dc19beddb..63242e0df7 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -538,13 +538,16 @@ is assumed by default."
     (define-key map "\\" #'self-insert-command)
     ;; Users benefit from `TeX-electric-macro' even in Texinfo mode
     (define-key map "@" #'TeX-insert-backslash)
+
+    ;; Hide "Text" menu entry inherited from text mode.
+    (define-key map [menu-bar text] #'undefined)
     map)
   "Keymap for Texinfo mode.")
 
 (easy-menu-define Texinfo-command-menu
   Texinfo-mode-map
   "Menu used in Texinfo mode for external commands."
-  (TeX-mode-specific-command-menu 'texinfo-mode))
+  (TeX-mode-specific-command-menu 'Texinfo-mode))
 
 (easy-menu-define Texinfo-mode-menu
   Texinfo-mode-map
@@ -622,28 +625,25 @@ is assumed by default."
 
 ;;; Mode:
 
-;;;###autoload
-(defalias 'Texinfo-mode #'texinfo-mode)
+(defvar semantic-symref-filepattern-alist) ; Silence compiler
+(with-eval-after-load 'semantic/symref/grep
+  (push '(Texinfo-mode "*.texinfo" "*.texi" "*.txi")
+        semantic-symref-filepattern-alist))
 
 ;;;###autoload
-(defun TeX-texinfo-mode ()
+(define-derived-mode Texinfo-mode text-mode "Texinfo"
   "Major mode in AUCTeX for editing Texinfo files.
 
-Special commands:
-\\{Texinfo-mode-map}
-
 Entering Texinfo mode calls the value of `text-mode-hook' and then the
 value of `Texinfo-mode-hook'."
-  (interactive)
-  (kill-all-local-variables)
+  :syntax-table texinfo-mode-syntax-table
+  :after-hook (Texinfo-mode-cleanup)
+
   (setq TeX-mode-p t)
   (setq TeX-output-extension (if TeX-PDF-mode "pdf" "dvi"))
   (setq TeX-sentinel-default-function #'TeX-TeX-sentinel)
   ;; Mostly stolen from texinfo.el
-  (setq TeX-base-mode-name "Texinfo")
-  (setq major-mode 'texinfo-mode)
-  (use-local-map Texinfo-mode-map)
-  (set-syntax-table texinfo-mode-syntax-table)
+  (setq TeX-base-mode-name mode-name)
 
   ;; Moved after `run-mode-hooks'. (bug#65750)
   ;; (set (make-local-variable 'page-delimiter)
@@ -859,10 +859,11 @@ value of `Texinfo-mode-hook'."
   ;; RefTeX plugging
   (add-hook 'reftex-mode-hook #'Texinfo-reftex-hook nil t)
   (if (and (boundp 'reftex-mode) reftex-mode)
-      (Texinfo-reftex-hook))
-
-  (run-mode-hooks 'text-mode-hook 'Texinfo-mode-hook)
+      (Texinfo-reftex-hook)))
 
+(defun Texinfo-mode-cleanup ()
+  "Cleanup function for `Texinfo-mode'.
+Run after mode hooks and file local variables application."
   ;; Don't overwrite the value the user set by hooks or file
   ;; (directory) variables.
   (or (local-variable-p 'page-delimiter)
diff --git a/tex-jp.el b/tex-jp.el
index 867f3f6a32..cdb62d974f 100644
--- a/tex-jp.el
+++ b/tex-jp.el
@@ -85,7 +85,6 @@ systems are determined by their values regardless of the 
kanji option."
 ;; Define before first use.
 (defvar-local japanese-TeX-mode nil
   "Non-nil means the current buffer handles Japanese TeX/LaTeX.")
-(put 'japanese-TeX-mode 'permanent-local t)
 
 (setq TeX-expand-list-builtin
       (append
@@ -277,8 +276,8 @@ See also a user custom option 
`TeX-japanese-process-input-coding-system'."
   (with-current-buffer TeX-command-buffer
     (when japanese-TeX-mode
       ;; TeX-engine が ptex, jtex, uptex のいずれかである場合のみ考え
-      ;; る。luatex-ja などの場合はそもそもただの latex-mode でよく、
-      ;; わざわざ japanese-latex-mode にする必要がない。
+      ;; る。luatex-ja などの場合はそもそもただの LaTeX-mode でよく、
+      ;; わざわざ japanese-LaTeX-mode にする必要がない。
 
       ;; FIXME: 以下の処理は tex engine を対象とする場合しか考えていない。
       ;; bibtex や mendex 等の補助ツールの場合は正しくない処理かもしれない。
@@ -407,92 +406,81 @@ For inappropriate encoding, nil instead."
 ;;; Japanese TeX modes
 
 ;;;###autoload
-(defun japanese-plain-tex-mode ()
-  "Major mode in AUCTeX for editing Japanese plain TeX files.
-Set `japanese-TeX-mode' to t, and enter `TeX-plain-tex-mode'."
-  (interactive)
+(define-derived-mode japanese-plain-TeX-mode plain-TeX-mode "TeX"
+  "Major mode in AUCTeX for editing Japanese plain TeX files."
+  :syntax-table nil
+  ;; See the comments below in `japanese-LaTeX-mode' for the intent of
+  ;; the following line.
+  :after-hook (setq major-mode 'plain-TeX-mode)
+
   (setq japanese-TeX-mode t)
-  (TeX-plain-tex-mode))
+
+  (TeX-engine-set japanese-TeX-engine-default))
 
 (defun japanese-plain-tex-mode-initialization ()
-  "Japanese plain-TeX specific initializations."
-  (when japanese-TeX-mode
-    (TeX-engine-set japanese-TeX-engine-default)
+  (message "\
+Now `japanese-plain-tex-mode-initialization' is no-op.  Don't use it."))
 
-    ;; For the intent of the following lines, see the comments below
-    ;; in `japanese-latex-mode-initialization'.
-    (when enable-local-variables
-      (setq major-mode 'japanese-plain-tex-mode)
-      (add-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name
-                nil t))))
+;;;###autoload
+(defalias 'japanese-plain-tex-mode #'japanese-plain-TeX-mode)
 
-(add-hook 'plain-TeX-mode-hook #'japanese-plain-tex-mode-initialization)
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `japanese-plain-tex-mode' and `plain-tex-mode'
+;; continue to be valid for `japanese-plain-TeX-mode'.
+(TeX-derived-mode-add-parents 'japanese-plain-TeX-mode
+                              '(japanese-plain-tex-mode plain-tex-mode))
 
 ;;;###autoload
-(defun japanese-latex-mode ()
-  "Major mode in AUCTeX for editing Japanese LaTeX files.
-Set `japanese-TeX-mode' to t, and enter `TeX-latex-mode'."
-  (interactive)
+(define-derived-mode japanese-LaTeX-mode LaTeX-mode "LaTeX"
+  "Major mode in AUCTeX for editing Japanese LaTeX files."
+  :syntax-table nil
+  ;; The value of `major-mode' should be `LaTeX-mode', not
+  ;; `japanese-LaTeX-mode', because the name `LaTeX-mode' is hard
+  ;; coded in several places of AUCTeX like
+  ;;   (eq major-mode 'LaTeX-mode),
+  ;;   (memq major-mode '(docTeX-mode LaTeX-mode)
+  ;; and so on.  By such piece of codes, `japanese-LaTeX-mode' should
+  ;; simply be regarded as `LaTeX-mode'.  However, if we change
+  ;; `major-mode' to `LaTeX-mode' here in the mode body,
+  ;; `hack-local-variables' does not apply the directory local
+  ;; variables prepared for `japanese-LaTeX-mode'.
+  ;; Thus we change `major-mode' to `LaTeX-mode' after
+  ;; `hack-local-variables' is done.
+  :after-hook (setq major-mode 'LaTeX-mode)
+
   (setq japanese-TeX-mode t)
-  (TeX-latex-mode))
+
+  ;; `TeX-match-style' を使うのは `TeX-update-style' の後に遅らせる。
+  ;; この段階で使うと、その中で呼ぶ `TeX-style-list' の中で
+  ;; `TeX-update-style' が呼ばれてしまい、local variable 等の準備が整っ
+  ;; てない段階で style hook が実行されて不適な結果になることがある。
+  ;; また、`TeX-update-style' は後から `find-file-hook' 中でもう一度呼
+  ;; ばれるので、`TeX-parse-self' が t だと parse 処理も無駄に 2 回行
+  ;; われてしまう。
+  (add-hook 'TeX-update-style-hook
+            #'japanese-LaTeX-guess-engine nil t)
+  (setq-local LaTeX-default-style japanese-LaTeX-default-style)
+
+  (when (and (fboundp 'font-latex-add-keywords)
+             (eq TeX-install-font-lock 'font-latex-setup))
+    ;; jLaTeX にはないコマンドだが、それはもう気にしなくていいだろう。
+    (font-latex-add-keywords '(("textgt" "{") ("mathgt" "{"))
+                             'bold-command)
+    (font-latex-add-keywords '("gtfamily")
+                             'bold-declaration)))
 
 (defun japanese-latex-mode-initialization ()
-  "Japanese LaTeX specific initializations."
-  (when japanese-TeX-mode
-    ;; `TeX-match-style' を使うのは `TeX-update-style' の後に遅らせる。
-    ;; この段階で使うと、その中で呼ぶ `TeX-style-list' の中で
-    ;; `TeX-update-style' が呼ばれてしまい、local variable 等の準備が
-    ;; 整ってない段階で style hook が実行されて不適な結果になることが
-    ;; ある。また、`TeX-update-style' は後から `find-file-hook' 中でも
-    ;; う一度呼ばれるので、`TeX-parse-self' が t だと parse 処理も無駄
-    ;; に 2 回行われてしまう。
-    (add-hook 'TeX-update-style-hook
-              #'japanese-LaTeX-guess-engine nil t)
-    (setq-local LaTeX-default-style japanese-LaTeX-default-style)
-
-    (when (and (fboundp 'font-latex-add-keywords)
-               (eq TeX-install-font-lock 'font-latex-setup))
-      ;; jLaTeX にはないコマンドだが、それはもう気にしなくていいだろう。
-      (font-latex-add-keywords '(("textgt" "{") ("mathgt" "{"))
-                               'bold-command)
-      (font-latex-add-keywords '("gtfamily")
-                               'bold-declaration))
-
-    ;; The value of `major-mode' should be `latex-mode', not
-    ;; `japanese-latex-mode', because the name `latex-mode' is hard
-    ;; coded in several places of AUCTeX like "(eq major-mode
-    ;; 'latex-mode)", "(memq major-mode '(doctex-mode latex-mode)" and
-    ;; so on.  By such piece of codes, `japanese-latex-mode' should
-    ;; simply be regarded as `latex-mode'.  So we'd like to leave
-    ;; `major-mode' as `latex-mode' here, but doing so confuses
-    ;; `hack-local-variables' in two ways.
-    ;; (1) It is tricked into considering that the major mode is not
-    ;;     yet initialized and calls `japanese-latex-mode' again.
-    ;; (2) It does not read the directory local variables prepared for
-    ;;     `japanese-latex-mode'.
-    ;; Thus we temporarily set `major-mode' to `japanese-latex-mode'
-    ;; here and plan to reset it to `latex-mode' after
-    ;; `hack-local-variables' is done.
-    (when enable-local-variables
-      (setq major-mode 'japanese-latex-mode)
-      (add-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name
-                nil t))))
-
-(add-hook 'LaTeX-mode-hook #'japanese-latex-mode-initialization)
-
-;; This function is useful only within `hack-local-variables-hook'.
-(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))
-
-;; Make `hack-dir-local-variables' to regard `latex-mode' as parent
-;; of `japanese-latex-mode', and `plain-tex-mode' as parent of
-;; `japanese-plain-tex-mode'.
-(put 'japanese-plain-tex-mode 'derived-mode-parent 'plain-tex-mode)
-(put 'japanese-latex-mode 'derived-mode-parent 'latex-mode)
+  (message "\
+Now `japanese-latex-mode-initialization' is no-op.  Don't use it."))
+
+;;;###autoload
+(defalias 'japanese-latex-mode #'japanese-LaTeX-mode)
+
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `japanese-latex-mode' and `latex-mode' continue to be
+;; valid for `japanese-LaTeX-mode'.
+(TeX-derived-mode-add-parents 'japanese-LaTeX-mode
+                              '(japanese-latex-mode latex-mode))
 
 (defun japanese-LaTeX-guess-engine ()
   "Guess Japanese TeX engine and set it to `TeX-engine'.
@@ -535,7 +523,9 @@ overwrite the value already set locally."
   (if (TeX-looking-at-backward "\\\\/\\(}+\\)" 50)
       (replace-match "\\1" t))
   (call-interactively #'japanese-TeX-self-insert-command))
-(advice-add 'TeX-insert-punctuation :override
+(define-key japanese-plain-TeX-mode-map [remap TeX-insert-punctuation]
+            #'japanese-TeX-insert-punctuation)
+(define-key japanese-LaTeX-mode-map [remap TeX-insert-punctuation]
             #'japanese-TeX-insert-punctuation)
 
 ;;; Error Messages
diff --git a/tex-site.el.in b/tex-site.el.in
index 4412323087..1301f52885 100644
--- a/tex-site.el.in
+++ b/tex-site.el.in
@@ -48,6 +48,7 @@
   ;; Try and support the case where someone loads tex-site.el or
   ;; auctex.el directly, in the old way.
   (provide 'tex-site)        ;Avoid (re)loading tex-site from auctex-autoloads.
+
   (load "auctex-autoloads" 'noerror 'nomessage))
 
 ;; Define here in order for `M-x customize-group <RET> AUCTeX <RET>'
@@ -84,17 +85,23 @@ shared by all users of a site."
   :type 'directory)
 
 (defconst TeX-mode-alist
-  '((tex-mode . tex-mode)
-    (plain-tex-mode . tex-mode)
-    (texinfo-mode . texinfo)
-    (latex-mode . tex-mode)
-    (doctex-mode . tex-mode))
-  "Alist of built-in TeX modes and their load files.")
+  '((tex-mode . TeX-tex-mode)
+    (plain-tex-mode . plain-TeX-mode)
+    (texinfo-mode . Texinfo-mode)
+    (latex-mode . LaTeX-mode)
+    (doctex-mode . docTeX-mode))
+  "Alist of built-in TeX modes and their counterparts in AUCTeX.")
 
 (defalias 'TeX-load-hack #'ignore)
 
 (defun tex-site-unload-function ()
   (TeX-modes-set 'TeX-modes nil)
+
+  ;; COMPATIBILITY for Emacs<29
+  (put 'plain-TeX-mode 'auctex-function-definition nil)
+  (put 'LaTeX-mode 'auctex-function-definition nil)
+  (put 'TeX-mode 'auctex-function-definition nil)
+
   (setq load-path (delq TeX-lisp-directory load-path))
   ;; Tell emacs to continue standard unloading procedure.
   nil)
@@ -102,25 +109,37 @@ shared by all users of a site."
 (defun TeX-modes-set (var value &optional _ignored)
   "Set VAR (which should be `TeX-modes') to VALUE.
 
-This places either the standard or the AUCTeX versions of
-functions into the respective function cell of the mode."
+Arrange the redirection of the built-in TeX modes according to VALUE.
+- The built-in modes in VALUE are redirected to the corresponding
+  AUCTeX major modes.
+- The built-in modes not in VALUE discard redirection, if any.
+If `major-mode-remap-alist' is available, use it for redirection.
+Otherwise, use advice facility."
   (custom-set-default var value)
-  (let ((list TeX-mode-alist) elt)
-    (while list
-      (setq elt (car (pop list)))
-      (let ((dst (intern (concat "TeX-" (symbol-name elt)))))
-        (if (memq elt value)
+  (let (elt dst)
+    (dolist (entry TeX-mode-alist)
+      (setq elt (car entry)
+            dst (cdr entry))
+      (if (memq elt value)
+          (if (boundp 'major-mode-remap-alist)
+              (or (eq (cdr-safe (assq elt major-mode-remap-alist)) dst)
+                  (push (cons elt dst) major-mode-remap-alist))
+            ;; COMPATIBILITY for Emacs<29
             (advice-add elt :override dst
                         ;; COMPATIBILITY for Emacs 28.[12]
                         ;; Give it higher precedence than the :around
                         ;; advice given to `tex-mode' in tex-mode.el.
                         ;; 
<URL:https://lists.gnu.org/r/auctex-devel/2022-09/msg00050.html>
-                        '((depth . -10)))
+                        '((depth . -10))))
+        (if (boundp 'major-mode-remap-alist)
+            (setq major-mode-remap-alist
+                  (delete entry major-mode-remap-alist))
+          ;; COMPATIBILITY for Emacs<29
           (advice-remove elt dst))))))
 
 (defcustom TeX-modes
   (mapcar #'car TeX-mode-alist)
-  "List of modes provided by AUCTeX.
+  "List of built-in TeX modes redirected to AUCTeX modes.
 
 This variable can't be set normally; use customize for that, or
 set it with `TeX-modes-set'."
@@ -129,6 +148,30 @@ set it with `TeX-modes-set'."
   :set #'TeX-modes-set
   :initialize #'custom-initialize-reset)
 
+(defun TeX--alias-overlapped-modes (&optional restore)
+  "Delete or restore definition of overlapped modes via `defalias'.
+Set function definition for modes overlapped between tex-mode.el
+and AUCTeX, `plain-TeX-mode', `LaTeX-mode' and `TeX-mode'.
+If optional argument RESTORE is nil, delete the definition.
+Otherwise, restore AUCTeX definition saved in the symbol property
+`auctex-function-definition'."
+  (dolist (mode '(plain-TeX-mode LaTeX-mode TeX-mode))
+    (if (eq (symbol-function mode)
+            (intern (downcase (symbol-name mode))))
+        (defalias mode (if restore
+                           (get mode 'auctex-function-definition))))))
+
+;; Delete aliases predefined in tex-mode.el so that AUCTeX
+;; autoloads provided below take precedence.
+(TeX--alias-overlapped-modes)
+
+;; COMPATIBILITY for Emacs<29, which executes
+;; (defalias 'LaTeX-mode #'latex-mode) etc. in tex-mode.el.
+(with-eval-after-load 'tex-mode
+  ;; This must be no-op after (unload-feature 'tex-site).
+  (if (featurep 'tex-site)
+      (TeX--alias-overlapped-modes t)))
+
 (defconst AUCTeX-version "@AUCTEXVERSION@"
   "AUCTeX version.
 If not a regular release, the date of the last change.")
diff --git a/tex.el b/tex.el
index 4b871841fe..4768651826 100644
--- a/tex.el
+++ b/tex.el
@@ -183,73 +183,73 @@ If nil, none is specified."
 (defcustom TeX-command-list
   '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) 
%S%(PDFout)%(mode)%' %(output-dir) %t"
      TeX-run-TeX nil
-     (plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX")
+     (plain-TeX-mode AmSTeX-mode Texinfo-mode) :help "Run plain TeX")
     ("LaTeX" "%`%l%(mode)%' %T"
      TeX-run-TeX nil
-     (latex-mode doctex-mode) :help "Run LaTeX")
+     (LaTeX-mode docTeX-mode) :help "Run LaTeX")
     ;; Not part of standard TeX.
     ("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t" TeX-run-compile nil
-     (texinfo-mode) :help "Run Makeinfo with Info output")
+     (Texinfo-mode) :help "Run Makeinfo with Info output")
     ("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t" 
TeX-run-compile nil
-     (texinfo-mode) :help "Run Makeinfo with HTML output")
+     (Texinfo-mode) :help "Run Makeinfo with HTML output")
     ("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %(output-dir) %t"
-     TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
+     TeX-run-TeX nil (AmSTeX-mode) :help "Run AMSTeX")
     ;; support for ConTeXt  --pg
     ;; first version of ConTeXt to support nonstopmode: 2003.2.10
     ("ConTeXt" "%(cntxcom) --once --texutil %(extraopts) %(execopts)%t"
-     TeX-run-TeX nil (context-mode) :help "Run ConTeXt once")
+     TeX-run-TeX nil (ConTeXt-mode) :help "Run ConTeXt once")
     ("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t"
      TeX-run-TeX nil
-     (context-mode) :help "Run ConTeXt until completion")
+     (ConTeXt-mode) :help "Run ConTeXt until completion")
     ("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode
-                     context-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode
+                     ConTeXt-mode)
      :help "Run BibTeX")
     ("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Run Biber")
     ;; Not part of standard TeX.
     ;; It seems that texindex doesn't support "--output-dir" option.
     ("Texindex" "texindex %s.??" TeX-run-command nil
-     (texinfo-mode) :help "Run Texindex")
+     (Texinfo-mode) :help "Run Texindex")
     ;; TODO:
     ;; 1. Supply "--dvipdf" option if `TeX-PDF-mode' and
     ;;    `TeX-PDF-from-DVI' are non-nil.
     ;; 2. Supply "--build-dir=DIR" option when `TeX-output-dir' is
     ;;    non-nil.
     ("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command nil
-     (texinfo-mode) :help "Run Texi2dvi or Texi2pdf")
+     (Texinfo-mode) :help "Run Texi2dvi or Texi2pdf")
     ("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer")
     ("Print" "%p" TeX-run-command t t :help "Print the file")
     ("Queue" "%q" TeX-run-background nil t :help "View the printer queue"
      :visible TeX-queue-command)
     ("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Generate PostScript file")
     ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Convert DVI file to PostScript")
     ("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Convert DVI file to PDF with dvipdfmx")
     ("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Convert PostScript file to PDF")
     ("Glossaries" "makeglossaries %(d-dir) %s" TeX-run-command nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Run makeglossaries to create glossary file")
     ("Index" "makeindex %(O?idx)" TeX-run-index nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Run makeindex to create index file")
     ("upMendex" "upmendex %(O?idx)" TeX-run-index t
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Run upmendex to create index file")
     ("Xindy" "texindy %s" TeX-run-command nil
-     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode)
+     (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
      :help "Run xindy to create index file")
-    ("Check" "lacheck %s" TeX-run-compile nil (latex-mode)
+    ("Check" "lacheck %s" TeX-run-compile nil (LaTeX-mode)
      :help "Check LaTeX file for correctness")
-    ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil (latex-mode)
+    ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil (LaTeX-mode)
      :help "Check LaTeX file for common mistakes")
     ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t
      :help "Spell-check the document")
@@ -346,12 +346,12 @@ Any additional elements get just transferred to the 
respective menu entries."
                         (boolean :tag "Prompt")
                         (choice :tag "Modes"
                                 (const :tag "All" t)
-                                (set (const :tag "Plain TeX" plain-tex-mode)
-                                     (const :tag "LaTeX" latex-mode)
-                                     (const :tag "DocTeX" doctex-mode)
-                                     (const :tag "ConTeXt" context-mode)
-                                     (const :tag "Texinfo" texinfo-mode)
-                                     (const :tag "AmSTeX" ams-tex-mode)))
+                                (set (const :tag "Plain TeX" plain-TeX-mode)
+                                     (const :tag "LaTeX" LaTeX-mode)
+                                     (const :tag "DocTeX" docTeX-mode)
+                                     (const :tag "ConTeXt" ConTeXt-mode)
+                                     (const :tag "Texinfo" Texinfo-mode)
+                                     (const :tag "AmSTeX" AmSTeX-mode)))
                         (repeat :tag "Menu elements" :inline t sexp))))
 
 (defcustom TeX-command-output-list
@@ -545,7 +545,7 @@ string."
                     "pdf"
                   "")))
     ("%(PDFout)" (lambda ()
-                   (cond ((eq major-mode 'ams-tex-mode)
+                   (cond ((eq major-mode 'AmSTeX-mode)
                           (if TeX-PDF-mode
                               " -output-format=pdf"
                             " -output-format=dvi"))
@@ -990,12 +990,12 @@ If RESET is non-nil, `TeX-command-next' is reset to
 (defun TeX-mode-prefix (&optional mode)
   "Return the prefix for the symbol MODE as string.
 If no mode is given the current major mode is used."
-  (cdr (assoc (or mode major-mode) '((plain-tex-mode . "plain-TeX")
-                                     (latex-mode . "LaTeX")
-                                     (ams-tex-mode . "AmSTeX")
-                                     (doctex-mode . "docTeX")
-                                     (texinfo-mode . "Texinfo")
-                                     (context-mode . "ConTeXt")))))
+  (cdr (assoc (or mode major-mode) '((plain-TeX-mode . "plain-TeX")
+                                     (LaTeX-mode . "LaTeX")
+                                     (AmSTeX-mode . "AmSTeX")
+                                     (docTeX-mode . "docTeX")
+                                     (Texinfo-mode . "Texinfo")
+                                     (ConTeXt-mode . "ConTeXt")))))
 
 ;;; Viewing
 
@@ -1745,6 +1745,7 @@ If this is nil, an empty string will be returned."
 (defvar TeX-source-correlate-map (make-sparse-keymap)
   "Keymap for `TeX-source-correlate-mode'.
 You could use this for unusual mouse bindings.")
+(set-keymap-parent TeX-source-correlate-map text-mode-map)
 
 (defun TeX-source-correlate-handle-TeX-region (file line col)
   "Translate backward search info with respect to `TeX-region'.
@@ -1845,13 +1846,14 @@ SyncTeX are recognized."
   :group 'TeX-view
   ;; Since this is a global minor mode and we don't want to require
   ;; tex.el when the mode variable is set, the mode function is called
-  ;; explicitly (if necessary) in `VirTeX-common-initialization'.  We
-  ;; do it there because otherwise `kill-all-local-variables' would
-  ;; reset `TeX-source-correlate-output-page-function' which is
+  ;; explicitly (if necessary) in `TeX-mode'.  We do it there because
+  ;; otherwise `kill-all-local-variables' would reset
+  ;; `TeX-source-correlate-output-page-function' which is
   ;; buffer-local.
   :global t
-  (set-keymap-parent TeX-mode-map (and TeX-source-correlate-mode
-                                       TeX-source-correlate-map))
+  (set-keymap-parent TeX-mode-map (if TeX-source-correlate-mode
+                                      TeX-source-correlate-map
+                                    text-mode-map))
   (TeX-set-mode-name 'TeX-source-correlate-mode t t)
   (setq TeX-source-correlate-start-server-flag TeX-source-correlate-mode)
   ;; Register Emacs for the SyncSource DBUS signal emitted by
@@ -2453,14 +2455,14 @@ Get `major-mode' from master file and enable it."
                             (TeX-master-file TeX-default-extension))
                          major-mode)
                      major-mode))
-             (comment-prefix (cond ((eq mode 'texinfo-mode) "@c ")
-                                   ((eq mode 'doctex-mode) "% ")
+             (comment-prefix (cond ((eq mode 'Texinfo-mode) "@c ")
+                                   ((eq mode 'docTeX-mode) "% ")
                                    (t "%%% ")))
              (mode-string (concat (and (boundp 'japanese-TeX-mode) 
japanese-TeX-mode
                                        "japanese-")
                                   (substring (symbol-name mode) 0 -5))))
         (newline)
-        (when (eq major-mode 'doctex-mode)
+        (when (eq major-mode 'docTeX-mode)
           (insert comment-prefix TeX-esc "endinput\n"))
         (insert
          comment-prefix "Local Variables:\n"
@@ -3633,41 +3635,41 @@ Choose `ignore' if you don't want AUCTeX to install 
support for font locking."
 ;;; The Mode
 
 (defvar TeX-format-list
-  '(("JLATEX" japanese-latex-mode
+  '(("JLATEX" japanese-LaTeX-mode
      "\\\\\\(documentstyle\\|documentclass\\)[^%\n]*{u?\\(j[s-]?\\|t\\)\
 \\(article\\|report\\|book\\|slides\\)")
-    ("JTEX" japanese-plain-tex-mode
+    ("JTEX" japanese-plain-TeX-mode
      "-- string likely in Japanese TeX --")
-    ("AMSTEX" ams-tex-mode
+    ("AMSTEX" AmSTeX-mode
      "\\\\document\\b")
-    ("CONTEXT" context-mode
+    ("CONTEXT" ConTeXt-mode
      "\\\\\\(start\\(text\\|tekst\\|proje[ck]t\\|proiect\\|\
 produ[ck]t\\|produs\\|environment\\|omgeving\\|umgebung\\|prostredi\\|mediu\\|\
 component\\|onderdeel\\|komponent[ea]\\|componenta\\)\
 \\|inizia\\(testo\\|progetto\\|prodotto\\|ambiente\\|componente\\)\
 \\)\\|%.*?interface=")
-    ("LATEX" latex-mode
+    ("LATEX" LaTeX-mode
      "\\\\\\(begin\\|\\(?:sub\\)\\{0,2\\}section\\|chapter\\|documentstyle\\|\
 documentclass\\)\\b")
-    ("TEX" plain-tex-mode "."))
+    ("TEX" plain-TeX-mode "."))
   "List of format packages to consider when choosing a TeX mode.
 
 A list with an entry for each format package available at the site.
 
 Each entry is a list with three elements.
 
-1. The name of the format package.
-2. The name of the major mode.
+1. The name of the format package (as string).
+2. The name of the major mode (as symbol).
 3. A regexp typically matched in the beginning of the file.
 
-When entering `tex-mode', each regexp is tried in turn in order to find
-the major mode to be used.")
+When entering `TeX-tex-mode', each regexp is tried in turn in
+order to find the major mode to be used.")
 
-(defcustom TeX-default-mode #'latex-mode
+(defcustom TeX-default-mode #'LaTeX-mode
   "Mode to enter for a new file when it can't be determined otherwise."
   :group 'TeX-misc
-  :type '(radio (function-item latex-mode)
-                (function-item plain-tex-mode)
+  :type '(radio (function-item LaTeX-mode)
+                (function-item plain-TeX-mode)
                 (function :tag "Other")))
 
 (defcustom TeX-force-default-mode nil
@@ -3677,16 +3679,27 @@ the major mode to be used.")
 
 ;;;###autoload
 (defun TeX-tex-mode ()
-  "Major mode in AUCTeX for editing TeX or LaTeX files.
+  "Call suitable AUCTeX major mode for editing TeX or LaTeX files.
 Tries to guess whether this file is for plain TeX or LaTeX.
 
 The algorithm is as follows:
 
-   1) if the file is empty or `TeX-force-default-mode' is not set to nil,
-      `TeX-default-mode' is chosen
-   2) If \\documentstyle or \\begin{, \\section{, \\part{ or \\chapter{ is
-      found, `latex-mode' is selected.
-   3) Otherwise, use `plain-tex-mode'"
+   1) If the file is empty or `TeX-force-default-mode' is not set to nil,
+      `TeX-default-mode' is chosen.
+   2) If non-commented out content matches with regular expression in
+      `TeX-format-list', use the associated major mode.  For example,
+      if \\documentclass or \\begin{, \\section{, \\part{ or \\chapter{ is
+      found, `LaTeX-mode' is selected.
+   3) Otherwise, use `TeX-default-mode'.
+
+By default, `TeX-format-list' has a fallback entry for
+`plain-TeX-mode', thus non-empty file which didn't match any
+other entries will enter `plain-TeX-mode'."
+  ;; This is a dispatch function meaningful only as target of
+  ;; `auto-mode-alist' and `major-mode-remap-alist'.  Hence we don't
+  ;; use `define-derived-mode'.  Note that it isn't a proper major
+  ;; mode and it actually makes little sense to specify this for
+  ;; "mode:" tag of file local variable.
   (interactive)
 
   (funcall (if (or (equal (buffer-size) 0)
@@ -3719,9 +3732,14 @@ The algorithm is as follows:
                   (memq 'font-latex-verbatim-face face)
                 (eq face 'font-latex-verbatim-face))))))
 
-(defun VirTeX-common-initialization ()
-  "Perform basic initialization."
-  (kill-all-local-variables)
+(define-derived-mode TeX-mode text-mode "TeX"
+  "Base mode for AUCTeX major modes except Texinfo mode.
+
+Not intended for direct use for user."
+  :abbrev-table nil
+  :after-hook (TeX-mode-cleanup)
+  :interactive nil
+
   (setq TeX-mode-p t)
   (setq TeX-output-extension (if TeX-PDF-mode "pdf" "dvi"))
   (setq indent-tabs-mode nil)
@@ -3759,24 +3777,6 @@ The algorithm is as follows:
   ;;                           (make-display-table)))
   ;;  (aset buffer-display-table ?\t (apply 'vector (append "<TAB>" nil)))
 
-  ;; Symbol & length completion.
-  ;; We have to move the setup of `TeX-complete-list' after
-  ;; `run-mode-hooks' in order to reflect the file local customization
-  ;; of `TeX-insert-braces' and `TeX-complete-word'.
-  (setq-local TeX-complete-list
-              (list (list "\\\\\\([a-zA-Z]*\\)"
-                          1
-                          (lambda ()
-                            (append (TeX-symbol-list-filtered)
-                                    (when (fboundp 'LaTeX-length-list)
-                                      (LaTeX-length-list))
-                                    (when (fboundp 'LaTeX-counter-list)
-                                      (mapcar (lambda (x)
-                                                `(,(concat "the" (car x))))
-                                              (LaTeX-counter-list)))))
-                          (if TeX-insert-braces "{}"))
-                    (list "" TeX-complete-word)))
-
   (funcall TeX-install-font-lock)
 
   ;; We want this to be early in the list, so we do not add it before
@@ -3819,6 +3819,57 @@ The algorithm is as follows:
                 (TeX-master-file nil nil t))
               (TeX-update-style t)) nil t))
 
+(defun TeX-mode-cleanup ()
+  "Cleanup function for `TeX-mode'.
+Run after mode hooks and file local variables application."
+  ;; Symbol & length completion.
+  (or (local-variable-p 'TeX-complete-list)
+      (setq-local TeX-complete-list
+                  (list (list "\\\\\\([a-zA-Z]*\\)"
+                              1
+                              (lambda ()
+                                (append
+                                 (TeX-symbol-list-filtered)
+                                 ;; These LaTeX-*-list are called even
+                                 ;; in non-LaTeX mode buffers, but
+                                 ;; that is permissible because they
+                                 ;; return empty list immediately.
+                                 (when (fboundp 'LaTeX-length-list)
+                                   (LaTeX-length-list))
+                                 (when (fboundp 'LaTeX-counter-list)
+                                   (mapcar (lambda (x)
+                                             `(,(concat "the" (car x))))
+                                           (LaTeX-counter-list)))))
+                              (if TeX-insert-braces "{}"))
+                        (list "" TeX-complete-word))))
+
+  ;; Complete style initialization in buffers which don't visit files
+  ;; and which are therefore missed by the setting of above
+  ;; `find-file-hook'.  This is necessary for `xref-find-references',
+  ;; for example. (bug#65912)
+  (unless buffer-file-truename
+    (TeX-update-style))
+
+  (TeX-set-mode-name))
+
+;; COMPATIBILITY for Emacs<29
+;;;###autoload
+(put 'TeX-mode 'auctex-function-definition (symbol-function 'TeX-mode))
+
+;; COMPATIBILITY for Emacs<30
+(unless (fboundp 'derived-mode-add-parents)
+  (advice-add 'derived-mode-p :after-until
+              ;; Don't quote by #'-style to avoid compiler warning.
+              'TeX--compat-derived-mode-p)
+  (defun TeX--compat-derived-mode-p (&rest modes)
+    "Add pseudo-parents facility to `derived-mode-p' like Emacs 30.
+Modes registered in `derived-mode-extra-parents' property of the
+current major mode name symbol are regarded as parent modes as
+long as `derived-mode-p' is concerned."
+    (let ((extra-parents (get major-mode 'derived-mode-extra-parents)))
+      (and extra-parents
+           (cl-loop for parent in extra-parents
+                    thereis (memq parent modes))))))
 
 ;;; Hilighting
 
@@ -4765,6 +4816,16 @@ Also see `ignore'.
 This is a compatibility function for Emacs versions prior to v.28."
     t))
 
+;; COMPATIBILITY for Emacs<30
+(if (fboundp 'derived-mode-add-parents)
+    (defalias 'TeX-derived-mode-add-parents #'derived-mode-add-parents)
+  ;; Adapted copy of `derived-mode-add-parents'.
+  (defun TeX-derived-mode-add-parents (mode extra-parents)
+    "Add EXTRA-PARENTS to the parents of MODE.
+Declares the parents of MODE to be its main parent (as defined
+in `define-derived-mode') plus EXTRA-PARENTS."
+    (put mode 'derived-mode-extra-parents extra-parents)))
+
 (defun TeX-match-buffer (n)
   "Return the substring corresponding to the N'th match.
 See `match-data' for details."
@@ -4827,9 +4888,6 @@ element to ALIST-VAR."
 
 ;;; Syntax Table
 
-(defvar-local TeX-mode-syntax-table (make-syntax-table)
-  "Syntax table used while in TeX mode.")
-
 (progn ; Define TeX-mode-syntax-table.
   (modify-syntax-entry (string-to-char TeX-esc)
                        "\\" TeX-mode-syntax-table)
@@ -4970,8 +5028,8 @@ Brace insertion is only done if point is in a math 
construct and
   "Call the function specified by the variable `TeX-newline-function'."
   (interactive) (call-interactively TeX-newline-function))
 
-(defvar TeX-mode-map
-  (let ((map (make-sparse-keymap)))
+(progn
+  (let ((map TeX-mode-map))
     ;; Standard
     ;; (define-key map "\177"     #'backward-delete-char-untabify)
     (define-key map "\C-c}"    #'up-list)
@@ -5031,8 +5089,9 @@ Brace insertion is only done if point is in a math 
construct and
     (define-key map "\C-c_" #'TeX-master-file-ask)  ;*** temporary
 
     (define-key map "\C-xng" #'TeX-narrow-to-group)
-    map)
-  "Keymap for common TeX and LaTeX commands.")
+
+    ;; Hide "Text" menu entry inherited from text mode.
+    (define-key map [menu-bar text] #'undefined)))
 
 (defun TeX-mode-specific-command-menu (mode)
   "Return a Command menu specific to the major MODE."
@@ -5162,7 +5221,7 @@ Brace insertion is only done if point is in a math 
construct and
      :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
      :help "Hide the macro containing point"]
     ["Hide Current Environment" TeX-fold-env
-     :visible (not (eq major-mode 'plain-tex-mode))
+     :visible (not (eq major-mode 'plain-TeX-mode))
      :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
      :help "Hide the environment containing point"]
     ["Hide Current Comment" TeX-fold-comment
@@ -5221,8 +5280,8 @@ Brace insertion is only done if point is in a math 
construct and
          ;; mode-specific menu title?
          (list
           (cond
-           ((eq major-mode 'doctex-mode) "LaTeX")
-           ((eq major-mode 'context-mode) "ConTeXt")
+           ((eq major-mode 'docTeX-mode) "LaTeX")
+           ((eq major-mode 'ConTeXt-mode) "ConTeXt")
            (t TeX-base-mode-name)))
          (or TeX-customization-menu
              (setq TeX-customization-menu
@@ -5232,7 +5291,6 @@ Brace insertion is only done if point is in a math 
construct and
      :help ,(format "Problems with AUCTeX %s? Mail us!"
                     AUCTeX-version)]))
 
-
 ;;; Verbatim constructs
 
 (defvar-local TeX-verbatim-p-function nil
@@ -5532,7 +5590,7 @@ reset to \" \"."
     ;; Preset mode-dependent syntax entries.  (Mode-independent entries
     ;; are set when the variable `TeX-search-syntax-table' is created.)
     (modify-syntax-entry (string-to-char TeX-esc) "\\" TeX-search-syntax-table)
-    (unless (eq major-mode 'texinfo-mode)
+    (unless (eq major-mode 'Texinfo-mode)
       (modify-syntax-entry ?\% "<" TeX-search-syntax-table))
     ;; Clean up the entries which can be specified as arguments.
     (dolist (elt char-syntax-alist)
@@ -6137,7 +6195,7 @@ With optional argument ARG, also reload the style hooks."
           (save-buffer)
         (TeX-auto-write)))
     (normal-mode)
-    ;; See also addition to `find-file-hook' in `VirTeX-common-initialization'.
+    ;; See also addition to `find-file-hook' in `TeX-mode'.
     (when (eq TeX-master 'shared) (TeX-master-file nil nil t))
     (TeX-update-style t)))
 
@@ -6218,7 +6276,7 @@ With prefix argument FORCE, always inserts \" characters."
                                              font-lock-comment-face)
                                            (1- (point))))
           (texmathp)
-          (and (TeX-in-comment) (not (eq major-mode 'doctex-mode))))
+          (and (TeX-in-comment) (not (eq major-mode 'docTeX-mode))))
       (self-insert-command (prefix-numeric-value force))
     (TeX-update-style)
     (let* ((lang-override (if (eq (car TeX-quote-language) 'override)
@@ -6457,7 +6515,7 @@ enter the number of the file to view, anything else to 
skip: ") list)))
 (autoload 'info-lookup->completions "info-look")
 
 (defvar TeX-doc-backend-alist
-  '((texdoc (plain-tex-mode latex-mode doctex-mode ams-tex-mode context-mode)
+  '((texdoc (plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode ConTeXt-mode)
             (lambda ()
               (when (executable-find "texdoc")
                 (TeX-search-files-by-type 'docs 'global t t)))
@@ -6465,25 +6523,25 @@ enter the number of the file to view, anything else to 
skip: ") list)))
               ;; texdoc in MiKTeX requires --view in order to start
               ;; the viewer instead of an intermediate web page.
               (call-process "texdoc" nil 0 nil "--view" doc)))
-    (latex-info (latex-mode)
+    (latex-info (LaTeX-mode)
                 (lambda ()
                   (mapcar (lambda (x)
                             (let ((x (car x)))
                               (if (string-match "\\`\\\\" x)
                                   (substring x 1) x)))
-                          (info-lookup->completions 'symbol 'latex-mode)))
+                          (info-lookup->completions 'symbol 'LaTeX-mode)))
                 (lambda (doc)
-                  (info-lookup-symbol (concat "\\" doc) 'latex-mode)))
-    (texinfo-info (texinfo-mode)
+                  (info-lookup-symbol (concat "\\" doc) 'LaTeX-mode)))
+    (texinfo-info (Texinfo-mode)
                   (lambda ()
                     (mapcar (lambda (x)
                               (let ((x (car x)))
                                 (if (string-match "\\`@" x)
                                     (substring x 1) x)))
                             (info-lookup->completions 'symbol
-                                                      'texinfo-mode)))
+                                                      'Texinfo-mode)))
                   (lambda (doc)
-                    (info-lookup-symbol (concat "@" doc) 'texinfo-mode))))
+                    (info-lookup-symbol (concat "@" doc) 'Texinfo-mode))))
   "Alist of backends used for looking up documentation.
 Each item consists of four elements.
 
@@ -6702,15 +6760,24 @@ error."
 
 ;;; Abbrev mode
 
-(defmacro TeX-abbrev-mode-setup (mode)
-  "Set up the abbrev table and variable for MODE."
+(defmacro TeX-abbrev-mode-setup (mode usertable)
+  "Set up the abbrev table and variable for MODE.
+The table inherits from USERTABLE if it is a valid abbrev table."
   (let ((symbol (intern (concat (symbol-name mode) "-abbrev-table")))
         (name (TeX-mode-prefix mode)))
     `(progn
        (defvar ,symbol nil
          ,(format "Abbrev table for %s mode." name))
        (define-abbrev-table ',symbol nil)
-       (abbrev-table-put ,symbol :parents (list text-mode-abbrev-table)))))
+       (let ((parents (list text-mode-abbrev-table)))
+         ;; Users may already have user abbrevs in tables based on the
+         ;; former mode names such as `latex-mode-abbrev-table',
+         ;; stored in .emacs.d/abbrev_defs.  In that case, add them as
+         ;; parent abbrev tables.
+         (if (and (boundp ',usertable)
+                  (abbrev-table-p ,usertable))
+             (push ,usertable parents))
+         (abbrev-table-put ,symbol :parents parents)))))
 
 
 ;;; Special provisions for other modes and libraries
@@ -7384,7 +7451,7 @@ in `TeX-expand-list-builtin' and `TeX-expand-list'."
            (format
             (if (and extra
                      (stringp TeX-command-text)
-                     (memq major-mode '(latex-mode doctex-mode))
+                     (memq major-mode '(LaTeX-mode docTeX-mode))
                      (memq TeX-engine '(default uptex)))
                 ;; Since TeXLive 2018, the default encoding for LaTeX
                 ;; files has been changed to UTF-8 if used with
@@ -7594,7 +7661,7 @@ omitted) and `TeX-region-file'."
                                 TeX-file-extensions)
              (TeX-save-document name-or-file-fn))
            TeX-command-default)
-          ((and (memq major-mode '(doctex-mode latex-mode))
+          ((and (memq major-mode '(docTeX-mode LaTeX-mode))
                 ;; Want to know if bib file is newer than .bbl
                 ;; We don't care whether the bib files are open in emacs
                 (TeX-check-files (TeX--concat-ext name-or-file-fn "bbl")
@@ -7938,7 +8005,7 @@ run of `TeX-run-format', use
 
   (let ((idx-file nil) (element nil))
     ;; Store md5 hash of the index file before running LaTeX.
-    (and (memq major-mode '(doctex-mode latex-mode))
+    (and (memq major-mode '(docTeX-mode LaTeX-mode))
          (prog1 (file-exists-p
                  (setq idx-file (expand-file-name (TeX-active-master "idx"))))
            ;; In order to avoid confusion and pollution of
@@ -8860,7 +8927,7 @@ from.")
   ;; names right when analysing the process output buffer.
   ;; Note that \usepackage[utf8]{inputenc} is enabled by default in
   ;; standard (pdf)latex since TeXLive 2018.
-  (if (and (memq major-mode '(latex-mode doctex-mode))
+  (if (and (memq major-mode '(LaTeX-mode docTeX-mode))
            ;; Japanese upLaTeX requires the same treatment with
            ;; respect to non-ascii characters other than Japanese, in
            ;; file names within \message{}.
@@ -9106,7 +9173,7 @@ If a prefix argument OVERRIDE-CONFIRM is given, 
confirmation will
 depend on it being positive instead of the entry in
 `TeX-command-list'."
   (interactive "P")
-  (if (eq major-mode 'latex-mode)
+  (if (eq major-mode 'LaTeX-mode)
       (let* ((bounds (LaTeX-command-section-boundaries))
              (TeX-command-region-begin (car bounds))
              (TeX-command-region-end (cdr bounds)))
@@ -9122,7 +9189,7 @@ depend on it being positive instead of the entry in
 (defun LaTeX-command-run-all-section ()
   "Compile the current section until an error occurs or it is finished."
   (interactive)
-  (if (eq major-mode 'latex-mode)
+  (if (eq major-mode 'LaTeX-mode)
       (let* ((bounds (LaTeX-command-section-boundaries))
              (TeX-command-region-begin (car bounds))
              (TeX-command-region-end (cdr bounds)))
diff --git a/texmathp.el b/texmathp.el
index 5631916ed0..3316c461e9 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -280,7 +280,7 @@ See the variable `texmathp-tex-commands' about which 
commands are checked."
   (let* ((pos (point)) math-on sw-match
          (bound (save-excursion
                   (if (re-search-backward
-                       (if (eq major-mode 'doctex-mode)
+                       (if (memq major-mode '(doctex-mode docTeX-mode))
                            "[\n\r]%*[ \t]*[\n\r]"
                          "[\n\r][ \t]*[\n\r]")
                        nil 1 texmathp-search-n-paragraphs)

Reply via email to