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
|
|
332 (defun rng-validate-buffer ()
|
|
333 (save-restriction
|
|
334 (widen)
|
|
335 (nxml-with-unmodifying-text-property-changes
|
|
336 (rng-clear-cached-state (point-min) (point-max)))
|
|
337 ;; 1+ to clear empty overlays at (point-max)
|
|
338 (rng-clear-overlays (point-min) (1+ (point-max))))
|
|
339 (setq rng-validate-up-to-date-end 1)
|
|
340 (rng-clear-conditional-region)
|
|
341 (setq rng-error-count 0)
|
|
342 (while (rng-do-some-validation
|
|
343 (lambda () t))))
|
|
344
|
86379
|
345 ;; arch-tag: 4b8c6143-daac-4888-9c61-9bea6f935f17
|
86361
|
346 ;;; rng-maint.el ends here
|