1 ;;; rng-maint.el --- commands for RELAX NG maintainers
3 ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
6 ;; Keywords: XML, RelaxNG
8 ;; This file is part of GNU Emacs.
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)
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.
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.
33 (defvar rng-dir
(file-name-directory load-file-name
))
35 ;;; Conversion from XML to texinfo.
36 ;; This is all a hack and is just enough to make the conversion work.
37 ;; It's not intended for public use.
39 (defvar rng-manual-base
"nxml-mode")
40 (defvar rng-manual-xml
(concat rng-manual-base
".xml"))
41 (defvar rng-manual-texi
(concat rng-manual-base
".texi"))
42 (defvar rng-manual-info
(concat rng-manual-base
".info"))
44 (defun rng-format-manual ()
45 "Create manual.texi from manual.xml."
47 (let ((xml-buf (find-file-noselect (expand-file-name rng-manual-xml
49 (texi-buf (find-file-noselect (expand-file-name rng-manual-texi
54 (let ((standard-output texi-buf
))
55 (princ (format "\\input texinfo @c -*- texinfo -*-\n\
56 @c %%**start of header\n\
59 @c %%**end of header\n" rng-manual-info
))
61 (goto-char (point-min))
63 (xmltok-forward-prolog)
68 (texinfo-insert-node-lines (point-min) (point-max) t
)
69 (texinfo-all-menus-update)
72 (defun rng-manual-fixup ()
73 (goto-char (point-min))
74 (search-forward "@top ")
77 (let ((title (buffer-substring-no-properties pos
(1- (point)))))
78 (goto-char (point-min))
79 (search-forward "@settitle ")
81 (search-forward "@node")
82 (goto-char (match-beginning 0))
83 (insert "@dircategory Emacs\n"
88 ").\n@end direntry\n\n"))))
90 (defvar rng-manual-inline-elements
'(kbd key samp code var emph uref point
))
92 (defun rng-process-tokens ()
93 (let ((section-depth 0)
94 ;; stack of per-element space treatment
95 ;; t means keep, nil means discard, fill means no blank lines
96 (keep-space-stack (list nil
))
97 (ignore-following-newline nil
)
99 name startp endp data keep-space-for-children
)
100 (while (xmltok-forward)
101 (cond ((memq xmltok-type
'(start-tag empty-element end-tag
))
102 (setq startp
(memq xmltok-type
'(start-tag empty-element
)))
103 (setq endp
(memq xmltok-type
'(end-tag empty-element
)))
104 (setq name
(intern (if startp
105 (xmltok-start-tag-qname)
106 (xmltok-end-tag-qname))))
107 (setq keep-space-for-children nil
)
108 (setq ignore-following-newline nil
)
109 (cond ((memq name rng-manual-inline-elements
)
111 (when want-blank-line
112 (rng-manual-output-force-blank-line)
113 (when (eq want-blank-line
'noindent
)
114 (princ "@noindent\n"))
115 (setq want-blank-line nil
))
116 (setq keep-space-for-children t
)
117 (princ (format "@%s{" name
)))
118 (when endp
(princ "}")))
121 (rng-manual-output-force-blank-line)
122 (setq want-blank-line nil
)
123 (princ "@itemize @bullet\n"))
125 (rng-manual-output-force-new-line)
126 (setq want-blank-line
'noindent
)
127 (princ "@end itemize\n")))
129 (rng-manual-output-force-new-line)
130 (setq want-blank-line endp
)
131 (when startp
(princ "@item\n")))
132 ((memq name
'(example display
))
134 (setq ignore-following-newline t
)
135 (rng-manual-output-force-blank-line)
136 (setq want-blank-line nil
)
137 (setq keep-space-for-children t
)
138 (princ (format "@%s\n" name
)))
140 (rng-manual-output-force-new-line)
141 (setq want-blank-line
'noindent
)
142 (princ (format "@end %s\n" name
))))
144 (rng-manual-output-force-new-line)
146 (when want-blank-line
147 (setq want-blank-line t
))
148 (setq keep-space-for-children
'fill
))
149 (when endp
(setq want-blank-line t
)))
152 (rng-manual-output-force-blank-line)
153 (when (eq section-depth
0)
154 (princ "@node Top\n"))
156 (princ (nth section-depth
'(top
162 (setq want-blank-line nil
)
163 (setq section-depth
(1+ section-depth
)))
165 (rng-manual-output-force-new-line)
166 (setq want-blank-line nil
)
167 (setq section-depth
(1- section-depth
))))
170 (setq keep-space-for-children
'fill
))
172 (setq want-blank-line t
)
175 (setq keep-space-stack
(cons keep-space-for-children
178 (setq keep-space-stack
(cdr keep-space-stack
))))
179 ((memq xmltok-type
'(data
185 (cond ((memq xmltok-type
'(data space
))
186 (setq data
(buffer-substring-no-properties xmltok-start
188 ((and (memq xmltok-type
'(char-ref entity-ref
))
190 (setq data xmltok-replacement
))
191 ((eq xmltok-type
'cdata-section
)
193 (buffer-substring-no-properties (+ xmltok-start
9)
195 (when (and data
(car keep-space-stack
))
196 (setq data
(replace-regexp-in-string "[@{}]"
200 (when ignore-following-newline
201 (setq data
(replace-regexp-in-string "\\`\n" "" data t
)))
202 (setq ignore-following-newline nil
)
203 ;; (when (eq (car keep-space-stack) 'fill)
204 ;; (setq data (replace-regexp-in-string "\n" " " data t)))
205 (when (eq want-blank-line
'noindent
)
206 (setq data
(replace-regexp-in-string "\\`\n*" "" data t
)))
207 (when (> (length data
) 0)
208 (when want-blank-line
209 (rng-manual-output-force-blank-line)
210 (when (eq want-blank-line
'noindent
)
211 (princ "@noindent\n"))
212 (setq want-blank-line nil
))
216 (defun rng-manual-output-force-new-line ()
218 (set-buffer standard-output
)
219 (unless (eq (char-before) ?
\n)
222 (defun rng-manual-output-force-blank-line ()
224 (set-buffer standard-output
)
225 (if (eq (char-before) ?
\n)
226 (unless (eq (char-before (1- (point))) ?
\n)
232 (defun rng-time-to-float (time)
233 (+ (* (nth 0 time
) 65536.0)
235 (/ (nth 2 time
) 1000000.0)))
237 (defun rng-time-function (function &rest args
)
238 (let* ((start (current-time))
239 (val (apply function args
))
240 (end (current-time)))
241 (message "%s ran in %g seconds"
243 (- (rng-time-to-float end
)
244 (rng-time-to-float start
)))
247 (defun rng-time-tokenize-buffer ()
249 (rng-time-function 'rng-tokenize-buffer
))
251 (defun rng-tokenize-buffer ()
253 (goto-char (point-min))
255 (xmltok-forward-prolog)
256 (while (xmltok-forward)))))
258 (defun rng-time-validate-buffer ()
260 (rng-time-function 'rng-validate-buffer
))
262 (defvar rng-error-count
)
263 (defvar rng-validate-up-to-date-end
)
264 (declare-function rng-clear-cached-state
"rng-valid" (start end
))
265 (declare-function rng-clear-overlays
"rng-valid" (beg end
))
266 (declare-function rng-clear-conditional-region
"rng-valid" ())
267 (declare-function rng-do-some-validation
"rng-valid"
268 (&optional continue-p-function
))
270 (defun rng-validate-buffer ()
273 (nxml-with-unmodifying-text-property-changes
274 (rng-clear-cached-state (point-min) (point-max)))
275 ;; 1+ to clear empty overlays at (point-max)
276 (rng-clear-overlays (point-min) (1+ (point-max))))
277 (setq rng-validate-up-to-date-end
1)
278 (rng-clear-conditional-region)
279 (setq rng-error-count
0)
280 (while (rng-do-some-validation
283 ;; arch-tag: 4b8c6143-daac-4888-9c61-9bea6f935f17
284 ;;; rng-maint.el ends here