diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el index 1eb728f23a5..5c906a9d510 100644 --- a/lisp/nxml/nxml-mode.el +++ b/lisp/nxml/nxml-mode.el @@ -544,6 +544,7 @@ 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 21dbaded25a..3be413ae00b 100644 --- a/lisp/nxml/nxml-rap.el +++ b/lisp/nxml/nxml-rap.el @@ -108,6 +108,12 @@ 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