[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex 9c6f701a0c 12/43: Use `define-derived-mode' for
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex 9c6f701a0c 12/43: Use `define-derived-mode' for AUCTeX major modes |
Date: |
Wed, 7 Feb 2024 06:07:09 -0500 (EST) |
branch: externals/auctex
commit 9c6f701a0c430f7208256185c1cd4889ff3bd777
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Use `define-derived-mode' for AUCTeX major modes
* latex.el (LaTeX-mode-syntax-table): Use `make-syntax-table' to
reduce overhead.
(TeX-LaTeX-mode-map,TeX-LaTeX-mode-hook): New defvaralias'es to make
`define-derived-mode' work with traditional variable names.
(TeX-LaTeX-mode): Define by `define-derived-mode'.
(docTeX-mode): Simplify.
(LaTeX-common-initialization): Simplify.
* plain-tex.el (TeX-plain-TeX-mode-map,TeX-plain-TeX-mode-hook): New
defvaralias'es to make `define-derived-mode' work with traditional
variable names.
(TeX-plain-TeX-mode): Define by `define-derived-mode'.
Move the tool bar related code into `plain-TeX-mode-hook' not to
install tool bar in AmSTeX mode.
(plain-TeX-common-initialization): Simplify.
(AmSTeX-mode): Define by `define-derived-mode' and make it derived
mode of `plain-TeX-mode'.
* tex-info.el (Texinfo-mode): Define by `define-derived-mode'.
* tex.el (TeX--VirTeX-mode-map,TeX--VirTeX-mode-hook): New
defvaralias'es to make `define-derived-mode' work with traditional
variable names.
(TeX-source-correlate-map): Set parent keymap to `text-mode-map'.
(TeX-source-correlate-mode): Reset parent keymap of `TeX-mode-map' to
`text-mode-map' when the minor mode is turned off.
(VirTeX-common-initialization): Simplify.
(TeX--VirTeX-mode): New base mode for AUCTeX major modes except
`Texinfo-mode'.
* context-en.el (ConTeXt-en-mode):
* context-nl.el (ConTeXt-nl-mode):
Define by `define-derived-mode' and make them derived mode of
`ConTeXt-mode'.
* context.el (ConTeXt-mode-common-initialization): Simplify.
(ConTeXt-mode): Define by `define-derived-mode'.
Move the contents into `change-major-mode-after-body-hook' so
that they don't interfere when `ConTeXt-mode' is called as parent of
`ConTeXt-en-mode' and `ConTeXt-nl-mode'.
(ConTeXt--auto-mode): Former major contents of `ConTeXt-mode'. It
also takes care of setting `TeX-base-mode-name'.
* tex-jp.el (japanese-plain-TeX-mode): Define by `define-derived-mode'
and make it derived mode of `plain-TeX-mode'.
Simplify the way to enable directory local variables.
(japanese-plain-tex-mode-initialization): Merge the contents into
`japanese-plain-TeX-mode'.
Revert the name to the former one and leave just a warning that it is
obsolete.
(japanese-LaTeX-mode): Define by `define-derived-mode' and make it
derived mode of `LaTeX-mode'.
Simplify the way to enable directory local variables.
(japanese-latex-mode-initialization): Merge the contents into
`japanese-LaTeX-mode'.
Revert the name to the former one and just warn the user that it is
obsolete.
(japanese-TeX-mode): Don't mark as permanent-local.
(japanese-TeX-reset-mode-name): Delete.
* tests/japanese/parse-timing.el (japanese-TeX-style-hook-timing):
Remove obsolete function `japanese-LaTeX-mode-initialization'.
---
context-en.el | 23 ++++----
context-nl.el | 22 +++----
context.el | 49 ++++++++--------
latex.el | 50 +++++++---------
plain-tex.el | 69 ++++++++++++----------
tests/japanese/parse-timing.el | 3 +-
tex-info.el | 20 ++-----
tex-jp.el | 127 +++++++++++++++++------------------------
tex.el | 36 +++++++++++-
9 files changed, 195 insertions(+), 204 deletions(-)
diff --git a/context-en.el b/context-en.el
index c9b984102c..26f8456482 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
@@ -203,26 +201,25 @@ That is, besides the section(-block) commands.")
'("sym" (TeX-arg-string "Symbol") (TeX-arg-literal " "))))
;;;###autoload
-(defun ConTeXt-en-mode ()
+(define-derived-mode ConTeXt-en-mode ConTeXt-mode "ConTeXt-en"
"Major mode for editing files for ConTeXt using its english 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)
+of `ConTeXt-mode-hook'.
+
+Don't use `ConTeXt-en-mode-hook' and `ConTeXt-en-mode-map', both
+specific to this mode. They are ignored unless `ConTeXt-en-mode'
+is called directly."
+ :syntax-table nil
+ :abbrev-table nil
+
;; set the ConTeXt interface
(setq ConTeXt-current-interface "en")
;; initialization
(ConTeXt-mode-common-initialization)
- (ConTeXt-en-mode-initialization)
-
- ;; set mode line
- (setq TeX-base-mode-name "ConTeXt-en")
- (TeX-set-mode-name))
+ (ConTeXt-en-mode-initialization))
;;;###autoload
(defalias 'context-en-mode #'ConTeXt-en-mode)
diff --git a/context-nl.el b/context-nl.el
index 956c132ffb..dfbcc3ac55 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
@@ -181,27 +179,25 @@ That is, besides the section(-block) commands.")
'("sym" (TeX-arg-string "Symbol") (TeX-arg-literal " "))))
;;;###autoload
-(defun ConTeXt-nl-mode ()
+(define-derived-mode ConTeXt-nl-mode ConTeXt-mode "ConTeXt-nl"
"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)
+of `ConTeXt-mode-hook'.
+
+Don't use `ConTeXt-nl-mode-hook' and `ConTeXt-nl-mode-map', both
+specific to this mode. They are ignored unless `ConTeXt-nl-mode'
+is called directly."
+ :syntax-table nil
+ :abbrev-table nil
;; set the ConTeXt interface
(setq ConTeXt-current-interface "nl")
;; initialization
(ConTeXt-mode-common-initialization)
- (ConTeXt-nl-mode-initialization)
-
- ;; set mode line
- (setq TeX-base-mode-name "ConTeXt-nl")
- (TeX-set-mode-name))
+ (ConTeXt-nl-mode-initialization))
;;;###autoload
(defalias 'context-nl-mode #'ConTeXt-nl-mode)
diff --git a/context.el b/context.el
index 362515a37a..fc448e9aaf 100644
--- a/context.el
+++ b/context.el
@@ -1823,16 +1823,9 @@ that is, you do _not_ have to cater for this yourself by
adding \\\\\\=' or $."
(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))
+ (plain-TeX-common-initialization)
(setq major-mode 'ConTeXt-mode)
- (setq local-abbrev-table ConTeXt-mode-abbrev-table)
(set (make-local-variable 'TeX-style-hook-dialect) ConTeXt-dialect)
(require (intern (concat "context-" ConTeXt-current-interface)))
@@ -1849,9 +1842,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)
@@ -1876,7 +1866,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,10 +1889,8 @@ 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-guess-current-interface ()
"Guess what ConTeXt interface the current buffer is using."
@@ -1926,19 +1913,33 @@ that is, you do _not_ have to cater for this yourself
by adding \\\\\\=' or $."
(defalias 'context-mode #'ConTeXt-mode)
;;;###autoload
-(defun ConTeXt-mode ()
+(define-derived-mode ConTeXt-mode TeX--VirTeX-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)
- (context-guess-current-interface)
- (require (intern (concat "context-" ConTeXt-current-interface)))
- (funcall (intern (concat "context-" ConTeXt-current-interface "-mode"))))
+ ;; When called as parent of ConTeXt-{en,nl}-mode, do nothing to
+ ;; avoid `TeX-add-symbols' and `ConTeXt-add-environments' for wrong
+ ;; language interface.
+ (add-hook 'change-major-mode-after-body-hook #'ConTeXt--auto-mode nil t))
+
+(defun ConTeXt--auto-mode ()
+ ;; When called as not parent of ConTeXt-{en,nl}-mode, guess ConTeXt
+ ;; interface and use it.
+ (remove-hook 'change-major-mode-after-body-hook #'ConTeXt--auto-mode t)
+ (when (string-equal mode-name "ConTeXt")
+ (context-guess-current-interface)
+ (ConTeXt-mode-common-initialization)
+ (require (intern (concat "context-" ConTeXt-current-interface)))
+ ;; This bypasses call to ConTeXt-{en,nl}-mode. Consequently,
+ ;; their mode-specific hook/keymap are ignored.
+ (funcall (intern (concat "ConTeXt-" ConTeXt-current-interface
"-mode-initialization")))
+
+ (setq mode-name
+ (concat "ConTeXt-" ConTeXt-current-interface)))
+ ;; set mode line
+ (setq TeX-base-mode-name mode-name))
(provide 'context)
diff --git a/latex.el b/latex.el
index f414fd6c12..81069f999f 100644
--- a/latex.el
+++ b/latex.el
@@ -118,7 +118,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.
@@ -6517,6 +6517,9 @@ environments."
;;; Keymap
+;; We can remove this defvaralias in future. See the comment before
+;; the definition of `TeX-LaTeX-mode'.
+(defvaralias 'TeX-LaTeX-mode-map 'LaTeX-mode-map)
(defvar LaTeX-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map TeX-mode-map)
@@ -7950,6 +7953,9 @@ This happens when \\left is inserted."
:type 'boolean
:group 'LaTeX-macro)
+;; We can remove this defvaralias in future. See the comment before
+;; the definition of `TeX-LaTeX-mode'.
+(defvaralias 'TeX-LaTeX-mode-hook 'LaTeX-mode-hook)
(defcustom LaTeX-mode-hook nil
"A hook run in LaTeX mode buffers."
:type 'hook
@@ -7972,22 +7978,23 @@ This happens when \\left is inserted."
;; #'latex-mode) in it.
;; When the least supported emacsen version becomes 29, we can safely
;; transform this definition to `(define-derived-mode LaTeX-mode
-;; text-mode ...)' and remove defaliases for compatibility.
+;; TeX-mode ...)' and remove defaliases for compatibility.
;;;###autoload
-(defun TeX-LaTeX-mode ()
- ;; FIXME: Use `define-derived-mode'.
+(define-derived-mode TeX-LaTeX-mode TeX--VirTeX-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)
+ :syntax-table LaTeX-mode-syntax-table
+ :abbrev-table LaTeX-mode-abbrev-table
+ :after-hook ;; Defeat filladapt
+ (if (bound-and-true-p filladapt-mode)
+ (turn-off-filladapt-mode))
+
(LaTeX-common-initialization)
- (setq TeX-base-mode-name "LaTeX")
+ (setq TeX-base-mode-name mode-name)
(setq major-mode 'LaTeX-mode)
(setq TeX-command-default "LaTeX")
(setq TeX-sentinel-default-function #'TeX-LaTeX-sentinel)
@@ -8014,14 +8021,8 @@ 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))
- (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))
@@ -8037,7 +8038,6 @@ of `LaTeX-mode-hook'."
"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
(set (make-local-variable 'LaTeX-insert-into-comments) t)
(set (make-local-variable 'LaTeX-syntactic-comments) t)
(setq TeX-default-extension docTeX-default-extension)
@@ -8045,8 +8045,7 @@ 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)
(funcall TeX-install-font-lock))
;; Enable LaTeX abbrevs in docTeX mode buffer.
@@ -8100,12 +8099,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)
@@ -8125,11 +8120,10 @@ function would return non-nil and `(match-string 1)'
would return
(require 'outline)
(set (make-local-variable 'outline-level) #'LaTeX-outline-level)
(set (make-local-variable 'outline-regexp) (LaTeX-outline-regexp t))
- (when (boundp 'outline-heading-alist)
- (setq outline-heading-alist
- (mapcar (lambda (x)
- (cons (concat "\\" (nth 0 x)) (nth 1 x)))
- LaTeX-section-list)))
+ (setq outline-heading-alist
+ (mapcar (lambda (x)
+ (cons (concat "\\" (nth 0 x)) (nth 1 x)))
+ LaTeX-section-list))
(setq-local TeX-auto-full-regexp-list
(delete-dups (append LaTeX-auto-regexp-list
@@ -8798,8 +8792,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/plain-tex.el b/plain-tex.el
index 79e8a42477..a314337a38 100644
--- a/plain-tex.el
+++ b/plain-tex.el
@@ -48,6 +48,9 @@ Install tool bar if `plain-TeX-enable-toolbar' and
;;; Keymap and menu
+;; We can remove this defvaralias in future. See the comment before
+;; the definition of `TeX-plain-TeX-mode'.
+(defvaralias 'TeX-plain-TeX-mode-map 'plain-TeX-mode-map)
(defvar plain-TeX-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map TeX-mode-map)
@@ -108,6 +111,9 @@ argument DIALECT-EXPR when the hook is to be run only on
plain-TeX file, or any mode derived thereof. See variable
`TeX-style-hook-dialect'." )
+;; We can remove this defvaralias in future. See the comment before
+;; the definition of `TeX-plain-TeX-mode'.
+(defvaralias 'TeX-plain-TeX-mode-hook 'plain-TeX-mode-hook)
(defcustom plain-TeX-mode-hook nil
"A hook run in plain TeX mode buffers."
:type 'hook
@@ -121,28 +127,36 @@ plain-TeX file, or any mode derived thereof. See variable
;; #'plain-tex-mode) in it.
;; When the least supported emacsen version becomes 29, we can safely
;; transform this definition to `(define-derived-mode plain-TeX-mode
-;; text-mode ...)' and remove defaliases for compatibility.
+;; TeX-mode ...)' and remove defaliases for compatibility.
;;;###autoload
-(defun TeX-plain-TeX-mode ()
+(define-derived-mode TeX-plain-TeX-mode TeX--VirTeX-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',
then the value of `TeX-mode-hook', and then the value
of `plain-TeX-mode-hook'."
- (interactive)
+ :syntax-table nil
+ :abbrev-table plain-TeX-mode-abbrev-table
+
(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-base-mode-name mode-name)
(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))
+
+ (add-hook 'plain-TeX-mode-hook
+ (lambda ()
+ ;; Don't install tool bar in AmSTeX mode.
+ (when (eq major-mode 'plain-TeX-mode)
+ (add-hook 'tool-bar-mode-hook
+ #'plain-TeX-maybe-install-toolbar nil t)
+ (plain-TeX-maybe-install-toolbar)))
+ nil t))
;; COMPATIBILITY for Emacs<29
;; Override defalias in tex-mode.el.
@@ -151,9 +165,6 @@ of `plain-TeX-mode-hook'."
(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
@@ -281,6 +292,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'.")
@@ -304,25 +320,18 @@ that is, you do _not_ have to cater for this yourself by
adding \\\\\\=' or $."
:group 'TeX-misc)
;;;###autoload
-(defun AmSTeX-mode ()
+(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', and then the value
-of `AmSTeX-mode-hook'."
- (interactive)
- (plain-TeX-common-initialization)
- (setq major-mode 'AmSTeX-mode)
- (use-local-map 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
- (setq TeX-base-mode-name "AmS-TeX")
- (setq TeX-command-default "AmSTeX")
- (run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'AmSTeX-mode-hook)
- (TeX-set-mode-name))
+ (setq TeX-base-mode-name mode-name)
+ (setq TeX-command-default "AmSTeX"))
;;;###autoload
(defalias 'ams-tex-mode #'AmSTeX-mode)
diff --git a/tests/japanese/parse-timing.el b/tests/japanese/parse-timing.el
index 81b2e3eaa6..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/tex-info.el b/tex-info.el
index 10ea33a82e..4bc034ef3e 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -629,24 +629,19 @@ is assumed by default."
;;;###autoload
-(defun 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 (TeX-set-mode-name)
+
(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)
(set (make-local-variable 'page-delimiter)
(concat
@@ -860,10 +855,7 @@ value of `Texinfo-mode-hook'."
;; RefTeX plugging
(add-hook 'reftex-mode-hook #'Texinfo-reftex-hook)
(if (and (boundp 'reftex-mode) reftex-mode)
- (Texinfo-reftex-hook))
-
- (run-mode-hooks 'text-mode-hook 'Texinfo-mode-hook)
- (TeX-set-mode-name))
+ (Texinfo-reftex-hook)))
(defcustom Texinfo-clean-intermediate-suffixes
'("\\.cps?" "\\.vrs?" "\\.fns?" "\\.tps?" "\\.pgs?" "\\.kys?")
diff --git a/tex-jp.el b/tex-jp.el
index 01ee6138dc..7cd9d62437 100644
--- a/tex-jp.el
+++ b/tex-jp.el
@@ -86,7 +86,6 @@ systems are determined by their values regardless of the
kanji option."
(defvar japanese-TeX-mode nil
"Non-nil means the current buffer handles Japanese TeX/LaTeX.")
(make-variable-buffer-local 'japanese-TeX-mode)
-(put 'japanese-TeX-mode 'permanent-local t)
(setq TeX-expand-list-builtin
(append
@@ -408,94 +407,70 @@ 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 `plain-TeX-mode'."
- (interactive)
- (setq japanese-TeX-mode t)
- (plain-TeX-mode))
+(define-derived-mode japanese-plain-TeX-mode plain-TeX-mode "plain-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)
-(defun japanese-plain-TeX-mode-initialization ()
- "Japanese plain-TeX specific initializations."
- (when japanese-TeX-mode
- (TeX-engine-set japanese-TeX-engine-default)
+ (setq japanese-TeX-mode t)
- ;; 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))))
+ (TeX-engine-set japanese-TeX-engine-default))
-(add-hook 'plain-TeX-mode-hook #'japanese-plain-TeX-mode-initialization)
+(defun japanese-plain-tex-mode-initialization ()
+ (message "\
+Now `japanese-plain-tex-mode-initialization' is no-op. Don't use it."))
;;;###autoload
(defalias 'japanese-plain-tex-mode #'japanese-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 `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)
- (LaTeX-mode))
-
-(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 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 in that case,
- ;; `hack-local-variables' 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)
+
+ ;; `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 ()
+ (message "\
+Now `japanese-latex-mode-initialization' is no-op. Don't use it."))
;;;###autoload
(defalias 'japanese-latex-mode #'japanese-LaTeX-mode)
-;; 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))
-
-;; Hack for directory local variable entry of the form (LaTeX-mode (...)) .
-(put 'japanese-LaTeX-mode 'derived-mode-parent 'LaTeX-mode)
-(put 'japanese-plain-TeX-mode 'derived-mode-parent 'plain-TeX-mode)
-
(defun japanese-LaTeX-guess-engine ()
"Guess Japanese TeX engine and set it to `TeX-engine'.
Document class and its option are taken into account. Do not
diff --git a/tex.el b/tex.el
index d3fdfced45..7fc288fc50 100644
--- a/tex.el
+++ b/tex.el
@@ -76,6 +76,9 @@
(defvar TeX-esc)
(defvar TeX-interactive-mode)
(defvar TeX-macro-global)
+;; We can remove this defvaralias in future. See the comment before
+;; the definition of `TeX--VirTeX-mode'.
+(defvaralias 'TeX--VirTeX-mode-map 'TeX-mode-map)
(defvar TeX-mode-map)
(defvar TeX-mode-p)
(defvar TeX-output-extension)
@@ -169,6 +172,9 @@ If nil, none is specified."
;; At least in TeXLive 2009 ConTeXt does not support an omega option anymore.
(make-obsolete-variable 'ConTeXt-Omega-engine 'TeX-engine-alist "11.86")
+;; We can remove this defvaralias in future. See the comment before
+;; the definition of `TeX--VirTeX-mode'.
+(defvaralias 'TeX--VirTeX-mode-hook 'TeX-mode-hook)
(defcustom TeX-mode-hook nil
"A hook run in TeX mode buffers."
:type 'hook
@@ -1748,6 +1754,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'.
@@ -1853,8 +1860,9 @@ SyncTeX are recognized."
;; 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
@@ -3751,7 +3759,6 @@ other entries will enter `plain-TeX-mode'."
(defun VirTeX-common-initialization ()
"Perform basic initialization."
- (kill-all-local-variables)
(setq TeX-mode-p t)
(setq TeX-output-extension (if TeX-PDF-mode "pdf" "dvi"))
(setq indent-tabs-mode nil)
@@ -4862,9 +4869,12 @@ element to ALIST-VAR."
;;; Syntax Table
+;; XXX: Now we have `text-mode' as parent mode. Should we make AUCTeX
+;; syntax table inherit from `text-mode-syntax-table'?
(defvar TeX-mode-syntax-table (make-syntax-table)
"Syntax table used while in TeX mode.")
+;; FIXME: Does this make sense?
(make-variable-buffer-local 'TeX-mode-syntax-table)
(progn ; Define TeX-mode-syntax-table.
@@ -5261,6 +5271,26 @@ Brace insertion is only done if point is in a math
construct and
:help ,(format "Problems with AUCTeX %s? Mail us!"
AUCTeX-version)]))
+;;; The mode (continuation)...
+;; We have to wait this `define-derived-mode' until `TeX-mode-map' and
+;; `TeX-mode-syntax-table' are ready.
+
+;; This should definitely be `TeX-mode', but then tex-mode.el would
+;; overwrite it by (defalias 'TeX-mode #'tex-mode) prior to emacs 29.
+;; When the least supported emacsen version becomes 29, we can safely
+;; transform this definition to `(define-derived-mode TeX-mode ...)'
+;; and get rid of ugly defvaralias'es for `TeX-mode-hook' and
+;; `TeX-mode-map'.
+(define-derived-mode TeX--VirTeX-mode text-mode "TeX"
+ "Base mode for AUCTeX major modes except Texinfo mode.
+
+Not intended for direct use for user."
+ :syntax-table TeX-mode-syntax-table
+ :abbrev-table nil
+ :after-hook (TeX-set-mode-name)
+ :interactive nil
+
+ (VirTeX-common-initialization))
;;; Verbatim constructs
- [elpa] externals/auctex updated (ea42107189 -> 561a08e1cf), Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 77ae6b5652 19/43: Restore tool bar on japanese-plain-TeX-mode, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 77a02f837a 30/43: Mark options as buffer-local with the :local keyword, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex f06778a7ae 27/43: * doc/changes.texi: Update the last change., Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 9b6130ad9a 11/43: Revert menu title, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex b407b239e2 36/43: Update style/simpleicons.el to package v11.1.0, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 8cb64a3487 21/43: Augment suitable default entry for M-?, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 43be8c047b 26/43: * doc/changes.texi: Document the change related mode name renewal., Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 9c6f701a0c 12/43: Use `define-derived-mode' for AUCTeX major modes,
Tassilo Horn <=
- [elpa] externals/auctex d42cd150b5 05/43: Commit for japanese LaTeX&plain-TeX mode, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 2dc9539961 25/43: Merge branch 'master' into feature/fix-mode-names-overlap, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 40d3662945 22/43: Add more default entries for M-?, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex a3c343654c 02/43: Commit for Texinfo mode, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex ab8f73a1cc 10/43: Merge branch 'master' into feature/fix-mode-names-overlap, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 15418dc957 34/43: ; * doc/changes.texi: Reshape the new entries., Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 46f2f2215d 07/43: Inherit abbrevs saved in table with former mode name, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex ebc69e7ae7 14/43: Canonicalize mode names, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex 561a08e1cf 43/43: Require emacs 27.1, Tassilo Horn, 2024/02/07
- [elpa] externals/auctex ebd04735e7 16/43: Merge branch 'master' into feature/fix-mode-names-overlap, Tassilo Horn, 2024/02/07