auctex-diffs
[Top][All Lists]
Advanced

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

[AUCTeX-diffs] [elpa] externals/auctex 9170170 11/27: Delete overhead in


From: Tassilo Horn
Subject: [AUCTeX-diffs] [elpa] externals/auctex 9170170 11/27: Delete overhead in extending font lock range of math expression
Date: Sat, 27 Jun 2020 03:17:43 -0400 (EDT)

branch: externals/auctex
commit 9170170438ec47e70f5b1c87ffc71a8e2d96b068
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>

    Delete overhead in extending font lock range of math expression
    
    * font-latex.el (font-latex-math-environments-from-texmathp): New
    helper function.
    (font-latex-math-environments): Take default value using the above
    function.
    (font-latex-extend-region-backwards-math): Rename from
    `font-latex-extend-region-backwards-dollar-math' and include the
    functionality of `font-latex-extend-region-backwards-math-env' and
    `font-latex-extend-region-backwards-math-envII'.
    (font-latex-extend-region-backwards-math-env):
    (font-latex-extend-region-backwards-math-envII):
    Remove.
    (font-latex-setup): Simplify according to the above change.
    * texmathp.el (texmathp-tex-commands-default): Move entries not in
    standard LaTeX to the respective style files.
    * style/amsmath.el ():
    * style/breqn.el ():
    * style/empheq.el ():
    * style/mathtools.el ():
    Add package specific entries to `texmathp-tex-commands-default' and
    take additions for `font-latex-math-environments' from it rather than
    adding constant entries.
---
 font-latex.el                  | 90 ++++++++++++++----------------------------
 style/amsmath.el               | 24 ++++++++++-
 style/breqn.el                 | 32 +++++++++------
 style/empheq.el                | 41 ++++++++++---------
 style/mathtools.el             |  7 +++-
 tests/latex/font-latex-test.el |  1 +
 texmathp.el                    | 34 +---------------
 7 files changed, 103 insertions(+), 126 deletions(-)

diff --git a/font-latex.el b/font-latex.el
index 14d64c6..216897f 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -1264,9 +1264,7 @@ triggers Font Lock to recognize the change."
             font-latex-extend-region-backwards-command-with-args
            font-latex-extend-region-backwards-command-in-braces
            font-latex-extend-region-backwards-quotation
-           font-latex-extend-region-backwards-math-env
-           font-latex-extend-region-backwards-math-envII
-           font-latex-extend-region-backwards-dollar-math)
+           font-latex-extend-region-backwards-math)
            (syntax-propertize-function
             . font-latex-syntax-propertize-function)
            (syntax-propertize-extend-region-functions
@@ -1748,26 +1746,22 @@ Used for patterns like:
            (store-match-data (list beg (point) (point) (point))))
          (throw 'match t))))))
 
-(defun font-latex-extend-region-backwards-math-env ()
-  "Extend region backwards for math environments."
-  (save-excursion
-    (goto-char font-lock-end)
-    (catch 'extend
-      (while (re-search-backward "\\(\\\\)\\)\\|\\(\\\\]\\)" font-lock-beg t)
-       (when (and (zerop (mod (skip-chars-backward "\\\\") 2))
-                  (re-search-backward
-                   (concat "[^\\]\\(?:\\\\\\\\\\)*\\("
-                           (regexp-quote (if (match-beginning 1) "\\(" "\\["))
-                           "\\)")
-                   (- font-lock-beg font-latex-multiline-boundary) t)
-                  (goto-char (match-beginning 1))
-                  (< (point) font-lock-beg))
-          (setq font-lock-beg (point))
-         (throw 'extend t))))))
+(require 'texmathp)
+(defun font-latex-math-environments-from-texmathp (list)
+  "Return list of math environments extracted from LIST.
+Utility to share data with texmathp.el.
+LIST should have the same structure as `texmathp-tex-commands'.
+Return list of environment names marked as `env-on' type in LIST,
+except starred forms."
+  (let (result)
+    (dolist (entry list)
+      (if (and (eq 'env-on (cadr entry))
+              (not (string= "*" (substring (car entry) -1))))
+         (push (car entry) result)))
+    result))
 
 (defcustom font-latex-math-environments
-  '("display" "displaymath" "equation" "eqnarray" "gather" "math" "multline"
-    "align" "alignat" "xalignat" "xxalignat" "flalign")
+  (font-latex-math-environments-from-texmathp texmathp-tex-commands1)
   "List of math environment names for font locking."
   :type '(repeat string)
   :group 'font-latex)
@@ -1812,29 +1806,6 @@ The \\begin{equation} incl. arguments in the same line 
and
       (store-match-data (list beg end))
       t)))
 
-(defun font-latex-extend-region-backwards-math-envII ()
-  "Extend region backwards for math environments."
-  (save-excursion
-    (goto-char font-lock-end)
-    (catch 'extend
-      (while (re-search-backward
-             (concat "\\\\end[ \t]*{"
-                     (regexp-opt font-latex-math-environments t)
-                     "\\*?}") font-lock-beg t)
-       (when (and (re-search-backward
-                   (concat  "\\\\begin[ \t]*{"
-                            (buffer-substring-no-properties
-                             (match-beginning 1)
-                             (match-end 0))
-                            ;; Match an optional and possible
-                            ;; mandatory argument(s)
-                            "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"
-                            "\\(?:{[^}]*}\\)*")
-                   (- font-lock-beg font-latex-multiline-boundary) t)
-                  (< (point) font-lock-beg))
-          (setq font-lock-beg (point))
-         (throw 'extend t))))))
-
 (defun font-latex-match-dollar-math (limit)
   "Match inline math $...$ or display math $$...$$ before LIMIT."
   (catch 'match
@@ -1903,7 +1874,7 @@ signs to follow the point and must be 1 or 2."
        ;; > \includegraphics{$HOME/path/to/graphic}
        ;; > \bibliography{$HOME/path/to/bib}
        ;;
-       ;; In order to spare work around of adding "%$" at the end of
+       ;; In order to spare workaround of adding "%$" at the end of
        ;; the lines for such cases, we stay away from the next syntax
        ;; state check.
        ;; ;; check 3: Else, is "$" in comments or verb-like construct?
@@ -1913,29 +1884,26 @@ signs to follow the point and must be 1 or 2."
        ;; That "$" is live one.
        (throw 'found t))))))
 
-(require 'texmathp)
-;; FIXME: Big overhead here. We can obviously unify
-;; `font-latex-extend-region-backwards-math-env' and
-;; `font-latex-extend-region-backwards-math-envII' into
-;; this function.
-(defun font-latex-extend-region-backwards-dollar-math ()
-  "Extend region backwards for math inside $...$ or $$...$$."
-  ;; Use `texmathp' to identify whether the point is inside $...$ or
-  ;; $$...$$. Only heuristic, but it's very difficult to identify
-  ;; rigorously without syntactic support.
-
-  ;; Check if `font-lock-beg' is inside "$...$" or "$$...$$".
+(defun font-latex-extend-region-backwards-math ()
+  "Extend region backwards for math environmets.
+Take into account $...$, $$...$$, \\(...\\) and \\=\\[...\\], too."
+  ;; Use `texmathp' to identify whether the point is inside math mode.
+  ;; Only heuristic, but it's very difficult to identify rigorously
+  ;; without syntactic support.
+
+  ;; Check if `font-lock-beg' is inside math mode.
   (goto-char font-lock-beg)
 
-  ;; Work around bug#41522. Ensure `syntax-table' property is given to
-  ;; all verbatim like constructs up to the position before running
+  ;; Workaround bug#41522. Ensure `syntax-table' property is given to
+  ;; all verbatim-like constructs up to the position before running
   ;; `texmathp' in order to prevent wrong fontification of verbatim
   ;; face. This is necessary because `texmathp' calls `up-list' inside
   ;; narrowing.
   (syntax-propertize (point))
 
-  (when (and (texmathp) (< (cdr texmathp-why) font-lock-beg)
-            (member (car texmathp-why) '("$" "$$")))
+  ;; XXX: Should we make the `texmathp' search honor
+  ;; `font-latex-multiline-boundary'?
+  (when (and (texmathp) (< (cdr texmathp-why) font-lock-beg))
     ;; Make its beginning a new start of font lock region.
     (setq font-lock-beg (cdr texmathp-why))
     t))
diff --git a/style/amsmath.el b/style/amsmath.el
index 7114b51..ebf651e 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -1,6 +1,6 @@
 ;;; amsmath.el --- Style hook for the AMS-LaTeX amsmath package.
 
-;; Copyright (C) 2002, 2005-2007, 2012-2014, 2017-2019
+;; Copyright (C) 2002, 2005-2007, 2012-2014, 2017-2020
 ;;      Free Software Foundation, Inc.
 ;; FIXME: What about the copyright for <= 2001?
 
@@ -30,6 +30,28 @@
 
 ;;; Code:
 
+(defvar font-latex-math-environments)
+(declare-function font-latex-math-environments-from-texmathp
+                 "font-latex" (list))
+(require 'texmathp)
+(let ((list '(("equation*"     env-on)
+             ("align"         env-on) ("align*"        env-on)
+             ("gather"        env-on) ("gather*"       env-on)
+             ("multline"      env-on) ("multline*"     env-on)
+             ("flalign"       env-on) ("flalign*"      env-on)
+             ("alignat"       env-on) ("alignat*"      env-on)
+             ("xalignat"      env-on) ("xalignat*"     env-on)
+             ("xxalignat"     env-on) ("\\boxed"       arg-on)
+             ("\\text"        arg-off) ("\\intertext"   arg-off))))
+  (dolist (entry list)
+    (add-to-list 'texmathp-tex-commands-default entry t))
+  (texmathp-compile)
+  (when (and (featurep 'font-latex)
+            (eq TeX-install-font-lock 'font-latex-setup))
+    (dolist (entry (font-latex-math-environments-from-texmathp list))
+      ;; Append our addition so that we don't interfere with user 
customizations
+      (add-to-list 'font-latex-math-environments entry t))))
+
 (TeX-add-style-hook
  "amsmath"
  (lambda ()
diff --git a/style/breqn.el b/style/breqn.el
index 3a89860..91d69d0 100644
--- a/style/breqn.el
+++ b/style/breqn.el
@@ -95,6 +95,24 @@ Keys offered for key=val query depend on ENV.  \"label\" and
 
 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
 
+(defvar font-latex-math-environments)
+(declare-function font-latex-math-environments-from-texmathp
+                 "font-latex" (list))
+(require 'texmathp)
+(let ((list '(("dmath"         env-on) ("dmath*"        env-on)
+             ("dseries"       env-on) ("dseries*"      env-on)
+             ("dgroup"        env-on) ("dgroup*"       env-on)
+             ("darray"        env-on) ("darray*"       env-on)
+             ("dsuspend"      env-off))))
+  (dolist (entry list)
+    (add-to-list 'texmathp-tex-commands-default entry t))
+  (texmathp-compile)
+  (when (and (featurep 'font-latex)
+            (eq TeX-install-font-lock 'font-latex-setup))
+    ;; Append our addition so that we don't interfere with user customizations
+    (dolist (entry (font-latex-math-environments-from-texmathp list))
+      (add-to-list 'font-latex-math-environments entry t))))
+
 (TeX-add-style-hook
  "breqn"
  (lambda ()
@@ -132,19 +150,7 @@ Keys offered for key=val query depend on ENV.  \"label\" 
and
    (TeX-add-symbols
     '("condition"  [ "Punctuation mark (default ,)" ] t)
     '("condition*" [ "Punctuation mark (default ,)" ] t)
-    '("hiderel" t))
-
-   ;; Fontification
-   (when (and (featurep 'font-latex)
-             (eq TeX-install-font-lock 'font-latex-setup)
-             (boundp 'font-latex-math-environments))
-     (make-local-variable 'font-latex-math-environments)
-     (let ((envs '(;; Do not insert the starred versions here;
-                  ;; function `font-latex-match-math-envII' takes
-                  ;; care of it
-                  "dmath" "dseries" "dgroup" "darray")))
-       (dolist (env envs)
-        (add-to-list 'font-latex-math-environments env t)))))
+    '("hiderel" t)))
  LaTeX-dialect)
 
 (defvar LaTeX-breqn-package-options nil
diff --git a/style/empheq.el b/style/empheq.el
index e01d04c..aacd6e7 100644
--- a/style/empheq.el
+++ b/style/empheq.el
@@ -1,6 +1,6 @@
 ;;; empheq.el --- AUCTeX style for `empheq.sty' (v2.14)
 
-;; Copyright (C) 2016-2018 Free Software Foundation, Inc.
+;; Copyright (C) 2016-2020 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <arash@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -41,6 +41,8 @@
 (declare-function font-latex-add-keywords
                  "font-latex"
                  (keywords class))
+(declare-function font-latex-math-environments-from-texmathp
+                 "font-latex" (list))
 
 (declare-function LaTeX-item-equation-alignat
                  "amsmath" (&optional suppress))
@@ -275,6 +277,25 @@ number of ampersands if possible."
       (save-excursion
        (insert (make-string (+ ncols ncols -1) ?&))))))
 
+(require 'texmathp)
+(let ((list '(("empheq"        env-on)
+             ;; XXX: Should we add the remaining entries only when
+             ;; "overload" or "overload2" option is given?
+             ("AmSequation"   env-on) ("AmSequation*"  env-on)
+             ("AmSalign"      env-on) ("AmSalign*"     env-on)
+             ("AmSgather"     env-on) ("AmSgather*"    env-on)
+             ("AmSmultline"   env-on) ("AmSmultline*"  env-on)
+             ("AmSflalign"    env-on) ("AmSflalign*"   env-on)
+             ("AmSalignat"    env-on) ("AmSalignat*"   env-on))))
+  (dolist (entry list)
+    (add-to-list 'texmathp-tex-commands-default entry t))
+  (texmathp-compile)
+  (when (and (featurep 'font-latex)
+            (eq TeX-install-font-lock 'font-latex-setup))
+    ;; Append our addition so that we don't interfere with user customizations
+    (dolist (entry (font-latex-math-environments-from-texmathp list))
+      (add-to-list 'font-latex-math-environments entry t))))
+
 (TeX-add-style-hook
  "empheq"
  (lambda ()
@@ -489,23 +510,7 @@ number of ampersands if possible."
      (font-latex-add-keywords '(("empheqset"             "{")
                                ("DeclareLeftDelimiter"  "[{")
                                ("DeclareRightDelimiter" "[{"))
-                             'function)
-     ;; Append our addition so that we don't interfere with user customizations
-     (make-local-variable 'font-latex-math-environments)
-     (add-to-list 'font-latex-math-environments "empheq" t)
-     (when (or (LaTeX-provided-package-options-member "empheq" "overload")
-              (LaTeX-provided-package-options-member "empheq" "overload2"))
-       (let ((envs '(;; Do not insert the starred versions here;
-                    ;; function `font-latex-match-math-envII' takes
-                    ;; care of it
-                    "AmSalign"
-                    "AmSalignat"
-                    "AmSequation"
-                    "AmSflalign"
-                    "AmSgather"
-                    "AmSmultline")))
-        (dolist (env envs)
-          (add-to-list 'font-latex-math-environments env t))))))
+                             'function)))
  LaTeX-dialect)
 
 ;;; empheq.el ends here
diff --git a/style/mathtools.el b/style/mathtools.el
index 83bef3e..03a0f9b 100644
--- a/style/mathtools.el
+++ b/style/mathtools.el
@@ -1,6 +1,6 @@
 ;;; mathtools.el --- Style hook for the LaTeX package `mathtools'.
 
-;; Copyright (C) 2011-2012, 2014, 2016, 2018 Free Software Foundation, Inc.
+;; Copyright (C) 2011-2020 Free Software Foundation, Inc.
 
 ;; Author: Mads Jensen <mje@inducks.org>
 ;; Created: 2011-02-13
@@ -235,6 +235,11 @@ Put line break macro on the last line.  Next, insert an 
ampersand."
   (save-excursion
     (insert ?&)))
 
+(require 'texmathp)
+(add-to-list 'texmathp-tex-commands-default
+            '("\\shortintertext" arg-off) t)
+(texmathp-compile)
+
 (TeX-add-style-hook
  "mathtools"
  (lambda ()
diff --git a/tests/latex/font-latex-test.el b/tests/latex/font-latex-test.el
index 2c204e9..c45a7b5 100644
--- a/tests/latex/font-latex-test.el
+++ b/tests/latex/font-latex-test.el
@@ -38,6 +38,7 @@
 $a$")
              (LaTeX-mode)
              (goto-char (point-min))
+             (setq font-latex--updated-region-end (point-max))
              (font-latex-match-dollar-math (point-max))))))
 
 ;;; font-latex-test.el ends here
diff --git a/texmathp.el b/texmathp.el
index 3beac2e..57475f7 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -1,6 +1,6 @@
 ;;; texmathp.el -- Code to check if point is inside LaTeX math environment
 
-;; Copyright (C) 1998, 2004, 2017 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2004, 2017, 2020 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
 ;; Maintainer: auctex-devel@gnu.org
@@ -130,37 +130,7 @@
     ("\\textrm"      arg-off)
     ("\\("           sw-on)       ("\\)"           sw-off)
     ("\\["           sw-on)       ("\\]"           sw-off)
-    ("\\ensuremath"  arg-on)
-
-    ;; AMS-LaTeX
-    ("equation*"     env-on)
-    ("align"         env-on)      ("align*"        env-on)
-    ("gather"        env-on)      ("gather*"       env-on)
-    ("multline"      env-on)      ("multline*"     env-on)
-    ("flalign"       env-on)      ("flalign*"      env-on)
-    ("alignat"       env-on)      ("alignat*"      env-on)
-    ("xalignat"      env-on)      ("xalignat*"     env-on)
-    ("xxalignat"     env-on)      ("\\boxed"       arg-on)
-    ("\\text"        arg-off)     ("\\intertext"   arg-off)
-
-    ;; mathtools
-    ("\\shortintertext"   arg-off)
-
-    ;; empheq
-    ("empheq"        env-on)
-    ("AmSequation"   env-on)      ("AmSequation*"  env-on)
-    ("AmSalign"      env-on)      ("AmSalign*"     env-on)
-    ("AmSgather"     env-on)      ("AmSgather*"    env-on)
-    ("AmSmultline"   env-on)      ("AmSmultline*"  env-on)
-    ("AmSflalign"    env-on)      ("AmSflalign*"   env-on)
-    ("AmSalignat"    env-on)      ("AmSalignat*"   env-on)
-
-    ;; breqn
-    ("dmath"         env-on)      ("dmath*"        env-on)
-    ("dseries"       env-on)      ("dseries*"      env-on)
-    ("dgroup"        env-on)      ("dgroup*"       env-on)
-    ("darray"        env-on)      ("darray*"       env-on)
-    ("dsuspend"      env-off))
+    ("\\ensuremath"  arg-on))
   "The default entries for `texmathp-tex-commands', which see.")
 
 (defun texmathp-compile ()



reply via email to

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