branch: master
commit 10c8f782f8c0456443f09db0c54403e8753ee52b
Author: Ikumi Keita <ik...@ikumi.que.jp>
Commit: Ikumi Keita <ik...@ikumi.que.jp>

    Keep compatibility with Org mode src editing (bug#71363)
    
    * tex-site.el.in (TeX-modes-set): Add entries for AUCTeX LaTeX mode to
    `org-src-lang-modes'.
    Use `major-mode-remap-defaults' for Emacs 30 and later, instead of
    `major-mode-remap-alist', in order to avoid altering user customize
    option.
    * doc/install.texi (Loading the package): Update the recommendation
    accordingly.
---
 doc/install.texi | 16 +++++++++-------
 tex-site.el.in   | 56 +++++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/doc/install.texi b/doc/install.texi
index c2499e63..74f5566d 100644
--- a/doc/install.texi
+++ b/doc/install.texi
@@ -371,13 +371,15 @@ list.  Type
 to manipulate the contents of @code{TeX-modes}.
 @end defopt
 
-Don't remove @code{tex-mode} from @code{TeX-modes} because it results in
-inconsistent behavior.
-
-On Emacs 29 and later, you can alter @code{major-mode-remap-alist} instead
-of @code{TeX-modes} as you like to arrange @AUCTeX{} redirections.  In
-fact, @code{TeX-modes} option does nothing other than setting up
-@code{major-mode-remap-alist} according its value on those Emacsens.
+Don't remove @code{tex-mode} from @code{TeX-modes} unless you set
+@code{TeX-modes} empty to disable @AUCTeX{} completely, otherwise it
+results in inconsistent behavior.
+
+On Emacs 29 and later, @AUCTeX{} uses either
+@code{major-mode-remap-defaults} or @code{major-mode-remap-alist} for
+redirection.  But we recommend not to customize them directly because the
+customization code for @code{TeX-modes} takes care of some other
+compatibility issues.
 
 If you want to remove a preinstalled @AUCTeX{} completely before any of
 its modes have been used,
diff --git a/tex-site.el.in b/tex-site.el.in
index 911a2080..7dd16333 100644
--- a/tex-site.el.in
+++ b/tex-site.el.in
@@ -113,29 +113,51 @@ 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."
+If either `major-mode-remap-defaults' or `major-mode-remap-alist' is
+available, use it for redirection in that order.  Otherwise, use advice
+facility."
   (custom-set-default var 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))))
-        (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))))))
+          (progn
+            (cond ((boundp 'major-mode-remap-defaults)
+                   ;; For Emacs 30 and later
+                   (add-to-list 'major-mode-remap-defaults (cons elt dst)))
+                  ((boundp 'major-mode-remap-alist)
+                   ;; COMPATIBILITY for Emacs 29
+                   (add-to-list 'major-mode-remap-alist (cons elt dst)))
+                  (t
+                   ;; COMPATIBILITY for Emacs<29
+                   (advice-add elt :override dst
+                               ;; COMPATIBILITY for Emacs 28
+                               ;; 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)))))
+            ;; Keep compatibility.  (bug#71363)
+            (if (eq elt 'latex-mode)
+                (with-eval-after-load 'org-src
+                  (defvar org-src-lang-modes) ; Silence byte compiler.
+                  ;; Check the actual presence in the entry in case that
+                  ;; the user once choosed AUCTeX LaTeX mode and
+                  ;; abandoned it afterwards in the same emacs session.
+                  (when (memq 'latex-mode TeX-modes)
+                    (push '("latex" . LaTeX) org-src-lang-modes)
+                    (push '("beamer" . LaTeX) org-src-lang-modes)))))
+        (cond ((boundp 'major-mode-remap-defaults)
+               ;; For Emacs 30 and later
+               (setq major-mode-remap-defaults
+                     (delete entry major-mode-remap-defaults)))
+              ((boundp 'major-mode-remap-alist)
+               ;; COMPATIBILITY for Emacs 29
+               (setq major-mode-remap-alist
+                     (delete entry major-mode-remap-alist)))
+              (t
+               ;; COMPATIBILITY for Emacs<29
+               (advice-remove elt dst)))))))
 
 (defcustom TeX-modes
   (mapcar #'car TeX-mode-alist)

Reply via email to