aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-05-15 14:31:51 -0400
committerStefan Monnier2013-05-15 14:31:51 -0400
commitc99904740ebcfde5533c29798618b968d56c0bf4 (patch)
treea9f40e16ec3f07f31dace8af562a0ea3cf6d3bae
parente3772e9833f971a450562350dc233bf00be7c5eb (diff)
downloademacs-c99904740ebcfde5533c29798618b968d56c0bf4.tar.gz
emacs-c99904740ebcfde5533c29798618b968d56c0bf4.zip
* lisp/nxml/nxml-mode.el: Treat unclosed <[[, <?, comment, and other
literals as extending to EOB. (nxml-last-fontify-end): Remove unused variable. (nxml-after-change1): Use with-silent-modifications. (nxml-extend-after-change-region): Simplify. (nxml-extend-after-change-region1): Remove function. (nxml-after-change1): Don't adjust for dependent regions. (nxml-fontify-matcher): Simplify. * lisp/nxml/xmltok.el (xmltok-dependent-regions): Remove variable. (xmltok-add-dependent): Remove function. (xmltok-scan-after-lt, xmltok-scan-after-processing-instruction-open) (xmltok-scan-after-comment-open, xmltok-scan-prolog-literal) (xmltok-scan-prolog-after-processing-instruction-open): Treat unclosed <[[, <?, comment, and other literals as extending to EOB. * lisp/nxml/rng-valid.el (rng-mark-xmltok-dependent-regions) (rng-mark-xmltok-dependent-region, rng-dependent-region-changed): Remove functions. (rng-do-some-validation-1): Don't mark dependent regions. * lisp/nxml/nxml-rap.el (nxml-adjust-start-for-dependent-regions) (nxml-mark-parse-dependent-regions, nxml-mark-parse-dependent-region) (nxml-clear-dependent-regions): Remove functions. (nxml-scan-after-change, nxml-scan-prolog, nxml-tokenize-forward) (nxml-ensure-scan-up-to-date): Don't clear&mark dependent regions.
-rw-r--r--lisp/ChangeLog37
-rw-r--r--lisp/nxml/nxml-mode.el52
-rw-r--r--lisp/nxml/nxml-rap.el86
-rw-r--r--lisp/nxml/rng-valid.el53
-rw-r--r--lisp/nxml/xmltok.el290
5 files changed, 154 insertions, 364 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ffcd36f4af1..4f620dfb00a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,7 +1,34 @@
12013-05-15 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * nxml/nxml-mode.el: Treat unclosed <[[, <?, comment, and other
4 literals as extending to EOB.
5 (nxml-last-fontify-end): Remove unused variable.
6 (nxml-after-change1): Use with-silent-modifications.
7 (nxml-extend-after-change-region): Simplify.
8 (nxml-extend-after-change-region1): Remove function.
9 (nxml-after-change1): Don't adjust for dependent regions.
10 (nxml-fontify-matcher): Simplify.
11 * nxml/xmltok.el (xmltok-dependent-regions): Remove variable.
12 (xmltok-add-dependent): Remove function.
13 (xmltok-scan-after-lt, xmltok-scan-after-processing-instruction-open)
14 (xmltok-scan-after-comment-open, xmltok-scan-prolog-literal)
15 (xmltok-scan-prolog-after-processing-instruction-open): Treat
16 unclosed <[[, <?, comment, and other literals as extending to EOB.
17 * nxml/rng-valid.el (rng-mark-xmltok-dependent-regions)
18 (rng-mark-xmltok-dependent-region, rng-dependent-region-changed):
19 Remove functions.
20 (rng-do-some-validation-1): Don't mark dependent regions.
21 * nxml/nxml-rap.el (nxml-adjust-start-for-dependent-regions)
22 (nxml-mark-parse-dependent-regions, nxml-mark-parse-dependent-region)
23 (nxml-clear-dependent-regions): Remove functions.
24 (nxml-scan-after-change, nxml-scan-prolog, nxml-tokenize-forward)
25 (nxml-ensure-scan-up-to-date):
26 Don't clear&mark dependent regions.
27
12013-05-15 Leo Liu <sdl.web@gmail.com> 282013-05-15 Leo Liu <sdl.web@gmail.com>
2 29
3 * progmodes/octave.el (octave-goto-function-definition): Improve 30 * progmodes/octave.el (octave-goto-function-definition):
4 and fix callers. 31 Improve and fix callers.
5 32
62013-05-15 Stefan Monnier <monnier@iro.umontreal.ca> 332013-05-15 Stefan Monnier <monnier@iro.umontreal.ca>
7 34
@@ -277,7 +304,8 @@
277 their declaration. 304 their declaration.
278 (vhdl-mode-syntax-table-init): Remove. 305 (vhdl-mode-syntax-table-init): Remove.
279 306
280 * progmodes/m4-mode.el (m4-mode-syntax-table): Add comment on last change. 307 * progmodes/m4-mode.el (m4-mode-syntax-table): Add comment on
308 last change.
281 309
282 * progmodes/ld-script.el (ld-script-mode-syntax-table): Use symbol 310 * progmodes/ld-script.el (ld-script-mode-syntax-table): Use symbol
283 syntax for "_". 311 syntax for "_".
@@ -292,7 +320,8 @@
292 Handle a _ with symbol syntax. 320 Handle a _ with symbol syntax.
293 (autoconf-mode): Don't change the syntax-table for imenu and font-lock. 321 (autoconf-mode): Don't change the syntax-table for imenu and font-lock.
294 322
295 * progmodes/ada-mode.el (ada-mode-abbrev-table): Consolidate declaration. 323 * progmodes/ada-mode.el (ada-mode-abbrev-table):
324 Consolidate declaration.
296 (ada-mode-syntax-table, ada-mode-symbol-syntax-table): Initialize in 325 (ada-mode-syntax-table, ada-mode-symbol-syntax-table): Initialize in
297 the declaration. 326 the declaration.
298 (ada-create-syntax-table): Remove. 327 (ada-create-syntax-table): Remove.
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index 44271a689cf..c45196f0316 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -352,11 +352,6 @@ Use `nxml-parent-document-set' to set it.")
352See the function `xmltok-forward-prolog' for more information.") 352See the function `xmltok-forward-prolog' for more information.")
353(make-variable-buffer-local 'nxml-prolog-regions) 353(make-variable-buffer-local 'nxml-prolog-regions)
354 354
355(defvar nxml-last-fontify-end nil
356 "Position where fontification last ended.
357It is nil if the buffer changed since the last fontification.")
358(make-variable-buffer-local 'nxml-last-fontify-end)
359
360(defvar nxml-degraded nil 355(defvar nxml-degraded nil
361 "Non-nil if currently operating in degraded mode. 356 "Non-nil if currently operating in degraded mode.
362Degraded mode is enabled when an internal error is encountered in the 357Degraded mode is enabled when an internal error is encountered in the
@@ -538,7 +533,6 @@ Many aspects this mode can be customized using
538 (save-excursion 533 (save-excursion
539 (save-restriction 534 (save-restriction
540 (widen) 535 (widen)
541 (nxml-clear-dependent-regions (point-min) (point-max))
542 (setq nxml-scan-end (copy-marker (point-min) nil)) 536 (setq nxml-scan-end (copy-marker (point-min) nil))
543 (with-silent-modifications 537 (with-silent-modifications
544 (nxml-clear-inside (point-min) (point-max)) 538 (nxml-clear-inside (point-min) (point-max))
@@ -583,12 +577,9 @@ Many aspects this mode can be customized using
583 ;; Clean up fontification. 577 ;; Clean up fontification.
584 (save-excursion 578 (save-excursion
585 (widen) 579 (widen)
586 (let ((inhibit-read-only t) 580 (with-silent-modifications
587 (buffer-undo-list t)
588 (modified (buffer-modified-p)))
589 (nxml-with-invisible-motion 581 (nxml-with-invisible-motion
590 (remove-text-properties (point-min) (point-max) '(face))) 582 (remove-text-properties (point-min) (point-max) '(face)))))
591 (set-buffer-modified-p modified)))
592 (remove-hook 'change-major-mode-hook 'nxml-cleanup t)) 583 (remove-hook 'change-major-mode-hook 'nxml-cleanup t))
593 584
594(defun nxml-degrade (context err) 585(defun nxml-degrade (context err)
@@ -638,10 +629,6 @@ the full extent of the area needing refontification.
638For bookkeeping, call this function even when fontification is 629For bookkeeping, call this function even when fontification is
639disabled." 630disabled."
640 (let ((pre-change-end (+ start pre-change-length))) 631 (let ((pre-change-end (+ start pre-change-length)))
641 (setq start
642 (nxml-adjust-start-for-dependent-regions start
643 end
644 pre-change-length))
645 ;; If the prolog might have changed, rescan the prolog 632 ;; If the prolog might have changed, rescan the prolog
646 (when (<= start 633 (when (<= start
647 ;; Add 2 so as to include the < and following char that 634 ;; Add 2 so as to include the < and following char that
@@ -902,26 +889,16 @@ Called with `font-lock-beg' and `font-lock-end' dynamically bound."
902 889
903(defun nxml-extend-after-change-region (start end pre-change-length) 890(defun nxml-extend-after-change-region (start end pre-change-length)
904 (unless nxml-degraded 891 (unless nxml-degraded
905 (setq nxml-last-fontify-end nil) 892 (nxml-with-degradation-on-error
906 (let ((region (nxml-with-degradation-on-error 893 'nxml-extend-after-change-region
907 'nxml-extend-after-change-region 894 (save-excursion
908 (save-excursion 895 (save-restriction
909 (save-restriction 896 (widen)
910 (widen) 897 (save-match-data
911 (save-match-data 898 (nxml-with-invisible-motion
912 (nxml-with-invisible-motion 899 (with-silent-modifications
913 (with-silent-modifications 900 (nxml-after-change1
914 (nxml-extend-after-change-region1 901 start end pre-change-length)))))))))
915 start end pre-change-length)))))))))
916 (if (consp region) region))))
917
918(defun nxml-extend-after-change-region1 (start end pre-change-length)
919 (let* ((region (nxml-after-change1 start end pre-change-length))
920 (font-lock-beg (car region))
921 (font-lock-end (cdr region)))
922
923 (nxml-extend-region)
924 (cons font-lock-beg font-lock-end)))
925 902
926(defun nxml-fontify-matcher (bound) 903(defun nxml-fontify-matcher (bound)
927 "Called as font-lock keyword matcher." 904 "Called as font-lock keyword matcher."
@@ -936,13 +913,12 @@ Called with `font-lock-beg' and `font-lock-end' dynamically bound."
936 (nxml-fontify-prolog) 913 (nxml-fontify-prolog)
937 (goto-char nxml-prolog-end)) 914 (goto-char nxml-prolog-end))
938 915
939 (let (xmltok-dependent-regions 916 (let (xmltok-errors)
940 xmltok-errors)
941 (while (and (nxml-tokenize-forward) 917 (while (and (nxml-tokenize-forward)
942 (<= (point) bound)) ; Intervals are open-ended. 918 (<= (point) bound)) ; Intervals are open-ended.
943 (nxml-apply-fontify-rule))) 919 (nxml-apply-fontify-rule)))
944 920
945 (setq nxml-last-fontify-end (point))) 921 )
946 922
947 ;; Since we did the fontification internally, tell font-lock to not 923 ;; Since we did the fontification internally, tell font-lock to not
948 ;; do anything itself. 924 ;; do anything itself.
diff --git a/lisp/nxml/nxml-rap.el b/lisp/nxml/nxml-rap.el
index 5bc4d74456b..ac4e9ac4cd9 100644
--- a/lisp/nxml/nxml-rap.el
+++ b/lisp/nxml/nxml-rap.el
@@ -69,18 +69,6 @@
69;; typical proportion of comments, CDATA sections and processing 69;; typical proportion of comments, CDATA sections and processing
70;; instructions is small relative to other things. Secondly, to scan 70;; instructions is small relative to other things. Secondly, to scan
71;; we just search for the regexp <[!?]. 71;; we just search for the regexp <[!?].
72;;
73;; One problem is unclosed comments, processing instructions and CDATA
74;; sections. Suppose, for example, we encounter a <!-- but there's no
75;; matching -->. This is not an unexpected situation if the user is
76;; creating a comment. It is not helpful to treat the whole of the
77;; file starting from the <!-- onwards as a single unclosed comment
78;; token. Instead we treat just the <!-- as a piece of not well-formed
79;; markup and continue. The problem is that if at some later stage a
80;; --> gets added to the buffer after the unclosed <!--, we will need
81;; to reparse the buffer starting from the <!--. We need to keep
82;; track of these reparse dependencies; they are called dependent
83;; regions in the code.
84 72
85;;; Code: 73;;; Code:
86 74
@@ -144,8 +132,7 @@ any 'inside' regions and at the beginning of a token."
144 (if (>= start nxml-scan-end) 132 (if (>= start nxml-scan-end)
145 nxml-scan-end 133 nxml-scan-end
146 (let ((inside-remove-start start) 134 (let ((inside-remove-start start)
147 xmltok-errors 135 xmltok-errors)
148 xmltok-dependent-regions)
149 (while (or (when (xmltok-forward-special (min end nxml-scan-end)) 136 (while (or (when (xmltok-forward-special (min end nxml-scan-end))
150 (when (memq xmltok-type 137 (when (memq xmltok-type
151 '(comment 138 '(comment
@@ -169,9 +156,7 @@ any 'inside' regions and at the beginning of a token."
169 (when inside-end 156 (when inside-end
170 (setq end inside-end) 157 (setq end inside-end)
171 t)))) 158 t))))
172 (nxml-clear-inside inside-remove-start end) 159 (nxml-clear-inside inside-remove-start end))
173 (nxml-clear-dependent-regions start end)
174 (nxml-mark-parse-dependent-regions))
175 (when (> end nxml-scan-end) 160 (when (> end nxml-scan-end)
176 (set-marker nxml-scan-end end)) 161 (set-marker nxml-scan-end end))
177 end)) 162 end))
@@ -182,63 +167,14 @@ any 'inside' regions and at the beginning of a token."
182(defun nxml-scan-prolog () 167(defun nxml-scan-prolog ()
183 (goto-char (point-min)) 168 (goto-char (point-min))
184 (let (xmltok-dtd 169 (let (xmltok-dtd
185 xmltok-errors 170 xmltok-errors)
186 xmltok-dependent-regions)
187 (setq nxml-prolog-regions (xmltok-forward-prolog)) 171 (setq nxml-prolog-regions (xmltok-forward-prolog))
188 (setq nxml-prolog-end (point)) 172 (setq nxml-prolog-end (point))
189 (nxml-clear-inside (point-min) nxml-prolog-end) 173 (nxml-clear-inside (point-min) nxml-prolog-end))
190 (nxml-clear-dependent-regions (point-min) nxml-prolog-end)
191 (nxml-mark-parse-dependent-regions))
192 (when (< nxml-scan-end nxml-prolog-end) 174 (when (< nxml-scan-end nxml-prolog-end)
193 (set-marker nxml-scan-end nxml-prolog-end))) 175 (set-marker nxml-scan-end nxml-prolog-end)))
194 176
195 177
196;;; Dependent regions
197
198(defun nxml-adjust-start-for-dependent-regions (start end pre-change-length)
199 (let ((overlays (overlays-in (1- start) start))
200 (adjusted-start start))
201 (while overlays
202 (let* ((overlay (car overlays))
203 (ostart (overlay-start overlay)))
204 (when (and (eq (overlay-get overlay 'category) 'nxml-dependent)
205 (< ostart adjusted-start))
206 (let ((funargs (overlay-get overlay 'nxml-funargs)))
207 (when (apply (car funargs)
208 (append (list start
209 end
210 pre-change-length
211 ostart
212 (overlay-end overlay))
213 (cdr funargs)))
214 (setq adjusted-start ostart)))))
215 (setq overlays (cdr overlays)))
216 adjusted-start))
217
218(defun nxml-mark-parse-dependent-regions ()
219 (while xmltok-dependent-regions
220 (apply 'nxml-mark-parse-dependent-region
221 (car xmltok-dependent-regions))
222 (setq xmltok-dependent-regions
223 (cdr xmltok-dependent-regions))))
224
225(defun nxml-mark-parse-dependent-region (fun start end &rest args)
226 (let ((overlay (make-overlay start end nil t t)))
227 (overlay-put overlay 'category 'nxml-dependent)
228 (overlay-put overlay 'nxml-funargs (cons fun args))))
229
230(put 'nxml-dependent 'evaporate t)
231
232(defun nxml-clear-dependent-regions (start end)
233 (let ((overlays (overlays-in start end)))
234 (while overlays
235 (let* ((overlay (car overlays))
236 (category (overlay-get overlay 'category)))
237 (when (and (eq category 'nxml-dependent)
238 (<= start (overlay-start overlay)))
239 (delete-overlay overlay)))
240 (setq overlays (cdr overlays)))))
241
242;;; Random access parsing 178;;; Random access parsing
243 179
244(defun nxml-token-after () 180(defun nxml-token-after ()
@@ -286,17 +222,14 @@ Sets variables like `nxml-token-after'."
286 (point))) 222 (point)))
287 223
288(defun nxml-tokenize-forward () 224(defun nxml-tokenize-forward ()
289 (let (xmltok-dependent-regions 225 (let (xmltok-errors)
290 xmltok-errors)
291 (when (and (xmltok-forward) 226 (when (and (xmltok-forward)
292 (> (point) nxml-scan-end)) 227 (> (point) nxml-scan-end))
293 (cond ((memq xmltok-type '(comment 228 (cond ((memq xmltok-type '(comment
294 cdata-section 229 cdata-section
295 processing-instruction)) 230 processing-instruction))
296 (with-silent-modifications 231 (with-silent-modifications
297 (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))) 232 (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))))
298 (xmltok-dependent-regions
299 (nxml-mark-parse-dependent-regions)))
300 (set-marker nxml-scan-end (point))) 233 (set-marker nxml-scan-end (point)))
301 xmltok-type)) 234 xmltok-type))
302 235
@@ -304,7 +237,7 @@ Sets variables like `nxml-token-after'."
304 "Move point backwards outside any 'inside' regions or tags. 237 "Move point backwards outside any 'inside' regions or tags.
305Point will not move past `nxml-prolog-end'. 238Point will not move past `nxml-prolog-end'.
306Point will either be at BOUND or a '<' character starting a tag 239Point will either be at BOUND or a '<' character starting a tag
307outside any 'inside' regions. Ignores dependent regions. 240outside any 'inside' regions.
308As a precondition, point must be >= BOUND." 241As a precondition, point must be >= BOUND."
309 (nxml-move-outside-backwards) 242 (nxml-move-outside-backwards)
310 (when (not (equal (char-after) ?<)) 243 (when (not (equal (char-after) ?<))
@@ -331,8 +264,7 @@ Leave point unmoved if it is not inside anything special."
331 (when (< nxml-scan-end pos) 264 (when (< nxml-scan-end pos)
332 (save-excursion 265 (save-excursion
333 (goto-char nxml-scan-end) 266 (goto-char nxml-scan-end)
334 (let (xmltok-errors 267 (let (xmltok-errors)
335 xmltok-dependent-regions)
336 (while (when (xmltok-forward-special pos) 268 (while (when (xmltok-forward-special pos)
337 (when (memq xmltok-type 269 (when (memq xmltok-type
338 '(comment 270 '(comment
@@ -346,8 +278,6 @@ Leave point unmoved if it is not inside anything special."
346 t 278 t
347 (setq pos (point)) 279 (setq pos (point))
348 nil))) 280 nil)))
349 (nxml-clear-dependent-regions nxml-scan-end pos)
350 (nxml-mark-parse-dependent-regions)
351 (set-marker nxml-scan-end pos)))))) 281 (set-marker nxml-scan-end pos))))))
352 282
353;;; Element scanning 283;;; Element scanning
diff --git a/lisp/nxml/rng-valid.el b/lisp/nxml/rng-valid.el
index e1140980813..fb8bd037bdc 100644
--- a/lisp/nxml/rng-valid.el
+++ b/lisp/nxml/rng-valid.el
@@ -530,7 +530,6 @@ Return t if there is work to do, nil otherwise."
530 xmltok-replacement 530 xmltok-replacement
531 xmltok-attributes 531 xmltok-attributes
532 xmltok-namespace-attributes 532 xmltok-namespace-attributes
533 xmltok-dependent-regions
534 xmltok-errors) 533 xmltok-errors)
535 (when (= (point) 1) 534 (when (= (point) 1)
536 (let ((regions (xmltok-forward-prolog))) 535 (let ((regions (xmltok-forward-prolog)))
@@ -566,7 +565,6 @@ Return t if there is work to do, nil otherwise."
566 ;; do this before setting rng-validate-up-to-date-end 565 ;; do this before setting rng-validate-up-to-date-end
567 ;; in case we get a quit 566 ;; in case we get a quit
568 (rng-mark-xmltok-errors) 567 (rng-mark-xmltok-errors)
569 (rng-mark-xmltok-dependent-regions)
570 (setq rng-validate-up-to-date-end 568 (setq rng-validate-up-to-date-end
571 (marker-position rng-conditional-up-to-date-end)) 569 (marker-position rng-conditional-up-to-date-end))
572 (rng-clear-conditional-region) 570 (rng-clear-conditional-region)
@@ -591,7 +589,6 @@ Return t if there is work to do, nil otherwise."
591 (when (not have-remaining-chars) 589 (when (not have-remaining-chars)
592 (rng-process-end-document)) 590 (rng-process-end-document))
593 (rng-mark-xmltok-errors) 591 (rng-mark-xmltok-errors)
594 (rng-mark-xmltok-dependent-regions)
595 (setq rng-validate-up-to-date-end pos) 592 (setq rng-validate-up-to-date-end pos)
596 (when rng-conditional-up-to-date-end 593 (when rng-conditional-up-to-date-end
597 (cond ((<= rng-conditional-up-to-date-end pos) 594 (cond ((<= rng-conditional-up-to-date-end pos)
@@ -661,57 +658,9 @@ Return t if there is work to do, nil otherwise."
661 ;; if overlays left over from a previous use 658 ;; if overlays left over from a previous use
662 ;; of rng-validate-mode that ended with a change of mode 659 ;; of rng-validate-mode that ended with a change of mode
663 (when rng-error-count 660 (when rng-error-count
664 (setq rng-error-count (1- rng-error-count))))) 661 (setq rng-error-count (1- rng-error-count)))))))
665 ((and (eq category 'rng-dependent)
666 (<= beg (overlay-start overlay)))
667 (delete-overlay overlay))))
668 (setq overlays (cdr overlays)))))) 662 (setq overlays (cdr overlays))))))
669 663
670;;; Dependent regions
671
672(defun rng-mark-xmltok-dependent-regions ()
673 (while xmltok-dependent-regions
674 (apply 'rng-mark-xmltok-dependent-region
675 (car xmltok-dependent-regions))
676 (setq xmltok-dependent-regions
677 (cdr xmltok-dependent-regions))))
678
679(defun rng-mark-xmltok-dependent-region (fun start end &rest args)
680 (let ((overlay (make-overlay start end nil t t)))
681 (overlay-put overlay 'category 'rng-dependent)
682 (overlay-put overlay 'rng-funargs (cons fun args))))
683
684(put 'rng-dependent 'evaporate t)
685(put 'rng-dependent 'modification-hooks '(rng-dependent-region-changed))
686(put 'rng-dependent 'insert-behind-hooks '(rng-dependent-region-changed))
687
688(defun rng-dependent-region-changed (overlay
689 after-p
690 change-start
691 change-end
692 &optional pre-change-length)
693 (when (and after-p
694 ;; Emacs sometimes appears to call deleted overlays
695 (overlay-start overlay)
696 (let ((funargs (overlay-get overlay 'rng-funargs)))
697 (save-match-data
698 (save-excursion
699 (save-restriction
700 (widen)
701 (apply (car funargs)
702 (append (list change-start
703 change-end
704 pre-change-length
705 (overlay-start overlay)
706 (overlay-end overlay))
707 (cdr funargs))))))))
708 (rng-after-change-function (overlay-start overlay)
709 change-end
710 (+ pre-change-length
711 (- (overlay-start overlay)
712 change-start)))
713 (delete-overlay overlay)))
714
715;;; Error state 664;;; Error state
716 665
717(defun rng-mark-xmltok-errors () 666(defun rng-mark-xmltok-errors ()
diff --git a/lisp/nxml/xmltok.el b/lisp/nxml/xmltok.el
index 03f05abac43..b80335362a1 100644
--- a/lisp/nxml/xmltok.el
+++ b/lisp/nxml/xmltok.el
@@ -132,33 +132,6 @@ from referencing the entity in element content and AR is either nil,
132meaning the replacement text included a <, or a string which is the 132meaning the replacement text included a <, or a string which is the
133normalized attribute value.") 133normalized attribute value.")
134 134
135(defvar xmltok-dependent-regions nil
136 "List of descriptors of regions that a parsed token depends on.
137
138A token depends on a region if the region occurs after the token and a
139change in the region may require the token to be reparsed. This only
140happens with markup that is not well-formed. For example, if a <?
141occurs without a matching ?>, then the <? is returned as a
142not-well-formed token. However, this token is dependent on region
143from the end of the token to the end of the buffer: if this ever
144contains ?> then the buffer must be reparsed from the <?.
145
146A region descriptor is a list (FUN START END ARG ...), where FUN is a
147function to be called when the region changes, START and END are
148integers giving the start and end of the region, and ARG... are
149additional arguments to be passed to FUN. FUN will be called with 5
150arguments followed by the additional arguments if any: the position of
151the start of the changed area in the region, the position of the end
152of the changed area in the region, the length of the changed area
153before the change, the position of the start of the region, the
154position of the end of the region. FUN must return non-nil if the
155region needs reparsing. FUN will be called in a `save-excursion'
156with match-data saved.
157
158`xmltok-forward', `xmltok-forward-special' and `xmltok-forward-prolog'
159may add entries to the beginning of this list, but will not clear it.
160`xmltok-forward' and `xmltok-forward-special' will only add entries
161when returning tokens of type not-well-formed.")
162 135
163(defvar xmltok-errors nil 136(defvar xmltok-errors nil
164 "List of errors detected by `xmltok-forward' and `xmltok-forward-prolog'. 137 "List of errors detected by `xmltok-forward' and `xmltok-forward-prolog'.
@@ -176,7 +149,6 @@ indicating the position of the error.")
176 xmltok-replacement 149 xmltok-replacement
177 xmltok-attributes 150 xmltok-attributes
178 xmltok-namespace-attributes 151 xmltok-namespace-attributes
179 xmltok-dependent-regions
180 xmltok-errors) 152 xmltok-errors)
181 ,@body)) 153 ,@body))
182 154
@@ -298,14 +270,6 @@ and VALUE-END, otherwise a STRING giving the value."
298 (or end (point))) 270 (or end (point)))
299 xmltok-errors))) 271 xmltok-errors)))
300 272
301(defun xmltok-add-dependent (fun &optional start end &rest args)
302 (setq xmltok-dependent-regions
303 (cons (cons fun
304 (cons (or start xmltok-start)
305 (cons (or end (point-max))
306 args)))
307 xmltok-dependent-regions)))
308
309(defun xmltok-forward () 273(defun xmltok-forward ()
310 (setq xmltok-start (point)) 274 (setq xmltok-start (point))
311 (let* ((case-fold-search nil) 275 (let* ((case-fold-search nil)
@@ -684,14 +648,8 @@ Return the type of the token."
684 (setq xmltok-type 'empty-element)) 648 (setq xmltok-type 'empty-element))
685 ((xmltok-after-lt start cdata-section-open) 649 ((xmltok-after-lt start cdata-section-open)
686 (setq xmltok-type 650 (setq xmltok-type
687 (if (search-forward "]]>" nil t) 651 (progn (search-forward "]]>" nil 'move)
688 'cdata-section 652 'cdata-section)))
689 (xmltok-add-error "No closing ]]>")
690 (xmltok-add-dependent 'xmltok-unclosed-reparse-p
691 nil
692 nil
693 "]]>")
694 'not-well-formed)))
695 ((xmltok-after-lt start processing-instruction-question) 653 ((xmltok-after-lt start processing-instruction-question)
696 (xmltok-scan-after-processing-instruction-open)) 654 (xmltok-scan-after-processing-instruction-open))
697 ((xmltok-after-lt start comment-open) 655 ((xmltok-after-lt start comment-open)
@@ -758,68 +716,44 @@ Return the type of the token."
758;; xmltok-scan-prolog-after-processing-instruction-open 716;; xmltok-scan-prolog-after-processing-instruction-open
759;; XXX maybe should include rest of line (up to any <,>) in unclosed PI 717;; XXX maybe should include rest of line (up to any <,>) in unclosed PI
760(defun xmltok-scan-after-processing-instruction-open () 718(defun xmltok-scan-after-processing-instruction-open ()
761 (cond ((not (search-forward "?>" nil t)) 719 (search-forward "?>" nil 'move)
762 (xmltok-add-error "No closing ?>" 720 (cond ((not (save-excursion
763 xmltok-start 721 (goto-char (+ 2 xmltok-start))
764 (+ xmltok-start 2)) 722 (and (looking-at (xmltok-ncname regexp))
765 (xmltok-add-dependent 'xmltok-unclosed-reparse-p 723 (setq xmltok-name-end (match-end 0)))))
766 nil 724 (setq xmltok-name-end (+ xmltok-start 2))
767 nil 725 (xmltok-add-error "<? not followed by name"
768 "?>") 726 (+ xmltok-start 2)
769 (setq xmltok-type 'not-well-formed)) 727 (+ xmltok-start 3)))
770 (t 728 ((not (or (memq (char-after xmltok-name-end)
771 (cond ((not (save-excursion 729 '(?\n ?\t ?\r ? ))
772 (goto-char (+ 2 xmltok-start)) 730 (= xmltok-name-end (- (point) 2))))
773 (and (looking-at (xmltok-ncname regexp)) 731 (xmltok-add-error "Target not followed by whitespace"
774 (setq xmltok-name-end (match-end 0))))) 732 xmltok-name-end
775 (setq xmltok-name-end (+ xmltok-start 2)) 733 (1+ xmltok-name-end)))
776 (xmltok-add-error "<? not followed by name" 734 ((and (= xmltok-name-end (+ xmltok-start 5))
777 (+ xmltok-start 2) 735 (save-excursion
778 (+ xmltok-start 3))) 736 (goto-char (+ xmltok-start 2))
779 ((not (or (memq (char-after xmltok-name-end) 737 (let ((case-fold-search t))
780 '(?\n ?\t ?\r ? )) 738 (looking-at "xml"))))
781 (= xmltok-name-end (- (point) 2)))) 739 (xmltok-add-error "Processing instruction target is xml"
782 (xmltok-add-error "Target not followed by whitespace" 740 (+ xmltok-start 2)
783 xmltok-name-end 741 (+ xmltok-start 5))))
784 (1+ xmltok-name-end))) 742 (setq xmltok-type 'processing-instruction))
785 ((and (= xmltok-name-end (+ xmltok-start 5))
786 (save-excursion
787 (goto-char (+ xmltok-start 2))
788 (let ((case-fold-search t))
789 (looking-at "xml"))))
790 (xmltok-add-error "Processing instruction target is xml"
791 (+ xmltok-start 2)
792 (+ xmltok-start 5))))
793 (setq xmltok-type 'processing-instruction))))
794 743
795(defun xmltok-scan-after-comment-open () 744(defun xmltok-scan-after-comment-open ()
796 (setq xmltok-type 745 (let ((found-- (search-forward "--" nil 'move)))
797 (cond ((not (search-forward "--" nil t)) 746 (setq xmltok-type
798 (xmltok-add-error "No closing -->") 747 (cond ((or (eq (char-after) ?>) (not found--))
799 (xmltok-add-dependent 'xmltok-unclosed-reparse-p 748 (goto-char (1+ (point)))
800 nil 749 'comment)
801 nil 750 (t
802 ;; not --> because 751 ;; just include the <!-- in the token
803 ;; -- is not allowed 752 (goto-char (+ xmltok-start 4))
804 ;; in comments in XML 753 ;; Need do this after the goto-char because
805 "--") 754 ;; marked error should just apply to <!--
806 'not-well-formed) 755 (xmltok-add-error "First following `--' not followed by `>'")
807 ((eq (char-after) ?>) 756 'not-well-formed)))))
808 (goto-char (1+ (point)))
809 'comment)
810 (t
811 (xmltok-add-dependent
812 'xmltok-semi-closed-reparse-p
813 nil
814 (point)
815 "--"
816 2)
817 ;; just include the <!-- in the token
818 (goto-char (+ xmltok-start 4))
819 ;; Need do this after the goto-char because
820 ;; marked error should just apply to <!--
821 (xmltok-add-error "First following `--' not followed by `>'")
822 'not-well-formed))))
823 757
824(defun xmltok-scan-attributes () 758(defun xmltok-scan-attributes ()
825 (let ((recovering nil) 759 (let ((recovering nil)
@@ -1124,7 +1058,7 @@ comment, processing-instruction-left, processing-instruction-right,
1124markup-declaration-open, markup-declaration-close, 1058markup-declaration-open, markup-declaration-close,
1125internal-subset-open, internal-subset-close, hash-name, keyword, 1059internal-subset-open, internal-subset-close, hash-name, keyword,
1126literal, encoding-name. 1060literal, encoding-name.
1127Adds to `xmltok-errors' and `xmltok-dependent-regions' as appropriate." 1061Adds to `xmltok-errors' as appropriate."
1128 (let ((case-fold-search nil) 1062 (let ((case-fold-search nil)
1129 xmltok-start 1063 xmltok-start
1130 xmltok-type 1064 xmltok-type
@@ -1148,7 +1082,6 @@ Adds to `xmltok-errors' and `xmltok-dependent-regions' as appropriate."
1148 (1- xmltok-internal-subset-start) 1082 (1- xmltok-internal-subset-start)
1149 xmltok-internal-subset-start)) 1083 xmltok-internal-subset-start))
1150 (xmltok-parse-entities) 1084 (xmltok-parse-entities)
1151 ;; XXX prune dependent-regions for those entirely in prolog
1152 (nreverse xmltok-prolog-regions))) 1085 (nreverse xmltok-prolog-regions)))
1153 1086
1154(defconst xmltok-bad-xml-decl-regexp 1087(defconst xmltok-bad-xml-decl-regexp
@@ -1648,95 +1581,68 @@ If LIMIT is non-nil, then do not consider characters beyond LIMIT."
1648 (end (save-excursion 1581 (end (save-excursion
1649 (goto-char safe-end) 1582 (goto-char safe-end)
1650 (search-forward delim nil t)))) 1583 (search-forward delim nil t))))
1651 (or (cond ((not end) 1584 (cond ((or (not end)
1652 (xmltok-add-dependent 'xmltok-unclosed-reparse-p 1585 (save-excursion
1653 nil 1586 (goto-char end)
1654 nil 1587 (looking-at "[ \t\r\n>%[]")))
1655 delim) 1588 (goto-char end))
1656 nil) 1589 ((eq (1+ safe-end) end)
1657 ((save-excursion 1590 (goto-char end)
1658 (goto-char end) 1591 (xmltok-add-error (format "Missing space after %s" delim)
1659 (looking-at "[ \t\r\n>%[]")) 1592 safe-end)))
1660 (goto-char end) 1593 (setq xmltok-type 'literal)))
1661 (setq xmltok-type 'literal))
1662 ((eq (1+ safe-end) end)
1663 (goto-char end)
1664 (xmltok-add-error (format "Missing space after %s" delim)
1665 safe-end)
1666 (setq xmltok-type 'literal))
1667 (t
1668 (xmltok-add-dependent 'xmltok-semi-closed-reparse-p
1669 xmltok-start
1670 (1+ end)
1671 delim
1672 1)
1673 nil))
1674 (progn
1675 (xmltok-add-error (format "Missing closing %s" delim))
1676 (goto-char safe-end)
1677 (skip-chars-backward " \t\r\n")
1678 (setq xmltok-type 'not-well-formed)))))
1679 1594
1680(defun xmltok-scan-prolog-after-processing-instruction-open () 1595(defun xmltok-scan-prolog-after-processing-instruction-open ()
1681 (cond ((not (search-forward "?>" nil t)) 1596 (search-forward "?>" nil 'move)
1682 (xmltok-add-error "No closing ?>" 1597 (let* ((end (point))
1683 xmltok-start 1598 (target
1684 (+ xmltok-start 2)) 1599 (save-excursion
1685 (xmltok-add-dependent 'xmltok-unclosed-reparse-p 1600 (goto-char (+ xmltok-start 2))
1686 nil 1601 (and (looking-at (xmltok-ncname regexp))
1687 nil 1602 (or (memq (char-after (match-end 0))
1688 "?>") 1603 '(?\n ?\t ?\r ? ))
1689 (setq xmltok-type 'not-well-formed)) 1604 (= (match-end 0) (- end 2)))
1690 (t 1605 (match-string-no-properties 0)))))
1691 (let* ((end (point)) 1606 (cond ((not target)
1692 (target 1607 (xmltok-add-error "\
1693 (save-excursion
1694 (goto-char (+ xmltok-start 2))
1695 (and (looking-at (xmltok-ncname regexp))
1696 (or (memq (char-after (match-end 0))
1697 '(?\n ?\t ?\r ? ))
1698 (= (match-end 0) (- end 2)))
1699 (match-string-no-properties 0)))))
1700 (cond ((not target)
1701 (xmltok-add-error "\
1702Processing instruction does not start with a name" 1608Processing instruction does not start with a name"
1703 (+ xmltok-start 2) 1609 (+ xmltok-start 2)
1704 (+ xmltok-start 3))) 1610 (+ xmltok-start 3)))
1705 ((not (and (= (length target) 3) 1611 ((not (and (= (length target) 3)
1706 (let ((case-fold-search t)) 1612 (let ((case-fold-search t))
1707 (string-match "xml" target))))) 1613 (string-match "xml" target)))))
1708 ((= xmltok-start 1) 1614 ((= xmltok-start 1)
1709 (xmltok-add-error "Invalid XML declaration" 1615 (xmltok-add-error "Invalid XML declaration"
1710 xmltok-start 1616 xmltok-start
1711 (point))) 1617 (point)))
1712 ((save-excursion 1618 ((save-excursion
1713 (goto-char xmltok-start) 1619 (goto-char xmltok-start)
1714 (looking-at (xmltok-xml-declaration regexp))) 1620 (looking-at (xmltok-xml-declaration regexp)))
1715 (xmltok-add-error "XML declaration not at beginning of file" 1621 (xmltok-add-error "XML declaration not at beginning of file"
1716 xmltok-start 1622 xmltok-start
1717 (point))) 1623 (point)))
1718 (t 1624 (t
1719 (xmltok-add-error "Processing instruction has target of xml" 1625 (xmltok-add-error "Processing instruction has target of xml"
1720 (+ xmltok-start 2) 1626 (+ xmltok-start 2)
1721 (+ xmltok-start 5)))) 1627 (+ xmltok-start 5))))
1722 (xmltok-add-prolog-region 'processing-instruction-left 1628 (xmltok-add-prolog-region 'processing-instruction-left
1723 xmltok-start 1629 xmltok-start
1724 (+ xmltok-start 1630 (+ xmltok-start
1725 2 1631 2
1726 (if target 1632 (if target
1727 (length target) 1633 (length target)
1728 0))) 1634 0)))
1729 (xmltok-add-prolog-region 'processing-instruction-right 1635 (xmltok-add-prolog-region 'processing-instruction-right
1730 (if target 1636 (if target
1731 (save-excursion 1637 (save-excursion
1732 (goto-char (+ xmltok-start 1638 (goto-char (+ xmltok-start
1733 (length target) 1639 (length target)
1734 2)) 1640 2))
1735 (skip-chars-forward " \t\r\n") 1641 (skip-chars-forward " \t\r\n")
1736 (point)) 1642 (point))
1737 (+ xmltok-start 2)) 1643 (+ xmltok-start 2))
1738 (point))) 1644 (point)))
1739 (setq xmltok-type 'processing-instruction)))) 1645 (setq xmltok-type 'processing-instruction))
1740 1646
1741(defun xmltok-parse-entities () 1647(defun xmltok-parse-entities ()
1742 (let ((todo xmltok-dtd)) 1648 (let ((todo xmltok-dtd))