auctex-diffs
[Top][All Lists]
Advanced

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

[AUCTeX-diffs] GNU AUCTeX branch, master, updated. b45bf4d19d599247eccc3


From: Ikumi Keita
Subject: [AUCTeX-diffs] GNU AUCTeX branch, master, updated. b45bf4d19d599247eccc369444dfab721c5d52aa
Date: Sat, 13 Jun 2020 07:08:54 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
       via  b45bf4d19d599247eccc369444dfab721c5d52aa (commit)
      from  b97a04957f19a7f84a794800b240ef70cf343a5d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b45bf4d19d599247eccc369444dfab721c5d52aa
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Date:   Sat Jun 13 20:04:38 2020 +0900

    Ignore 3 consective $'s properly
    
    * font-latex.el (font-latex-match-dollar-math): Ignore 3 or more
    consecutive $'s when searching opening of $...$ or $$...$$, instead of
    stopping to return nil.
    * tests/latex/font-latex-test.el: New test.

diff --git a/font-latex.el b/font-latex.el
index a707616..d2f0064 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -1808,33 +1808,38 @@ The \\begin{equation} incl. arguments in the same line 
and
 
 (defun font-latex-match-dollar-math (limit)
   "Match inline math $...$ or display math $$...$$ before LIMIT."
-  (if (font-latex-find-dollar-math limit)
-      ;; Found "$" which starts $...$ or $$...$$.
-      (let ((beg (point))
-           ;; Go inside the math expression.
-           (num (skip-chars-forward "$" limit)))
-       (if (< num 3)
-           (if ;; Let's find the same number of live dollar signs.
-               (font-latex-find-dollar-math limit num)
-               ;; Found.
-               (progn
-                 (forward-char num)
-                 (set-match-data (list beg (point)))
-                 t)
-             ;; Not found. It means that there was opening "$" or
-             ;; "$$", but we can't find the corresponding close tag
-             ;; until LIMIT. Then it is either
-             ;; (1) The math expression continues to the next line, or
-             ;; (2) The buffer has unclosed "$" or "$$".
-             ;; Regard the former case as a positive match because
-             ;; experiments tends to imply that's more robust despite
-             ;; of frequent false positives produced during editing.
-             ;; N.B. It is ensured that LIMIT doesn't fall just
-             ;; inside single "$$" because
-             ;; `font-lock-extend-region-functions' takes care of it.
-             (unless (eobp)
+  (catch 'match
+    (let (beg num)
+      (while (font-latex-find-dollar-math limit)
+       ;; Found "$" which starts $...$ or $$...$$.
+       (setq beg (point)
+             ;; Go inside the math expression.
+             num (skip-chars-forward "$" limit))
+       ;; If those are three or more consecutive $, ignore them and
+       ;; search again.
+       (when (< num 3)
+         (if ;; Let's find the same number of live dollar signs.
+             (font-latex-find-dollar-math limit num)
+             ;; Found.
+             (progn
+               (forward-char num)
                (set-match-data (list beg (point)))
-               t))))))
+               (throw 'match t))
+           ;; Not found. It means that there was opening "$" or
+           ;; "$$", but we can't find the corresponding close tag
+           ;; until LIMIT. Then it is either
+           ;; (1) The math expression continues to the next line, or
+           ;; (2) The buffer has unclosed "$" or "$$".
+           ;; Regard the former case as a positive match because
+           ;; experiments tends to imply that's more robust despite
+           ;; of frequent false positives produced during editing.
+           ;; N.B. It is ensured that LIMIT doesn't fall just
+           ;; inside single "$$" because
+           ;; `font-lock-extend-region-functions' takes care of it.
+           (if (eobp)
+               (throw 'match nil)
+             (set-match-data (list beg (point)))
+             (throw 'match t))))))))
 
 (defun font-latex-find-dollar-math (limit &optional num)
   "Find dollar sign(s) before LIMIT.
diff --git a/tests/latex/font-latex-test.el b/tests/latex/font-latex-test.el
new file mode 100644
index 0000000..2c204e9
--- /dev/null
+++ b/tests/latex/font-latex-test.el
@@ -0,0 +1,43 @@
+;;; font-latex-test.el --- tests for font-latex
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Code:
+
+(require 'ert)
+(require 'latex)
+(require 'font-latex)
+
+(ert-deftest font-latex-three-dollars ()
+  "Test three consecutive dollar is ignored."
+  ;; When the function `font-latex-match-dollar-math' encounters three
+  ;; or more consecutive dollar signs which have no special meaning,
+  ;; it should not stop there and return nil, but instead should
+  ;; ignore them and search another occurence of $. That is the
+  ;; behavior expected for MATCHER function of `font-lock-keywords'.
+  (should (let ((TeX-install-font-lock 'font-latex-setup))
+           (with-temp-buffer
+             (insert "% $$$ $$$
+$a$")
+             (LaTeX-mode)
+             (goto-char (point-min))
+             (font-latex-match-dollar-math (point-max))))))
+
+;;; font-latex-test.el ends here

-----------------------------------------------------------------------

Summary of changes:
 font-latex.el                                      | 57 ++++++++++++----------
 .../latex/{texmathp-test.el => font-latex-test.el} | 46 ++++++++---------
 2 files changed, 50 insertions(+), 53 deletions(-)
 copy tests/latex/{texmathp-test.el => font-latex-test.el} (52%)


hooks/post-receive
-- 
GNU AUCTeX



reply via email to

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