[ Cc: changed ]

Hi Arash,

>>>>> Arash Esbati <ar...@gnu.org> writes:
> Hmm, strange.  I don't have Emacs 29 installed so I can't test it
> myself.

> I put this on my todo list and ask on emacs-devel how to proceed.  I
> think Emacs core should arrange to support this OOTB.

I think I have figured out the reason. The culprit is the insufficient
capability of pseudo-parent mode facility I discussed in bug#69069[1].
Eglot finds out the correct server if we extend
`provided-mode-derived-p' so that several our new modes identify
themselves as descended from `tex-mode' as the attached patch.

[1] https://lists.gnu.org/r/bug-auctex/2024-02/msg00041.html

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW

diff --git a/latex.el b/latex.el
index 1b9a1656..d3c1c22c 100644
--- a/latex.el
+++ b/latex.el
@@ -8331,7 +8331,9 @@ Run after mode hooks and file local variables application."
 
 ;; 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))
+;; COMPATIBILITY for emacs<30: `tex-mode' can be removed from the list
+;; once least supported emacsen becomes 30.
+(TeX-derived-mode-add-parents 'LaTeX-mode '(latex-mode tex-mode))
 
 (with-eval-after-load 'semantic/symref/grep
   (push '(docTeX-mode "*.dtx") semantic-symref-filepattern-alist))
@@ -8368,7 +8370,9 @@ runs the hooks in `docTeX-mode-hook'."
 ;; 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))
+;; COMPATIBILITY for emacs<30: `latex-mode' and `tex-mode' can be removed
+;; from the list once least supported emacsen becomes 30.
+(TeX-derived-mode-add-parents 'docTeX-mode '(doctex-mode latex-mode tex-mode))
 
 (defcustom docTeX-clean-intermediate-suffixes
   TeX-clean-default-intermediate-suffixes
diff --git a/plain-tex.el b/plain-tex.el
index e3ffd53d..4be55edc 100644
--- a/plain-tex.el
+++ b/plain-tex.el
@@ -153,7 +153,9 @@ Run after mode hooks and file local variables application."
 ;; 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))
+;; COMPATIBILITY for emacs<30: `tex-mode' can be removed from the list
+;; once least supported emacsen becomes 30.
+(TeX-derived-mode-add-parents 'plain-TeX-mode '(plain-tex-mode tex-mode))
 
 (defun plain-TeX-common-initialization ()
   "Common initialization for plain TeX like modes."
diff --git a/tests/latex/align-in.tex b/tests/latex/align-in.tex
new file mode 100644
index 00000000..b2c8a99e
--- /dev/null
+++ b/tests/latex/align-in.tex
@@ -0,0 +1,9 @@
+\documentclass{article}
+\begin{document}
+% Broken by new mode name (Bug#69069)
+\begin{tabular}{cccc}
+  Mat.-Nr. & Nachname & Vorname & Unterschrift \\
+  Mat. No. & Surname  & Name    & Signature
+\end{tabular}
+
+\end{document}
diff --git a/tests/latex/align-out.tex b/tests/latex/align-out.tex
new file mode 100644
index 00000000..b2c8a99e
--- /dev/null
+++ b/tests/latex/align-out.tex
@@ -0,0 +1,9 @@
+\documentclass{article}
+\begin{document}
+% Broken by new mode name (Bug#69069)
+\begin{tabular}{cccc}
+  Mat.-Nr. & Nachname & Vorname & Unterschrift \\
+  Mat. No. & Surname  & Name    & Signature
+\end{tabular}
+
+\end{document}
diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el
index eae951f1..e22d2a08 100644
--- a/tests/latex/latex-test.el
+++ b/tests/latex/latex-test.el
@@ -1,6 +1,6 @@
 ;;; latex-test.el --- tests for LaTeX mode  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2014-2022  Free Software Foundation, Inc.
+;; Copyright (C) 2014-2024  Free Software Foundation, Inc.
 
 ;; This file is part of AUCTeX.
 
@@ -53,6 +53,10 @@
  "nested-indent-in.tex"
  'LaTeX-nested-indent/out
  "nested-indent-out.tex"
+ 'LaTeX-align/in
+ "align-in.tex"
+ 'LaTeX-align/out
+ "align-out.tex"
  'docTeX/in
  "doctex-indent-in.dtx"
  'docTeX/out
@@ -696,6 +700,21 @@ check the indentation for optional argument of \\usepackage."
              (insert-file-contents LaTeX-conditionals-indent/out)
              (buffer-string)))))
 
+(ert-deftest LaTeX-align ()
+  "Test if align.el works correctly."
+  (should (string=
+           (with-temp-buffer
+             (insert-file-contents LaTeX-align/in)
+             (goto-char (point-min))
+             (LaTeX-mode)
+             (search-forward "\\begin{")
+             (forward-line 1)
+             (align-current)
+             (buffer-string))
+           (with-temp-buffer
+             (insert-file-contents LaTeX-align/out)
+             (buffer-string)))))
+
 (ert-deftest docTeX-indentation ()
   "Test if content in docTeX-mode is indented correctly."
   (should (string=
diff --git a/tests/tex/utility.el b/tests/tex/utility.el
index ac0a8aab..50916233 100644
--- a/tests/tex/utility.el
+++ b/tests/tex/utility.el
@@ -1,6 +1,6 @@
 ;;; utility.el --- tests for AUCTeX utility functions -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2017, 2021 Free Software Foundation, Inc.
+;; Copyright (C) 2017, 2021, 2024 Free Software Foundation, Inc.
 
 ;; This file is part of AUCTeX.
 
@@ -55,4 +55,20 @@
   (TeX-add-to-alist 'TeX-dummy-alist '((a a)))
   (should (equal TeX-dummy-alist '((b 2 3) (a 1 4 a)))))
 
+(ert-deftest TeX-pseudo-parent-mode ()
+  "Check pseudo parent modes are recognized.
+For example, `LaTeX-mode' should be regarded as derived from
+`latex-mode' for compatibility with the former mode names."
+  (require 'plain-tex)
+  (require 'latex)
+  (require 'tex-info)
+  (require 'context)
+  (require 'tex-jp)
+  (dolist (mode-pair TeX-mode-comparison-alist)
+    (should (provided-mode-derived-p (cdr mode-pair) (car mode-pair)))
+    ;; In addition, several modes should be regarded as derived from
+    ;; `tex-mode' for better compatibility with Emacs core.
+    (unless (memq (cdr mode-pair) '(Texinfo-mode ConTeXt-mode AmSTeX-mode))
+      (should (provided-mode-derived-p (cdr mode-pair) 'tex-mode)))))
+
 ;;; utility.el ends here
diff --git a/tex-info.el b/tex-info.el
index 63242e0d..fc10f018 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -1,6 +1,6 @@
 ;;; tex-info.el --- Support for editing Texinfo source.  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 1993-2023  Free Software Foundation, Inc.
+;; Copyright (C) 1993-2024  Free Software Foundation, Inc.
 
 ;; Maintainer: auctex-devel@gnu.org
 ;; Keywords: tex
@@ -890,6 +890,11 @@ Run after mode hooks and file local variables application."
 
   (TeX-set-mode-name))
 
+;; Compatibility for former mode name.  Directory local variables
+;; prepared for `texinfo-mode' continue to be valid for
+;; `Texinfo-mode'.
+(TeX-derived-mode-add-parents 'Texinfo-mode '(texinfo-mode))
+
 (defcustom Texinfo-clean-intermediate-suffixes
   '("\\.cps?" "\\.vrs?" "\\.fns?" "\\.tps?" "\\.pgs?" "\\.kys?")
   "List of regexps matching suffixes of files to be deleted.
diff --git a/tex-jp.el b/tex-jp.el
index cdb62d97..86a1b0e1 100644
--- a/tex-jp.el
+++ b/tex-jp.el
@@ -1,7 +1,6 @@
 ;;; tex-jp.el --- Support for Japanese TeX.  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 1999, 2001-2008, 2012-2013, 2016-2018, 2020-2023
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1999-2024 Free Software Foundation, Inc.
 
 ;; Author:     KOBAYASHI Shinji <k...@flab.fujitsu.co.jp>,
 ;;             Hidenobu Nabetani <n...@debian.or.jp>
@@ -427,8 +426,10 @@ Now `japanese-plain-tex-mode-initialization' is no-op.  Don't use it."))
 ;; 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'.
+;; COMPATIBILITY for emacs<30: `tex-mode' can be removed from the list
+;; once least supported emacsen becomes 30.
 (TeX-derived-mode-add-parents 'japanese-plain-TeX-mode
-                              '(japanese-plain-tex-mode plain-tex-mode))
+                              '(japanese-plain-tex-mode plain-tex-mode tex-mode))
 
 ;;;###autoload
 (define-derived-mode japanese-LaTeX-mode LaTeX-mode "LaTeX"
@@ -479,8 +480,10 @@ Now `japanese-latex-mode-initialization' is no-op.  Don't use it."))
 ;; Compatibility for former mode name.  Directory local variables
 ;; prepared for `japanese-latex-mode' and `latex-mode' continue to be
 ;; valid for `japanese-LaTeX-mode'.
+;; COMPATIBILITY for emacs<30: `tex-mode' can be removed from the list
+;; once least supported emacsen becomes 30.
 (TeX-derived-mode-add-parents 'japanese-LaTeX-mode
-                              '(japanese-latex-mode latex-mode))
+                              '(japanese-latex-mode latex-mode tex-mode))
 
 (defun japanese-LaTeX-guess-engine ()
   "Guess Japanese TeX engine and set it to `TeX-engine'.
diff --git a/tex.el b/tex.el
index 17cb1aa9..d1440963 100644
--- a/tex.el
+++ b/tex.el
@@ -3886,18 +3886,18 @@ Run after mode hooks and file local variables application."
 
 ;; COMPATIBILITY for Emacs<30
 (unless (fboundp 'derived-mode-add-parents)
-  (advice-add 'derived-mode-p :after-until
+  (advice-add 'provided-mode-derived-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))))))
+              'TeX--compat-provided-mode-derived-p)
+  (defun TeX--compat-provided-mode-derived-p (mode &rest modes)
+    "Add pseudo-parents facility to `provided-mode-derived-p' like Emacs 30.
+Modes registered in `derived-mode-extra-parents' property of MODE
+symbol are regarded as parent modes by `provided-mode-derived-p'."
+    (when (rassq mode TeX-mode-comparison-alist)
+      (let ((extra-parents (get mode 'derived-mode-extra-parents)))
+        (and extra-parents
+             (cl-loop for parent in extra-parents
+                      thereis (memq parent modes)))))))
 
 ;;; Hilighting
 

Reply via email to