aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2019-06-05 19:24:58 -0400
committerNoam Postavsky2019-06-05 20:30:23 -0400
commitda118e6a7c5d1d1d07fd186b0ae5e60340ac9dca (patch)
tree932423461bb4df20c46b50ffbf0c96c74ddf49d8
parent610fb73ab6d7a22b722f523d6ebc4aa8fa1db7c9 (diff)
downloademacs-da118e6a7c5d1d1d07fd186b0ae5e60340ac9dca.tar.gz
emacs-da118e6a7c5d1d1d07fd186b0ae5e60340ac9dca.zip
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.
-rw-r--r--lisp/nxml/nxml-mode.el22
-rw-r--r--lisp/nxml/nxml-rap.el7
-rw-r--r--test/lisp/nxml/nxml-mode-tests.el18
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.")
428 428
429(defun nxml-syntax-propertize (start end) 429(defun nxml-syntax-propertize (start end)
430 "Syntactic keywords for `nxml-mode'." 430 "Syntactic keywords for `nxml-mode'."
431 ;; Like `sgml-syntax-propertize', but handle `nxml-prolog-regions'. 431 ;; Like `sgml-syntax-propertize', but rescan prolog if needed.
432 (when (< start nxml-prolog-end) 432 (when (< start nxml-prolog-end)
433 (catch 'done-prolog 433 (nxml-scan-prolog))
434 (dolist (prolog-elem nxml-prolog-regions) 434 (sgml-syntax-propertize start end))
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 435
451(defvar tildify-space-string) 436(defvar tildify-space-string)
452(defvar tildify-foreach-region-function) 437(defvar tildify-foreach-region-function)
@@ -544,7 +529,6 @@ Many aspects this mode can be customized using
544 (setq-local syntax-ppss-table sgml-tag-syntax-table) 529 (setq-local syntax-ppss-table sgml-tag-syntax-table)
545 (setq-local syntax-propertize-function #'nxml-syntax-propertize) 530 (setq-local syntax-propertize-function #'nxml-syntax-propertize)
546 (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) 531 (add-hook 'change-major-mode-hook #'nxml-cleanup nil t)
547 (add-hook 'after-change-functions #'nxml-maybe-rescan-prolog nil t)
548 532
549 ;; Emacs 23 handles the encoding attribute on the xml declaration 533 ;; Emacs 23 handles the encoding attribute on the xml declaration
550 ;; transparently to nxml-mode, so there is no longer a need for the below 534 ;; 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."
108 (setq nxml-prolog-regions (xmltok-forward-prolog)) 108 (setq nxml-prolog-regions (xmltok-forward-prolog))
109 (setq nxml-prolog-end (point)))) 109 (setq nxml-prolog-end (point))))
110 110
111(defun nxml-maybe-rescan-prolog (start _end _length)
112 "Reparse the prolog if START lies within it.
113`nxml-mode' adds this function on `after-change-functions'."
114 (when (<= start nxml-prolog-end)
115 (save-excursion
116 (nxml-scan-prolog))))
117
118;;; Random access parsing 111;;; Random access parsing
119 112
120(defun nxml-token-after () 113(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 @@
114 (should (= 1 (- (car (syntax-ppss (1- (point-max)))) 114 (should (= 1 (- (car (syntax-ppss (1- (point-max))))
115 (car (syntax-ppss (point-max)))))))) 115 (car (syntax-ppss (point-max))))))))
116 116
117(ert-deftest nxml-mode-edit-prolog ()
118 "Test for Bug#23668."
119 (with-temp-buffer
120 (insert "
121 <t>
122 <sub/>
123</t>")
124 (nxml-mode)
125 ;; The leading "\n " before "<t>" is the prolog, indenting will
126 ;; delete the space hence changing the prolog size. If that is
127 ;; not taken into account, then the <sub/> tag won't be indented
128 ;; correctly.
129 (indent-region (point-min) (point-max))
130 (should (equal (buffer-string) "
131<t>
132 <sub/>
133</t>"))))
134
117(provide 'nxml-mode-tests) 135(provide 'nxml-mode-tests)
118;;; nxml-mode-tests.el ends here 136;;; nxml-mode-tests.el ends here