Comment change.
[bpt/emacs.git] / lisp / textmodes / texinfmt.el
1 ;;; texinfmt.el --- format Texinfo files into Info files.
2
3 ;; Copyright (C) 1985, 1986, 1988,
4 ;; 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
5
6 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
7
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 2, or (at your option)
13 ;; any later version.
14
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.
19
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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Code:
25
26 ;;; Emacs lisp functions to convert Texinfo files to Info files.
27
28 (defvar texinfmt-version "2.32 of 19 November 1993")
29 \f
30 ;;; Variable definitions
31
32 (require 'texinfo) ; So `texinfo-footnote-style' is defined.
33 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
34
35 (defvar texinfo-format-syntax-table nil)
36
37 (defvar texinfo-vindex)
38 (defvar texinfo-findex)
39 (defvar texinfo-cindex)
40 (defvar texinfo-pindex)
41 (defvar texinfo-tindex)
42 (defvar texinfo-kindex)
43 (defvar texinfo-last-node)
44 (defvar texinfo-node-names)
45 (defvar texinfo-enclosure-list)
46 (defvar texinfo-alias-list)
47
48 (defvar texinfo-command-start)
49 (defvar texinfo-command-end)
50 (defvar texinfo-command-name)
51 (defvar texinfo-defun-type)
52 (defvar texinfo-last-node-pos)
53 (defvar texinfo-stack)
54 (defvar texinfo-short-index-cmds-alist)
55 (defvar texinfo-short-index-format-cmds-alist)
56 (defvar texinfo-format-filename)
57 (defvar texinfo-footnote-number)
58 (defvar texinfo-start-of-header)
59 (defvar texinfo-end-of-header)
60 (defvar texinfo-raisesections-alist)
61 (defvar texinfo-lowersections-alist)
62 \f
63 ;;; Syntax table
64
65 (if texinfo-format-syntax-table
66 nil
67 (setq texinfo-format-syntax-table (make-syntax-table))
68 (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
69 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
70 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
71 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
72 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
73 (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
74 (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
75 (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
76 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
77 (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
78 (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
79
80 \f
81 ;;; Top level buffer and region formatting functions
82
83 ;;;###autoload
84 (defun texinfo-format-buffer (&optional notagify)
85 "Process the current buffer as texinfo code, into an Info file.
86 The Info file output is generated in a buffer visiting the Info file
87 names specified in the @setfilename command.
88
89 Non-nil argument (prefix, if interactive) means don't make tag table
90 and don't split the file if large. You can use Info-tagify and
91 Info-split to do these manually."
92 (interactive "P")
93 (let ((lastmessage "Formatting Info file..."))
94 (message lastmessage)
95 (texinfo-format-buffer-1)
96 (if notagify
97 nil
98 (if (> (buffer-size) 30000)
99 (progn
100 (message (setq lastmessage "Making tags table for Info file..."))
101 (Info-tagify)))
102 (if (> (buffer-size) 100000)
103 (progn
104 (message (setq lastmessage "Splitting Info file..."))
105 (Info-split))))
106 (message (concat lastmessage
107 (if (interactive-p) "done. Now save it." "done.")))))
108
109 (defvar texinfo-region-buffer-name "*Info Region*"
110 "*Name of the temporary buffer used by \\[texinfo-format-region].")
111
112 ;;;###autoload
113 (defun texinfo-format-region (region-beginning region-end)
114 "Convert the current region of the Texinfo file to Info format.
115 This lets you see what that part of the file will look like in Info.
116 The command is bound to \\[texinfo-format-region]. The text that is
117 converted to Info is stored in a temporary buffer."
118 (interactive "r")
119 (message "Converting region to Info format...")
120 (let (texinfo-command-start
121 texinfo-command-end
122 texinfo-command-name
123 texinfo-vindex
124 texinfo-findex
125 texinfo-cindex
126 texinfo-pindex
127 texinfo-tindex
128 texinfo-kindex
129 texinfo-stack
130 (texinfo-format-filename "")
131 texinfo-example-start
132 texinfo-last-node-pos
133 texinfo-last-node
134 texinfo-node-names
135 (texinfo-footnote-number 0)
136 last-input-buffer
137 (fill-column-for-info fill-column)
138 (input-buffer (current-buffer))
139 (input-directory default-directory)
140 (header-text "")
141 (header-beginning 1)
142 (header-end 1))
143
144 ;;; Copy lines between beginning and end of header lines,
145 ;;; if any, or else copy the `@setfilename' line, if any.
146 (save-excursion
147 (save-restriction
148 (widen)
149 (goto-char (point-min))
150 (let ((search-end (save-excursion (forward-line 100) (point))))
151 (if (or
152 ;; Either copy header text.
153 (and
154 (prog1
155 (search-forward tex-start-of-header search-end t)
156 (forward-line 1)
157 ;; Mark beginning of header.
158 (setq header-beginning (point)))
159 (prog1
160 (search-forward tex-end-of-header nil t)
161 (beginning-of-line)
162 ;; Mark end of header
163 (setq header-end (point))))
164 ;; Or copy @filename line.
165 (prog2
166 (goto-char (point-min))
167 (search-forward "@setfilename" search-end t)
168 (beginning-of-line)
169 (setq header-beginning (point))
170 (forward-line 1)
171 (setq header-end (point))))
172
173 ;; Copy header
174 (setq header-text
175 (buffer-substring
176 (min header-beginning region-beginning)
177 header-end))))))
178
179 ;;; Find a buffer to use.
180 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
181 (erase-buffer)
182 ;; Insert the header into the buffer.
183 (insert header-text)
184 ;; Insert the region into the buffer.
185 (insert-buffer-substring
186 input-buffer
187 (max region-beginning header-end)
188 region-end)
189 ;; Make sure region ends in a newline.
190 (or (= (preceding-char) ?\n)
191 (insert "\n"))
192
193 (goto-char (point-min))
194 (texinfo-mode)
195 (message "Converting region to Info format...")
196 (setq fill-column fill-column-for-info)
197 ;; Install a syntax table useful for scanning command operands.
198 (set-syntax-table texinfo-format-syntax-table)
199
200 ;; Insert @include files so `texinfo-raise-lower-sections' can
201 ;; work on them without losing track of multiple
202 ;; @raise/@lowersections commands.
203 (while (re-search-forward "^@include" nil t)
204 (setq texinfo-command-end (point))
205 (let ((filename (concat input-directory
206 (texinfo-parse-line-arg))))
207 (re-search-backward "^@include")
208 (delete-region (point) (save-excursion (forward-line 1) (point)))
209 (message "Reading included file: %s" filename)
210 (save-excursion
211 (save-restriction
212 (narrow-to-region
213 (point)
214 (+ (point) (car (cdr (insert-file-contents filename)))))
215 (goto-char (point-min))
216 ;; Remove `@setfilename' line from included file, if any,
217 ;; so @setfilename command not duplicated.
218 (if (re-search-forward
219 "^@setfilename" (save-excursion (forward-line 100) (point)) t)
220 (progn
221 (beginning-of-line)
222 (delete-region
223 (point) (save-excursion (forward-line 1) (point)))))))))
224
225 ;; Raise or lower level of each section, if necessary.
226 (goto-char (point-min))
227 (texinfo-raise-lower-sections)
228 ;; Append @refill to appropriate paragraphs for filling.
229 (goto-char (point-min))
230 (texinfo-append-refill)
231 ;; If the region includes the effective end of the data,
232 ;; discard everything after that.
233 (goto-char (point-max))
234 (if (re-search-backward "^@bye" nil t)
235 (delete-region (point) (point-max)))
236 ;; Make sure buffer ends in a newline.
237 (or (= (preceding-char) ?\n)
238 (insert "\n"))
239 ;; Don't use a previous value of texinfo-enclosure-list.
240 (setq texinfo-enclosure-list nil)
241 (setq texinfo-alias-list nil)
242
243 (goto-char (point-min))
244 (if (looking-at "\\\\input[ \t]+texinfo")
245 (delete-region (point) (save-excursion (forward-line 1) (point))))
246
247 ;; Insert Info region title text.
248 (goto-char (point-min))
249 (if (search-forward
250 "@setfilename" (save-excursion (forward-line 100) (point)) t)
251 (progn
252 (setq texinfo-command-end (point))
253 (beginning-of-line)
254 (setq texinfo-command-start (point))
255 (let ((arg (texinfo-parse-arg-discard)))
256 (insert " "
257 texinfo-region-buffer-name
258 " buffer for: `")
259 (insert (file-name-nondirectory (expand-file-name arg)))
260 (insert "', -*-Text-*-\n")))
261 ;; Else no `@setfilename' line
262 (insert " "
263 texinfo-region-buffer-name
264 " buffer -*-Text-*-\n"))
265 (insert "produced by `texinfo-format-region'\n"
266 "from a region in: "
267 (if (buffer-file-name input-buffer)
268 (concat "`"
269 (file-name-sans-versions
270 (file-name-nondirectory
271 (buffer-file-name input-buffer)))
272 "'")
273 (concat "buffer `" (buffer-name input-buffer) "'"))
274 "\nusing `texinfmt.el' version "
275 texinfmt-version
276 ".\n\n")
277
278 ;; Now convert for real.
279 (goto-char (point-min))
280 (texinfo-format-scan)
281 (goto-char (point-min))
282
283 (message "Done.")))
284
285 \f
286 ;;; Primary internal formatting function for the whole buffer.
287
288 (defun texinfo-format-buffer-1 ()
289 (let (texinfo-format-filename
290 texinfo-example-start
291 texinfo-command-start
292 texinfo-command-end
293 texinfo-command-name
294 texinfo-last-node
295 texinfo-last-node-pos
296 texinfo-vindex
297 texinfo-findex
298 texinfo-cindex
299 texinfo-pindex
300 texinfo-tindex
301 texinfo-kindex
302 texinfo-stack
303 texinfo-node-names
304 (texinfo-footnote-number 0)
305 last-input-buffer
306 outfile
307 (fill-column-for-info fill-column)
308 (input-buffer (current-buffer))
309 (input-directory default-directory))
310 (setq texinfo-enclosure-list nil)
311 (setq texinfo-alias-list nil)
312 (save-excursion
313 (goto-char (point-min))
314 (or (search-forward "@setfilename" nil t)
315 (error "Texinfo file needs an `@setfilename FILENAME' line."))
316 (setq texinfo-command-end (point))
317 (setq outfile (texinfo-parse-line-arg)))
318 (find-file outfile)
319 (texinfo-mode)
320 (setq fill-column fill-column-for-info)
321 (set-syntax-table texinfo-format-syntax-table)
322 (erase-buffer)
323 (insert-buffer-substring input-buffer)
324 (message "Converting %s to Info format..." (buffer-name input-buffer))
325
326 ;; Insert @include files so `texinfo-raise-lower-sections' can
327 ;; work on them without losing track of multiple
328 ;; @raise/@lowersections commands.
329 (goto-char (point-min))
330 (while (re-search-forward "^@include" nil t)
331 (setq texinfo-command-end (point))
332 (let ((filename (concat input-directory
333 (texinfo-parse-line-arg))))
334 (re-search-backward "^@include")
335 (delete-region (point) (save-excursion (forward-line 1) (point)))
336 (message "Reading included file: %s" filename)
337 (save-excursion
338 (save-restriction
339 (narrow-to-region
340 (point)
341 (+ (point) (car (cdr (insert-file-contents filename)))))
342 (goto-char (point-min))
343 ;; Remove `@setfilename' line from included file, if any,
344 ;; so @setfilename command not duplicated.
345 (if (re-search-forward
346 "^@setfilename"
347 (save-excursion (forward-line 100) (point)) t)
348 (progn
349 (beginning-of-line)
350 (delete-region
351 (point) (save-excursion (forward-line 1) (point)))))))))
352 ;; Raise or lower level of each section, if necessary.
353 (goto-char (point-min))
354 (texinfo-raise-lower-sections)
355 ;; Append @refill to appropriate paragraphs
356 (goto-char (point-min))
357 (texinfo-append-refill)
358 (goto-char (point-min))
359 (search-forward "@setfilename")
360 (beginning-of-line)
361 (delete-region (point-min) (point))
362 ;; Remove @bye at end of file, if it is there.
363 (goto-char (point-max))
364 (if (search-backward "@bye" nil t)
365 (delete-region (point) (point-max)))
366 ;; Make sure buffer ends in a newline.
367 (or (= (preceding-char) ?\n)
368 (insert "\n"))
369 ;; Scan the whole buffer, converting to Info format.
370 (texinfo-format-scan)
371 ;; Return data for indices.
372 (goto-char (point-min))
373 (list outfile
374 texinfo-vindex texinfo-findex texinfo-cindex
375 texinfo-pindex texinfo-tindex texinfo-kindex)))
376
377 \f
378 ;;; Perform non-@-command file conversions: quotes and hyphens
379
380 (defun texinfo-format-convert (min max)
381 ;; Convert left and right quotes to typewriter font quotes.
382 (goto-char min)
383 (while (search-forward "``" max t)
384 (replace-match "\""))
385 (goto-char min)
386 (while (search-forward "''" max t)
387 (replace-match "\""))
388 ;; Convert three hyphens in a row to two.
389 (goto-char min)
390 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
391 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
392 2)))))
393
394 \f
395 ;;; Handle paragraph filling
396
397 (defvar texinfo-no-refill-regexp
398 "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|ifhtml\\|tex\\|html\\)"
399 "Regexp specifying environments in which paragraphs are not filled.")
400
401 (defvar texinfo-part-of-para-regexp
402 "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
403 "Regexp specifying @-commands found within paragraphs.")
404
405 (defun texinfo-append-refill ()
406 "Append @refill at end of each paragraph that should be filled.
407 Do not append @refill to paragraphs within @example and similar environments.
408 Do not append @refill to paragraphs containing @w{TEXT} or @*."
409
410 ;; It is necessary to append @refill before other processing because
411 ;; the other processing removes information that tells Texinfo
412 ;; whether the text should or should not be filled.
413
414 (while (< (point) (point-max))
415 (let ((refill-blank-lines "^[ \t\n]*$")
416 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
417 (beginning-of-line)
418 ;; 1. Skip over blank lines;
419 ;; skip over lines beginning with @-commands,
420 ;; but do not skip over lines
421 ;; that are no-refill environments such as @example or
422 ;; that begin with within-paragraph @-commands such as @code.
423 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
424 (not (looking-at
425 (concat
426 "\\("
427 texinfo-no-refill-regexp
428 "\\|"
429 texinfo-part-of-para-regexp
430 "\\)")))
431 (< (point) (point-max)))
432 (forward-line 1))
433 ;; 2. Skip over @example and similar no-refill environments.
434 (if (looking-at texinfo-no-refill-regexp)
435 (let ((environment
436 (buffer-substring (match-beginning 1) (match-end 1))))
437 (progn (re-search-forward (concat "^@end " environment) nil t)
438 (forward-line 1)))
439 ;; 3. Do not refill a paragraph containing @w or @*
440 (if (or
441 (>= (point) (point-max))
442 (re-search-forward
443 "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t))
444 ;; Go to end of paragraph and do nothing.
445 (forward-paragraph)
446 ;; 4. Else go to end of paragraph and insert @refill
447 (forward-paragraph)
448 (forward-line -1)
449 (end-of-line)
450 (delete-region
451 (point)
452 (save-excursion (skip-chars-backward " \t") (point)))
453 ;; `looking-at-backward' not available in v. 18.57
454 ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
455 (if (not (re-search-backward
456 "@refill\\|@bye"
457 (save-excursion (beginning-of-line) (point))
458 t))
459 (insert "@refill"))
460 (forward-line 1))))))
461
462 \f
463 ;;; Handle `@raisesections' and `@lowersections' commands
464
465 ;; These commands change the hierarchical level of chapter structuring
466 ;; commands.
467 ;;
468 ;; @raisesections changes @subsection to @section,
469 ;; @section to @chapter,
470 ;; etc.
471 ;;
472 ;; @lowersections changes @chapter to @section
473 ;; @subsection to @subsubsection,
474 ;; etc.
475 ;;
476 ;; An @raisesections/@lowersections command changes only those
477 ;; structuring commands that follow the @raisesections/@lowersections
478 ;; command.
479 ;;
480 ;; Repeated @raisesections/@lowersections continue to raise or lower
481 ;; the heading level.
482 ;;
483 ;; An @lowersections command cancels an @raisesections command, and
484 ;; vice versa.
485 ;;
486 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
487 ;; trying to do so does not elicit an error---you just get more
488 ;; headings that mean the same thing as you keep raising or lowering
489 ;; (for example, after a single @raisesections, both @chapter and
490 ;; @section produce chapter headings).
491
492 (defun texinfo-raise-lower-sections ()
493 "Raise or lower the hierarchical level of chapters, sections, etc.
494
495 This function acts according to `@raisesections' and `@lowersections'
496 commands in the Texinfo file.
497
498 For example, an `@lowersections' command is useful if you wish to
499 include what is written as an outer or standalone Texinfo file in
500 another Texinfo file as an inner, included file. The `@lowersections'
501 command changes chapters to sections, sections to subsections and so
502 on.
503
504 @raisesections changes @subsection to @section,
505 @section to @chapter,
506 @heading to @chapheading,
507 etc.
508
509 @lowersections changes @chapter to @section,
510 @subsection to @subsubsection,
511 @heading to @subheading,
512 etc.
513
514 An `@raisesections' or `@lowersections' command changes only those
515 structuring commands that follow the `@raisesections' or
516 `@lowersections' command.
517
518 An `@lowersections' command cancels an `@raisesections' command, and
519 vice versa.
520
521 Repeated use of the commands continue to raise or lower the hierarchical
522 level a step at a time.
523
524 An attempt to raise above `chapters' reproduces chapter commands; an
525 attempt to lower below subsubsections reproduces subsubsection
526 commands."
527
528 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
529 ;; it is a regexp matching chapter, section, other headings
530 ;; (but not the top node).
531
532 (let (type (level 0))
533 (while
534 (re-search-forward
535 (concat
536 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
537 texinfo-section-types-regexp
538 "\\)\\)")
539 nil t)
540 (beginning-of-line)
541 (save-excursion (setq type (read (current-buffer))))
542 (cond
543
544 ;; 1. Increment level
545 ((eq type '@raisesections)
546 (setq level (1+ level))
547 (delete-region
548 (point) (save-excursion (forward-line 1) (point))))
549
550 ;; 2. Decrement level
551 ((eq type '@lowersections)
552 (setq level (1- level))
553 (delete-region
554 (point) (save-excursion (forward-line 1) (point))))
555
556 ;; Now handle structuring commands
557 ((cond
558
559 ;; 3. Raise level when positive
560 ((> level 0)
561 (let ((count level)
562 (new-level type))
563 (while (> count 0)
564 (setq new-level
565 (cdr (assq new-level texinfo-raisesections-alist)))
566 (setq count (1- count)))
567 (kill-word 1)
568 (insert (symbol-name new-level))))
569
570 ;; 4. Do nothing except move point when level is zero
571 ((= level 0) (forward-line 1))
572
573 ;; 5. Lower level when positive
574 ((< level 0)
575 (let ((count level)
576 (new-level type))
577 (while (< count 0)
578 (setq new-level
579 (cdr (assq new-level texinfo-lowersections-alist)))
580 (setq count (1+ count)))
581 (kill-word 1)
582 (insert (symbol-name new-level))))))))))
583
584 (defvar texinfo-raisesections-alist
585 '((@chapter . @chapter) ; Cannot go higher
586 (@unnumbered . @unnumbered)
587
588 (@majorheading . @majorheading)
589 (@chapheading . @chapheading)
590 (@appendix . @appendix)
591
592 (@section . @chapter)
593 (@unnumberedsec . @unnumbered)
594 (@heading . @chapheading)
595 (@appendixsec . @appendix)
596
597 (@subsection . @section)
598 (@unnumberedsubsec . @unnumberedsec)
599 (@subheading . @heading)
600 (@appendixsubsec . @appendixsec)
601
602 (@subsubsection . @subsection)
603 (@unnumberedsubsubsec . @unnumberedsubsec)
604 (@subsubheading . @subheading)
605 (@appendixsubsubsec . @appendixsubsec))
606 "*An alist of next higher levels for chapters, sections. etc.
607 For example, section to chapter, subsection to section.
608 Used by `texinfo-raise-lower-sections'.
609 The keys specify types of section; the values correspond to the next
610 higher types.")
611
612 (defvar texinfo-lowersections-alist
613 '((@chapter . @section)
614 (@unnumbered . @unnumberedsec)
615 (@majorheading . @heading)
616 (@chapheading . @heading)
617 (@appendix . @appendixsec)
618
619 (@section . @subsection)
620 (@unnumberedsec . @unnumberedsubsec)
621 (@heading . @subheading)
622 (@appendixsec . @appendixsubsec)
623
624 (@subsection . @subsubsection)
625 (@unnumberedsubsec . @unnumberedsubsubsec)
626 (@subheading . @subsubheading)
627 (@appendixsubsec . @appendixsubsubsec)
628
629 (@subsubsection . @subsubsection) ; Cannot go lower.
630 (@unnumberedsubsubsec . @unnumberedsubsubsec)
631 (@subsubheading . @subsubheading)
632 (@appendixsubsubsec . @appendixsubsubsec))
633 "*An alist of next lower levels for chapters, sections. etc.
634 For example, chapter to section, section to subsection.
635 Used by `texinfo-raise-lower-sections'.
636 The keys specify types of section; the values correspond to the next
637 lower types.")
638
639 \f
640 ;;; Perform those texinfo-to-info conversions that apply to the whole input
641 ;;; uniformly.
642
643 (defun texinfo-format-scan ()
644 (texinfo-format-convert (point-min) (point-max))
645 ;; Scan for @-commands.
646 (goto-char (point-min))
647 (while (search-forward "@" nil t)
648 (if (looking-at "[@{}^'` *\"?!]")
649 ;; Handle a few special @-followed-by-one-char commands.
650 (if (= (following-char) ?*)
651 (progn
652 ;; remove command
653 (delete-region (1- (point)) (1+ (point)))
654 ;; insert return if not at end of line;
655 ;; else line is already broken.
656 (if (not (= (following-char) ?\n))
657 (insert ?\n)))
658 ;; The other characters are simply quoted. Delete the @.
659 (delete-char -1)
660 (forward-char 1))
661 ;; @ is followed by a command-word; find the end of the word.
662 (setq texinfo-command-start (1- (point)))
663 (if (= (char-syntax (following-char)) ?w)
664 (forward-word 1)
665 (forward-char 1))
666 (setq texinfo-command-end (point))
667 ;; Handle let aliasing
668 (setq texinfo-command-name
669 (let (trial
670 (cmdname
671 (buffer-substring
672 (1+ texinfo-command-start) texinfo-command-end)))
673 (while (setq trial (assoc cmdname texinfo-alias-list))
674 (setq cmdname (cdr trial)))
675 (intern cmdname)))
676 ;; Call the handler for this command.
677 (let ((enclosure-type
678 (assoc
679 (symbol-name texinfo-command-name)
680 texinfo-enclosure-list)))
681 (if enclosure-type
682 (progn
683 (insert
684 (car (car (cdr enclosure-type)))
685 (texinfo-parse-arg-discard)
686 (car (cdr (car (cdr enclosure-type)))))
687 (goto-char texinfo-command-start))
688 (let ((cmd (get texinfo-command-name 'texinfo-format)))
689 (if cmd (funcall cmd) (texinfo-unsupported)))))))
690
691 (cond (texinfo-stack
692 (goto-char (nth 2 (car texinfo-stack)))
693 (error "Unterminated @%s" (car (car texinfo-stack))))))
694
695 (put 'begin 'texinfo-format 'texinfo-format-begin)
696 (defun texinfo-format-begin ()
697 (texinfo-format-begin-end 'texinfo-format))
698
699 (put 'end 'texinfo-format 'texinfo-format-end)
700 (defun texinfo-format-end ()
701 (texinfo-format-begin-end 'texinfo-end))
702
703 (defun texinfo-format-begin-end (prop)
704 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
705 (let ((cmd (get texinfo-command-name prop)))
706 (if cmd (funcall cmd)
707 (texinfo-unsupported))))
708 \f
709 ;;; Parsing functions
710
711 (defun texinfo-parse-line-arg ()
712 (goto-char texinfo-command-end)
713 (let ((start (point)))
714 (cond ((looking-at " ")
715 (skip-chars-forward " ")
716 (setq start (point))
717 (end-of-line)
718 (skip-chars-backward " ")
719 (delete-region (point) (progn (end-of-line) (point)))
720 (setq texinfo-command-end (1+ (point))))
721 ((looking-at "{")
722 (setq start (1+ (point)))
723 (forward-list 1)
724 (setq texinfo-command-end (point))
725 (forward-char -1))
726 (t
727 (error "Invalid texinfo command arg format")))
728 (prog1 (buffer-substring start (point))
729 (if (eolp) (forward-char 1)))))
730
731 (defun texinfo-parse-expanded-arg ()
732 (goto-char texinfo-command-end)
733 (let ((start (point))
734 marker)
735 (cond ((looking-at " ")
736 (skip-chars-forward " ")
737 (setq start (point))
738 (end-of-line)
739 (setq texinfo-command-end (1+ (point))))
740 ((looking-at "{")
741 (setq start (1+ (point)))
742 (forward-list 1)
743 (setq texinfo-command-end (point))
744 (forward-char -1))
745 (t
746 (error "Invalid texinfo command arg format")))
747 (setq marker (move-marker (make-marker) texinfo-command-end))
748 (texinfo-format-expand-region start (point))
749 (setq texinfo-command-end (marker-position marker))
750 (move-marker marker nil)
751 (prog1 (buffer-substring start (point))
752 (if (eolp) (forward-char 1)))))
753
754 (defun texinfo-format-expand-region (start end)
755 (save-restriction
756 (narrow-to-region start end)
757 (let (texinfo-command-start
758 texinfo-command-end
759 texinfo-command-name
760 texinfo-stack)
761 (texinfo-format-scan))
762 (goto-char (point-max))))
763
764 (defun texinfo-parse-arg-discard ()
765 (prog1 (texinfo-parse-line-arg)
766 (texinfo-discard-command)))
767
768 (defun texinfo-discard-command ()
769 (delete-region texinfo-command-start texinfo-command-end))
770
771 (defun texinfo-optional-braces-discard ()
772 "Discard braces following command, if any."
773 (goto-char texinfo-command-end)
774 (let ((start (point)))
775 (cond ((looking-at "[ \t]*\n")) ; do nothing
776 ((looking-at "{") ; remove braces, if any
777 (forward-list 1)
778 (setq texinfo-command-end (point)))
779 (t
780 (error
781 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
782 (delete-region texinfo-command-start texinfo-command-end)))
783
784 (defun texinfo-format-parse-line-args ()
785 (let ((start (1- (point)))
786 next beg end
787 args)
788 (skip-chars-forward " ")
789 (while (not (eolp))
790 (setq beg (point))
791 (re-search-forward "[\n,]")
792 (setq next (point))
793 (if (bolp) (setq next (1- next)))
794 (forward-char -1)
795 (skip-chars-backward " ")
796 (setq end (point))
797 (setq args (cons (if (> end beg) (buffer-substring beg end))
798 args))
799 (goto-char next)
800 (skip-chars-forward " "))
801 (if (eolp) (forward-char 1))
802 (setq texinfo-command-end (point))
803 (nreverse args)))
804
805 (defun texinfo-format-parse-args ()
806 (let ((start (1- (point)))
807 next beg end
808 args)
809 (search-forward "{")
810 (save-excursion
811 (texinfo-format-expand-region
812 (point)
813 (save-excursion (up-list 1) (1- (point)))))
814 ;; The following does not handle cross references of the form:
815 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
816 ;; re-search-forward finds the first right brace after the second
817 ;; comma.
818 (while (/= (preceding-char) ?\})
819 (skip-chars-forward " \t\n")
820 (setq beg (point))
821 (re-search-forward "[},]")
822 (setq next (point))
823 (forward-char -1)
824 (skip-chars-backward " \t\n")
825 (setq end (point))
826 (cond ((< beg end)
827 (goto-char beg)
828 (while (search-forward "\n" end t)
829 (replace-match " "))))
830 (setq args (cons (if (> end beg) (buffer-substring beg end))
831 args))
832 (goto-char next))
833 (if (eolp) (forward-char 1))
834 (setq texinfo-command-end (point))
835 (nreverse args)))
836
837 (defun texinfo-format-parse-defun-args ()
838 (goto-char texinfo-command-end)
839 (let ((start (point)))
840 (end-of-line)
841 (setq texinfo-command-end (1+ (point)))
842 (let ((marker (move-marker (make-marker) texinfo-command-end)))
843 (texinfo-format-expand-region start (point))
844 (setq texinfo-command-end (marker-position marker))
845 (move-marker marker nil))
846 (goto-char start)
847 (let ((args '())
848 beg end)
849 (skip-chars-forward " ")
850 (while (not (eolp))
851 (cond ((looking-at "{")
852 (setq beg (1+ (point)))
853 (forward-list 1)
854 (setq end (1- (point))))
855 (t
856 (setq beg (point))
857 (re-search-forward "[\n ]")
858 (forward-char -1)
859 (setq end (point))))
860 (setq args (cons (buffer-substring beg end) args))
861 (skip-chars-forward " "))
862 (forward-char 1)
863 (nreverse args))))
864
865 (defun texinfo-discard-line ()
866 (goto-char texinfo-command-end)
867 (skip-chars-forward " \t")
868 (or (eolp)
869 (error "Extraneous text at end of command line."))
870 (goto-char texinfo-command-start)
871 (or (bolp)
872 (error "Extraneous text at beginning of command line."))
873 (delete-region (point) (progn (forward-line 1) (point))))
874
875 (defun texinfo-discard-line-with-args ()
876 (goto-char texinfo-command-start)
877 (delete-region (point) (progn (forward-line 1) (point))))
878
879 \f
880 ;;; @setfilename
881
882 ;; Only `texinfo-format-buffer' handles @setfilename with this
883 ;; definition; `texinfo-format-region' handles @setfilename, if any,
884 ;; specially.
885 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
886 (defun texinfo-format-setfilename ()
887 (let ((arg (texinfo-parse-arg-discard)))
888 (message "Formatting Info file: %s" arg)
889 (setq texinfo-format-filename
890 (file-name-nondirectory (expand-file-name arg)))
891 (insert "Info file: "
892 texinfo-format-filename ", -*-Text-*-\n"
893 ;; Date string removed so that regression testing is easier.
894 ;; "produced on "
895 ;; (substring (current-time-string) 8 10) " "
896 ;; (substring (current-time-string) 4 7) " "
897 ;; (substring (current-time-string) -4) " "
898 "produced by `texinfo-format-buffer'\n"
899 "from file"
900 (if (buffer-file-name input-buffer)
901 (concat " `"
902 (file-name-sans-versions
903 (file-name-nondirectory
904 (buffer-file-name input-buffer)))
905 "'")
906 (concat "buffer `" (buffer-name input-buffer) "'"))
907 "\nusing `texinfmt.el' version "
908 texinfmt-version
909 ".\n\n")))
910 \f
911 ;;; @node, @menu
912
913 (put 'node 'texinfo-format 'texinfo-format-node)
914 (put 'nwnode 'texinfo-format 'texinfo-format-node)
915 (defun texinfo-format-node ()
916 (let* ((args (texinfo-format-parse-line-args))
917 (name (nth 0 args))
918 (next (nth 1 args))
919 (prev (nth 2 args))
920 (up (nth 3 args)))
921 (texinfo-discard-command)
922 (setq texinfo-last-node name)
923 (let ((tem (downcase name)))
924 (if (assoc tem texinfo-node-names)
925 (error "Duplicate node name: %s" name)
926 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
927 (setq texinfo-footnote-number 0)
928 ;; insert "\n\^_" unconditionally since this is what info is looking for
929 (insert "\n\^_\nFile: " texinfo-format-filename
930 ", Node: " name)
931 (if next
932 (insert ", Next: " next))
933 (if prev
934 (insert ", Prev: " prev))
935 (if up
936 (insert ", Up: " up))
937 (insert ?\n)
938 (setq texinfo-last-node-pos (point))))
939
940 (put 'menu 'texinfo-format 'texinfo-format-menu)
941 (defun texinfo-format-menu ()
942 (texinfo-discard-line)
943 (insert "* Menu:\n\n"))
944
945 (put 'menu 'texinfo-end 'texinfo-discard-command)
946
947 \f
948 ;;; Cross references
949
950 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
951 ; -> *Note FNAME: (FILE)NODE
952 ; If FILE is missing,
953 ; *Note FNAME: NODE
954 ; If FNAME is empty and NAME is present
955 ; *Note NAME: Node
956 ; If both NAME and FNAME are missing
957 ; *Note NODE::
958 ; texinfo ignores the DOCUMENT argument.
959 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
960 ; If FILE is specified, (FILE)NODE is used for xrefs.
961 ; If fifth argument DOCUMENT is specified, produces
962 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
963 ; of DOCUMENT
964
965 ; @ref a reference that does not put `See' or `see' in
966 ; the hardcopy and is the same as @xref in Info
967 (put 'ref 'texinfo-format 'texinfo-format-xref)
968
969 (put 'xref 'texinfo-format 'texinfo-format-xref)
970 (defun texinfo-format-xref ()
971 (let ((args (texinfo-format-parse-args)))
972 (texinfo-discard-command)
973 (insert "*Note ")
974 (let ((fname (or (nth 1 args) (nth 2 args))))
975 (if (null (or fname (nth 3 args)))
976 (insert (car args) "::")
977 (insert (or fname (car args)) ": ")
978 (if (nth 3 args)
979 (insert "(" (nth 3 args) ")"))
980 (insert (car args))))))
981
982 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
983 (defun texinfo-format-pxref ()
984 (texinfo-format-xref)
985 (or (save-excursion
986 (forward-char -2)
987 (looking-at "::"))
988 (insert ".")))
989
990 ;@inforef{NODE, FNAME, FILE}
991 ;Like @xref{NODE, FNAME,,FILE} in texinfo.
992 ;In Tex, generates "See Info file FILE, node NODE"
993 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
994 (defun texinfo-format-inforef ()
995 (let ((args (texinfo-format-parse-args)))
996 (texinfo-discard-command)
997 (if (nth 1 args)
998 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
999 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
1000
1001 \f
1002 ;;; Section headings
1003
1004 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
1005 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
1006 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
1007 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
1008 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1009 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1010 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1011 (put 'top 'texinfo-format 'texinfo-format-chapter)
1012 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1013 (defun texinfo-format-chapter ()
1014 (texinfo-format-chapter-1 ?*))
1015
1016 (put 'heading 'texinfo-format 'texinfo-format-section)
1017 (put 'isection 'texinfo-format 'texinfo-format-section)
1018 (put 'section 'texinfo-format 'texinfo-format-section)
1019 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1020 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1021 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1022 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1023 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1024 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1025 (defun texinfo-format-section ()
1026 (texinfo-format-chapter-1 ?=))
1027
1028 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1029 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1030 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1031 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1032 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1033 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1034 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1035 (defun texinfo-format-subsection ()
1036 (texinfo-format-chapter-1 ?-))
1037
1038 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1039 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1040 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1041 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1042 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1043 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1044 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1045 (defun texinfo-format-subsubsection ()
1046 (texinfo-format-chapter-1 ?.))
1047
1048 (defun texinfo-format-chapter-1 (belowchar)
1049 (let ((arg (texinfo-parse-arg-discard)))
1050 (message "Formatting: %s ... " arg) ; So we can see where we are.
1051 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1052 (forward-line -2)))
1053
1054 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1055 (defun texinfo-format-sectionpad ()
1056 (let ((str (texinfo-parse-arg-discard)))
1057 (forward-char -1)
1058 (let ((column (current-column)))
1059 (forward-char 1)
1060 (while (> column 0)
1061 (insert str)
1062 (setq column (1- column))))
1063 (insert ?\n)))
1064
1065 \f
1066 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1067
1068 (put '\. 'texinfo-format 'texinfo-format-\.)
1069 (defun texinfo-format-\. ()
1070 (texinfo-discard-command)
1071 (insert "."))
1072
1073 (put '\: 'texinfo-format 'texinfo-format-\:)
1074 (defun texinfo-format-\: ()
1075 (texinfo-discard-command))
1076
1077 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
1078 (defun texinfo-format-soft-hyphen ()
1079 (texinfo-discard-command))
1080
1081 \f
1082 ;;; @center, @sp, and @br
1083
1084 (put 'center 'texinfo-format 'texinfo-format-center)
1085 (defun texinfo-format-center ()
1086 (let ((arg (texinfo-parse-expanded-arg)))
1087 (texinfo-discard-command)
1088 (insert arg)
1089 (insert ?\n)
1090 (save-restriction
1091 (goto-char (1- (point)))
1092 (let ((indent-tabs-mode nil))
1093 (center-line)))))
1094
1095 (put 'sp 'texinfo-format 'texinfo-format-sp)
1096 (defun texinfo-format-sp ()
1097 (let* ((arg (texinfo-parse-arg-discard))
1098 (num (read arg)))
1099 (insert-char ?\n num)))
1100
1101 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1102 (defun texinfo-format-paragraph-break ()
1103 "Force a paragraph break.
1104 If used within a line, follow `@br' with braces."
1105 (texinfo-optional-braces-discard)
1106 ;; insert one return if at end of line;
1107 ;; else insert two returns, to generate a blank line.
1108 (if (= (following-char) ?\n)
1109 (insert ?\n)
1110 (insert-char ?\n 2)))
1111
1112 \f
1113 ;;; @footnote and @footnotestyle
1114
1115 ; In Texinfo, footnotes are created with the `@footnote' command.
1116 ; This command is followed immediately by a left brace, then by the text of
1117 ; the footnote, and then by a terminating right brace. The
1118 ; template for a footnote is:
1119 ;
1120 ; @footnote{TEXT}
1121 ;
1122 ; Info has two footnote styles:
1123 ;
1124 ; * In the End of node style, all the footnotes for a single node
1125 ; are placed at the end of that node. The footnotes are
1126 ; separated from the rest of the node by a line of dashes with
1127 ; the word `Footnotes' within it.
1128 ;
1129 ; * In the Separate node style, all the footnotes for a single node
1130 ; are placed in an automatically constructed node of their own.
1131
1132 ; Footnote style is specified by the @footnotestyle command, either
1133 ; @footnotestyle separate
1134 ; or
1135 ; @footnotestyle end
1136 ;
1137 ; The default is separate
1138
1139 (defvar texinfo-footnote-style "separate"
1140 "Footnote style, either separate or end.")
1141
1142 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1143 (defun texinfo-footnotestyle ()
1144 "Specify whether footnotes are at end of node or in separate nodes.
1145 Argument is either end or separate."
1146 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1147
1148 (defvar texinfo-footnote-number)
1149
1150 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1151 (defun texinfo-format-footnote ()
1152 "Format a footnote in either end of node or separate node style.
1153 The texinfo-footnote-style variable controls which style is used."
1154 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1155 (cond ((string= texinfo-footnote-style "end")
1156 (texinfo-format-end-node))
1157 ((string= texinfo-footnote-style "separate")
1158 (texinfo-format-separate-node))))
1159
1160 (defun texinfo-format-separate-node ()
1161 "Format footnote in Separate node style, with notes in own node.
1162 The node is constructed automatically."
1163 (let* (start
1164 (arg (texinfo-parse-line-arg))
1165 (node-name-beginning
1166 (save-excursion
1167 (re-search-backward
1168 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1169 (match-end 0)))
1170 (node-name
1171 (save-excursion
1172 (buffer-substring
1173 (progn (goto-char node-name-beginning) ; skip over node command
1174 (skip-chars-forward " \t") ; and over spaces
1175 (point))
1176 (if (search-forward
1177 ","
1178 (save-excursion (end-of-line) (point)) t) ; bound search
1179 (1- (point))
1180 (end-of-line) (point))))))
1181 (texinfo-discard-command) ; remove or insert whitespace, as needed
1182 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1183 (point))
1184 (insert (format " (%d) (*Note %s-Footnotes::)"
1185 texinfo-footnote-number node-name))
1186 (fill-paragraph nil)
1187 (save-excursion
1188 (if (re-search-forward "^@node" nil 'move)
1189 (forward-line -1))
1190
1191 ;; two cases: for the first footnote, we must insert a node header;
1192 ;; for the second and subsequent footnotes, we need only insert
1193 ;; the text of the footnote.
1194
1195 (if (save-excursion
1196 (re-search-backward
1197 (concat node-name "-Footnotes, Up: ")
1198 node-name-beginning
1199 t))
1200 (progn ; already at least one footnote
1201 (setq start (point))
1202 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1203 (fill-region start (point)))
1204 ;; else not yet a footnote
1205 (insert "\n\^_\nFile: " texinfo-format-filename
1206 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1207 (setq start (point))
1208 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1209 (fill-region start (point))))))
1210
1211 (defun texinfo-format-end-node ()
1212 "Format footnote in the End of node style, with notes at end of node."
1213 (let (start
1214 (arg (texinfo-parse-line-arg)))
1215 (texinfo-discard-command) ; remove or insert whitespace, as needed
1216 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1217 (point))
1218 (insert (format " (%d) " texinfo-footnote-number))
1219 (fill-paragraph nil)
1220 (save-excursion
1221 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1222 (progn ; already have footnote, put new one before end of node
1223 (if (re-search-forward "^@node" nil 'move)
1224 (forward-line -1))
1225 (setq start (point))
1226 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1227 (fill-region start (point)))
1228 ;; else no prior footnote
1229 (if (re-search-forward "^@node" nil 'move)
1230 (forward-line -1))
1231 (insert "\n--------- Footnotes ---------\n")
1232 (setq start (point))
1233 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1234
1235 \f
1236 ;;; @itemize, @enumerate, and similar commands
1237
1238 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1239 ;; @enumerate pushes (enumerate 0 STARTPOS).
1240 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1241 ;; For itemize, this puts in and rescans the COMMANDS.
1242 ;; For enumerate, this increments the number and puts it in.
1243 ;; In either case, it puts a Backspace at the front of the line
1244 ;; which marks it not to be indented later.
1245 ;; All other lines get indented by 5 when the @end is reached.
1246
1247 (defvar texinfo-stack-depth 0
1248 "Count of number of unpopped texinfo-push-stack calls.
1249 Used by @refill indenting command to avoid indenting within lists, etc.")
1250
1251 (defun texinfo-push-stack (check arg)
1252 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1253 (setq texinfo-stack
1254 (cons (list check arg texinfo-command-start)
1255 texinfo-stack)))
1256
1257 (defun texinfo-pop-stack (check)
1258 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1259 (if (null texinfo-stack)
1260 (error "Unmatched @end %s" check))
1261 (if (not (eq (car (car texinfo-stack)) check))
1262 (error "@end %s matches @%s"
1263 check (car (car texinfo-stack))))
1264 (prog1 (cdr (car texinfo-stack))
1265 (setq texinfo-stack (cdr texinfo-stack))))
1266
1267 (put 'itemize 'texinfo-format 'texinfo-itemize)
1268 (defun texinfo-itemize ()
1269 (texinfo-push-stack
1270 'itemize
1271 (progn (skip-chars-forward " \t")
1272 (if (eolp)
1273 "@bullet"
1274 (texinfo-parse-line-arg))))
1275 (texinfo-discard-line-with-args)
1276 (setq fill-column (- fill-column 5)))
1277
1278 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1279 (defun texinfo-end-itemize ()
1280 (setq fill-column (+ fill-column 5))
1281 (texinfo-discard-command)
1282 (let ((stacktop
1283 (texinfo-pop-stack 'itemize)))
1284 (texinfo-do-itemize (nth 1 stacktop))))
1285
1286 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1287 (defun texinfo-enumerate ()
1288 (texinfo-push-stack
1289 'enumerate
1290 (progn (skip-chars-forward " \t")
1291 (if (eolp)
1292 1
1293 (read (current-buffer)))))
1294 (if (and (symbolp (car (cdr (car texinfo-stack))))
1295 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1296 (error
1297 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1298 (texinfo-discard-line-with-args)
1299 (setq fill-column (- fill-column 5)))
1300
1301 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1302 (defun texinfo-end-enumerate ()
1303 (setq fill-column (+ fill-column 5))
1304 (texinfo-discard-command)
1305 (let ((stacktop
1306 (texinfo-pop-stack 'enumerate)))
1307 (texinfo-do-itemize (nth 1 stacktop))))
1308
1309 ;; @alphaenumerate never became a standard part of Texinfo
1310 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1311 (defun texinfo-alphaenumerate ()
1312 (texinfo-push-stack 'alphaenumerate (1- ?a))
1313 (setq fill-column (- fill-column 5))
1314 (texinfo-discard-line))
1315
1316 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1317 (defun texinfo-end-alphaenumerate ()
1318 (setq fill-column (+ fill-column 5))
1319 (texinfo-discard-command)
1320 (let ((stacktop
1321 (texinfo-pop-stack 'alphaenumerate)))
1322 (texinfo-do-itemize (nth 1 stacktop))))
1323
1324 ;; @capsenumerate never became a standard part of Texinfo
1325 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1326 (defun texinfo-capsenumerate ()
1327 (texinfo-push-stack 'capsenumerate (1- ?A))
1328 (setq fill-column (- fill-column 5))
1329 (texinfo-discard-line))
1330
1331 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1332 (defun texinfo-end-capsenumerate ()
1333 (setq fill-column (+ fill-column 5))
1334 (texinfo-discard-command)
1335 (let ((stacktop
1336 (texinfo-pop-stack 'capsenumerate)))
1337 (texinfo-do-itemize (nth 1 stacktop))))
1338
1339 ;; At the @end, indent all the lines within the construct
1340 ;; except those marked with backspace. FROM says where
1341 ;; construct started.
1342 (defun texinfo-do-itemize (from)
1343 (save-excursion
1344 (while (progn (forward-line -1)
1345 (>= (point) from))
1346 (if (= (following-char) ?\b)
1347 (save-excursion
1348 (delete-char 1)
1349 (end-of-line)
1350 (delete-char 6))
1351 (if (not (looking-at "[ \t]*$"))
1352 (save-excursion (insert " ")))))))
1353
1354 (put 'item 'texinfo-format 'texinfo-item)
1355 (put 'itemx 'texinfo-format 'texinfo-item)
1356 (defun texinfo-item ()
1357 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1358
1359 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1360 (defun texinfo-itemize-item ()
1361 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1362 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1363 (if (looking-at "[ \t]*[^ \t\n]+")
1364 ;; Text on same line as @item command.
1365 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1366 ;; Else text on next line.
1367 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1368 (forward-line -1))
1369
1370 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1371 (defun texinfo-enumerate-item ()
1372 (texinfo-discard-line)
1373 (let (enumerating-symbol)
1374 (cond ((integerp (car (cdr (car texinfo-stack))))
1375 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1376 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1377 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1378 ((symbolp (car (cdr (car texinfo-stack))))
1379 (setq enumerating-symbol
1380 (symbol-name (car (cdr (car texinfo-stack)))))
1381 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1382 (equal ?\{ (string-to-char enumerating-symbol)))
1383 (error
1384 "Too many items in enumerated list; alphabet ends at Z."))
1385 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1386 (setcar (cdr (car texinfo-stack))
1387 (make-symbol
1388 (char-to-string
1389 (1+
1390 (string-to-char enumerating-symbol))))))
1391 (t
1392 (error
1393 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1394 (forward-line -1)))
1395
1396 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1397 (defun texinfo-alphaenumerate-item ()
1398 (texinfo-discard-line)
1399 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1400 (if (> next ?z)
1401 (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
1402 (setcar (cdr (car texinfo-stack)) next)
1403 (insert "\b " next ". \n"))
1404 (forward-line -1))
1405
1406 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1407 (defun texinfo-capsenumerate-item ()
1408 (texinfo-discard-line)
1409 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1410 (if (> next ?Z)
1411 (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
1412 (setcar (cdr (car texinfo-stack)) next)
1413 (insert "\b " next ". \n"))
1414 (forward-line -1))
1415
1416 \f
1417 ;;; @table
1418
1419 ; The `@table' command produces two-column tables.
1420
1421 (put 'table 'texinfo-format 'texinfo-table)
1422 (defun texinfo-table ()
1423 (texinfo-push-stack
1424 'table
1425 (progn (skip-chars-forward " \t")
1426 (if (eolp)
1427 "@asis"
1428 (texinfo-parse-line-arg))))
1429 (texinfo-discard-line-with-args)
1430 (setq fill-column (- fill-column 5)))
1431
1432 (put 'table 'texinfo-item 'texinfo-table-item)
1433 (defun texinfo-table-item ()
1434 (let ((arg (texinfo-parse-arg-discard))
1435 (itemfont (car (cdr (car texinfo-stack)))))
1436 (insert ?\b itemfont ?\{ arg "}\n \n"))
1437 (forward-line -2))
1438
1439 (put 'table 'texinfo-end 'texinfo-end-table)
1440 (defun texinfo-end-table ()
1441 (setq fill-column (+ fill-column 5))
1442 (texinfo-discard-command)
1443 (let ((stacktop
1444 (texinfo-pop-stack 'table)))
1445 (texinfo-do-itemize (nth 1 stacktop))))
1446
1447 ;; @description appears to be an undocumented variant on @table that
1448 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1449 ;; part of makeinfo.c The command appears to be a relic of the past.
1450 (put 'description 'texinfo-end 'texinfo-end-table)
1451 (put 'description 'texinfo-format 'texinfo-description)
1452 (defun texinfo-description ()
1453 (texinfo-push-stack 'table "@asis")
1454 (setq fill-column (- fill-column 5))
1455 (texinfo-discard-line))
1456
1457 \f
1458 ;;; @ftable, @vtable
1459
1460 ; The `@ftable' and `@vtable' commands are like the `@table' command
1461 ; but they also insert each entry in the first column of the table
1462 ; into the function or variable index.
1463
1464 ;; Handle the @ftable and @vtable commands:
1465
1466 (put 'ftable 'texinfo-format 'texinfo-ftable)
1467 (put 'vtable 'texinfo-format 'texinfo-vtable)
1468
1469 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1470 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1471
1472 (defun texinfo-indextable (table-type)
1473 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1474 (setq fill-column (- fill-column 5)))
1475
1476 ;; Handle the @item commands within ftable and vtable:
1477
1478 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1479 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1480
1481 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1482 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1483
1484 (defun texinfo-indextable-item (index-type)
1485 (let ((item (texinfo-parse-arg-discard))
1486 (itemfont (car (cdr (car texinfo-stack))))
1487 (indexvar index-type))
1488 (insert ?\b itemfont ?\{ item "}\n \n")
1489 (set indexvar
1490 (cons
1491 (list item texinfo-last-node)
1492 (symbol-value indexvar)))
1493 (forward-line -2)))
1494
1495 ;; Handle @end ftable, @end vtable
1496
1497 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1498 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1499
1500 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1501 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1502
1503 (defun texinfo-end-indextable (table-type)
1504 (setq fill-column (+ fill-column 5))
1505 (texinfo-discard-command)
1506 (let ((stacktop
1507 (texinfo-pop-stack table-type)))
1508 (texinfo-do-itemize (nth 1 stacktop))))
1509
1510 \f
1511 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html
1512
1513 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
1514 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
1515
1516 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
1517 (defun texinfo-format-iftex ()
1518 (delete-region texinfo-command-start
1519 (progn (re-search-forward "@end iftex[ \t]*\n")
1520 (point))))
1521
1522 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
1523 (defun texinfo-format-ifhtml ()
1524 (delete-region texinfo-command-start
1525 (progn (re-search-forward "@end ifhtml[ \t]*\n")
1526 (point))))
1527
1528 (put 'tex 'texinfo-format 'texinfo-format-tex)
1529 (defun texinfo-format-tex ()
1530 (delete-region texinfo-command-start
1531 (progn (re-search-forward "@end tex[ \t]*\n")
1532 (point))))
1533
1534 (put 'html 'texinfo-format 'texinfo-format-html)
1535 (defun texinfo-format-html ()
1536 (delete-region texinfo-command-start
1537 (progn (re-search-forward "@end html[ \t]*\n")
1538 (point))))
1539
1540 \f
1541 ;;; @titlepage
1542
1543 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
1544 (defun texinfo-format-titlepage ()
1545 (delete-region texinfo-command-start
1546 (progn (re-search-forward "@end titlepage[ \t]*\n")
1547 (point))))
1548
1549 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
1550
1551 ; @titlespec an alternative titling command; ignored by Info
1552
1553 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
1554 (defun texinfo-format-titlespec ()
1555 (delete-region texinfo-command-start
1556 (progn (re-search-forward "@end titlespec[ \t]*\n")
1557 (point))))
1558
1559 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
1560
1561 \f
1562 ;;; @today
1563
1564 (put 'today 'texinfo-format 'texinfo-format-today)
1565
1566 ; Produces Day Month Year style of output. eg `1 Jan 1900'
1567 ; The `@today{}' command requires a pair of braces, like `@dots{}'.
1568 (defun texinfo-format-today ()
1569 (texinfo-parse-arg-discard)
1570 (insert (format "%s %s %s"
1571 (substring (current-time-string) 8 10)
1572 (substring (current-time-string) 4 7)
1573 (substring (current-time-string) -4))))
1574
1575 \f
1576 ;;; @ignore
1577
1578 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
1579 (defun texinfo-format-ignore ()
1580 (delete-region texinfo-command-start
1581 (progn (re-search-forward "@end ignore[ \t]*\n")
1582 (point))))
1583
1584 (put 'endignore 'texinfo-format 'texinfo-discard-line)
1585
1586 \f
1587 ;;; Define the Info enclosure command: @definfoenclose
1588
1589 ; A `@definfoenclose' command may be used to define a highlighting
1590 ; command for Info, but not for TeX. A command defined using
1591 ; `@definfoenclose' marks text by enclosing it in strings that precede
1592 ; and follow the text.
1593 ;
1594 ; Presumably, if you define a command with `@definfoenclose` for Info,
1595 ; you will also define the same command in the TeX definitions file,
1596 ; `texinfo.tex' in a manner appropriate for typesetting.
1597 ;
1598 ; Write a `@definfoenclose' command on a line and follow it with three
1599 ; arguments separated by commas (commas are used as separators in an
1600 ; `@node' line in the same way). The first argument to
1601 ; `@definfoenclose' is the @-command name \(without the `@'\); the
1602 ; second argument is the Info start delimiter string; and the third
1603 ; argument is the Info end delimiter string. The latter two arguments
1604 ; enclose the highlighted text in the Info file. A delimiter string
1605 ; may contain spaces. Neither the start nor end delimiter is
1606 ; required. However, if you do not provide a start delimiter, you
1607 ; must follow the command name with two commas in a row; otherwise,
1608 ; the Info formatting commands will misinterpret the end delimiter
1609 ; string as a start delimiter string.
1610 ;
1611 ; If you do a @definfoenclose{} on the name of a pre-defined macro (such
1612 ; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
1613 ; override the built-in definition.
1614 ;
1615 ; An enclosure command defined this way takes one argument in braces.
1616 ;
1617 ; For example, you can write:
1618 ;
1619 ; @ifinfo
1620 ; @definfoenclose phoo, //, \\
1621 ; @end ifinfo
1622 ;
1623 ; near the beginning of a Texinfo file at the beginning of the lines
1624 ; to define `@phoo' as an Info formatting command that inserts `//'
1625 ; before and `\\' after the argument to `@phoo'. You can then write
1626 ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
1627 ;
1628 ; Also, for TeX formatting, you could write
1629 ;
1630 ; @iftex
1631 ; @global@let@phoo=@i
1632 ; @end iftex
1633 ;
1634 ; to define `@phoo' as a command that causes TeX to typeset
1635 ; the argument to `@phoo' in italics.
1636 ;
1637 ; Note that each definition applies to its own formatter: one for TeX,
1638 ; the other for texinfo-format-buffer or texinfo-format-region.
1639 ;
1640 ; Here is another example: write
1641 ;
1642 ; @definfoenclose headword, , :
1643 ;
1644 ; near the beginning of the file, to define `@headword' as an Info
1645 ; formatting command that inserts nothing before and a colon after the
1646 ; argument to `@headword'.
1647
1648 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
1649 (defun texinfo-define-info-enclosure ()
1650 (let* ((args (texinfo-format-parse-line-args))
1651 (command-name (nth 0 args))
1652 (beginning-delimiter (or (nth 1 args) ""))
1653 (end-delimiter (or (nth 2 args) "")))
1654 (texinfo-discard-command)
1655 (setq texinfo-enclosure-list
1656 (cons
1657 (list command-name
1658 (list
1659 beginning-delimiter
1660 end-delimiter))
1661 texinfo-enclosure-list))))
1662
1663 \f
1664 ;;; @var, @code and the like
1665
1666 (put 'var 'texinfo-format 'texinfo-format-var)
1667 ; @sc a small caps font for TeX; formatted as `var' in Info
1668 (put 'sc 'texinfo-format 'texinfo-format-var)
1669 (defun texinfo-format-var ()
1670 (insert (upcase (texinfo-parse-arg-discard)))
1671 (goto-char texinfo-command-start))
1672
1673 ; various noops
1674
1675 (put 'b 'texinfo-format 'texinfo-format-noop)
1676 (put 'i 'texinfo-format 'texinfo-format-noop)
1677 (put 'r 'texinfo-format 'texinfo-format-noop)
1678 (put 't 'texinfo-format 'texinfo-format-noop)
1679 (put 'w 'texinfo-format 'texinfo-format-noop)
1680 (put 'asis 'texinfo-format 'texinfo-format-noop)
1681 (put 'dmn 'texinfo-format 'texinfo-format-noop)
1682 (put 'key 'texinfo-format 'texinfo-format-noop)
1683 (put 'math 'texinfo-format 'texinfo-format-noop)
1684 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
1685 (defun texinfo-format-noop ()
1686 (insert (texinfo-parse-arg-discard))
1687 (goto-char texinfo-command-start))
1688
1689 (put 'cite 'texinfo-format 'texinfo-format-code)
1690 (put 'code 'texinfo-format 'texinfo-format-code)
1691 (put 'file 'texinfo-format 'texinfo-format-code)
1692 (put 'kbd 'texinfo-format 'texinfo-format-code)
1693 (put 'samp 'texinfo-format 'texinfo-format-code)
1694 (defun texinfo-format-code ()
1695 (insert "`" (texinfo-parse-arg-discard) "'")
1696 (goto-char texinfo-command-start))
1697
1698 (put 'emph 'texinfo-format 'texinfo-format-emph)
1699 (put 'strong 'texinfo-format 'texinfo-format-emph)
1700 (defun texinfo-format-emph ()
1701 (insert "*" (texinfo-parse-arg-discard) "*")
1702 (goto-char texinfo-command-start))
1703
1704 (put 'dfn 'texinfo-format 'texinfo-format-defn)
1705 (put 'defn 'texinfo-format 'texinfo-format-defn)
1706 (defun texinfo-format-defn ()
1707 (insert "\"" (texinfo-parse-arg-discard) "\"")
1708 (goto-char texinfo-command-start))
1709
1710 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
1711 (defun texinfo-format-bullet ()
1712 "Insert an asterisk.
1713 If used within a line, follow `@bullet' with braces."
1714 (texinfo-optional-braces-discard)
1715 (insert "*"))
1716
1717 \f
1718 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
1719
1720 (put 'display 'texinfo-format 'texinfo-format-example)
1721 (put 'example 'texinfo-format 'texinfo-format-example)
1722 (put 'lisp 'texinfo-format 'texinfo-format-example)
1723 (put 'quotation 'texinfo-format 'texinfo-format-example)
1724 (put 'smallexample 'texinfo-format 'texinfo-format-example)
1725 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
1726 (defun texinfo-format-example ()
1727 (texinfo-push-stack 'example nil)
1728 (setq fill-column (- fill-column 5))
1729 (texinfo-discard-line))
1730
1731 (put 'example 'texinfo-end 'texinfo-end-example)
1732 (put 'display 'texinfo-end 'texinfo-end-example)
1733 (put 'lisp 'texinfo-end 'texinfo-end-example)
1734 (put 'quotation 'texinfo-end 'texinfo-end-example)
1735 (put 'smallexample 'texinfo-end 'texinfo-end-example)
1736 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
1737 (defun texinfo-end-example ()
1738 (setq fill-column (+ fill-column 5))
1739 (texinfo-discard-command)
1740 (let ((stacktop
1741 (texinfo-pop-stack 'example)))
1742 (texinfo-do-itemize (nth 1 stacktop))))
1743
1744 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
1745 (defun texinfo-format-exdent ()
1746 (texinfo-discard-command)
1747 (delete-region (point)
1748 (progn
1749 (skip-chars-forward " ")
1750 (point)))
1751 (insert ?\b)
1752 ;; Cancel out the deletion that texinfo-do-itemize
1753 ;; is going to do at the end of this line.
1754 (save-excursion
1755 (end-of-line)
1756 (insert "\n ")))
1757
1758 \f
1759 ;;; @cartouche
1760
1761 ; The @cartouche command is a noop in Info; in a printed manual,
1762 ; it makes a box with rounded corners.
1763
1764 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
1765 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
1766
1767 \f
1768 ;;; @flushleft and @format
1769
1770 ; The @flushleft command left justifies every line but leaves the
1771 ; right end ragged. As far as Info is concerned, @flushleft is a
1772 ; `do-nothing' command
1773
1774 ; The @format command is similar to @example except that it does not
1775 ; indent; this means that in Info, @format is similar to @flushleft.
1776
1777 (put 'format 'texinfo-format 'texinfo-format-flushleft)
1778 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
1779 (defun texinfo-format-flushleft ()
1780 (texinfo-discard-line))
1781
1782 (put 'format 'texinfo-end 'texinfo-end-flushleft)
1783 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
1784 (defun texinfo-end-flushleft ()
1785 (texinfo-discard-command))
1786
1787 \f
1788 ;;; @flushright
1789
1790 ; The @flushright command right justifies every line but leaves the
1791 ; left end ragged. Spaces and tabs at the right ends of lines are
1792 ; removed so that visible text lines up on the right side.
1793
1794 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
1795 (defun texinfo-format-flushright ()
1796 (texinfo-push-stack 'flushright nil)
1797 (texinfo-discard-line))
1798
1799 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
1800 (defun texinfo-end-flushright ()
1801 (texinfo-discard-command)
1802
1803 (let ((stacktop
1804 (texinfo-pop-stack 'flushright)))
1805
1806 (texinfo-do-flushright (nth 1 stacktop))))
1807
1808 (defun texinfo-do-flushright (from)
1809 (save-excursion
1810 (while (progn (forward-line -1)
1811 (>= (point) from))
1812
1813 (beginning-of-line)
1814 (insert
1815 (make-string
1816 (- fill-column
1817 (save-excursion
1818 (end-of-line)
1819 (skip-chars-backward " \t")
1820 (delete-region (point) (progn (end-of-line) (point)))
1821 (current-column)))
1822 ? )))))
1823
1824 \f
1825 ;;; @ctrl, @TeX, @copyright, @minus, @dots
1826
1827 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
1828 (defun texinfo-format-ctrl ()
1829 (let ((str (texinfo-parse-arg-discard)))
1830 (insert (logand 31 (aref str 0)))))
1831
1832 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
1833 (defun texinfo-format-TeX ()
1834 (texinfo-parse-arg-discard)
1835 (insert "TeX"))
1836
1837 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
1838 (defun texinfo-format-copyright ()
1839 (texinfo-parse-arg-discard)
1840 (insert "(C)"))
1841
1842 (put 'minus 'texinfo-format 'texinfo-format-minus)
1843 (defun texinfo-format-minus ()
1844 "Insert a minus sign.
1845 If used within a line, follow `@minus' with braces."
1846 (texinfo-optional-braces-discard)
1847 (insert "-"))
1848
1849 (put 'dots 'texinfo-format 'texinfo-format-dots)
1850 (defun texinfo-format-dots ()
1851 (texinfo-parse-arg-discard)
1852 (insert "..."))
1853
1854 (put 'enddots 'texinfo-format 'texinfo-format-enddots)
1855 (defun texinfo-format-enddots ()
1856 (texinfo-parse-arg-discard)
1857 (insert "...."))
1858
1859 \f
1860 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
1861
1862 ;;; Indent only those paragraphs that are refilled as a result of an
1863 ;;; @refill command.
1864
1865 ; * If the value is `asis', do not change the existing indentation at
1866 ; the starts of paragraphs.
1867
1868 ; * If the value zero, delete any existing indentation.
1869
1870 ; * If the value is greater than zero, indent each paragraph by that
1871 ; number of spaces.
1872
1873 ;;; But do not refill paragraphs with an @refill command that are
1874 ;;; preceded by @noindent or are part of a table, list, or deffn.
1875
1876 (defvar texinfo-paragraph-indent "asis"
1877 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
1878
1879 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
1880
1881 (defun texinfo-paragraphindent ()
1882 "Specify the number of spaces for @refill to indent a paragraph.
1883 Default is to leave the number of spaces as is."
1884 (let ((arg (texinfo-parse-arg-discard)))
1885 (if (string= "asis" arg)
1886 (setq texinfo-paragraph-indent "asis")
1887 (setq texinfo-paragraph-indent (string-to-int arg)))))
1888
1889 (put 'refill 'texinfo-format 'texinfo-format-refill)
1890 (defun texinfo-format-refill ()
1891 "Refill paragraph. Also, indent first line as set by @paragraphindent.
1892 Default is to leave paragraph indentation as is."
1893 (texinfo-discard-command)
1894 (forward-paragraph -1)
1895 (if (looking-at "[ \t\n]*$") (forward-line 1))
1896 ;; Do not indent if an entry in a list, table, or deffn,
1897 ;; or if paragraph is preceded by @noindent.
1898 ;; Otherwise, indent
1899 (cond
1900 ;; delete a @noindent line and do not indent paragraph
1901 ((save-excursion (forward-line -1)
1902 (looking-at "^@noindent"))
1903 (forward-line -1)
1904 (delete-region (point) (progn (forward-line 1) (point))))
1905 ;; do nothing if "asis"
1906 ((equal texinfo-paragraph-indent "asis"))
1907 ;; do no indenting in list, etc.
1908 ((> texinfo-stack-depth 0))
1909 ;; otherwise delete existing whitespace and indent
1910 (t
1911 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
1912 (insert (make-string texinfo-paragraph-indent ? ))))
1913 (forward-paragraph 1)
1914 (forward-line -1)
1915 (end-of-line)
1916 ;; Do not fill a section title line with asterisks, hyphens, etc. that
1917 ;; are used to underline it. This could occur if the line following
1918 ;; the underlining is not an index entry and has text within it.
1919 (let* ((previous-paragraph-separate paragraph-separate)
1920 (paragraph-separate (concat paragraph-separate "\\|[-=*.]+"))
1921 (previous-paragraph-start paragraph-start)
1922 (paragraph-start (concat paragraph-start "\\|[-=*.]+")))
1923 (unwind-protect
1924 (fill-paragraph nil)
1925 (setq paragraph-separate previous-paragraph-separate)
1926 (setq paragraph-start previous-paragraph-start))))
1927
1928 (put 'noindent 'texinfo-format 'texinfo-noindent)
1929 (defun texinfo-noindent ()
1930 (save-excursion
1931 (forward-paragraph 1)
1932 (if (search-backward "@refill"
1933 (save-excursion (forward-line -1) (point)) t)
1934 () ; leave @noindent command so @refill command knows not to indent
1935 ;; else
1936 (texinfo-discard-line))))
1937
1938 \f
1939 ;;; Index generation
1940
1941 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
1942 (defun texinfo-format-vindex ()
1943 (texinfo-index 'texinfo-vindex))
1944
1945 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
1946 (defun texinfo-format-cindex ()
1947 (texinfo-index 'texinfo-cindex))
1948
1949 (put 'findex 'texinfo-format 'texinfo-format-findex)
1950 (defun texinfo-format-findex ()
1951 (texinfo-index 'texinfo-findex))
1952
1953 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
1954 (defun texinfo-format-pindex ()
1955 (texinfo-index 'texinfo-pindex))
1956
1957 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
1958 (defun texinfo-format-tindex ()
1959 (texinfo-index 'texinfo-tindex))
1960
1961 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
1962 (defun texinfo-format-kindex ()
1963 (texinfo-index 'texinfo-kindex))
1964
1965 (defun texinfo-index (indexvar)
1966 (let ((arg (texinfo-parse-expanded-arg)))
1967 (texinfo-discard-command)
1968 (set indexvar
1969 (cons (list arg
1970 texinfo-last-node
1971 ;; Region formatting may not provide last node position.
1972 (if texinfo-last-node-pos
1973 (1+ (count-lines texinfo-last-node-pos (point)))
1974 1))
1975 (symbol-value indexvar)))))
1976
1977 (defconst texinfo-indexvar-alist
1978 '(("cp" . texinfo-cindex)
1979 ("fn" . texinfo-findex)
1980 ("vr" . texinfo-vindex)
1981 ("tp" . texinfo-tindex)
1982 ("pg" . texinfo-pindex)
1983 ("ky" . texinfo-kindex)))
1984
1985 \f
1986 ;;; @defindex @defcodeindex
1987 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
1988 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
1989
1990 (defun texinfo-format-defindex ()
1991 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
1992 (indexing-command (intern (concat index-name "index")))
1993 (index-formatting-command ; eg: `texinfo-format-aaindex'
1994 (intern (concat "texinfo-format-" index-name "index")))
1995 (index-alist-name ; eg: `texinfo-aaindex'
1996 (intern (concat "texinfo-" index-name "index"))))
1997
1998 (set index-alist-name nil)
1999
2000 (put indexing-command ; eg, aaindex
2001 'texinfo-format
2002 index-formatting-command) ; eg, texinfo-format-aaindex
2003
2004 ;; eg: "aa" . texinfo-aaindex
2005 (or (assoc index-name texinfo-indexvar-alist)
2006 (setq texinfo-indexvar-alist
2007 (cons
2008 (cons index-name
2009 index-alist-name)
2010 texinfo-indexvar-alist)))
2011
2012 (fset index-formatting-command
2013 (list 'lambda 'nil
2014 (list 'texinfo-index
2015 (list 'quote index-alist-name))))))
2016
2017 \f
2018 ;;; @synindex @syncodeindex
2019
2020 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
2021 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
2022
2023 (defun texinfo-format-synindex ()
2024 (let* ((args (texinfo-parse-arg-discard))
2025 (second (cdr (read-from-string args)))
2026 (joiner (symbol-name (car (read-from-string args))))
2027 (joined (symbol-name (car (read-from-string args second)))))
2028
2029 (if (assoc joiner texinfo-short-index-cmds-alist)
2030 (put
2031 (cdr (assoc joiner texinfo-short-index-cmds-alist))
2032 'texinfo-format
2033 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
2034 (intern (concat "texinfo-format-" joined "index"))))
2035 (put
2036 (intern (concat joiner "index"))
2037 'texinfo-format
2038 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
2039 (intern (concat "texinfo-format-" joined "index")))))))
2040
2041 (defconst texinfo-short-index-cmds-alist
2042 '(("cp" . cindex)
2043 ("fn" . findex)
2044 ("vr" . vindex)
2045 ("tp" . tindex)
2046 ("pg" . pindex)
2047 ("ky" . kindex)))
2048
2049 (defconst texinfo-short-index-format-cmds-alist
2050 '(("cp" . texinfo-format-cindex)
2051 ("fn" . texinfo-format-findex)
2052 ("vr" . texinfo-format-vindex)
2053 ("tp" . texinfo-format-tindex)
2054 ("pg" . texinfo-format-pindex)
2055 ("ky" . texinfo-format-kindex)))
2056
2057 \f
2058 ;;; Sort and index (for VMS)
2059
2060 ;; Sort an index which is in the current buffer between START and END.
2061 ;; Used on VMS, where the `sort' utility is not available.
2062 (defun texinfo-sort-region (start end)
2063 (require 'sort)
2064 (save-restriction
2065 (narrow-to-region start end)
2066 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
2067
2068 ;; Subroutine for sorting an index.
2069 ;; At start of a line, return a string to sort the line under.
2070 (defun texinfo-sort-startkeyfun ()
2071 (let ((line
2072 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
2073 ;; Canonicalize whitespace and eliminate funny chars.
2074 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
2075 (setq line (concat (substring line 0 (match-beginning 0))
2076 " "
2077 (substring line (match-end 0) (length line)))))
2078 line))
2079
2080 \f
2081 ;;; @printindex
2082
2083 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
2084
2085 (defun texinfo-format-printindex ()
2086 (let ((indexelts (symbol-value
2087 (cdr (assoc (texinfo-parse-arg-discard)
2088 texinfo-indexvar-alist))))
2089 opoint)
2090 (insert "\n* Menu:\n\n")
2091 (setq opoint (point))
2092 (texinfo-print-index nil indexelts)
2093
2094 (if (eq system-type 'vax-vms)
2095 (texinfo-sort-region opoint (point))
2096 (shell-command-on-region opoint (point) "sort -fd" 1))))
2097
2098 (defun texinfo-print-index (file indexelts)
2099 (while indexelts
2100 (if (stringp (car (car indexelts)))
2101 (progn
2102 (insert "* " (car (car indexelts)) ": " )
2103 (indent-to 32)
2104 (insert
2105 (if file (concat "(" file ")") "")
2106 (nth 1 (car indexelts)) ".")
2107 (indent-to 54)
2108 (insert
2109 (if (nth 2 (car indexelts))
2110 (format " %d." (nth 2 (car indexelts)))
2111 "")
2112 "\n"))
2113 ;; index entries from @include'd file
2114 (texinfo-print-index (nth 1 (car indexelts))
2115 (nth 2 (car indexelts))))
2116 (setq indexelts (cdr indexelts))))
2117
2118 \f
2119 ;;; Glyphs: @equiv, @error, etc
2120
2121 ;; @equiv to show that two expressions are equivalent
2122 ;; @error to show an error message
2123 ;; @expansion to show what a macro expands to
2124 ;; @point to show the location of point in an example
2125 ;; @print to show what an evaluated expression prints
2126 ;; @result to indicate the value returned by an expression
2127
2128 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
2129 (defun texinfo-format-equiv ()
2130 (texinfo-parse-arg-discard)
2131 (insert "=="))
2132
2133 (put 'error 'texinfo-format 'texinfo-format-error)
2134 (defun texinfo-format-error ()
2135 (texinfo-parse-arg-discard)
2136 (insert "error-->"))
2137
2138 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
2139 (defun texinfo-format-expansion ()
2140 (texinfo-parse-arg-discard)
2141 (insert "==>"))
2142
2143 (put 'point 'texinfo-format 'texinfo-format-point)
2144 (defun texinfo-format-point ()
2145 (texinfo-parse-arg-discard)
2146 (insert "-!-"))
2147
2148 (put 'print 'texinfo-format 'texinfo-format-print)
2149 (defun texinfo-format-print ()
2150 (texinfo-parse-arg-discard)
2151 (insert "-|"))
2152
2153 (put 'result 'texinfo-format 'texinfo-format-result)
2154 (defun texinfo-format-result ()
2155 (texinfo-parse-arg-discard)
2156 (insert "=>"))
2157
2158 \f
2159 ;;; Definition formatting: @deffn, @defun, etc
2160
2161 ;; What definition formatting produces:
2162 ;;
2163 ;; @deffn category name args...
2164 ;; In Info, `Category: name ARGS'
2165 ;; In index: name: node. line#.
2166 ;;
2167 ;; @defvr category name
2168 ;; In Info, `Category: name'
2169 ;; In index: name: node. line#.
2170 ;;
2171 ;; @deftp category name attributes...
2172 ;; `category name attributes...' Note: @deftp args in lower case.
2173 ;; In index: name: node. line#.
2174 ;;
2175 ;; Specialized function-like or variable-like entity:
2176 ;;
2177 ;; @defun, @defmac, @defspec, @defvar, @defopt
2178 ;;
2179 ;; @defun name args In Info, `Function: name ARGS'
2180 ;; @defmac name args In Info, `Macro: name ARGS'
2181 ;; @defvar name In Info, `Variable: name'
2182 ;; etc.
2183 ;; In index: name: node. line#.
2184 ;;
2185 ;; Generalized typed-function-like or typed-variable-like entity:
2186 ;; @deftypefn category data-type name args...
2187 ;; In Info, `Category: data-type name args...'
2188 ;; @deftypevr category data-type name
2189 ;; In Info, `Category: data-type name'
2190 ;; In index: name: node. line#.
2191 ;;
2192 ;; Specialized typed-function-like or typed-variable-like entity:
2193 ;; @deftypefun data-type name args...
2194 ;; In Info, `Function: data-type name ARGS'
2195 ;; In index: name: node. line#.
2196 ;;
2197 ;; @deftypevar data-type name
2198 ;; In Info, `Variable: data-type name'
2199 ;; In index: name: node. line#. but include args after name!?
2200 ;;
2201 ;; Generalized object oriented entity:
2202 ;; @defop category class name args...
2203 ;; In Info, `Category on class: name ARG'
2204 ;; In index: name on class: node. line#.
2205 ;;
2206 ;; @defcv category class name
2207 ;; In Info, `Category of class: name'
2208 ;; In index: name of class: node. line#.
2209 ;;
2210 ;; Specialized object oriented entity:
2211 ;; @defmethod class name args...
2212 ;; In Info, `Method on class: name ARGS'
2213 ;; In index: name on class: node. line#.
2214 ;;
2215 ;; @defivar class name
2216 ;; In Info, `Instance variable of class: name'
2217 ;; In index: name of class: node. line#.
2218
2219 \f
2220 ;;; The definition formatting functions
2221
2222 (defun texinfo-format-defun ()
2223 (texinfo-push-stack 'defun nil)
2224 (setq fill-column (- fill-column 5))
2225 (texinfo-format-defun-1 t))
2226
2227 (defun texinfo-end-defun ()
2228 (setq fill-column (+ fill-column 5))
2229 (texinfo-discard-command)
2230 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
2231 (texinfo-do-itemize start)
2232 ;; Delete extra newline inserted after header.
2233 (save-excursion
2234 (goto-char start)
2235 (delete-char -1))))
2236
2237 (defun texinfo-format-defunx ()
2238 (texinfo-format-defun-1 nil))
2239
2240 (defun texinfo-format-defun-1 (first-p)
2241 (let ((parse-args (texinfo-format-parse-defun-args))
2242 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
2243 (texinfo-discard-command)
2244 ;; Delete extra newline inserted after previous header line.
2245 (if (not first-p)
2246 (delete-char -1))
2247 (funcall
2248 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
2249 ;; Insert extra newline so that paragraph filling does not mess
2250 ;; with header line.
2251 (insert "\n\n")
2252 (rplaca (cdr (cdr (car texinfo-stack))) (point))
2253 (funcall
2254 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
2255
2256 ;;; Formatting the first line of a definition
2257
2258 ;; @deffn, @defvr, @deftp
2259 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2260 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2261 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2262 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2263 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2264 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2265 (defun texinfo-format-deffn (parsed-args)
2266 ;; Generalized function-like, variable-like, or generic data-type entity:
2267 ;; @deffn category name args...
2268 ;; In Info, `Category: name ARGS'
2269 ;; @deftp category name attributes...
2270 ;; `category name attributes...' Note: @deftp args in lower case.
2271 (let ((category (car parsed-args))
2272 (name (car (cdr parsed-args)))
2273 (args (cdr (cdr parsed-args))))
2274 (insert " -- " category ": " name)
2275 (while args
2276 (insert " "
2277 (if (or (= ?& (aref (car args) 0))
2278 (eq (eval (car texinfo-defun-type)) 'deftp-type))
2279 (car args)
2280 (upcase (car args))))
2281 (setq args (cdr args)))))
2282
2283 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
2284 (put 'defun 'texinfo-deffn-formatting-property
2285 'texinfo-format-specialized-defun)
2286 (put 'defunx 'texinfo-deffn-formatting-property
2287 'texinfo-format-specialized-defun)
2288 (put 'defmac 'texinfo-deffn-formatting-property
2289 'texinfo-format-specialized-defun)
2290 (put 'defmacx 'texinfo-deffn-formatting-property
2291 'texinfo-format-specialized-defun)
2292 (put 'defspec 'texinfo-deffn-formatting-property
2293 'texinfo-format-specialized-defun)
2294 (put 'defspecx 'texinfo-deffn-formatting-property
2295 'texinfo-format-specialized-defun)
2296 (put 'defvar 'texinfo-deffn-formatting-property
2297 'texinfo-format-specialized-defun)
2298 (put 'defvarx 'texinfo-deffn-formatting-property
2299 'texinfo-format-specialized-defun)
2300 (put 'defopt 'texinfo-deffn-formatting-property
2301 'texinfo-format-specialized-defun)
2302 (put 'defoptx 'texinfo-deffn-formatting-property
2303 'texinfo-format-specialized-defun)
2304 (defun texinfo-format-specialized-defun (parsed-args)
2305 ;; Specialized function-like or variable-like entity:
2306 ;; @defun name args In Info, `Function: Name ARGS'
2307 ;; @defmac name args In Info, `Macro: Name ARGS'
2308 ;; @defvar name In Info, `Variable: Name'
2309 ;; Use cdr of texinfo-defun-type to determine category:
2310 (let ((category (car (cdr texinfo-defun-type)))
2311 (name (car parsed-args))
2312 (args (cdr parsed-args)))
2313 (insert " -- " category ": " name)
2314 (while args
2315 (insert " "
2316 (if (= ?& (aref (car args) 0))
2317 (car args)
2318 (upcase (car args))))
2319 (setq args (cdr args)))))
2320
2321 ;; @deftypefn, @deftypevr: Generalized typed
2322 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2323 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2324 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2325 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2326 (defun texinfo-format-deftypefn (parsed-args)
2327 ;; Generalized typed-function-like or typed-variable-like entity:
2328 ;; @deftypefn category data-type name args...
2329 ;; In Info, `Category: data-type name args...'
2330 ;; @deftypevr category data-type name
2331 ;; In Info, `Category: data-type name'
2332 ;; Note: args in lower case, unless modified in command line.
2333 (let ((category (car parsed-args))
2334 (data-type (car (cdr parsed-args)))
2335 (name (car (cdr (cdr parsed-args))))
2336 (args (cdr (cdr (cdr parsed-args)))))
2337 (insert " -- " category ": " data-type " " name)
2338 (while args
2339 (insert " " (car args))
2340 (setq args (cdr args)))))
2341
2342 ;; @deftypefun, @deftypevar: Specialized typed
2343 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
2344 (put 'deftypefunx 'texinfo-deffn-formatting-property
2345 'texinfo-format-deftypefun)
2346 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
2347 (put 'deftypevarx 'texinfo-deffn-formatting-property
2348 'texinfo-format-deftypefun)
2349 (defun texinfo-format-deftypefun (parsed-args)
2350 ;; Specialized typed-function-like or typed-variable-like entity:
2351 ;; @deftypefun data-type name args...
2352 ;; In Info, `Function: data-type name ARGS'
2353 ;; @deftypevar data-type name
2354 ;; In Info, `Variable: data-type name'
2355 ;; Note: args in lower case, unless modified in command line.
2356 ;; Use cdr of texinfo-defun-type to determine category:
2357 (let ((category (car (cdr texinfo-defun-type)))
2358 (data-type (car parsed-args))
2359 (name (car (cdr parsed-args)))
2360 (args (cdr (cdr parsed-args))))
2361 (insert " -- " category ": " data-type " " name)
2362 (while args
2363 (insert " " (car args))
2364 (setq args (cdr args)))))
2365
2366 ;; @defop: Generalized object-oriented
2367 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
2368 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
2369 (defun texinfo-format-defop (parsed-args)
2370 ;; Generalized object oriented entity:
2371 ;; @defop category class name args...
2372 ;; In Info, `Category on class: name ARG'
2373 ;; Note: args in upper case; use of `on'
2374 (let ((category (car parsed-args))
2375 (class (car (cdr parsed-args)))
2376 (name (car (cdr (cdr parsed-args))))
2377 (args (cdr (cdr (cdr parsed-args)))))
2378 (insert " -- " category " on " class ": " name)
2379 (while args
2380 (insert " " (upcase (car args)))
2381 (setq args (cdr args)))))
2382
2383 ;; @defcv: Generalized object-oriented
2384 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
2385 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
2386 (defun texinfo-format-defcv (parsed-args)
2387 ;; Generalized object oriented entity:
2388 ;; @defcv category class name
2389 ;; In Info, `Category of class: name'
2390 ;; Note: args in upper case; use of `of'
2391 (let ((category (car parsed-args))
2392 (class (car (cdr parsed-args)))
2393 (name (car (cdr (cdr parsed-args))))
2394 (args (cdr (cdr (cdr parsed-args)))))
2395 (insert " -- " category " of " class ": " name)
2396 (while args
2397 (insert " " (upcase (car args)))
2398 (setq args (cdr args)))))
2399
2400 ;; @defmethod: Specialized object-oriented
2401 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
2402 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
2403 (defun texinfo-format-defmethod (parsed-args)
2404 ;; Specialized object oriented entity:
2405 ;; @defmethod class name args...
2406 ;; In Info, `Method on class: name ARGS'
2407 ;; Note: args in upper case; use of `on'
2408 ;; Use cdr of texinfo-defun-type to determine category:
2409 (let ((category (car (cdr texinfo-defun-type)))
2410 (class (car parsed-args))
2411 (name (car (cdr parsed-args)))
2412 (args (cdr (cdr parsed-args))))
2413 (insert " -- " category " on " class ": " name)
2414 (while args
2415 (insert " " (upcase (car args)))
2416 (setq args (cdr args)))))
2417
2418 ;; @defivar: Specialized object-oriented
2419 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
2420 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
2421 (defun texinfo-format-defivar (parsed-args)
2422 ;; Specialized object oriented entity:
2423 ;; @defivar class name
2424 ;; In Info, `Instance variable of class: name'
2425 ;; Note: args in upper case; use of `of'
2426 ;; Use cdr of texinfo-defun-type to determine category:
2427 (let ((category (car (cdr texinfo-defun-type)))
2428 (class (car parsed-args))
2429 (name (car (cdr parsed-args)))
2430 (args (cdr (cdr parsed-args))))
2431 (insert " -- " category " of " class ": " name)
2432 (while args
2433 (insert " " (upcase (car args)))
2434 (setq args (cdr args)))))
2435
2436 \f
2437 ;;; Indexing for definitions
2438
2439 ;; An index entry has three parts: the `entry proper', the node name, and the
2440 ;; line number. Depending on the which command is used, the entry is
2441 ;; formatted differently:
2442 ;;
2443 ;; @defun,
2444 ;; @defmac,
2445 ;; @defspec,
2446 ;; @defvar,
2447 ;; @defopt all use their 1st argument as the entry-proper
2448 ;;
2449 ;; @deffn,
2450 ;; @defvr,
2451 ;; @deftp
2452 ;; @deftypefun
2453 ;; @deftypevar all use their 2nd argument as the entry-proper
2454 ;;
2455 ;; @deftypefn,
2456 ;; @deftypevr both use their 3rd argument as the entry-proper
2457 ;;
2458 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
2459 ;; formatted: NAME on CLASS
2460
2461 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
2462 ;; formatted: NAME on CLASS
2463 ;;
2464 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
2465 ;; formatted: NAME of CLASS
2466 ;;
2467 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
2468 ;; formatted: NAME of CLASS
2469
2470 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
2471 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2472 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
2473 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2474 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
2475 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2476 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
2477 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2478 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
2479 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2480 (defun texinfo-index-defun (parsed-args)
2481 ;; use 1st parsed-arg as entry-proper
2482 ;; `index-list' will be texinfo-findex or the like
2483 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2484 (set index-list
2485 (cons
2486 ;; Three elements: entry-proper, node-name, line-number
2487 (list
2488 (car parsed-args)
2489 texinfo-last-node
2490 ;; Region formatting may not provide last node position.
2491 (if texinfo-last-node-pos
2492 (1+ (count-lines texinfo-last-node-pos (point)))
2493 1))
2494 (symbol-value index-list)))))
2495
2496 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2497 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2498 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2499 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2500 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2501 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2502 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2503 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2504 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2505 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2506 (defun texinfo-index-deffn (parsed-args)
2507 ;; use 2nd parsed-arg as entry-proper
2508 ;; `index-list' will be texinfo-findex or the like
2509 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2510 (set index-list
2511 (cons
2512 ;; Three elements: entry-proper, node-name, line-number
2513 (list
2514 (car (cdr parsed-args))
2515 texinfo-last-node
2516 ;; Region formatting may not provide last node position.
2517 (if texinfo-last-node-pos
2518 (1+ (count-lines texinfo-last-node-pos (point)))
2519 1))
2520 (symbol-value index-list)))))
2521
2522 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2523 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2524 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2525 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2526 (defun texinfo-index-deftypefn (parsed-args)
2527 ;; use 3rd parsed-arg as entry-proper
2528 ;; `index-list' will be texinfo-findex or the like
2529 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2530 (set index-list
2531 (cons
2532 ;; Three elements: entry-proper, node-name, line-number
2533 (list
2534 (car (cdr (cdr parsed-args)))
2535 texinfo-last-node
2536 ;; Region formatting may not provide last node position.
2537 (if texinfo-last-node-pos
2538 (1+ (count-lines texinfo-last-node-pos (point)))
2539 1))
2540 (symbol-value index-list)))))
2541
2542 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
2543 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
2544 (defun texinfo-index-defmethod (parsed-args)
2545 ;; use 2nd on 1st parsed-arg as entry-proper
2546 ;; `index-list' will be texinfo-findex or the like
2547 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2548 (set index-list
2549 (cons
2550 ;; Three elements: entry-proper, node-name, line-number
2551 (list
2552 (format "%s on %s"
2553 (car (cdr parsed-args))
2554 (car parsed-args))
2555 texinfo-last-node
2556 ;; Region formatting may not provide last node position.
2557 (if texinfo-last-node-pos
2558 (1+ (count-lines texinfo-last-node-pos (point)))
2559 1))
2560 (symbol-value index-list)))))
2561
2562 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
2563 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
2564 (defun texinfo-index-defop (parsed-args)
2565 ;; use 3rd on 2nd parsed-arg as entry-proper
2566 ;; `index-list' will be texinfo-findex or the like
2567 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2568 (set index-list
2569 (cons
2570 ;; Three elements: entry-proper, node-name, line-number
2571 (list
2572 (format "%s on %s"
2573 (car (cdr (cdr parsed-args)))
2574 (car (cdr parsed-args)))
2575 texinfo-last-node
2576 ;; Region formatting may not provide last node position.
2577 (if texinfo-last-node-pos
2578 (1+ (count-lines texinfo-last-node-pos (point)))
2579 1))
2580 (symbol-value index-list)))))
2581
2582 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
2583 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
2584 (defun texinfo-index-defivar (parsed-args)
2585 ;; use 2nd of 1st parsed-arg as entry-proper
2586 ;; `index-list' will be texinfo-findex or the like
2587 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2588 (set index-list
2589 (cons
2590 ;; Three elements: entry-proper, node-name, line-number
2591 (list
2592 (format "%s of %s"
2593 (car (cdr parsed-args))
2594 (car parsed-args))
2595 texinfo-last-node
2596 ;; Region formatting may not provide last node position.
2597 (if texinfo-last-node-pos
2598 (1+ (count-lines texinfo-last-node-pos (point)))
2599 1))
2600 (symbol-value index-list)))))
2601
2602 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
2603 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
2604 (defun texinfo-index-defcv (parsed-args)
2605 ;; use 3rd of 2nd parsed-arg as entry-proper
2606 ;; `index-list' will be texinfo-findex or the like
2607 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2608 (set index-list
2609 (cons
2610 ;; Three elements: entry-proper, node-name, line-number
2611 (list
2612 (format "%s of %s"
2613 (car (cdr (cdr parsed-args)))
2614 (car (cdr parsed-args)))
2615 texinfo-last-node
2616 ;; Region formatting may not provide last node position.
2617 (if texinfo-last-node-pos
2618 (1+ (count-lines texinfo-last-node-pos (point)))
2619 1))
2620 (symbol-value index-list)))))
2621
2622 \f
2623 ;;; Properties for definitions
2624
2625 ;; Each definition command has six properties:
2626 ;;
2627 ;; 1. texinfo-deffn-formatting-property to format definition line
2628 ;; 2. texinfo-defun-indexing-property to create index entry
2629 ;; 3. texinfo-format formatting command
2630 ;; 4. texinfo-end end formatting command
2631 ;; 5. texinfo-defun-type type of deffn to format
2632 ;; 6. texinfo-defun-index type of index to use
2633 ;;
2634 ;; The `x' forms of each definition command are used for the second
2635 ;; and subsequent header lines.
2636
2637 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
2638 ;; are listed just before the appropriate formatting and indexing commands.
2639
2640 (put 'deffn 'texinfo-format 'texinfo-format-defun)
2641 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
2642 (put 'deffn 'texinfo-end 'texinfo-end-defun)
2643 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
2644 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
2645 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
2646 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
2647
2648 (put 'defun 'texinfo-format 'texinfo-format-defun)
2649 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
2650 (put 'defun 'texinfo-end 'texinfo-end-defun)
2651 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
2652 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
2653 (put 'defun 'texinfo-defun-index 'texinfo-findex)
2654 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
2655
2656 (put 'defmac 'texinfo-format 'texinfo-format-defun)
2657 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
2658 (put 'defmac 'texinfo-end 'texinfo-end-defun)
2659 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
2660 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
2661 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
2662 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
2663
2664 (put 'defspec 'texinfo-format 'texinfo-format-defun)
2665 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
2666 (put 'defspec 'texinfo-end 'texinfo-end-defun)
2667 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
2668 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
2669 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
2670 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
2671
2672 (put 'defvr 'texinfo-format 'texinfo-format-defun)
2673 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
2674 (put 'defvr 'texinfo-end 'texinfo-end-defun)
2675 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
2676 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
2677 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
2678 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
2679
2680 (put 'defvar 'texinfo-format 'texinfo-format-defun)
2681 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
2682 (put 'defvar 'texinfo-end 'texinfo-end-defun)
2683 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
2684 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
2685 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
2686 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
2687
2688 (put 'defconst 'texinfo-format 'texinfo-format-defun)
2689 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
2690 (put 'defconst 'texinfo-end 'texinfo-end-defun)
2691 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
2692 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
2693 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
2694 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
2695
2696 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
2697 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
2698 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
2699 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
2700 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
2701 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
2702 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
2703
2704 (put 'defopt 'texinfo-format 'texinfo-format-defun)
2705 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
2706 (put 'defopt 'texinfo-end 'texinfo-end-defun)
2707 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
2708 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
2709 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
2710 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
2711
2712 (put 'deftp 'texinfo-format 'texinfo-format-defun)
2713 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
2714 (put 'deftp 'texinfo-end 'texinfo-end-defun)
2715 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
2716 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
2717 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
2718 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
2719
2720 ;;; Object-oriented stuff is a little hairier.
2721
2722 (put 'defop 'texinfo-format 'texinfo-format-defun)
2723 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
2724 (put 'defop 'texinfo-end 'texinfo-end-defun)
2725 (put 'defop 'texinfo-defun-type '('defop-type nil))
2726 (put 'defopx 'texinfo-defun-type '('defop-type nil))
2727 (put 'defop 'texinfo-defun-index 'texinfo-findex)
2728 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
2729
2730 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
2731 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
2732 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
2733 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
2734 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
2735 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
2736 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
2737
2738 (put 'defcv 'texinfo-format 'texinfo-format-defun)
2739 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
2740 (put 'defcv 'texinfo-end 'texinfo-end-defun)
2741 (put 'defcv 'texinfo-defun-type '('defop-type nil))
2742 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
2743 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
2744 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
2745
2746 (put 'defivar 'texinfo-format 'texinfo-format-defun)
2747 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
2748 (put 'defivar 'texinfo-end 'texinfo-end-defun)
2749 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
2750 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
2751 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
2752 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
2753
2754 ;;; Typed functions and variables
2755
2756 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
2757 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
2758 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
2759 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
2760 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
2761 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
2762 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
2763
2764 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
2765 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
2766 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
2767 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
2768 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
2769 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
2770 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
2771
2772 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
2773 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
2774 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
2775 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
2776 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
2777 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
2778 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
2779
2780 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
2781 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
2782 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
2783 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
2784 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
2785 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
2786 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
2787
2788 \f
2789 ;;; @set, @clear, @ifset, @ifclear
2790
2791 ;; If a flag is set with @set FLAG, then text between @ifset and @end
2792 ;; ifset is formatted normally, but if the flag is is cleared with
2793 ;; @clear FLAG, then the text is not formatted; it is ignored.
2794
2795 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
2796 ;; and @end ifclear is formatted normally, but if the flag is is set with
2797 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
2798 ;; is the opposite of @ifset.
2799
2800 ;; If a flag is set to a string with @set FLAG,
2801 ;; replace @value{FLAG} with the string.
2802 ;; If a flag with a value is cleared,
2803 ;; @value{FLAG} is invalid,
2804 ;; as if there had never been any @set FLAG previously.
2805
2806 (put 'clear 'texinfo-format 'texinfo-clear)
2807 (defun texinfo-clear ()
2808 "Clear the value of the flag."
2809 (let* ((arg (texinfo-parse-arg-discard))
2810 (flag (car (read-from-string arg)))
2811 (value (substring arg (cdr (read-from-string arg)))))
2812 (put flag 'texinfo-whether-setp 'flag-cleared)
2813 (put flag 'texinfo-set-value "")))
2814
2815 (put 'set 'texinfo-format 'texinfo-set)
2816 (defun texinfo-set ()
2817 "Set the value of the flag, optionally to a string.
2818 The command `@set foo This is a string.'
2819 sets flag foo to the value: `This is a string.'
2820 The command `@value{foo}' expands to the value."
2821 (let* ((arg (texinfo-parse-arg-discard))
2822 (flag (car (read-from-string arg)))
2823 (value (substring arg (cdr (read-from-string arg)))))
2824 (put flag 'texinfo-whether-setp 'flag-set)
2825 (put flag 'texinfo-set-value value)))
2826
2827 (put 'value 'texinfo-format 'texinfo-value)
2828 (defun texinfo-value ()
2829 "Insert the string to which the flag is set.
2830 The command `@set foo This is a string.'
2831 sets flag foo to the value: `This is a string.'
2832 The command `@value{foo}' expands to the value."
2833 (let ((arg (texinfo-parse-arg-discard)))
2834 (cond ((and
2835 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2836 'flag-set)
2837 (get (car (read-from-string arg)) 'texinfo-set-value))
2838 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
2839 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2840 'flag-cleared)
2841 (insert (format "{No value for \"%s\"}" arg)))
2842 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
2843 (insert (format "{No value for \"%s\"}" arg))))))
2844
2845 (put 'ifset 'texinfo-end 'texinfo-discard-command)
2846 (put 'ifset 'texinfo-format 'texinfo-if-set)
2847 (defun texinfo-if-set ()
2848 "If set, continue formatting; else do not format region up to @end ifset"
2849 (let ((arg (texinfo-parse-arg-discard)))
2850 (cond
2851 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2852 'flag-set)
2853 ;; Format the text (i.e., do not remove it); do nothing here.
2854 ())
2855 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2856 'flag-cleared)
2857 ;; Clear region (i.e., cause the text to be ignored).
2858 (delete-region texinfo-command-start
2859 (progn (re-search-forward "@end ifset[ \t]*\n")
2860 (point))))
2861 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2862 nil)
2863 ;; In this case flag is neither set nor cleared.
2864 ;; Act as if set, i.e. do nothing.
2865 ()))))
2866
2867 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
2868 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
2869 (defun texinfo-if-clear ()
2870 "If clear, continue formatting; if set, do not format up to @end ifset"
2871 (let ((arg (texinfo-parse-arg-discard)))
2872 (cond
2873 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2874 'flag-set)
2875 ;; Clear region (i.e., cause the text to be ignored).
2876 (delete-region texinfo-command-start
2877 (progn (re-search-forward "@end ifclear[ \t]*\n")
2878 (point))))
2879 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2880 'flag-cleared)
2881 ;; Format the text (i.e., do not remove it); do nothing here.
2882 ())
2883 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2884 nil)
2885 ;; In this case flag is neither set nor cleared.
2886 ;; Act as if clear, i.e. do nothing.
2887 ()))))
2888
2889 \f
2890 ;;; Process included files: `@include' command
2891
2892 ;; Updated 19 October 1990
2893 ;; In the original version, include files were ignored by Info but
2894 ;; incorporated in to the printed manual. To make references to the
2895 ;; included file, the Texinfo source file has to refer to the included
2896 ;; files using the `(filename)nodename' format for refering to other
2897 ;; Info files. Also, the included files had to be formatted on their
2898 ;; own. It was just like they were another file.
2899
2900 ;; Currently, include files are inserted into the buffer that is
2901 ;; formatted for Info. If large, the resulting info file is split and
2902 ;; tagified. For current include files to work, the master menu must
2903 ;; refer to all the nodes, and the highest level nodes in the include
2904 ;; files must have the correct next, prev, and up pointers.
2905
2906 ;; The included file may have an @setfilename and even an @settitle,
2907 ;; but not an `\input texinfo' line.
2908
2909 ;; Updated 24 March 1993
2910 ;; In order for @raisesections and @lowersections to work, included
2911 ;; files must be inserted into the buffer holding the outer file
2912 ;; before other Info formatting takes place. So @include is no longer
2913 ;; is treated like other @-commands.
2914 (put 'include 'texinfo-format 'texinfo-format-noop)
2915
2916 ; Original definition:
2917 ; (defun texinfo-format-include ()
2918 ; (let ((filename (texinfo-parse-arg-discard))
2919 ; (default-directory input-directory)
2920 ; subindex)
2921 ; (setq subindex
2922 ; (save-excursion
2923 ; (progn (find-file
2924 ; (cond ((file-readable-p (concat filename ".texinfo"))
2925 ; (concat filename ".texinfo"))
2926 ; ((file-readable-p (concat filename ".texi"))
2927 ; (concat filename ".texi"))
2928 ; ((file-readable-p (concat filename ".tex"))
2929 ; (concat filename ".tex"))
2930 ; ((file-readable-p filename)
2931 ; filename)
2932 ; (t (error "@include'd file %s not found"
2933 ; filename))))
2934 ; (texinfo-format-buffer-1))))
2935 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
2936 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
2937 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
2938 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
2939 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
2940 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
2941 ;
2942 ;(defun texinfo-subindex (indexvar file content)
2943 ; (set indexvar (cons (list 'recurse file content)
2944 ; (symbol-value indexvar))))
2945
2946 ; Second definition:
2947 ; (put 'include 'texinfo-format 'texinfo-format-include)
2948 ; (defun texinfo-format-include ()
2949 ; (let ((filename (concat input-directory
2950 ; (texinfo-parse-arg-discard)))
2951 ; (default-directory input-directory))
2952 ; (message "Reading: %s" filename)
2953 ; (save-excursion
2954 ; (save-restriction
2955 ; (narrow-to-region
2956 ; (point)
2957 ; (+ (point) (car (cdr (insert-file-contents filename)))))
2958 ; (goto-char (point-min))
2959 ; (texinfo-append-refill)
2960 ; (texinfo-format-convert (point-min) (point-max))))
2961 ; (setq last-input-buffer input-buffer) ; to bypass setfilename
2962 ; ))
2963
2964 \f
2965 ;;; Numerous commands do nothing in Texinfo
2966
2967 ;; These commands are defined in texinfo.tex for printed output.
2968
2969 (put 'bye 'texinfo-format 'texinfo-discard-line)
2970 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
2971 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
2972 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
2973 (put 'finalout 'texinfo-format 'texinfo-discard-line)
2974 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
2975 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
2976 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
2977 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
2978 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
2979 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
2980 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
2981 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
2982 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
2983 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
2984 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
2985 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
2986 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
2987 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
2988 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
2989 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
2990 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
2991
2992 \f
2993 ;;; Some commands cannot be handled
2994
2995 (defun texinfo-unsupported ()
2996 (error "%s is not handled by texinfo"
2997 (buffer-substring texinfo-command-start texinfo-command-end)))
2998 \f
2999 ;;; Batch formatting
3000
3001 (defun batch-texinfo-format ()
3002 "Runs texinfo-format-buffer on the files remaining on the command line.
3003 Must be used only with -batch, and kills emacs on completion.
3004 Each file will be processed even if an error occurred previously.
3005 For example, invoke
3006 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
3007 (if (not noninteractive)
3008 (error "batch-texinfo-format may only be used -batch."))
3009 (let ((version-control t)
3010 (auto-save-default nil)
3011 (find-file-run-dired nil)
3012 (kept-old-versions 259259)
3013 (kept-new-versions 259259))
3014 (let ((error 0)
3015 file
3016 (files ()))
3017 (while command-line-args-left
3018 (setq file (expand-file-name (car command-line-args-left)))
3019 (cond ((not (file-exists-p file))
3020 (message ">> %s does not exist!" file)
3021 (setq error 1
3022 command-line-args-left (cdr command-line-args-left)))
3023 ((file-directory-p file)
3024 (setq command-line-args-left
3025 (nconc (directory-files file)
3026 (cdr command-line-args-left))))
3027 (t
3028 (setq files (cons file files)
3029 command-line-args-left (cdr command-line-args-left)))))
3030 (while files
3031 (setq file (car files)
3032 files (cdr files))
3033 (condition-case err
3034 (progn
3035 (if buffer-file-name (kill-buffer (current-buffer)))
3036 (find-file file)
3037 (buffer-disable-undo (current-buffer))
3038 (set-buffer-modified-p nil)
3039 (texinfo-mode)
3040 (message "texinfo formatting %s..." file)
3041 (texinfo-format-buffer nil)
3042 (if (buffer-modified-p)
3043 (progn (message "Saving modified %s" (buffer-file-name))
3044 (save-buffer))))
3045 (error
3046 (message ">> Error: %s" (prin1-to-string err))
3047 (message ">> point at")
3048 (let ((s (buffer-substring (point)
3049 (min (+ (point) 100)
3050 (point-max))))
3051 (tem 0))
3052 (while (setq tem (string-match "\n+" s tem))
3053 (setq s (concat (substring s 0 (match-beginning 0))
3054 "\n>> "
3055 (substring s (match-end 0)))
3056 tem (1+ tem)))
3057 (message ">> %s" s))
3058 (setq error 1))))
3059 (kill-emacs error))))
3060
3061 \f
3062 ;;; Place `provide' at end of file.
3063 (provide 'texinfmt)
3064
3065 ;;; texinfmt.el ends here.