Mercurial > emacs
annotate lisp/nxml/rng-maint.el @ 87006:a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
(doc-view-current-overlay, doc-view-pending-cache-flush): Add doc
string.
author | Reiner Steib <Reiner.Steib@gmx.de> |
---|---|
date | Mon, 03 Dec 2007 07:24:34 +0000 |
parents | d41a39f17964 |
children | 24f44404f3aa |
rev | line source |
---|---|
86361 | 1 ;;; rng-maint.el --- commands for RELAX NG maintainers |
2 | |
86548 | 3 ;; Copyright (C) 2003, 2007 Free Software Foundation, Inc. |
86361 | 4 |
5 ;; Author: James Clark | |
6 ;; Keywords: XML, RelaxNG | |
7 | |
86548 | 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 |
86548 | 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 |
86548 | 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 ;;; Code: | |
28 | |
29 (require 'xmltok) | |
30 (require 'nxml-mode) | |
31 (require 'texnfo-upd) | |
32 | |
33 (defvar rng-dir (file-name-directory load-file-name)) | |
34 | |
35 (defconst rng-autoload-modules | |
36 '(xmltok | |
37 nxml-mode | |
38 nxml-uchnm | |
39 nxml-glyph | |
40 rng-cmpct | |
41 rng-maint | |
42 rng-valid | |
43 rng-xsd | |
44 rng-nxml)) | |
45 | |
46 ;;;###autoload | |
47 (defun rng-update-autoloads () | |
48 "Update the autoloads in rng-auto.el." | |
49 (interactive) | |
50 (let* ((generated-autoload-file (expand-file-name "rng-auto.el" | |
51 rng-dir))) | |
52 (mapcar (lambda (x) | |
53 (update-file-autoloads | |
54 (expand-file-name (concat (symbol-name x) ".el") rng-dir))) | |
55 rng-autoload-modules))) | |
56 | |
57 | |
58 (defconst rng-compile-modules | |
59 '(xmltok | |
60 nxml-util | |
61 nxml-enc | |
62 nxml-glyph | |
63 nxml-rap | |
64 nxml-outln | |
65 nxml-mode | |
66 nxml-uchnm | |
67 nxml-ns | |
68 nxml-parse | |
69 nxml-maint | |
70 xsd-regexp | |
71 rng-util | |
72 rng-dt | |
73 rng-xsd | |
74 rng-uri | |
75 rng-pttrn | |
76 rng-cmpct | |
77 rng-match | |
78 rng-parse | |
79 rng-loc | |
80 rng-valid | |
81 rng-nxml | |
82 rng-maint)) | |
83 | |
84 ;;;###autoload | |
85 (defun rng-byte-compile-load () | |
86 "Byte-compile and load all of the RELAX NG library in an appropriate order." | |
87 (interactive) | |
88 (mapcar (lambda (x) | |
89 (byte-compile-file (expand-file-name (concat (symbol-name x) ".el") | |
90 rng-dir) | |
91 t)) | |
92 rng-compile-modules)) | |
93 | |
94 | |
95 ;;; Conversion from XML to texinfo. | |
96 ;; This is all a hack and is just enough to make the conversion work. | |
97 ;; It's not intended for public use. | |
98 | |
99 (defvar rng-manual-base "nxml-mode") | |
100 (defvar rng-manual-xml (concat rng-manual-base ".xml")) | |
101 (defvar rng-manual-texi (concat rng-manual-base ".texi")) | |
102 (defvar rng-manual-info (concat rng-manual-base ".info")) | |
103 | |
104 ;;;###autoload | |
105 (defun rng-format-manual () | |
106 "Create manual.texi from manual.xml." | |
107 (interactive) | |
108 (let ((xml-buf (find-file-noselect (expand-file-name rng-manual-xml | |
109 rng-dir))) | |
110 (texi-buf (find-file-noselect (expand-file-name rng-manual-texi | |
111 rng-dir)))) | |
112 (save-excursion | |
113 (set-buffer texi-buf) | |
114 (erase-buffer) | |
115 (let ((standard-output texi-buf)) | |
116 (princ (format "\\input texinfo @c -*- texinfo -*-\n\ | |
117 @c %%**start of header\n\ | |
118 @setfilename %s\n\ | |
119 @settitle \n\ | |
120 @c %%**end of header\n" rng-manual-info)) | |
121 (set-buffer xml-buf) | |
122 (goto-char (point-min)) | |
123 (xmltok-save | |
124 (xmltok-forward-prolog) | |
125 (rng-process-tokens)) | |
126 (princ "\n@bye\n")) | |
127 (set-buffer texi-buf) | |
128 (rng-manual-fixup) | |
129 (texinfo-insert-node-lines (point-min) (point-max) t) | |
130 (texinfo-all-menus-update) | |
131 (save-buffer)))) | |
132 | |
133 (defun rng-manual-fixup () | |
134 (goto-char (point-min)) | |
135 (search-forward "@top ") | |
136 (let ((pos (point))) | |
137 (search-forward "\n") | |
138 (let ((title (buffer-substring-no-properties pos (1- (point))))) | |
139 (goto-char (point-min)) | |
140 (search-forward "@settitle ") | |
141 (insert title) | |
142 (search-forward "@node") | |
143 (goto-char (match-beginning 0)) | |
144 (insert "@dircategory Emacs\n" | |
145 "@direntry\n* " | |
146 title | |
147 ": (" | |
148 rng-manual-info | |
149 ").\n@end direntry\n\n")))) | |
150 | |
151 (defvar rng-manual-inline-elements '(kbd key samp code var emph uref point)) | |
152 | |
153 (defun rng-process-tokens () | |
154 (let ((section-depth 0) | |
155 ;; stack of per-element space treatment | |
156 ;; t means keep, nil means discard, fill means no blank lines | |
157 (keep-space-stack (list nil)) | |
158 (ignore-following-newline nil) | |
159 (want-blank-line nil) | |
160 name startp endp data keep-space-for-children) | |
161 (while (xmltok-forward) | |
162 (cond ((memq xmltok-type '(start-tag empty-element end-tag)) | |
163 (setq startp (memq xmltok-type '(start-tag empty-element))) | |
164 (setq endp (memq xmltok-type '(end-tag empty-element))) | |
165 (setq name (intern (if startp | |
166 (xmltok-start-tag-qname) | |
167 (xmltok-end-tag-qname)))) | |
168 (setq keep-space-for-children nil) | |
169 (setq ignore-following-newline nil) | |
170 (cond ((memq name rng-manual-inline-elements) | |
171 (when startp | |
172 (when want-blank-line | |
173 (rng-manual-output-force-blank-line) | |
174 (when (eq want-blank-line 'noindent) | |
175 (princ "@noindent\n")) | |
176 (setq want-blank-line nil)) | |
177 (setq keep-space-for-children t) | |
178 (princ (format "@%s{" name))) | |
179 (when endp (princ "}"))) | |
180 ((eq name 'ulist) | |
181 (when startp | |
182 (rng-manual-output-force-blank-line) | |
183 (setq want-blank-line nil) | |
184 (princ "@itemize @bullet\n")) | |
185 (when endp | |
186 (rng-manual-output-force-new-line) | |
187 (setq want-blank-line 'noindent) | |
188 (princ "@end itemize\n"))) | |
189 ((eq name 'item) | |
190 (rng-manual-output-force-new-line) | |
191 (setq want-blank-line endp) | |
192 (when startp (princ "@item\n"))) | |
193 ((memq name '(example display)) | |
194 (when startp | |
195 (setq ignore-following-newline t) | |
196 (rng-manual-output-force-blank-line) | |
197 (setq want-blank-line nil) | |
198 (setq keep-space-for-children t) | |
199 (princ (format "@%s\n" name))) | |
200 (when endp | |
201 (rng-manual-output-force-new-line) | |
202 (setq want-blank-line 'noindent) | |
203 (princ (format "@end %s\n" name)))) | |
204 ((eq name 'para) | |
205 (rng-manual-output-force-new-line) | |
206 (when startp | |
207 (when want-blank-line | |
208 (setq want-blank-line t)) | |
209 (setq keep-space-for-children 'fill)) | |
210 (when endp (setq want-blank-line t))) | |
211 ((eq name 'section) | |
212 (when startp | |
213 (rng-manual-output-force-blank-line) | |
214 (when (eq section-depth 0) | |
215 (princ "@node Top\n")) | |
216 (princ "@") | |
217 (princ (nth section-depth '(top | |
218 chapter | |
219 section | |
220 subsection | |
221 subsubsection))) | |
222 (princ " ") | |
223 (setq want-blank-line nil) | |
224 (setq section-depth (1+ section-depth))) | |
225 (when endp | |
226 (rng-manual-output-force-new-line) | |
227 (setq want-blank-line nil) | |
228 (setq section-depth (1- section-depth)))) | |
229 ((eq name 'title) | |
230 (when startp | |
231 (setq keep-space-for-children 'fill)) | |
232 (when endp | |
233 (setq want-blank-line t) | |
234 (princ "\n")))) | |
235 (when startp | |
236 (setq keep-space-stack (cons keep-space-for-children | |
237 keep-space-stack))) | |
238 (when endp | |
239 (setq keep-space-stack (cdr keep-space-stack)))) | |
240 ((memq xmltok-type '(data | |
241 space | |
242 char-ref | |
243 entity-ref | |
244 cdata-section)) | |
245 (setq data nil) | |
246 (cond ((memq xmltok-type '(data space)) | |
247 (setq data (buffer-substring-no-properties xmltok-start | |
248 (point)))) | |
249 ((and (memq xmltok-type '(char-ref entity-ref)) | |
250 xmltok-replacement) | |
251 (setq data xmltok-replacement)) | |
252 ((eq xmltok-type 'cdata-section) | |
253 (setq data | |
254 (buffer-substring-no-properties (+ xmltok-start 9) | |
255 (- (point) 3))))) | |
256 (when (and data (car keep-space-stack)) | |
257 (setq data (replace-regexp-in-string "[@{}]" | |
258 "@\\&" | |
259 data | |
260 t)) | |
261 (when ignore-following-newline | |
262 (setq data (replace-regexp-in-string "\\`\n" "" data t))) | |
263 (setq ignore-following-newline nil) | |
264 ;; (when (eq (car keep-space-stack) 'fill) | |
265 ;; (setq data (replace-regexp-in-string "\n" " " data t))) | |
266 (when (eq want-blank-line 'noindent) | |
267 (setq data (replace-regexp-in-string "\\`\n*" "" data t))) | |
268 (when (> (length data) 0) | |
269 (when want-blank-line | |
270 (rng-manual-output-force-blank-line) | |
271 (when (eq want-blank-line 'noindent) | |
272 (princ "@noindent\n")) | |
273 (setq want-blank-line nil)) | |
274 (princ data)))) | |
275 )))) | |
276 | |
277 (defun rng-manual-output-force-new-line () | |
278 (save-excursion | |
279 (set-buffer standard-output) | |
280 (unless (eq (char-before) ?\n) | |
281 (insert ?\n)))) | |
282 | |
283 (defun rng-manual-output-force-blank-line () | |
284 (save-excursion | |
285 (set-buffer standard-output) | |
286 (if (eq (char-before) ?\n) | |
287 (unless (eq (char-before (1- (point))) ?\n) | |
288 (insert ?\n)) | |
289 (insert "\n\n")))) | |
290 | |
291 ;;; Versioning | |
292 | |
293 ;;;###autoload | |
294 (defun rng-write-version () | |
295 (find-file "VERSION") | |
296 (erase-buffer) | |
297 (insert nxml-version "\n") | |
298 (save-buffer)) | |
299 | |
300 ;;; Timing | |
301 | |
302 (defun rng-time-to-float (time) | |
303 (+ (* (nth 0 time) 65536.0) | |
304 (nth 1 time) | |
305 (/ (nth 2 time) 1000000.0))) | |
306 | |
307 (defun rng-time-function (function &rest args) | |
308 (let* ((start (current-time)) | |
309 (val (apply function args)) | |
310 (end (current-time))) | |
311 (message "%s ran in %g seconds" | |
312 function | |
313 (- (rng-time-to-float end) | |
314 (rng-time-to-float start))) | |
315 val)) | |
316 | |
317 (defun rng-time-tokenize-buffer () | |
318 (interactive) | |
319 (rng-time-function 'rng-tokenize-buffer)) | |
320 | |
321 (defun rng-tokenize-buffer () | |
322 (save-excursion | |
323 (goto-char (point-min)) | |
324 (xmltok-save | |
325 (xmltok-forward-prolog) | |
326 (while (xmltok-forward))))) | |
327 | |
328 (defun rng-time-validate-buffer () | |
329 (interactive) | |
330 (rng-time-function 'rng-validate-buffer)) | |
331 | |
86851
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86548
diff
changeset
|
332 (defvar rng-error-count) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86548
diff
changeset
|
333 (defvar rng-validate-up-to-date-end) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86548
diff
changeset
|
334 (declare-function rng-clear-cached-state "rng-valid" (start end)) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86548
diff
changeset
|
335 (declare-function rng-clear-overlays "rng-valid" (beg end)) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86548
diff
changeset
|
336 (declare-function rng-clear-conditional-region "rng-valid" ()) |
86866
d41a39f17964
(rng-do-some-validation): Fix declaration.
Glenn Morris <rgm@gnu.org>
parents:
86851
diff
changeset
|
337 (declare-function rng-do-some-validation "rng-valid" |
d41a39f17964
(rng-do-some-validation): Fix declaration.
Glenn Morris <rgm@gnu.org>
parents:
86851
diff
changeset
|
338 (&optional continue-p-function)) |
86851
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
86548
diff
changeset
|
339 |
86361 | 340 (defun rng-validate-buffer () |
341 (save-restriction | |
342 (widen) | |
343 (nxml-with-unmodifying-text-property-changes | |
344 (rng-clear-cached-state (point-min) (point-max))) | |
345 ;; 1+ to clear empty overlays at (point-max) | |
346 (rng-clear-overlays (point-min) (1+ (point-max)))) | |
347 (setq rng-validate-up-to-date-end 1) | |
348 (rng-clear-conditional-region) | |
349 (setq rng-error-count 0) | |
350 (while (rng-do-some-validation | |
351 (lambda () t)))) | |
352 | |
86379 | 353 ;; arch-tag: 4b8c6143-daac-4888-9c61-9bea6f935f17 |
86361 | 354 ;;; rng-maint.el ends here |