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 14:49:42 -0400 [thread overview]
Message-ID: <87r28vd2d5.fsf@gmail.com> (raw)
In-Reply-To: <20190518144756.GA21327@zira.vinc17.org> (Vincent Lefevre's message of "Sat, 18 May 2019 16:47:56 +0200")
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
Vincent Lefevre <vincent@vinc17.net> writes:
> There's still an issue. On the following XML file
>
> <root>
> <a>text</a>
> <!-- ' -->
> <a>text</a>
> </root>
>
> the part after the comment <!-- ' --> is highlighted as a comment.
> And another one:
>
> <root>
> <a>text</a>
> <!-- "don't" -->
> <a>text</a>
> </root>
>
> The second text is highlighted as a comment.
Right, this is a collision between the syntax rules. The following
patch fixes it, though perhaps it would be better to just search for the
end of the comment in the ("\\(<\\)!--" (1 "< b")) rule instead?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2702 bytes --]
From a866e4f4b556fb4a346fa68c62296f10966690a1 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 18 May 2019 13:18:19 -0400
Subject: [PATCH] Fix sgml syntax handling of quotes in comments
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-rules): Make
sure not to skip over comment ender when searching for quotes.
* test/lisp/textmodes/sgml-mode-tests.el (sgml-tests--quotes-syntax):
Add a some more cases.
---
lisp/textmodes/sgml-mode.el | 11 ++++++++---
test/lisp/textmodes/sgml-mode-tests.el | 16 +++++++++-------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index e3cf56aa0e..1af1d1eaef 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -350,9 +350,14 @@ sgml-font-lock-keywords
;; 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 ".")))))
+ (let ((ppss (syntax-ppss (match-beginning 0))))
+ (if (prog1 (zerop (car ppss)) ; Outside tag.
+ (goto-char (1- (match-end 0)))
+ ;; If we're in a comment, don't skip over comment
+ ;; ender.
+ (when (nth 4 ppss)
+ (skip-chars-backward "- \t\n")))
+ (string-to-syntax "."))))))
)))
(defun sgml-syntax-propertize (start end)
diff --git a/test/lisp/textmodes/sgml-mode-tests.el b/test/lisp/textmodes/sgml-mode-tests.el
index ffcc2cd840..7e1ddf4047 100644
--- a/test/lisp/textmodes/sgml-mode-tests.el
+++ b/test/lisp/textmodes/sgml-mode-tests.el
@@ -166,13 +166,15 @@ sgml-with-content
"<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))))))))
+ "<t>'a\"'</t>"
+ "<t><!-- ' --></t>"
+ "<t><!-- \" --></t>"))
+ (ert-info (str :prefix "Test string: ")
+ (sgml-with-content
+ 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: 449 bytes --]
> <!DOCTYPE root [
> <!ENTITY f SYSTEM "f.xml">
> ]>
> <root>
> <a>ab'cd</a>
> <a>text</a>
> </root>
This is a different issue, I think the problem is that
sgml-syntax-propertize-inside doesn't handle nesting in the DTD
definition <! [ <! ... > ]>. The patch below just avoids calling
sgml-syntax-propertize-inside on the prolog in nxml-mode (but the
problem remains in sgml-mode). Though you'll hit Bug#18871/23668 if you
try to edit the DTD.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: patch --]
[-- Type: text/x-diff, Size: 2580 bytes --]
From 9a50fc38b537d570f739c428a57c66557152151b Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 18 May 2019 14:37:51 -0400
Subject: [PATCH] Don't sgml-syntax-propertize-inside XML prolog
* lisp/nxml/nxml-mode.el (nxml-syntax-propertize): New function.
(nxml-mode): Use it as the syntax-propertize-function.
* test/lisp/nxml/nxml-mode-tests.el (nxml-mode-doctype-and-quote-syntax):
New test.
---
lisp/nxml/nxml-mode.el | 16 +++++++++++++++-
test/lisp/nxml/nxml-mode-tests.el | 8 ++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index ab035b927e..7c39c5023c 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -423,6 +423,20 @@ nxml-parent-document-set
(when rng-validate-mode
(rng-validate-while-idle (current-buffer)))))
+(defvar nxml-prolog-end) ;; nxml-rap.el
+(defun nxml-syntax-propertize (start end)
+ "Syntactic keywords for `nxml-mode'."
+ ;; Like `sgml-syntax-propertize', but skip prolog.
+ (setq start (max start nxml-prolog-end))
+ (if (>= start end)
+ (goto-char end)
+ (goto-char start)
+ (sgml-syntax-propertize-inside end)
+ (funcall
+ (syntax-propertize-rules sgml-syntax-propertize-rules)
+ start end)))
+
+
(defvar tildify-space-string)
(defvar tildify-foreach-region-function)
@@ -518,7 +532,7 @@ nxml-mode
(nxml-with-invisible-motion
(nxml-scan-prolog)))))
(setq-local syntax-ppss-table sgml-tag-syntax-table)
- (setq-local syntax-propertize-function #'sgml-syntax-propertize)
+ (setq-local syntax-propertize-function #'nxml-syntax-propertize)
(add-hook 'change-major-mode-hook #'nxml-cleanup nil t)
;; Emacs 23 handles the encoding attribute on the xml declaration
diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el
index 92744be619..2bbf92bc96 100644
--- a/test/lisp/nxml/nxml-mode-tests.el
+++ b/test/lisp/nxml/nxml-mode-tests.el
@@ -78,5 +78,13 @@ nxml-mode-tests-correctly-indented-string
(should-not (equal (get-text-property squote-txt-pos 'face)
(get-text-property dquote-att-pos 'face))))))
+(ert-deftest nxml-mode-doctype-and-quote-syntax ()
+ (with-temp-buffer
+ (insert "<!DOCTYPE t [\n<!ENTITY f SYSTEM \"f.xml\">\n]>\n<t>'</t>")
+ (nxml-mode)
+ ;; 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 'nxml-mode-tests)
;;; nxml-mode-tests.el ends here
--
2.11.0
next prev parent reply other threads:[~2019-05-18 18:49 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
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 [this message]
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=87r28vd2d5.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.