From da118e6a7c5d1d1d07fd186b0ae5e60340ac9dca Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 5 Jun 2019 19:24:58 -0400 Subject: [PATCH] Keep nxml prolog updated via syntax-propertize Instead of using after-change-functions. Also, stop consulting nxml-prolog-regions during syntax-propertize. It turns out the problems fixed by using prolog information are actually due to using the wrong syntax table during propertizing. This was fixed in 2019-06-04 "* lisp/emacs-lisp/syntax.el: Use syntax-ppss-table for syntax-propertize." so consulting the prolog data is no longer needed. * lisp/nxml/nxml-rap.el (nxml-maybe-rescan-prolog): Remove. * lisp/nxml/nxml-mode.el (nxml-mode): Stop using it. (nxml-syntax-propertize): Don't use nxml-prolog-regions, just call nxml-scan-prolog if needed before delegating to sgml-syntax-propertize. * test/lisp/nxml/nxml-mode-tests.el (nxml-mode-edit-prolog): New test. --- lisp/nxml/nxml-mode.el | 22 +++------------------- lisp/nxml/nxml-rap.el | 7 ------- test/lisp/nxml/nxml-mode-tests.el | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el index 5c906a9d510..ad78d086c74 100644 --- a/lisp/nxml/nxml-mode.el +++ b/lisp/nxml/nxml-mode.el @@ -428,25 +428,10 @@ reference.") (defun nxml-syntax-propertize (start end) "Syntactic keywords for `nxml-mode'." - ;; Like `sgml-syntax-propertize', but handle `nxml-prolog-regions'. + ;; Like `sgml-syntax-propertize', but rescan prolog if needed. (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))) + (nxml-scan-prolog)) + (sgml-syntax-propertize start end)) (defvar tildify-space-string) (defvar tildify-foreach-region-function) @@ -544,7 +529,6 @@ Many aspects this mode can be customized using (setq-local syntax-ppss-table sgml-tag-syntax-table) (setq-local syntax-propertize-function #'nxml-syntax-propertize) (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) - (add-hook 'after-change-functions #'nxml-maybe-rescan-prolog nil t) ;; Emacs 23 handles the encoding attribute on the xml declaration ;; transparently to nxml-mode, so there is no longer a need for the below diff --git a/lisp/nxml/nxml-rap.el b/lisp/nxml/nxml-rap.el index 3be413ae00b..cf34119c2c0 100644 --- a/lisp/nxml/nxml-rap.el +++ b/lisp/nxml/nxml-rap.el @@ -108,13 +108,6 @@ Return nil if the character at POS is not inside." (setq nxml-prolog-regions (xmltok-forward-prolog)) (setq nxml-prolog-end (point)))) -(defun nxml-maybe-rescan-prolog (start _end _length) - "Reparse the prolog if START lies within it. -`nxml-mode' adds this function on `after-change-functions'." - (when (<= start nxml-prolog-end) - (save-excursion - (nxml-scan-prolog)))) - ;;; Random access parsing (defun nxml-token-after () diff --git a/test/lisp/nxml/nxml-mode-tests.el b/test/lisp/nxml/nxml-mode-tests.el index 53416b4280c..e9b4fb7c7e1 100644 --- a/test/lisp/nxml/nxml-mode-tests.el +++ b/test/lisp/nxml/nxml-mode-tests.el @@ -114,5 +114,23 @@ (should (= 1 (- (car (syntax-ppss (1- (point-max)))) (car (syntax-ppss (point-max)))))))) +(ert-deftest nxml-mode-edit-prolog () + "Test for Bug#23668." + (with-temp-buffer + (insert " + + +") + (nxml-mode) + ;; The leading "\n " before "" is the prolog, indenting will + ;; delete the space hence changing the prolog size. If that is + ;; not taken into account, then the tag won't be indented + ;; correctly. + (indent-region (point-min) (point-max)) + (should (equal (buffer-string) " + + +")))) + (provide 'nxml-mode-tests) ;;; nxml-mode-tests.el ends here -- 2.39.2