Function: TeX-modes-set

TeX-modes-set is a byte-compiled function defined in tex-site.el.

Signature

(TeX-modes-set VAR VALUE &optional IGNORED)

Documentation

Set VAR (which should be TeX-modes) to VALUE.

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 either major-mode-remap-defaults or major-mode-remap-alist is available, use it for redirection in that order. Otherwise, use advice facility.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex-site.el
(defun TeX-modes-set (var value &optional _ignored)
  "Set VAR (which should be `TeX-modes') to VALUE.

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 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)
          (progn
            (cond ((boundp 'major-mode-remap-defaults)
                   ;; For Emacs 30 and later

                   ;; Remove the entry provided by tex-mode.el.
                   ;; <URL:https://lists.gnu.org/r/auctex-devel/2025-01/msg00000.html>
                   (setq major-mode-remap-defaults
                         (assq-delete-all dst major-mode-remap-defaults))
                   ;; (We don't restore the removed entry in the ELSE
                   ;; clause because it makes too little sense.)

                   ;; Add the intended entry.
                   (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)))))))