summaryrefslogtreecommitdiff
path: root/lisp/nxml/nxml-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/nxml/nxml-mode.el')
-rw-r--r--lisp/nxml/nxml-mode.el75
1 files changed, 22 insertions, 53 deletions
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index c45196f0316..da3c034b5ff 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -1,4 +1,4 @@
-;;; nxml-mode.el --- a new XML mode
+;;; nxml-mode.el --- a new XML mode -*- lexical-binding:t -*-
;; Copyright (C) 2003-2004, 2007-2013 Free Software Foundation, Inc.
@@ -540,14 +540,14 @@ Many aspects this mode can be customized using
(nxml-scan-prolog)))))
(add-hook 'completion-at-point-functions
#'nxml-completion-at-point-function nil t)
- (add-hook 'after-change-functions 'nxml-after-change nil t)
+ (setq-local syntax-propertize-function #'nxml-after-change)
(add-hook 'change-major-mode-hook 'nxml-cleanup 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
;; hook. The hook also had the drawback of overriding explicit user
;; instruction to save as some encoding other than utf-8.
-;;; (add-hook 'write-contents-hooks 'nxml-prepare-to-save)
+ ;;(add-hook 'write-contents-hooks 'nxml-prepare-to-save)
(when (not (and (buffer-file-name) (file-exists-p (buffer-file-name))))
(when (and nxml-default-buffer-file-coding-system
(not (local-variable-p 'buffer-file-coding-system)))
@@ -561,8 +561,6 @@ Many aspects this mode can be customized using
nil ; font-lock-keywords-case-fold-search. XML is case sensitive
nil ; no special syntax table
nil ; no automatic syntactic fontification
- (font-lock-extend-after-change-region-function
- . nxml-extend-after-change-region)
(font-lock-extend-region-functions . (nxml-extend-region))
(jit-lock-contextually . t)
(font-lock-unfontify-region-function . nxml-unfontify-region)))
@@ -597,6 +595,7 @@ Many aspects this mode can be customized using
;;; Change management
+(defvar font-lock-beg) (defvar font-lock-end)
(defun nxml-debug-region (start end)
(interactive "r")
(let ((font-lock-beg start)
@@ -605,22 +604,16 @@ Many aspects this mode can be customized using
(goto-char font-lock-beg)
(set-mark font-lock-end)))
-(defun nxml-after-change (start end pre-change-length)
- ; In font-lock mode, nxml-after-change1 is called via
- ; nxml-extend-after-change-region instead so that the updated
- ; book-keeping information is available for fontification.
- (unless (or font-lock-mode nxml-degraded)
+(defun nxml-after-change (start end)
+ ;; Called via syntax-propertize-function.
+ (unless nxml-degraded
(nxml-with-degradation-on-error 'nxml-after-change
- (save-excursion
- (save-restriction
- (widen)
- (save-match-data
- (nxml-with-invisible-motion
- (with-silent-modifications
- (nxml-after-change1
- start end pre-change-length)))))))))
-
-(defun nxml-after-change1 (start end pre-change-length)
+ (save-restriction
+ (widen)
+ (nxml-with-invisible-motion
+ (nxml-after-change1 start end))))))
+
+(defun nxml-after-change1 (start end)
"After-change bookkeeping.
Returns a cons cell containing a possibly-enlarged change region.
You must call `nxml-extend-region' on this expanded region to obtain
@@ -628,23 +621,14 @@ the full extent of the area needing refontification.
For bookkeeping, call this function even when fontification is
disabled."
- (let ((pre-change-end (+ start pre-change-length)))
- ;; If the prolog might have changed, rescan the prolog
- (when (<= start
- ;; Add 2 so as to include the < and following char that
- ;; start the instance (document element), since changing
- ;; these can change where the prolog ends.
- (+ nxml-prolog-end 2))
- ;; end must be extended to at least the end of the old prolog in
- ;; case the new prolog is shorter
- (when (< pre-change-end nxml-prolog-end)
- (setq end
- ;; don't let end get out of range even if pre-change-length
- ;; is bogus
- (min (point-max)
- (+ end (- nxml-prolog-end pre-change-end)))))
- (nxml-scan-prolog)
- (setq start (point-min))))
+ ;; If the prolog might have changed, rescan the prolog.
+ (when (<= start
+ ;; Add 2 so as to include the < and following char that
+ ;; start the instance (document element), since changing
+ ;; these can change where the prolog ends.
+ (+ nxml-prolog-end 2))
+ (nxml-scan-prolog)
+ (setq start (point-min)))
(when (> end nxml-prolog-end)
(goto-char start)
@@ -653,8 +637,7 @@ disabled."
(setq end (max (nxml-scan-after-change start end)
end)))
- (nxml-debug-change "nxml-after-change1" start end)
- (cons start end))
+ (nxml-debug-change "nxml-after-change1" start end))
;;; Encodings
@@ -845,7 +828,6 @@ The XML declaration will declare an encoding depending on the buffer's
(font-lock-default-unfontify-region start end)
(nxml-clear-char-ref-extra-display start end))
-(defvar font-lock-beg) (defvar font-lock-end)
(defun nxml-extend-region ()
"Extend the region to hold the minimum area we can fontify with nXML.
Called with `font-lock-beg' and `font-lock-end' dynamically bound."
@@ -887,19 +869,6 @@ Called with `font-lock-beg' and `font-lock-end' dynamically bound."
(nxml-debug-change "nxml-extend-region" start end)
t)))
-(defun nxml-extend-after-change-region (start end pre-change-length)
- (unless nxml-degraded
- (nxml-with-degradation-on-error
- 'nxml-extend-after-change-region
- (save-excursion
- (save-restriction
- (widen)
- (save-match-data
- (nxml-with-invisible-motion
- (with-silent-modifications
- (nxml-after-change1
- start end pre-change-length)))))))))
-
(defun nxml-fontify-matcher (bound)
"Called as font-lock keyword matcher."