diff options
| author | Stefan Monnier | 2016-01-16 15:03:42 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2016-01-16 15:03:42 -0500 |
| commit | 56e1097584c13f2b6db85592769db1c6c36e9419 (patch) | |
| tree | f2ad4406bd02486ac2c984e84d444f952430a49f | |
| parent | 3dee7772f25085a1f3224b8aa05af68df2efff29 (diff) | |
| download | emacs-56e1097584c13f2b6db85592769db1c6c36e9419.tar.gz emacs-56e1097584c13f2b6db85592769db1c6c36e9419.zip | |
lisp/nxml: Use syntax-tables for comments
* lisp/nxml/nxml-mode.el (nxml-set-face): Prepend.
(nxml-mode): Set syntax-ppss-table.
Use sgml-syntax-propertize-function for syntax-propertize-function.
Let font-lock highlight strings and comments.
(nxml-degrade): Don't touch "nxml-inside" property any more.
(nxml-after-change, nxml-after-change1): Remove functions.
(comment): Don't set fontify rule any more.
(nxml-fontify-attribute): Don't highlight the value any more.
(nxml-namespace-attribute-value-delimiter, nxml-namespace-attribute-value)
(nxml-comment-delimiter, nxml-comment-content): Remove faces.
* lisp/nxml/nxml-rap.el (nxml-scan-end): Remove.
(nxml-get-inside, nxml-inside-start, nxml-inside-end): Use syntax-ppss.
(nxml-clear-inside, nxml-set-inside): Remove.
(nxml-scan-after-change): Remove function.
(nxml-scan-prolog, nxml-tokenize-forward): Simplify.
(nxml-ensure-scan-up-to-date): Use syntax-propertize.
(nxml-move-outside-backwards):
* lisp/nxml/nxml-outln.el (nxml-section-tag-backward): Adjust to new
nxml-inside-start behavior.
* lisp/nxml/nxml-util.el (nxml-debug-set-inside)
(nxml-debug-clear-inside): Remove macros.
* lisp/nxml/xmltok.el (xmltok-forward-special): Remove function.
(xmltok-scan-after-comment-open): Simplify.
| -rw-r--r-- | lisp/nxml/nxml-mode.el | 112 | ||||
| -rw-r--r-- | lisp/nxml/nxml-outln.el | 2 | ||||
| -rw-r--r-- | lisp/nxml/nxml-rap.el | 127 | ||||
| -rw-r--r-- | lisp/nxml/nxml-util.el | 14 | ||||
| -rw-r--r-- | lisp/nxml/xmltok.el | 26 |
5 files changed, 43 insertions, 238 deletions
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el index c6600b185e6..edc7414bfbf 100644 --- a/lisp/nxml/nxml-mode.el +++ b/lisp/nxml/nxml-mode.el | |||
| @@ -37,6 +37,7 @@ | |||
| 37 | ;; So we might as well just require it and silence the compiler. | 37 | ;; So we might as well just require it and silence the compiler. |
| 38 | (provide 'nxml-mode) ; avoid recursive require | 38 | (provide 'nxml-mode) ; avoid recursive require |
| 39 | (require 'rng-nxml) | 39 | (require 'rng-nxml) |
| 40 | (require 'sgml-mode) | ||
| 40 | 41 | ||
| 41 | ;;; Customization | 42 | ;;; Customization |
| 42 | 43 | ||
| @@ -147,16 +148,6 @@ This is not used directly, but only via inheritance by other faces." | |||
| 147 | "Face used to highlight text." | 148 | "Face used to highlight text." |
| 148 | :group 'nxml-faces) | 149 | :group 'nxml-faces) |
| 149 | 150 | ||
| 150 | (defface nxml-comment-content | ||
| 151 | '((t (:inherit font-lock-comment-face))) | ||
| 152 | "Face used to highlight the content of comments." | ||
| 153 | :group 'nxml-faces) | ||
| 154 | |||
| 155 | (defface nxml-comment-delimiter | ||
| 156 | '((t (:inherit font-lock-comment-delimiter-face))) | ||
| 157 | "Face used for the delimiters of comments, i.e., <!-- and -->." | ||
| 158 | :group 'nxml-faces) | ||
| 159 | |||
| 160 | (defface nxml-processing-instruction-delimiter | 151 | (defface nxml-processing-instruction-delimiter |
| 161 | '((t (:inherit nxml-delimiter))) | 152 | '((t (:inherit nxml-delimiter))) |
| 162 | "Face used for the delimiters of processing instructions, i.e., <? and ?>." | 153 | "Face used for the delimiters of processing instructions, i.e., <? and ?>." |
| @@ -274,15 +265,6 @@ This includes ths `x' in hex references." | |||
| 274 | "Face used for the delimiters of attribute values." | 265 | "Face used for the delimiters of attribute values." |
| 275 | :group 'nxml-faces) | 266 | :group 'nxml-faces) |
| 276 | 267 | ||
| 277 | (defface nxml-namespace-attribute-value | ||
| 278 | '((t (:inherit nxml-attribute-value))) | ||
| 279 | "Face used for the value of namespace attributes." | ||
| 280 | :group 'nxml-faces) | ||
| 281 | |||
| 282 | (defface nxml-namespace-attribute-value-delimiter | ||
| 283 | '((t (:inherit nxml-attribute-value-delimiter))) | ||
| 284 | "Face used for the delimiters of namespace attribute values." | ||
| 285 | :group 'nxml-faces) | ||
| 286 | 268 | ||
| 287 | (defface nxml-prolog-literal-delimiter | 269 | (defface nxml-prolog-literal-delimiter |
| 288 | '((t (:inherit nxml-delimited-data))) | 270 | '((t (:inherit nxml-delimited-data))) |
| @@ -405,7 +387,9 @@ reference.") | |||
| 405 | 387 | ||
| 406 | (defsubst nxml-set-face (start end face) | 388 | (defsubst nxml-set-face (start end face) |
| 407 | (when (and face (< start end)) | 389 | (when (and face (< start end)) |
| 408 | (font-lock-append-text-property start end 'face face))) | 390 | ;; Prepend, so the character reference highlighting takes precedence over |
| 391 | ;; the string highlighting applied syntactically. | ||
| 392 | (font-lock-prepend-text-property start end 'face face))) | ||
| 409 | 393 | ||
| 410 | (defun nxml-parent-document-set (parent-document) | 394 | (defun nxml-parent-document-set (parent-document) |
| 411 | "Set `nxml-parent-document' and inherit the DTD &c." | 395 | "Set `nxml-parent-document' and inherit the DTD &c." |
| @@ -530,12 +514,11 @@ Many aspects this mode can be customized using | |||
| 530 | (save-excursion | 514 | (save-excursion |
| 531 | (save-restriction | 515 | (save-restriction |
| 532 | (widen) | 516 | (widen) |
| 533 | (setq nxml-scan-end (copy-marker (point-min) nil)) | ||
| 534 | (with-silent-modifications | 517 | (with-silent-modifications |
| 535 | (nxml-clear-inside (point-min) (point-max)) | ||
| 536 | (nxml-with-invisible-motion | 518 | (nxml-with-invisible-motion |
| 537 | (nxml-scan-prolog))))) | 519 | (nxml-scan-prolog))))) |
| 538 | (setq-local syntax-propertize-function #'nxml-after-change) | 520 | (setq-local syntax-ppss-table sgml-tag-syntax-table) |
| 521 | (setq-local syntax-propertize-function sgml-syntax-propertize-function) | ||
| 539 | (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) | 522 | (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) |
| 540 | 523 | ||
| 541 | ;; Emacs 23 handles the encoding attribute on the xml declaration | 524 | ;; Emacs 23 handles the encoding attribute on the xml declaration |
| @@ -552,7 +535,7 @@ Many aspects this mode can be customized using | |||
| 552 | 535 | ||
| 553 | (setq font-lock-defaults | 536 | (setq font-lock-defaults |
| 554 | '(nxml-font-lock-keywords | 537 | '(nxml-font-lock-keywords |
| 555 | t ; keywords-only; we highlight comments and strings here | 538 | nil ; highlight comments and strings based on syntax-tables |
| 556 | nil ; font-lock-keywords-case-fold-search. XML is case sensitive | 539 | nil ; font-lock-keywords-case-fold-search. XML is case sensitive |
| 557 | nil ; no special syntax table | 540 | nil ; no special syntax table |
| 558 | (font-lock-extend-region-functions . (nxml-extend-region)) | 541 | (font-lock-extend-region-functions . (nxml-extend-region)) |
| @@ -579,12 +562,7 @@ Many aspects this mode can be customized using | |||
| 579 | (error-message-string err)) | 562 | (error-message-string err)) |
| 580 | (ding) | 563 | (ding) |
| 581 | (setq nxml-degraded t) | 564 | (setq nxml-degraded t) |
| 582 | (setq nxml-prolog-end 1) | 565 | (setq nxml-prolog-end 1)) |
| 583 | (save-excursion | ||
| 584 | (save-restriction | ||
| 585 | (widen) | ||
| 586 | (with-silent-modifications | ||
| 587 | (nxml-clear-inside (point-min) (point-max)))))) | ||
| 588 | 566 | ||
| 589 | ;;; Change management | 567 | ;;; Change management |
| 590 | 568 | ||
| @@ -597,41 +575,6 @@ Many aspects this mode can be customized using | |||
| 597 | (goto-char font-lock-beg) | 575 | (goto-char font-lock-beg) |
| 598 | (set-mark font-lock-end))) | 576 | (set-mark font-lock-end))) |
| 599 | 577 | ||
| 600 | (defun nxml-after-change (start end) | ||
| 601 | ;; Called via syntax-propertize-function. | ||
| 602 | (unless nxml-degraded | ||
| 603 | (nxml-with-degradation-on-error 'nxml-after-change | ||
| 604 | (save-restriction | ||
| 605 | (widen) | ||
| 606 | (nxml-with-invisible-motion | ||
| 607 | (nxml-after-change1 start end)))))) | ||
| 608 | |||
| 609 | (defun nxml-after-change1 (start end) | ||
| 610 | "After-change bookkeeping. | ||
| 611 | Returns a cons cell containing a possibly-enlarged change region. | ||
| 612 | You must call `nxml-extend-region' on this expanded region to obtain | ||
| 613 | the full extent of the area needing refontification. | ||
| 614 | |||
| 615 | For bookkeeping, call this function even when fontification is | ||
| 616 | disabled." | ||
| 617 | ;; If the prolog might have changed, rescan the prolog. | ||
| 618 | (when (<= start | ||
| 619 | ;; Add 2 so as to include the < and following char that | ||
| 620 | ;; start the instance (document element), since changing | ||
| 621 | ;; these can change where the prolog ends. | ||
| 622 | (+ nxml-prolog-end 2)) | ||
| 623 | (nxml-scan-prolog) | ||
| 624 | (setq start (point-min))) | ||
| 625 | |||
| 626 | (when (> end nxml-prolog-end) | ||
| 627 | (goto-char start) | ||
| 628 | (nxml-move-tag-backwards (point-min)) | ||
| 629 | (setq start (point)) | ||
| 630 | (setq end (max (nxml-scan-after-change start end) | ||
| 631 | end))) | ||
| 632 | |||
| 633 | (nxml-debug-change "nxml-after-change1" start end)) | ||
| 634 | |||
| 635 | ;;; Encodings | 578 | ;;; Encodings |
| 636 | 579 | ||
| 637 | (defun nxml-insert-xml-declaration () | 580 | (defun nxml-insert-xml-declaration () |
| @@ -957,11 +900,11 @@ faces appropriately." | |||
| 957 | [1 -1 nxml-entity-ref-name] | 900 | [1 -1 nxml-entity-ref-name] |
| 958 | [-1 nil nxml-entity-ref-delimiter])) | 901 | [-1 nil nxml-entity-ref-delimiter])) |
| 959 | 902 | ||
| 960 | (put 'comment | 903 | ;; (put 'comment |
| 961 | 'nxml-fontify-rule | 904 | ;; 'nxml-fontify-rule |
| 962 | '([nil 4 nxml-comment-delimiter] | 905 | ;; '([nil 4 nxml-comment-delimiter] |
| 963 | [4 -3 nxml-comment-content] | 906 | ;; [4 -3 nxml-comment-content] |
| 964 | [-3 nil nxml-comment-delimiter])) | 907 | ;; [-3 nil nxml-comment-delimiter])) |
| 965 | 908 | ||
| 966 | (put 'processing-instruction | 909 | (put 'processing-instruction |
| 967 | 'nxml-fontify-rule | 910 | 'nxml-fontify-rule |
| @@ -993,7 +936,7 @@ faces appropriately." | |||
| 993 | 'nxml-fontify-rule | 936 | 'nxml-fontify-rule |
| 994 | '([nil nil nxml-attribute-local-name])) | 937 | '([nil nil nxml-attribute-local-name])) |
| 995 | 938 | ||
| 996 | (put 'xml-declaration-attribute-value | 939 | (put 'xml-declaration-attribute-value ;FIXME: What is this for? |
| 997 | 'nxml-fontify-rule | 940 | 'nxml-fontify-rule |
| 998 | '([nil 1 nxml-attribute-value-delimiter] | 941 | '([nil 1 nxml-attribute-value-delimiter] |
| 999 | [1 -1 nxml-attribute-value] | 942 | [1 -1 nxml-attribute-value] |
| @@ -1112,28 +1055,11 @@ faces appropriately." | |||
| 1112 | 'nxml-attribute-prefix | 1055 | 'nxml-attribute-prefix |
| 1113 | 'nxml-attribute-colon | 1056 | 'nxml-attribute-colon |
| 1114 | 'nxml-attribute-local-name)) | 1057 | 'nxml-attribute-local-name)) |
| 1115 | (let ((start (xmltok-attribute-value-start att)) | 1058 | (dolist (ref (xmltok-attribute-refs att)) |
| 1116 | (end (xmltok-attribute-value-end att)) | 1059 | (let* ((ref-type (aref ref 0)) |
| 1117 | (refs (xmltok-attribute-refs att)) | 1060 | (ref-start (aref ref 1)) |
| 1118 | (delimiter-face (if namespace-declaration | 1061 | (ref-end (aref ref 2))) |
| 1119 | 'nxml-namespace-attribute-value-delimiter | 1062 | (nxml-apply-fontify-rule ref-type ref-start ref-end)))) |
| 1120 | 'nxml-attribute-value-delimiter)) | ||
| 1121 | (value-face (if namespace-declaration | ||
| 1122 | 'nxml-namespace-attribute-value | ||
| 1123 | 'nxml-attribute-value))) | ||
| 1124 | (when start | ||
| 1125 | (nxml-set-face (1- start) start delimiter-face) | ||
| 1126 | (nxml-set-face end (1+ end) delimiter-face) | ||
| 1127 | (while refs | ||
| 1128 | (let* ((ref (car refs)) | ||
| 1129 | (ref-type (aref ref 0)) | ||
| 1130 | (ref-start (aref ref 1)) | ||
| 1131 | (ref-end (aref ref 2))) | ||
| 1132 | (nxml-set-face start ref-start value-face) | ||
| 1133 | (nxml-apply-fontify-rule ref-type ref-start ref-end) | ||
| 1134 | (setq start ref-end)) | ||
| 1135 | (setq refs (cdr refs))) | ||
| 1136 | (nxml-set-face start end value-face)))) | ||
| 1137 | 1063 | ||
| 1138 | (defun nxml-fontify-qname (start | 1064 | (defun nxml-fontify-qname (start |
| 1139 | colon | 1065 | colon |
diff --git a/lisp/nxml/nxml-outln.el b/lisp/nxml/nxml-outln.el index 79e6406f553..289816a1bba 100644 --- a/lisp/nxml/nxml-outln.el +++ b/lisp/nxml/nxml-outln.el | |||
| @@ -888,7 +888,7 @@ Point is at the end of the tag. `xmltok-start' is the start." | |||
| 888 | (nxml-ensure-scan-up-to-date) | 888 | (nxml-ensure-scan-up-to-date) |
| 889 | (let ((pos (nxml-inside-start (point)))) | 889 | (let ((pos (nxml-inside-start (point)))) |
| 890 | (when pos | 890 | (when pos |
| 891 | (goto-char (1- pos)) | 891 | (goto-char pos) |
| 892 | t)))) | 892 | t)))) |
| 893 | ((progn | 893 | ((progn |
| 894 | (xmltok-forward) | 894 | (xmltok-forward) |
diff --git a/lisp/nxml/nxml-rap.el b/lisp/nxml/nxml-rap.el index e68c8a427fd..e66289d042a 100644 --- a/lisp/nxml/nxml-rap.el +++ b/lisp/nxml/nxml-rap.el | |||
| @@ -46,8 +46,7 @@ | |||
| 46 | ;; look like it scales to large numbers of overlays in a buffer. | 46 | ;; look like it scales to large numbers of overlays in a buffer. |
| 47 | ;; | 47 | ;; |
| 48 | ;; We don't in fact track all these constructs, but only track them in | 48 | ;; We don't in fact track all these constructs, but only track them in |
| 49 | ;; some initial part of the instance. The variable `nxml-scan-end' | 49 | ;; some initial part of the instance. |
| 50 | ;; contains the limit of where we have scanned up to for them. | ||
| 51 | ;; | 50 | ;; |
| 52 | ;; Thus to parse some random point in the file we first ensure that we | 51 | ;; Thus to parse some random point in the file we first ensure that we |
| 53 | ;; have scanned up to that point. Then we search backwards for a | 52 | ;; have scanned up to that point. Then we search backwards for a |
| @@ -74,93 +73,33 @@ | |||
| 74 | 73 | ||
| 75 | (require 'xmltok) | 74 | (require 'xmltok) |
| 76 | (require 'nxml-util) | 75 | (require 'nxml-util) |
| 76 | (require 'sgml-mode) | ||
| 77 | 77 | ||
| 78 | (defvar nxml-prolog-end nil | 78 | (defvar-local nxml-prolog-end nil |
| 79 | "Integer giving position following end of the prolog.") | 79 | "Integer giving position following end of the prolog.") |
| 80 | (make-variable-buffer-local 'nxml-prolog-end) | ||
| 81 | |||
| 82 | (defvar nxml-scan-end nil | ||
| 83 | "Marker giving position up to which we have scanned. | ||
| 84 | nxml-scan-end must be >= nxml-prolog-end. Furthermore, nxml-scan-end | ||
| 85 | must not be an inside position in the following sense. A position is | ||
| 86 | inside if the following character is a part of, but not the first | ||
| 87 | character of, a CDATA section, comment or processing instruction. | ||
| 88 | Furthermore all positions >= nxml-prolog-end and < nxml-scan-end that | ||
| 89 | are inside positions must have a non-nil `nxml-inside' property whose | ||
| 90 | value is a symbol specifying what it is inside. Any characters with a | ||
| 91 | non-nil `fontified' property must have position < nxml-scan-end and | ||
| 92 | the correct face. Dependent regions must also be established for any | ||
| 93 | unclosed constructs starting before nxml-scan-end. | ||
| 94 | There must be no `nxml-inside' properties after nxml-scan-end.") | ||
| 95 | (make-variable-buffer-local 'nxml-scan-end) | ||
| 96 | 80 | ||
| 97 | (defsubst nxml-get-inside (pos) | 81 | (defsubst nxml-get-inside (pos) |
| 98 | (get-text-property pos 'nxml-inside)) | 82 | (save-excursion (nth 8 (syntax-ppss pos)))) |
| 99 | |||
| 100 | (defsubst nxml-clear-inside (start end) | ||
| 101 | (nxml-debug-clear-inside start end) | ||
| 102 | (remove-text-properties start end '(nxml-inside nil))) | ||
| 103 | |||
| 104 | (defsubst nxml-set-inside (start end type) | ||
| 105 | (nxml-debug-set-inside start end) | ||
| 106 | (put-text-property start end 'nxml-inside type)) | ||
| 107 | 83 | ||
| 108 | (defun nxml-inside-end (pos) | 84 | (defun nxml-inside-end (pos) |
| 109 | "Return the end of the inside region containing POS. | 85 | "Return the end of the inside region containing POS. |
| 110 | Return nil if the character at POS is not inside." | 86 | Return nil if the character at POS is not inside." |
| 111 | (if (nxml-get-inside pos) | 87 | (save-excursion |
| 112 | (or (next-single-property-change pos 'nxml-inside) | 88 | (let ((ppss (syntax-ppss pos))) |
| 113 | (point-max)) | 89 | (when (nth 8 ppss) |
| 114 | nil)) | 90 | (goto-char (nth 8 ppss)) |
| 91 | (with-syntax-table sgml-tag-syntax-table | ||
| 92 | (if (nth 3 ppss) | ||
| 93 | (progn (forward-comment 1) (point)) | ||
| 94 | (or (scan-sexps (point) 1) (point-max)))))))) | ||
| 115 | 95 | ||
| 116 | (defun nxml-inside-start (pos) | 96 | (defun nxml-inside-start (pos) |
| 117 | "Return the start of the inside region containing POS. | 97 | "Return the start of the inside region containing POS. |
| 118 | Return nil if the character at POS is not inside." | 98 | Return nil if the character at POS is not inside." |
| 119 | (if (nxml-get-inside pos) | 99 | (save-excursion (nth 8 (syntax-ppss pos)))) |
| 120 | (or (previous-single-property-change (1+ pos) 'nxml-inside) | ||
| 121 | (point-min)) | ||
| 122 | nil)) | ||
| 123 | 100 | ||
| 124 | ;;; Change management | 101 | ;;; Change management |
| 125 | 102 | ||
| 126 | (defun nxml-scan-after-change (start end) | ||
| 127 | "Restore `nxml-scan-end' invariants after a change. | ||
| 128 | The change happened between START and END. | ||
| 129 | Return position after which lexical state is unchanged. | ||
| 130 | END must be > `nxml-prolog-end'. START must be outside | ||
| 131 | any “inside” regions and at the beginning of a token." | ||
| 132 | (if (>= start nxml-scan-end) | ||
| 133 | nxml-scan-end | ||
| 134 | (let ((inside-remove-start start) | ||
| 135 | xmltok-errors) | ||
| 136 | (while (or (when (xmltok-forward-special (min end nxml-scan-end)) | ||
| 137 | (when (memq xmltok-type | ||
| 138 | '(comment | ||
| 139 | cdata-section | ||
| 140 | processing-instruction)) | ||
| 141 | (nxml-clear-inside inside-remove-start | ||
| 142 | (1+ xmltok-start)) | ||
| 143 | (nxml-set-inside (1+ xmltok-start) | ||
| 144 | (point) | ||
| 145 | xmltok-type) | ||
| 146 | (setq inside-remove-start (point))) | ||
| 147 | (if (< (point) (min end nxml-scan-end)) | ||
| 148 | t | ||
| 149 | (setq end (point)) | ||
| 150 | nil)) | ||
| 151 | ;; The end of the change was inside but is now outside. | ||
| 152 | ;; Imagine something really weird like | ||
| 153 | ;; <![CDATA[foo <!-- bar ]]> <![CDATA[ stuff --> <!-- ]]> --> | ||
| 154 | ;; and suppose we deleted "<![CDATA[f" | ||
| 155 | (let ((inside-end (nxml-inside-end end))) | ||
| 156 | (when inside-end | ||
| 157 | (setq end inside-end) | ||
| 158 | t)))) | ||
| 159 | (nxml-clear-inside inside-remove-start end)) | ||
| 160 | (when (> end nxml-scan-end) | ||
| 161 | (set-marker nxml-scan-end end)) | ||
| 162 | end)) | ||
| 163 | |||
| 164 | ;; n-s-p only called from nxml-mode.el, where this variable is defined. | 103 | ;; n-s-p only called from nxml-mode.el, where this variable is defined. |
| 165 | (defvar nxml-prolog-regions) | 104 | (defvar nxml-prolog-regions) |
| 166 | 105 | ||
| @@ -169,10 +108,7 @@ any “inside” regions and at the beginning of a token." | |||
| 169 | (let (xmltok-dtd | 108 | (let (xmltok-dtd |
| 170 | xmltok-errors) | 109 | xmltok-errors) |
| 171 | (setq nxml-prolog-regions (xmltok-forward-prolog)) | 110 | (setq nxml-prolog-regions (xmltok-forward-prolog)) |
| 172 | (setq nxml-prolog-end (point)) | 111 | (setq nxml-prolog-end (point)))) |
| 173 | (nxml-clear-inside (point-min) nxml-prolog-end)) | ||
| 174 | (when (< nxml-scan-end nxml-prolog-end) | ||
| 175 | (set-marker nxml-scan-end nxml-prolog-end))) | ||
| 176 | 112 | ||
| 177 | 113 | ||
| 178 | ;;; Random access parsing | 114 | ;;; Random access parsing |
| @@ -223,14 +159,7 @@ Sets variables like `nxml-token-after'." | |||
| 223 | 159 | ||
| 224 | (defun nxml-tokenize-forward () | 160 | (defun nxml-tokenize-forward () |
| 225 | (let (xmltok-errors) | 161 | (let (xmltok-errors) |
| 226 | (when (and (xmltok-forward) | 162 | (xmltok-forward) |
| 227 | (> (point) nxml-scan-end)) | ||
| 228 | (cond ((memq xmltok-type '(comment | ||
| 229 | cdata-section | ||
| 230 | processing-instruction)) | ||
| 231 | (with-silent-modifications | ||
| 232 | (nxml-set-inside (1+ xmltok-start) (point) xmltok-type)))) | ||
| 233 | (set-marker nxml-scan-end (point))) | ||
| 234 | xmltok-type)) | 163 | xmltok-type)) |
| 235 | 164 | ||
| 236 | (defun nxml-move-tag-backwards (bound) | 165 | (defun nxml-move-tag-backwards (bound) |
| @@ -253,32 +182,12 @@ As a precondition, point must be >= BOUND." | |||
| 253 | Leave point unmoved if it is not inside anything special." | 182 | Leave point unmoved if it is not inside anything special." |
| 254 | (let ((start (nxml-inside-start (point)))) | 183 | (let ((start (nxml-inside-start (point)))) |
| 255 | (when start | 184 | (when start |
| 256 | (goto-char (1- start)) | 185 | (goto-char start) |
| 257 | (when (nxml-get-inside (point)) | 186 | (when (nxml-get-inside (point)) |
| 258 | (error "Char before inside-start at %s had nxml-inside property %s" | 187 | (error "Char before inside-start at %s is still \"inside\"" (point)))))) |
| 259 | (point) | ||
| 260 | (nxml-get-inside (point))))))) | ||
| 261 | 188 | ||
| 262 | (defun nxml-ensure-scan-up-to-date () | 189 | (defun nxml-ensure-scan-up-to-date () |
| 263 | (let ((pos (point))) | 190 | (syntax-propertize (point))) |
| 264 | (when (< nxml-scan-end pos) | ||
| 265 | (save-excursion | ||
| 266 | (goto-char nxml-scan-end) | ||
| 267 | (let (xmltok-errors) | ||
| 268 | (while (when (xmltok-forward-special pos) | ||
| 269 | (when (memq xmltok-type | ||
| 270 | '(comment | ||
| 271 | processing-instruction | ||
| 272 | cdata-section)) | ||
| 273 | (with-silent-modifications | ||
| 274 | (nxml-set-inside (1+ xmltok-start) | ||
| 275 | (point) | ||
| 276 | xmltok-type))) | ||
| 277 | (if (< (point) pos) | ||
| 278 | t | ||
| 279 | (setq pos (point)) | ||
| 280 | nil))) | ||
| 281 | (set-marker nxml-scan-end pos)))))) | ||
| 282 | 191 | ||
| 283 | ;;; Element scanning | 192 | ;;; Element scanning |
| 284 | 193 | ||
diff --git a/lisp/nxml/nxml-util.el b/lisp/nxml/nxml-util.el index 14b887ea085..282d4952bf7 100644 --- a/lisp/nxml/nxml-util.el +++ b/lisp/nxml/nxml-util.el | |||
| @@ -36,20 +36,6 @@ | |||
| 36 | `(nxml-debug "%s: %S" ,name | 36 | `(nxml-debug "%s: %S" ,name |
| 37 | (buffer-substring-no-properties ,start ,end)))) | 37 | (buffer-substring-no-properties ,start ,end)))) |
| 38 | 38 | ||
| 39 | (defmacro nxml-debug-set-inside (start end) | ||
| 40 | (when nxml-debug | ||
| 41 | `(let ((overlay (make-overlay ,start ,end))) | ||
| 42 | (overlay-put overlay 'face '(:background "red")) | ||
| 43 | (overlay-put overlay 'nxml-inside-debug t) | ||
| 44 | (nxml-debug-change "nxml-set-inside" ,start ,end)))) | ||
| 45 | |||
| 46 | (defmacro nxml-debug-clear-inside (start end) | ||
| 47 | (when nxml-debug | ||
| 48 | `(cl-loop for overlay in (overlays-in ,start ,end) | ||
| 49 | if (overlay-get overlay 'nxml-inside-debug) | ||
| 50 | do (delete-overlay overlay) | ||
| 51 | finally (nxml-debug-change "nxml-clear-inside" ,start ,end)))) | ||
| 52 | |||
| 53 | (defun nxml-make-namespace (str) | 39 | (defun nxml-make-namespace (str) |
| 54 | "Return a symbol for the namespace URI STR. | 40 | "Return a symbol for the namespace URI STR. |
| 55 | STR must be a string. If STR is the empty string, return nil. | 41 | STR must be a string. If STR is the empty string, return nil. |
diff --git a/lisp/nxml/xmltok.el b/lisp/nxml/xmltok.el index 93d47c195c0..f12905a86d0 100644 --- a/lisp/nxml/xmltok.el +++ b/lisp/nxml/xmltok.el | |||
| @@ -34,10 +34,7 @@ | |||
| 34 | ;; preceding part of the instance. This allows the instance to be | 34 | ;; preceding part of the instance. This allows the instance to be |
| 35 | ;; parsed incrementally. The main entry point is `xmltok-forward': | 35 | ;; parsed incrementally. The main entry point is `xmltok-forward': |
| 36 | ;; this can be called at any point in the instance provided it is | 36 | ;; this can be called at any point in the instance provided it is |
| 37 | ;; between tokens. The other entry point is `xmltok-forward-special' | 37 | ;; between tokens. |
| 38 | ;; which skips over tokens other comments, processing instructions or | ||
| 39 | ;; CDATA sections (i.e. the constructs in an instance that can contain | ||
| 40 | ;; less than signs that don't start a token). | ||
| 41 | ;; | 38 | ;; |
| 42 | ;; This is a non-validating XML 1.0 processor. It does not resolve | 39 | ;; This is a non-validating XML 1.0 processor. It does not resolve |
| 43 | ;; parameter entities (including the external DTD subset) and it does | 40 | ;; parameter entities (including the external DTD subset) and it does |
| @@ -307,18 +304,6 @@ and VALUE-END, otherwise a STRING giving the value." | |||
| 307 | (goto-char (point-max)) | 304 | (goto-char (point-max)) |
| 308 | (setq xmltok-type 'data))))) | 305 | (setq xmltok-type 'data))))) |
| 309 | 306 | ||
| 310 | (defun xmltok-forward-special (bound) | ||
| 311 | "Scan forward past the first special token starting at or after point. | ||
| 312 | Return nil if there is no special token that starts before BOUND. | ||
| 313 | CDATA sections, processing instructions and comments (and indeed | ||
| 314 | anything starting with < following by ? or !) count as special. | ||
| 315 | Return the type of the token." | ||
| 316 | (when (re-search-forward "<[?!]" (1+ bound) t) | ||
| 317 | (setq xmltok-start (match-beginning 0)) | ||
| 318 | (goto-char (1+ xmltok-start)) | ||
| 319 | (let ((case-fold-search nil)) | ||
| 320 | (xmltok-scan-after-lt)))) | ||
| 321 | |||
| 322 | (eval-when-compile | 307 | (eval-when-compile |
| 323 | 308 | ||
| 324 | ;; A symbolic regexp is represented by a list whose CAR is the string | 309 | ;; A symbolic regexp is represented by a list whose CAR is the string |
| @@ -738,11 +723,10 @@ Return the type of the token." | |||
| 738 | (setq xmltok-type 'processing-instruction)) | 723 | (setq xmltok-type 'processing-instruction)) |
| 739 | 724 | ||
| 740 | (defun xmltok-scan-after-comment-open () | 725 | (defun xmltok-scan-after-comment-open () |
| 741 | (let (found--) | 726 | (while (and (re-search-forward "--\\(>\\)?" nil 'move) |
| 742 | (while (and (setq found-- (re-search-forward "--\\(>\\)?" nil 'move)) | 727 | (not (match-end 1))) |
| 743 | (not (match-end 1))) | 728 | (xmltok-add-error "`--' not followed by `>'" (match-beginning 0))) |
| 744 | (xmltok-add-error "`--' not followed by `>'" (match-beginning 0))) | 729 | (setq xmltok-type 'comment)) |
| 745 | (setq xmltok-type 'comment))) | ||
| 746 | 730 | ||
| 747 | (defun xmltok-scan-attributes () | 731 | (defun xmltok-scan-attributes () |
| 748 | (let ((recovering nil) | 732 | (let ((recovering nil) |