From: Noam Postavsky <npostavs@gmail.com>
To: Vincent Lefevre <vincent@vinc17.net>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, 33887@debbugs.gnu.org
Subject: bug#33887: 26.1; Emacs hangs for several seconds when going to the end of an XML file in nXML mode
Date: Sat, 18 May 2019 00:15:39 -0400 [thread overview]
Message-ID: <875zq8e6tw.fsf@gmail.com> (raw)
In-Reply-To: <20190517213602.GA11777@zira.vinc17.org> (Vincent Lefevre's message of "Fri, 17 May 2019 23:36:02 +0200")
[-- Attachment #1: Type: text/plain, Size: 634 bytes --]
Vincent Lefevre <vincent@vinc17.net> writes:
> I've tried the combination of
>
> ca14dd1d4628094dd33d5d94694dcf5f29e843b8
> 7dab3ee7ab54b3c2e7bc24170376054786c01d6f
>
> and this patch against Debian's current source package.
>
> Emacs no longer hangs, but I get incorrect highlighting,
> for instance on the following XML file.
>
> <root>
> <!-- comment -->
> <a>"a'</a>
> <!-- comment -->
> </root>
>
> Highlighting starts to be wrong at the single-quote character.
> I've attached a screenshot obtained with the -Q option.
>
> Did I miss anything?
Ah, I didn't get the mixed quote handling right. Here's the fix for master:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2449 bytes --]
From 4677edd8dd65b5d956732821e78794f35b275418 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 18 May 2019 00:04:01 -0400
Subject: [PATCH] Fix Bug#33887 for mixed quote usage
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-rules): Only
skip syntax-ppss for matched quotes.
* test/lisp/textmodes/sgml-mode-tests.el (sgml-tests--quotes-syntax):
Expand test.
---
lisp/textmodes/sgml-mode.el | 4 ++--
test/lisp/textmodes/sgml-mode-tests.el | 17 ++++++++++++-----
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 1b064fb825..e3cf56aa0e 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -345,8 +345,8 @@ 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:\"\\)[^\"<>]*[<>\"]\\|\\(?1:'\\)[^'<>]*[<>']\\)"
- (1 (unless (memq (char-before) '(?\' ?\"))
+ ("\\([\"']\\)[^<>\"']*[<>\"']"
+ (1 (unless (eq (char-after (match-beginning 1)) (char-before))
;; 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/textmodes/sgml-mode-tests.el b/test/lisp/textmodes/sgml-mode-tests.el
index a900e8dcf2..ffcc2cd840 100644
--- a/test/lisp/textmodes/sgml-mode-tests.el
+++ b/test/lisp/textmodes/sgml-mode-tests.el
@@ -161,11 +161,18 @@ sgml-with-content
(should (string= "&&" (buffer-string))))))
(ert-deftest sgml-tests--quotes-syntax ()
- (with-temp-buffer
- (sgml-mode)
- (insert "a\"b <tag>c'd</tag>")
- (should (= 1 (car (syntax-ppss (1- (point-max))))))
- (should (= 0 (car (syntax-ppss (point-max)))))))
+ (dolist (str '("a\"b <t>c'd</t>"
+ "a'b <t>c\"d</t>"
+ "<t>\"a'</t>"
+ "<t>'a\"</t>"
+ "<t>\"a'\"</t>"
+ "<t>'a\"'</t>"))
+ (with-temp-buffer
+ (sgml-mode)
+ (insert str)
+ ;; Check that last tag is parsed as a tag.
+ (should (= 1 (car (syntax-ppss (1- (point-max))))))
+ (should (= 0 (car (syntax-ppss (point-max))))))))
(provide 'sgml-mode-tests)
;;; sgml-mode-tests.el ends here
--
2.11.0
[-- Attachment #3: Type: text/plain, Size: 47 bytes --]
And the correponding patch against emacs-26:
[-- Attachment #4: patch --]
[-- Type: text/plain, Size: 3402 bytes --]
From 3a1a36b0b42772f35c70fb7e996ba8fed787e1c2 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 15 May 2019 18:51:30 -0400
Subject: [PATCH] Backport sgml-syntax-propertize-rules speedup (Bug#33887)
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-rules): Reapply
2019-01-17 "* lisp/textmodes/sgml-mode.el: Try and fix bug#33887."
taking into account 2019-05-09 "Recognize single quote attribute
values in nxml and sgml (Bug#35381)" which means we have to handle
single quotes as well.
* test/lisp/textmodes/sgml-mode-tests.el (sgml-quote-works): New test.
---
lisp/textmodes/sgml-mode.el | 21 +++++++++++++++------
test/lisp/textmodes/sgml-mode-tests.el | 14 ++++++++++++++
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 128e58810e..f8a37c3820 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -347,12 +347,21 @@ sgml-font-lock-keywords
("--[ \t\n]*\\(>\\)" (1 "> b"))
("\\(<\\)[?!]" (1 (prog1 "|>"
(sgml-syntax-propertize-inside end))))
- ;; Quotes outside of tags should not introduce strings.
- ;; 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.
- ("[\"']" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
- (goto-char (match-end 0)))
- (string-to-syntax ".")))))))
+ ;; Quotes outside of tags should not introduce strings which end up
+ ;; hiding tags. We used to test every quote and mark it as "."
+ ;; if it's outside of tags, but there are too many quotes and
+ ;; 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))
+ ;; 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.
+ (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
+ (goto-char (1- (match-end 0))))
+ (string-to-syntax ".")))))
+ )))
(defun sgml-syntax-propertize (start end)
"Syntactic keywords for `sgml-mode'."
diff --git a/test/lisp/textmodes/sgml-mode-tests.el b/test/lisp/textmodes/sgml-mode-tests.el
index 7318a667b3..8d0bb88163 100644
--- a/test/lisp/textmodes/sgml-mode-tests.el
+++ b/test/lisp/textmodes/sgml-mode-tests.el
@@ -130,5 +130,19 @@ sgml-with-content
(sgml-delete-tag 1)
(should (string= "Winter is comin'" (buffer-string)))))
+(ert-deftest sgml-tests--quotes-syntax ()
+ (dolist (str '("a\"b <t>c'd</t>"
+ "a'b <t>c\"d</t>"
+ "<t>\"a'</t>"
+ "<t>'a\"</t>"
+ "<t>\"a'\"</t>"
+ "<t>'a\"'</t>"))
+ (with-temp-buffer
+ (sgml-mode)
+ (insert str)
+ ;; Check that last tag is parsed as a tag.
+ (should (= 1 (car (syntax-ppss (1- (point-max))))))
+ (should (= 0 (car (syntax-ppss (point-max))))))))
+
(provide 'sgml-mode-tests)
;;; sgml-mode-tests.el ends here
--
2.11.0
next prev parent reply other threads:[~2019-05-18 4:15 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-27 10:13 bug#33887: 26.1; Emacs hangs for several seconds when going to the end of an XML file in nXML mode Vincent Lefevre
2018-12-27 16:02 ` Eli Zaretskii
2018-12-27 16:39 ` Stefan Monnier
2018-12-27 16:43 ` Eli Zaretskii
2018-12-27 17:32 ` Stefan Monnier
2018-12-27 17:47 ` Eli Zaretskii
2018-12-27 18:43 ` Vincent Lefevre
2018-12-28 17:18 ` Stefan Monnier
2019-01-17 22:57 ` Stefan Monnier
2019-01-08 22:11 ` Fernando Jascovich
2019-01-10 15:09 ` Eli Zaretskii
2019-01-17 23:25 ` Stefan Monnier
2019-05-15 23:53 ` Noam Postavsky
2019-05-16 10:54 ` Vincent Lefevre
2019-05-16 12:15 ` Noam Postavsky
2019-05-17 21:36 ` Vincent Lefevre
2019-05-18 4:15 ` Noam Postavsky [this message]
2019-05-18 14:47 ` Vincent Lefevre
2019-05-18 14:55 ` Vincent Lefevre
2019-05-18 14:57 ` Vincent Lefevre
2019-05-18 15:01 ` Vincent Lefevre
2019-05-18 18:49 ` Noam Postavsky
2019-05-19 0:17 ` Vincent Lefevre
2019-05-19 17:43 ` Noam Postavsky
2019-05-19 18:48 ` Stefan Monnier
2019-05-19 19:03 ` Noam Postavsky
2019-05-19 19:24 ` Stefan Monnier
2019-05-20 20:47 ` Noam Postavsky
2019-05-21 1:06 ` Vincent Lefevre
2019-05-21 12:27 ` Noam Postavsky
2019-05-22 13:58 ` Stefan Monnier
2019-05-22 15:44 ` Vincent Lefevre
2019-05-22 16:01 ` Stefan Monnier
2019-05-22 22:37 ` Stefan Monnier
2019-05-26 22:17 ` Noam Postavsky
2019-05-27 9:18 ` Vincent Lefevre
2019-05-27 12:02 ` Noam Postavsky
2019-05-29 0:30 ` Vincent Lefevre
2019-06-04 12:55 ` Noam Postavsky
2019-05-22 21:44 ` Stefan Monnier
2019-05-20 11:47 ` Vincent Lefevre
2019-05-16 14:01 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875zq8e6tw.fsf@gmail.com \
--to=npostavs@gmail.com \
--cc=33887@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=vincent@vinc17.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.