auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AUCTeX and "builtin latex mode" integration


From: Stefan Monnier
Subject: Re: AUCTeX and "builtin latex mode" integration
Date: Tue, 20 Sep 2022 15:57:54 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Maybe we could start by stating some goals:

- AUCTeX should not set the `major-mode` to point to
  non-AUCTeX functions (even if/when it overrides those functions).

- Cleanup the mode function names.  Currently, AUCTeX's LaTeX mode is
  variously called:

    latex-mode
    TeX-latex-mode
    LaTeX-mode

  AUCTeX should pick one and stick to it as much as possible (e.g. fix
  all the docs and have the auxiliary user-exposed variables be named
  accordingly to the base major mode name).

WIP patch below.


        Stefan


diff --git a/font-latex.el b/font-latex.el
index 4406dea610..577a9834a0 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -36,6 +36,7 @@
 
 (require 'font-lock)
 (require 'tex)
+(require 'latex)
 
 (eval-when-compile
   (require 'cl-lib))
@@ -1285,7 +1286,7 @@ triggers Font Lock to recognize the change."
 
 (defun font-latex--make-syntax-propertize-function ()
   "Return a `syntax-propertize-function' for (La|Doc)TeX documents."
-  (let ((kws ;; (if (derived-mode-p 'doctex-mode)
+  (let ((kws ;; (if (LaTeX--doctex-p)
              ;;     font-latex-doctex-syntactic-keywords
                font-latex-syntactic-keywords)) ;; )
     (syntax-propertize-via-font-lock kws)))
@@ -1324,7 +1325,7 @@ triggers Font Lock to recognize the change."
             syntax-propertize-wholelines
             font-latex-sp-extend-region-backwards-verb-env))))
     ;; Add the mode-dependent stuff to the basic variables defined above.
-    (if (eq major-mode 'doctex-mode)
+    (if (LaTeX--doctex-p)
         (progn
           (setcar defaults (append (car defaults)
                                    '(font-latex-doctex-keywords)))
@@ -1429,7 +1430,8 @@ OPENCHAR is the opening character and CLOSECHAR is the 
closing
 character.  Character pairs are usually { } or [ ].  Comments are
 ignored during the search."
   (let ((parse-sexp-ignore-comments
-         (not (eq major-mode 'doctex-mode))) ; scan-sexps ignores comments
+         ;; `scan-sexps' ignores comments.
+         (not (LaTeX--doctex-p)))
         (init-point (point))
         (mycount 1)
         (esc-char (or (and (boundp 'TeX-esc) TeX-esc) "\\"))
@@ -1482,13 +1484,14 @@ ignored during the search."
       (forward-line 0)
       (if (and (eq (char-after) ?\%)
                (not (font-latex-faces-present-p 'font-latex-verbatim-face)))
-          (not (eq major-mode 'doctex-mode))
+          (not (LaTeX--doctex-p))
         (catch 'found
           (while (progn (skip-chars-forward "^%" limit)
                         (< (point) limit))
             (when (and (save-excursion
                          (zerop (mod (skip-chars-backward
-                                      (regexp-quote esc-char)) 2)))
+                                      (regexp-quote esc-char))
+                                     2)))
                        (not (font-latex-faces-present-p
                              'font-latex-verbatim-face)))
               (throw 'found t))
@@ -1510,7 +1513,7 @@ If POS is omitted, the current position of point is used."
 (defun font-latex-forward-comment ()
   "Like `forward-comment' but with special provisions for docTeX mode.
 In docTeX mode \"%\" at the start of a line will be treated as whitespace."
-  (if (eq major-mode 'doctex-mode)
+  (if (LaTeX--doctex-p)
       ;; XXX: We should probably cater for ^^A as well.
       (progn
         (while (progn (if (bolp) (skip-chars-forward "%"))
@@ -1767,7 +1770,7 @@ cases.")
          (pos (funcall search)))
     (while (and pos
                 (member (match-string 1)
-                        (if (eq major-mode 'doctex-mode)
+                        (if (LaTeX--doctex-p)
                             (remove "_" font-latex-match-simple-exclude-list)
                           font-latex-match-simple-exclude-list)))
       (setq pos (funcall search)))
diff --git a/latex.el b/latex.el
index 59ba9cbfc6..02d23803ca 100644
--- a/latex.el
+++ b/latex.el
@@ -894,6 +894,11 @@ position just before \\begin and the position just before
 
 (defvar LaTeX-syntactic-comments) ;; Defined further below.
 
+(defsubst LaTeX--doctex-p ()
+  ;; FIXME: What's the difference between this test and testing
+  ;; `LaTeX-syntactic-comments'?
+  (derived-mode-p 'docTeX-mode))
+
 (defun LaTeX-current-environment (&optional arg)
   "Return the name (a string) of the enclosing LaTeX environment.
 With optional ARG>=1, find that outer level.
@@ -925,7 +930,7 @@ work analogously."
                   ;; comment-prefix.  Hence, the next check just looks
                   ;; if we're inside such a group and returns t to
                   ;; recognize such a situation.
-                  (and (eq major-mode 'doctex-mode)
+                  (and (LaTeX--doctex-p)
                        (member (match-string-no-properties 2)
                                '("macrocode" "macrocode*"))))
           (setq arg (if (string= (match-string 1) "end") (1+ arg) (1- arg)))))
@@ -939,7 +944,8 @@ work analogously."
     (save-excursion
       (re-search-backward
        (concat "^%    " (regexp-quote TeX-esc)
-               "\\(begin\\|end\\)[ \t]*{macrocode\\*?}") nil 'move)
+               "\\(begin\\|end\\)[ \t]*{macrocode\\*?}")
+       nil 'move)
       (not (or (bobp)
                (= (char-after (match-beginning 1)) ?e))))))
 
@@ -3727,10 +3733,10 @@ non-parenthetical delimiters, like \\verb+foo+, are 
recognized."
 ;;; Formatting
 
 (defcustom LaTeX-syntactic-comments t
-  "If non-nil comments will be handled according to LaTeX syntax.
+  "If non-nil, comments' contents are expected to obey LaTeX syntax.
 This variable influences, among others, the behavior of
 indentation and filling which will take LaTeX syntax into
-consideration just as is in the non-commented source code."
+consideration just as t is in the non-comment source code."
   :type 'boolean
   :group 'LaTeX)
 
@@ -4047,7 +4053,7 @@ Lines starting with an item is given an extra indentation 
of
                  (concat (match-string 0) (TeX-comment-padding-string))))))
     (save-excursion
       (cond ((and fill-prefix
-                  (eq major-mode 'doctex-mode)
+                  (LaTeX--doctex-p)
                   (TeX-in-line-comment))
              ;; If point is in a line comment in `doctex-mode' we only
              ;; consider the inner indentation.  An exception is when
@@ -4123,7 +4129,7 @@ outer indentation in case of a commented line.  The 
symbols
           entry
           found)
       (cond ((save-excursion (beginning-of-line) (bobp)) 0)
-            ((and (eq major-mode 'doctex-mode)
+            ((and (LaTeX--doctex-p)
                   fill-prefix
                   (TeX-in-line-comment)
                   (progn
@@ -4253,7 +4259,7 @@ outer indentation in case of a commented line.  The 
symbols
     ;; where large amounts of line comments may have to be skipped
     ;; and indentation should not be influenced by unrelated code in
     ;; other macrocode environments.
-    (while (and (not (eq major-mode 'doctex-mode))
+    (while (and (not (LaTeX--doctex-p))
                 (not comment-current-flag)
                 (TeX-in-commented-line)
                 (not (bobp)))
@@ -4266,7 +4272,7 @@ outer indentation in case of a commented line.  The 
symbols
     ;; code comments).  Additionally we don't want to compute inner
     ;; indentation when a commented and a non-commented line are
     ;; compared.
-    (cond ((or (and (eq major-mode 'doctex-mode)
+    (cond ((or (and (LaTeX--doctex-p)
                     (or (and line-comment-current-flag
                              (not line-comment-last-flag))
                         (and (not line-comment-current-flag)
@@ -4287,7 +4293,7 @@ outer indentation in case of a commented line.  The 
symbols
               ;; Some people have opening braces at the end of the
               ;; line, e.g. in case of `\begin{letter}{%'.
               (TeX-brace-count-line)))
-          ((and (eq major-mode 'doctex-mode)
+          ((and (LaTeX--doctex-p)
                 (looking-at (concat (regexp-quote TeX-esc)
                                     "end[ \t]*{macrocode\\*?}"))
                 fill-prefix
@@ -4380,7 +4386,7 @@ outer indentation in case of a commented line.  The 
symbols
                      ;; indented syntax-aware so we need their inner
                      ;; indentation.
                      (and (TeX-in-line-comment)
-                          (eq major-mode 'doctex-mode))))))
+                          (LaTeX--doctex-p))))))
       ;; INNER indentation
       (save-excursion
         (beginning-of-line)
@@ -4404,7 +4410,7 @@ recognized."
                (eq force-type 'inner))
           (and (not force-type)
                (or (and (TeX-in-line-comment)
-                        (eq major-mode 'doctex-mode))
+                        (LaTeX--doctex-p))
                    (and (TeX-in-commented-line)
                         ;; Only move after the % if we're not
                         ;; performing a newline command (bug#47757).
@@ -5013,7 +5019,7 @@ depends on the value of `LaTeX-syntactic-comments'."
        ((or (or LaTeX-syntactic-comments
                 (and (not LaTeX-syntactic-comments)
                      (not has-comment)))
-            (and (eq major-mode 'doctex-mode)
+            (and (LaTeX--doctex-p)
                  (TeX-in-line-comment)))
         (let ((fill-prefix comment-fill-prefix))
           (save-excursion
@@ -6220,8 +6226,6 @@ the symbols will be surrounded by dollar signs.  The 
following
 commands are defined:
 
 \\{LaTeX-math-mode-map}"
-  :init-value nil
-  :lighter nil
   :keymap (list (cons (LaTeX-math-abbrev-prefix) LaTeX-math-keymap))
   (TeX-set-mode-name))
 (defalias 'latex-math-mode #'LaTeX-math-mode)
@@ -7221,21 +7225,11 @@ This happens when \\left is inserted."
 (declare-function LaTeX-preview-setup "preview")
 
 ;;;###autoload
-(defun TeX-latex-mode ()
-  ;; FIXME: Use `define-derived-mode'.
+(define-derived-mode LaTeX-mode TeX-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)
+See info under AUCTeX for full documentation."
   (LaTeX-common-initialization)
   (setq TeX-base-mode-name "LaTeX")
-  (setq major-mode 'latex-mode)
   (setq TeX-command-default "LaTeX")
   (setq TeX-sentinel-default-function #'TeX-LaTeX-sentinel)
   (add-hook 'tool-bar-mode-hook #'LaTeX-maybe-install-toolbar nil t)
@@ -7261,30 +7255,26 @@ 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))
-  (when (< 25 emacs-major-version)
-    ;; Set up flymake backend, see latex-flymake.el
-    (add-hook 'flymake-diagnostic-functions #'LaTeX-flymake nil t)))
+  (add-hook 'after-change-major-mode-hook
+            (lambda ()
+              (when (fboundp 'LaTeX-preview-setup)
+                (LaTeX-preview-setup))
+              ;; Defeat filladapt
+              (if (and (boundp 'filladapt-mode)
+                       filladapt-mode)
+                  (turn-off-filladapt-mode))
+              ;; FIXME: Why is this in the after-change-mode function?
+              (when (< 25 emacs-major-version)
+                ;; Set up flymake backend, see latex-flymake.el
+                (add-hook 'flymake-diagnostic-functions #'LaTeX-flymake nil 
t)))
+            nil t))
 
 (TeX-abbrev-mode-setup doctex-mode)
 
-;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.dtx\\'" . doctex-mode))
-
 ;;;###autoload
 (define-derived-mode docTeX-mode TeX-latex-mode "docTeX"
-  "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'."
+  "Major mode in AUCTeX for editing .dtx files derived from `LaTeX-mode'."
   :abbrev-table doctex-mode-abbrev-table
-  (setq major-mode 'doctex-mode)
   (set (make-local-variable 'LaTeX-insert-into-comments) t)
   (set (make-local-variable 'LaTeX-syntactic-comments) t)
   (setq TeX-default-extension docTeX-default-extension)
diff --git a/plain-tex.el b/plain-tex.el
index 4f06a026f0..cca9a1299a 100644
--- a/plain-tex.el
+++ b/plain-tex.el
@@ -116,26 +116,18 @@ plain-TeX file, or any mode derived thereof. See variable
 (TeX-abbrev-mode-setup plain-tex-mode)
 
 ;;;###autoload
-(defun TeX-plain-tex-mode ()
+(define-derived-mode plain-TeX-mode TeX-mode "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)
   (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))
+  (plain-TeX-maybe-install-toolbar))
 
 (defun plain-TeX-common-initialization ()
   "Common initialization for plain TeX like modes."
diff --git a/preview.el b/preview.el
index 7796fcb4fd..8c39ed9f70 100644
--- a/preview.el
+++ b/preview.el
@@ -2272,7 +2272,7 @@ has FUNC called with its current buffer being set to it."
       (with-current-buffer (pop buffers)
         (when
             (or (memq (current-buffer) default-buffers)
-                (and (memq major-mode '(plain-tex-mode latex-mode))
+                (and (memq major-mode '(plain-TeX-mode LaTeX-mode))
                      (or (stringp TeX-master)
                          (eq TeX-master t))
                      (string= (expand-file-name (TeX-master-file t))
@@ -3104,7 +3104,7 @@ to add the preview functionality."
            (customize-menu-create 'preview))])
         ["Read documentation" preview-goto-info-page]
         ["Report Bug" preview-report-bug]))
-    (if (eq major-mode 'latex-mode)
+    (if (eq major-mode 'LaTeX-mode)
         (preview-mode-setup))
     (unless preview-tb-icon
       (setq preview-tb-icon (preview-filter-specs preview-tb-icon-specs)))
diff --git a/style/kpfonts.el b/style/kpfonts.el
index d55142f3f4..1b48eea92a 100644
--- a/style/kpfonts.el
+++ b/style/kpfonts.el
@@ -510,8 +510,6 @@ argument, the symbols will be surrounded by dollar signs.  
The
 following commands are defined:
 
 \\{LaTeX-kpfonts-mode-map}"
-  :init-value nil
-  :lighter nil
   :keymap (list (cons (LaTeX-kpfonts-abbrev-prefix) LaTeX-kpfonts-keymap))
   (TeX-set-mode-name))
 
diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index 9834487fa4..998b299101 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -1,6 +1,6 @@
 ;;; command-expansion.el --- tests for TeX command expansion  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2014-2021  Free Software Foundation, Inc.
+;; Copyright (C) 2014-2022  Free Software Foundation, Inc.
 
 ;; This file is part of AUCTeX.
 
@@ -88,7 +88,7 @@
   ;; Skip on w32 because the quoting style of `shell-quote-argument'
   ;; is different.
   (skip-unless (not (eq system-type 'windows-nt)))
-  (let ((major-mode 'latex-mode)
+  (let ((major-mode 'LaTeX-mode)
         (TeX-engine 'default)
         (TeX-command-extra-options " \"\\foo\"")
         TeX-master)
diff --git a/tex-fold.el b/tex-fold.el
index 6f74f75a3c..312485c9ed 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -903,8 +903,6 @@ the other elements.  The ordering among elements is 
maintained."
 Called interactively, with no prefix argument, toggle the mode.
 With universal prefix ARG (or if ARG is nil) turn mode on.
 With zero or negative ARG turn mode off."
-  :init-value nil
-  :lighter nil
   :keymap (list (cons TeX-fold-command-prefix TeX-fold-keymap))
   (if TeX-fold-mode
       (progn
diff --git a/tex-info.el b/tex-info.el
index 2ee3d7acc1..7e58750389 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -646,7 +646,7 @@ value of `Texinfo-mode-hook'."
   (setq TeX-sentinel-default-function #'TeX-TeX-sentinel)
   ;; Mostly stolen from texinfo.el
   (setq TeX-base-mode-name "Texinfo")
-  (setq major-mode 'texinfo-mode)
+  (setq major-mode 'TeX-texinfo-mode)
   (use-local-map Texinfo-mode-map)
   (set-syntax-table texinfo-mode-syntax-table)
 
diff --git a/tex-jp.el b/tex-jp.el
index 8428c3793a..fa226b8ec3 100644
--- a/tex-jp.el
+++ b/tex-jp.el
@@ -423,9 +423,7 @@ Set `japanese-TeX-mode' to t, and enter 
`TeX-plain-tex-mode'."
     ;; 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))))
+      (japanese-TeX--set-mode 'japanese-plain-tex-mode))))
 
 (add-hook 'plain-TeX-mode-hook #'japanese-plain-tex-mode-initialization)
 
@@ -474,19 +472,25 @@ Set `japanese-TeX-mode' to t, and enter `TeX-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.
+    ;; FIXME: Can we get rid of this hack?
     (when enable-local-variables
-      (setq major-mode 'japanese-latex-mode)
-      (add-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name
-                nil t))))
+      (japanese-TeX--set-mode 'japanese-latex-mode))))
 
 (add-hook 'LaTeX-mode-hook #'japanese-latex-mode-initialization)
 
+(defvar-local japanese-TeX--original-mode nil)
+
+(defun japanese-TeX--set-mode (mode)
+  (setq japanese-TeX--original-mode major-mode)
+  (setq major-mode mode)
+  (add-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name
+            nil t))
+
 ;; 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)))
+  (when japanese-TeX--original-mode
+    (setq major-mode japanese-TeX--original-mode)
+    (setq japanese-TeX--original-mode nil))
   (remove-hook 'hack-local-variables-hook #'japanese-TeX-reset-mode-name t))
 
 ;; Make `hack-dir-local-variables' to regard `latex-mode' as parent
diff --git a/tex.el b/tex.el
index 1497f2281c..196f3c0140 100644
--- a/tex.el
+++ b/tex.el
@@ -1598,7 +1598,6 @@ For available TYPEs, see variable `TeX-engine'."
 
 (define-minor-mode TeX-Omega-mode
   "Minor mode for using the Omega engine."
-  :init-value nil :lighter nil :keymap nil
   :group 'TeX-command
   (TeX-engine-set (if TeX-Omega-mode 'omega 'default)))
 (defalias 'tex-omega-mode #'TeX-Omega-mode)
@@ -2121,7 +2120,6 @@ for backward compatibility."
 
 (define-minor-mode TeX-interactive-mode
   "Minor mode for interactive runs of TeX."
-  :init-value nil :lighter nil :keymap nil
   :group 'TeX-command
   (TeX-set-mode-name 'TeX-interactive-mode t t))
 (defalias 'tex-interactive-mode #'TeX-interactive-mode)
@@ -2469,7 +2467,7 @@ Get `major-mode' from master file and enable it."
                                        "japanese-")
                                   (substring (symbol-name mode) 0 -5))))
         (newline)
-        (when (eq major-mode 'doctex-mode)
+        (when (TeX--doctext-p)
           (insert comment-prefix TeX-esc "endinput\n"))
         (insert
          comment-prefix "Local Variables:\n"
@@ -3722,7 +3720,6 @@ The algorithm is as follows:
 
 (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)
@@ -5208,7 +5205,7 @@ Brace insertion is only done if point is in a math 
construct and
         (easy-menu-add-item
          nil
          ;; Ugly hack because docTeX mode uses the LaTeX menu.
-         (list (if (eq major-mode 'doctex-mode) "LaTeX" TeX-base-mode-name))
+         (list (if (TeX--doctext-p) "LaTeX" TeX-base-mode-name))
          (or TeX-customization-menu
              (setq TeX-customization-menu
                    (customize-menu-create 'AUCTeX "Customize AUCTeX")))))
@@ -5217,6 +5214,10 @@ Brace insertion is only done if point is in a math 
construct and
      :help ,(format "Problems with AUCTeX %s? Mail us!"
                     AUCTeX-version)]))
 
+(define-derived-mode TeX-mode text-mode "generic-TeX"
+  "Parent mode of various(all?) AUCTeX modes."
+  (add-hook 'after-change-major-mode-hook #'TeX-set-mode-name nil t))
+
 
 ;;; Verbatim constructs
 
@@ -6151,7 +6152,7 @@ With prefix argument FORCE, always inserts \" characters."
                                              font-lock-comment-face)
                                            (1- (point))))
           (texmathp)
-          (and (TeX-in-comment) (not (eq major-mode 'doctex-mode))))
+          (and (TeX-in-comment) (not (TeX--doctext-p))))
       (self-insert-command (prefix-numeric-value force))
     (TeX-update-style)
     (let* ((lang-override (if (eq (car TeX-quote-language) 'override)
@@ -7350,7 +7351,7 @@ in `TeX-expand-list-builtin' and `TeX-expand-list'."
            (format
             (if (and extra
                      (stringp TeX-command-text)
-                     (memq major-mode '(latex-mode doctex-mode))
+                     (memq major-mode '(LaTeX-mode docTeX-mode))
                      (memq TeX-engine '(default uptex)))
                 ;; Since TeXLive 2018, the default encoding for LaTeX
                 ;; files has been changed to UTF-8 if used with
@@ -7560,7 +7561,7 @@ omitted) and `TeX-region-file'."
                                 TeX-file-extensions)
              (TeX-save-document name-or-file-fn))
            TeX-command-default)
-          ((and (memq major-mode '(doctex-mode latex-mode))
+          ((and (memq major-mode '(docTeX-mode LaTeX-mode))
                 ;; Want to know if bib file is newer than .bbl
                 ;; We don't care whether the bib files are open in emacs
                 (TeX-check-files (TeX--concat-ext name-or-file-fn "bbl")
@@ -7906,7 +7907,7 @@ run of `TeX-run-format', use
 
   (let ((idx-file nil) (element nil))
     ;; Store md5 hash of the index file before running LaTeX.
-    (and (memq major-mode '(doctex-mode latex-mode))
+    (and (memq major-mode '(docTeX-mode LaTeX-mode))
          (prog1 (file-exists-p
                  (setq idx-file (expand-file-name (TeX-active-master "idx"))))
            ;; In order to avoid confusion and pollution of
@@ -8829,7 +8830,7 @@ from.")
   ;; names right when analysing the process output buffer.
   ;; Note that \usepackage[utf8]{inputenc} is enabled by default in
   ;; standard (pdf)latex since TeXLive 2018.
-  (if (and (memq major-mode '(latex-mode doctex-mode))
+  (if (and (memq major-mode '(LaTeX-mode docTeX-mode))
            ;; Japanese upLaTeX requires the same treatment with
            ;; respect to non-ascii characters other than Japanese, in
            ;; file names within \message{}.
@@ -9066,6 +9067,11 @@ The section is determined by 
`LaTeX-command-section-level'."
             (forward-line 0)
             (point)))))
 
+(defsubst LaTeX--mode-p ()
+  ;; IIUC this excludes `docTeX-mode' and `plain-TeX-mode', but it *should*
+  ;; include `japanese-latex-mode' AFAICT.
+  (eq major-mode 'LaTeX-mode))
+
 (defun LaTeX-command-section (&optional override-confirm)
   "Run a command on the current section.
 
@@ -9081,7 +9087,7 @@ If a prefix argument OVERRIDE-CONFIRM is given, 
confirmation will
 depend on it being positive instead of the entry in
 `TeX-command-list'."
   (interactive "P")
-  (if (eq major-mode 'latex-mode)
+  (if (LaTeX--mode-p)
       (let* ((bounds (LaTeX-command-section-boundaries))
              (TeX-command-region-begin (car bounds))
              (TeX-command-region-end (cdr bounds)))
@@ -9097,7 +9103,7 @@ depend on it being positive instead of the entry in
 (defun LaTeX-command-run-all-section ()
   "Compile the current section until an error occurs or it is finished."
   (interactive)
-  (if (eq major-mode 'latex-mode)
+  (if (LaTeX--mode-p)
       (let* ((bounds (LaTeX-command-section-boundaries))
              (TeX-command-region-begin (car bounds))
              (TeX-command-region-end (cdr bounds)))
diff --git a/texmathp.el b/texmathp.el
index f02824cec1..c7d28cb16d 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -1,6 +1,6 @@
 ;;; texmathp.el -- Code to check if point is inside LaTeX math environment  
-*- lexical-binding: t; -*-
 
-;; Copyright (C) 1998-2021  Free Software Foundation, Inc.
+;; Copyright (C) 1998-2022  Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
 ;; Maintainer: auctex-devel@gnu.org
@@ -275,10 +275,10 @@ See the variable `texmathp-tex-commands' about which 
commands are checked."
   (let* ((pos (point)) math-on sw-match
          (bound (save-excursion
                   (if (re-search-backward
-                       (if (eq major-mode 'doctex-mode)
+                       (if (derived-mode-p 'doctex-mode 'docTeX-mode)
                            "[\n\r]%*[ \t]*[\n\r]"
                          "[\n\r][ \t]*[\n\r]")
-                                          nil 1 texmathp-search-n-paragraphs)
+                       nil 1 texmathp-search-n-paragraphs)
                       (match-beginning 0)
                     (point-min))))
          (mac-match (texmathp-match-macro bound))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]