emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master d414c93 3/4: Don't sgml-syntax-propertize-inside XM


From: Noam Postavsky
Subject: [Emacs-diffs] master d414c93 3/4: Don't sgml-syntax-propertize-inside XML prolog (Bug#32823)
Date: Tue, 4 Jun 2019 08:43:39 -0400 (EDT)

branch: master
commit d414c93b062cc3e245a6db0cb764d354d037bd42
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Don't sgml-syntax-propertize-inside XML prolog (Bug#32823)
    
    * 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)
    (nxml-mode-prolog-comment): New tests.
---
 lisp/nxml/nxml-mode.el            | 26 +++++++++++++++++++++++++-
 test/lisp/nxml/nxml-mode-tests.el | 21 +++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 232352b..1eb728f 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -424,6 +424,30 @@ reference.")
     (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 handle `nxml-prolog-regions'.
+  (when (< start nxml-prolog-end)
+    (catch 'done-prolog
+      (dolist (prolog-elem nxml-prolog-regions)
+        (let ((type (aref prolog-elem 0))
+              (pbeg (aref prolog-elem 1))
+              (pend (aref prolog-elem 2)))
+          (when (eq type 'comment)
+            (put-text-property pbeg (1+ pbeg)
+                               'syntax-table (string-to-syntax "< b"))
+            (put-text-property (1- pend) pend
+                               'syntax-table (string-to-syntax "> b")))
+          (when (> pend end)
+            (throw 'done-prolog t)))))
+    (setq start nxml-prolog-end))
+  (if (>= start end)
+      (goto-char end)
+    (goto-char start)
+    (sgml-syntax-propertize start end)))
+
 (defvar tildify-space-string)
 (defvar tildify-foreach-region-function)
 
@@ -518,7 +542,7 @@ Many aspects this mode can be customized using
        (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 92744be..70816bb 100644
--- a/test/lisp/nxml/nxml-mode-tests.el
+++ b/test/lisp/nxml/nxml-mode-tests.el
@@ -78,5 +78,26 @@
       (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)))))))
+
+(ert-deftest nxml-mode-prolog-comment ()
+  (with-temp-buffer
+    (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?><!-- comment1 -->
+<t><!-- comment2 --></t><!-- comment3 -->")
+    (nxml-mode)
+    ;; Check that all comments are parsed as comments
+    (goto-char (point-min))
+    (search-forward "comment1")
+    (should (nth 4 (syntax-ppss)))
+    (search-forward "comment2")
+    (should (nth 4 (syntax-ppss)))
+    (search-forward "comment3")))
+
 (provide 'nxml-mode-tests)
 ;;; nxml-mode-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]