Mercurial > emacs
annotate lisp/nxml/nxml-mode.el @ 94186:7870d07a291c
* tooltip.el (tooltip-previous-message): New var.
(tooltip-show-help-non-mode): Rewrite to better follow the behavior of the
C code (avoid overwriting a minibuffer, restore previous echo message, ...).
(tooltip-delay, tooltip-process-prompt-regexp, tooltip-strip-prompt): Simplify.
* keyboard.c (Vpre_help_message): Remove.
(show_help_echo): Remove default C code.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 19 Apr 2008 19:30:53 +0000 |
parents | 3fad91a9740c |
children | d495d4d5452f |
rev | line source |
---|---|
86361 | 1 ;;; nxml-mode.el --- a new XML mode |
2 | |
87665 | 3 ;; Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. |
86361 | 4 |
5 ;; Author: James Clark | |
6 ;; Keywords: XML | |
7 | |
86538 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 3, or (at your option) | |
13 ;; any later version. | |
86361 | 14 |
86538 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
86361 | 19 |
86538 | 20 ;; You should have received a copy of the GNU General Public License |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
23 ;; Boston, MA 02110-1301, USA. | |
86361 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; See nxml-rap.el for description of parsing strategy. | |
28 | |
29 ;; The font locking here is independent of font-lock.el. We want to | |
30 ;; do more sophisticated handling of changes and we want to use the | |
31 ;; same xmltok rather than regexps for parsing so that we parse | |
32 ;; consistently and correctly. | |
33 | |
34 ;;; Code: | |
35 | |
36 (when (featurep 'mucs) | |
37 (error "nxml-mode is not compatible with Mule-UCS")) | |
38 | |
39 (require 'xmltok) | |
40 (require 'nxml-enc) | |
41 (require 'nxml-glyph) | |
42 (require 'nxml-util) | |
43 (require 'nxml-rap) | |
44 (require 'nxml-outln) | |
45 | |
87719
a38e332c61af
(nxml-enable-unicode-char-name-sets, rng-nxml-mode-init): Declare.
Jason Rumney <jasonr@gnu.org>
parents:
87715
diff
changeset
|
46 (declare-function rng-nxml-mode-init "rng-nxml") |
a38e332c61af
(nxml-enable-unicode-char-name-sets, rng-nxml-mode-init): Declare.
Jason Rumney <jasonr@gnu.org>
parents:
87715
diff
changeset
|
47 (declare-function nxml-enable-unicode-char-name-sets "nxml-uchnm") |
a38e332c61af
(nxml-enable-unicode-char-name-sets, rng-nxml-mode-init): Declare.
Jason Rumney <jasonr@gnu.org>
parents:
87715
diff
changeset
|
48 |
86361 | 49 ;;; Customization |
50 | |
51 (defgroup nxml nil | |
52 "New XML editing mode" | |
53 :group 'languages | |
54 :group 'wp) | |
55 | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
56 (defgroup nxml-faces nil |
86361 | 57 "Faces for XML syntax highlighting." |
58 :group 'nxml | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
59 :group 'font-lock-faces) |
86361 | 60 |
61 (defcustom nxml-syntax-highlight-flag t | |
62 "*Non-nil means nxml-mode should perform syntax highlighting." | |
63 :group 'nxml | |
64 :type 'boolean) | |
65 | |
66 (defcustom nxml-char-ref-display-glyph-flag t | |
67 "*Non-nil means display glyph following character reference. | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
68 The glyph is displayed in face `nxml-glyph'. The hook |
86361 | 69 `nxml-glyph-set-hook' can be used to customize for which characters |
70 glyphs are displayed." | |
71 :group 'nxml | |
72 :type 'boolean) | |
73 | |
74 (defcustom nxml-mode-hook nil | |
75 "Hook run by command `nxml-mode'." | |
76 :group 'nxml | |
77 :type 'hook) | |
78 | |
79 (defcustom nxml-sexp-element-flag nil | |
80 "*Non-nil means sexp commands treat an element as a single expression." | |
81 :group 'nxml | |
82 :type 'boolean) | |
83 | |
84 (defcustom nxml-slash-auto-complete-flag nil | |
85 "*Non-nil means typing a slash automatically completes the end-tag. | |
86 This is used by `nxml-electric-slash'." | |
87 :group 'nxml | |
88 :type 'boolean) | |
89 | |
90 (defcustom nxml-child-indent 2 | |
91 "*Indentation for the children of an element relative to the start-tag. | |
92 This only applies when the line or lines containing the start-tag contains | |
93 nothing else other than that start-tag." | |
94 :group 'nxml | |
95 :type 'integer) | |
96 | |
97 (defcustom nxml-attribute-indent 4 | |
98 "*Indentation for the attributes of an element relative to the start-tag. | |
99 This only applies when the first attribute of a tag starts a line. In other | |
100 cases, the first attribute on one line is indented the same as the first | |
101 attribute on the previous line." | |
102 :group 'nxml | |
103 :type 'integer) | |
104 | |
105 (defvar nxml-fontify-chunk-size 500) | |
106 | |
107 (defcustom nxml-bind-meta-tab-to-complete-flag (not window-system) | |
108 "*Non-nil means bind M-TAB in `nxml-mode-map' to `nxml-complete'. | |
109 C-return will be bound to `nxml-complete' in any case. | |
110 M-TAB gets swallowed by many window systems/managers, and | |
111 `documentation' will show M-TAB rather than C-return as the | |
112 binding `rng-complete' when both are bound. So it's better | |
113 to bind M-TAB only when it will work." | |
114 :group 'nxml | |
115 :set (lambda (sym flag) | |
116 (set-default sym flag) | |
117 (when (and (boundp 'nxml-mode-map) nxml-mode-map) | |
118 (define-key nxml-mode-map "\M-\t" (and flag 'nxml-complete)))) | |
119 :type 'boolean) | |
120 | |
121 (defcustom nxml-prefer-utf-16-to-utf-8-flag nil | |
122 "*Non-nil means prefer UTF-16 to UTF-8 when saving a buffer. | |
123 This is used only when a buffer does not contain an encoding declaration | |
124 and when its current `buffer-file-coding-system' specifies neither UTF-16 | |
125 nor UTF-8." | |
126 :group 'nxml | |
127 :type 'boolean) | |
128 | |
129 (defcustom nxml-prefer-utf-16-little-to-big-endian-flag (eq system-type | |
130 'windows-nt) | |
131 "*Non-nil means prefer little-endian to big-endian byte-order for UTF-16. | |
132 This is used only for saving a buffer; when reading the byte-order is | |
133 auto-detected. It may be relevant both when there is no encoding declaration | |
134 and when the encoding declaration specifies `UTF-16'." | |
135 :group 'nxml | |
136 :type 'boolean) | |
137 | |
138 (defcustom nxml-default-buffer-file-coding-system nil | |
139 "*Default value for `buffer-file-coding-system' for a buffer for a new file. | |
140 Nil means use the default value of `buffer-file-coding-system' as normal. | |
141 A buffer's `buffer-file-coding-system' affects what \\[nxml-insert-xml-declaration] inserts." | |
142 :group 'nxml | |
143 :type 'coding-system) | |
144 | |
145 (defcustom nxml-auto-insert-xml-declaration-flag nil | |
146 "*Non-nil means automatically insert an XML declaration in a new file. | |
147 The XML declaration is inserted using `nxml-insert-xml-declaration'." | |
148 :group 'nxml | |
149 :type 'boolean) | |
150 | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
151 (defface nxml-delimited-data |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
152 '((t (:inherit font-lock-doc-face))) |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
153 "Face used to highlight data enclosed between delimiters. |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
154 This is not used directly, but only via inheritance by other faces." |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
155 :group 'nxml-faces) |
86361 | 156 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
157 (defface nxml-name |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
158 '((t (:inherit font-lock-builtin-face))) |
86361 | 159 "Face used to highlight various names. |
160 This includes element and attribute names, processing | |
161 instruction targets and the CDATA keyword in a CDATA section. | |
162 This is not used directly, but only via inheritance by other faces." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
163 :group 'nxml-faces) |
86361 | 164 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
165 (defface nxml-ref |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
166 '((t (:inherit font-lock-constant-face))) |
86361 | 167 "Face used to highlight character and entity references. |
168 This is not used directly, but only via inheritance by other faces." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
169 :group 'nxml-faces) |
86361 | 170 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
171 (defface nxml-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
172 nil |
86361 | 173 "Face used to highlight delimiters. |
174 This is not used directly, but only via inheritance by other faces." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
175 :group 'nxml-faces) |
86361 | 176 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
177 (defface nxml-text |
86361 | 178 nil |
179 "Face used to highlight text." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
180 :group 'nxml-faces) |
86361 | 181 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
182 (defface nxml-comment-content |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
183 '((t (:inherit font-lock-comment-face))) |
86361 | 184 "Face used to highlight the content of comments." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
185 :group 'nxml-faces) |
86361 | 186 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
187 (defface nxml-comment-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
188 '((t (:inherit font-lock-comment-delimiter-face))) |
86361 | 189 "Face used for the delimiters of comments, i.e <!-- and -->." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
190 :group 'nxml-faces) |
86361 | 191 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
192 (defface nxml-processing-instruction-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
193 '((t (:inherit nxml-delimiter))) |
86361 | 194 "Face used for the delimiters of processing instructions, i.e <? and ?>." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
195 :group 'nxml-faces) |
86361 | 196 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
197 (defface nxml-processing-instruction-target |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
198 '((t (:inherit font-lock-keyword-face))) |
86361 | 199 "Face used for the target of processing instructions." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
200 :group 'nxml-faces) |
86361 | 201 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
202 (defface nxml-processing-instruction-content |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
203 '((t (:inherit nxml-delimited-data))) |
86361 | 204 "Face used for the content of processing instructions." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
205 :group 'nxml-faces) |
86361 | 206 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
207 (defface nxml-cdata-section-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
208 '((t (:inherit nxml-delimiter))) |
86361 | 209 "Face used for the delimiters of CDATA sections, i.e <![, [, and ]]>." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
210 :group 'nxml-faces) |
86361 | 211 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
212 (defface nxml-cdata-section-CDATA |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
213 '((t (:inherit nxml-name))) |
86361 | 214 "Face used for the CDATA keyword in CDATA sections." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
215 :group 'nxml-faces) |
86361 | 216 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
217 (defface nxml-cdata-section-content |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
218 '((t (:inherit nxml-text))) |
86361 | 219 "Face used for the content of CDATA sections." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
220 :group 'nxml-faces) |
86361 | 221 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
222 (defface nxml-char-ref-number |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
223 '((t (:inherit nxml-ref))) |
86361 | 224 "Face used for the number in character references. |
225 This includes ths `x' in hex references." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
226 :group 'nxml-faces) |
86361 | 227 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
228 (defface nxml-char-ref-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
229 '((t (:inherit nxml-ref))) |
86361 | 230 "Face used for the delimiters of character references, i.e &# and ;." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
231 :group 'nxml-faces) |
86361 | 232 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
233 (defface nxml-entity-ref-name |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
234 '((t (:inherit nxml-ref))) |
86361 | 235 "Face used for the entity name in general entity references." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
236 :group 'nxml-faces) |
86361 | 237 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
238 (defface nxml-entity-ref-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
239 '((t (:inherit nxml-ref))) |
86361 | 240 "Face used for the delimiters of entity references, i.e & and ;." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
241 :group 'nxml-faces) |
86361 | 242 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
243 (defface nxml-tag-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
244 '((t (:inherit nxml-delimiter))) |
86361 | 245 "Face used for the angle brackets delimiting tags. |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
246 `nxml-tag-slash' is used for slashes." |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
247 :group 'nxml-faces) |
86361 | 248 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
249 (defface nxml-tag-slash |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
250 '((t (:inherit nxml-tag-delimiter))) |
86361 | 251 "Face used for slashes in tags, both in end-tags and empty-elements." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
252 :group 'nxml-faces) |
86361 | 253 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
254 (defface nxml-element-prefix |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
255 '((t (:inherit nxml-name))) |
86361 | 256 "Face used for the prefix of elements." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
257 :group 'nxml-faces) |
86361 | 258 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
259 (defface nxml-element-colon |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
260 nil |
86361 | 261 "Face used for the colon in element names." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
262 :group 'nxml-faces) |
86361 | 263 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
264 (defface nxml-element-local-name |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
265 '((t (:inherit font-lock-function-name-face))) |
86361 | 266 "Face used for the local name of elements." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
267 :group 'nxml-faces) |
86361 | 268 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
269 (defface nxml-attribute-prefix |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
270 '((t (:inherit nxml-name))) |
86361 | 271 "Face used for the prefix of attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
272 :group 'nxml-faces) |
86361 | 273 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
274 (defface nxml-attribute-colon |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
275 '((t (:inherit nxml-delimiter))) |
86361 | 276 "Face used for the colon in attribute names." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
277 :group 'nxml-faces) |
86361 | 278 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
279 (defface nxml-attribute-local-name |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
280 '((t (:inherit font-lock-variable-name-face))) |
86361 | 281 "Face used for the local name of attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
282 :group 'nxml-faces) |
86361 | 283 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
284 (defface nxml-namespace-attribute-xmlns |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
285 '((t (:inherit nxml-attribute-prefix))) |
86361 | 286 "Face used for `xmlns' in namespace attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
287 :group 'nxml-faces) |
86361 | 288 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
289 (defface nxml-namespace-attribute-colon |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
290 '((t (:inherit nxml-attribute-colon))) |
86361 | 291 "Face used for the colon in namespace attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
292 :group 'nxml-faces) |
86361 | 293 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
294 (defface nxml-namespace-attribute-prefix |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
295 '((t (:inherit nxml-attribute-local-name))) |
86361 | 296 "Face used for the prefix declared in namespace attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
297 :group 'nxml-faces) |
86361 | 298 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
299 (defface nxml-attribute-value |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
300 '((t (:inherit font-lock-string-face))) |
86361 | 301 "Face used for the value of attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
302 :group 'nxml-faces) |
86361 | 303 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
304 (defface nxml-attribute-value-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
305 '((t (:inherit nxml-attribute-value))) |
86361 | 306 "Face used for the delimiters of attribute values." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
307 :group 'nxml-faces) |
86361 | 308 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
309 (defface nxml-namespace-attribute-value |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
310 '((t (:inherit nxml-attribute-value))) |
86361 | 311 "Face used for the value of namespace attributes." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
312 :group 'nxml-faces) |
86361 | 313 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
314 (defface nxml-namespace-attribute-value-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
315 '((t (:inherit nxml-attribute-value-delimiter))) |
86361 | 316 "Face used for the delimiters of namespace attribute values." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
317 :group 'nxml-faces) |
86361 | 318 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
319 (defface nxml-prolog-literal-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
320 '((t (:inherit nxml-delimited-data))) |
86361 | 321 "Face used for the delimiters of literals in the prolog." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
322 :group 'nxml-faces) |
86361 | 323 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
324 (defface nxml-prolog-literal-content |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
325 '((t (:inherit nxml-delimited-data))) |
86361 | 326 "Face used for the content of literals in the prolog." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
327 :group 'nxml-faces) |
86361 | 328 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
329 (defface nxml-prolog-keyword |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
330 '((t (:inherit font-lock-keyword-face))) |
86361 | 331 "Face used for keywords in the prolog." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
332 :group 'nxml-faces) |
86361 | 333 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
334 (defface nxml-markup-declaration-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
335 '((t (:inherit nxml-delimiter))) |
86361 | 336 "Face used for the delimiters of markup declarations in the prolog. |
337 The delimiters are <! and >." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
338 :group 'nxml-faces) |
86361 | 339 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
340 (defface nxml-hash |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
341 '((t (:inherit nxml-name))) |
86361 | 342 "Face used for # before a name in the prolog." |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
343 :group 'nxml-faces) |
86361 | 344 |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
345 (defface nxml-glyph |
86361 | 346 '((((type x)) |
347 (:family | |
348 "misc-fixed" | |
349 :background | |
350 "light grey" | |
351 :foreground | |
352 "black" | |
353 :weight | |
354 normal | |
355 :slant | |
356 normal)) | |
357 (t | |
358 (:background | |
359 "light grey" | |
360 :foreground | |
361 "black" | |
362 :weight | |
363 normal | |
364 :slant | |
365 normal))) | |
366 "Face used for glyph for char references." | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
367 :group 'nxml-faces) |
86361 | 368 |
369 ;;; Global variables | |
370 | |
371 (defvar nxml-prolog-regions nil | |
372 "List of regions in the prolog to be fontified. | |
373 See the function `xmltok-forward-prolog' for more information.") | |
374 (make-variable-buffer-local 'nxml-prolog-regions) | |
375 | |
376 (defvar nxml-last-fontify-end nil | |
377 "Position where fontification last ended. | |
378 Nil if the buffer changed since the last fontification.") | |
379 (make-variable-buffer-local 'nxml-last-fontify-end) | |
380 | |
381 (defvar nxml-degraded nil | |
382 "Non-nil if currently operating in degraded mode. | |
383 Degraded mode is enabled when an internal error is encountered in the | |
384 fontification or after-change functions.") | |
385 (make-variable-buffer-local 'nxml-degraded) | |
386 | |
387 (defvar nxml-completion-hook nil | |
388 "Hook run by `nxml-complete'. | |
389 This hook is run until success.") | |
390 | |
391 (defvar nxml-in-mixed-content-hook nil | |
392 "Hook to determine whether point is in mixed content. | |
393 The hook is called without arguments. It should return nil if it is | |
394 definitely not mixed; non-nil otherwise. The hook will be run until | |
395 one of the functions returns nil.") | |
396 | |
397 (defvar nxml-mixed-scan-distance 4000 | |
398 "Maximum distance from point to scan when checking for mixed content.") | |
399 | |
400 (defvar nxml-end-tag-indent-scan-distance 4000 | |
401 "Maximum distance from point to scan backwards when indenting end-tag.") | |
402 | |
403 (defvar nxml-char-ref-extra-display t | |
404 "Non-nil means display extra information for character references. | |
405 The extra information consists of a tooltip with the character name | |
406 and, if `nxml-char-ref-display-glyph-flag' is non-nil, a glyph | |
407 corresponding to the referenced character following the character | |
408 reference.") | |
409 (make-variable-buffer-local 'nxml-char-ref-extra-display) | |
410 | |
411 (defvar nxml-mode-map | |
412 (let ((map (make-sparse-keymap))) | |
413 (define-key map "\M-\C-u" 'nxml-backward-up-element) | |
414 (define-key map "\M-\C-d" 'nxml-down-element) | |
415 (define-key map "\M-\C-n" 'nxml-forward-element) | |
416 (define-key map "\M-\C-p" 'nxml-backward-element) | |
417 (define-key map "\M-{" 'nxml-backward-paragraph) | |
418 (define-key map "\M-}" 'nxml-forward-paragraph) | |
419 (define-key map "\M-h" 'nxml-mark-paragraph) | |
420 (define-key map "\C-c\C-f" 'nxml-finish-element) | |
421 (define-key map "\C-c\C-m" 'nxml-split-element) | |
422 (define-key map "\C-c\C-b" 'nxml-balanced-close-start-tag-block) | |
423 (define-key map "\C-c\C-i" 'nxml-balanced-close-start-tag-inline) | |
424 (define-key map "\C-c\C-x" 'nxml-insert-xml-declaration) | |
425 (define-key map "\C-c\C-d" 'nxml-dynamic-markup-word) | |
426 ;; u is for Unicode | |
427 (define-key map "\C-c\C-u" 'nxml-insert-named-char) | |
428 (define-key map "\C-c\C-o" nxml-outline-prefix-map) | |
429 (define-key map [S-mouse-2] 'nxml-mouse-hide-direct-text-content) | |
430 (define-key map "/" 'nxml-electric-slash) | |
431 (define-key map [C-return] 'nxml-complete) | |
432 (when nxml-bind-meta-tab-to-complete-flag | |
433 (define-key map "\M-\t" 'nxml-complete)) | |
434 map) | |
435 "Keymap for nxml-mode.") | |
436 | |
437 (defsubst nxml-set-face (start end face) | |
438 (when (and face (< start end)) | |
439 (put-text-property start end 'face face))) | |
440 | |
441 (defun nxml-clear-face (start end) | |
442 (remove-text-properties start end '(face nil)) | |
443 (nxml-clear-char-ref-extra-display start end)) | |
444 | |
445 (defsubst nxml-set-fontified (start end) | |
446 (put-text-property start end 'fontified t)) | |
447 | |
448 (defsubst nxml-clear-fontified (start end) | |
449 (remove-text-properties start end '(fontified nil))) | |
450 | |
451 ;;;###autoload | |
452 (defun nxml-mode () | |
453 ;; We use C-c C-i instead of \\[nxml-balanced-close-start-tag-inline] | |
454 ;; because Emacs turns C-c C-i into C-c TAB which is hard to type and | |
455 ;; not mnemonic. | |
456 "Major mode for editing XML. | |
457 | |
458 Syntax highlighting is performed unless the variable | |
459 `nxml-syntax-highlight-flag' is nil. | |
460 | |
461 \\[nxml-finish-element] finishes the current element by inserting an end-tag. | |
462 C-c C-i closes a start-tag with `>' and then inserts a balancing end-tag | |
463 leaving point between the start-tag and end-tag. | |
464 \\[nxml-balanced-close-start-tag-block] is similar but for block rather than inline elements: | |
465 the start-tag, point, and end-tag are all left on separate lines. | |
466 If `nxml-slash-auto-complete-flag' is non-nil, then inserting a `</' | |
467 automatically inserts the rest of the end-tag. | |
468 | |
469 \\[nxml-complete] performs completion on the symbol preceding point. | |
470 | |
471 \\[nxml-dynamic-markup-word] uses the contents of the current buffer | |
472 to choose a tag to put around the word preceding point. | |
473 | |
474 Sections of the document can be displayed in outline form. The | |
475 variable `nxml-section-element-name-regexp' controls when an element | |
476 is recognized as a section. The same key sequences that change | |
477 visibility in outline mode are used except that they start with C-c C-o | |
478 instead of C-c. | |
479 | |
480 Validation is provided by the related minor-mode `rng-validate-mode'. | |
481 This also makes completion schema- and context- sensitive. Element | |
482 names, attribute names, attribute values and namespace URIs can all be | |
87712
a9f53375739a
(nxml-mode): Call rng-nxml-mode-init directly.
Jason Rumney <jasonr@gnu.org>
parents:
87665
diff
changeset
|
483 completed. By default, `rng-validate-mode' is automatically enabled. You |
a9f53375739a
(nxml-mode): Call rng-nxml-mode-init directly.
Jason Rumney <jasonr@gnu.org>
parents:
87665
diff
changeset
|
484 can toggle it using \\[rng-validate-mode] or change the default by |
a9f53375739a
(nxml-mode): Call rng-nxml-mode-init directly.
Jason Rumney <jasonr@gnu.org>
parents:
87665
diff
changeset
|
485 customizing `rng-nxml-auto-validate-flag'. |
86361 | 486 |
487 \\[indent-for-tab-command] indents the current line appropriately. | |
488 This can be customized using the variable `nxml-child-indent' | |
489 and the variable `nxml-attribute-indent'. | |
490 | |
491 \\[nxml-insert-named-char] inserts a character reference using | |
492 the character's name (by default, the Unicode name). \\[universal-argument] \\[nxml-insert-named-char] | |
493 inserts the character directly. | |
494 | |
495 The Emacs commands that normally operate on balanced expressions will | |
496 operate on XML markup items. Thus \\[forward-sexp] will move forward | |
497 across one markup item; \\[backward-sexp] will move backward across | |
498 one markup item; \\[kill-sexp] will kill the following markup item; | |
499 \\[mark-sexp] will mark the following markup item. By default, each | |
500 tag each treated as a single markup item; to make the complete element | |
501 be treated as a single markup item, set the variable | |
502 `nxml-sexp-element-flag' to t. For more details, see the function | |
503 `nxml-forward-balanced-item'. | |
504 | |
505 \\[nxml-backward-up-element] and \\[nxml-down-element] move up and down the element structure. | |
506 | |
507 Many aspects this mode can be customized using | |
508 \\[customize-group] nxml RET." | |
509 (interactive) | |
510 (kill-all-local-variables) | |
511 (setq major-mode 'nxml-mode) | |
512 (setq mode-name "nXML") | |
87793
b0683497550c
(nxml-mode): Use mode-line-process to indicate the use of degraded mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87719
diff
changeset
|
513 (set (make-local-variable 'mode-line-process) '((nxml-degraded "/degraded"))) |
86361 | 514 ;; We'll determine the fill prefix ourselves |
515 (make-local-variable 'adaptive-fill-mode) | |
516 (setq adaptive-fill-mode nil) | |
517 (make-local-variable 'forward-sexp-function) | |
518 (setq forward-sexp-function 'nxml-forward-balanced-item) | |
519 (make-local-variable 'indent-line-function) | |
520 (setq indent-line-function 'nxml-indent-line) | |
521 (make-local-variable 'fill-paragraph-function) | |
522 (setq fill-paragraph-function 'nxml-do-fill-paragraph) | |
523 ;; Comment support | |
524 ;; This doesn't seem to work too well; | |
525 ;; I think we should probably roll our own nxml-comment-dwim function. | |
526 (make-local-variable 'comment-indent-function) | |
527 (setq comment-indent-function 'nxml-indent-line) | |
528 (make-local-variable 'comment-start) | |
529 (setq comment-start "<!--") | |
530 (make-local-variable 'comment-start-skip) | |
531 (setq comment-start-skip "<!--[ \t\r\n]*") | |
532 (make-local-variable 'comment-end) | |
533 (setq comment-end "-->") | |
534 (make-local-variable 'comment-end-skip) | |
535 (setq comment-end-skip "[ \t\r\n]*-->") | |
536 (make-local-variable 'comment-line-break-function) | |
537 (setq comment-line-break-function 'nxml-newline-and-indent) | |
538 (use-local-map nxml-mode-map) | |
539 (save-excursion | |
540 (save-restriction | |
541 (widen) | |
542 (nxml-clear-dependent-regions (point-min) (point-max)) | |
543 (setq nxml-scan-end (copy-marker (point-min) nil)) | |
544 (nxml-with-unmodifying-text-property-changes | |
545 (when nxml-syntax-highlight-flag | |
546 (nxml-clear-fontified (point-min) (point-max))) | |
547 (nxml-clear-inside (point-min) (point-max)) | |
548 (nxml-with-invisible-motion | |
549 (nxml-scan-prolog))))) | |
550 (when nxml-syntax-highlight-flag | |
551 (add-hook 'fontification-functions 'nxml-fontify nil t)) | |
552 (add-hook 'after-change-functions 'nxml-after-change nil t) | |
93917
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
553 (add-hook 'change-major-mode-hook 'nxml-cleanup nil t) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
554 |
91924
b6c62ca6da76
(nxml-mode): Don't add a write-contents-hook.
Jason Rumney <jasonr@gnu.org>
parents:
87793
diff
changeset
|
555 ;; Emacs 23 handles the encoding attribute on the xml declaration |
b6c62ca6da76
(nxml-mode): Don't add a write-contents-hook.
Jason Rumney <jasonr@gnu.org>
parents:
87793
diff
changeset
|
556 ;; transparently to nxml-mode, so there is no longer a need for the below |
b6c62ca6da76
(nxml-mode): Don't add a write-contents-hook.
Jason Rumney <jasonr@gnu.org>
parents:
87793
diff
changeset
|
557 ;; hook. The hook also had the drawback of overriding explicit user |
b6c62ca6da76
(nxml-mode): Don't add a write-contents-hook.
Jason Rumney <jasonr@gnu.org>
parents:
87793
diff
changeset
|
558 ;; instruction to save as some encoding other than utf-8. |
b6c62ca6da76
(nxml-mode): Don't add a write-contents-hook.
Jason Rumney <jasonr@gnu.org>
parents:
87793
diff
changeset
|
559 ;;; (add-hook 'write-contents-hooks 'nxml-prepare-to-save) |
86361 | 560 (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name)))) |
561 (when (and nxml-default-buffer-file-coding-system | |
562 (not (local-variable-p 'buffer-file-coding-system))) | |
563 (setq buffer-file-coding-system nxml-default-buffer-file-coding-system)) | |
564 (when nxml-auto-insert-xml-declaration-flag | |
565 (nxml-insert-xml-declaration))) | |
87712
a9f53375739a
(nxml-mode): Call rng-nxml-mode-init directly.
Jason Rumney <jasonr@gnu.org>
parents:
87665
diff
changeset
|
566 (rng-nxml-mode-init) |
87715
39844b05431b
(nxml-char-name-ignore-case): Change default value.
Jason Rumney <jasonr@gnu.org>
parents:
87712
diff
changeset
|
567 (nxml-enable-unicode-char-name-sets) |
86361 | 568 (run-hooks 'nxml-mode-hook)) |
569 | |
93917
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
570 (defun nxml-cleanup () |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
571 "Clean up after nxml-mode." |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
572 ;; Disable associated minor modes. |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
573 (rng-validate-mode -1) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
574 ;; Clean up fontification. |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
575 (save-excursion |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
576 (widen) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
577 (let ((inhibit-read-only t) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
578 (buffer-undo-list t) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
579 (modified (buffer-modified-p))) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
580 (nxml-with-invisible-motion |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
581 (remove-text-properties (point-min) (point-max) '(face))) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
582 (set-buffer-modified-p modified))) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
583 (remove-hook 'change-major-mode-hook 'nxml-cleanup t)) |
3fad91a9740c
2008-04-09 Lennart Borgman <lennart.borgman@gmail.com>
Jason Rumney <jasonr@gnu.org>
parents:
91924
diff
changeset
|
584 |
86361 | 585 (defun nxml-degrade (context err) |
586 (message "Internal nXML mode error in %s (%s), degrading" | |
587 context | |
588 (error-message-string err)) | |
589 (ding) | |
590 (setq nxml-degraded t) | |
591 (setq nxml-prolog-end 1) | |
592 (save-excursion | |
593 (save-restriction | |
594 (widen) | |
595 (nxml-with-unmodifying-text-property-changes | |
596 (nxml-clear-face (point-min) (point-max)) | |
597 (nxml-set-fontified (point-min) (point-max)) | |
87793
b0683497550c
(nxml-mode): Use mode-line-process to indicate the use of degraded mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87719
diff
changeset
|
598 (nxml-clear-inside (point-min) (point-max)))))) |
86361 | 599 |
600 ;;; Change management | |
601 | |
602 (defun nxml-after-change (start end pre-change-length) | |
603 ;; Work around bug in insert-file-contents. | |
604 (when (> end (1+ (buffer-size))) | |
605 (setq start 1) | |
606 (setq end (1+ (buffer-size)))) | |
607 (unless nxml-degraded | |
608 (condition-case err | |
609 (save-excursion | |
610 (save-restriction | |
611 (widen) | |
612 (save-match-data | |
613 (nxml-with-invisible-motion | |
614 (nxml-with-unmodifying-text-property-changes | |
615 (nxml-after-change1 start end pre-change-length)))))) | |
616 (error | |
617 (nxml-degrade 'nxml-after-change err))))) | |
618 | |
619 (defun nxml-after-change1 (start end pre-change-length) | |
620 (setq nxml-last-fontify-end nil) | |
621 (let ((pre-change-end (+ start pre-change-length))) | |
622 (setq start | |
623 (nxml-adjust-start-for-dependent-regions start | |
624 end | |
625 pre-change-length)) | |
626 (when (<= start | |
627 ;; Add 2 so as to include the < and following char | |
628 ;; that start the instance, since changing these | |
629 ;; can change where the prolog ends. | |
630 (+ nxml-prolog-end 2)) | |
631 ;; end must be extended to at least the end of the old prolog | |
632 (when (< pre-change-end nxml-prolog-end) | |
633 (setq end | |
634 ;; don't let end get out of range even if pre-change-length | |
635 ;; is bogus | |
636 (min (point-max) | |
637 (+ end (- nxml-prolog-end pre-change-end))))) | |
638 (nxml-scan-prolog))) | |
639 (cond ((<= end nxml-prolog-end) | |
640 (setq end nxml-prolog-end) | |
641 (goto-char start) | |
642 ;; This is so that Emacs redisplay works | |
643 (setq start (line-beginning-position))) | |
644 ((and (<= start nxml-scan-end) | |
645 (> start (point-min)) | |
646 (nxml-get-inside (1- start))) | |
647 ;; The closing delimiter might have been removed. | |
648 ;; So we may need to redisplay from the beginning | |
649 ;; of the token. | |
650 (goto-char (1- start)) | |
651 (nxml-move-outside-backwards) | |
652 ;; This is so that Emacs redisplay works | |
653 (setq start (line-beginning-position)) | |
654 (setq end (max (nxml-scan-after-change (point) end) | |
655 end))) | |
656 (t | |
657 (goto-char start) | |
658 ;; This is both for redisplay and to move back | |
659 ;; past any incomplete opening delimiters | |
660 (setq start (line-beginning-position)) | |
661 (setq end (max (nxml-scan-after-change start end) | |
662 end)))) | |
663 (when nxml-syntax-highlight-flag | |
664 (when (>= start end) | |
665 ;; Must clear at least one char so as to trigger redisplay. | |
666 (cond ((< start (point-max)) | |
667 (setq end (1+ start))) | |
668 (t | |
669 (setq end (point-max)) | |
670 (goto-char end) | |
671 (setq start (line-beginning-position))))) | |
672 (nxml-clear-fontified start end))) | |
673 | |
674 ;;; Encodings | |
675 | |
676 (defun nxml-insert-xml-declaration () | |
677 "Insert an XML declaration at the beginning of buffer. | |
678 The XML declaration will declare an encoding depending on the buffer's | |
679 `buffer-file-coding-system'." | |
680 (interactive "*") | |
681 (let ((coding-system | |
682 (if (and buffer-file-coding-system | |
683 (coding-system-p buffer-file-coding-system) | |
684 (coding-system-get buffer-file-coding-system | |
685 'mime-charset)) | |
686 buffer-file-coding-system | |
687 (nxml-choose-utf-coding-system)))) | |
688 (goto-char (point-min)) | |
689 (insert (format "<?xml version=\"1.0\" encoding=\"%s\"?>\n" | |
690 (nxml-coding-system-name coding-system))))) | |
691 | |
692 (defun nxml-prepare-to-save () | |
693 (unless (and (not enable-multibyte-characters) | |
694 (local-variable-p 'buffer-file-coding-system) | |
695 buffer-file-coding-system | |
696 (or (eq (coding-system-type buffer-file-coding-system) 5) | |
697 (eq buffer-file-coding-system 'no-conversion))) | |
698 (save-excursion | |
699 (setq buffer-file-coding-system (nxml-select-coding-system)))) | |
700 ;; nil from a function in `write-contents-hooks' means | |
701 ;; to continue and write the file as normal | |
702 nil) | |
703 | |
704 (defun nxml-select-coding-system () | |
705 (let* ((suitable-coding-systems | |
706 (find-coding-systems-region (point-min) (point-max))) | |
707 (enc-pos (progn | |
708 (goto-char (point-min)) | |
709 (xmltok-get-declared-encoding-position))) | |
710 (enc-name | |
711 (and (consp enc-pos) | |
712 (buffer-substring-no-properties (car enc-pos) | |
713 (cdr enc-pos)))) | |
714 (coding-system | |
715 (cond (enc-name | |
716 (if (string= (downcase enc-name) "utf-16") | |
717 (nxml-choose-utf-16-coding-system) | |
718 (nxml-mime-charset-coding-system enc-name))) | |
719 (enc-pos (nxml-choose-utf-coding-system))))) | |
720 ;; Make sure we have a coding-system | |
721 (unless coding-system | |
722 (setq coding-system | |
723 (and (not buffer-read-only) | |
724 (nxml-choose-suitable-coding-system | |
725 suitable-coding-systems))) | |
726 (let ((message | |
727 (if enc-name | |
728 (format "Unknown encoding %s" enc-name) | |
729 "XML declaration is not well-formed"))) | |
730 (cond ((not coding-system) | |
731 (error "%s" message)) | |
732 ((y-or-n-p | |
733 (concat message | |
734 ". " | |
735 (format (if enc-name | |
736 "Save with %s" | |
737 "Modify and save with encoding %s") | |
738 (nxml-coding-system-name coding-system)) | |
739 " ")) | |
740 (nxml-fix-encoding-declaration enc-pos coding-system)) | |
741 (t (signal 'quit nil))))) | |
742 ;; Make sure it can encode all the characters in the buffer | |
743 (unless (or (memq (coding-system-base coding-system) | |
744 suitable-coding-systems) | |
745 (equal suitable-coding-systems '(undecided))) | |
746 (let ((message | |
747 (nxml-unsuitable-coding-system-message coding-system | |
748 enc-name))) | |
749 (setq coding-system | |
750 (and (not buffer-read-only) | |
751 (nxml-choose-suitable-coding-system | |
752 suitable-coding-systems))) | |
753 (cond ((not coding-system) (error "%s" message)) | |
754 ((y-or-n-p (concat message | |
755 (format ". Save with %s " | |
756 (nxml-coding-system-name | |
757 coding-system)))) | |
758 (nxml-fix-encoding-declaration enc-pos coding-system)) | |
759 (t (signal 'quit nil))))) | |
760 ;; Merge the newline type of our existing encoding | |
761 (let ((current-eol-type | |
762 (coding-system-eol-type buffer-file-coding-system))) | |
763 (when (and current-eol-type (integerp current-eol-type)) | |
764 (setq coding-system | |
765 (coding-system-change-eol-conversion coding-system | |
766 current-eol-type)))) | |
767 coding-system)) | |
768 | |
769 (defun nxml-unsuitable-coding-system-message (coding-system &optional enc-name) | |
770 (if (nxml-coding-system-unicode-p coding-system) | |
771 "Cannot translate some characters to Unicode" | |
772 (format "Cannot encode some characters with %s" | |
773 (or enc-name | |
774 (nxml-coding-system-name coding-system))))) | |
775 | |
776 (defconst nxml-utf-16-coding-systems (and (coding-system-p 'utf-16-be) | |
777 (coding-system-p 'utf-16-le) | |
778 '(utf-16-be utf-16-le))) | |
779 | |
780 (defconst nxml-utf-coding-systems (cons 'utf-8 nxml-utf-16-coding-systems)) | |
781 | |
782 (defun nxml-coding-system-unicode-p (coding-system) | |
783 (nxml-coding-system-member (coding-system-base coding-system) | |
784 nxml-utf-coding-systems)) | |
785 | |
786 (defun nxml-coding-system-name (coding-system) | |
787 (setq coding-system (coding-system-base coding-system)) | |
788 (symbol-name | |
789 (if (nxml-coding-system-member coding-system nxml-utf-16-coding-systems) | |
790 'utf-16 | |
791 (or (coding-system-get coding-system 'mime-charset) | |
792 coding-system)))) | |
793 | |
794 (defun nxml-fix-encoding-declaration (enc-pos coding-system) | |
795 (let ((charset (nxml-coding-system-name coding-system))) | |
796 (cond ((consp enc-pos) | |
797 (delete-region (car enc-pos) (cdr enc-pos)) | |
798 (goto-char (car enc-pos)) | |
799 (insert charset)) | |
800 ((integerp enc-pos) | |
801 (goto-char enc-pos) | |
802 (insert " encoding=\"" charset ?\")) | |
803 (t | |
804 (goto-char (point-min)) | |
805 (insert "<?xml version=\"1.0\" encoding=\"" | |
806 charset | |
807 "\"?>\n") | |
808 (when (and (not enc-pos) | |
809 (let ((case-fold-search t)) | |
810 (looking-at xmltok-bad-xml-decl-regexp))) | |
811 (delete-region (point) (match-end 0))))))) | |
812 | |
813 (defun nxml-choose-suitable-coding-system (suitable-coding-systems) | |
814 (let (ret coding-system) | |
815 (if (and buffer-file-coding-system | |
816 (memq (coding-system-base buffer-file-coding-system) | |
817 suitable-coding-systems)) | |
818 buffer-file-coding-system | |
819 (while (and suitable-coding-systems (not ret)) | |
820 (setq coding-system (car suitable-coding-systems)) | |
821 (if (coding-system-get coding-system 'mime-charset) | |
822 (setq ret coding-system) | |
823 (setq suitable-coding-systems (cdr suitable-coding-systems)))) | |
824 ret))) | |
825 | |
826 (defun nxml-choose-utf-coding-system () | |
827 (let ((cur (and (local-variable-p 'buffer-file-coding-system) | |
828 buffer-file-coding-system | |
829 (coding-system-base buffer-file-coding-system)))) | |
830 (cond ((car (nxml-coding-system-member cur nxml-utf-coding-systems))) | |
831 ((and nxml-prefer-utf-16-to-utf-8-flag | |
832 (coding-system-p 'utf-16-le) | |
833 (coding-system-p 'utf-16-be)) | |
834 (if nxml-prefer-utf-16-little-to-big-endian-flag | |
835 'utf-16-le | |
836 'utf-16-be)) | |
837 (t 'utf-8)))) | |
838 | |
839 (defun nxml-choose-utf-16-coding-system () | |
840 (let ((cur (and (local-variable-p 'buffer-file-coding-system) | |
841 buffer-file-coding-system | |
842 (coding-system-base buffer-file-coding-system)))) | |
843 (cond ((car (nxml-coding-system-member cur nxml-utf-16-coding-systems))) | |
844 (nxml-prefer-utf-16-little-to-big-endian-flag | |
845 (and (coding-system-p 'utf-16-le) 'utf-16-le)) | |
846 (t (and (coding-system-p 'utf-16-be) 'utf-16-be))))) | |
847 | |
848 (defun nxml-coding-system-member (coding-system coding-systems) | |
849 (let (ret) | |
850 (while (and coding-systems (not ret)) | |
851 (if (coding-system-equal coding-system | |
852 (car coding-systems)) | |
853 (setq ret coding-systems) | |
854 (setq coding-systems (cdr coding-systems)))) | |
855 ret)) | |
856 | |
857 ;;; Fontification | |
858 | |
859 (defun nxml-fontify (start) | |
860 (condition-case err | |
861 (save-excursion | |
862 (save-restriction | |
863 (widen) | |
864 (save-match-data | |
865 (nxml-with-invisible-motion | |
866 (nxml-with-unmodifying-text-property-changes | |
867 (if (or nxml-degraded | |
868 ;; just in case we get called in the wrong buffer | |
869 (not nxml-prolog-end)) | |
870 (nxml-set-fontified start (point-max)) | |
871 (nxml-fontify1 start))))))) | |
872 (error | |
873 (nxml-degrade 'nxml-fontify err)))) | |
874 | |
875 (defun nxml-fontify1 (start) | |
876 (cond ((< start nxml-prolog-end) | |
877 (nxml-fontify-prolog) | |
878 (nxml-set-fontified (point-min) | |
879 nxml-prolog-end)) | |
880 (t | |
881 (goto-char start) | |
882 (when (not (eq nxml-last-fontify-end start)) | |
883 (when (not (equal (char-after) ?\<)) | |
884 (search-backward "<" nxml-prolog-end t)) | |
885 (nxml-ensure-scan-up-to-date) | |
886 (nxml-move-outside-backwards)) | |
887 (let ((start (point))) | |
888 (nxml-do-fontify (min (point-max) | |
889 (+ start nxml-fontify-chunk-size))) | |
890 (setq nxml-last-fontify-end (point)) | |
891 (nxml-set-fontified start nxml-last-fontify-end))))) | |
892 | |
893 (defun nxml-fontify-buffer () | |
894 (interactive) | |
895 (save-excursion | |
896 (save-restriction | |
897 (widen) | |
898 (nxml-with-invisible-motion | |
899 (goto-char (point-min)) | |
900 (nxml-with-unmodifying-text-property-changes | |
901 (nxml-fontify-prolog) | |
902 (goto-char nxml-prolog-end) | |
903 (nxml-do-fontify)))))) | |
904 | |
905 (defun nxml-fontify-prolog () | |
906 "Fontify the prolog. | |
907 The buffer is assumed to be prepared for fontification. | |
908 This does not set the fontified property, but it does clear | |
909 faces appropriately." | |
910 (let ((regions nxml-prolog-regions)) | |
911 (nxml-clear-face (point-min) nxml-prolog-end) | |
912 (while regions | |
913 (let ((region (car regions))) | |
914 (nxml-apply-fontify-rule (aref region 0) | |
915 (aref region 1) | |
916 (aref region 2))) | |
917 (setq regions (cdr regions))))) | |
918 | |
919 (defun nxml-do-fontify (&optional bound) | |
920 "Fontify at least as far as bound. | |
921 Leave point after last fontified position." | |
922 (unless bound (setq bound (point-max))) | |
923 (let (xmltok-dependent-regions | |
924 xmltok-errors) | |
925 (while (and (< (point) bound) | |
926 (nxml-tokenize-forward)) | |
927 (nxml-clear-face xmltok-start (point)) | |
928 (nxml-apply-fontify-rule)))) | |
929 | |
930 ;; Vectors identify a substring of the token to be highlighted in some face. | |
931 | |
932 ;; Token types returned by xmltok-forward. | |
933 | |
934 (put 'start-tag | |
935 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
936 '([nil 1 nxml-tag-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
937 [-1 nil nxml-tag-delimiter] |
86361 | 938 (element-qname . 1) |
939 attributes)) | |
940 | |
941 (put 'partial-start-tag | |
942 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
943 '([nil 1 nxml-tag-delimiter] |
86361 | 944 (element-qname . 1) |
945 attributes)) | |
946 | |
947 (put 'end-tag | |
948 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
949 '([nil 1 nxml-tag-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
950 [1 2 nxml-tag-slash] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
951 [-1 nil nxml-tag-delimiter] |
86361 | 952 (element-qname . 2))) |
953 | |
954 (put 'partial-end-tag | |
955 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
956 '([nil 1 nxml-tag-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
957 [1 2 nxml-tag-slash] |
86361 | 958 (element-qname . 2))) |
959 | |
960 (put 'empty-element | |
961 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
962 '([nil 1 nxml-tag-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
963 [-2 -1 nxml-tag-slash] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
964 [-1 nil nxml-tag-delimiter] |
86361 | 965 (element-qname . 1) |
966 attributes)) | |
967 | |
968 (put 'partial-empty-element | |
969 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
970 '([nil 1 nxml-tag-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
971 [-1 nil nxml-tag-slash] |
86361 | 972 (element-qname . 1) |
973 attributes)) | |
974 | |
975 (put 'char-ref | |
976 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
977 '([nil 2 nxml-char-ref-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
978 [2 -1 nxml-char-ref-number] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
979 [-1 nil nxml-char-ref-delimiter] |
86361 | 980 char-ref)) |
981 | |
982 (put 'entity-ref | |
983 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
984 '([nil 1 nxml-entity-ref-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
985 [1 -1 nxml-entity-ref-name] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
986 [-1 nil nxml-entity-ref-delimiter])) |
86361 | 987 |
988 (put 'comment | |
989 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
990 '([nil 4 nxml-comment-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
991 [4 -3 nxml-comment-content] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
992 [-3 nil nxml-comment-delimiter])) |
86361 | 993 |
994 (put 'processing-instruction | |
995 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
996 '([nil 2 nxml-processing-instruction-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
997 [-2 nil nxml-processing-instruction-delimiter] |
86361 | 998 processing-instruction-content)) |
999 | |
1000 (put 'cdata-section | |
1001 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1002 '([nil 3 nxml-cdata-section-delimiter] ; <![ |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1003 [3 8 nxml-cdata-section-CDATA] ; CDATA |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1004 [8 9 nxml-cdata-section-delimiter] ; [ |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1005 [9 -3 nxml-cdata-section-content] ; ]]> |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1006 [-3 nil nxml-cdata-section-delimiter])) |
86361 | 1007 |
1008 (put 'data | |
1009 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1010 '([nil nil nxml-text])) |
86361 | 1011 |
1012 ;; Prolog region types in list returned by xmltok-forward-prolog. | |
1013 | |
1014 (put 'xml-declaration | |
1015 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1016 '([nil 2 nxml-processing-instruction-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1017 [2 5 nxml-processing-instruction-target] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1018 [-2 nil nxml-processing-instruction-delimiter])) |
86361 | 1019 |
1020 (put 'xml-declaration-attribute-name | |
1021 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1022 '([nil nil nxml-attribute-local-name])) |
86361 | 1023 |
1024 (put 'xml-declaration-attribute-value | |
1025 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1026 '([nil 1 nxml-attribute-value-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1027 [1 -1 nxml-attribute-value] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1028 [-1 nil nxml-attribute-value-delimiter])) |
86361 | 1029 |
1030 (put 'processing-instruction-left | |
1031 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1032 '([nil 2 nxml-processing-instruction-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1033 [2 nil nxml-processing-instruction-target])) |
86361 | 1034 |
1035 (put 'processing-instruction-right | |
1036 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1037 '([nil -2 nxml-processing-instruction-content] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1038 [-2 nil nxml-processing-instruction-delimiter])) |
86361 | 1039 |
1040 (put 'literal | |
1041 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1042 '([nil 1 nxml-prolog-literal-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1043 [1 -1 nxml-prolog-literal-content] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1044 [-1 nil nxml-prolog-literal-delimiter])) |
86361 | 1045 |
1046 (put 'keyword | |
1047 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1048 '([nil nil nxml-prolog-keyword])) |
86361 | 1049 |
1050 (put 'markup-declaration-open | |
1051 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1052 '([0 2 nxml-markup-declaration-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1053 [2 nil nxml-prolog-keyword])) |
86361 | 1054 |
1055 (put 'markup-declaration-close | |
1056 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1057 '([nil nil nxml-markup-declaration-delimiter])) |
86361 | 1058 |
1059 (put 'internal-subset-open | |
1060 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1061 '([nil nil nxml-markup-declaration-delimiter])) |
86361 | 1062 |
1063 (put 'internal-subset-close | |
1064 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1065 '([nil 1 nxml-markup-declaration-delimiter] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1066 [-1 nil nxml-markup-declaration-delimiter])) |
86361 | 1067 |
1068 (put 'hash-name | |
1069 'nxml-fontify-rule | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1070 '([nil 1 nxml-hash] |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1071 [1 nil nxml-prolog-keyword])) |
86361 | 1072 |
1073 (defun nxml-apply-fontify-rule (&optional type start end) | |
1074 (let ((rule (get (or type xmltok-type) 'nxml-fontify-rule))) | |
1075 (unless start (setq start xmltok-start)) | |
1076 (unless end (setq end (point))) | |
1077 (while rule | |
1078 (let* ((action (car rule))) | |
1079 (setq rule (cdr rule)) | |
1080 (cond ((vectorp action) | |
1081 (nxml-set-face (let ((offset (aref action 0))) | |
1082 (cond ((not offset) start) | |
1083 ((< offset 0) (+ end offset)) | |
1084 (t (+ start offset)))) | |
1085 (let ((offset (aref action 1))) | |
1086 (cond ((not offset) end) | |
1087 ((< offset 0) (+ end offset)) | |
1088 (t (+ start offset)))) | |
1089 (aref action 2))) | |
1090 ((and (consp action) | |
1091 (eq (car action) 'element-qname)) | |
1092 (when xmltok-name-end ; maybe nil in partial-end-tag case | |
1093 (nxml-fontify-qname (+ start (cdr action)) | |
1094 xmltok-name-colon | |
1095 xmltok-name-end | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1096 'nxml-element-prefix |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1097 'nxml-element-colon |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1098 'nxml-element-local-name))) |
86361 | 1099 ((eq action 'attributes) |
1100 (nxml-fontify-attributes)) | |
1101 ((eq action 'processing-instruction-content) | |
1102 (nxml-set-face (+ start 2) | |
1103 xmltok-name-end | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1104 'nxml-processing-instruction-target) |
86361 | 1105 (nxml-set-face (save-excursion |
1106 (goto-char xmltok-name-end) | |
1107 (skip-chars-forward " \t\r\n") | |
1108 (point)) | |
1109 (- end 2) | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1110 'nxml-processing-instruction-content)) |
86361 | 1111 ((eq action 'char-ref) |
1112 (nxml-char-ref-display-extra start | |
1113 end | |
1114 (xmltok-char-number start end))) | |
1115 (t (error "Invalid nxml-fontify-rule action %s" action))))))) | |
1116 | |
1117 (defun nxml-fontify-attributes () | |
1118 (while xmltok-namespace-attributes | |
1119 (nxml-fontify-attribute (car xmltok-namespace-attributes) | |
1120 'namespace) | |
1121 (setq xmltok-namespace-attributes | |
1122 (cdr xmltok-namespace-attributes))) | |
1123 (while xmltok-attributes | |
1124 (nxml-fontify-attribute (car xmltok-attributes)) | |
1125 (setq xmltok-attributes | |
1126 (cdr xmltok-attributes)))) | |
1127 | |
1128 (defun nxml-fontify-attribute (att &optional namespace-declaration) | |
1129 (if namespace-declaration | |
1130 (nxml-fontify-qname (xmltok-attribute-name-start att) | |
1131 (xmltok-attribute-name-colon att) | |
1132 (xmltok-attribute-name-end att) | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1133 'nxml-namespace-attribute-xmlns |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1134 'nxml-namespace-attribute-colon |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1135 'nxml-namespace-attribute-prefix |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1136 'nxml-namespace-attribute-xmlns) |
86361 | 1137 (nxml-fontify-qname (xmltok-attribute-name-start att) |
1138 (xmltok-attribute-name-colon att) | |
1139 (xmltok-attribute-name-end att) | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1140 'nxml-attribute-prefix |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1141 'nxml-attribute-colon |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1142 'nxml-attribute-local-name)) |
86361 | 1143 (let ((start (xmltok-attribute-value-start att)) |
1144 (end (xmltok-attribute-value-end att)) | |
1145 (refs (xmltok-attribute-refs att)) | |
1146 (delimiter-face (if namespace-declaration | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1147 'nxml-namespace-attribute-value-delimiter |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1148 'nxml-attribute-value-delimiter)) |
86361 | 1149 (value-face (if namespace-declaration |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1150 'nxml-namespace-attribute-value |
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
1151 'nxml-attribute-value))) |
86361 | 1152 (when start |
1153 (nxml-set-face (1- start) start delimiter-face) | |
1154 (nxml-set-face end (1+ end) delimiter-face) | |
1155 (while refs | |
1156 (let* ((ref (car refs)) | |
1157 (ref-type (aref ref 0)) | |
1158 (ref-start (aref ref 1)) | |
1159 (ref-end (aref ref 2))) | |
1160 (nxml-set-face start ref-start value-face) | |
1161 (nxml-apply-fontify-rule ref-type ref-start ref-end) | |
1162 (setq start ref-end)) | |
1163 (setq refs (cdr refs))) | |
1164 (nxml-set-face start end value-face)))) | |
1165 | |
1166 (defun nxml-fontify-qname (start | |
1167 colon | |
1168 end | |
1169 prefix-face | |
1170 colon-face | |
1171 local-name-face | |
1172 &optional | |
1173 unprefixed-face) | |
1174 (cond (colon (nxml-set-face start colon prefix-face) | |
1175 (nxml-set-face colon (1+ colon) colon-face) | |
1176 (nxml-set-face (1+ colon) end local-name-face)) | |
1177 (t (nxml-set-face start end (or unprefixed-face | |
1178 local-name-face))))) | |
1179 | |
1180 ;;; Editing | |
1181 | |
1182 (defun nxml-electric-slash (arg) | |
1183 "Insert a slash. | |
1184 | |
1185 With a prefix ARG, do nothing other than insert the slash. | |
1186 | |
1187 Otherwise, if `nxml-slash-auto-complete-flag' is non-nil, insert the | |
1188 rest of the end-tag or empty-element if the slash is potentially part | |
1189 of an end-tag or the close of an empty-element. | |
1190 | |
1191 If the slash is part of an end-tag that is the first non-whitespace | |
1192 on the line, reindent the line." | |
1193 (interactive "*P") | |
1194 (nxml-ensure-scan-up-to-date) | |
1195 (let* ((slash-pos (point)) | |
1196 (end-tag-p (and (eq (char-before slash-pos) ?<) | |
1197 (not (nxml-get-inside slash-pos)))) | |
1198 (at-indentation (save-excursion | |
1199 (back-to-indentation) | |
1200 (eq (point) (1- slash-pos))))) | |
1201 (self-insert-command (prefix-numeric-value arg)) | |
1202 (unless arg | |
1203 (if nxml-slash-auto-complete-flag | |
1204 (if end-tag-p | |
1205 (condition-case err | |
1206 (let ((start-tag-end | |
1207 (nxml-scan-element-backward (1- slash-pos) t))) | |
1208 (when start-tag-end | |
1209 (insert (xmltok-start-tag-qname) ">") | |
1210 ;; copy the indentation of the start-tag | |
1211 (when (and at-indentation | |
1212 (save-excursion | |
1213 (goto-char xmltok-start) | |
1214 (back-to-indentation) | |
1215 (eq (point) xmltok-start))) | |
1216 (save-excursion | |
1217 (indent-line-to (save-excursion | |
1218 (goto-char xmltok-start) | |
1219 (current-column))))))) | |
1220 (nxml-scan-error nil)) | |
1221 (when (and (eq (nxml-token-before) (point)) | |
1222 (eq xmltok-type 'partial-empty-element)) | |
1223 (insert ">"))) | |
1224 (when (and end-tag-p at-indentation) | |
1225 (nxml-indent-line)))))) | |
1226 | |
1227 (defun nxml-balanced-close-start-tag-block () | |
1228 "Close the start-tag before point with `>' and insert a balancing end-tag. | |
1229 Point is left between the start-tag and the end-tag. | |
1230 If there is nothing but whitespace before the `<' that opens the | |
1231 start-tag, then put point on a blank line, and put the end-tag on | |
1232 another line aligned with the start-tag." | |
1233 (interactive "*") | |
1234 (nxml-balanced-close-start-tag 'block)) | |
1235 | |
1236 (defun nxml-balanced-close-start-tag-inline () | |
1237 "Close the start-tag before point with `>' and insert a balancing end-tag. | |
1238 Point is left between the start-tag and the end-tag. | |
1239 No extra whitespace is inserted." | |
1240 (interactive "*") | |
1241 (nxml-balanced-close-start-tag 'inline)) | |
1242 | |
1243 (defun nxml-balanced-close-start-tag (block-or-inline) | |
1244 (let ((token-end (nxml-token-before)) | |
1245 (pos (1+ (point)))) | |
1246 (unless (or (eq xmltok-type 'partial-start-tag) | |
1247 (and (memq xmltok-type '(start-tag | |
1248 empty-element | |
1249 partial-empty-element)) | |
1250 (>= token-end pos))) | |
1251 (error "Not in a start-tag")) | |
1252 (insert "></" | |
1253 (buffer-substring-no-properties (+ xmltok-start 1) | |
1254 (min xmltok-name-end (point))) | |
1255 ">") | |
1256 (if (eq block-or-inline 'inline) | |
1257 (goto-char pos) | |
1258 (goto-char xmltok-start) | |
1259 (back-to-indentation) | |
1260 (if (= (point) xmltok-start) | |
1261 (let ((indent (current-column))) | |
1262 (goto-char pos) | |
1263 (insert "\n") | |
1264 (indent-line-to indent) | |
1265 (goto-char pos) | |
1266 (insert "\n") | |
1267 (indent-line-to (+ nxml-child-indent indent))) | |
1268 (goto-char pos))))) | |
1269 | |
1270 (defun nxml-finish-element () | |
1271 "Finish the current element by inserting an end-tag." | |
1272 (interactive "*") | |
1273 (nxml-finish-element-1 nil)) | |
1274 | |
1275 (defvar nxml-last-split-position nil | |
1276 "Position where `nxml-split-element' split the current element.") | |
1277 | |
1278 (defun nxml-split-element () | |
1279 "Split the current element by inserting an end-tag and a start-tag. | |
1280 Point is left after the newly inserted start-tag. When repeated, | |
1281 split immediately before the previously inserted start-tag and leave | |
1282 point unchanged." | |
1283 (interactive "*") | |
1284 (setq nxml-last-split-position | |
1285 (if (and (eq last-command this-command) | |
1286 nxml-last-split-position) | |
1287 (save-excursion | |
1288 (goto-char nxml-last-split-position) | |
1289 (nxml-finish-element-1 t)) | |
1290 (nxml-finish-element-1 t)))) | |
1291 | |
1292 (defun nxml-finish-element-1 (startp) | |
1293 "Insert an end-tag for the current element and optionally a start-tag. | |
1294 The start-tag is inserted if STARTP is non-nil. Return the position | |
1295 of the inserted start-tag or nil if none was inserted." | |
1296 (interactive "*") | |
1297 (let* ((token-end (nxml-token-before)) | |
1298 (start-tag-end | |
1299 (save-excursion | |
1300 (when (and (< (point) token-end) | |
1301 (memq xmltok-type | |
1302 '(cdata-section | |
1303 processing-instruction | |
1304 comment | |
1305 start-tag | |
1306 end-tag | |
1307 empty-element))) | |
1308 (error "Point is inside a %s" | |
1309 (nxml-token-type-friendly-name xmltok-type))) | |
1310 (nxml-scan-element-backward token-end t))) | |
1311 (starts-line | |
1312 (save-excursion | |
1313 (unless (eq xmltok-type 'start-tag) | |
1314 (error "No matching start-tag")) | |
1315 (goto-char xmltok-start) | |
1316 (back-to-indentation) | |
1317 (eq (point) xmltok-start))) | |
1318 (ends-line | |
1319 (save-excursion | |
1320 (goto-char start-tag-end) | |
1321 (looking-at "[ \t\r\n]*$"))) | |
1322 (start-tag-indent (save-excursion | |
1323 (goto-char xmltok-start) | |
1324 (current-column))) | |
1325 (qname (xmltok-start-tag-qname)) | |
1326 inserted-start-tag-pos) | |
1327 (when (and starts-line ends-line) | |
1328 ;; start-tag is on a line by itself | |
1329 ;; => put the end-tag on a line by itself | |
1330 (unless (<= (point) | |
1331 (save-excursion | |
1332 (back-to-indentation) | |
1333 (point))) | |
1334 (insert "\n")) | |
1335 (indent-line-to start-tag-indent)) | |
1336 (insert "</" qname ">") | |
1337 (when startp | |
1338 (when starts-line | |
1339 (insert "\n") | |
1340 (indent-line-to start-tag-indent)) | |
1341 (setq inserted-start-tag-pos (point)) | |
1342 (insert "<" qname ">") | |
1343 (when (and starts-line ends-line) | |
1344 (insert "\n") | |
1345 (indent-line-to (save-excursion | |
1346 (goto-char xmltok-start) | |
1347 (forward-line 1) | |
1348 (back-to-indentation) | |
1349 (if (= (current-column) | |
1350 (+ start-tag-indent nxml-child-indent)) | |
1351 (+ start-tag-indent nxml-child-indent) | |
1352 start-tag-indent))))) | |
1353 inserted-start-tag-pos)) | |
1354 | |
1355 ;;; Indentation | |
1356 | |
1357 (defun nxml-indent-line () | |
1358 "Indent current line as XML." | |
1359 (let ((indent (nxml-compute-indent)) | |
1360 (from-end (- (point-max) (point)))) | |
1361 (when indent | |
1362 (beginning-of-line) | |
1363 (let ((bol (point))) | |
1364 (skip-chars-forward " \t") | |
1365 (delete-region bol (point))) | |
1366 (indent-to indent) | |
1367 (when (> (- (point-max) from-end) (point)) | |
1368 (goto-char (- (point-max) from-end)))))) | |
1369 | |
1370 (defun nxml-compute-indent () | |
1371 "Return the indent for the line containing point." | |
1372 (or (nxml-compute-indent-from-matching-start-tag) | |
1373 (nxml-compute-indent-from-previous-line))) | |
1374 | |
1375 (defun nxml-compute-indent-from-matching-start-tag () | |
1376 "Compute the indent for a line with an end-tag using the matching start-tag. | |
1377 When the line containing point ends with an end-tag and does not start | |
1378 in the middle of a token, return the indent of the line containing the | |
1379 matching start-tag, if there is one and it occurs at the beginning of | |
1380 its line. Otherwise return nil." | |
1381 (save-excursion | |
1382 (back-to-indentation) | |
1383 (let ((bol (point))) | |
1384 (let ((inhibit-field-text-motion t)) | |
1385 (end-of-line)) | |
1386 (skip-chars-backward " \t") | |
1387 (and (= (nxml-token-before) (point)) | |
1388 (memq xmltok-type '(end-tag partial-end-tag)) | |
1389 ;; start of line must not be inside a token | |
1390 (or (= xmltok-start bol) | |
1391 (save-excursion | |
1392 (goto-char bol) | |
1393 (nxml-token-after) | |
1394 (= xmltok-start bol)) | |
1395 (eq xmltok-type 'data)) | |
1396 (condition-case err | |
1397 (nxml-scan-element-backward | |
1398 (point) | |
1399 nil | |
1400 (- (point) | |
1401 nxml-end-tag-indent-scan-distance)) | |
1402 (nxml-scan-error nil)) | |
1403 (< xmltok-start bol) | |
1404 (progn | |
1405 (goto-char xmltok-start) | |
1406 (skip-chars-backward " \t") | |
1407 (bolp)) | |
1408 (current-indentation))))) | |
1409 | |
1410 (defun nxml-compute-indent-from-previous-line () | |
1411 "Compute the indent for a line using the indentation of a previous line." | |
1412 (save-excursion | |
1413 (end-of-line) | |
1414 (let ((eol (point)) | |
1415 bol prev-bol ref | |
1416 before-context after-context) | |
1417 (back-to-indentation) | |
1418 (setq bol (point)) | |
1419 (catch 'indent | |
1420 ;; Move backwards until the start of a non-blank line that is | |
1421 ;; not inside a token. | |
1422 (while (progn | |
1423 (when (= (forward-line -1) -1) | |
1424 (throw 'indent 0)) | |
1425 (back-to-indentation) | |
1426 (if (looking-at "[ \t]*$") | |
1427 t | |
1428 (or prev-bol | |
1429 (setq prev-bol (point))) | |
1430 (nxml-token-after) | |
1431 (not (or (= xmltok-start (point)) | |
1432 (eq xmltok-type 'data)))))) | |
1433 (setq ref (point)) | |
1434 ;; Now scan over tokens until the end of the line to be indented. | |
1435 ;; Determine the context before and after the beginning of the | |
1436 ;; line. | |
1437 (while (< (point) eol) | |
1438 (nxml-tokenize-forward) | |
1439 (cond ((<= bol xmltok-start) | |
1440 (setq after-context | |
1441 (nxml-merge-indent-context-type after-context))) | |
1442 ((and (<= (point) bol) | |
1443 (not (and (eq xmltok-type 'partial-start-tag) | |
1444 (= (point) bol)))) | |
1445 (setq before-context | |
1446 (nxml-merge-indent-context-type before-context))) | |
1447 ((eq xmltok-type 'data) | |
1448 (setq before-context | |
1449 (nxml-merge-indent-context-type before-context)) | |
1450 (setq after-context | |
1451 (nxml-merge-indent-context-type after-context))) | |
1452 ;; If in the middle of a token that looks inline, | |
1453 ;; then indent relative to the previous non-blank line | |
1454 ((eq (nxml-merge-indent-context-type before-context) | |
1455 'mixed) | |
1456 (goto-char prev-bol) | |
1457 (throw 'indent (current-column))) | |
1458 (t | |
1459 (throw 'indent | |
1460 (nxml-compute-indent-in-token bol)))) | |
1461 (skip-chars-forward " \t\r\n")) | |
1462 (goto-char ref) | |
1463 (+ (current-column) | |
1464 (* nxml-child-indent | |
1465 (+ (if (eq before-context 'start-tag) 1 0) | |
1466 (if (eq after-context 'end-tag) -1 0)))))))) | |
1467 | |
1468 (defun nxml-merge-indent-context-type (context) | |
1469 "Merge the indent context type CONTEXT with the token in `xmltok-type'. | |
1470 Return the merged indent context type. An indent context type is | |
1471 either nil or one of the symbols start-tag, end-tag, markup, comment, | |
1472 mixed." | |
1473 (cond ((memq xmltok-type '(start-tag partial-start-tag)) | |
1474 (if (memq context '(nil start-tag comment)) | |
1475 'start-tag | |
1476 'mixed)) | |
1477 ((memq xmltok-type '(end-tag partial-end-tag)) | |
1478 (if (memq context '(nil end-tag comment)) | |
1479 'end-tag | |
1480 'mixed)) | |
1481 ((eq xmltok-type 'comment) | |
1482 (cond ((memq context '(start-tag end-tag comment)) | |
1483 context) | |
1484 (context 'mixed) | |
1485 (t 'comment))) | |
1486 (context 'mixed) | |
1487 (t 'markup))) | |
1488 | |
1489 (defun nxml-compute-indent-in-token (pos) | |
1490 "Return the indent for a line that starts inside a token. | |
1491 POS is the position of the first non-whitespace character of the line. | |
1492 This expects the xmltok-* variables to be set up as by `xmltok-forward'." | |
1493 (cond ((memq xmltok-type '(start-tag | |
1494 partial-start-tag | |
1495 empty-element | |
1496 partial-empty-element)) | |
1497 (nxml-compute-indent-in-start-tag pos)) | |
1498 ((eq xmltok-type 'comment) | |
1499 (nxml-compute-indent-in-delimited-token pos "<!--" "-->")) | |
1500 ((eq xmltok-type 'cdata-section) | |
1501 (nxml-compute-indent-in-delimited-token pos "<![CDATA[" "]]>")) | |
1502 ((eq xmltok-type 'processing-instruction) | |
1503 (nxml-compute-indent-in-delimited-token pos "<?" "?>")) | |
1504 (t | |
1505 (goto-char pos) | |
1506 (if (and (= (forward-line -1) 0) | |
1507 (< xmltok-start (point))) | |
1508 (back-to-indentation) | |
1509 (goto-char xmltok-start)) | |
1510 (current-column)))) | |
1511 | |
1512 (defun nxml-compute-indent-in-start-tag (pos) | |
1513 "Return the indent for a line that starts inside a start-tag. | |
1514 Also for a line that starts inside an empty element. | |
1515 POS is the position of the first non-whitespace character of the line. | |
1516 This expects the xmltok-* variables to be set up as by `xmltok-forward'." | |
1517 (let ((value-boundary (nxml-attribute-value-boundary pos)) | |
1518 (off 0)) | |
1519 (if value-boundary | |
1520 ;; inside an attribute value | |
1521 (let ((value-start (car value-boundary)) | |
1522 (value-end (cdr value-boundary))) | |
1523 (goto-char pos) | |
1524 (forward-line -1) | |
1525 (if (< (point) value-start) | |
1526 (goto-char value-start) | |
1527 (back-to-indentation))) | |
1528 ;; outside an attribute value | |
1529 (goto-char pos) | |
1530 (while (and (= (forward-line -1) 0) | |
1531 (nxml-attribute-value-boundary (point)))) | |
1532 (cond ((<= (point) xmltok-start) | |
1533 (goto-char xmltok-start) | |
1534 (setq off nxml-attribute-indent) | |
1535 (let ((atts (xmltok-merge-attributes))) | |
1536 (when atts | |
1537 (let* ((att (car atts)) | |
1538 (start (xmltok-attribute-name-start att))) | |
1539 (when (< start pos) | |
1540 (goto-char start) | |
1541 (setq off 0)))))) | |
1542 (t | |
1543 (back-to-indentation)))) | |
1544 (+ (current-column) off))) | |
1545 | |
1546 (defun nxml-attribute-value-boundary (pos) | |
1547 "Return a pair (START . END) if POS is inside an attribute value. | |
1548 Otherwise return nil. START and END are the positions of the start | |
1549 and end of the attribute value containing POS. This expects the | |
1550 xmltok-* variables to be set up as by `xmltok-forward'." | |
1551 (let ((atts (xmltok-merge-attributes)) | |
1552 att value-start value-end value-boundary) | |
1553 (while atts | |
1554 (setq att (car atts)) | |
1555 (setq value-start (xmltok-attribute-value-start att)) | |
1556 (setq value-end (xmltok-attribute-value-end att)) | |
1557 (cond ((and value-start (< pos value-start)) | |
1558 (setq atts nil)) | |
1559 ((and value-start value-end (<= pos value-end)) | |
1560 (setq value-boundary (cons value-start value-end)) | |
1561 (setq atts nil)) | |
1562 (t (setq atts (cdr atts))))) | |
1563 value-boundary)) | |
1564 | |
1565 (defun nxml-compute-indent-in-delimited-token (pos open-delim close-delim) | |
1566 "Return the indent for a line that starts inside a token with delimiters. | |
1567 OPEN-DELIM and CLOSE-DELIM are strings giving the opening and closing | |
1568 delimiters. POS is the position of the first non-whitespace character | |
1569 of the line. This expects the xmltok-* variables to be set up as by | |
1570 `xmltok-forward'." | |
1571 (cond ((let ((end (+ pos (length close-delim)))) | |
1572 (and (<= end (point-max)) | |
1573 (string= (buffer-substring-no-properties pos end) | |
1574 close-delim))) | |
1575 (goto-char xmltok-start)) | |
1576 ((progn | |
1577 (goto-char pos) | |
1578 (forward-line -1) | |
1579 (<= (point) xmltok-start)) | |
1580 (goto-char (+ xmltok-start (length open-delim))) | |
1581 (when (and (string= open-delim "<!--") | |
1582 (looking-at " ")) | |
1583 (goto-char (1+ (point))))) | |
1584 (t (back-to-indentation))) | |
1585 (current-column)) | |
1586 | |
1587 ;;; Completion | |
1588 | |
1589 (defun nxml-complete () | |
1590 "Perform completion on the symbol preceding point. | |
1591 | |
1592 Inserts as many characters as can be completed. However, if not even | |
1593 one character can be completed, then a buffer with the possibilities | |
1594 is popped up and the symbol is read from the minibuffer with | |
1595 completion. If the symbol is complete, then any characters that must | |
1596 follow the symbol are also inserted. | |
1597 | |
1598 The name space used for completion and what is treated as a symbol | |
1599 depends on the context. The contexts in which completion is performed | |
1600 depend on `nxml-completion-hook'." | |
1601 (interactive) | |
1602 (unless (run-hook-with-args-until-success 'nxml-completion-hook) | |
1603 ;; Eventually we will complete on entity names here. | |
1604 (ding) | |
1605 (message "Cannot complete in this context"))) | |
1606 | |
1607 ;;; Movement | |
1608 | |
1609 (defun nxml-forward-balanced-item (&optional arg) | |
1610 "Move forward across one balanced item. | |
1611 With ARG, do it that many times. Negative arg -N means | |
1612 move backward across N balanced expressions. | |
1613 This is the equivalent of `forward-sexp' for XML. | |
1614 | |
1615 An element contains as items strings with no markup, tags, processing | |
1616 instructions, comments, CDATA sections, entity references and | |
1617 characters references. However, if the variable | |
1618 `nxml-sexp-element-flag' is non-nil, then an element is treated as a | |
1619 single markup item. A start-tag contains an element name followed by | |
1620 one or more attributes. An end-tag contains just an element name. An | |
1621 attribute value literals contains strings with no markup, entity | |
1622 references and character references. A processing instruction | |
1623 consists of a target and a content string. A comment or a CDATA | |
1624 section contains a single string. An entity reference contains a | |
1625 single name. A character reference contains a character number." | |
1626 (interactive "p") | |
1627 (or arg (setq arg 1)) | |
1628 (cond ((> arg 0) | |
1629 (while (progn | |
1630 (nxml-forward-single-balanced-item) | |
1631 (> (setq arg (1- arg)) 0)))) | |
1632 ((< arg 0) | |
1633 (while (progn | |
1634 (nxml-backward-single-balanced-item) | |
1635 (< (setq arg (1+ arg)) 0)))))) | |
1636 | |
1637 (defun nxml-forward-single-balanced-item () | |
1638 (condition-case err | |
1639 (goto-char (let ((end (nxml-token-after))) | |
1640 (save-excursion | |
1641 (while (eq xmltok-type 'space) | |
1642 (goto-char end) | |
1643 (setq end (nxml-token-after))) | |
1644 (cond ((/= (point) xmltok-start) | |
1645 (nxml-scan-forward-within end)) | |
1646 ((and nxml-sexp-element-flag | |
1647 (eq xmltok-type 'start-tag)) | |
1648 ;; can't ever return nil here | |
1649 (nxml-scan-element-forward xmltok-start)) | |
1650 ((and nxml-sexp-element-flag | |
1651 (memq xmltok-type | |
1652 '(end-tag partial-end-tag))) | |
1653 (error "Already at end of element")) | |
1654 (t end))))) | |
1655 (nxml-scan-error | |
1656 (goto-char (cadr err)) | |
1657 (apply 'error (cddr err))))) | |
1658 | |
1659 (defun nxml-backward-single-balanced-item () | |
1660 (condition-case err | |
1661 (goto-char (let ((end (nxml-token-before))) | |
1662 (save-excursion | |
1663 (while (eq xmltok-type 'space) | |
1664 (goto-char xmltok-start) | |
1665 (setq end (nxml-token-before))) | |
1666 (cond ((/= (point) end) | |
1667 (nxml-scan-backward-within end)) | |
1668 ((and nxml-sexp-element-flag | |
1669 (eq xmltok-type 'end-tag)) | |
1670 ;; can't ever return nil here | |
1671 (nxml-scan-element-backward end) | |
1672 xmltok-start) | |
1673 ((and nxml-sexp-element-flag | |
1674 (eq xmltok-type 'start-tag)) | |
1675 (error "Already at start of element")) | |
1676 (t xmltok-start))))) | |
1677 (nxml-scan-error | |
1678 (goto-char (cadr err)) | |
1679 (apply 'error (cddr err))))) | |
1680 | |
1681 (defun nxml-scan-forward-within (end) | |
1682 (setq end (- end (nxml-end-delimiter-length xmltok-type))) | |
1683 (when (<= end (point)) | |
1684 (error "Already at end of %s" | |
1685 (nxml-token-type-friendly-name xmltok-type))) | |
1686 (cond ((memq xmltok-type '(start-tag | |
1687 empty-element | |
1688 partial-start-tag | |
1689 partial-empty-element)) | |
1690 (if (< (point) xmltok-name-end) | |
1691 xmltok-name-end | |
1692 (let ((att (nxml-find-following-attribute))) | |
1693 (cond ((not att) end) | |
1694 ((and (xmltok-attribute-value-start att) | |
1695 (<= (xmltok-attribute-value-start att) | |
1696 (point))) | |
1697 (nxml-scan-forward-in-attribute-value att)) | |
1698 ((xmltok-attribute-value-end att) | |
1699 (1+ (xmltok-attribute-value-end att))) | |
1700 ((save-excursion | |
1701 (goto-char (xmltok-attribute-name-end att)) | |
1702 (looking-at "[ \t\r\n]*=")) | |
1703 (match-end 0)) | |
1704 (t (xmltok-attribute-name-end att)))))) | |
1705 ((and (eq xmltok-type 'processing-instruction) | |
1706 (< (point) xmltok-name-end)) | |
1707 xmltok-name-end) | |
1708 (t end))) | |
1709 | |
1710 (defun nxml-scan-backward-within (end) | |
1711 (setq xmltok-start | |
1712 (+ xmltok-start | |
1713 (nxml-start-delimiter-length xmltok-type))) | |
1714 (when (<= (point) xmltok-start) | |
1715 (error "Already at start of %s" | |
1716 (nxml-token-type-friendly-name xmltok-type))) | |
1717 (cond ((memq xmltok-type '(start-tag | |
1718 empty-element | |
1719 partial-start-tag | |
1720 partial-empty-element)) | |
1721 (let ((att (nxml-find-preceding-attribute))) | |
1722 (cond ((not att) xmltok-start) | |
1723 ((and (xmltok-attribute-value-start att) | |
1724 (<= (xmltok-attribute-value-start att) | |
1725 (point)) | |
1726 (<= (point) | |
1727 (xmltok-attribute-value-end att))) | |
1728 (nxml-scan-backward-in-attribute-value att)) | |
1729 (t (xmltok-attribute-name-start att))))) | |
1730 ((and (eq xmltok-type 'processing-instruction) | |
1731 (let ((content-start (save-excursion | |
1732 (goto-char xmltok-name-end) | |
1733 (skip-chars-forward " \r\t\n") | |
1734 (point)))) | |
1735 (and (< content-start (point)) | |
1736 content-start)))) | |
1737 (t xmltok-start))) | |
1738 | |
1739 (defun nxml-scan-forward-in-attribute-value (att) | |
1740 (when (= (point) (xmltok-attribute-value-end att)) | |
1741 (error "Already at end of attribute value")) | |
1742 (let ((refs (xmltok-attribute-refs att)) | |
1743 ref) | |
1744 (while refs | |
1745 (setq ref (car refs)) | |
1746 (if (< (point) (aref ref 2)) | |
1747 (setq refs nil) | |
1748 (setq ref nil) | |
1749 (setq refs (cdr refs)))) | |
1750 (cond ((not ref) | |
1751 (xmltok-attribute-value-end att)) | |
1752 ((< (point) (aref ref 1)) | |
1753 (aref ref 1)) | |
1754 ((= (point) (aref ref 1)) | |
1755 (aref ref 2)) | |
1756 (t | |
1757 (let ((end (- (aref ref 2) | |
1758 (nxml-end-delimiter-length (aref ref 0))))) | |
1759 (if (< (point) end) | |
1760 end | |
1761 (error "Already at end of %s" | |
1762 (nxml-token-type-friendly-name (aref ref 0))))))))) | |
1763 | |
1764 (defun nxml-scan-backward-in-attribute-value (att) | |
1765 (when (= (point) (xmltok-attribute-value-start att)) | |
1766 (error "Already at start of attribute value")) | |
1767 (let ((refs (reverse (xmltok-attribute-refs att))) | |
1768 ref) | |
1769 (while refs | |
1770 (setq ref (car refs)) | |
1771 (if (< (aref ref 1) (point)) | |
1772 (setq refs nil) | |
1773 (setq ref nil) | |
1774 (setq refs (cdr refs)))) | |
1775 (cond ((not ref) | |
1776 (xmltok-attribute-value-start att)) | |
1777 ((< (aref ref 2) (point)) | |
1778 (aref ref 2)) | |
1779 ((= (point) (aref ref 2)) | |
1780 (aref ref 1)) | |
1781 (t | |
1782 (let ((start (+ (aref ref 1) | |
1783 (nxml-start-delimiter-length (aref ref 0))))) | |
1784 (if (< start (point)) | |
1785 start | |
1786 (error "Already at start of %s" | |
1787 (nxml-token-type-friendly-name (aref ref 0))))))))) | |
1788 | |
1789 (defun nxml-find-following-attribute () | |
1790 (let ((ret nil) | |
1791 (atts (or xmltok-attributes xmltok-namespace-attributes)) | |
1792 (more-atts (and xmltok-attributes xmltok-namespace-attributes))) | |
1793 (while atts | |
1794 (let* ((att (car atts)) | |
1795 (name-start (xmltok-attribute-name-start att))) | |
1796 (cond ((and (<= name-start (point)) | |
1797 (xmltok-attribute-value-end att) | |
1798 ;; <= because end is before quote | |
1799 (<= (point) (xmltok-attribute-value-end att))) | |
1800 (setq atts nil) | |
1801 (setq ret att)) | |
1802 ((and (< (point) name-start) | |
1803 (or (not ret) | |
1804 (< name-start | |
1805 (xmltok-attribute-name-start ret)))) | |
1806 (setq ret att)))) | |
1807 (setq atts (cdr atts)) | |
1808 (unless atts | |
1809 (setq atts more-atts) | |
1810 (setq more-atts nil))) | |
1811 ret)) | |
1812 | |
1813 (defun nxml-find-preceding-attribute () | |
1814 (let ((ret nil) | |
1815 (atts (or xmltok-attributes xmltok-namespace-attributes)) | |
1816 (more-atts (and xmltok-attributes xmltok-namespace-attributes))) | |
1817 (while atts | |
1818 (let* ((att (car atts)) | |
1819 (name-start (xmltok-attribute-name-start att))) | |
1820 (cond ((and (< name-start (point)) | |
1821 (xmltok-attribute-value-end att) | |
1822 ;; <= because end is before quote | |
1823 (<= (point) (xmltok-attribute-value-end att))) | |
1824 (setq atts nil) | |
1825 (setq ret att)) | |
1826 ((and (< name-start (point)) | |
1827 (or (not ret) | |
1828 (< (xmltok-attribute-name-start ret) | |
1829 name-start))) | |
1830 (setq ret att)))) | |
1831 (setq atts (cdr atts)) | |
1832 (unless atts | |
1833 (setq atts more-atts) | |
1834 (setq more-atts nil))) | |
1835 ret)) | |
1836 | |
1837 (defun nxml-up-element (&optional arg) | |
1838 (interactive "p") | |
1839 (or arg (setq arg 1)) | |
1840 (if (< arg 0) | |
1841 (nxml-backward-up-element (- arg)) | |
1842 (condition-case err | |
1843 (while (and (> arg 0) | |
1844 (< (point) (point-max))) | |
1845 (let ((token-end (nxml-token-after))) | |
1846 (goto-char (cond ((or (memq xmltok-type '(end-tag | |
1847 partial-end-tag)) | |
1848 (and (memq xmltok-type | |
1849 '(empty-element | |
1850 partial-empty-element)) | |
1851 (< xmltok-start (point)))) | |
1852 token-end) | |
1853 ((nxml-scan-element-forward | |
1854 (if (and (eq xmltok-type 'start-tag) | |
1855 (= (point) xmltok-start)) | |
1856 xmltok-start | |
1857 token-end) | |
1858 t)) | |
1859 (t (error "No parent element"))))) | |
1860 (setq arg (1- arg))) | |
1861 (nxml-scan-error | |
1862 (goto-char (cadr err)) | |
1863 (apply 'error (cddr err)))))) | |
1864 | |
1865 (defun nxml-backward-up-element (&optional arg) | |
1866 (interactive "p") | |
1867 (or arg (setq arg 1)) | |
1868 (if (< arg 0) | |
1869 (nxml-up-element (- arg)) | |
1870 (condition-case err | |
1871 (while (and (> arg 0) | |
1872 (< (point-min) (point))) | |
1873 (let ((token-end (nxml-token-before))) | |
1874 (goto-char (cond ((or (memq xmltok-type '(start-tag | |
1875 partial-start-tag)) | |
1876 (and (memq xmltok-type | |
1877 '(empty-element | |
1878 partial-empty-element)) | |
1879 (< (point) token-end))) | |
1880 xmltok-start) | |
1881 ((nxml-scan-element-backward | |
1882 (if (and (eq xmltok-type 'end-tag) | |
1883 (= (point) token-end)) | |
1884 token-end | |
1885 xmltok-start) | |
1886 t) | |
1887 xmltok-start) | |
1888 (t (error "No parent element"))))) | |
1889 (setq arg (1- arg))) | |
1890 (nxml-scan-error | |
1891 (goto-char (cadr err)) | |
1892 (apply 'error (cddr err)))))) | |
1893 | |
1894 (defun nxml-down-element (&optional arg) | |
1895 "Move forward down into the content of an element. | |
1896 With ARG, do this that many times. | |
1897 Negative ARG means move backward but still down." | |
1898 (interactive "p") | |
1899 (or arg (setq arg 1)) | |
1900 (if (< arg 0) | |
1901 (nxml-backward-down-element (- arg)) | |
1902 (while (> arg 0) | |
1903 (goto-char | |
1904 (let ((token-end (nxml-token-after))) | |
1905 (save-excursion | |
1906 (goto-char token-end) | |
1907 (while (progn | |
1908 (when (memq xmltok-type '(nil end-tag partial-end-tag)) | |
1909 (error "No following start-tags in this element")) | |
1910 (not (memq xmltok-type '(start-tag partial-start-tag)))) | |
1911 (nxml-tokenize-forward)) | |
1912 (point)))) | |
1913 (setq arg (1- arg))))) | |
1914 | |
1915 (defun nxml-backward-down-element (&optional arg) | |
1916 (interactive "p") | |
1917 (or arg (setq arg 1)) | |
1918 (if (< arg 0) | |
1919 (nxml-down-element (- arg)) | |
1920 (while (> arg 0) | |
1921 (goto-char | |
1922 (save-excursion | |
1923 (nxml-token-before) | |
1924 (goto-char xmltok-start) | |
1925 (while (progn | |
1926 (when (memq xmltok-type '(start-tag | |
1927 partial-start-tag | |
1928 prolog | |
1929 nil)) | |
1930 (error "No preceding end-tags in this element")) | |
1931 (not (memq xmltok-type '(end-tag partial-end-tag)))) | |
1932 (if (or (<= (point) nxml-prolog-end) | |
1933 (not (search-backward "<" nxml-prolog-end t))) | |
1934 (setq xmltok-type nil) | |
1935 (nxml-move-outside-backwards) | |
1936 (xmltok-forward))) | |
1937 xmltok-start)) | |
1938 (setq arg (1- arg))))) | |
1939 | |
1940 (defun nxml-forward-element (&optional arg) | |
1941 "Move forward over one element. | |
1942 With ARG, do it that many times. | |
1943 Negative ARG means move backward." | |
1944 (interactive "p") | |
1945 (or arg (setq arg 1)) | |
1946 (if (< arg 0) | |
1947 (nxml-backward-element (- arg)) | |
1948 (condition-case err | |
1949 (while (and (> arg 0) | |
1950 (< (point) (point-max))) | |
1951 (goto-char | |
1952 (or (nxml-scan-element-forward (nxml-token-before)) | |
1953 (error "No more elements"))) | |
1954 (setq arg (1- arg))) | |
1955 (nxml-scan-error | |
1956 (goto-char (cadr err)) | |
1957 (apply 'error (cddr err)))))) | |
1958 | |
1959 (defun nxml-backward-element (&optional arg) | |
1960 "Move backward over one element. | |
1961 With ARG, do it that many times. | |
1962 Negative ARG means move forward." | |
1963 (interactive "p") | |
1964 (or arg (setq arg 1)) | |
1965 (if (< arg 0) | |
1966 (nxml-forward-element (- arg)) | |
1967 (condition-case err | |
1968 (while (and (> arg 0) | |
1969 (< (point-min) (point))) | |
1970 (goto-char | |
1971 (or (and (nxml-scan-element-backward (progn | |
1972 (nxml-token-after) | |
1973 xmltok-start)) | |
1974 xmltok-start) | |
1975 (error "No preceding elements"))) | |
1976 (setq arg (1- arg))) | |
1977 (nxml-scan-error | |
1978 (goto-char (cadr err)) | |
1979 (apply 'error (cddr err)))))) | |
1980 | |
1981 (defun nxml-mark-token-after () | |
1982 (interactive) | |
1983 (push-mark (nxml-token-after) nil t) | |
1984 (goto-char xmltok-start) | |
1985 (message "Marked %s" xmltok-type)) | |
1986 | |
1987 ;;; Paragraphs | |
1988 | |
1989 (defun nxml-mark-paragraph () | |
1990 "Put point at beginning of this paragraph, mark at end. | |
1991 The paragraph marked is the one that contains point or follows point." | |
1992 (interactive) | |
1993 (nxml-forward-paragraph) | |
1994 (push-mark nil t t) | |
1995 (nxml-backward-paragraph)) | |
1996 | |
1997 (defun nxml-forward-paragraph (&optional arg) | |
1998 (interactive "p") | |
1999 (or arg (setq arg 1)) | |
2000 (cond ((< arg 0) | |
2001 (nxml-backward-paragraph (- arg))) | |
2002 ((> arg 0) | |
2003 (forward-line 0) | |
2004 (while (and (nxml-forward-single-paragraph) | |
2005 (> (setq arg (1- arg)) 0)))))) | |
2006 | |
2007 (defun nxml-backward-paragraph (&optional arg) | |
2008 (interactive "p") | |
2009 (or arg (setq arg 1)) | |
2010 (cond ((< arg 0) | |
2011 (nxml-forward-paragraph (- arg))) | |
2012 ((> arg 0) | |
2013 (unless (bolp) | |
2014 (let ((inhibit-field-text-motion t)) | |
2015 (end-of-line))) | |
2016 (while (and (nxml-backward-single-paragraph) | |
2017 (> (setq arg (1- arg)) 0)))))) | |
2018 | |
2019 (defun nxml-forward-single-paragraph () | |
2020 "Move forward over a single paragraph. | |
2021 Return nil at end of buffer, t otherwise." | |
2022 (let* ((token-end (nxml-token-after)) | |
2023 (offset (- (point) xmltok-start)) | |
2024 pos had-data) | |
2025 (goto-char token-end) | |
2026 (while (and (< (point) (point-max)) | |
2027 (not (setq pos | |
2028 (nxml-paragraph-end-pos had-data offset)))) | |
2029 (when (nxml-token-contains-data-p offset) | |
2030 (setq had-data t)) | |
2031 (nxml-tokenize-forward) | |
2032 (setq offset 0)) | |
2033 (when pos (goto-char pos)))) | |
2034 | |
2035 (defun nxml-backward-single-paragraph () | |
2036 "Move backward over a single paragraph. | |
2037 Return nil at start of buffer, t otherwise." | |
2038 (let* ((token-end (nxml-token-before)) | |
2039 (offset (- token-end (point))) | |
2040 (last-tag-pos xmltok-start) | |
2041 pos had-data last-data-pos) | |
2042 (goto-char token-end) | |
2043 (unless (setq pos (nxml-paragraph-start-pos nil offset)) | |
2044 (setq had-data (nxml-token-contains-data-p nil offset)) | |
2045 (goto-char xmltok-start) | |
2046 (while (and (not pos) (< (point-min) (point))) | |
2047 (cond ((search-backward "<" nxml-prolog-end t) | |
2048 (nxml-move-outside-backwards) | |
2049 (save-excursion | |
2050 (while (< (point) last-tag-pos) | |
2051 (xmltok-forward) | |
2052 (when (and (not had-data) (nxml-token-contains-data-p)) | |
2053 (setq pos nil) | |
2054 (setq last-data-pos xmltok-start)) | |
2055 (let ((tem (nxml-paragraph-start-pos had-data 0))) | |
2056 (when tem (setq pos tem))))) | |
2057 (when (and (not had-data) last-data-pos (not pos)) | |
2058 (setq had-data t) | |
2059 (save-excursion | |
2060 (while (< (point) last-data-pos) | |
2061 (xmltok-forward)) | |
2062 (let ((tem (nxml-paragraph-start-pos had-data 0))) | |
2063 (when tem (setq pos tem))))) | |
2064 (setq last-tag-pos (point))) | |
2065 (t (goto-char (point-min)))))) | |
2066 (when pos (goto-char pos)))) | |
2067 | |
2068 (defun nxml-token-contains-data-p (&optional start end) | |
2069 (setq start (+ xmltok-start (or start 0))) | |
2070 (setq end (- (point) (or end 0))) | |
2071 (when (eq xmltok-type 'cdata-section) | |
2072 (setq start (max start (+ xmltok-start 9))) | |
2073 (setq end (min end (- (point) 3)))) | |
2074 (or (and (eq xmltok-type 'data) | |
2075 (eq start xmltok-start) | |
2076 (eq end (point))) | |
2077 (eq xmltok-type 'char-ref) | |
2078 (and (memq xmltok-type '(data cdata-section)) | |
2079 (< start end) | |
2080 (save-excursion | |
2081 (goto-char start) | |
2082 (re-search-forward "[^ \t\r\n]" end t))))) | |
2083 | |
2084 (defun nxml-paragraph-end-pos (had-data offset) | |
2085 "Return the position of the paragraph end if contained in the current token. | |
2086 Return nil if the current token does not contain the paragraph end. | |
2087 Only characters after OFFSET from the start of the token are eligible. | |
2088 HAD-DATA says whether there have been non-whitespace data characters yet." | |
2089 (cond ((not had-data) | |
2090 (cond ((memq xmltok-type '(data cdata-section)) | |
2091 (save-excursion | |
2092 (let ((end (point))) | |
2093 (goto-char (+ xmltok-start | |
2094 (max (if (eq xmltok-type 'cdata-section) | |
2095 9 | |
2096 0) | |
2097 offset))) | |
2098 (and (re-search-forward "[^ \t\r\n]" end t) | |
2099 (re-search-forward "^[ \t]*$" end t) | |
2100 (match-beginning 0))))) | |
2101 ((and (eq xmltok-type 'comment) | |
2102 (nxml-token-begins-line-p) | |
2103 (nxml-token-ends-line-p)) | |
2104 (save-excursion | |
2105 (let ((end (point))) | |
2106 (goto-char (+ xmltok-start (max 4 offset))) | |
2107 (when (re-search-forward "[^ \t\r\n]" (- end 3) t) | |
2108 (if (re-search-forward "^[ \t]*$" end t) | |
2109 (match-beginning 0) | |
2110 (goto-char (- end 3)) | |
2111 (skip-chars-backward " \t") | |
2112 (unless (bolp) | |
2113 (beginning-of-line 2)) | |
2114 (point)))))))) | |
2115 ((memq xmltok-type '(data space cdata-section)) | |
2116 (save-excursion | |
2117 (let ((end (point))) | |
2118 (goto-char (+ xmltok-start offset)) | |
2119 (and (re-search-forward "^[ \t]*$" end t) | |
2120 (match-beginning 0))))) | |
2121 ((and (memq xmltok-type '(start-tag | |
2122 end-tag | |
2123 empty-element | |
2124 comment | |
2125 processing-instruction | |
2126 entity-ref)) | |
2127 (nxml-token-begins-line-p) | |
2128 (nxml-token-ends-line-p)) | |
2129 (save-excursion | |
2130 (goto-char xmltok-start) | |
2131 (skip-chars-backward " \t") | |
2132 (point))) | |
2133 ((and (eq xmltok-type 'end-tag) | |
2134 (looking-at "[ \t]*$") | |
2135 (not (nxml-in-mixed-content-p t))) | |
2136 (save-excursion | |
2137 (or (search-forward "\n" nil t) | |
2138 (point-max)))))) | |
2139 | |
2140 (defun nxml-paragraph-start-pos (had-data offset) | |
2141 "Return the position of the paragraph start if contained in the current token. | |
2142 Return nil if the current token does not contain the paragraph start. | |
2143 Only characters before OFFSET from the end of the token are eligible. | |
2144 HAD-DATA says whether there have been non-whitespace data characters yet." | |
2145 (cond ((not had-data) | |
2146 (cond ((memq xmltok-type '(data cdata-section)) | |
2147 (save-excursion | |
2148 (goto-char (- (point) | |
2149 (max (if (eq xmltok-type 'cdata-section) | |
2150 3 | |
2151 0) | |
2152 offset))) | |
2153 (and (re-search-backward "[^ \t\r\n]" xmltok-start t) | |
2154 (re-search-backward "^[ \t]*$" xmltok-start t) | |
2155 (match-beginning 0)))) | |
2156 ((and (eq xmltok-type 'comment) | |
2157 (nxml-token-ends-line-p) | |
2158 (nxml-token-begins-line-p)) | |
2159 (save-excursion | |
2160 (goto-char (- (point) (max 3 offset))) | |
2161 (when (and (< (+ xmltok-start 4) (point)) | |
2162 (re-search-backward "[^ \t\r\n]" | |
2163 (+ xmltok-start 4) | |
2164 t)) | |
2165 (if (re-search-backward "^[ \t]*$" xmltok-start t) | |
2166 (match-beginning 0) | |
2167 (goto-char xmltok-start) | |
2168 (if (looking-at "<!--[ \t]*\n") | |
2169 (match-end 0) | |
2170 (skip-chars-backward " \t") | |
2171 (point)))))))) | |
2172 ((memq xmltok-type '(data space cdata-section)) | |
2173 (save-excursion | |
2174 (goto-char (- (point) offset)) | |
2175 (and (re-search-backward "^[ \t]*$" xmltok-start t) | |
2176 (match-beginning 0)))) | |
2177 ((and (memq xmltok-type '(start-tag | |
2178 end-tag | |
2179 empty-element | |
2180 comment | |
2181 processing-instruction | |
2182 entity-ref)) | |
2183 (nxml-token-ends-line-p) | |
2184 (nxml-token-begins-line-p)) | |
2185 (or (search-forward "\n" nil t) | |
2186 (point-max))) | |
2187 ((and (eq xmltok-type 'start-tag) | |
2188 (nxml-token-begins-line-p) | |
2189 (not (save-excursion | |
2190 (goto-char xmltok-start) | |
2191 (nxml-in-mixed-content-p nil)))) | |
2192 (save-excursion | |
2193 (goto-char xmltok-start) | |
2194 (skip-chars-backward " \t") | |
2195 ;; include any blank line before | |
2196 (or (and (eq (char-before) ?\n) | |
2197 (save-excursion | |
2198 (goto-char (1- (point))) | |
2199 (skip-chars-backward " \t") | |
2200 (and (bolp) (point)))) | |
2201 (point)))))) | |
2202 | |
2203 (defun nxml-token-ends-line-p () (looking-at "[ \t]*$")) | |
2204 | |
2205 (defun nxml-token-begins-line-p () | |
2206 (save-excursion | |
2207 (goto-char xmltok-start) | |
2208 (skip-chars-backward " \t") | |
2209 (bolp))) | |
2210 | |
2211 (defun nxml-in-mixed-content-p (endp) | |
2212 "Return non-nil if point is in mixed content. | |
2213 Point must be after an end-tag or before a start-tag. | |
2214 ENDP is t in the former case, nil in the latter." | |
2215 (let (matching-tag-pos) | |
2216 (cond ((not (run-hook-with-args-until-failure | |
2217 'nxml-in-mixed-content-hook)) | |
2218 nil) | |
2219 ;; See if the matching tag does not start or end a line. | |
2220 ((condition-case err | |
2221 (progn | |
2222 (setq matching-tag-pos | |
2223 (xmltok-save | |
2224 (if endp | |
2225 (and (nxml-scan-element-backward (point)) | |
2226 xmltok-start) | |
2227 (nxml-scan-element-forward (point))))) | |
2228 (and matching-tag-pos | |
2229 (save-excursion | |
2230 (goto-char matching-tag-pos) | |
2231 (not (if endp | |
2232 (progn | |
2233 (skip-chars-backward " \t") | |
2234 (bolp)) | |
2235 (looking-at "[ \t]*$")))))) | |
2236 (nxml-scan-error nil)) | |
2237 t) | |
2238 ;; See if there's data at the same level. | |
2239 ((let (start end) | |
2240 (if endp | |
2241 (setq start matching-tag-pos | |
2242 end (point)) | |
2243 (setq start (point) | |
2244 end matching-tag-pos)) | |
2245 (save-excursion | |
2246 (or (when start | |
2247 (goto-char start) | |
2248 (nxml-preceding-sibling-data-p)) | |
2249 (when end | |
2250 (goto-char end) | |
2251 (nxml-following-sibling-data-p))))) | |
2252 t) | |
2253 ;; Otherwise, treat as not mixed | |
2254 (t nil)))) | |
2255 | |
2256 (defun nxml-preceding-sibling-data-p () | |
2257 "Return non-nil if there is a previous sibling that is data." | |
2258 (let ((lim (max (- (point) nxml-mixed-scan-distance) | |
2259 nxml-prolog-end)) | |
2260 (level 0) | |
2261 found end) | |
2262 (xmltok-save | |
2263 (save-excursion | |
2264 (while (and (< lim (point)) | |
2265 (>= level 0) | |
2266 (not found) | |
2267 (progn | |
2268 (setq end (point)) | |
2269 (search-backward "<" lim t))) | |
2270 (nxml-move-outside-backwards) | |
2271 (save-excursion | |
2272 (xmltok-forward) | |
2273 (let ((prev-level level)) | |
2274 (cond ((eq xmltok-type 'end-tag) | |
2275 (setq level (1+ level))) | |
2276 ((eq xmltok-type 'start-tag) | |
2277 (setq level (1- level)))) | |
2278 (when (eq prev-level 0) | |
2279 (while (and (< (point) end) (not found)) | |
2280 (xmltok-forward) | |
2281 (when (memq xmltok-type '(data cdata-section char-ref)) | |
2282 (setq found t))))))))) | |
2283 found)) | |
2284 | |
2285 (defun nxml-following-sibling-data-p () | |
2286 (let ((lim (min (+ (point) nxml-mixed-scan-distance) | |
2287 (point-max))) | |
2288 (level 0) | |
2289 found) | |
2290 (xmltok-save | |
2291 (save-excursion | |
2292 (while (and (< (point) lim) | |
2293 (>= level 0) | |
2294 (nxml-tokenize-forward) | |
2295 (not found)) | |
2296 (cond ((eq xmltok-type 'start-tag) | |
2297 (setq level (1+ level))) | |
2298 ((eq xmltok-type 'end-tag) | |
2299 (setq level (1- level))) | |
2300 ((and (eq level 0) | |
2301 (memq xmltok-type '(data cdata-section char-ref))) | |
2302 (setq found t)))))) | |
2303 found)) | |
2304 | |
2305 ;;; Filling | |
2306 | |
2307 (defun nxml-do-fill-paragraph (arg) | |
2308 (let (fill-paragraph-function | |
2309 fill-prefix | |
2310 start end) | |
2311 (save-excursion | |
2312 (nxml-forward-paragraph) | |
2313 (setq end (point)) | |
2314 (nxml-backward-paragraph) | |
2315 (skip-chars-forward " \t\r\n") | |
2316 (setq start (point)) | |
2317 (beginning-of-line) | |
2318 (setq fill-prefix (buffer-substring-no-properties (point) start)) | |
2319 (when (and (not (nxml-get-inside (point))) | |
2320 (looking-at "[ \t]*<!--")) | |
2321 (setq fill-prefix (concat fill-prefix " "))) | |
2322 (fill-region-as-paragraph start end arg)) | |
2323 (skip-line-prefix fill-prefix) | |
2324 fill-prefix)) | |
2325 | |
2326 (defun nxml-newline-and-indent (soft) | |
2327 (delete-horizontal-space) | |
2328 (if soft (insert-and-inherit ?\n) (newline 1)) | |
2329 (nxml-indent-line)) | |
2330 | |
2331 | |
2332 ;;; Dynamic markup | |
2333 | |
2334 (defvar nxml-dynamic-markup-prev-pos nil) | |
2335 (defvar nxml-dynamic-markup-prev-lengths nil) | |
2336 (defvar nxml-dynamic-markup-prev-found-marker nil) | |
2337 (defvar nxml-dynamic-markup-prev-start-tags (make-hash-table :test 'equal)) | |
2338 | |
2339 (defun nxml-dynamic-markup-word () | |
2340 "Dynamically markup the word before point. | |
2341 This attempts to find a tag to put around the word before point based | |
2342 on the contents of the current buffer. The end-tag will be inserted at | |
2343 point. The start-tag will be inserted at or before the beginning of | |
2344 the word before point; the contents of the current buffer is used to | |
2345 decide where. | |
2346 | |
2347 It works in a similar way to \\[dabbrev-expand]. It searches first | |
2348 backwards from point, then forwards from point for an element whose | |
2349 content is a string which matches the contents of the buffer before | |
2350 point and which includes at least the word before point. It then | |
2351 copies the start- and end-tags from that element and uses them to | |
2352 surround the matching string before point. | |
2353 | |
2354 Repeating \\[nxml-dynamic-markup-word] immediately after successful | |
2355 \\[nxml-dynamic-markup-word] removes the previously inserted markup | |
2356 and attempts to find another possible way to do the markup." | |
2357 (interactive "*") | |
2358 (let (search-start-pos done) | |
2359 (if (and (integerp nxml-dynamic-markup-prev-pos) | |
2360 (= nxml-dynamic-markup-prev-pos (point)) | |
2361 (eq last-command this-command) | |
2362 nxml-dynamic-markup-prev-lengths) | |
2363 (let* ((end-tag-open-pos | |
2364 (- nxml-dynamic-markup-prev-pos | |
2365 (nth 2 nxml-dynamic-markup-prev-lengths))) | |
2366 (start-tag-close-pos | |
2367 (- end-tag-open-pos | |
2368 (nth 1 nxml-dynamic-markup-prev-lengths))) | |
2369 (start-tag-open-pos | |
2370 (- start-tag-close-pos | |
2371 (nth 0 nxml-dynamic-markup-prev-lengths)))) | |
2372 (delete-region end-tag-open-pos nxml-dynamic-markup-prev-pos) | |
2373 (delete-region start-tag-open-pos start-tag-close-pos) | |
2374 (setq search-start-pos | |
2375 (marker-position nxml-dynamic-markup-prev-found-marker))) | |
2376 (clrhash nxml-dynamic-markup-prev-start-tags)) | |
2377 (setq nxml-dynamic-markup-prev-pos nil) | |
2378 (setq nxml-dynamic-markup-prev-lengths nil) | |
2379 (setq nxml-dynamic-markup-prev-found-marker nil) | |
2380 (goto-char | |
2381 (save-excursion | |
2382 (let* ((pos (point)) | |
2383 (word (progn | |
2384 (backward-word 1) | |
2385 (unless (< (point) pos) | |
2386 (error "No word to markup")) | |
2387 (buffer-substring-no-properties (point) pos))) | |
2388 (search (concat word "</")) | |
2389 done) | |
2390 (when search-start-pos | |
2391 (goto-char search-start-pos)) | |
2392 (while (and (not done) | |
2393 (or (and (< (point) pos) | |
2394 (or (search-backward search nil t) | |
2395 (progn (goto-char pos) nil))) | |
2396 (search-forward search nil t))) | |
2397 (goto-char (- (match-end 0) 2)) | |
2398 (setq done (nxml-try-copy-markup pos))) | |
2399 (or done | |
2400 (error (if (zerop (hash-table-count | |
2401 nxml-dynamic-markup-prev-start-tags)) | |
2402 "No possible markup found for `%s'" | |
2403 "No more markup possibilities found for `%s'") | |
2404 word))))))) | |
2405 | |
2406 (defun nxml-try-copy-markup (word-end-pos) | |
2407 (save-excursion | |
2408 (let ((end-tag-pos (point))) | |
2409 (when (and (not (nxml-get-inside end-tag-pos)) | |
2410 (search-backward "<" nil t) | |
2411 (not (nxml-get-inside (point)))) | |
2412 (xmltok-forward) | |
2413 (when (and (eq xmltok-type 'start-tag) | |
2414 (< (point) end-tag-pos)) | |
2415 (let* ((start-tag-close-pos (point)) | |
2416 (start-tag | |
2417 (buffer-substring-no-properties xmltok-start | |
2418 start-tag-close-pos)) | |
2419 (words | |
2420 (nreverse | |
2421 (split-string | |
2422 (buffer-substring-no-properties start-tag-close-pos | |
2423 end-tag-pos) | |
2424 "[ \t\r\n]+")))) | |
2425 (goto-char word-end-pos) | |
2426 (while (and words | |
2427 (re-search-backward (concat | |
2428 (regexp-quote (car words)) | |
2429 "\\=") | |
2430 nil | |
2431 t)) | |
2432 (setq words (cdr words)) | |
2433 (skip-chars-backward " \t\r\n")) | |
2434 (when (and (not words) | |
2435 (progn | |
2436 (skip-chars-forward " \t\r\n") | |
2437 (not (gethash (cons (point) start-tag) | |
2438 nxml-dynamic-markup-prev-start-tags))) | |
2439 (or (< end-tag-pos (point)) | |
2440 (< word-end-pos xmltok-start))) | |
2441 (setq nxml-dynamic-markup-prev-found-marker | |
2442 (copy-marker end-tag-pos t)) | |
2443 (puthash (cons (point) start-tag) | |
2444 t | |
2445 nxml-dynamic-markup-prev-start-tags) | |
2446 (setq nxml-dynamic-markup-prev-lengths | |
2447 (list (- start-tag-close-pos xmltok-start) | |
2448 (- word-end-pos (point)) | |
2449 (+ (- xmltok-name-end xmltok-start) 2))) | |
2450 (let ((name (xmltok-start-tag-qname))) | |
2451 (insert start-tag) | |
2452 (goto-char (+ word-end-pos | |
2453 (- start-tag-close-pos xmltok-start))) | |
2454 (insert "</" name ">") | |
2455 (setq nxml-dynamic-markup-prev-pos (point)))))))))) | |
2456 | |
2457 | |
2458 ;;; Character names | |
2459 | |
87715
39844b05431b
(nxml-char-name-ignore-case): Change default value.
Jason Rumney <jasonr@gnu.org>
parents:
87712
diff
changeset
|
2460 (defvar nxml-char-name-ignore-case t) |
86361 | 2461 |
2462 (defvar nxml-char-name-alist nil | |
2463 "Alist of character names. | |
2464 Each member of the list has the form (NAME CODE . NAMESET), | |
2465 where NAME is a string naming a character, NAMESET is a symbol | |
2466 identifying a set of names and CODE is an integer specifying the | |
2467 Unicode scalar value of the named character. | |
2468 The NAME will only be used for completion if NAMESET has | |
2469 a non-nil `nxml-char-name-set-enabled' property. | |
2470 If NAMESET does does not have `nxml-char-name-set-defined' property, | |
2471 then it must have a `nxml-char-name-set-file' property and `load' | |
2472 will be applied to the value of this property if the nameset | |
2473 is enabled.") | |
2474 | |
2475 (defvar nxml-char-name-table (make-hash-table :test 'eq) | |
2476 "Hash table for mapping char codes to names. | |
2477 Each key is a Unicode scalar value. | |
2478 Each value is a list of pairs of the form (NAMESET . NAME), | |
2479 where NAMESET is a symbol identifying a set of names, | |
2480 and NAME is a string naming a character.") | |
2481 | |
2482 (defvar nxml-autoload-char-name-set-list nil | |
2483 "List of char namesets that can be autoloaded.") | |
2484 | |
2485 (defun nxml-enable-char-name-set (nameset) | |
2486 (put nameset 'nxml-char-name-set-enabled t)) | |
2487 | |
2488 (defun nxml-disable-char-name-set (nameset) | |
2489 (put nameset 'nxml-char-name-set-enabled nil)) | |
2490 | |
2491 (defun nxml-char-name-set-enabled-p (nameset) | |
2492 (get nameset 'nxml-char-name-set-enabled)) | |
2493 | |
2494 (defun nxml-autoload-char-name-set (nameset file) | |
2495 (unless (memq nameset nxml-autoload-char-name-set-list) | |
2496 (setq nxml-autoload-char-name-set-list | |
2497 (cons nameset nxml-autoload-char-name-set-list))) | |
2498 (put nameset 'nxml-char-name-set-file file)) | |
2499 | |
2500 (defun nxml-define-char-name-set (nameset alist) | |
2501 "Define a set of character names. | |
2502 NAMESET is a symbol identifying the set. | |
2503 Alist is a list where each member has the form (NAME CODE), | |
2504 where NAME is a string naming a character and code | |
2505 is an integer giving the Unicode scalar value of the character." | |
2506 (when (get nameset 'nxml-char-name-set-defined) | |
2507 (error "Nameset `%s' already defined" nameset)) | |
2508 (let ((iter alist)) | |
2509 (while iter | |
2510 (let* ((name-code (car iter)) | |
2511 (name (car name-code)) | |
2512 (code (cadr name-code))) | |
2513 (puthash code | |
2514 (cons (cons nameset name) | |
2515 (gethash code nxml-char-name-table)) | |
2516 nxml-char-name-table)) | |
2517 (setcdr (cdr (car iter)) nameset) | |
2518 (setq iter (cdr iter)))) | |
2519 (setq nxml-char-name-alist | |
2520 (nconc alist nxml-char-name-alist)) | |
2521 (put nameset 'nxml-char-name-set-defined t)) | |
2522 | |
2523 (defun nxml-get-char-name (code) | |
86538 | 2524 (mapc 'nxml-maybe-load-char-name-set nxml-autoload-char-name-set-list) |
86361 | 2525 (let ((names (gethash code nxml-char-name-table)) |
2526 name) | |
2527 (while (and names (not name)) | |
2528 (if (nxml-char-name-set-enabled-p (caar names)) | |
2529 (setq name (cdar names)) | |
2530 (setq names (cdr names)))) | |
2531 name)) | |
2532 | |
2533 (defvar nxml-named-char-history nil) | |
2534 | |
2535 (defun nxml-insert-named-char (arg) | |
2536 "Insert a character using its name. | |
2537 The name is read from the minibuffer. | |
2538 Normally, inserts the character as a numeric character reference. | |
2539 With a prefix argument, inserts the character directly." | |
2540 (interactive "*P") | |
86538 | 2541 (mapc 'nxml-maybe-load-char-name-set nxml-autoload-char-name-set-list) |
86361 | 2542 (let ((name |
2543 (let ((completion-ignore-case nxml-char-name-ignore-case)) | |
2544 (completing-read "Character name: " | |
2545 nxml-char-name-alist | |
2546 (lambda (member) | |
2547 (get (cddr member) 'nxml-char-name-set-enabled)) | |
2548 t | |
2549 nil | |
2550 'nxml-named-char-history))) | |
2551 (alist nxml-char-name-alist) | |
2552 elt code) | |
2553 (while (and alist (not code)) | |
2554 (setq elt (assoc name alist)) | |
2555 (if (get (cddr elt) 'nxml-char-name-set-enabled) | |
2556 (setq code (cadr elt)) | |
2557 (setq alist (cdr (member elt alist))))) | |
2558 (when code | |
2559 (insert (if arg | |
2560 (or (decode-char 'ucs code) | |
2561 (error "Character %x is not supported by Emacs" | |
2562 code)) | |
2563 (format "&#x%X;" code)))))) | |
2564 | |
2565 (defun nxml-maybe-load-char-name-set (sym) | |
2566 (when (and (get sym 'nxml-char-name-set-enabled) | |
2567 (not (get sym 'nxml-char-name-set-defined)) | |
2568 (stringp (get sym 'nxml-char-name-set-file))) | |
2569 (load (get sym 'nxml-char-name-set-file)))) | |
2570 | |
2571 (defun nxml-toggle-char-ref-extra-display (arg) | |
2572 "*Toggle the display of extra information for character references." | |
2573 (interactive "P") | |
2574 (let ((new (if (null arg) | |
2575 (not nxml-char-ref-extra-display) | |
2576 (> (prefix-numeric-value arg) 0)))) | |
2577 (when (not (eq new nxml-char-ref-extra-display)) | |
2578 (setq nxml-char-ref-extra-display new) | |
2579 (save-excursion | |
2580 (save-restriction | |
2581 (widen) | |
2582 (if nxml-char-ref-extra-display | |
2583 (nxml-with-unmodifying-text-property-changes | |
2584 (nxml-clear-fontified (point-min) (point-max))) | |
2585 (nxml-clear-char-ref-extra-display (point-min) (point-max)))))))) | |
2586 | |
2587 (put 'nxml-char-ref 'evaporate t) | |
2588 | |
2589 (defun nxml-char-ref-display-extra (start end n) | |
2590 (when nxml-char-ref-extra-display | |
2591 (let ((name (nxml-get-char-name n)) | |
2592 (glyph-string (and nxml-char-ref-display-glyph-flag | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
2593 (nxml-glyph-display-string n 'nxml-glyph))) |
86361 | 2594 ov) |
2595 (when (or name glyph-string) | |
2596 (setq ov (make-overlay start end nil t)) | |
2597 (overlay-put ov 'category 'nxml-char-ref) | |
2598 (when name | |
2599 (overlay-put ov 'help-echo name)) | |
2600 (when glyph-string | |
2601 (overlay-put ov | |
2602 'after-string | |
87348
3d42d5ccb130
(nxml-faces): Rename from nxml-highlighting-faces.
Jason Rumney <jasonr@gnu.org>
parents:
86538
diff
changeset
|
2603 (propertize glyph-string 'face 'nxml-glyph))))))) |
86361 | 2604 |
2605 (defun nxml-clear-char-ref-extra-display (start end) | |
2606 (let ((ov (overlays-in start end))) | |
2607 (while ov | |
2608 (when (eq (overlay-get (car ov) 'category) 'nxml-char-ref) | |
2609 (delete-overlay (car ov))) | |
2610 (setq ov (cdr ov))))) | |
2611 | |
2612 | |
2613 (defun nxml-start-delimiter-length (type) | |
2614 (or (get type 'nxml-start-delimiter-length) | |
2615 0)) | |
2616 | |
2617 (put 'cdata-section 'nxml-start-delimiter-length 9) | |
2618 (put 'comment 'nxml-start-delimiter-length 4) | |
2619 (put 'processing-instruction 'nxml-start-delimiter-length 2) | |
2620 (put 'start-tag 'nxml-start-delimiter-length 1) | |
2621 (put 'empty-element 'nxml-start-delimiter-length 1) | |
2622 (put 'partial-empty-element 'nxml-start-delimiter-length 1) | |
2623 (put 'entity-ref 'nxml-start-delimiter-length 1) | |
2624 (put 'char-ref 'nxml-start-delimiter-length 2) | |
2625 | |
2626 (defun nxml-end-delimiter-length (type) | |
2627 (or (get type 'nxml-end-delimiter-length) | |
2628 0)) | |
2629 | |
2630 (put 'cdata-section 'nxml-end-delimiter-length 3) | |
2631 (put 'comment 'nxml-end-delimiter-length 3) | |
2632 (put 'processing-instruction 'nxml-end-delimiter-length 2) | |
2633 (put 'start-tag 'nxml-end-delimiter-length 1) | |
2634 (put 'empty-element 'nxml-end-delimiter-length 2) | |
2635 (put 'partial-empty-element 'nxml-end-delimiter-length 1) | |
2636 (put 'entity-ref 'nxml-end-delimiter-length 1) | |
2637 (put 'char-ref 'nxml-end-delimiter-length 1) | |
2638 | |
2639 (defun nxml-token-type-friendly-name (type) | |
2640 (or (get type 'nxml-friendly-name) | |
2641 (symbol-name type))) | |
2642 | |
2643 (put 'cdata-section 'nxml-friendly-name "CDATA section") | |
2644 (put 'processing-instruction 'nxml-friendly-name "processing instruction") | |
2645 (put 'entity-ref 'nxml-friendly-name "entity reference") | |
2646 (put 'char-ref 'nxml-friendly-name "character reference") | |
2647 | |
2648 (provide 'nxml-mode) | |
2649 | |
86379 | 2650 ;; arch-tag: 8603bc5f-1ef9-4021-b223-322fb2ca708e |
86361 | 2651 ;;; nxml-mode.el ends here |