[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/fix-mode-names-overlap ef86afda 6/6: Commit for initialization c
From: |
Ikumi Keita |
Subject: |
feature/fix-mode-names-overlap ef86afda 6/6: Commit for initialization codes |
Date: |
Mon, 8 May 2023 09:44:56 -0400 (EDT) |
branch: feature/fix-mode-names-overlap
commit ef86afdac5d72e23096bb06fff7452b867545128
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Commit for initialization codes
* tex-site.el.in: Arrange initialization code to work with new major
mode names, making use of Emacs 29 new feature
`major-mode-remap-alist'.
* tex.el (TeX-format-list, TeX-tex-mode, TeX-modes): Adapt doc strings
and comments.
---
tex-site.el.in | 57 ++++++++++++++++++++++++++++++++++++++++++---------------
tex.el | 29 ++++++++++++++++++++---------
2 files changed, 62 insertions(+), 24 deletions(-)
diff --git a/tex-site.el.in b/tex-site.el.in
index 05ef1156..f788772b 100644
--- a/tex-site.el.in
+++ b/tex-site.el.in
@@ -46,6 +46,12 @@
;; 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.
+
+ ;; Delete predefined autoloads by tex-mode.el so that AUCTeX
+ ;; autoloads provided aftarwards take precedence.
+ (fset 'plain-TeX-mode nil)
+ (fset 'LaTeX-mode nil)
+
(load "auctex-autoloads" 'noerror 'nomessage))
;; Define here in order for `M-x customize-group <RET> AUCTeX <RET>'
@@ -82,12 +88,12 @@ 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)
@@ -100,25 +106,36 @@ 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)
+ (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
+ (assq-delete-all elt 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'."
@@ -127,6 +144,16 @@ set it with `TeX-modes-set'."
:set #'TeX-modes-set
:initialize #'custom-initialize-reset)
+;; COMPATIBILITY for Emacs<29, which executes
+;; (defalias 'LaTeX-mode #'latex-mode) etc. in tex-mode.el.
+;; This `with-eval-after-load' should be removed when the supported
+;; emacsens version becomes 29 or higher and (defun TeX-LaTeX-mode
+;; ...) etc. are turned into (define-derived-mode LaTeX-mode ...) etc.
+(with-eval-after-load 'tex-mode
+ (progn
+ (defalias 'plain-TeX-mode #'TeX-plain-TeX-mode)
+ (defalias 'LaTeX-mode #'TeX-LaTeX-mode)))
+
(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 f7810aa0..db8b9981 100644
--- a/tex.el
+++ b/tex.el
@@ -3675,12 +3675,12 @@ 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
"Mode to enter for a new file when it can't be determined otherwise."
@@ -3696,16 +3696,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
+ 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 `plain-TeX-mode'"
+ 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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/fix-mode-names-overlap ef86afda 6/6: Commit for initialization codes,
Ikumi Keita <=