>From 2025fa25f76fd8a2df46fca8807ca386372757d5 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Mon, 20 May 2019 16:04:24 -0400 Subject: [PATCH 1/2] Handle lone quote 500+ characters away from XML tag (Bug#33887) Because syntax-propertize works in small buffer chunks, the rule for finding quotes which don't contain angle brackets failed to trigger when the angle bracket was outside of the current chunk. * lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-rules): Match quotes on lines with no other angle bracket or quote too (the syntax-propertize chunk is extended to cover whole lines). * test/lisp/nxml/nxml-mode-tests.el (nxml-mode-quote-in-long-text): New test. --- lisp/textmodes/sgml-mode.el | 9 +++++++-- test/lisp/nxml/nxml-mode-tests.el | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 137745fbc1..b555db7b76 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -353,8 +353,13 @@ sgml-font-lock-keywords ;; the resulting number of calls to syntax-ppss made it too slow ;; (bug#33887), so we're now careful to leave alone any pair ;; of quotes that doesn't hold a < or > char, which is the vast majority. - ("\\([\"']\\)[^<>\"']*[<>\"']" - (1 (unless (eq (char-after (match-beginning 1)) (char-before)) + ;; We also check quotes which are unpaired to end of line, + ;; otherwise we miss the case where the quote might "contain" an + ;; angle bracket outside of the current syntax-propertize chunk + ;; (this relies on `syntax-propertize-wholelines' being enabled). + ("\\([\"']\\)[^<>\"']*\\([<>\"']\\|$\\)" + (1 (unless (eq (char-after (match-beginning 1)) + (char-after (match-beginning 2))) ;; Be careful to call `syntax-ppss' on a position before the one ;; we're going to change, so as not to need to flush the data we ;; just computed. diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el index 2bbf92bc96..0916a1e652 100644 --- a/test/lisp/nxml/nxml-mode-tests.el +++ b/test/lisp/nxml/nxml-mode-tests.el @@ -86,5 +86,27 @@ nxml-mode-tests-correctly-indented-string (should (= 1 (car (syntax-ppss (1- (point-max)))))) (should (= 0 (car (syntax-ppss (point-max))))))) +(ert-deftest nxml-mode-quote-in-long-text () + (with-temp-buffer + (nxml-mode) + (insert "" + ;; `syntax-propertize-wholelines' extends chunk size based + ;; on line length, so newlines are significant! + (make-string syntax-propertize-chunk-size ?a) "\n" + "'" + (make-string syntax-propertize-chunk-size ?a) "\n" + "") + ;; If we just check (syntax-ppss (point-max)) immediately, then + ;; we'll end up propertizing the whole buffer in one chunk (so the + ;; test is useless). Simulate something more like what happens + ;; when the buffer is viewed normally. + (cl-loop for pos from (point-min) to (point-max) + by syntax-propertize-chunk-size + do (syntax-ppss pos)) + (syntax-ppss (point-max)) + ;; Check that last tag is parsed as a tag. + (should (= 1 (- (car (syntax-ppss (1- (point-max)))) + (car (syntax-ppss (point-max)))))))) + (provide 'nxml-mode-tests) ;;; nxml-mode-tests.el ends here -- 2.11.0