From: Noam Postavsky <npostavs@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Vincent Lefevre <vincent@vinc17.net>, 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: Sun, 26 May 2019 18:17:55 -0400 [thread overview]
Message-ID: <875zpw97xo.fsf@gmail.com> (raw)
In-Reply-To: <jwvftp65epc.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Wed, 22 May 2019 18:37:44 -0400")
[-- Attachment #1: Type: text/plain, Size: 516 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> I pushed a patch which should fix the "lone >" problem without
> introducing any undue extra cost. It should also fix the "very long
> line" case.
Seems to pass my tests. Not sure if you missed the alternate fix I
proposed in https://debbugs.gnu.org/33887#94 or not. It does have the
disadvantage of leaving (car (syntax-ppss)) unreliable for any other
code which uses it.
Here's a patch against master that should cover the remaining cases
Vincent raised:
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 4011 bytes --]
From 2ffdab0e86161396e3d2606949d1fcf93c58b592 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 26 May 2019 11:07:14 -0400
Subject: [PATCH 1/2] Fix some SGML syntax edge cases (Bug#33887)
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-rules): Handle
single and double quotes symmetrically. Don't skip quoted comment
enders.
* test/lisp/textmodes/sgml-mode-tests.el (sgml-tests--quotes-syntax):
Add more test cases.
(sgml-mode-quote-in-long-text): New test.
---
lisp/textmodes/sgml-mode.el | 5 +++-
test/lisp/textmodes/sgml-mode-tests.el | 45 ++++++++++++++++++++++++++++------
2 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 75f20722b0..1df7e78afc 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -363,9 +363,12 @@ (eval-and-compile
;; 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 (if (eq (char-after) (char-after (match-beginning 0)))
(forward-char 1)
+ ;; Avoid skipping comment ender.
+ (when (eq (char-after) ?>)
+ (skip-chars-backward "-"))
;; 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 1b8965e344..34d26480a4 100644
--- a/test/lisp/textmodes/sgml-mode-tests.el
+++ b/test/lisp/textmodes/sgml-mode-tests.el
@@ -161,15 +161,46 @@ (ert-deftest sgml-quote-works ()
(should (string= "&&" (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>"
+ "a\"b <tag>c'd</tag>"
+ "<tag>c>'d</tag>"
+ "<t><!-- \" --></t>"
+ "<t><!-- ' --></t>"
+ ))
+ (with-temp-buffer
+ (sgml-mode)
+ (insert str)
+ (ert-info ((format "%S" str) :prefix "Test case: ")
+ ;; Check that last tag is parsed as a tag.
+ (should (= 1 (car (syntax-ppss (1- (point-max))))))
+ (should (= 0 (car (syntax-ppss (point-max)))))))))
+
+(ert-deftest sgml-mode-quote-in-long-text ()
(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)))))
- (erase-buffer)
- (insert "<tag>c>d</tag>")
- (should (= 1 (car (syntax-ppss (1- (point-max))))))
- (should (= 0 (car (syntax-ppss (point-max)))))))
+ (insert "<t>"
+ ;; `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"
+ "</t>")
+ ;; 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 'sgml-mode-tests)
;;; sgml-mode-tests.el ends here
--
2.11.0
[-- Attachment #3: Type: text/plain, Size: 134 bytes --]
And about the highlighting of quoted text outside tags, we can just
disable fontification, while leaving the syntax code untouched:
[-- Attachment #4: patch --]
[-- Type: text/plain, Size: 4141 bytes --]
From a4a6008d96011e2517939cb8cb51624802a8c31e Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 26 May 2019 17:41:22 -0400
Subject: [PATCH 2/2] Don't fontiy text outside of SGML/XML tags (Bug#33887)
* lisp/font-lock.el (font-lock-syntactic-face-function-default): New
function.
(font-lock-syntactic-face-function): Use it as default value.
* lisp/textmodes/sgml-mode.el (sgml-font-lock-syntactic-face): New
function.
(sgml-mode):
* lisp/nxml/nxml-mode.el (nxml-mode): Use it as
font-lock-syntactic-face-function value.
---
lisp/font-lock.el | 7 +++++--
lisp/nxml/nxml-mode.el | 4 +++-
lisp/textmodes/sgml-mode.el | 11 +++++++++--
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 3991a4ee8e..ddf1cbdb9f 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -527,9 +527,12 @@ (defvar font-lock-syntactically-fontified 0
sometimes be slightly incorrect.")
(make-variable-buffer-local 'font-lock-syntactically-fontified)
+(defun font-lock-syntactic-face-function-default (state)
+ "Default value for `font-lock-syntactic-face-function'."
+ (if (nth 3 state) font-lock-string-face font-lock-comment-face))
+
(defvar font-lock-syntactic-face-function
- (lambda (state)
- (if (nth 3 state) font-lock-string-face font-lock-comment-face))
+ #'font-lock-syntactic-face-function-default
"Function to determine which face to use when fontifying syntactically.
The function is called with a single parameter (the state as returned by
`parse-partial-sexp' at the beginning of the region to highlight) and
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index da01b2a342..05044d66df 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -551,7 +551,9 @@ (define-derived-mode nxml-mode text-mode "nXML"
nil ; no special syntax table
(font-lock-extend-region-functions . (nxml-extend-region))
(jit-lock-contextually . t)
- (font-lock-unfontify-region-function . nxml-unfontify-region)))
+ (font-lock-unfontify-region-function . nxml-unfontify-region)
+ (font-lock-syntactic-face-function
+ . sgml-font-lock-syntactic-face)))
(with-demoted-errors (rng-nxml-mode-init)))
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 1df7e78afc..225fe72a01 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -329,6 +329,11 @@ (defconst sgml-font-lock-keywords-2
(defvar sgml-font-lock-keywords sgml-font-lock-keywords-1
"Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
+(defun sgml-font-lock-syntactic-face (state)
+ "`font-lock-syntactic-face-function' for `sgml-mode'."
+ (and (nth 9 state) ;; Only use faces within tags.
+ (font-lock-syntactic-face-function-default state)))
+
(defvar-local sgml--syntax-propertize-ppss nil)
(defun sgml--syntax-propertize-ppss (pos)
@@ -573,7 +578,7 @@ (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML")
;; This is desirable because SGML discards a newline that appears
;; immediately after a start tag or immediately before an end tag.
(setq-local paragraph-start (concat "[ \t]*$\\|\
-[ \t]*</?\\(" sgml-name-re sgml-attrs-re "\\)?>"))
+\[ \t]*</?\\(" sgml-name-re sgml-attrs-re "\\)?>"))
(setq-local paragraph-separate (concat paragraph-start "$"))
(setq-local adaptive-fill-regexp "[ \t]*")
(add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t)
@@ -591,7 +596,9 @@ (define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "SGML")
(setq font-lock-defaults '((sgml-font-lock-keywords
sgml-font-lock-keywords-1
sgml-font-lock-keywords-2)
- nil t))
+ nil t nil
+ (font-lock-syntactic-face-function
+ . sgml-font-lock-syntactic-face)))
(setq-local syntax-propertize-function #'sgml-syntax-propertize)
(setq-local facemenu-add-face-function 'sgml-mode-facemenu-add-face-function)
(setq-local sgml-xml-mode (sgml-xml-guess))
--
2.11.0
next prev parent reply other threads:[~2019-05-26 22:17 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
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 [this message]
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=875zpw97xo.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.