[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex a27850f 10/30: Fix previous commit and add new t
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex a27850f 10/30: Fix previous commit and add new test |
Date: |
Fri, 25 Sep 2020 11:00:12 -0400 (EDT) |
branch: externals/auctex
commit a27850faedf2a9c0871a558353a8f8f42597794c
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Fix previous commit and add new test
* font-latex.el (font-latex-extend-region-backwards-quotation): Move
the point back to the correct position when the inner loop search
fails.
* tests/latex/font-latex-test.el
(font-latex-extend-region-backwards-quotation): New test.
---
font-latex.el | 67 ++++++++++++++++++++++++------------------
tests/latex/font-latex-test.el | 40 +++++++++++++++++++++++++
2 files changed, 78 insertions(+), 29 deletions(-)
diff --git a/font-latex.el b/font-latex.el
index 09a6feb..6ce901f 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -2050,12 +2050,13 @@ set to french, and >>german<< (and 8-bit) are used if
set to german."
"Extend region backwards for quotations."
(when font-latex-quotes
(font-latex-update-quote-list)
- (let ((regexp-end (regexp-opt (mapcar 'cadr font-latex-quote-list) t)))
+ (let ((regexp-end (regexp-opt (mapcar #'cadr font-latex-quote-list) t)))
(save-excursion
(goto-char font-lock-end)
(catch 'extend
(while (re-search-backward regexp-end font-lock-beg t)
- (let ((closing-quote (match-string 0))
+ (let ((found-end (match-beginning 0))
+ (closing-quote (match-string-no-properties 0))
(nest-count 0)
(point-of-surrender (- font-lock-beg
font-latex-multiline-boundary))
@@ -2066,33 +2067,41 @@ set to french, and >>german<< (and 8-bit) are used if
set to german."
(setq opening-quote (car elt))
(throw 'found nil))))
;; Find opening quote taking nested quotes into account.
- (while (and (re-search-backward (concat opening-quote "\\|"
- closing-quote)
- point-of-surrender t)
- ;; Found quotes before point-of-surrender.
- (cond ((string= (match-string 0) closing-quote)
- ;; Encountered another closing quote.
- ;; Increase nest-count and continue
- ;; the inner loop.
- (setq nest-count (1+ nest-count)))
- ;; Found an opening quote.
- ((/= nest-count 0)
- ;; If in nest, decrease nest-count
- ;; and continue the inner loop.
- (setq nest-count (1- nest-count)))
- ;; Else we arrived at the opening quote
- ;; matching with the closing quote found
- ;; in the outer loop.
- ((< (point) font-lock-beg)
- ;; If that opening quote locates
- ;; before `font-lock-beg', break the
- ;; outer loop and extend the region.
- (setq font-lock-beg (point))
- (throw 'extend t))
- (t
- ;; Else terminate the inner loop and
- ;; continue the outer loop.
- nil)))))))))))
+ (while (if (re-search-backward (concat opening-quote "\\|"
+ closing-quote)
+ point-of-surrender 'move)
+ ;; Found quotes before point-of-surrender.
+ (cond ((string= (match-string-no-properties 0)
+ closing-quote)
+ ;; Encountered another closing quote.
+ ;; Increase nest-count and continue
+ ;; the inner loop.
+ (setq nest-count (1+ nest-count)))
+ ;; Found an opening quote.
+ ((/= nest-count 0)
+ ;; If in nest, decrease nest-count
+ ;; and continue the inner loop.
+ (setq nest-count (1- nest-count)))
+ ;; Else we arrived at the opening quote
+ ;; matching with the closing quote found
+ ;; in the outer loop.
+ ((< (point) font-lock-beg)
+ ;; If that opening quote locates
+ ;; before `font-lock-beg', break the
+ ;; outer loop and extend the region.
+ (setq font-lock-beg (point))
+ (throw 'extend t))
+ (t
+ ;; Else terminate the inner loop and
+ ;; continue the outer loop.
+ nil))
+ ;; Didn't find quotes before
+ ;; point-of-surrender.
+ ;; Go back just before the closing quote,
+ ;; terminate the inner loop and
+ ;; continue the outer loop.
+ (goto-char found-end)
+ nil)))))))))
(defun font-latex-match-script (limit)
"Match subscript and superscript patterns up to LIMIT."
diff --git a/tests/latex/font-latex-test.el b/tests/latex/font-latex-test.el
index c45a7b5..a869fe4 100644
--- a/tests/latex/font-latex-test.el
+++ b/tests/latex/font-latex-test.el
@@ -41,4 +41,44 @@ $a$")
(setq font-latex--updated-region-end (point-max))
(font-latex-match-dollar-math (point-max))))))
+(ert-deftest font-latex-extend-region-backwards-quotation ()
+ "Test f-l-e-r-b-q doesn't extend region too eagerly."
+ (with-temp-buffer
+ (let ((TeX-install-font-lock 'font-latex-setup)
+ (font-latex-quotes 'french)
+ font-lock-beg font-lock-end)
+ (LaTeX-mode)
+
+ ;; Test 1: Double prime in math expression doesn't cause region
+ ;; extension.
+ (setq font-lock-beg (point))
+ (insert "$f''(x)=x^{3}$")
+ (setq font-lock-end (point))
+ (should-not (font-latex-extend-region-backwards-quotation))
+
+ (erase-buffer)
+ (insert "abc ``def ghi'' jkl ")
+ (setq font-lock-beg (point))
+ (insert "$f''(x)=x^{3}$")
+ (setq font-lock-end (point))
+ (should-not (font-latex-extend-region-backwards-quotation))
+
+ ;; Test 2: open-close pair before '' in math expression is
+ ;; picked up.
+ (erase-buffer)
+ (insert "abc ``def ")
+ (setq font-lock-beg (point))
+ (insert "ghi'' jkl $f''(x)=x^{3}$")
+ (setq font-lock-end (point))
+ (should (font-latex-extend-region-backwards-quotation))
+ (should (= font-lock-beg 5))
+
+ (erase-buffer)
+ (insert "abc <<def ")
+ (setq font-lock-beg (point))
+ (insert "ghi>> jkl $f''(x)=x^{3}$")
+ (setq font-lock-end (point))
+ (should (font-latex-extend-region-backwards-quotation))
+ (should (= font-lock-beg 5)))))
+
;;; font-latex-test.el ends here
- [elpa] externals/auctex 971bece 14/30: Update style/csquotes.el to package version 5.2j, (continued)
- [elpa] externals/auctex 971bece 14/30: Update style/csquotes.el to package version 5.2j, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex a17fee2 16/30: ; Silence the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 59b7942 17/30: ; Silence the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 07b79fc 24/30: ; Silence the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 087b030 28/30: Simplify mode line for emacs 27, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex b06ca0a 25/30: Fix document, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 0692e51 23/30: ; Silence the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 601e6a3 01/30: Get rid of gabage in generated texi file, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 4d58d7d 09/30: Don't extend font lock region too eagerly (bug#42267), Tassilo Horn, 2020/09/25
- [elpa] externals/auctex d7cba92 21/30: Prepare for pdf output for PSTricks documents, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex a27850f 10/30: Fix previous commit and add new test,
Tassilo Horn <=
- [elpa] externals/auctex 67ecb0b 18/30: ; Silence the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 255e768 11/30: Cater for case where fontification match goes over limit, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 92aa02b 29/30: Merge remote-tracking branch 'origin/master' into externals/auctex, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex be4a912 26/30: ; Silence the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 3ef28a5 20/30: Add an extra check for tex-buf.el in some style hooks, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex f04a508 22/30: Restore all math environments in texmathp.el, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex 1bc7a21 30/30: ; Regenerate docs, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex ef1f670 27/30: ; Partially revert silencing the compiler, Tassilo Horn, 2020/09/25
- [elpa] externals/auctex b21889e 19/30: Merge prv-emacs.el into preview.el.in, Tassilo Horn, 2020/09/25