* nxml maintainer?
@ 2013-05-10 17:25 Stefan Monnier
2013-05-11 6:47 ` Andreas Röhler
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Monnier @ 2013-05-10 17:25 UTC (permalink / raw)
To: emacs-devel
I'd like to install the patch below, which removes a "feature" which
I find dubious: it's a lot of code just to provide a behavior which is
not clearly superior.
The behavior in question is to treat an unmatched <? as an error token
rather than to consider that the matching ?> is "somewhere after
point-max".
Stefan
=== modified file 'lisp/nxml/nxml-mode.el'
--- lisp/nxml/nxml-mode.el 2013-03-23 02:21:25 +0000
+++ lisp/nxml/nxml-mode.el 2013-05-09 22:42:47 +0000
@@ -352,11 +352,6 @@
See the function `xmltok-forward-prolog' for more information.")
(make-variable-buffer-local 'nxml-prolog-regions)
-(defvar nxml-last-fontify-end nil
- "Position where fontification last ended.
-It is nil if the buffer changed since the last fontification.")
-(make-variable-buffer-local 'nxml-last-fontify-end)
-
(defvar nxml-degraded nil
"Non-nil if currently operating in degraded mode.
Degraded mode is enabled when an internal error is encountered in the
@@ -538,7 +533,6 @@
(save-excursion
(save-restriction
(widen)
- (nxml-clear-dependent-regions (point-min) (point-max))
(setq nxml-scan-end (copy-marker (point-min) nil))
(with-silent-modifications
(nxml-clear-inside (point-min) (point-max))
@@ -583,12 +577,9 @@
;; Clean up fontification.
(save-excursion
(widen)
- (let ((inhibit-read-only t)
- (buffer-undo-list t)
- (modified (buffer-modified-p)))
+ (with-silent-modifications
(nxml-with-invisible-motion
- (remove-text-properties (point-min) (point-max) '(face)))
- (set-buffer-modified-p modified)))
+ (remove-text-properties (point-min) (point-max) '(face)))))
(remove-hook 'change-major-mode-hook 'nxml-cleanup t))
(defun nxml-degrade (context err)
@@ -638,10 +629,6 @@
For bookkeeping, call this function even when fontification is
disabled."
(let ((pre-change-end (+ start pre-change-length)))
- (setq start
- (nxml-adjust-start-for-dependent-regions start
- end
- 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
@@ -902,8 +889,7 @@
(defun nxml-extend-after-change-region (start end pre-change-length)
(unless nxml-degraded
- (setq nxml-last-fontify-end nil)
- (let ((region (nxml-with-degradation-on-error
+ (nxml-with-degradation-on-error
'nxml-extend-after-change-region
(save-excursion
(save-restriction
@@ -911,17 +897,8 @@
(save-match-data
(nxml-with-invisible-motion
(with-silent-modifications
- (nxml-extend-after-change-region1
+ (nxml-after-change1
start end pre-change-length)))))))))
- (if (consp region) region))))
-
-(defun nxml-extend-after-change-region1 (start end pre-change-length)
- (let* ((region (nxml-after-change1 start end pre-change-length))
- (font-lock-beg (car region))
- (font-lock-end (cdr region)))
-
- (nxml-extend-region)
- (cons font-lock-beg font-lock-end)))
(defun nxml-fontify-matcher (bound)
"Called as font-lock keyword matcher."
@@ -936,13 +913,12 @@
(nxml-fontify-prolog)
(goto-char nxml-prolog-end))
- (let (xmltok-dependent-regions
- xmltok-errors)
+ (let (xmltok-errors)
(while (and (nxml-tokenize-forward)
(<= (point) bound)) ; Intervals are open-ended.
(nxml-apply-fontify-rule)))
- (setq nxml-last-fontify-end (point)))
+ )
;; Since we did the fontification internally, tell font-lock to not
;; do anything itself.
=== modified file 'lisp/nxml/nxml-rap.el'
--- lisp/nxml/nxml-rap.el 2013-03-23 02:21:25 +0000
+++ lisp/nxml/nxml-rap.el 2013-05-09 22:37:06 +0000
@@ -69,18 +69,6 @@
;; typical proportion of comments, CDATA sections and processing
;; instructions is small relative to other things. Secondly, to scan
;; we just search for the regexp <[!?].
-;;
-;; One problem is unclosed comments, processing instructions and CDATA
-;; sections. Suppose, for example, we encounter a <!-- but there's no
-;; matching -->. This is not an unexpected situation if the user is
-;; creating a comment. It is not helpful to treat the whole of the
-;; file starting from the <!-- onwards as a single unclosed comment
-;; token. Instead we treat just the <!-- as a piece of not well-formed
-;; markup and continue. The problem is that if at some later stage a
-;; --> gets added to the buffer after the unclosed <!--, we will need
-;; to reparse the buffer starting from the <!--. We need to keep
-;; track of these reparse dependencies; they are called dependent
-;; regions in the code.
;;; Code:
@@ -144,8 +132,7 @@
(if (>= start nxml-scan-end)
nxml-scan-end
(let ((inside-remove-start start)
- xmltok-errors
- xmltok-dependent-regions)
+ xmltok-errors)
(while (or (when (xmltok-forward-special (min end nxml-scan-end))
(when (memq xmltok-type
'(comment
@@ -169,9 +156,7 @@
(when inside-end
(setq end inside-end)
t))))
- (nxml-clear-inside inside-remove-start end)
- (nxml-clear-dependent-regions start end)
- (nxml-mark-parse-dependent-regions))
+ (nxml-clear-inside inside-remove-start end))
(when (> end nxml-scan-end)
(set-marker nxml-scan-end end))
end))
@@ -182,63 +167,14 @@
(defun nxml-scan-prolog ()
(goto-char (point-min))
(let (xmltok-dtd
- xmltok-errors
- xmltok-dependent-regions)
+ xmltok-errors)
(setq nxml-prolog-regions (xmltok-forward-prolog))
(setq nxml-prolog-end (point))
- (nxml-clear-inside (point-min) nxml-prolog-end)
- (nxml-clear-dependent-regions (point-min) nxml-prolog-end)
- (nxml-mark-parse-dependent-regions))
+ (nxml-clear-inside (point-min) nxml-prolog-end))
(when (< nxml-scan-end nxml-prolog-end)
(set-marker nxml-scan-end nxml-prolog-end)))
-;;; Dependent regions
-
-(defun nxml-adjust-start-for-dependent-regions (start end pre-change-length)
- (let ((overlays (overlays-in (1- start) start))
- (adjusted-start start))
- (while overlays
- (let* ((overlay (car overlays))
- (ostart (overlay-start overlay)))
- (when (and (eq (overlay-get overlay 'category) 'nxml-dependent)
- (< ostart adjusted-start))
- (let ((funargs (overlay-get overlay 'nxml-funargs)))
- (when (apply (car funargs)
- (append (list start
- end
- pre-change-length
- ostart
- (overlay-end overlay))
- (cdr funargs)))
- (setq adjusted-start ostart)))))
- (setq overlays (cdr overlays)))
- adjusted-start))
-
-(defun nxml-mark-parse-dependent-regions ()
- (while xmltok-dependent-regions
- (apply 'nxml-mark-parse-dependent-region
- (car xmltok-dependent-regions))
- (setq xmltok-dependent-regions
- (cdr xmltok-dependent-regions))))
-
-(defun nxml-mark-parse-dependent-region (fun start end &rest args)
- (let ((overlay (make-overlay start end nil t t)))
- (overlay-put overlay 'category 'nxml-dependent)
- (overlay-put overlay 'nxml-funargs (cons fun args))))
-
-(put 'nxml-dependent 'evaporate t)
-
-(defun nxml-clear-dependent-regions (start end)
- (let ((overlays (overlays-in start end)))
- (while overlays
- (let* ((overlay (car overlays))
- (category (overlay-get overlay 'category)))
- (when (and (eq category 'nxml-dependent)
- (<= start (overlay-start overlay)))
- (delete-overlay overlay)))
- (setq overlays (cdr overlays)))))
-
;;; Random access parsing
(defun nxml-token-after ()
@@ -286,17 +222,14 @@
(point)))
(defun nxml-tokenize-forward ()
- (let (xmltok-dependent-regions
- xmltok-errors)
+ (let (xmltok-errors)
(when (and (xmltok-forward)
(> (point) nxml-scan-end))
(cond ((memq xmltok-type '(comment
cdata-section
processing-instruction))
(with-silent-modifications
- (nxml-set-inside (1+ xmltok-start) (point) xmltok-type)))
- (xmltok-dependent-regions
- (nxml-mark-parse-dependent-regions)))
+ (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))))
(set-marker nxml-scan-end (point)))
xmltok-type))
@@ -304,7 +237,7 @@
"Move point backwards outside any 'inside' regions or tags.
Point will not move past `nxml-prolog-end'.
Point will either be at BOUND or a '<' character starting a tag
-outside any 'inside' regions. Ignores dependent regions.
+outside any 'inside' regions.
As a precondition, point must be >= BOUND."
(nxml-move-outside-backwards)
(when (not (equal (char-after) ?<))
@@ -331,8 +264,7 @@
(when (< nxml-scan-end pos)
(save-excursion
(goto-char nxml-scan-end)
- (let (xmltok-errors
- xmltok-dependent-regions)
+ (let (xmltok-errors)
(while (when (xmltok-forward-special pos)
(when (memq xmltok-type
'(comment
@@ -346,8 +278,6 @@
t
(setq pos (point))
nil)))
- (nxml-clear-dependent-regions nxml-scan-end pos)
- (nxml-mark-parse-dependent-regions)
(set-marker nxml-scan-end pos))))))
;;; Element scanning
=== modified file 'lisp/nxml/rng-valid.el'
--- lisp/nxml/rng-valid.el 2013-03-24 06:42:25 +0000
+++ lisp/nxml/rng-valid.el 2013-05-09 22:32:04 +0000
@@ -530,7 +530,6 @@
xmltok-replacement
xmltok-attributes
xmltok-namespace-attributes
- xmltok-dependent-regions
xmltok-errors)
(when (= (point) 1)
(let ((regions (xmltok-forward-prolog)))
@@ -566,7 +565,6 @@
;; do this before setting rng-validate-up-to-date-end
;; in case we get a quit
(rng-mark-xmltok-errors)
- (rng-mark-xmltok-dependent-regions)
(setq rng-validate-up-to-date-end
(marker-position rng-conditional-up-to-date-end))
(rng-clear-conditional-region)
@@ -591,7 +589,6 @@
(when (not have-remaining-chars)
(rng-process-end-document))
(rng-mark-xmltok-errors)
- (rng-mark-xmltok-dependent-regions)
(setq rng-validate-up-to-date-end pos)
(when rng-conditional-up-to-date-end
(cond ((<= rng-conditional-up-to-date-end pos)
@@ -661,57 +658,9 @@
;; if overlays left over from a previous use
;; of rng-validate-mode that ended with a change of mode
(when rng-error-count
- (setq rng-error-count (1- rng-error-count)))))
- ((and (eq category 'rng-dependent)
- (<= beg (overlay-start overlay)))
- (delete-overlay overlay))))
+ (setq rng-error-count (1- rng-error-count)))))))
(setq overlays (cdr overlays))))))
-;;; Dependent regions
-
-(defun rng-mark-xmltok-dependent-regions ()
- (while xmltok-dependent-regions
- (apply 'rng-mark-xmltok-dependent-region
- (car xmltok-dependent-regions))
- (setq xmltok-dependent-regions
- (cdr xmltok-dependent-regions))))
-
-(defun rng-mark-xmltok-dependent-region (fun start end &rest args)
- (let ((overlay (make-overlay start end nil t t)))
- (overlay-put overlay 'category 'rng-dependent)
- (overlay-put overlay 'rng-funargs (cons fun args))))
-
-(put 'rng-dependent 'evaporate t)
-(put 'rng-dependent 'modification-hooks '(rng-dependent-region-changed))
-(put 'rng-dependent 'insert-behind-hooks '(rng-dependent-region-changed))
-
-(defun rng-dependent-region-changed (overlay
- after-p
- change-start
- change-end
- &optional pre-change-length)
- (when (and after-p
- ;; Emacs sometimes appears to call deleted overlays
- (overlay-start overlay)
- (let ((funargs (overlay-get overlay 'rng-funargs)))
- (save-match-data
- (save-excursion
- (save-restriction
- (widen)
- (apply (car funargs)
- (append (list change-start
- change-end
- pre-change-length
- (overlay-start overlay)
- (overlay-end overlay))
- (cdr funargs))))))))
- (rng-after-change-function (overlay-start overlay)
- change-end
- (+ pre-change-length
- (- (overlay-start overlay)
- change-start)))
- (delete-overlay overlay)))
-
;;; Error state
(defun rng-mark-xmltok-errors ()
=== modified file 'lisp/nxml/xmltok.el'
--- lisp/nxml/xmltok.el 2013-01-01 09:11:05 +0000
+++ lisp/nxml/xmltok.el 2013-05-09 22:36:32 +0000
@@ -132,33 +132,6 @@
meaning the replacement text included a <, or a string which is the
normalized attribute value.")
-(defvar xmltok-dependent-regions nil
- "List of descriptors of regions that a parsed token depends on.
-
-A token depends on a region if the region occurs after the token and a
-change in the region may require the token to be reparsed. This only
-happens with markup that is not well-formed. For example, if a <?
-occurs without a matching ?>, then the <? is returned as a
-not-well-formed token. However, this token is dependent on region
-from the end of the token to the end of the buffer: if this ever
-contains ?> then the buffer must be reparsed from the <?.
-
-A region descriptor is a list (FUN START END ARG ...), where FUN is a
-function to be called when the region changes, START and END are
-integers giving the start and end of the region, and ARG... are
-additional arguments to be passed to FUN. FUN will be called with 5
-arguments followed by the additional arguments if any: the position of
-the start of the changed area in the region, the position of the end
-of the changed area in the region, the length of the changed area
-before the change, the position of the start of the region, the
-position of the end of the region. FUN must return non-nil if the
-region needs reparsing. FUN will be called in a `save-excursion'
-with match-data saved.
-
-`xmltok-forward', `xmltok-forward-special' and `xmltok-forward-prolog'
-may add entries to the beginning of this list, but will not clear it.
-`xmltok-forward' and `xmltok-forward-special' will only add entries
-when returning tokens of type not-well-formed.")
(defvar xmltok-errors nil
"List of errors detected by `xmltok-forward' and `xmltok-forward-prolog'.
@@ -176,7 +149,6 @@
xmltok-replacement
xmltok-attributes
xmltok-namespace-attributes
- xmltok-dependent-regions
xmltok-errors)
,@body))
@@ -298,14 +270,6 @@
(or end (point)))
xmltok-errors)))
-(defun xmltok-add-dependent (fun &optional start end &rest args)
- (setq xmltok-dependent-regions
- (cons (cons fun
- (cons (or start xmltok-start)
- (cons (or end (point-max))
- args)))
- xmltok-dependent-regions)))
-
(defun xmltok-forward ()
(setq xmltok-start (point))
(let* ((case-fold-search nil)
@@ -684,14 +648,8 @@
(setq xmltok-type 'empty-element))
((xmltok-after-lt start cdata-section-open)
(setq xmltok-type
- (if (search-forward "]]>" nil t)
- 'cdata-section
- (xmltok-add-error "No closing ]]>")
- (xmltok-add-dependent 'xmltok-unclosed-reparse-p
- nil
- nil
- "]]>")
- 'not-well-formed)))
+ (progn (search-forward "]]>" nil 'move)
+ 'cdata-section)))
((xmltok-after-lt start processing-instruction-question)
(xmltok-scan-after-processing-instruction-open))
((xmltok-after-lt start comment-open)
@@ -758,16 +716,7 @@
;; xmltok-scan-prolog-after-processing-instruction-open
;; XXX maybe should include rest of line (up to any <,>) in unclosed PI
(defun xmltok-scan-after-processing-instruction-open ()
- (cond ((not (search-forward "?>" nil t))
- (xmltok-add-error "No closing ?>"
- xmltok-start
- (+ xmltok-start 2))
- (xmltok-add-dependent 'xmltok-unclosed-reparse-p
- nil
- nil
- "?>")
- (setq xmltok-type 'not-well-formed))
- (t
+ (search-forward "?>" nil 'move)
(cond ((not (save-excursion
(goto-char (+ 2 xmltok-start))
(and (looking-at (xmltok-ncname regexp))
@@ -790,36 +739,21 @@
(xmltok-add-error "Processing instruction target is xml"
(+ xmltok-start 2)
(+ xmltok-start 5))))
- (setq xmltok-type 'processing-instruction))))
+ (setq xmltok-type 'processing-instruction))
(defun xmltok-scan-after-comment-open ()
+ (let ((found-- (search-forward "--" nil 'move)))
(setq xmltok-type
- (cond ((not (search-forward "--" nil t))
- (xmltok-add-error "No closing -->")
- (xmltok-add-dependent 'xmltok-unclosed-reparse-p
- nil
- nil
- ;; not --> because
- ;; -- is not allowed
- ;; in comments in XML
- "--")
- 'not-well-formed)
- ((eq (char-after) ?>)
+ (cond ((or (eq (char-after) ?>) (not found--))
(goto-char (1+ (point)))
'comment)
(t
- (xmltok-add-dependent
- 'xmltok-semi-closed-reparse-p
- nil
- (point)
- "--"
- 2)
;; just include the <!-- in the token
(goto-char (+ xmltok-start 4))
;; Need do this after the goto-char because
;; marked error should just apply to <!--
(xmltok-add-error "First following `--' not followed by `>'")
- 'not-well-formed))))
+ 'not-well-formed)))))
(defun xmltok-scan-attributes ()
(let ((recovering nil)
@@ -1124,7 +1058,7 @@
markup-declaration-open, markup-declaration-close,
internal-subset-open, internal-subset-close, hash-name, keyword,
literal, encoding-name.
-Adds to `xmltok-errors' and `xmltok-dependent-regions' as appropriate."
+Adds to `xmltok-errors' as appropriate."
(let ((case-fold-search nil)
xmltok-start
xmltok-type
@@ -1148,7 +1082,6 @@
(1- xmltok-internal-subset-start)
xmltok-internal-subset-start))
(xmltok-parse-entities)
- ;; XXX prune dependent-regions for those entirely in prolog
(nreverse xmltok-prolog-regions)))
(defconst xmltok-bad-xml-decl-regexp
@@ -1648,46 +1581,19 @@
(end (save-excursion
(goto-char safe-end)
(search-forward delim nil t))))
- (or (cond ((not end)
- (xmltok-add-dependent 'xmltok-unclosed-reparse-p
- nil
- nil
- delim)
- nil)
- ((save-excursion
- (goto-char end)
- (looking-at "[ \t\r\n>%[]"))
+ (cond ((or (not end)
+ (save-excursion
(goto-char end)
- (setq xmltok-type 'literal))
+ (looking-at "[ \t\r\n>%[]")))
+ (goto-char end))
((eq (1+ safe-end) end)
(goto-char end)
(xmltok-add-error (format "Missing space after %s" delim)
- safe-end)
- (setq xmltok-type 'literal))
- (t
- (xmltok-add-dependent 'xmltok-semi-closed-reparse-p
- xmltok-start
- (1+ end)
- delim
- 1)
- nil))
- (progn
- (xmltok-add-error (format "Missing closing %s" delim))
- (goto-char safe-end)
- (skip-chars-backward " \t\r\n")
- (setq xmltok-type 'not-well-formed)))))
+ safe-end)))
+ (setq xmltok-type 'literal)))
(defun xmltok-scan-prolog-after-processing-instruction-open ()
- (cond ((not (search-forward "?>" nil t))
- (xmltok-add-error "No closing ?>"
- xmltok-start
- (+ xmltok-start 2))
- (xmltok-add-dependent 'xmltok-unclosed-reparse-p
- nil
- nil
- "?>")
- (setq xmltok-type 'not-well-formed))
- (t
+ (search-forward "?>" nil 'move)
(let* ((end (point))
(target
(save-excursion
@@ -1736,7 +1642,7 @@
(point))
(+ xmltok-start 2))
(point)))
- (setq xmltok-type 'processing-instruction))))
+ (setq xmltok-type 'processing-instruction))
(defun xmltok-parse-entities ()
(let ((todo xmltok-dtd))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: nxml maintainer?
2013-05-10 17:25 nxml maintainer? Stefan Monnier
@ 2013-05-11 6:47 ` Andreas Röhler
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Röhler @ 2013-05-11 6:47 UTC (permalink / raw)
To: emacs-devel; +Cc: Stefan Monnier
Am 10.05.2013 19:25, schrieb Stefan Monnier:
> I'd like to install the patch below, which removes a "feature" which
> I find dubious: it's a lot of code just to provide a behavior which is
> not clearly superior.
>
> The behavior in question is to treat an unmatched <? as an error token
> rather than to consider that the matching ?> is "somewhere after
> point-max".
>
>
> Stefan
>
>
> === modified file 'lisp/nxml/nxml-mode.el'
> --- lisp/nxml/nxml-mode.el 2013-03-23 02:21:25 +0000
> +++ lisp/nxml/nxml-mode.el 2013-05-09 22:42:47 +0000
> @@ -352,11 +352,6 @@
> See the function `xmltok-forward-prolog' for more information.")
> (make-variable-buffer-local 'nxml-prolog-regions)
>
> -(defvar nxml-last-fontify-end nil
> - "Position where fontification last ended.
> -It is nil if the buffer changed since the last fontification.")
> -(make-variable-buffer-local 'nxml-last-fontify-end)
> -
> (defvar nxml-degraded nil
> "Non-nil if currently operating in degraded mode.
> Degraded mode is enabled when an internal error is encountered in the
> @@ -538,7 +533,6 @@
> (save-excursion
> (save-restriction
> (widen)
> - (nxml-clear-dependent-regions (point-min) (point-max))
> (setq nxml-scan-end (copy-marker (point-min) nil))
> (with-silent-modifications
> (nxml-clear-inside (point-min) (point-max))
> @@ -583,12 +577,9 @@
> ;; Clean up fontification.
> (save-excursion
> (widen)
> - (let ((inhibit-read-only t)
> - (buffer-undo-list t)
> - (modified (buffer-modified-p)))
> + (with-silent-modifications
> (nxml-with-invisible-motion
> - (remove-text-properties (point-min) (point-max) '(face)))
> - (set-buffer-modified-p modified)))
> + (remove-text-properties (point-min) (point-max) '(face)))))
> (remove-hook 'change-major-mode-hook 'nxml-cleanup t))
>
> (defun nxml-degrade (context err)
> @@ -638,10 +629,6 @@
> For bookkeeping, call this function even when fontification is
> disabled."
> (let ((pre-change-end (+ start pre-change-length)))
> - (setq start
> - (nxml-adjust-start-for-dependent-regions start
> - end
> - 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
> @@ -902,8 +889,7 @@
>
> (defun nxml-extend-after-change-region (start end pre-change-length)
> (unless nxml-degraded
> - (setq nxml-last-fontify-end nil)
> - (let ((region (nxml-with-degradation-on-error
> + (nxml-with-degradation-on-error
> 'nxml-extend-after-change-region
> (save-excursion
> (save-restriction
> @@ -911,17 +897,8 @@
> (save-match-data
> (nxml-with-invisible-motion
> (with-silent-modifications
> - (nxml-extend-after-change-region1
> + (nxml-after-change1
> start end pre-change-length)))))))))
> - (if (consp region) region))))
> -
> -(defun nxml-extend-after-change-region1 (start end pre-change-length)
> - (let* ((region (nxml-after-change1 start end pre-change-length))
> - (font-lock-beg (car region))
> - (font-lock-end (cdr region)))
> -
> - (nxml-extend-region)
> - (cons font-lock-beg font-lock-end)))
>
> (defun nxml-fontify-matcher (bound)
> "Called as font-lock keyword matcher."
> @@ -936,13 +913,12 @@
> (nxml-fontify-prolog)
> (goto-char nxml-prolog-end))
>
> - (let (xmltok-dependent-regions
> - xmltok-errors)
> + (let (xmltok-errors)
> (while (and (nxml-tokenize-forward)
> (<= (point) bound)) ; Intervals are open-ended.
> (nxml-apply-fontify-rule)))
>
> - (setq nxml-last-fontify-end (point)))
> + )
>
> ;; Since we did the fontification internally, tell font-lock to not
> ;; do anything itself.
>
> === modified file 'lisp/nxml/nxml-rap.el'
> --- lisp/nxml/nxml-rap.el 2013-03-23 02:21:25 +0000
> +++ lisp/nxml/nxml-rap.el 2013-05-09 22:37:06 +0000
> @@ -69,18 +69,6 @@
> ;; typical proportion of comments, CDATA sections and processing
> ;; instructions is small relative to other things. Secondly, to scan
> ;; we just search for the regexp <[!?].
> -;;
> -;; One problem is unclosed comments, processing instructions and CDATA
> -;; sections. Suppose, for example, we encounter a <!-- but there's no
> -;; matching -->. This is not an unexpected situation if the user is
> -;; creating a comment. It is not helpful to treat the whole of the
> -;; file starting from the <!-- onwards as a single unclosed comment
> -;; token. Instead we treat just the <!-- as a piece of not well-formed
> -;; markup and continue. The problem is that if at some later stage a
> -;; --> gets added to the buffer after the unclosed <!--, we will need
> -;; to reparse the buffer starting from the <!--. We need to keep
> -;; track of these reparse dependencies; they are called dependent
> -;; regions in the code.
>
> ;;; Code:
>
> @@ -144,8 +132,7 @@
> (if (>= start nxml-scan-end)
> nxml-scan-end
> (let ((inside-remove-start start)
> - xmltok-errors
> - xmltok-dependent-regions)
> + xmltok-errors)
> (while (or (when (xmltok-forward-special (min end nxml-scan-end))
> (when (memq xmltok-type
> '(comment
> @@ -169,9 +156,7 @@
> (when inside-end
> (setq end inside-end)
> t))))
> - (nxml-clear-inside inside-remove-start end)
> - (nxml-clear-dependent-regions start end)
> - (nxml-mark-parse-dependent-regions))
> + (nxml-clear-inside inside-remove-start end))
> (when (> end nxml-scan-end)
> (set-marker nxml-scan-end end))
> end))
> @@ -182,63 +167,14 @@
> (defun nxml-scan-prolog ()
> (goto-char (point-min))
> (let (xmltok-dtd
> - xmltok-errors
> - xmltok-dependent-regions)
> + xmltok-errors)
> (setq nxml-prolog-regions (xmltok-forward-prolog))
> (setq nxml-prolog-end (point))
> - (nxml-clear-inside (point-min) nxml-prolog-end)
> - (nxml-clear-dependent-regions (point-min) nxml-prolog-end)
> - (nxml-mark-parse-dependent-regions))
> + (nxml-clear-inside (point-min) nxml-prolog-end))
> (when (< nxml-scan-end nxml-prolog-end)
> (set-marker nxml-scan-end nxml-prolog-end)))
>
>
> -;;; Dependent regions
> -
> -(defun nxml-adjust-start-for-dependent-regions (start end pre-change-length)
> - (let ((overlays (overlays-in (1- start) start))
> - (adjusted-start start))
> - (while overlays
> - (let* ((overlay (car overlays))
> - (ostart (overlay-start overlay)))
> - (when (and (eq (overlay-get overlay 'category) 'nxml-dependent)
> - (< ostart adjusted-start))
> - (let ((funargs (overlay-get overlay 'nxml-funargs)))
> - (when (apply (car funargs)
> - (append (list start
> - end
> - pre-change-length
> - ostart
> - (overlay-end overlay))
> - (cdr funargs)))
> - (setq adjusted-start ostart)))))
> - (setq overlays (cdr overlays)))
> - adjusted-start))
> -
> -(defun nxml-mark-parse-dependent-regions ()
> - (while xmltok-dependent-regions
> - (apply 'nxml-mark-parse-dependent-region
> - (car xmltok-dependent-regions))
> - (setq xmltok-dependent-regions
> - (cdr xmltok-dependent-regions))))
> -
> -(defun nxml-mark-parse-dependent-region (fun start end &rest args)
> - (let ((overlay (make-overlay start end nil t t)))
> - (overlay-put overlay 'category 'nxml-dependent)
> - (overlay-put overlay 'nxml-funargs (cons fun args))))
> -
> -(put 'nxml-dependent 'evaporate t)
> -
> -(defun nxml-clear-dependent-regions (start end)
> - (let ((overlays (overlays-in start end)))
> - (while overlays
> - (let* ((overlay (car overlays))
> - (category (overlay-get overlay 'category)))
> - (when (and (eq category 'nxml-dependent)
> - (<= start (overlay-start overlay)))
> - (delete-overlay overlay)))
> - (setq overlays (cdr overlays)))))
> -
> ;;; Random access parsing
>
> (defun nxml-token-after ()
> @@ -286,17 +222,14 @@
> (point)))
>
> (defun nxml-tokenize-forward ()
> - (let (xmltok-dependent-regions
> - xmltok-errors)
> + (let (xmltok-errors)
> (when (and (xmltok-forward)
> (> (point) nxml-scan-end))
> (cond ((memq xmltok-type '(comment
> cdata-section
> processing-instruction))
> (with-silent-modifications
> - (nxml-set-inside (1+ xmltok-start) (point) xmltok-type)))
> - (xmltok-dependent-regions
> - (nxml-mark-parse-dependent-regions)))
> + (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))))
> (set-marker nxml-scan-end (point)))
> xmltok-type))
>
> @@ -304,7 +237,7 @@
> "Move point backwards outside any 'inside' regions or tags.
> Point will not move past `nxml-prolog-end'.
> Point will either be at BOUND or a '<' character starting a tag
> -outside any 'inside' regions. Ignores dependent regions.
> +outside any 'inside' regions.
> As a precondition, point must be >= BOUND."
> (nxml-move-outside-backwards)
> (when (not (equal (char-after) ?<))
> @@ -331,8 +264,7 @@
> (when (< nxml-scan-end pos)
> (save-excursion
> (goto-char nxml-scan-end)
> - (let (xmltok-errors
> - xmltok-dependent-regions)
> + (let (xmltok-errors)
> (while (when (xmltok-forward-special pos)
> (when (memq xmltok-type
> '(comment
> @@ -346,8 +278,6 @@
> t
> (setq pos (point))
> nil)))
> - (nxml-clear-dependent-regions nxml-scan-end pos)
> - (nxml-mark-parse-dependent-regions)
> (set-marker nxml-scan-end pos))))))
>
> ;;; Element scanning
>
> === modified file 'lisp/nxml/rng-valid.el'
> --- lisp/nxml/rng-valid.el 2013-03-24 06:42:25 +0000
> +++ lisp/nxml/rng-valid.el 2013-05-09 22:32:04 +0000
> @@ -530,7 +530,6 @@
> xmltok-replacement
> xmltok-attributes
> xmltok-namespace-attributes
> - xmltok-dependent-regions
> xmltok-errors)
> (when (= (point) 1)
> (let ((regions (xmltok-forward-prolog)))
> @@ -566,7 +565,6 @@
> ;; do this before setting rng-validate-up-to-date-end
> ;; in case we get a quit
> (rng-mark-xmltok-errors)
> - (rng-mark-xmltok-dependent-regions)
> (setq rng-validate-up-to-date-end
> (marker-position rng-conditional-up-to-date-end))
> (rng-clear-conditional-region)
> @@ -591,7 +589,6 @@
> (when (not have-remaining-chars)
> (rng-process-end-document))
> (rng-mark-xmltok-errors)
> - (rng-mark-xmltok-dependent-regions)
> (setq rng-validate-up-to-date-end pos)
> (when rng-conditional-up-to-date-end
> (cond ((<= rng-conditional-up-to-date-end pos)
> @@ -661,57 +658,9 @@
> ;; if overlays left over from a previous use
> ;; of rng-validate-mode that ended with a change of mode
> (when rng-error-count
> - (setq rng-error-count (1- rng-error-count)))))
> - ((and (eq category 'rng-dependent)
> - (<= beg (overlay-start overlay)))
> - (delete-overlay overlay))))
> + (setq rng-error-count (1- rng-error-count)))))))
> (setq overlays (cdr overlays))))))
>
> -;;; Dependent regions
> -
> -(defun rng-mark-xmltok-dependent-regions ()
> - (while xmltok-dependent-regions
> - (apply 'rng-mark-xmltok-dependent-region
> - (car xmltok-dependent-regions))
> - (setq xmltok-dependent-regions
> - (cdr xmltok-dependent-regions))))
> -
> -(defun rng-mark-xmltok-dependent-region (fun start end &rest args)
> - (let ((overlay (make-overlay start end nil t t)))
> - (overlay-put overlay 'category 'rng-dependent)
> - (overlay-put overlay 'rng-funargs (cons fun args))))
> -
> -(put 'rng-dependent 'evaporate t)
> -(put 'rng-dependent 'modification-hooks '(rng-dependent-region-changed))
> -(put 'rng-dependent 'insert-behind-hooks '(rng-dependent-region-changed))
> -
> -(defun rng-dependent-region-changed (overlay
> - after-p
> - change-start
> - change-end
> - &optional pre-change-length)
> - (when (and after-p
> - ;; Emacs sometimes appears to call deleted overlays
> - (overlay-start overlay)
> - (let ((funargs (overlay-get overlay 'rng-funargs)))
> - (save-match-data
> - (save-excursion
> - (save-restriction
> - (widen)
> - (apply (car funargs)
> - (append (list change-start
> - change-end
> - pre-change-length
> - (overlay-start overlay)
> - (overlay-end overlay))
> - (cdr funargs))))))))
> - (rng-after-change-function (overlay-start overlay)
> - change-end
> - (+ pre-change-length
> - (- (overlay-start overlay)
> - change-start)))
> - (delete-overlay overlay)))
> -
> ;;; Error state
>
> (defun rng-mark-xmltok-errors ()
>
> === modified file 'lisp/nxml/xmltok.el'
> --- lisp/nxml/xmltok.el 2013-01-01 09:11:05 +0000
> +++ lisp/nxml/xmltok.el 2013-05-09 22:36:32 +0000
> @@ -132,33 +132,6 @@
> meaning the replacement text included a <, or a string which is the
> normalized attribute value.")
>
> -(defvar xmltok-dependent-regions nil
> - "List of descriptors of regions that a parsed token depends on.
> -
> -A token depends on a region if the region occurs after the token and a
> -change in the region may require the token to be reparsed. This only
> -happens with markup that is not well-formed. For example, if a <?
> -occurs without a matching ?>, then the <? is returned as a
> -not-well-formed token. However, this token is dependent on region
> -from the end of the token to the end of the buffer: if this ever
> -contains ?> then the buffer must be reparsed from the <?.
> -
> -A region descriptor is a list (FUN START END ARG ...), where FUN is a
> -function to be called when the region changes, START and END are
> -integers giving the start and end of the region, and ARG... are
> -additional arguments to be passed to FUN. FUN will be called with 5
> -arguments followed by the additional arguments if any: the position of
> -the start of the changed area in the region, the position of the end
> -of the changed area in the region, the length of the changed area
> -before the change, the position of the start of the region, the
> -position of the end of the region. FUN must return non-nil if the
> -region needs reparsing. FUN will be called in a `save-excursion'
> -with match-data saved.
> -
> -`xmltok-forward', `xmltok-forward-special' and `xmltok-forward-prolog'
> -may add entries to the beginning of this list, but will not clear it.
> -`xmltok-forward' and `xmltok-forward-special' will only add entries
> -when returning tokens of type not-well-formed.")
>
> (defvar xmltok-errors nil
> "List of errors detected by `xmltok-forward' and `xmltok-forward-prolog'.
> @@ -176,7 +149,6 @@
> xmltok-replacement
> xmltok-attributes
> xmltok-namespace-attributes
> - xmltok-dependent-regions
> xmltok-errors)
> ,@body))
>
> @@ -298,14 +270,6 @@
> (or end (point)))
> xmltok-errors)))
>
> -(defun xmltok-add-dependent (fun &optional start end &rest args)
> - (setq xmltok-dependent-regions
> - (cons (cons fun
> - (cons (or start xmltok-start)
> - (cons (or end (point-max))
> - args)))
> - xmltok-dependent-regions)))
> -
> (defun xmltok-forward ()
> (setq xmltok-start (point))
> (let* ((case-fold-search nil)
> @@ -684,14 +648,8 @@
> (setq xmltok-type 'empty-element))
> ((xmltok-after-lt start cdata-section-open)
> (setq xmltok-type
> - (if (search-forward "]]>" nil t)
> - 'cdata-section
> - (xmltok-add-error "No closing ]]>")
> - (xmltok-add-dependent 'xmltok-unclosed-reparse-p
> - nil
> - nil
> - "]]>")
> - 'not-well-formed)))
> + (progn (search-forward "]]>" nil 'move)
> + 'cdata-section)))
> ((xmltok-after-lt start processing-instruction-question)
> (xmltok-scan-after-processing-instruction-open))
> ((xmltok-after-lt start comment-open)
> @@ -758,16 +716,7 @@
> ;; xmltok-scan-prolog-after-processing-instruction-open
> ;; XXX maybe should include rest of line (up to any <,>) in unclosed PI
> (defun xmltok-scan-after-processing-instruction-open ()
> - (cond ((not (search-forward "?>" nil t))
> - (xmltok-add-error "No closing ?>"
> - xmltok-start
> - (+ xmltok-start 2))
> - (xmltok-add-dependent 'xmltok-unclosed-reparse-p
> - nil
> - nil
> - "?>")
> - (setq xmltok-type 'not-well-formed))
> - (t
> + (search-forward "?>" nil 'move)
> (cond ((not (save-excursion
> (goto-char (+ 2 xmltok-start))
> (and (looking-at (xmltok-ncname regexp))
> @@ -790,36 +739,21 @@
> (xmltok-add-error "Processing instruction target is xml"
> (+ xmltok-start 2)
> (+ xmltok-start 5))))
> - (setq xmltok-type 'processing-instruction))))
> + (setq xmltok-type 'processing-instruction))
>
> (defun xmltok-scan-after-comment-open ()
> + (let ((found-- (search-forward "--" nil 'move)))
> (setq xmltok-type
> - (cond ((not (search-forward "--" nil t))
> - (xmltok-add-error "No closing -->")
> - (xmltok-add-dependent 'xmltok-unclosed-reparse-p
> - nil
> - nil
> - ;; not --> because
> - ;; -- is not allowed
> - ;; in comments in XML
> - "--")
> - 'not-well-formed)
> - ((eq (char-after) ?>)
> + (cond ((or (eq (char-after) ?>) (not found--))
> (goto-char (1+ (point)))
> 'comment)
> (t
> - (xmltok-add-dependent
> - 'xmltok-semi-closed-reparse-p
> - nil
> - (point)
> - "--"
> - 2)
> ;; just include the <!-- in the token
> (goto-char (+ xmltok-start 4))
> ;; Need do this after the goto-char because
> ;; marked error should just apply to <!--
> (xmltok-add-error "First following `--' not followed by `>'")
> - 'not-well-formed))))
> + 'not-well-formed)))))
>
> (defun xmltok-scan-attributes ()
> (let ((recovering nil)
> @@ -1124,7 +1058,7 @@
> markup-declaration-open, markup-declaration-close,
> internal-subset-open, internal-subset-close, hash-name, keyword,
> literal, encoding-name.
> -Adds to `xmltok-errors' and `xmltok-dependent-regions' as appropriate."
> +Adds to `xmltok-errors' as appropriate."
> (let ((case-fold-search nil)
> xmltok-start
> xmltok-type
> @@ -1148,7 +1082,6 @@
> (1- xmltok-internal-subset-start)
> xmltok-internal-subset-start))
> (xmltok-parse-entities)
> - ;; XXX prune dependent-regions for those entirely in prolog
> (nreverse xmltok-prolog-regions)))
>
> (defconst xmltok-bad-xml-decl-regexp
> @@ -1648,46 +1581,19 @@
> (end (save-excursion
> (goto-char safe-end)
> (search-forward delim nil t))))
> - (or (cond ((not end)
> - (xmltok-add-dependent 'xmltok-unclosed-reparse-p
> - nil
> - nil
> - delim)
> - nil)
> - ((save-excursion
> - (goto-char end)
> - (looking-at "[ \t\r\n>%[]"))
> + (cond ((or (not end)
> + (save-excursion
> (goto-char end)
> - (setq xmltok-type 'literal))
> + (looking-at "[ \t\r\n>%[]")))
> + (goto-char end))
> ((eq (1+ safe-end) end)
> (goto-char end)
> (xmltok-add-error (format "Missing space after %s" delim)
> - safe-end)
> - (setq xmltok-type 'literal))
> - (t
> - (xmltok-add-dependent 'xmltok-semi-closed-reparse-p
> - xmltok-start
> - (1+ end)
> - delim
> - 1)
> - nil))
> - (progn
> - (xmltok-add-error (format "Missing closing %s" delim))
> - (goto-char safe-end)
> - (skip-chars-backward " \t\r\n")
> - (setq xmltok-type 'not-well-formed)))))
> + safe-end)))
> + (setq xmltok-type 'literal)))
>
> (defun xmltok-scan-prolog-after-processing-instruction-open ()
> - (cond ((not (search-forward "?>" nil t))
> - (xmltok-add-error "No closing ?>"
> - xmltok-start
> - (+ xmltok-start 2))
> - (xmltok-add-dependent 'xmltok-unclosed-reparse-p
> - nil
> - nil
> - "?>")
> - (setq xmltok-type 'not-well-formed))
> - (t
> + (search-forward "?>" nil 'move)
> (let* ((end (point))
> (target
> (save-excursion
> @@ -1736,7 +1642,7 @@
> (point))
> (+ xmltok-start 2))
> (point)))
> - (setq xmltok-type 'processing-instruction))))
> + (setq xmltok-type 'processing-instruction))
>
> (defun xmltok-parse-entities ()
> (let ((todo xmltok-dtd))
>
>
>
Reads like it does kind of on-the-fly check.
Checking for a closing seems not unreasonable as such.
What about making it dependent from a boolean, so in case some user will miss it, it might be switched on?
Just for consideration - cleaning up the code is always a good idea.
Andreas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-11 6:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-10 17:25 nxml maintainer? Stefan Monnier
2013-05-11 6:47 ` Andreas Röhler
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).