emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex f7c0c73 01/62: Enable lexical-binding for AUCTeX


From: Tassilo Horn
Subject: [elpa] externals/auctex f7c0c73 01/62: Enable lexical-binding for AUCTeX core files
Date: Sun, 20 Dec 2020 10:39:48 -0500 (EST)

branch: externals/auctex
commit f7c0c735d48c822a9df0ad486817084c9511d6bd
Author: Tassilo Horn <tsdh@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>

    Enable lexical-binding for AUCTeX core files
    
    * tex.el: Enable lexical-binding.
    (TeX-command-text,TeX-command-pos): Moved from tex-buf.el.
    (TeX-expand-pos,TeX-expand-command): New defvars used in place of `pos' and
    `command' in TeX-expand-list{,-builtin} entries.
    (TeX-expand-list-builtin): Use TeX-expand-pos and TeX-expand-command 
(instead
    of pos and command).  Use TeX-active-master instead of formerly dynamically
    bound `file'.
    (TeX-view-command-raw): Adapt to TeX-command-expand signature change.
    (TeX-exit-mark): New defvar.
    (TeX-parse-macro): Adapt docstring; bind and use TeX-exit-mark instead of
    exit-mark.
    (TeX-last-optional-rejected): New defvar.
    (TeX-parse-arguments): Use TeX-last-optional-rejected instead of
    last-optional-rejected.
    (TeX-parse-argument): Use TeX-exit-mark instead of exit-mark.
    (TeX-argument-insert): Use TeX-exit-mark and TeX-last-optional-rejected 
instead
    of the former unprefixed variables.
    (TeX-safe-auto-write,TeX-auto-untabify,TeX-auto-parse-region,TeX-verbatim-p)
    (TeX-submit-bug-report): Prefix unused var with _.
    (TeX-mode-specific-command-menu-entries): Don't bind `file'.
    (TeX-doc): Remove unused var `doc'.
    (TeX-run-ispell): Remove unused var `found'.
    (TeX-ispell-document): Use `when' instead of `if' with `progn'.
    * tex-buf.el: Enable lexical-binding.
    (TeX-command-expand): Remove file argument but use TeX-active-master 
instead.
    (TeX-command): Rename file argument to file-fn; adapt to TeX-command-expand
    signature change.
    (TeX--master-or-region-file-with-extra-quotes): Remove file-fn argument.
    * latex.el: Enable lexical-binding.
    (LaTeX-title,LaTeX-name,LaTeX-level,LaTeX-done-mark,LaTeX-toc): New defvars.
    (LaTeX-section): Bind them.
    (LaTeX-section-hook): Adapt docstring to the new defvars.
    (LaTeX-section-section): Ditto, and use the new defvars.
    
(LaTeX-section-heading,LaTeX-section-title,LaTeX-section-toc,LaTeX-section-label):
    Use the new defvars.
    (LaTeX-env-args): Use TeX-exit-mark instead of exit-mark.
    (TeX-arg-index): Prefix unused argument args with _.
    (TeX-arg-cite): Prefix unused argument definition with _.
    (LaTeX-mark-environment,LaTeX-forward-paragraph,LaTeX-backward-paragraph)
    (LaTeX-narrow-to-environment): Use _ for unused dotimes counter variable.
    (LaTeX-check-insert-macro-default-style): Use TeX-last-optional-rejected
    instead of last-optional-rejected.
    * context.el: Enable lexical-binding.
    
(ConTeXt-title,ConTeXt-name,ConTeXt-level,ConTeXt-done-mark,ConTeXt-reference):
    New defvars.
    (ConTeXt-section): Bind them.
    (ConTeXt-numbered-section-hook): Adapt docstring to the new defvars.
    (ConTeXt-unnumbered-section-hook): Ditto.
    (ConTeXt-numbered-section-heading,ConTeXt-unnumbered-section-heading)
    (ConTeXt-section-section,ConTeXt-section-ref): Use the new defvars.
    * preview.el.in (preview-generate-preview): Remove region-p argument.
    (preview-start-dvipng,preview-start-dvips)
    (preview-cache-preamble): Adapt to TeX-command-expand and
    preview-generate-preview signature change.
    (preview-region, preview-document): Ditto.
    * style/bicaption.el (LaTeX-arg-bicaption-bicaption): Use
    TeX-last-optional-rejected instead of last-optional-rejected.
    * style/booktabs.el ("booktabs"): Menion TeX-last-optional-rejected in 
comment.
    * style/caption.el (LaTeX-arg-caption-captionbox): Use
    TeX-last-optional-rejected instead of last-optional-rejected.
    * style/color.el (TeX-arg-color,(TeX-arg-color-fcolorbox): Use
    TeX-last-optional-rejected instead of last-optional-rejected.
    * style/exam.el: Enable lexical-binding.
    (LaTeX-exam-insert-item): Use LaTeX-current-environment instead of 
dynamically
    bound `environment'.
    * style/floatrow.el (LaTeX-floatrow-arg-floatbox): Use
    TeX-last-optional-rejected instead of last-optional-rejected.
    * style/ifluatex.el (LaTeX-ifluatex-set-TeX-exit-mark): Use TeX-exit-mark
    instead of exit-mark.
    * style/xcolor.el 
(TeX-arg-xcolor-definecolor,TeX-arg-xcolor-definecolorset):
    (TeX-arg-xcolor,TeX-arg-xcolor-fcolorbox): Use TeX-last-optional-rejected
    instead of last-optional-rejected.
    * tests/japanese/preview-latex.el (japanese-preview-preserve-kanji-option2)
    (japanese-preview-preserve-kanji-option3): Adapt to TeX-command-expand
    signature change.
    * tests/tex/command-expansion.el (TeX-command-expansion)
    (TeX-command-expansion-errors,TeX-command-detokenize)
    (TeX-command-expand-skip-file-name,TeX-command-expand-active-master): Adapt 
to
    TeX-command-expand signature change.
    * doc/auctex.texi (Sectioning): Describe LaTeX-level, LaTeX-name, 
LaTeX-title,
    LaTeX-toc, and LaTeX-done-mark instead of the former unprefixed vars.
---
 context.el                      | 146 +++++++++++++++++++---------------------
 doc/auctex.texi                 |  29 ++++----
 latex.el                        | 143 +++++++++++++++++++--------------------
 preview.el.in                   |  47 ++++++-------
 style/bicaption.el              |   6 +-
 style/booktabs.el               |   2 +-
 style/caption.el                |   6 +-
 style/color.el                  |   4 +-
 style/exam.el                   |  33 ++++-----
 style/floatrow.el               |  10 +--
 style/ifluatex.el               |  52 +++++++-------
 style/xcolor.el                 |  14 ++--
 tests/japanese/preview-latex.el |   6 +-
 tests/tex/command-expansion.el  |  23 +++----
 tex-buf.el                      | 143 ++++++++++++++++-----------------------
 tex.el                          | 134 +++++++++++++++++++-----------------
 16 files changed, 386 insertions(+), 412 deletions(-)

diff --git a/context.el b/context.el
index 626da22..a2e9314 100644
--- a/context.el
+++ b/context.el
@@ -1,4 +1,4 @@
-;;; context.el --- Support for ConTeXt documents.
+;;; context.el --- Support for ConTeXt documents.  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2003-2006, 2008, 2010, 2012, 2014-2020
 ;;   Free Software Foundation, Inc.
@@ -64,24 +64,6 @@
   :group 'ConTeXt
   :group 'TeX-macro)
 
-
-;;; variables
-
-;; Dynamically scoped vars used in certain macro's.
-;; BEWARE: We used to give them a global nil value, but this can mess up poor
-;; unrelated packages using those same vars but expecting them to be
-;; lexically scoped.
-;; So don't give them a global value, which makes sure the effect of `defvar'
-;; localized to this file!
-;; N.B.: These forms are commented out since they produce a "lack of
-;; prefix" warning during byte-compilation.  This way they produce
-;; only a "reference to free variable" one.
-;; (defvar done-mark) ; Position of point afterwards, default nil (meaning end)
-;; (defvar reference) ; Used by `ConTeXt-section-ref' and 
`ConTeXt-section-section'.
-;; (defvar title) ; Used by `ConTeXt-section-title' and 
`ConTeXt-section-section'.
-;; (defvar name)
-;; (defvar level)
-
 ;; others
 
 (defvar ConTeXt-known-interfaces '("cz" "de" "en" "it" "nl" "ro" "uk"))
@@ -271,6 +253,13 @@
 
 ;;; Sections
 
+;; Declare dynamically scoped vars.
+(defvar ConTeXt-title nil "Dynamically bound by `ConTeXt-section'.")
+(defvar ConTeXt-name nil "Dynamically bound by `ConTeXt-section'.")
+(defvar ConTeXt-level nil "Dynamically bound by `ConTeXt-section'.")
+(defvar ConTeXt-done-mark nil "Dynamically bound by `ConTeXt-section'.")
+(defvar ConTeXt-reference nil "Dynamically bound by `ConTeXt-section'.")
+
 (defun ConTeXt-section (arg)
   "Insert a template for a ConTeXt section.
 Determinate the type of section to be inserted, by the argument ARG.
@@ -301,23 +290,23 @@ The following variables can be set to customize:
 
   (interactive "*P")
   (let* ((val (prefix-numeric-value arg))
-        (level (cond ((null arg)
-                      (ConTeXt-current-section))
-                     ((listp arg)
-                      (ConTeXt-down-section))
-                     ((< val 0)
-                      (ConTeXt-up-section (- val)))
-                     (t val)))
-        (name (ConTeXt-numbered-section-name level))
-        (title "")
-         (reference nil)
-        (done-mark (make-marker)))
+        (ConTeXt-level (cond ((null arg)
+                              (ConTeXt-current-section))
+                             ((listp arg)
+                              (ConTeXt-down-section))
+                             ((< val 0)
+                              (ConTeXt-up-section (- val)))
+                             (t val)))
+        (ConTeXt-name (ConTeXt-numbered-section-name ConTeXt-level))
+        (ConTeXt-title "")
+         (ConTeXt-reference nil)
+        (ConTeXt-done-mark (make-marker)))
     (newline)
     (run-hooks 'ConTeXt-numbered-section-hook)
     (newline)
-    (if (marker-position done-mark)
-       (goto-char (marker-position done-mark)))
-    (set-marker done-mark nil)))
+    (if (marker-position ConTeXt-done-mark)
+       (goto-char (marker-position ConTeXt-done-mark)))
+    (set-marker ConTeXt-done-mark nil)))
 
 ;; LaTeX has a max function here, which makes no sense.
 ;; I think you want to insert a section that is max ConTeXt-largest-level
@@ -417,22 +406,24 @@ section."
 
 The following variables are set before the hooks are run
 
-`level' - numeric section level, see the documentation of `ConTeXt-section'.
-`name' - name of the sectioning command, derived from `level'.
-`title' - The title of the section, default to an empty string.
-`done-mark' - Position of point afterwards, default nil (meaning end).
+`ConTeXt-level' - numeric section level, see the documentation of 
`ConTeXt-section'.
+`ConTeXt-name' - name of the sectioning command, derived from `level'.
+`ConTeXt-title' - The title of the section, default to an empty string.
+`ConTeXt-done-mark' - Position of point afterwards, default nil (meaning end).
 
 The following standard hook exist -
 
-ConTeXt-section-heading: Query the user about the name of the
-sectioning command.  Modifies `level' and `name'.
+ConTeXt-numbered-section-heading: Query the user about the name
+of the sectioning command.  Modifies `ConTeXt-level' and
+`ConTeXt-name'.
 
 ConTeXt-section-title: Query the user about the title of the
-section.  Modifies `title'.
+section.  Modifies `ConTeXt-title'.
 
-ConTeXt-section-section: Insert ConTeXt section command according to
-`name', `title', and `reference'.  If `title' is an empty string,
-`done-mark' will be placed at the point they should be inserted.
+ConTeXt-section-section: Insert ConTeXt section command according
+to `ConTeXt-name', `ConTeXt-title', and `LaTeX-reference'.  If
+`ConTeXt-title' is an empty string, `ConTeXt-done-mark' will be
+placed at the point they should be inserted.
 
 ConTeXt-section-ref: Insert a reference for this section command.
 
@@ -463,22 +454,24 @@ in your .emacs file."
 
 The following variables are set before the hooks are run
 
-`level' - numeric section level, see the documentation of `ConTeXt-section'.
-`name' - name of the sectioning command, derived from `level'.
-`title' - The title of the section, default to an empty string.
-`done-mark' - Position of point afterwards, default nil (meaning end).
+`ConTeXt-level' - numeric section level, see the documentation of 
`ConTeXt-section'.
+`ConTeXt-name' - name of the sectioning command, derived from `ConTeXt-level'.
+`ConTeXt-title' - The title of the section, default to an empty string.
+`ConTeXt-done-mark' - Position of point afterwards, default nil (meaning end).
 
 The following standard hook exist -
 
-ConTeXt-section-heading: Query the user about the name of the
-sectioning command.  Modifies `level' and `name'.
+ConTeXt-unnumbered-section-heading: Query the user about the name
+of the sectioning command.  Modifies `ConTeXt-level' and
+`ConTeXt-name'.
 
 ConTeXt-section-title: Query the user about the title of the
-section.  Modifies `title'.
+section.  Modifies `ConTeXt-title'.
 
-ConTeXt-section-section: Insert ConTeXt section command according to
-`name', `title', and `reference'.  If `title' is an empty string,
-`done-mark' will be placed at the point they should be inserted.
+ConTeXt-section-section: Insert ConTeXt section command according
+to `ConTeXt-name', `ConTeXt-title', and `LaTeX-reference'.  If
+`ConTeXt-title' is an empty string, `ConTeXt-done-mark' will be
+placed at the point they should be inserted.
 
 ConTeXt-section-ref: Insert a reference for this section command.
 
@@ -512,48 +505,49 @@ in your .emacs file."
 Insert this hook into `ConTeXt-numbered-section-hook' to allow the user to 
change
 the name of the sectioning command inserted with `\\[ConTeXt-section]'."
   (let ((string (completing-read
-                (concat "Select level (default " name "): ")
+                (concat "Select level (default " ConTeXt-name "): ")
                 ConTeXt-numbered-section-list
                 nil nil nil)))
     ;; Update name
     (if (not (zerop (length string)))
-       (setq name string))))
+       (setq ConTeXt-name string))))
 
 (defun ConTeXt-unnumbered-section-heading ()
   "Hook to prompt for ConTeXt section name.
 Insert this hook into `ConTeXt-unnumbered-section-hook' to allow the user to 
change
 the name of the sectioning command inserted with `\\[ConTeXt-section]'."
   (let ((string (completing-read
-                (concat "Select level (default " name "): ")
+                (concat "Select level (default " ConTeXt-name "): ")
                 ConTeXt-unnumbered-section-list
                 nil nil nil)))
     ;; Update name
     (if (not (zerop (length string)))
-       (setq name string))))
+       (setq ConTeXt-name string))))
 
 (defun ConTeXt-section-title ()
   "Hook to prompt for ConTeXt section title.
 Insert this hook into `ConTeXt-(un)numbered-section-hook' to allow the user to 
change
 the title of the section inserted with `\\[ConTeXt-section]."
-  (setq title (TeX-read-string "What title: ")))
+  (setq ConTeXt-title (TeX-read-string "What title: ")))
 
 (defun ConTeXt-section-section ()
   "Hook to insert ConTeXt section command into the file.
-Insert this hook into `ConTeXt-section-hook' after those hooks which sets
-the `name', `title', and `reference' variables, but before those hooks which
+Insert this hook into `ConTeXt-section-hook' after those hooks
+which sets the `ConTeXt-name', `ConTeXt-title', and
+`ConTeXt-reference' variables, but before those hooks which
 assumes the section already is inserted."
-  (insert TeX-esc name)
-  (cond ((null reference))
-       ((zerop (length reference))
+  (insert TeX-esc ConTeXt-name)
+  (cond ((null ConTeXt-reference))
+       ((zerop (length ConTeXt-reference))
         (insert ConTeXt-optop)
-        (set-marker done-mark (point))
+        (set-marker ConTeXt-done-mark (point))
         (insert ConTeXt-optcl))
        (t
-        (insert ConTeXt-optop reference ConTeXt-optcl)))
+        (insert ConTeXt-optop ConTeXt-reference ConTeXt-optcl)))
   (insert TeX-grop)
-  (if (zerop (length title))
-      (set-marker done-mark (point)))
-  (insert title TeX-grcl)
+  (if (zerop (length ConTeXt-title))
+      (set-marker ConTeXt-done-mark (point)))
+  (insert ConTeXt-title TeX-grcl)
   (newline)
   ;; If RefTeX is available, tell it that we've just made a new section
   (and (fboundp 'reftex-notice-new-section)
@@ -563,13 +557,14 @@ assumes the section already is inserted."
   "Hook to insert a reference after the sectioning command.
 Insert this hook into `ConTeXt-section-hook' to prompt for a label to be
 inserted after the sectioning command."
-  (setq reference (completing-read
-                  (TeX-argument-prompt t nil
-                                       "Comma separated list of references")
-                  (LaTeX-label-list) nil nil))
+  (setq ConTeXt-reference
+        (completing-read
+        (TeX-argument-prompt t nil
+                             "Comma separated list of references")
+        (LaTeX-label-list) nil nil))
   ;; No reference or empty string entered?
-  (if (string-equal "" reference)
-      (setq reference nil)))
+  (if (string-equal "" ConTeXt-reference)
+      (setq ConTeXt-reference nil)))
 
 
 ;; Various
@@ -1147,7 +1142,8 @@ An optional fourth (or sixth) element means always 
replace if t."
 (defun ConTeXt-imenu-create-index-function ()
   "Imenu support function for ConTeXt."
   (TeX-update-style)
-  (let (entries level (regexp (ConTeXt-outline-regexp)))
+  (let (entries
+        (regexp (ConTeXt-outline-regexp)))
     (goto-char (point-max))
     (while (re-search-backward regexp nil t)
       (let* ((name (ConTeXt-outline-name))
diff --git a/doc/auctex.texi b/doc/auctex.texi
index b19b60d..1fd92e8 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -770,16 +770,16 @@ List of hooks to run when a new section is inserted.
 The following variables are set before the hooks are run
 
 @table @var
-@item level
+@item LaTeX-level
 Numeric section level, default set by prefix arg to
 @code{LaTeX-section}.
-@item name
+@item LaTeX-name
 Name of the sectioning command, derived from @var{level}.
-@item title
+@item LaTeX-title
 The title of the section, default to an empty string.
-@item toc
+@item LaTeX-toc
 Entry for the table of contents list, default nil.
-@item done-mark
+@item LaTeX-done-mark
 Position of point afterwards, default nil meaning after the inserted
 text.
 @end table
@@ -790,16 +790,17 @@ get the desired functionality by choosing from these 
hooks.
 @ftable @code
 @item LaTeX-section-heading
 Query the user about the name of the sectioning command.  Modifies
-@var{level} and @var{name}.
+@var{LaTeX-level} and @var{LaTeX-name}.
 @item LaTeX-section-title
-Query the user about the title of the section. Modifies @var{title}.
+Query the user about the title of the section. Modifies @var{LaTeX-title}.
 @item LaTeX-section-toc
-Query the user for the toc entry.  Modifies @var{toc}.
+Query the user for the toc entry.  Modifies @var{LaTeX-toc}.
 @item LaTeX-section-section
-Insert @LaTeX{} section command according to @var{name}, @var{title},
-and @var{toc}.  If @var{toc} is nil, no toc entry is inserted.  If
-@var{toc} or @var{title} are empty strings, @var{done-mark} will be
-placed at the point they should be inserted.
+Insert @LaTeX{} section command according to @var{LaTeX-name},
+@var{LaTeX-title}, and @var{LaTeX-toc}.  If @var{LaTeX-toc} is nil, no
+toc entry is inserted.  If @var{LaTeX-toc} or @var{LaTeX-title} are
+empty strings, @var{LaTeX-done-mark} will be placed at the point they
+should be inserted.
 @item LaTeX-section-label
 Insert a label after the section command.  Controlled by the variable
 @code{LaTeX-section-label}.
@@ -5354,8 +5355,8 @@ If you add new hooks, you can assume that point is placed 
directly after
 the previous argument, or after the macro name if this is the first
 argument.  Please leave point located after the argument you are
 inserting.  If you want point to be located somewhere else after all
-hooks have been processed, set the value of @code{exit-mark}.  It will
-point nowhere, until the argument hook sets it.
+hooks have been processed, set the value of @code{TeX-exit-mark}.  It
+will point nowhere, until the argument hook sets it.
 
 Some packages provide macros that are rarely useful to non-expert users.
 Those should be marked as expert macros using
diff --git a/latex.el b/latex.el
index 923d27a..2dc00ba 100644
--- a/latex.el
+++ b/latex.el
@@ -1,4 +1,4 @@
-;;; latex.el --- Support for LaTeX documents.
+;;; latex.el --- Support for LaTeX documents.  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 1991, 1993-2020 Free Software Foundation, Inc.
 
@@ -127,14 +127,11 @@ This depends on `LaTeX-insert-into-comments'."
 ;;; Sections
 
 ;; Declare dynamically scoped vars.
-;; N.B.: These forms are commented out since they produce a "lack of
-;; prefix" warning during byte-compilation.  This way they produce
-;; only a "reference to free variable" one.
-;; (defvar title)
-;; (defvar name)
-;; (defvar level)
-;; (defvar done-mark)
-;; (defvar toc)
+(defvar LaTeX-title nil "Dynamically bound by `LaTeX-section'.")
+(defvar LaTeX-name nil "Dynamically bound by `LaTeX-section'.")
+(defvar LaTeX-level nil "Dynamically bound by `LaTeX-section'.")
+(defvar LaTeX-done-mark nil "Dynamically bound by `LaTeX-section'.")
+(defvar LaTeX-toc nil "Dynamically bound by `LaTeX-section'.")
 
 (defun LaTeX-section (arg)
   "Insert a template for a LaTeX section.
@@ -160,25 +157,25 @@ The following variables can be set to customize:
 
   (interactive "*P")
   (let* ((val (prefix-numeric-value arg))
-        (level (cond ((null arg)
-                      (LaTeX-current-section))
-                     ((listp arg)
-                      (LaTeX-down-section))
-                     ((< val 0)
-                      (LaTeX-up-section (- val)))
-                     (t val)))
-        (name (LaTeX-section-name level))
-        (toc nil)
-        (title (if (TeX-active-mark)
-                   (buffer-substring (region-beginning)
-                                     (region-end))
-                 ""))
-        (done-mark (make-marker)))
+        (LaTeX-level (cond ((null arg)
+                            (LaTeX-current-section))
+                           ((listp arg)
+                            (LaTeX-down-section))
+                           ((< val 0)
+                            (LaTeX-up-section (- val)))
+                           (t val)))
+        (LaTeX-name (LaTeX-section-name LaTeX-level))
+        (LaTeX-toc nil)
+        (LaTeX-title (if (TeX-active-mark)
+                         (buffer-substring (region-beginning)
+                                           (region-end))
+                       ""))
+        (LaTeX-done-mark (make-marker)))
     (run-hooks 'LaTeX-section-hook)
     (LaTeX-newline)
-    (if (marker-position done-mark)
-       (goto-char (marker-position done-mark)))
-    (set-marker done-mark nil)))
+    (if (marker-position LaTeX-done-mark)
+       (goto-char (marker-position LaTeX-done-mark)))
+    (set-marker LaTeX-done-mark nil)))
 
 (defun LaTeX-current-section ()
   "Return the level of the section that contain point.
@@ -371,34 +368,35 @@ If so, return the second element, otherwise return nil."
 (defcustom LaTeX-section-hook
   '(LaTeX-section-heading
     LaTeX-section-title
-;; LaTeX-section-toc           ; Most people won't want this
+    ;; LaTeX-section-toc               ; Most people won't want this
     LaTeX-section-section
     LaTeX-section-label)
   "List of hooks to run when a new section is inserted.
 
 The following variables are set before the hooks are run
 
-level - numeric section level, see the documentation of `LaTeX-section'.
-name - name of the sectioning command, derived from `level'.
-title - The title of the section, default to an empty string.
-toc - Entry for the table of contents list, default nil.
-done-mark - Position of point afterwards, default nil (meaning end).
+LaTeX-level - numeric section level, see the documentation of `LaTeX-section'.
+LaTeX-name - name of the sectioning command, derived from `LaTeX-level'.
+LaTeX-title - The title of the section, default to an empty string.
+LaTeX-toc - Entry for the table of contents list, default nil.
+LaTeX-done-mark - Position of point afterwards, default nil (meaning end).
 
 The following standard hook exist -
 
 LaTeX-section-heading: Query the user about the name of the
-sectioning command.  Modifies `level' and `name'.
+sectioning command.  Modifies `LaTeX-level' and `LaTeX-name'.
 
 LaTeX-section-title: Query the user about the title of the
-section.  Modifies `title'.
+section.  Modifies `LaTeX-title'.
 
 LaTeX-section-toc: Query the user for the toc entry.  Modifies
-`toc'.
+`LaTeX-toc'.
 
 LaTeX-section-section: Insert LaTeX section command according to
-`name', `title', and `toc'.  If `toc' is nil, no toc entry is
-inserted.  If `toc' or `title' are empty strings, `done-mark' will be
-placed at the point they should be inserted.
+`LaTeX-name', `LaTeX-title', and `LaTeX-toc'.  If `LaTeX-toc' is
+nil, no toc entry is inserted.  If `LaTeX-toc' or `LaTeX-title'
+are empty strings, `LaTeX-done-mark' will be placed at the point
+they should be inserted.
 
 LaTeX-section-label: Insert a label after the section command.
 Controled by the variable `LaTeX-section-label'.
@@ -458,20 +456,20 @@ no label is inserted."
 Insert this hook into `LaTeX-section-hook' to allow the user to change
 the name of the sectioning command inserted with `\\[LaTeX-section]'."
   (let ((string (completing-read
-                (concat "Level (default " name "): ")
+                (concat "Level (default " LaTeX-name "): ")
                 LaTeX-section-list
-                nil nil nil nil name)))
-    ;; Update name
+                nil nil nil nil LaTeX-name)))
+    ;; Update LaTeX-name
     (if (not (zerop (length string)))
-       (setq name string))
+       (setq LaTeX-name string))
     ;; Update level
-    (setq level (LaTeX-section-level name))))
+    (setq LaTeX-level (LaTeX-section-level LaTeX-name))))
 
 (defun LaTeX-section-title ()
   "Hook to prompt for LaTeX section title.
 Insert this hook into `LaTeX-section-hook' to allow the user to change
 the title of the section inserted with `\\[LaTeX-section]."
-  (setq title (TeX-read-string "Title: " title))
+  (setq LaTeX-title (TeX-read-string "Title: " LaTeX-title))
   (let ((region (and (TeX-active-mark)
                     (cons (region-beginning) (region-end)))))
     (when region (delete-region (car region) (cdr region)))))
@@ -480,15 +478,16 @@ the title of the section inserted with 
`\\[LaTeX-section]."
   "Hook to prompt for the LaTeX section entry in the table of content .
 Insert this hook into `LaTeX-section-hook' to allow the user to insert
 a different entry for the section in the table of content."
-  (setq toc (TeX-read-string "Toc Entry: "))
-  (if (zerop (length toc))
-      (setq toc nil)))
+  (setq LaTeX-toc (TeX-read-string "Toc Entry: "))
+  (if (zerop (length LaTeX-toc))
+      (setq LaTeX-toc nil)))
 
 (defun LaTeX-section-section ()
   "Hook to insert LaTeX section command into the file.
-Insert this hook into `LaTeX-section-hook' after those hooks that set
-the `name', `title', and `toc' variables, but before those hooks that
-assume that the section is already inserted."
+Insert this hook into `LaTeX-section-hook' after those hooks that
+set the `LaTeX-name', `LaTeX-title', and `LaTeX-toc' variables,
+but before those hooks that assume that the section is already
+inserted."
   ;; insert a new line if the current line and the previous line are
   ;; not empty (except for whitespace), with one exception: do not
   ;; insert a new line if the previous (or current, sigh) line starts
@@ -499,18 +498,18 @@ assume that the section is already inserted."
                     "begin")
             (line-beginning-position 0) t))
     (LaTeX-newline))
-  (insert TeX-esc name)
-  (cond ((null toc))
-       ((zerop (length toc))
+  (insert TeX-esc LaTeX-name)
+  (cond ((null LaTeX-toc))
+       ((zerop (length LaTeX-toc))
         (insert LaTeX-optop)
-        (set-marker done-mark (point))
+        (set-marker LaTeX-done-mark (point))
         (insert LaTeX-optcl))
        (t
-        (insert LaTeX-optop toc LaTeX-optcl)))
+        (insert LaTeX-optop LaTeX-toc LaTeX-optcl)))
   (insert TeX-grop)
-  (if (zerop (length title))
-      (set-marker done-mark (point)))
-  (insert title TeX-grcl)
+  (if (zerop (length LaTeX-title))
+      (set-marker LaTeX-done-mark (point)))
+  (insert LaTeX-title TeX-grcl)
   (LaTeX-newline)
   ;; If RefTeX is available, tell it that we've just made a new section
   (and (fboundp 'reftex-notice-new-section)
@@ -522,7 +521,7 @@ Insert this hook into `LaTeX-section-hook' to prompt for a 
label to be
 inserted after the sectioning command.
 
 The behaviour of this hook is controlled by variable `LaTeX-section-label'."
-  (and (LaTeX-label name 'section)
+  (and (LaTeX-label LaTeX-name 'section)
        (LaTeX-newline)))
 
 ;;; Environments
@@ -1317,9 +1316,9 @@ Just like array and tabular."
   (save-excursion
     (LaTeX-find-matching-begin)
     (end-of-line)
-    (let ((exit-mark (if (boundp 'exit-mark)
-                        exit-mark
-                      (make-marker))))
+    (let ((TeX-exit-mark (if (boundp 'TeX-exit-mark)
+                            TeX-exit-mark
+                          (make-marker))))
       (TeX-parse-arguments args))))
 
 (defun LaTeX-env-label-as-keyval (_optional &optional keyword keyvals 
environment)
@@ -2055,7 +2054,7 @@ string.  ARGS is unused."
   (TeX-argument-insert
    (TeX-read-string (TeX-argument-prompt optional prompt "Index tag")) 
optional))
 
-(defun TeX-arg-index (optional &optional prompt &rest args)
+(defun TeX-arg-index (optional &optional prompt &rest _args)
   "Prompt for an index entry completing with known entries.
 If OPTIONAL is non-nil, insert the resulting value as an optional
 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
@@ -2099,7 +2098,7 @@ the list of defined environments."
     (TeX-argument-insert environment optional)))
 
 ;; Why is DEFINITION unused?
-(defun TeX-arg-cite (optional &optional prompt definition)
+(defun TeX-arg-cite (optional &optional prompt _definition)
   "Prompt for a BibTeX citation with completion.
 If OPTIONAL is non-nil, insert the resulting value as an optional
 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
@@ -4479,10 +4478,10 @@ environments."
     ;; Only change point and mark after beginning and end were found.
     ;; Point should not end up in the middle of nowhere if the search fails.
     (save-excursion
-      (dotimes (c count) (LaTeX-find-matching-end))
+      (dotimes (_ count) (LaTeX-find-matching-end))
       (setq end (line-beginning-position 2))
       (goto-char cur)
-      (dotimes (c count) (LaTeX-find-matching-begin))
+      (dotimes (_ count) (LaTeX-find-matching-begin))
       (setq beg (point)))
     (push-mark end)
     (goto-char beg)
@@ -4615,7 +4614,7 @@ convenience function which can be used in style files."
   "Move forward to end of paragraph.
 If COUNT is non-nil, do it COUNT times."
   (or count (setq count 1))
-  (dotimes (i count)
+  (dotimes (_ count)
     (let* ((macro-start (TeX-find-macro-start))
           (paragraph-command-start
            (cond
@@ -4668,7 +4667,7 @@ If COUNT is non-nil, do it COUNT times."
   "Move backward to beginning of paragraph.
 If COUNT is non-nil, do it COUNT times."
   (or count (setq count 1))
-  (dotimes (i count)
+  (dotimes (_ count)
     (let* ((macro-start (TeX-find-macro-start)))
       (if (and macro-start
               ;; Point really has to be inside of the macro, not before it.
@@ -5557,10 +5556,10 @@ environments."
     (widen)
     (let ((opoint (point))
          beg end)
-      (dotimes (c count) (LaTeX-find-matching-end))
+      (dotimes (_ count) (LaTeX-find-matching-end))
       (setq end (point))
       (goto-char opoint)
-      (dotimes (c count) (LaTeX-find-matching-begin))
+      (dotimes (_ count) (LaTeX-find-matching-begin))
       (setq beg (point))
       (narrow-to-region beg end))))
 (put 'LaTeX-narrow-to-environment 'disabled t)
@@ -6794,7 +6793,7 @@ function would return non-nil and `(match-string 1)' 
would return
 (defun LaTeX-imenu-create-index-function ()
   "Imenu support function for LaTeX."
   (TeX-update-style)
-  (let (entries level
+  (let (entries
        (regexp (LaTeX-outline-regexp)))
     (goto-char (point-max))
     (while (re-search-backward regexp nil t)
@@ -6930,7 +6929,7 @@ functions `TeX-arg-color' (style/color.el) or
                   (equal current-prefix-arg '(4)))
              (and (eq TeX-insert-macro-default-style 'mandatory-args-only)
                   (null (equal current-prefix-arg '(4))))
-             last-optional-rejected))
+             TeX-last-optional-rejected))
      ,@body))
 
 (defun LaTeX-extract-key-value-label (&optional key num)
diff --git a/preview.el.in b/preview.el.in
index c14e490..f1cbb18 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -945,9 +945,9 @@ Pure borderless black-on-white will return an empty string."
           (funcall (car gsfile) "dvi" t))))
     (file-error nil))
   (when preview-ps-file
-      (condition-case nil
-         (preview-delete-file preview-ps-file)
-       (file-error nil)))
+    (condition-case nil
+       (preview-delete-file preview-ps-file)
+      (file-error nil)))
   (setq TeX-sentinel-function nil))
 
 (defalias 'preview-dvipng-abort 'preview-dvips-abort)
@@ -3671,8 +3671,7 @@ The fourth value is the transparent border thickness."
         (colors (preview-dvipng-color-string preview-colors res))
         (command (with-current-buffer TeX-command-buffer
                    (prog1
-                       (concat (TeX-command-expand preview-dvipng-command
-                                                   (car file))
+                       (concat (TeX-command-expand preview-dvipng-command)
                                " " colors resolution)
                      (setq tempdir TeX-active-tempdir))))
         (name "Preview-DviPNG"))
@@ -3710,8 +3709,7 @@ If FAST is set, do a fast conversion."
                    (prog1
                        (TeX-command-expand (if fast
                                                preview-fast-dvips-command
-                                             preview-dvips-command)
-                                           (car file))
+                                             preview-dvips-command))
                      (setq tempdir TeX-active-tempdir))))
         (name "Preview-DviPS"))
     (setq TeX-active-tempdir tempdir)
@@ -3751,8 +3749,7 @@ If FAST is set, do a fast conversion."
         pdfsource
         (command (with-current-buffer TeX-command-buffer
                    (prog1
-                       (TeX-command-expand preview-pdf2dsc-command
-                                           (car file))
+                       (TeX-command-expand preview-pdf2dsc-command)
                      (setq tempdir TeX-active-tempdir
                            pdfsource (funcall (car file) "pdf" t)))))
         (name "Preview-PDF2DSC"))
@@ -3930,8 +3927,7 @@ If FORMAT-CONS is non-nil, a previous format may get 
reused."
         (master-file (expand-file-name (TeX-master-file t)))
         (command (preview-do-replacements
                   (TeX-command-expand
-                   (preview-string-expand preview-LaTeX-command)
-                   'TeX-master-file)
+                   (preview-string-expand preview-LaTeX-command))
                   preview-dump-replacements))
         (preview-auto-cache-preamble nil))
     (unless (and (consp (cdr format-cons))
@@ -3952,10 +3948,8 @@ If FORMAT-CONS is non-nil, a previous format may get 
reused."
 \\def\\AUCTEXINPUT##1{\\catcode`/ 12\\relax\\catcode`\\ 
9\\relax\\input\\detokenize{##1}\\relax}%
 \\let\\dump\\PREVIEWdump\\dump}\\input mylatex.ltx \\relax%\n" nil dump-file)
       (TeX-save-document master)
-      (prog1
-         (preview-generate-preview
-          nil master
-          command)
+      (setq TeX-current-process-region-p nil)
+      (prog1 (preview-generate-preview master command)
        (add-hook 'kill-emacs-hook #'preview-cleanout-tempfiles t)
        (setq TeX-sentinel-function
              `(lambda (process string)
@@ -4003,11 +3997,11 @@ stored in `preview-dumped-alist'."
                            (save-excursion
                              (goto-char begin)
                              (if (bolp) 0 -1))))))
-  (preview-generate-preview t (TeX-region-file)
+  (setq TeX-current-process-region-p t)
+  (preview-generate-preview (TeX-region-file)
                            (preview-do-replacements
                             (TeX-command-expand
-                             (preview-string-expand preview-LaTeX-command)
-                             'TeX-region-file)
+                             (preview-string-expand preview-LaTeX-command))
                             preview-LaTeX-command-replacements)))
 
 (defun preview-buffer ()
@@ -4042,12 +4036,12 @@ stored in `preview-dumped-alist'."
   "Run preview on master document."
   (interactive)
   (TeX-save-document (TeX-master-file))
+  (setq TeX-current-process-region-p nil)
   (preview-generate-preview
-   nil (TeX-master-file)
+   (TeX-master-file)
    (preview-do-replacements
     (TeX-command-expand
-     (preview-string-expand preview-LaTeX-command)
-     'TeX-master-file)
+     (preview-string-expand preview-LaTeX-command))
     preview-LaTeX-command-replacements)))
 
 (defun preview-environment (count)
@@ -4080,19 +4074,16 @@ environments is selected."
     (preview-region (region-beginning) (region-end))))
 
 
-(defun preview-generate-preview (region-p file command)
+(defun preview-generate-preview (file command)
   "Generate a preview.
-REGION-P is the region flag, FILE the file (without default
-extension), COMMAND is the command to use.
+FILE the file (without default extension), COMMAND is the command
+to use.
 
 It returns the started process."
-  (setq TeX-current-process-region-p region-p)
   (let* ((geometry (preview-get-geometry))
         (commandbuff (current-buffer))
         (pr-file (cons
-                  (if TeX-current-process-region-p
-                      'TeX-region-file
-                    'TeX-master-file)
+                  'TeX-active-master
                   (file-name-nondirectory file)))
         (master (TeX-master-file))
         (master-file (expand-file-name master))
diff --git a/style/bicaption.el b/style/bicaption.el
index 8622cd5..f29ccce 100644
--- a/style/bicaption.el
+++ b/style/bicaption.el
@@ -117,13 +117,13 @@ arguments."
     (when cap-box
       (let* ((TeX-arg-opening-brace "[")
             (TeX-arg-closing-brace "]")
-            (last-optional-rejected nil)
+            (TeX-last-optional-rejected nil)
             (width (LaTeX-check-insert-macro-default-style
                     (completing-read (TeX-argument-prompt t nil "Width")
                                      (mapcar (lambda (elt) (concat TeX-esc 
(car elt)))
                                              (LaTeX-length-list)))))
-            (last-optional-rejected (or (not width)
-                                        (and width (string= width ""))))
+            (TeX-last-optional-rejected (or (not width)
+                                            (and width (string= width ""))))
             (inpos (LaTeX-check-insert-macro-default-style
                     (if (and width (not (string-equal width "")))
                         (completing-read (TeX-argument-prompt t nil "Inner 
position")
diff --git a/style/booktabs.el b/style/booktabs.el
index 5a58b28..f4e60db 100644
--- a/style/booktabs.el
+++ b/style/booktabs.el
@@ -57,7 +57,7 @@ PROMPT is the value of the prompt to be shown."
     '("toprule" [ "Thickness" ])
     '("midrule" [ "Thickness" ])
     '("bottomrule" [ "Thickness" ])
-    ;; The `ignore' resets `last-optional-rejected' to nil so that the trim
+    ;; The `ignore' resets `TeX-last-optional-rejected' to nil so that the trim
     ;; argument is prompted also when the thickness is skipped.
     '("cmidrule" [ "Thickness" ] (ignore) [ LaTeX-booktabs-arg-paren "Trim" ]
       "Column(s)")
diff --git a/style/caption.el b/style/caption.el
index fb9ddbe..a5d325b 100644
--- a/style/caption.el
+++ b/style/caption.el
@@ -269,13 +269,13 @@ caption, insert only a caption."
     (insert TeX-grcl))
   (let* ((TeX-arg-opening-brace "[")
         (TeX-arg-closing-brace "]")
-        (last-optional-rejected nil)
+        (TeX-last-optional-rejected nil)
         (width (LaTeX-check-insert-macro-default-style
                 (completing-read (TeX-argument-prompt t nil "Width")
                                  (mapcar (lambda (elt) (concat TeX-esc (car 
elt)))
                                          (LaTeX-length-list)))))
-        (last-optional-rejected (or (not width)
-                                    (and width (string= width ""))))
+        (TeX-last-optional-rejected (or (not width)
+                                        (and width (string= width ""))))
         (inpos (LaTeX-check-insert-macro-default-style
                 (if (and width (not (string-equal width "")))
                     (completing-read (TeX-argument-prompt t nil "Inner 
position")
diff --git a/style/color.el b/style/color.el
index f8f850a..bfc91b4 100644
--- a/style/color.el
+++ b/style/color.el
@@ -131,7 +131,7 @@
   ;; `TeX-insert-macro-default-style' and if `current-prefix-arg'.
   ;; `named' is removed here from completion if package option is not
   ;; given.
-  (let* ((last-optional-rejected nil)
+  (let* ((TeX-last-optional-rejected nil)
          (model (LaTeX-check-insert-macro-default-style
                  (completing-read
                   (TeX-argument-prompt t prompt "Color model")
@@ -181,7 +181,7 @@
   ;; First, ask for <model> depending on
   ;; `TeX-insert-macro-default-style' and `current-prefix-arg'.
   ;; Remove `named' if necessary.
-  (let* ((last-optional-rejected nil)
+  (let* ((TeX-last-optional-rejected nil)
         (model (LaTeX-check-insert-macro-default-style
                  (completing-read
                   (TeX-argument-prompt t prompt "Color model")
diff --git a/style/exam.el b/style/exam.el
index 76bff4b..1dd7b2b 100644
--- a/style/exam.el
+++ b/style/exam.el
@@ -1,4 +1,4 @@
-;;; exam.el --- AUCTeX style for the (LaTeX) exam class
+;;; exam.el --- AUCTeX style for the (LaTeX) exam class  -*- lexical-binding: 
t; -*-
 
 ;; Copyright (C) 2016--2020 Free Software Foundation, Inc.
 
@@ -49,22 +49,23 @@
   (add-to-list 'LaTeX-exam-class-options opt))
 
 (defun LaTeX-exam-insert-item ()
-  "Insert a new item in an environment from exam class.
+  "Insert a new item in the current environment from exam class.
 Item inserted depends on the environment."
-  (TeX-insert-macro
-   (cond ((string= environment "questions")
-          "question")
-         ((string= environment "parts")
-          "part")
-         ((string= environment "subparts")
-          "subpart")
-         ((string= environment "subsubparts")
-          "subsubpart")
-        ((member environment '("choices" "oneparchoices"
-                               "checkboxes" "oneparcheckboxes"))
-         "choice")
-         ;; Fallback
-         (t "item"))))
+  (let ((env (LaTeX-current-environment)))
+    (TeX-insert-macro
+     (cond ((string= env "questions")
+            "question")
+           ((string= env "parts")
+            "part")
+           ((string= env "subparts")
+            "subpart")
+           ((string= env "subsubparts")
+            "subsubpart")
+          ((member env '("choices" "oneparchoices"
+                         "checkboxes" "oneparcheckboxes"))
+           "choice")
+           ;; Fallback
+           (t "item")))))
 
 (defun LaTeX-exam-insert-label (_optional &optional name type)
   "Indent the line and query/insert a label incl. the \"\\label\" macro.
diff --git a/style/floatrow.el b/style/floatrow.el
index 57f58c7..2411d67 100644
--- a/style/floatrow.el
+++ b/style/floatrow.el
@@ -349,21 +349,21 @@ If OPTIONAL is non-nil, indicate optional argument during 
query."
   ;; `TeX-argument-insert':
   (let* ((TeX-arg-opening-brace "[")
         (TeX-arg-closing-brace "]")
-        (last-optional-rejected nil)
+        (TeX-last-optional-rejected nil)
         (width (LaTeX-check-insert-macro-default-style
                 (completing-read
                  (TeX-argument-prompt t nil "Width")
                  (mapcar (lambda (x) (concat TeX-esc (car x)))
                          (LaTeX-length-list)))))
-        (last-optional-rejected (or (not width)
-                                    (and width (string= width ""))))
+        (TeX-last-optional-rejected (or (not width)
+                                        (and width (string= width ""))))
         (height (LaTeX-check-insert-macro-default-style
                  (completing-read
                   (TeX-argument-prompt t nil "Height")
                   (mapcar (lambda (x) (concat TeX-esc (car x)))
                           (LaTeX-length-list)))))
-        (last-optional-rejected (or (not height)
-                                    (and height (string= height ""))))
+        (TeX-last-optional-rejected (or (not height)
+                                        (and height (string= height ""))))
         (vertpos (LaTeX-check-insert-macro-default-style
                   (if (string= height "")
                       ""
diff --git a/style/ifluatex.el b/style/ifluatex.el
index 246bc22..46d59cd 100644
--- a/style/ifluatex.el
+++ b/style/ifluatex.el
@@ -34,35 +34,35 @@
                  "font-latex"
                  (keywords class))
 
-(defun LaTeX-ifluatex-set-exit-mark (_optional)
-  "Discard OPTIONAL and set exit-mark to current point."
-  (set-marker exit-mark (point)))
+(defun LaTeX-ifluatex-set-TeX-exit-mark (_optional)
+  "Discard OPTIONAL and set `TeX-exit-mark' to current point."
+  (set-marker TeX-exit-mark (point)))
 
 (TeX-add-style-hook
+ "ifluatex"
+ (lambda ()
+   (TeX-add-symbols
+    '("ifluatex"
+      (TeX-arg-literal "%\n")
+      LaTeX-ifluatex-set-TeX-exit-mark
+      (TeX-arg-literal "\n\\else%\n\\fi%"))
+    '("luatexversion" 0)
+    '("luatexrevision" 0))
+   (TeX-declare-expert-macros
     "ifluatex"
-  (lambda ()
-    (TeX-add-symbols
-     '("ifluatex"
-       (TeX-arg-literal "%\n")
-       LaTeX-ifluatex-set-exit-mark
-       (TeX-arg-literal "\n\\else%\n\\fi%"))
-     '("luatexversion" 0)
-     '("luatexrevision" 0))
-    (TeX-declare-expert-macros
-     "ifluatex"
-     "ifluatex" "luatexversion" "luatexrevision")
-
-    ;; This package is used to make it possible to compile a document with both
-    ;; LuaTeX and base TeX engines.  By setting `TeX-check-engine-list' to nil
-    ;; we ignore engine restrictions posed by other packages.
-    (setq TeX-check-engine-list nil)
-
-    (when (and (featurep 'font-latex)
-              (eq TeX-install-font-lock 'font-latex-setup))
-      (font-latex-add-keywords '(("luatexversion")
-                                ("luatexrevision"))
-                              'function)))
-  LaTeX-dialect)
+    "ifluatex" "luatexversion" "luatexrevision")
+
+   ;; This package is used to make it possible to compile a document with both
+   ;; LuaTeX and base TeX engines.  By setting `TeX-check-engine-list' to nil
+   ;; we ignore engine restrictions posed by other packages.
+   (setq TeX-check-engine-list nil)
+
+   (when (and (featurep 'font-latex)
+             (eq TeX-install-font-lock 'font-latex-setup))
+     (font-latex-add-keywords '(("luatexversion")
+                               ("luatexrevision"))
+                             'function)))
+ LaTeX-dialect)
 
 (defvar LaTeX-ifluatex-package-options nil
   "Package options for the ifluatex package.")
diff --git a/style/xcolor.el b/style/xcolor.el
index 43c5637..3d77b35 100644
--- a/style/xcolor.el
+++ b/style/xcolor.el
@@ -284,7 +284,7 @@ xcolor package.")
 (defun TeX-arg-xcolor-definecolor (optional)
   "Insert arguments of \\definecolor and similar macros from xcolor.sty."
   ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
-  (let* ((last-optional-rejected nil)
+  (let* ((TeX-last-optional-rejected nil)
         (xcoltype  (LaTeX-check-insert-macro-default-style
                     (completing-read
                      (TeX-argument-prompt t nil "Type")
@@ -311,7 +311,7 @@ xcolor package.")
 
 (defun TeX-arg-xcolor-definecolorset (optional)
   "Insert arguments of \\definecolorset and similar macros from xcolor.sty."
-  (let* ((last-optional-rejected nil)
+  (let* ((TeX-last-optional-rejected nil)
         (xcoltype (LaTeX-check-insert-macro-default-style
                    (completing-read
                     (TeX-argument-prompt t nil "Type")
@@ -326,7 +326,7 @@ xcolor package.")
 (defun TeX-arg-xcolor (optional)
   "Insert arguments of various color commands from xcolor.sty."
   ;; \color{<name>} or \color[<model-list>]{<spec-list>}
-  (let* ((last-optional-rejected nil)
+  (let* ((TeX-last-optional-rejected nil)
         (xcolmodel (LaTeX-check-insert-macro-default-style
                     (completing-read
                      (TeX-argument-prompt t nil "Model (list)")
@@ -344,14 +344,14 @@ xcolor package.")
 (defun TeX-arg-xcolor-fcolorbox (optional)
   "Insert arguments of \\fcolorbox from xcolor.sty."
   ;;\fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background 
spec>}{<text>}
-  (let* ((last-optional-rejected nil)
+  (let* ((TeX-last-optional-rejected nil)
         (xfrmodel (LaTeX-check-insert-macro-default-style
                    (completing-read
                     (TeX-argument-prompt t nil "(Frame) Color model")
                     LaTeX-xcolor-color-models)))
-        ;; Set `last-optional-rejected' acc. to `xfrmodel'
-        (last-optional-rejected (or (not xfrmodel)
-                                    (and xfrmodel (string= xfrmodel ""))))
+        ;; Set `TeX-last-optional-rejected' acc. to `xfrmodel'
+        (TeX-last-optional-rejected (or (not xfrmodel)
+                                        (and xfrmodel (string= xfrmodel ""))))
         (xfrspec  (if (or (null xfrmodel)
                           (string= xfrmodel "")
                           (string= xfrmodel "named"))
diff --git a/tests/japanese/preview-latex.el b/tests/japanese/preview-latex.el
index 41907df..5ca3d96 100644
--- a/tests/japanese/preview-latex.el
+++ b/tests/japanese/preview-latex.el
@@ -228,8 +228,7 @@ String encoded in `shift_jis' can have regexp meta 
characters in it."
          (setq process (TeX-inline-preview-internal
                         (preview-do-replacements
                          (TeX-command-expand
-                          (preview-string-expand preview-LaTeX-command)
-                          'TeX-master-file)
+                          (preview-string-expand preview-LaTeX-command))
                          preview-LaTeX-command-replacements)
                         dummyfile '(nil . nil) (current-buffer)
                         '(nil . (t . t)) dummyfile '(nil nil nil)))
@@ -263,8 +262,7 @@ String encoded in `shift_jis' can have regexp meta 
characters in it."
          (setq process (TeX-inline-preview-internal
                         (preview-do-replacements
                          (TeX-command-expand
-                          (preview-string-expand preview-LaTeX-command)
-                          'TeX-master-file)
+                          (preview-string-expand preview-LaTeX-command))
                          preview-dump-replacements)
                         dummyfile '(nil . nil) (current-buffer)
                         nil dummyfile '(nil nil nil)))
diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index 0de5831..bb5c7d4 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -29,8 +29,7 @@
   (should (string=
            (let ((TeX-command-list
                  (list (cons "Test" '("%%%% %`%'" TeX-run-command t t)))))
-            (TeX-command-expand (nth 1 (assoc "Test" TeX-command-list))
-                                'TeX-master-file))
+            (TeX-command-expand (nth 1 (assoc "Test" TeX-command-list))))
            "%% ")))
 
 (ert-deftest TeX-command-expansion-errors ()
@@ -39,7 +38,7 @@
    ;; This error is actually thrown by `TeX-engine-in-engine-alist', but we 
want
    ;; to be sure that `TeX-command-expand' fails when the engine is not valid.
    (let ((TeX-engine 'non-existing-engine))
-     (TeX-command-expand "%l" 'TeX-master-file))))
+     (TeX-command-expand "%l"))))
 
 (ert-deftest TeX-view-command-raw-errors ()
   "Tests to trigger errors in `TeX-view-command-raw'."
@@ -94,7 +93,7 @@
                 (TeX-engine 'default)
                 (TeX-master "/tmp/abc")
                 (TeX-command-extra-options " \"\\foo\""))
-            (TeX-command-expand "%`%(extraopts)%' %T" #'TeX-master-file))
+            (TeX-command-expand "%`%(extraopts)%' %T"))
           " \"\\foo\" \"\\input\" \\\\detokenize\\{\\ abc.tex\\ \\}")))
 
 (ert-deftest TeX-command-expand-skip-file-name ()
@@ -108,24 +107,24 @@ See 
<https://lists.gnu.org/r/bug-auctex/2014-08/msg00012.html>."
   (let ((TeX-master "abc-def")
        (TeX-expand-list '(("-" (lambda () ":")))))
     (should (string=
-            (TeX-command-expand "%s" #'TeX-master-file)
+            (TeX-command-expand "%s")
             TeX-master))
     (should (string=
-            (TeX-command-expand "%t" #'TeX-master-file)
+            (TeX-command-expand "%t")
             (TeX-master-file "tex" t)))
     (should (string=
-            (TeX-command-expand "%T" #'TeX-master-file)
+            (TeX-command-expand "%T")
             (TeX-master-file "tex" t)))
     (should (string=
-            (TeX-command-expand "%d" #'TeX-master-file)
+            (TeX-command-expand "%d")
             (TeX-master-file "dvi" t)))
     (should (string=
-            (TeX-command-expand "%f" #'TeX-master-file)
+            (TeX-command-expand "%f")
             (TeX-master-file "ps" t)))
     ;; The expander of "%o" does not yet cater for this possible endless
     ;; loop.
     ;; (should (string=
-    ;;              (TeX-command-expand "%o" #'TeX-master-file)
+    ;;              (TeX-command-expand "%o")
     ;;              (TeX-master-file "pdf" t)))
     ))
 
@@ -138,11 +137,11 @@ See 
<https://lists.gnu.org/r/bug-auctex/2014-08/msg00012.html>."
        TeX-current-process-region-p)
     (setq TeX-current-process-region-p nil)
     (should (string=
-            (TeX-command-expand "%s" #'TeX-active-master)
+            (TeX-command-expand "%s")
             TeX-master))
     (setq TeX-current-process-region-p t)
     (should (string=
-            (TeX-command-expand "%s" #'TeX-active-master)
+            (TeX-command-expand "%s")
             TeX-region))))
 
 ;;; command-expansion.el ends here
diff --git a/tex-buf.el b/tex-buf.el
index 510722c..b9d9085 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -1,4 +1,4 @@
-;;; tex-buf.el --- External commands for AUCTeX.
+;;; tex-buf.el --- External commands for AUCTeX.  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 1991-1999, 2001-2020 Free Software Foundation, Inc.
 
@@ -463,10 +463,10 @@ Do you want to select one of these engines? "
   :group 'TeX-command
   :type 'integer)
 
-(defun TeX-command (name file &optional override-confirm)
-  "Run command NAME on the file returned by calling FILE.
+(defun TeX-command (name file-fn &optional override-confirm)
+  "Run command NAME on the file returned by calling FILE-FN.
 
-FILE is the symbol of a function returning a file name.  The
+FILE-FN is the symbol of a function returning a file name.  The
 function has one optional argument, the extension to use on the
 file.
 
@@ -485,17 +485,16 @@ been set."
   ;; because preview-latex calls `TeX-run-command' directly.
   (setq-default TeX-command-buffer (current-buffer))
 
-  (cond ((eq file #'TeX-region-file)
+  (cond ((eq file-fn #'TeX-region-file)
         (setq TeX-current-process-region-p t))
-       ((eq file #'TeX-master-file)
+       ((eq file-fn #'TeX-master-file)
         (setq TeX-current-process-region-p nil)))
 
   ;; When we're operating on a region, we need to update the position
   ;; of point in the region file so that forward search works.
   (if (string= name "View") (TeX-region-update-point))
 
-  (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list))
-                                    file))
+  (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list))))
        (hook (nth 2 (assoc name TeX-command-list)))
        (confirm (if override-confirm
                     (> (prefix-numeric-value override-confirm) 0)
@@ -531,94 +530,68 @@ remember to add /Library/TeX/texbin/ to your PATH"
                          ""))))
 
     ;; Now start the process
-    (setq file (funcall file))
-    (TeX-process-set-variable file 'TeX-command-next TeX-command-Show)
-    (funcall hook name command file)))
+    (let ((file (funcall file-fn)))
+      (TeX-process-set-variable file 'TeX-command-next TeX-command-Show)
+      (funcall hook name command file))))
 
-(defvar TeX-command-text)               ;Dynamically scoped.
-(defvar TeX-command-pos)                ;Dynamically scoped.
-
-(defun TeX-command-expand (command file &optional list)
-  "Expand COMMAND for FILE as described in LIST.
+(defun TeX-command-expand (command &optional list)
+  "Expand COMMAND for `TeX-active-master' as described in LIST.
 LIST default to `TeX-expand-list'.  As a special exception,
 `%%' can be used to produce a single `%' sign in the output
 without further expansion."
-  (defvar TeX-command-pos)
-  (let (pat
-       pos ;;FIXME: Should this be dynamically scoped?
-       entry TeX-command-text TeX-command-pos
-        expansion-res case-fold-search string expansion arguments)
+  (let ((TeX-expand-command command)
+        TeX-expand-pos
+        TeX-command-text
+        TeX-command-pos
+       pat entry case-fold-search string expansion arguments)
     (setq list (cons
                (list "%%" (lambda nil
-                            (setq pos (1+ pos))
+                            (setq TeX-expand-pos (1+ TeX-expand-pos))
                             "%"))
                (or list (TeX-expand-list)))
          pat (regexp-opt (mapcar #'car list)))
-    ;; `TeX-command-expand' is called with `file' argument being one
-    ;; of `TeX-master-file', `TeX-region-file' and
-    ;; `TeX-active-master'.  The return value of these functions
-    ;; sometimes needs suitable "decorations" for an argument for
-    ;; underlying shell or latex executable, or both, when the
-    ;; relavant file name involves some special characters such as
-    ;; space and multibyte characters.  Hence embed that function in a
-    ;; template prepared for that purpose.
-    (setq file (apply-partially
-               #'TeX--master-or-region-file-with-extra-quotes
-               file))
-    (while (setq pos (string-match pat command pos))
-      (setq string (match-string 0 command)
-           entry (assoc string list)
-           expansion (car (cdr entry)) ;Second element
-           arguments (cdr (cdr entry)) ;Remaining elements
-           string (save-match-data
-                    ;; Note regarding the special casing of `file':
-                    ;; `file' is prevented from being evaluated as a
-                    ;; function because inside of AUCTeX it only has
-                    ;; a meaning as a variable.  This makes sure that
-                    ;; a function definition made by an external
-                    ;; package (e.g. icicles) is not picked up.
-                    (cond ((and (not (eq expansion 'file))
-                                (functionp expansion))
-                           (apply expansion arguments))
-                          ((boundp expansion)
-                            (setq expansion-res
-                                  (apply (symbol-value expansion) arguments))
-                            (when (eq expansion 'file)
-                              ;; Advance past the file name in order to
-                              ;; prevent expanding any substring of it.
-                              (setq pos (+ pos (length expansion-res))))
-                           expansion-res)
-                          (t
-                           (error "Nonexpansion %s" expansion)))))
-      (if (stringp string)
-         (setq command
-               (replace-match string t t command)))))
-  command)
+    (let ((file-fn #'TeX--master-or-region-file-with-extra-quotes))
+      (while (setq TeX-expand-pos (string-match pat TeX-expand-command 
TeX-expand-pos))
+        (setq string (match-string 0 TeX-expand-command)
+             entry (assoc string list)
+             expansion (car (cdr entry)) ;Second element
+             arguments (cdr (cdr entry)) ;Remaining elements
+             string (save-match-data
+                      (cond
+                        ((memq expansion (list 'TeX-active-master
+                                               #'TeX-active-master))
+                         (let ((res (apply file-fn arguments)))
+                           ;; Advance past the file name in order to
+                           ;; prevent expanding any substring of it.
+                           (setq TeX-expand-pos
+                                 (+ TeX-expand-pos (length res)))
+                           res))
+                        ((functionp expansion)
+                         (apply expansion arguments))
+                       ((boundp expansion)
+                         (apply (symbol-value expansion) arguments))
+                       (t
+                        (error "Nonexpansion %s" expansion)))))
+        (if (stringp string)
+           (setq TeX-expand-command
+                 (replace-match string t t TeX-expand-command))))
+      TeX-expand-command)))
 
 (defun TeX--master-or-region-file-with-extra-quotes
-    (file-fn &optional extension nondirectory ask extra)
-  "Return file name with quote for shell.
-Helper function of `TeX-command-expand'.
-
-This is a kind of template.  How to use:
-Fix, by `apply-partially', the first argument FILE-FN as one of
-the three functions `TeX-master-file', `TeX-region-file' or
-`TeX-active-master'.  Then the result is just a wrapper for that
-function suitable in `TeX-command-expand'.
-
-As a wrapper described above, it passes EXTENSION, NONDIRECTORY
-and ASK to the \"bare\" function as-is, and arranges the returned
-file name for use with command shell.  I.e. it encloses the file
-name with space within quotes `\"' first when \" \\input\" is
-supplemented (indicated by dynamically binded variable
-`TeX-command-text' having string value.)  It also encloses the
-file name within \\detokenize{} when the following three
-conditions are met:
-1. compiling with standard (pdf)LaTeX or upLaTeX
-2. \" \\input\" is supplemented
-3. EXTRA is non-nil (default when expanding \"%T\")"
+    (&optional extension nondirectory ask extra)
+  "Return the current master or region file name with quote for shell.
+I.e. it encloses the file name with space within quotes `\"'
+first when \" \\input\" is supplemented (indicated by dynamically
+binded variable `TeX-command-text' having string value.)  It also
+encloses the file name within \\detokenize{} when the following
+three conditions are met:
+  1. compiling with standard (pdf)LaTeX or upLaTeX
+  2. \" \\input\" is supplemented
+  3. EXTRA is non-nil (default when expanding \"%T\")
+
+Helper function of `TeX-command-expand'."
   (shell-quote-argument
-   (let* ((raw (funcall file-fn extension nondirectory ask))
+   (let* ((raw (funcall #'TeX-active-master extension nondirectory ask))
          ;; String `TeX-command-text' means that the file name is
          ;; given through \input command.
          (quote-for-space (if (and (stringp TeX-command-text)
@@ -2475,6 +2448,7 @@ If REPARSE is non-nil, reparse the output log.
 If the file occurs in an included file, the file is loaded (if not
 already in an Emacs buffer) and the cursor is placed at the error."
   (let ((old-buffer (current-buffer))
+        ;; FIXME: default-major-mode has been removed in Emacs 26.
        (default-major-mode major-mode)
        max-index item)
 
@@ -3546,6 +3520,7 @@ please restart TeX error overview")))
          (with-current-buffer TeX-command-buffer
            ;; For consistency with `TeX-parse-TeX', use the major mode of
            ;; `TeX-command-buffer' when visiting the error point.
+            ;; FIXME: default-major-mode has been removed in Emacs 26.
            (let ((default-major-mode major-mode))
              ;; Find the error and display the help.
              (apply #'TeX-find-display-help item)))
diff --git a/tex.el b/tex.el
index b2bbbbf..ce31831 100644
--- a/tex.el
+++ b/tex.el
@@ -1,4 +1,4 @@
-;;; tex.el --- Support for TeX documents.
+;;; tex.el --- Support for TeX documents.  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 1985-2020 Free Software Foundation, Inc.
 
@@ -511,6 +511,15 @@ string."
   :type 'string)
 (make-variable-buffer-local 'TeX-command-extra-options)
 
+(defvar TeX-command-text nil
+  "Dynamically bound by `TeX-command-expand'.")
+(defvar TeX-command-pos nil
+  "Dynamically bound by `TeX-command-expand'.")
+(defvar TeX-expand-pos nil
+  "Dynamically bound by `TeX-command-expand'.")
+(defvar TeX-expand-command nil
+  "Dynamically bound by `TeX-command-expand'.")
+
 ;; This is the list of expansion for the commands in
 ;; TeX-command-list.  Not likely to be changed, but you may e.g. want
 ;; to handle .ps files.
@@ -581,9 +590,10 @@ string."
                    (or (if TeX-source-correlate-output-page-function
                            (funcall TeX-source-correlate-output-page-function))
                        "1")))
-    ;; `file' means to call `TeX-master-file', `TeX-region-file' or 
`TeX-active-master'
-    ("%s" file nil t)
-    ("%t" file t t)
+    ;; `TeX-active-master' calls either calls`TeX-master-file' or
+    ;; `TeX-region-file' returning the master or region file.
+    ("%s" TeX-active-master nil t)
+    ("%t" TeX-active-master t t)
     ;; If any TeX codes appear in the interval between %` and %', move
     ;; all of them after the interval and supplement " \input".  The
     ;; appearance is marked by leaving the bind to `TeX-command-text'
@@ -599,42 +609,42 @@ string."
            ""))
     (" \"\\" (lambda nil
               (if (eq TeX-command-pos t)
-                  (setq TeX-command-pos pos
-                        pos (+ 3 pos))
-                (setq pos (1+ pos)))))
+                  (setq TeX-command-pos TeX-expand-pos
+                        TeX-expand-pos (+ 3 TeX-expand-pos))
+                (setq TeX-expand-pos (1+ TeX-expand-pos)))))
     ("\"" (lambda nil (if (numberp TeX-command-pos)
                          (setq TeX-command-text
                                (concat
                                 TeX-command-text
-                                (substring command
+                                (substring TeX-expand-command
                                            TeX-command-pos
-                                           (1+ pos)))
-                               command
+                                           (1+ TeX-expand-pos)))
+                               TeX-expand-command
                                (concat
-                                (substring command
+                                (substring TeX-expand-command
                                            0
                                            TeX-command-pos)
-                                (substring command
-                                           (1+ pos)))
-                               pos TeX-command-pos
+                                (substring TeX-expand-command
+                                           (1+ TeX-expand-pos)))
+                               TeX-expand-pos TeX-command-pos
                                TeX-command-pos t)
-                       (setq pos (1+ pos)))))
+                       (setq TeX-expand-pos (1+ TeX-expand-pos)))))
     ("%'" (lambda nil
            (setq TeX-command-pos nil)
            (if (stringp TeX-command-text)
                (progn
-                 (setq pos (+ pos (length TeX-command-text) 9))
+                 (setq TeX-expand-pos (+ TeX-expand-pos (length 
TeX-command-text) 9))
                  (concat TeX-command-text " \"\\input\""))
              "")))
     ;; The fourth argument of t is actually for wrapper function
     ;; provided by `TeX--master-or-region-file-with-extra-quotes'.
     ;; See its doc string as well as the comments in
     ;; `TeX-command-expand'.
-    ("%T" file t t nil t)
+    ("%T" TeX-active-master t t nil t)
     ("%n" TeX-current-line)
-    ("%d" file "dvi" t)
-    ("%f" file "ps" t)
-    ("%o" (lambda nil (funcall file (TeX-output-extension) t)))
+    ("%d" TeX-active-master "dvi" t)
+    ("%f" TeX-active-master "ps" t)
+    ("%o" (lambda nil (TeX-active-master (TeX-output-extension) t)))
     ;; for source specials the file name generated for the xdvi
     ;; command needs to be relative to the master file, just in
     ;; case the file is in a different subdirectory
@@ -1237,7 +1247,7 @@ entry in `TeX-view-program-list-builtin'."
                                 (get-file-buffer (TeX-region-file t)))
                               (current-buffer))
        (pdf-sync-forward-search))
-    (let ((pdf (concat file "." (TeX-output-extension))))
+    (let ((pdf (TeX-active-master (TeX-output-extension))))
       (pop-to-buffer (or (find-buffer-visiting pdf)
                         (find-file-noselect pdf))))))
 
@@ -1259,9 +1269,10 @@ for the Evince-compatible entries in
 DE is the name of the desktop environment, APP is the name of
 viewer."
   (require 'url-util)
-  (let* ((uri (concat "file://" (url-encode-url
-                                (expand-file-name
-                                 (concat file "." (TeX-output-extension))))))
+  (let* ((uri (concat "file://"
+                      (url-encode-url
+                      (expand-file-name
+                       (TeX-active-master (TeX-output-extension))))))
         (owner (dbus-call-method
                 :session (format "org.%s.%s.Daemon" de app)
                 (format "/org/%s/%s/Daemon" de app)
@@ -1556,11 +1567,11 @@ predicates are true, nil otherwise."
     (unless (or (null executable)
                (cond
                 ((stringp executable)
-                 (executable-find (TeX-command-expand executable nil)))
+                 (executable-find (TeX-command-expand executable)))
                 ((listp executable)
                  (catch 'notfound
                    (dolist (exec executable t)
-                     (unless (executable-find (TeX-command-expand exec nil))
+                     (unless (executable-find (TeX-command-expand exec))
                        (throw 'notfound nil)))))))
       (error (format "Cannot find %S viewer.  \
 Select another one in `TeX-view-program-selection'" viewer)))
@@ -3122,7 +3133,6 @@ Possible values are nil, t, or a list of style names.
 
 (defmacro TeX-complete-make-expert-command-functions (thing list-var prefix)
   (let* ((plural (concat thing "s"))
-        (upcase (upcase thing))
         (upcase-plural (upcase plural)))
     `(progn
        (defvar ,(intern (format "%s-expert-%s-table" prefix thing))
@@ -3363,6 +3373,9 @@ Space will complete and exit."
         (let ((minibuffer-local-completion-map TeX-electric-macro-map))
           (call-interactively 'TeX-insert-macro)))))
 
+(defvar TeX-exit-mark nil
+  "Dynamically bound by `TeX-parse-macro' and `LaTeX-env-args'.")
+
 (defun TeX-parse-macro (symbol args)
   "How to parse TeX macros which takes one or more arguments.
 
@@ -3386,9 +3399,10 @@ TeX macro.  What is done depend on the type of the 
element:
   after the previous argument, or after the macro name if this is
   the first argument.  Please leave point located after the
   argument you are inserting.  If you want point to be located
-  somewhere else after all hooks have been processed, set the value
-  of `exit-mark'.  It will point nowhere, until the argument hook
-  set it.  By convention, these hooks all start with `TeX-arg-'.
+  somewhere else after all hooks have been processed, set the
+  value of `TeX-exit-mark'.  It will point nowhere, until the
+  argument hook set it.  By convention, these hooks all start
+  with `TeX-arg-'.
 
   list: If the car is a string, insert it as a prompt and the next
   element as initial input.  Otherwise, call the car of the list
@@ -3412,12 +3426,12 @@ TeX macro.  What is done depend on the type of the 
element:
             (> (point) (mark)))
        (exchange-point-and-mark))
     (insert TeX-esc symbol)
-    (let ((exit-mark (make-marker))
+    (let ((TeX-exit-mark (make-marker))
          (position (point)))
       (TeX-parse-arguments args)
-      (cond ((marker-position exit-mark)
-            (goto-char (marker-position exit-mark))
-            (set-marker exit-mark nil))
+      (cond ((marker-position TeX-exit-mark)
+            (goto-char (marker-position TeX-exit-mark))
+            (set-marker TeX-exit-mark nil))
            ((let ((element (assoc symbol TeX-insert-braces-alist)))
               ;; If in `TeX-insert-braces-alist' there is an element associated
               ;; to the current macro, use its value to decide whether 
inserting
@@ -3457,11 +3471,14 @@ INITIAL-INPUT is a string to insert before reading 
input."
      (TeX-read-string (TeX-argument-prompt optional prompt "Text") 
initial-input))
    optional))
 
+(defvar TeX-last-optional-rejected nil
+  "Dynamically bound by `TeX-parse-arguments'.")
+
 (defun TeX-parse-arguments (args)
   "Parse TeX macro arguments ARGS.
 
 See `TeX-parse-macro' for details."
-  (let ((last-optional-rejected nil))
+  (let ((TeX-last-optional-rejected nil))
     (while args
       (if (vectorp (car args))
          ;; Maybe get rid of all optional arguments.  See `TeX-insert-macro'
@@ -3476,7 +3493,7 @@ See `TeX-parse-macro' for details."
                          (equal current-prefix-arg '(4)))
                     (and (eq TeX-insert-macro-default-style 
'mandatory-args-only)
                          (null (equal current-prefix-arg '(4))))
-                    last-optional-rejected))
+                    TeX-last-optional-rejected))
            (let ((TeX-arg-opening-brace LaTeX-optop)
                  (TeX-arg-closing-brace LaTeX-optcl))
              (TeX-parse-argument t (if (equal (length (car args)) 1)
@@ -3484,7 +3501,7 @@ See `TeX-parse-macro' for details."
                                      (append (car args) nil)))))
        (let ((TeX-arg-opening-brace TeX-grop)
              (TeX-arg-closing-brace TeX-grcl))
-         (setq last-optional-rejected nil)
+         (setq TeX-last-optional-rejected nil)
          (TeX-parse-argument nil (car args))))
       (setq args (cdr args)))))
 
@@ -3529,7 +3546,7 @@ See `TeX-parse-macro' for details."
           (if (and (not optional) (TeX-active-mark))
               (progn
                 (exchange-point-and-mark))
-            (set-marker exit-mark (point)))
+            (set-marker TeX-exit-mark (point)))
           (insert TeX-arg-closing-brace)
           (setq insert-flag t))
          ((symbolp arg)
@@ -3553,13 +3570,13 @@ See `TeX-parse-macro' for details."
 If OPTIONAL, only insert it if not empty, and then use square brackets.
 If PREFIX is given, insert it before NAME."
   (if (and optional (string-equal name ""))
-      (setq last-optional-rejected t)
+      (setq TeX-last-optional-rejected t)
     (insert TeX-arg-opening-brace)
     (if prefix
        (insert prefix))
     (if (and (string-equal name "")
-            (null (marker-position exit-mark)))
-       (set-marker exit-mark (point))
+            (null (marker-position TeX-exit-mark)))
+       (set-marker TeX-exit-mark (point))
       (insert name))
     (insert TeX-arg-closing-brace)))
 
@@ -3949,7 +3966,7 @@ Generated by `TeX-auto-add-type'.")
 
 (defun TeX-safe-auto-write ()
   "Call `TeX-auto-write' safely."
-  (condition-case name
+  (condition-case _ignored
       (and (boundp 'TeX-auto-update)
           TeX-auto-update
           (TeX-auto-write))
@@ -3981,7 +3998,7 @@ Generated by `TeX-auto-add-type'.")
             (dir (file-name-directory file)))
        ;; Create auto directory if possible.
        (if (not (file-exists-p dir))
-           (condition-case name
+           (condition-case _ignored
                (make-directory dir)
              (error nil)))
        (if (file-writable-p file)
@@ -4301,7 +4318,7 @@ you should not use something like `[\\(]' for a character 
range."
        (goto-char (if end (min end (point-max)) (point-max)))
        (while (re-search-backward regexp beg t)
          (let* ((entry (cdr (TeX-member nil groups
-                                        (lambda (a b)
+                                        (lambda (_a b)
                                           (match-beginning (car b))))))
                 (symbol (nth 2 entry))
                 (match (nth 1 entry)))
@@ -5073,10 +5090,9 @@ Brace insertion is only done if point is in a math 
construct and
        :help "Make \"Next Error\" show warnings"])
      ["Compile and view" TeX-command-run-all
       :help "Compile the document until it is ready and open the viewer"])
-   (let ((file 'TeX-command-on-current)) ;; is this actually needed?
-     (delq nil
-          (mapcar #'TeX-command-menu-entry
-                  (TeX-mode-specific-command-list mode))))))
+   (delq nil
+        (mapcar #'TeX-command-menu-entry
+                (TeX-mode-specific-command-list mode)))))
 
 (defun TeX-mode-specific-command-list (mode)
   "Return the list of commands available in the given MODE."
@@ -5181,7 +5197,7 @@ Brace insertion is only done if point is in a math 
construct and
 (make-variable-buffer-local 'TeX-verbatim-p-function)
 
 ;; XXX: We only have an implementation for LaTeX mode at the moment (Oct 2009).
-(defun TeX-verbatim-p (&optional pos)
+(defun TeX-verbatim-p (&optional _pos)
   "Return non-nil if position POS is in a verbatim-like construct.
 A mode-specific implementation is required.  If it is not
 available, the function always returns nil."
@@ -5289,7 +5305,7 @@ not move point further than this value."
   ;; A value of 0 is nonsense.
   (when (= count 0) (setq count 1))
   (unless limit (setq limit (point-max)))
-  (dotimes (i (abs count))
+  (dotimes (_ (abs count))
     (if (< count 0)
        (forward-line -1)
       (beginning-of-line))
@@ -6225,7 +6241,7 @@ available from ")
         "https://www.gnu.org/software/auctex/";
         'face 'link
         'help-echo (concat "mouse-2, RET: Follow this link")
-        'action (lambda (button)
+        'action (lambda (_button)
                   (browse-url "https://www.gnu.org/software/auctex/";))
         'follow-link t)
        (insert " if your
@@ -6241,7 +6257,7 @@ tracker.  Visit ")
         "https://debbugs.gnu.org/cgi/pkgreport.cgi?pkg=auctex";
         'face 'link
         'help-echo (concat "mouse-2, RET: Follow this link")
-        'action (lambda (button)
+        'action (lambda (_button)
                   (browse-url 
"https://debbugs.gnu.org/cgi/pkgreport.cgi?pkg=auctex";))
         'follow-link t)
        (insert "\nto browse existing AUCTeX bugs.
@@ -6410,7 +6426,7 @@ NAME may be a package, a command, or a document."
       (when (and (called-interactively-p 'any)
                 (or (not name) (string= name "")))
        (let ((symbol (thing-at-point 'symbol))
-             contained completions doc)
+             contained completions)
          ;; Is the symbol at point contained in the lists of available
          ;; documentation?
          (setq contained (catch 'found
@@ -6451,7 +6467,7 @@ NAME may be a package, a command, or a document."
 ;; The FSF ispell.el might one day use this.
 (setq ispell-enable-tex-parser t)
 
-(defun TeX-run-ispell (command string file)
+(defun TeX-run-ispell (_command _string file)
   "Run ispell on current TeX buffer."
   (cond ((and (string-equal file (TeX-region-file))
              (fboundp 'ispell-region))
@@ -6471,8 +6487,7 @@ NAME may be a package, a command, or a document."
   (if (string-equal name "")
       (setq name (TeX-master-file)))
 
-  (let ((found nil)
-       (regexp (concat "\\`\\("
+  (let ((regexp (concat "\\`\\("
                        (mapconcat (lambda (dir)
                                     (regexp-quote
                                      (expand-file-name
@@ -6493,10 +6508,9 @@ NAME may be a package, a command, or a document."
       (let* ((buffer (car buffers))
             (name (buffer-file-name buffer)))
        (setq buffers (cdr buffers))
-       (if (and name (string-match regexp name))
-           (progn
-             (save-excursion (switch-to-buffer buffer) (ispell-buffer))
-             (setq found t)))))))
+       (when (and name (string-match regexp name))
+         (save-excursion (switch-to-buffer buffer) (ispell-buffer))
+          t)))))
 
 ;; Some versions of ispell 3 use this.
 (defvar ispell-tex-major-modes nil)



reply via email to

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