aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2019-05-18 14:37:51 -0400
committerNoam Postavsky2019-06-04 08:42:50 -0400
commitd414c93b062cc3e245a6db0cb764d354d037bd42 (patch)
treee594558391e8a55800012b8d9642e322685ff355
parente04f93e18a8083d3a4930decc523c4f5d9a97c9e (diff)
downloademacs-d414c93b062cc3e245a6db0cb764d354d037bd42.tar.gz
emacs-d414c93b062cc3e245a6db0cb764d354d037bd42.zip
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.
-rw-r--r--lisp/nxml/nxml-mode.el26
-rw-r--r--test/lisp/nxml/nxml-mode-tests.el21
2 files changed, 46 insertions, 1 deletions
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 232352b26bd..1eb728f23a5 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -424,6 +424,30 @@ reference.")
424 (when rng-validate-mode 424 (when rng-validate-mode
425 (rng-validate-while-idle (current-buffer))))) 425 (rng-validate-while-idle (current-buffer)))))
426 426
427(defvar nxml-prolog-end) ;; nxml-rap.el
428
429(defun nxml-syntax-propertize (start end)
430 "Syntactic keywords for `nxml-mode'."
431 ;; Like `sgml-syntax-propertize', but handle `nxml-prolog-regions'.
432 (when (< start nxml-prolog-end)
433 (catch 'done-prolog
434 (dolist (prolog-elem nxml-prolog-regions)
435 (let ((type (aref prolog-elem 0))
436 (pbeg (aref prolog-elem 1))
437 (pend (aref prolog-elem 2)))
438 (when (eq type 'comment)
439 (put-text-property pbeg (1+ pbeg)
440 'syntax-table (string-to-syntax "< b"))
441 (put-text-property (1- pend) pend
442 'syntax-table (string-to-syntax "> b")))
443 (when (> pend end)
444 (throw 'done-prolog t)))))
445 (setq start nxml-prolog-end))
446 (if (>= start end)
447 (goto-char end)
448 (goto-char start)
449 (sgml-syntax-propertize start end)))
450
427(defvar tildify-space-string) 451(defvar tildify-space-string)
428(defvar tildify-foreach-region-function) 452(defvar tildify-foreach-region-function)
429 453
@@ -518,7 +542,7 @@ Many aspects this mode can be customized using
518 (nxml-with-invisible-motion 542 (nxml-with-invisible-motion
519 (nxml-scan-prolog))))) 543 (nxml-scan-prolog)))))
520 (setq-local syntax-ppss-table sgml-tag-syntax-table) 544 (setq-local syntax-ppss-table sgml-tag-syntax-table)
521 (setq-local syntax-propertize-function #'sgml-syntax-propertize) 545 (setq-local syntax-propertize-function #'nxml-syntax-propertize)
522 (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) 546 (add-hook 'change-major-mode-hook #'nxml-cleanup nil t)
523 547
524 ;; Emacs 23 handles the encoding attribute on the xml declaration 548 ;; 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 92744be619d..70816bb9de0 100644
--- a/test/lisp/nxml/nxml-mode-tests.el
+++ b/test/lisp/nxml/nxml-mode-tests.el
@@ -78,5 +78,26 @@
78 (should-not (equal (get-text-property squote-txt-pos 'face) 78 (should-not (equal (get-text-property squote-txt-pos 'face)
79 (get-text-property dquote-att-pos 'face)))))) 79 (get-text-property dquote-att-pos 'face))))))
80 80
81(ert-deftest nxml-mode-doctype-and-quote-syntax ()
82 (with-temp-buffer
83 (insert "<!DOCTYPE t [\n<!ENTITY f SYSTEM \"f.xml\">\n]>\n<t>'</t>")
84 (nxml-mode)
85 ;; Check that last tag is parsed as a tag.
86 (should (= 1 (car (syntax-ppss (1- (point-max))))))
87 (should (= 0 (car (syntax-ppss (point-max)))))))
88
89(ert-deftest nxml-mode-prolog-comment ()
90 (with-temp-buffer
91 (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?><!-- comment1 -->
92<t><!-- comment2 --></t><!-- comment3 -->")
93 (nxml-mode)
94 ;; Check that all comments are parsed as comments
95 (goto-char (point-min))
96 (search-forward "comment1")
97 (should (nth 4 (syntax-ppss)))
98 (search-forward "comment2")
99 (should (nth 4 (syntax-ppss)))
100 (search-forward "comment3")))
101
81(provide 'nxml-mode-tests) 102(provide 'nxml-mode-tests)
82;;; nxml-mode-tests.el ends here 103;;; nxml-mode-tests.el ends here