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

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

[elpa] externals/auctex b45bf4d 07/27: Ignore 3 consective $'s properly


From: Tassilo Horn
Subject: [elpa] externals/auctex b45bf4d 07/27: Ignore 3 consective $'s properly
Date: Sat, 27 Jun 2020 03:17:42 -0400 (EDT)

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

    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.
---
 font-latex.el                  | 57 +++++++++++++++++++++++-------------------
 tests/latex/font-latex-test.el | 43 +++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 26 deletions(-)

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



reply via email to

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