]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfmt.el
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / lisp / textmodes / texinfmt.el
1 ;;; texinfmt.el --- format Texinfo files into Info files
2
3 ;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2011 Free Software Foundation, Inc.
4
5 ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org>
6 ;; Keywords: maint, tex, docs
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 3 of the License, or
13 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 ;;; Emacs lisp functions to convert Texinfo files to Info files.
28
29 (defvar texinfmt-version "2.42 of 7 Jul 2006")
30
31 (defun texinfmt-version (&optional here)
32 "Show the version of texinfmt.el in the minibuffer.
33 If optional argument HERE is non-nil, insert info at point."
34 (interactive "P")
35 (let ((version-string
36 (format "Version of \`texinfmt.el\': %s" texinfmt-version)))
37 (if here
38 (insert version-string)
39 (if (called-interactively-p 'interactive)
40 (message "%s" version-string)
41 version-string))))
42
43 \f
44 ;;; Variable definitions
45
46 (require 'texinfo) ; So `texinfo-footnote-style' is defined.
47 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
48
49 (defvar texinfo-vindex)
50 (defvar texinfo-findex)
51 (defvar texinfo-cindex)
52 (defvar texinfo-pindex)
53 (defvar texinfo-tindex)
54 (defvar texinfo-kindex)
55 (defvar texinfo-last-node)
56 (defvar texinfo-node-names)
57 (defvar texinfo-enclosure-list)
58 (defvar texinfo-alias-list)
59 (defvar texinfo-fold-nodename-case nil)
60
61 (defvar texinfo-command-start)
62 (defvar texinfo-command-end)
63 (defvar texinfo-command-name)
64 (defvar texinfo-defun-type)
65 (defvar texinfo-last-node-pos)
66 (defvar texinfo-stack)
67 (defvar texinfo-short-index-cmds-alist)
68 (defvar texinfo-short-index-format-cmds-alist)
69 (defvar texinfo-format-filename)
70 (defvar texinfo-footnote-number)
71
72 (defvar texinfo-raisesections-alist
73 '((@chapter . @chapter) ; Cannot go higher
74 (@unnumbered . @unnumbered)
75 (@centerchap . @unnumbered)
76
77 (@majorheading . @majorheading)
78 (@chapheading . @chapheading)
79 (@appendix . @appendix)
80
81 (@section . @chapter)
82 (@unnumberedsec . @unnumbered)
83 (@heading . @chapheading)
84 (@appendixsec . @appendix)
85
86 (@subsection . @section)
87 (@unnumberedsubsec . @unnumberedsec)
88 (@subheading . @heading)
89 (@appendixsubsec . @appendixsec)
90
91 (@subsubsection . @subsection)
92 (@unnumberedsubsubsec . @unnumberedsubsec)
93 (@subsubheading . @subheading)
94 (@appendixsubsubsec . @appendixsubsec))
95 "*An alist of next higher levels for chapters, sections, etc...
96 For example, section to chapter, subsection to section.
97 Used by `texinfo-raise-lower-sections'.
98 The keys specify types of section; the values correspond to the next
99 higher types.")
100
101 (defvar texinfo-lowersections-alist
102 '((@chapter . @section)
103 (@unnumbered . @unnumberedsec)
104 (@centerchap . @unnumberedsec)
105 (@majorheading . @heading)
106 (@chapheading . @heading)
107 (@appendix . @appendixsec)
108
109 (@section . @subsection)
110 (@unnumberedsec . @unnumberedsubsec)
111 (@heading . @subheading)
112 (@appendixsec . @appendixsubsec)
113
114 (@subsection . @subsubsection)
115 (@unnumberedsubsec . @unnumberedsubsubsec)
116 (@subheading . @subsubheading)
117 (@appendixsubsec . @appendixsubsubsec)
118
119 (@subsubsection . @subsubsection) ; Cannot go lower.
120 (@unnumberedsubsubsec . @unnumberedsubsubsec)
121 (@subsubheading . @subsubheading)
122 (@appendixsubsubsec . @appendixsubsubsec))
123 "*An alist of next lower levels for chapters, sections, etc...
124 For example, chapter to section, section to subsection.
125 Used by `texinfo-raise-lower-sections'.
126 The keys specify types of section; the values correspond to the next
127 lower types.")
128 \f
129 ;;; Syntax table
130
131 (defvar texinfo-format-syntax-table
132 (let ((st (make-syntax-table)))
133 (modify-syntax-entry ?\" " " st)
134 (modify-syntax-entry ?\\ " " st)
135 (modify-syntax-entry ?@ "\\" st)
136 (modify-syntax-entry ?\^q "\\" st)
137 (modify-syntax-entry ?\[ "." st)
138 (modify-syntax-entry ?\] "." st)
139 (modify-syntax-entry ?\( "." st)
140 (modify-syntax-entry ?\) "." st)
141 (modify-syntax-entry ?{ "(}" st)
142 (modify-syntax-entry ?} "){" st)
143 (modify-syntax-entry ?\' "." st)
144 st))
145
146 \f
147 ;;; Top level buffer and region formatting functions
148
149 ;;;###autoload
150 (defun texinfo-format-buffer (&optional nosplit)
151 "Process the current buffer as texinfo code, into an Info file.
152 The Info file output is generated in a buffer visiting the Info file
153 name specified in the @setfilename command.
154
155 Non-nil argument (prefix, if interactive) means don't make tag table
156 and don't split the file if large. You can use `Info-tagify' and
157 `Info-split' to do these manually."
158 (interactive "P")
159 (let ((lastmessage "Formatting Info file...")
160 (coding-system-for-write buffer-file-coding-system))
161 (message lastmessage)
162 (widen)
163 (texinfo-format-buffer-1)
164 (Info-tagify)
165 (if nosplit
166 nil
167 (if (> (buffer-size) (+ 50000 Info-split-threshold))
168 (progn
169 (message (setq lastmessage "Splitting Info file..."))
170 (Info-split))))
171 (message (concat lastmessage
172 (if (called-interactively-p 'interactive)
173 "done. Now save it." "done.")))))
174
175 (defvar texinfo-region-buffer-name "*Info Region*"
176 "*Name of the temporary buffer used by \\[texinfo-format-region].")
177
178 (defvar texinfo-pre-format-hook nil
179 "Hook called before the conversion of the Texinfo file to Info format.
180 The functions on this hook are called with argument BUFFER, the buffer
181 containing the Texinfo file.")
182
183 ;; These come from tex-mode.el.
184 (defvar tex-start-of-header)
185 (defvar tex-end-of-header)
186
187 ;;;###autoload
188 (defun texinfo-format-region (region-beginning region-end)
189 "Convert the current region of the Texinfo file to Info format.
190 This lets you see what that part of the file will look like in Info.
191 The command is bound to \\[texinfo-format-region]. The text that is
192 converted to Info is stored in a temporary buffer."
193 (interactive "r")
194 (message "Converting region to Info format...")
195 (let (texinfo-command-start
196 texinfo-command-end
197 texinfo-command-name
198 texinfo-vindex
199 texinfo-findex
200 texinfo-cindex
201 texinfo-pindex
202 texinfo-tindex
203 texinfo-kindex
204 texinfo-stack
205 (texinfo-format-filename "")
206 texinfo-example-start
207 texinfo-last-node-pos
208 texinfo-last-node
209 texinfo-node-names
210 (texinfo-footnote-number 0)
211 last-input-buffer
212 (fill-column-for-info fill-column)
213 (input-buffer (current-buffer))
214 (input-directory default-directory)
215 (header-text "")
216 (header-beginning 1)
217 (header-end 1))
218
219 ;;; Copy lines between beginning and end of header lines,
220 ;;; if any, or else copy the `@setfilename' line, if any.
221 (save-excursion
222 (save-restriction
223 (widen)
224 (goto-char (point-min))
225 (let ((search-end (line-beginning-position 101)))
226 (if (or
227 ;; Either copy header text.
228 (and
229 (prog1
230 (search-forward tex-start-of-header search-end t)
231 (forward-line 1)
232 ;; Mark beginning of header.
233 (setq header-beginning (point)))
234 (prog1
235 (search-forward tex-end-of-header nil t)
236 (beginning-of-line)
237 ;; Mark end of header
238 (setq header-end (point))))
239 ;; Or copy @filename line.
240 (prog2
241 (goto-char (point-min))
242 (search-forward "@setfilename" search-end t)
243 (beginning-of-line)
244 (setq header-beginning (point))
245 (forward-line 1)
246 (setq header-end (point))))
247
248 ;; Copy header
249 (setq header-text
250 (buffer-substring-no-properties
251 (min header-beginning region-beginning)
252 header-end))))))
253
254 ;;; Find a buffer to use.
255 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
256 (setq buffer-read-only t)
257 (let ((inhibit-read-only t))
258 (erase-buffer)
259 ;; Insert the header into the buffer.
260 (insert header-text)
261 ;; Insert the region into the buffer.
262 (insert-buffer-substring
263 input-buffer
264 (max region-beginning header-end)
265 region-end)
266 (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
267 ;; Make sure region ends in a newline.
268 (or (= (preceding-char) ?\n)
269 (insert "\n"))
270
271 (goto-char (point-min))
272 (texinfo-mode)
273 (message "Converting region to Info format...")
274 (setq fill-column fill-column-for-info)
275 ;; Install a syntax table useful for scanning command operands.
276 (set-syntax-table texinfo-format-syntax-table)
277
278 ;; Insert @include files so `texinfo-raise-lower-sections' can
279 ;; work on them without losing track of multiple
280 ;; @raise/@lowersections commands.
281 (while (re-search-forward "^@include" nil t)
282 (setq texinfo-command-end (point))
283 (let ((filename (concat input-directory
284 (texinfo-parse-line-arg))))
285 (re-search-backward "^@include")
286 (delete-region (point) (line-beginning-position 2))
287 (message "Reading included file: %s" filename)
288 (save-excursion
289 (save-restriction
290 (narrow-to-region
291 (point)
292 (+ (point) (car (cdr (insert-file-contents filename)))))
293 (goto-char (point-min))
294 ;; Remove `@setfilename' line from included file, if any,
295 ;; so @setfilename command not duplicated.
296 (if (re-search-forward "^@setfilename" (line-end-position 100) t)
297 (delete-region (line-beginning-position 1)
298 (line-beginning-position 2)))))))
299
300 ;; Raise or lower level of each section, if necessary.
301 (goto-char (point-min))
302 (texinfo-raise-lower-sections)
303 ;; Append @refill to appropriate paragraphs for filling.
304 (goto-char (point-min))
305 (texinfo-append-refill)
306 ;; If the region includes the effective end of the data,
307 ;; discard everything after that.
308 (goto-char (point-max))
309 (if (re-search-backward "^@bye" nil t)
310 (delete-region (point) (point-max)))
311 ;; Make sure buffer ends in a newline.
312 (or (= (preceding-char) ?\n)
313 (insert "\n"))
314 ;; Don't use a previous value of texinfo-enclosure-list.
315 (setq texinfo-enclosure-list nil)
316 (setq texinfo-alias-list nil)
317
318 (goto-char (point-min))
319 (if (looking-at "\\\\input[ \t]+texinfo")
320 (delete-region (point) (line-beginning-position 2)))
321
322 ;; Insert Info region title text.
323 (goto-char (point-min))
324 (if (search-forward "@setfilename" (line-beginning-position 101) t)
325 (progn
326 (setq texinfo-command-end (point))
327 (beginning-of-line)
328 (setq texinfo-command-start (point))
329 (let ((arg (texinfo-parse-arg-discard)))
330 (insert " "
331 texinfo-region-buffer-name
332 " buffer for: `")
333 (insert (file-name-nondirectory (expand-file-name arg)))
334 (insert "', -*-Text-*-\n")))
335 ;; Else no `@setfilename' line
336 (insert " "
337 texinfo-region-buffer-name
338 " buffer -*-Text-*-\n"))
339 (insert "produced by `texinfo-format-region'\n"
340 "from a region in: "
341 (if (buffer-file-name input-buffer)
342 (concat "`"
343 (file-name-sans-versions
344 (file-name-nondirectory
345 (buffer-file-name input-buffer)))
346 "'")
347 (concat "buffer `" (buffer-name input-buffer) "'"))
348 "\nusing `texinfmt.el' version "
349 texinfmt-version
350 ".\n\n")
351
352 ;; Now convert for real.
353 (goto-char (point-min))
354 (texinfo-format-scan)
355 (goto-char (point-min))
356 (Info-tagify input-buffer)
357 (goto-char (point-min))
358 (message "Done."))))
359
360 ;;;###autoload
361 (defun texi2info (&optional nosplit)
362 "Convert the current buffer (written in Texinfo code) into an Info file.
363 The Info file output is generated in a buffer visiting the Info file
364 names specified in the @setfilename command.
365
366 This function automatically updates all node pointers and menus, and
367 creates a master menu. This work is done on a temporary buffer that
368 is automatically removed when the Info file is created. The original
369 Texinfo source buffer is not changed.
370
371 Non-nil argument (prefix, if interactive) means don't split the file
372 if large. You can use `Info-split' to do this manually."
373 (interactive "P")
374 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" )))
375 (message "First updating nodes and menus, then creating Info file.")
376 ;; (sit-for 2)
377 (copy-to-buffer temp-buffer (point-min) (point-max))
378 (switch-to-buffer temp-buffer)
379 (texinfo-master-menu t)
380 (message "Now creating Info file.")
381 (sit-for 2)
382 (texinfo-format-buffer nosplit)
383 (save-buffer)
384 (kill-buffer temp-buffer)))
385
386 \f
387 ;;; Primary internal formatting function for the whole buffer.
388
389 (defun texinfo-format-buffer-1 ()
390 (let (texinfo-format-filename
391 texinfo-example-start
392 texinfo-command-start
393 texinfo-command-end
394 texinfo-command-name
395 texinfo-last-node
396 texinfo-last-node-pos
397 texinfo-vindex
398 texinfo-findex
399 texinfo-cindex
400 texinfo-pindex
401 texinfo-tindex
402 texinfo-kindex
403 texinfo-stack
404 texinfo-node-names
405 (texinfo-footnote-number 0)
406 last-input-buffer
407 outfile
408 (fill-column-for-info fill-column)
409 (input-buffer (current-buffer))
410 (input-directory default-directory))
411 (setq texinfo-enclosure-list nil)
412 (setq texinfo-alias-list nil)
413 (save-excursion
414 (goto-char (point-min))
415 (or (search-forward "@setfilename" nil t)
416 (error "Texinfo file needs an `@setfilename FILENAME' line"))
417 (setq texinfo-command-end (point))
418 (setq outfile (texinfo-parse-line-arg)))
419
420 (find-file outfile)
421 (texinfo-mode)
422 (erase-buffer)
423 (buffer-disable-undo)
424
425 (message "Formatting Info file: %s" outfile)
426 (setq texinfo-format-filename
427 (file-name-nondirectory (expand-file-name outfile)))
428
429 (setq fill-column fill-column-for-info)
430 (set-syntax-table texinfo-format-syntax-table)
431
432 (insert-buffer-substring input-buffer)
433 (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
434 (message "Converting %s to Info format..." (buffer-name input-buffer))
435
436 ;; Insert @include files so `texinfo-raise-lower-sections' can
437 ;; work on them without losing track of multiple
438 ;; @raise/@lowersections commands.
439 (goto-char (point-min))
440 (while (re-search-forward "^@include" nil t)
441 (setq texinfo-command-end (point))
442 (let ((filename (concat input-directory
443 (texinfo-parse-line-arg))))
444 (re-search-backward "^@include")
445 (delete-region (point) (line-beginning-position 2))
446 (message "Reading included file: %s" filename)
447 (save-excursion
448 (save-restriction
449 (narrow-to-region
450 (point)
451 (+ (point) (car (cdr (insert-file-contents filename)))))
452 (goto-char (point-min))
453 ;; Remove `@setfilename' line from included file, if any,
454 ;; so @setfilename command not duplicated.
455 (if (re-search-forward "^@setfilename" (line-end-position 100) t)
456 (delete-region (line-beginning-position 1)
457 (line-beginning-position 2)))))))
458 ;; Raise or lower level of each section, if necessary.
459 (goto-char (point-min))
460 (texinfo-raise-lower-sections)
461 ;; Append @refill to appropriate paragraphs
462 (goto-char (point-min))
463 (texinfo-append-refill)
464 (goto-char (point-min))
465 (search-forward "@setfilename")
466 (beginning-of-line)
467 (delete-region (point-min) (point))
468 ;; Remove @bye at end of file, if it is there.
469 (goto-char (point-max))
470 (if (search-backward "@bye" nil t)
471 (delete-region (point) (point-max)))
472 ;; Make sure buffer ends in a newline.
473 (or (= (preceding-char) ?\n)
474 (insert "\n"))
475 ;; Scan the whole buffer, converting to Info format.
476 (texinfo-format-scan)
477 (goto-char (point-min))
478 ;; Insert info about how this file was made.
479 (insert "Info file: "
480 texinfo-format-filename ", -*-Text-*-\n"
481 "produced by `texinfo-format-buffer'\n"
482 ;; Date string removed so that regression testing is easier.
483 ;; "on "
484 ;; (insert (format-time-string "%e %b %Y")) " "
485 "from file"
486 (if (buffer-file-name input-buffer)
487 (concat " `"
488 (file-name-sans-versions
489 (file-name-nondirectory
490 (buffer-file-name input-buffer)))
491 "'")
492 (concat "buffer `" (buffer-name input-buffer) "'"))
493 "\nusing `texinfmt.el' version "
494 texinfmt-version
495 ".\n\n")
496 ;; Return data for indices.
497 (list outfile
498 texinfo-vindex texinfo-findex texinfo-cindex
499 texinfo-pindex texinfo-tindex texinfo-kindex)))
500
501 \f
502 ;;; Perform non-@-command file conversions: quotes and hyphens
503
504 (defun texinfo-format-convert (min max)
505 ;; Convert left and right quotes to typewriter font quotes.
506 (goto-char min)
507 (while (search-forward "``" max t)
508 (replace-match "\""))
509 (goto-char min)
510 (while (search-forward "''" max t)
511 (replace-match "\""))
512 ;; Convert three hyphens in a row to two.
513 (goto-char min)
514 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
515 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning 2)))))
516
517 \f
518 ;;; Handle paragraph filling
519
520 ;; Keep as concatinated lists for ease of maintenance
521
522 (defvar texinfo-no-refill-regexp
523 (concat
524 "^@"
525 "\\("
526 ;; add "itemize\\|" (from experiment of 2001 Nov 28)
527 ;; because of a problem with @end itemize@refill
528 ;; I don't know if this causes other problems.
529 ;; I suspect itemized lists don't get filled properly and a
530 ;; more precise fix is required. Bob
531 ;; commented out on 2005 Feb 28 by Bob
532 ;; "itemize\\|"
533 "direntry\\|"
534 "lisp\\|"
535 "smalllisp\\|"
536 "example\\|"
537 "smallexample\\|"
538 "display\\|"
539 "smalldisplay\\|"
540 "format\\|"
541 "smallformat\\|"
542 "flushleft\\|"
543 "flushright\\|"
544 "menu\\|"
545 "multitable\\|"
546 "titlepage\\|"
547 "iftex\\|"
548 "ifhtml\\|"
549 "tex\\|"
550 "html"
551 "\\)")
552 "Regexp specifying environments in which paragraphs are not filled.")
553
554 (defvar texinfo-accent-commands
555 (concat
556 "@^\\|"
557 "@`\\|"
558 "@'\\|"
559 "@\"\\|"
560 "@,\\|"
561 "@=\\|"
562 "@~\\|"
563 "@OE{\\|"
564 "@oe{\\|"
565 "@AA{\\|"
566 "@aa{\\|"
567 "@AE{\\|"
568 "@ae{\\|"
569 "@ss{\\|"
570 "@questiondown{\\|"
571 "@exclamdown{\\|"
572 "@L{\\|"
573 "@l{\\|"
574 "@O{\\|"
575 "@o{\\|"
576 "@dotaccent{\\|"
577 "@ubaraccent{\\|"
578 "@d{\\|"
579 "@H{\\|"
580 "@ringaccent{\\|"
581 "@tieaccent{\\|"
582 "@u{\\|"
583 "@v{\\|"
584 "@dotless{"
585 ))
586
587 (defvar texinfo-part-of-para-regexp
588 (concat
589 "^@"
590 "\\("
591 "b{\\|"
592 "bullet{\\|"
593 "cite{\\|"
594 "code{\\|"
595 "email{\\|"
596 "emph{\\|"
597 "equiv{\\|"
598 "error{\\|"
599 "expansion{\\|"
600 "file{\\|"
601 "i{\\|"
602 "inforef{\\|"
603 "kbd{\\|"
604 "key{\\|"
605 "lisp{\\|"
606 "minus{\\|"
607 "point{\\|"
608 "print{\\|"
609 "pxref{\\|"
610 "r{\\|"
611 "ref{\\|"
612 "result{\\|"
613 "samp{\\|"
614 "sc{\\|"
615 "t{\\|"
616 "TeX{\\|"
617 "today{\\|"
618 "url{\\|"
619 "var{\\|"
620 "w{\\|"
621 "xref{\\|"
622 "@-\\|" ; @- is a descretionary hyphen (not an accent) (a noop).
623 texinfo-accent-commands
624 "\\)"
625 )
626 "Regexp specifying @-commands found within paragraphs.")
627
628 (defun texinfo-append-refill ()
629 "Append @refill at end of each paragraph that should be filled.
630 Do not append @refill to paragraphs within @example and similar environments.
631 Do not append @refill to paragraphs containing @w{TEXT} or @*."
632
633 ;; It is necessary to append @refill before other processing because
634 ;; the other processing removes information that tells Texinfo
635 ;; whether the text should or should not be filled.
636
637 (while (< (point) (point-max))
638 (let ((refill-blank-lines "^[ \t\n]*$")
639 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
640 (beginning-of-line)
641 ;; 1. Skip over blank lines;
642 ;; skip over lines beginning with @-commands,
643 ;; but do not skip over lines
644 ;; that are no-refill environments such as @example or
645 ;; that begin with within-paragraph @-commands such as @code.
646 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
647 (not (looking-at
648 (concat
649 "\\("
650 texinfo-no-refill-regexp
651 "\\|"
652 texinfo-part-of-para-regexp
653 "\\)")))
654 (< (point) (point-max)))
655 (forward-line 1))
656 ;; 2. Skip over @example and similar no-refill environments.
657 (if (looking-at texinfo-no-refill-regexp)
658 (let ((environment (match-string-no-properties 1)))
659 (progn (re-search-forward (concat "^@end " environment) nil t)
660 (forward-line 1)))
661 ;; Else
662 ;; 3. Do not refill a paragraph containing @w or @*, or ending
663 ;; with @<newline> followed by a newline.
664 (if (or (>= (point) (point-max))
665 (re-search-forward
666 "@w{\\|@\\*\\|@\n\n"
667 (save-excursion (forward-paragraph)
668 (line-beginning-position 2))
669 t))
670 ;; Go to end of paragraph and do nothing.
671 (forward-paragraph)
672 ;; 4. Else go to end of paragraph and insert @refill
673 (forward-paragraph)
674 (forward-line -1)
675 (let ((line-beg (point)))
676 (end-of-line)
677 (delete-region
678 (point)
679 (save-excursion (skip-chars-backward " \t") (point)))
680 (forward-char 1)
681 (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t)
682 (forward-char -1))
683 (unless (re-search-backward "@refill\\|^[ \t]*@" line-beg t)
684 (insert "@refill")))
685 (forward-line 1))))))
686
687 \f
688 ;;; Handle `@raisesections' and `@lowersections' commands
689
690 ;; These commands change the hierarchical level of chapter structuring
691 ;; commands.
692 ;;
693 ;; @raisesections changes @subsection to @section,
694 ;; @section to @chapter,
695 ;; etc.
696 ;;
697 ;; @lowersections changes @chapter to @section
698 ;; @subsection to @subsubsection,
699 ;; etc.
700 ;;
701 ;; An @raisesections/@lowersections command changes only those
702 ;; structuring commands that follow the @raisesections/@lowersections
703 ;; command.
704 ;;
705 ;; Repeated @raisesections/@lowersections continue to raise or lower
706 ;; the heading level.
707 ;;
708 ;; An @lowersections command cancels an @raisesections command, and
709 ;; vice versa.
710 ;;
711 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
712 ;; trying to do so does not elicit an error---you just get more
713 ;; headings that mean the same thing as you keep raising or lowering
714 ;; (for example, after a single @raisesections, both @chapter and
715 ;; @section produce chapter headings).
716
717 (defun texinfo-raise-lower-sections ()
718 "Raise or lower the hierarchical level of chapters, sections, etc.
719
720 This function acts according to `@raisesections' and `@lowersections'
721 commands in the Texinfo file.
722
723 For example, an `@lowersections' command is useful if you wish to
724 include what is written as an outer or standalone Texinfo file in
725 another Texinfo file as an inner, included file. The `@lowersections'
726 command changes chapters to sections, sections to subsections and so
727 on.
728
729 @raisesections changes @subsection to @section,
730 @section to @chapter,
731 @heading to @chapheading,
732 etc.
733
734 @lowersections changes @chapter to @section,
735 @subsection to @subsubsection,
736 @heading to @subheading,
737 etc.
738
739 An `@raisesections' or `@lowersections' command changes only those
740 structuring commands that follow the `@raisesections' or
741 `@lowersections' command.
742
743 An `@lowersections' command cancels an `@raisesections' command, and
744 vice versa.
745
746 Repeated use of the commands continue to raise or lower the hierarchical
747 level a step at a time.
748
749 An attempt to raise above `chapters' reproduces chapter commands; an
750 attempt to lower below subsubsections reproduces subsubsection
751 commands."
752
753 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
754 ;; it is a regexp matching chapter, section, other headings
755 ;; (but not the top node).
756
757 (let (type (level 0))
758 (while
759 (re-search-forward
760 (concat
761 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
762 texinfo-section-types-regexp
763 "\\)\\)")
764 nil t)
765 (beginning-of-line)
766 (save-excursion (setq type (read (current-buffer))))
767 (cond
768
769 ;; 1. Increment level
770 ((eq type '@raisesections)
771 (setq level (1+ level))
772 (delete-region
773 (point) (line-beginning-position 2)))
774
775 ;; 2. Decrement level
776 ((eq type '@lowersections)
777 (setq level (1- level))
778 (delete-region
779 (point) (line-beginning-position 2)))
780
781 ;; Now handle structuring commands
782 ((cond
783
784 ;; 3. Raise level when positive
785 ((> level 0)
786 (let ((count level)
787 (new-level type))
788 (while (> count 0)
789 (setq new-level
790 (cdr (assq new-level texinfo-raisesections-alist)))
791 (setq count (1- count)))
792 (kill-word 1)
793 (insert (symbol-name new-level))))
794
795 ;; 4. Do nothing except move point when level is zero
796 ((= level 0) (forward-line 1))
797
798 ;; 5. Lower level when positive
799 ((< level 0)
800 (let ((count level)
801 (new-level type))
802 (while (< count 0)
803 (setq new-level
804 (cdr (assq new-level texinfo-lowersections-alist)))
805 (setq count (1+ count)))
806 (kill-word 1)
807 (insert (symbol-name new-level))))))))))
808 \f
809 ;;; Perform those texinfo-to-info conversions that apply to the whole input
810 ;;; uniformly.
811
812 (defun texinfo-format-scan ()
813 (texinfo-format-convert (point-min) (point-max))
814 ;; Search for @copying, which has to be first since the
815 ;; @insertcopying command then inserts the text elsewhere.
816 (goto-char (point-min))
817 (when (search-forward "@copying" nil t)
818 (texinfo-copying))
819 (while (search-forward "@insertcopying" nil t)
820 (delete-region (match-beginning 0) (match-end 0))
821
822 (texinfo-insertcopying))
823 ;; Scan for other @-commands.
824 (goto-char (point-min))
825 (while (search-forward "@" nil t)
826 ;;
827 ;; These are the single-character accent commands: @^ @` @' @" @= @~
828 ;; In Info, they are simply quoted and the @ deleted.
829 ;; Other single-character commands:
830 ;; @* forces a line break,
831 ;; @- is a discretionary hyphenation point; does nothing in Info.
832 ;; @<space>, @<tab>, @<newline> each produce a single space,
833 ;; unless followed by a newline.
834 ;;
835 ;; Old version 2.34 expression: (looking-at "[@{}^'` *\"?!]")
836 (if (looking-at "[@{}^'`\"=~ \t\n*?!-]")
837 ;; @*, causes a line break.
838 (cond
839 ;; @*, a line break
840 ((= (following-char) ?*)
841 ;; remove command
842 (delete-region (1- (point)) (1+ (point)))
843 ;; insert return if not at end of line;
844 ;; else line is already broken.
845 (if (not (= (following-char) ?\n))
846 (insert ?\n)))
847 ;; @-, deleted
848 ((= (following-char) ?-)
849 (delete-region (1- (point)) (1+ (point))))
850 ;; @<space>, @<tab>, @<newline>: produce a single space,
851 ;; unless followed by a newline.
852 ((= (following-char) ? )
853 (delete-region (1- (point)) (1+ (point)))
854 ;; insert single space if not at end of line;
855 ;; else line is already broken.
856 (if (not (= (following-char) ?\n))
857 (insert ? )))
858 ((= (following-char) ?\t)
859 (delete-region (1- (point)) (1+ (point)))
860 ;; insert single space if not at end of line;
861 ;; else line is already broken.
862 (if (not (= (following-char) ?\n))
863 (insert ? )))
864 ;; following char is a carriage return
865 ((= (following-char) ?\n)
866 ;; remove command
867 (delete-region (1- (point)) (1+ (point)))
868 ;; insert single space if not at end of line;
869 ;; else line is already broken.
870 (if (not (= (following-char) ?\n))
871 (insert ? )))
872 ;; Otherwise: the other characters are simply quoted. Delete the @.
873 (t
874 (delete-char -1)
875 ;; Be compatible with makeinfo: if @' and its ilk are
876 ;; followed by a @ without a brace, barf.
877 (if (looking-at "[\"'^`~=]")
878 (progn
879 (if (= (char-after (1+ (point))) ?@)
880 (error "Use braces to give a command as an argument to @%c"
881 (following-char)))
882 (forward-char 1)
883 ;; @' etc. can optionally accept their argument in
884 ;; braces (makeinfo supports that).
885 (when (looking-at "{")
886 (let ((start (point)))
887 (forward-list 1)
888 (delete-char -1)
889 (goto-char start)
890 (delete-char 1))))
891 (forward-char 1))))
892 ;; @ is followed by a command-word; find the end of the word.
893 (setq texinfo-command-start (1- (point)))
894 (if (= (char-syntax (following-char)) ?w)
895 (forward-word 1)
896 (forward-char 1))
897 (setq texinfo-command-end (point))
898 ;; Detect the case of two @-commands in a row;
899 ;; process just the first one.
900 (goto-char (1+ texinfo-command-start))
901 (skip-chars-forward "^@" texinfo-command-end)
902 (setq texinfo-command-end (point))
903 ;; Handle let aliasing
904 (setq texinfo-command-name
905 (let (trial
906 (cmdname
907 (buffer-substring-no-properties
908 (1+ texinfo-command-start) texinfo-command-end)))
909 (while (setq trial (assoc cmdname texinfo-alias-list))
910 (setq cmdname (cdr trial)))
911 (intern cmdname)))
912 ;; Call the handler for this command.
913 (let ((enclosure-type
914 (assoc
915 (symbol-name texinfo-command-name)
916 texinfo-enclosure-list)))
917 (if enclosure-type
918 (progn
919 (insert
920 (car (car (cdr enclosure-type)))
921 (texinfo-parse-arg-discard)
922 (car (cdr (car (cdr enclosure-type)))))
923 (goto-char texinfo-command-start))
924 (let ((cmd (get texinfo-command-name 'texinfo-format)))
925 (if cmd (funcall cmd) (texinfo-unsupported)))))))
926
927 (cond (texinfo-stack
928 (goto-char (nth 2 (car texinfo-stack)))
929 (error "Unterminated @%s" (car (car texinfo-stack)))))
930
931 ;; Remove excess whitespace
932 (let ((whitespace-silent t))
933 (whitespace-cleanup)))
934
935 (defvar texinfo-copying-text ""
936 "Text of the copyright notice and copying permissions.")
937
938 (defun texinfo-copying ()
939 "Copy the copyright notice and copying permissions from the Texinfo file,
940 as indicated by the @copying ... @end copying command;
941 insert the text with the @insertcopying command."
942 (let ((beg (progn (beginning-of-line) (point)))
943 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
944 (setq texinfo-copying-text
945 (buffer-substring-no-properties
946 (save-excursion (goto-char beg) (line-beginning-position 2))
947 (save-excursion (goto-char end) (line-beginning-position 0))))
948 (delete-region beg end)))
949
950 (defun texinfo-insertcopying ()
951 "Insert the copyright notice and copying permissions from the Texinfo file,
952 which are indicated by the @copying ... @end copying command."
953 (insert (concat "\n" texinfo-copying-text)))
954
955 (put 'begin 'texinfo-format 'texinfo-format-begin)
956 (defun texinfo-format-begin ()
957 (texinfo-format-begin-end 'texinfo-format))
958
959 (put 'end 'texinfo-format 'texinfo-format-end)
960 (defun texinfo-format-end ()
961 (texinfo-format-begin-end 'texinfo-end))
962
963 (defun texinfo-format-begin-end (prop)
964 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
965 (let ((cmd (get texinfo-command-name prop)))
966 (if cmd (funcall cmd)
967 (texinfo-unsupported))))
968 \f
969 ;;; Parsing functions
970
971 (defun texinfo-parse-line-arg ()
972 "Return argument of @-command as string.
973 Argument is separated from command either by a space or by a brace.
974 If a space, return rest of line, with beginning and ending white
975 space removed. If a brace, return string between braces.
976 Leave point after argument."
977 (goto-char texinfo-command-end)
978 (let ((start (point)))
979 (cond ((looking-at " ")
980 (skip-chars-forward " ")
981 (setq start (point))
982 (end-of-line)
983 (skip-chars-backward " ")
984 (delete-region (point) (progn (end-of-line) (point)))
985 (setq texinfo-command-end (1+ (point))))
986 ((looking-at "{")
987 (setq start (1+ (point)))
988 (forward-list 1)
989 (setq texinfo-command-end (point))
990 (forward-char -1))
991 (t
992 (error "Invalid texinfo command arg format")))
993 (prog1 (buffer-substring-no-properties start (point))
994 (if (eolp) (forward-char 1)))))
995
996 (defun texinfo-parse-expanded-arg ()
997 (goto-char texinfo-command-end)
998 (let ((start (point))
999 marker)
1000 (cond ((looking-at " ")
1001 (skip-chars-forward " ")
1002 (setq start (point))
1003 (end-of-line)
1004 (setq texinfo-command-end (1+ (point))))
1005 ((looking-at "{")
1006 (setq start (1+ (point)))
1007 (forward-list 1)
1008 (setq texinfo-command-end (point))
1009 (forward-char -1))
1010 (t
1011 (error "Invalid texinfo command arg format")))
1012 (setq marker (move-marker (make-marker) texinfo-command-end))
1013 (texinfo-format-expand-region start (point))
1014 (setq texinfo-command-end (marker-position marker))
1015 (move-marker marker nil)
1016 (prog1 (buffer-substring-no-properties start (point))
1017 (if (eolp) (forward-char 1)))))
1018
1019 (defun texinfo-format-expand-region (start end)
1020 (save-restriction
1021 (narrow-to-region start end)
1022 (let (texinfo-command-start
1023 texinfo-command-end
1024 texinfo-command-name
1025 texinfo-stack)
1026 (texinfo-format-scan))
1027 (goto-char (point-max))))
1028
1029 (defun texinfo-parse-arg-discard ()
1030 "Delete command and argument; return argument of command."
1031 (prog1 (texinfo-parse-line-arg)
1032 (texinfo-discard-command)))
1033
1034 (defun texinfo-discard-command ()
1035 (delete-region texinfo-command-start texinfo-command-end))
1036
1037 (defun texinfo-optional-braces-discard ()
1038 "Discard braces following command, if any."
1039 (goto-char texinfo-command-end)
1040 (let ((start (point)))
1041 (cond ((looking-at "[ \t]*\n")) ; do nothing
1042 ((looking-at "{") ; remove braces, if any
1043 (forward-list 1)
1044 (setq texinfo-command-end (point)))
1045 (t
1046 (error
1047 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
1048 (delete-region texinfo-command-start texinfo-command-end)))
1049
1050 (defun texinfo-format-parse-line-args ()
1051 (let ((start (1- (point)))
1052 next beg end
1053 args)
1054 (skip-chars-forward " ")
1055 (while (not (eolp))
1056 (setq beg (point))
1057 (re-search-forward "[\n,]")
1058 (setq next (point))
1059 (if (bolp) (setq next (1- next)))
1060 (forward-char -1)
1061 (skip-chars-backward " ")
1062 (setq end (point))
1063 (push (if (> end beg) (buffer-substring-no-properties beg end))
1064 args)
1065 (goto-char next)
1066 (skip-chars-forward " "))
1067 (if (eolp) (forward-char 1))
1068 (setq texinfo-command-end (point))
1069 (nreverse args)))
1070
1071 (defun texinfo-format-parse-args ()
1072 (let ((start (1- (point)))
1073 next beg end
1074 args)
1075 (search-forward "{")
1076 (save-excursion
1077 (texinfo-format-expand-region
1078 (point)
1079 (save-excursion (up-list 1) (1- (point)))))
1080 ;; The following does not handle cross references of the form:
1081 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
1082 ;; re-search-forward finds the first right brace after the second
1083 ;; comma.
1084 (while (/= (preceding-char) ?\})
1085 (skip-chars-forward " \t\n")
1086 (setq beg (point))
1087 (re-search-forward "[},]")
1088 (setq next (point))
1089 (forward-char -1)
1090 (skip-chars-backward " \t\n")
1091 (setq end (point))
1092 (cond ((< beg end)
1093 (goto-char beg)
1094 (while (search-forward "\n" end t)
1095 (replace-match " "))))
1096 (push (if (> end beg) (buffer-substring-no-properties beg end))
1097 args)
1098 (goto-char next))
1099 ;;(if (eolp) (forward-char 1))
1100 (setq texinfo-command-end (point))
1101 (nreverse args)))
1102
1103 (defun texinfo-format-parse-defun-args ()
1104 (goto-char texinfo-command-end)
1105 (let ((start (point)))
1106 (end-of-line)
1107 (setq texinfo-command-end (1+ (point)))
1108 (let ((marker (move-marker (make-marker) texinfo-command-end)))
1109 (texinfo-format-expand-region start (point))
1110 (setq texinfo-command-end (marker-position marker))
1111 (move-marker marker nil))
1112 (goto-char start)
1113 (let ((args '())
1114 beg end)
1115 (skip-chars-forward " ")
1116 (while (not (eolp))
1117 (cond ((looking-at "{")
1118 (setq beg (1+ (point)))
1119 (forward-list 1)
1120 (setq end (1- (point))))
1121 (t
1122 (setq beg (point))
1123 (re-search-forward "[\n ]")
1124 (forward-char -1)
1125 (setq end (point))))
1126 (push (buffer-substring-no-properties beg end) args)
1127 (skip-chars-forward " "))
1128 (forward-char 1)
1129 (nreverse args))))
1130
1131 (defun texinfo-discard-line ()
1132 (goto-char texinfo-command-end)
1133 (skip-chars-forward " \t")
1134 (or (eolp)
1135 (error "Extraneous text at end of command line"))
1136 (goto-char texinfo-command-start)
1137 (or (bolp)
1138 (error "Extraneous text at beginning of command line"))
1139 (delete-region (point) (progn (forward-line 1) (point))))
1140
1141 (defun texinfo-discard-line-with-args ()
1142 (goto-char texinfo-command-start)
1143 (delete-region (point) (progn (forward-line 1) (point))))
1144
1145 \f
1146 ;;; @setfilename
1147
1148 ;; Only `texinfo-format-buffer' handles @setfilename with this
1149 ;; definition; `texinfo-format-region' handles @setfilename, if any,
1150 ;; specially.
1151 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
1152 (defun texinfo-format-setfilename ()
1153 (texinfo-parse-arg-discard))
1154 \f
1155 ;;; @node, @menu, @detailmenu
1156
1157 (put 'node 'texinfo-format 'texinfo-format-node)
1158 (put 'nwnode 'texinfo-format 'texinfo-format-node)
1159 (defun texinfo-format-node ()
1160 (let* ((args (texinfo-format-parse-line-args))
1161 (name (nth 0 args))
1162 (next (nth 1 args))
1163 (prev (nth 2 args))
1164 (up (nth 3 args)))
1165 (texinfo-discard-command)
1166 (setq texinfo-last-node name)
1167 (let ((tem (if texinfo-fold-nodename-case (downcase name) name)))
1168 (if (assoc tem texinfo-node-names)
1169 (error "Duplicate node name: %s" name)
1170 (push (list tem) texinfo-node-names)))
1171 (setq texinfo-footnote-number 0)
1172 ;; insert "\n\^_" unconditionally since this is what info is looking for
1173 (insert "\n\^_\nFile: " texinfo-format-filename
1174 ", Node: " name)
1175 (if next
1176 (insert ", Next: " next))
1177 (if prev
1178 (insert ", Prev: " prev))
1179 (if up
1180 (insert ", Up: " up))
1181 (insert ?\n)
1182 (setq texinfo-last-node-pos (point))))
1183
1184 (put 'anchor 'texinfo-format 'texinfo-anchor)
1185 (defun texinfo-anchor ()
1186 (let (anchor-string
1187 (here (- (point) 7)) ; save location of beginning of `@anchor'
1188 (arg (texinfo-parse-arg-discard)))
1189 (if (looking-at " ") ; since a space may be left after -discard
1190 (delete-char 1))
1191 (forward-paragraph)
1192 (let ((end (point)))
1193 (if (save-excursion
1194 (backward-word 1)
1195 (search-forward "@refill" end t))
1196 (setq anchor-string "@anchor-yes-refill")
1197 (setq anchor-string "@anchor-no-refill")))
1198 (goto-char here)
1199 (insert anchor-string "{" arg "}")))
1200
1201 (put 'menu 'texinfo-format 'texinfo-format-menu)
1202 (defun texinfo-format-menu ()
1203 (texinfo-discard-line)
1204 (insert "* Menu:\n\n"))
1205
1206 (put 'menu 'texinfo-end 'texinfo-discard-command)
1207
1208 ;; The @detailmenu should be removed eventually.
1209
1210 ;; According to Karl Berry, 31 August 1996:
1211 ;;
1212 ;; You don't like, I don't like it. I agree, it would be better just to
1213 ;; fix the bug [in `makeinfo']. .. At this point, since inserting those
1214 ;; two commands in the Elisp fn is trivial, I don't especially want to
1215 ;; expend more effort...
1216 ;;
1217 ;; I added a couple sentences of documentation to the manual (putting the
1218 ;; blame on makeinfo where it belongs :-().
1219
1220 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
1221 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
1222
1223 ;; (Also see `texnfo-upd.el')
1224
1225 \f
1226 ;;; Cross references
1227
1228 ;; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
1229 ;; -> *Note FNAME: (FILE)NODE
1230 ;; If FILE is missing,
1231 ;; *Note FNAME: NODE
1232 ;; If FNAME is empty and NAME is present
1233 ;; *Note NAME: Node
1234 ;; If both NAME and FNAME are missing
1235 ;; *Note NODE::
1236 ;; texinfo ignores the DOCUMENT argument.
1237 ;; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1238 ;; If FILE is specified, (FILE)NODE is used for xrefs.
1239 ;; If fifth argument DOCUMENT is specified, produces
1240 ;; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1241 ;; of DOCUMENT
1242
1243 ;; @ref a reference that does not put `See' or `see' in
1244 ;; the hardcopy and is the same as @xref in Info
1245 (put 'ref 'texinfo-format 'texinfo-format-xref)
1246
1247 (put 'xref 'texinfo-format 'texinfo-format-xref)
1248 (defun texinfo-format-xref ()
1249 (let ((args (texinfo-format-parse-args)))
1250 (texinfo-discard-command)
1251 (insert "*Note ")
1252 (let ((fname (or (nth 1 args) (nth 2 args))))
1253 (if (null (or fname (nth 3 args)))
1254 (insert (car args) "::")
1255 (insert (or fname (car args)) ": ")
1256 (if (nth 3 args)
1257 (insert "(" (nth 3 args) ")"))
1258 (and (car args) (insert (car args)))))))
1259
1260 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
1261 (defun texinfo-format-pxref ()
1262 (texinfo-format-xref)
1263 (or (save-excursion
1264 (forward-char -2)
1265 (looking-at "::"))
1266 (insert ".")))
1267
1268 ;; @inforef{NODE, FNAME, FILE}
1269 ;; Like @xref{NODE, FNAME,,FILE} in texinfo.
1270 ;; In Tex, generates "See Info file FILE, node NODE"
1271 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
1272 (defun texinfo-format-inforef ()
1273 (let ((args (texinfo-format-parse-args)))
1274 (texinfo-discard-command)
1275 (if (nth 1 args)
1276 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
1277 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
1278
1279 \f
1280 ;;; URL Reference: @uref
1281
1282 ;; @uref produces a reference to a uniform resource locator (URL).
1283 ;; It takes one mandatory argument, the URL, and one optional argument,
1284 ;; the text to display (the default is the URL itself).
1285
1286 (put 'uref 'texinfo-format 'texinfo-format-uref)
1287 (defun texinfo-format-uref ()
1288 "Format URL and optional URL-TITLE.
1289 Insert ` ... ' around URL if no URL-TITLE argument;
1290 otherwise, insert URL-TITLE followed by URL in parentheses."
1291 (let ((args (texinfo-format-parse-args)))
1292 (texinfo-discard-command)
1293 ;; if url-title
1294 (if (nth 1 args)
1295 (insert (nth 1 args) " (" (nth 0 args) ")")
1296 (insert "`" (nth 0 args) "'"))
1297 (goto-char texinfo-command-start)))
1298
1299 \f
1300 ;;; Section headings
1301
1302 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
1303 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
1304 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
1305 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
1306 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1307 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1308 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1309 (put 'top 'texinfo-format 'texinfo-format-chapter)
1310 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1311 (put 'centerchap 'texinfo-format 'texinfo-format-chapter)
1312 (defun texinfo-format-chapter ()
1313 (texinfo-format-chapter-1 ?*))
1314
1315 (put 'heading 'texinfo-format 'texinfo-format-section)
1316 (put 'isection 'texinfo-format 'texinfo-format-section)
1317 (put 'section 'texinfo-format 'texinfo-format-section)
1318 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1319 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1320 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1321 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1322 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1323 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1324 (defun texinfo-format-section ()
1325 (texinfo-format-chapter-1 ?=))
1326
1327 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1328 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1329 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1330 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1331 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1332 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1333 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1334 (defun texinfo-format-subsection ()
1335 (texinfo-format-chapter-1 ?-))
1336
1337 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1338 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1339 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1340 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1341 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1342 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1343 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1344 (defun texinfo-format-subsubsection ()
1345 (texinfo-format-chapter-1 ?.))
1346
1347 (defun texinfo-format-chapter-1 (belowchar)
1348 (let ((arg (texinfo-parse-arg-discard)))
1349 (message "Formatting: %s ... " arg) ; So we can see where we are.
1350 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1351 (forward-line -2)))
1352
1353 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1354 (defun texinfo-format-sectionpad ()
1355 (let ((str (texinfo-parse-arg-discard)))
1356 (forward-char -1)
1357 (let ((column (current-column)))
1358 (forward-char 1)
1359 (while (> column 0)
1360 (insert str)
1361 (setq column (1- column))))
1362 (insert ?\n)))
1363
1364 \f
1365 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1366
1367 (put '\. 'texinfo-format 'texinfo-format-\.)
1368 (defun texinfo-format-\. ()
1369 (texinfo-discard-command)
1370 (insert "."))
1371
1372 (put '\: 'texinfo-format 'texinfo-format-\:)
1373 (defun texinfo-format-\: ()
1374 (texinfo-discard-command))
1375
1376 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
1377 (defun texinfo-format-soft-hyphen ()
1378 (texinfo-discard-command))
1379
1380 \f
1381 ;;; @kbdinputstyle, @vskip, headings & footings
1382 ;; These commands for not for Info and should never
1383 ;; appear in an Info environment; but if they do,
1384 ;; this causes them to be discarded.
1385
1386 ;; @kbdinputstyle
1387 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
1388
1389 ;; @vskip
1390 (put 'vskip 'texinfo-format 'texinfo-discard-line-with-args)
1391
1392 ;; headings & footings
1393 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
1394 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
1395 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
1396 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
1397 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
1398 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
1399
1400 \f
1401 ;;; @documentdescription ... @end documentdescription
1402 ;; This command is for HTML output and should never
1403 ;; appear in an Info environment; but if it does,
1404 ;; this causes it to be discarded.
1405
1406 (put 'documentdescription 'texinfo-format 'texinfo-format-documentdescription)
1407 (defun texinfo-format-documentdescription ()
1408 (delete-region texinfo-command-start
1409 (progn (re-search-forward "^@end documentdescription[ \t]*\n")
1410 (point))))
1411
1412
1413 \f
1414 ;;; @center, @sp, and @br
1415
1416 (put 'center 'texinfo-format 'texinfo-format-center)
1417 (defun texinfo-format-center ()
1418 (let ((arg (texinfo-parse-expanded-arg)))
1419 (texinfo-discard-command)
1420 (insert arg)
1421 (insert ?\n)
1422 (save-restriction
1423 (goto-char (1- (point)))
1424 (let ((indent-tabs-mode nil))
1425 (center-line)))))
1426
1427 (put 'sp 'texinfo-format 'texinfo-format-sp)
1428 (defun texinfo-format-sp ()
1429 (let* ((arg (texinfo-parse-arg-discard))
1430 (num (read arg)))
1431 (insert-char ?\n num)))
1432
1433 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1434 (defun texinfo-format-paragraph-break ()
1435 "Force a paragraph break.
1436 If used within a line, follow `@br' with braces."
1437 (texinfo-optional-braces-discard)
1438 ;; insert one return if at end of line;
1439 ;; else insert two returns, to generate a blank line.
1440 (if (= (following-char) ?\n)
1441 (insert ?\n)
1442 (insert-char ?\n 2)))
1443
1444 \f
1445 ;;; @footnote and @footnotestyle
1446
1447 ;; In Texinfo, footnotes are created with the `@footnote' command.
1448 ;; This command is followed immediately by a left brace, then by the text of
1449 ;; the footnote, and then by a terminating right brace. The
1450 ;; template for a footnote is:
1451 ;;
1452 ;; @footnote{TEXT}
1453 ;;
1454 ;; Info has two footnote styles:
1455 ;;
1456 ;; * In the End of node style, all the footnotes for a single node
1457 ;; are placed at the end of that node. The footnotes are
1458 ;; separated from the rest of the node by a line of dashes with
1459 ;; the word `Footnotes' within it.
1460 ;;
1461 ;; * In the Separate node style, all the footnotes for a single node
1462 ;; are placed in an automatically constructed node of their own.
1463
1464 ;; Footnote style is specified by the @footnotestyle command, either
1465 ;; @footnotestyle separate
1466 ;; or
1467 ;; @footnotestyle end
1468 ;;
1469 ;; The default is separate
1470
1471 (defvar texinfo-footnote-style "separate"
1472 "Footnote style, either separate or end.")
1473
1474 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1475 (defun texinfo-footnotestyle ()
1476 "Specify whether footnotes are at end of node or in separate nodes.
1477 Argument is either end or separate."
1478 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1479
1480 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1481 (defun texinfo-format-footnote ()
1482 "Format a footnote in either end of node or separate node style.
1483 The texinfo-footnote-style variable controls which style is used."
1484 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1485 (cond ((string= texinfo-footnote-style "end")
1486 (texinfo-format-end-node))
1487 ((string= texinfo-footnote-style "separate")
1488 (texinfo-format-separate-node))))
1489
1490 (defun texinfo-format-separate-node ()
1491 "Format footnote in Separate node style, with notes in own node.
1492 The node is constructed automatically."
1493 (let* (start
1494 (arg (texinfo-parse-line-arg))
1495 (node-name-beginning
1496 (save-excursion
1497 (re-search-backward
1498 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1499 (match-end 0)))
1500 (node-name
1501 (save-excursion
1502 (buffer-substring-no-properties
1503 (progn (goto-char node-name-beginning) ; skip over node command
1504 (skip-chars-forward " \t") ; and over spaces
1505 (point))
1506 (if (search-forward "," (line-end-position) t) ; bound search
1507 (1- (point))
1508 (end-of-line) (point))))))
1509 (texinfo-discard-command) ; remove or insert whitespace, as needed
1510 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1511 (point))
1512 (insert (format " (%d) (*Note %s-Footnotes::)"
1513 texinfo-footnote-number node-name))
1514 (fill-paragraph nil)
1515 (save-excursion
1516 (if (re-search-forward "^@node" nil 'move)
1517 (forward-line -1))
1518
1519 ;; two cases: for the first footnote, we must insert a node header;
1520 ;; for the second and subsequent footnotes, we need only insert
1521 ;; the text of the footnote.
1522
1523 (if (save-excursion
1524 (search-backward
1525 (concat node-name "-Footnotes, Up: ")
1526 node-name-beginning
1527 t))
1528 (progn ; already at least one footnote
1529 (setq start (point))
1530 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1531 (fill-region start (point)))
1532 ;; else not yet a footnote
1533 (insert "\n\^_\nFile: " texinfo-format-filename
1534 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1535 (setq start (point))
1536 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1537 (narrow-to-region (save-excursion (goto-char start) (point)) (point))
1538 (fill-region (point-min) (point-max))
1539 (widen)))))
1540
1541 (defun texinfo-format-end-node ()
1542 "Format footnote in the End of node style, with notes at end of node."
1543 (let (start
1544 (arg (texinfo-parse-line-arg)))
1545 (texinfo-discard-command) ; remove or insert whitespace, as needed
1546 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1547 (point))
1548 (insert (format " (%d) " texinfo-footnote-number))
1549 (fill-paragraph nil)
1550 (save-excursion
1551 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1552 (progn ; already have footnote, put new one before end of node
1553 (if (re-search-forward "^@node" nil 'move)
1554 (forward-line -1))
1555 (setq start (point))
1556 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1557 (fill-region start (point)))
1558 ;; else no prior footnote
1559 (if (re-search-forward "^@node" nil 'move)
1560 (forward-line -1))
1561 (insert "\n--------- Footnotes ---------\n")
1562 (setq start (point))
1563 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1564
1565 \f
1566 ;;; @itemize, @enumerate, and similar commands
1567
1568 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1569 ;; @enumerate pushes (enumerate 0 STARTPOS).
1570 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1571 ;; For itemize, this puts in and rescans the COMMANDS.
1572 ;; For enumerate, this increments the number and puts it in.
1573 ;; In either case, it puts a Backspace at the front of the line
1574 ;; which marks it not to be indented later.
1575 ;; All other lines get indented by 5 when the @end is reached.
1576
1577 (defvar texinfo-stack-depth 0
1578 "Count of number of unpopped texinfo-push-stack calls.
1579 Used by @refill indenting command to avoid indenting within lists, etc.")
1580
1581 (defun texinfo-push-stack (check arg)
1582 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1583 (push (list check arg texinfo-command-start)
1584 texinfo-stack))
1585
1586 (defun texinfo-pop-stack (check)
1587 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1588 (if (null texinfo-stack)
1589 (error "Unmatched @end %s" check))
1590 (if (not (eq (car (car texinfo-stack)) check))
1591 (error "@end %s matches @%s"
1592 check (car (car texinfo-stack))))
1593 (prog1 (cdr (car texinfo-stack))
1594 (setq texinfo-stack (cdr texinfo-stack))))
1595
1596 (put 'itemize 'texinfo-format 'texinfo-itemize)
1597 (defun texinfo-itemize ()
1598 (texinfo-push-stack
1599 'itemize
1600 (progn (skip-chars-forward " \t")
1601 (if (eolp)
1602 "@bullet"
1603 (texinfo-parse-line-arg))))
1604 (texinfo-discard-line-with-args)
1605 (setq fill-column (- fill-column 5)))
1606
1607 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1608 (defun texinfo-end-itemize ()
1609 (setq fill-column (+ fill-column 5))
1610 (texinfo-discard-command)
1611 (let ((stacktop
1612 (texinfo-pop-stack 'itemize)))
1613 (texinfo-do-itemize (nth 1 stacktop))))
1614
1615 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1616 (defun texinfo-enumerate ()
1617 (texinfo-push-stack
1618 'enumerate
1619 (progn (skip-chars-forward " \t")
1620 (if (eolp)
1621 1
1622 (read (current-buffer)))))
1623 (if (and (symbolp (car (cdr (car texinfo-stack))))
1624 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1625 (error
1626 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1627 (texinfo-discard-line-with-args)
1628 (setq fill-column (- fill-column 5)))
1629
1630 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1631 (defun texinfo-end-enumerate ()
1632 (setq fill-column (+ fill-column 5))
1633 (texinfo-discard-command)
1634 (let ((stacktop
1635 (texinfo-pop-stack 'enumerate)))
1636 (texinfo-do-itemize (nth 1 stacktop))))
1637
1638 ;; @alphaenumerate never became a standard part of Texinfo
1639 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1640 (defun texinfo-alphaenumerate ()
1641 (texinfo-push-stack 'alphaenumerate (1- ?a))
1642 (setq fill-column (- fill-column 5))
1643 (texinfo-discard-line))
1644
1645 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1646 (defun texinfo-end-alphaenumerate ()
1647 (setq fill-column (+ fill-column 5))
1648 (texinfo-discard-command)
1649 (let ((stacktop
1650 (texinfo-pop-stack 'alphaenumerate)))
1651 (texinfo-do-itemize (nth 1 stacktop))))
1652
1653 ;; @capsenumerate never became a standard part of Texinfo
1654 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1655 (defun texinfo-capsenumerate ()
1656 (texinfo-push-stack 'capsenumerate (1- ?A))
1657 (setq fill-column (- fill-column 5))
1658 (texinfo-discard-line))
1659
1660 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1661 (defun texinfo-end-capsenumerate ()
1662 (setq fill-column (+ fill-column 5))
1663 (texinfo-discard-command)
1664 (let ((stacktop
1665 (texinfo-pop-stack 'capsenumerate)))
1666 (texinfo-do-itemize (nth 1 stacktop))))
1667
1668 ;; At the @end, indent all the lines within the construct
1669 ;; except those marked with backspace. FROM says where
1670 ;; construct started.
1671 (defun texinfo-do-itemize (from)
1672 (save-excursion
1673 (while (progn (forward-line -1)
1674 (>= (point) from))
1675 (if (= (following-char) ?\b)
1676 (save-excursion
1677 (delete-char 1)
1678 (end-of-line)
1679 (delete-char 6))
1680 (if (not (looking-at "[ \t]*$"))
1681 (save-excursion (insert " ")))))))
1682
1683 (put 'item 'texinfo-format 'texinfo-item)
1684 (put 'itemx 'texinfo-format 'texinfo-item)
1685 (defun texinfo-item ()
1686 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1687
1688 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1689 (defun texinfo-itemize-item ()
1690 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1691 (delete-region (1+ (point)) (line-beginning-position))
1692 (if (looking-at "[ \t]*[^ \t\n]+")
1693 ;; Text on same line as @item command.
1694 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1695 ;; Else text on next line.
1696 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1697 (forward-line -1))
1698
1699 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1700 (defun texinfo-enumerate-item ()
1701 (texinfo-discard-line)
1702 (let (enumerating-symbol)
1703 (cond ((integerp (car (cdr (car texinfo-stack))))
1704 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1705 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1706 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1707 ((symbolp (car (cdr (car texinfo-stack))))
1708 (setq enumerating-symbol
1709 (symbol-name (car (cdr (car texinfo-stack)))))
1710 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1711 (equal ?\{ (string-to-char enumerating-symbol)))
1712 (error
1713 "Too many items in enumerated list; alphabet ends at Z."))
1714 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1715 (setcar (cdr (car texinfo-stack))
1716 (make-symbol
1717 (char-to-string
1718 (1+
1719 (string-to-char enumerating-symbol))))))
1720 (t
1721 (error
1722 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1723 (forward-line -1)))
1724
1725 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1726 (defun texinfo-alphaenumerate-item ()
1727 (texinfo-discard-line)
1728 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1729 (if (> next ?z)
1730 (error "More than 26 items in @alphaenumerate; get a bigger alphabet"))
1731 (setcar (cdr (car texinfo-stack)) next)
1732 (insert "\b " next ". \n"))
1733 (forward-line -1))
1734
1735 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1736 (defun texinfo-capsenumerate-item ()
1737 (texinfo-discard-line)
1738 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1739 (if (> next ?Z)
1740 (error "More than 26 items in @capsenumerate; get a bigger alphabet"))
1741 (setcar (cdr (car texinfo-stack)) next)
1742 (insert "\b " next ". \n"))
1743 (forward-line -1))
1744
1745 \f
1746 ;;; @table
1747
1748 ;; The `@table' command produces two-column tables.
1749
1750 (put 'table 'texinfo-format 'texinfo-table)
1751 (defun texinfo-table ()
1752 (texinfo-push-stack
1753 'table
1754 (progn (skip-chars-forward " \t")
1755 (if (eolp)
1756 "@asis"
1757 (texinfo-parse-line-arg))))
1758 (texinfo-discard-line-with-args)
1759 (setq fill-column (- fill-column 5)))
1760
1761 (put 'table 'texinfo-item 'texinfo-table-item)
1762 (defun texinfo-table-item ()
1763 (let ((arg (texinfo-parse-arg-discard))
1764 (itemfont (car (cdr (car texinfo-stack)))))
1765 (insert ?\b itemfont ?\{ arg "}\n \n"))
1766 (forward-line -2))
1767
1768 (put 'table 'texinfo-end 'texinfo-end-table)
1769 (defun texinfo-end-table ()
1770 (setq fill-column (+ fill-column 5))
1771 (texinfo-discard-command)
1772 (let ((stacktop
1773 (texinfo-pop-stack 'table)))
1774 (texinfo-do-itemize (nth 1 stacktop))))
1775
1776 ;; @description appears to be an undocumented variant on @table that
1777 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1778 ;; part of makeinfo.c The command appears to be a relic of the past.
1779 (put 'description 'texinfo-end 'texinfo-end-table)
1780 (put 'description 'texinfo-format 'texinfo-description)
1781 (defun texinfo-description ()
1782 (texinfo-push-stack 'table "@asis")
1783 (setq fill-column (- fill-column 5))
1784 (texinfo-discard-line))
1785
1786 \f
1787 ;;; @ftable, @vtable
1788
1789 ;; The `@ftable' and `@vtable' commands are like the `@table' command
1790 ;; but they also insert each entry in the first column of the table
1791 ;; into the function or variable index.
1792
1793 ;; Handle the @ftable and @vtable commands:
1794
1795 (put 'ftable 'texinfo-format 'texinfo-ftable)
1796 (put 'vtable 'texinfo-format 'texinfo-vtable)
1797
1798 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1799 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1800
1801 (defun texinfo-indextable (table-type)
1802 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1803 (setq fill-column (- fill-column 5)))
1804
1805 ;; Handle the @item commands within ftable and vtable:
1806
1807 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1808 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1809
1810 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1811 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1812
1813 (defun texinfo-indextable-item (index-type)
1814 (let ((item (texinfo-parse-arg-discard))
1815 (itemfont (car (cdr (car texinfo-stack))))
1816 (indexvar index-type))
1817 (insert ?\b itemfont ?\{ item "}\n \n")
1818 (set indexvar
1819 (cons
1820 (list item texinfo-last-node)
1821 (symbol-value indexvar)))
1822 (forward-line -2)))
1823
1824 ;; Handle @end ftable, @end vtable
1825
1826 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1827 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1828
1829 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1830 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1831
1832 (defun texinfo-end-indextable (table-type)
1833 (setq fill-column (+ fill-column 5))
1834 (texinfo-discard-command)
1835 (let ((stacktop
1836 (texinfo-pop-stack table-type)))
1837 (texinfo-do-itemize (nth 1 stacktop))))
1838
1839 \f
1840 ;;; @multitable ... @end multitable
1841
1842 ;; Produce a multi-column table, with as many columns as desired.
1843 ;;
1844 ;; A multi-column table has this template:
1845 ;;
1846 ;; @multitable {A1} {A2} {A3}
1847 ;; @item A1 @tab A2 @tab A3
1848 ;; @item B1 @tab B2 @tab B3
1849 ;; @item C1 @tab C2 @tab C3
1850 ;; @end multitable
1851 ;;
1852 ;; where the width of the text in brackets specifies the width of the
1853 ;; respective column.
1854 ;;
1855 ;; Or else:
1856 ;;
1857 ;; @multitable @columnfractions .25 .3 .45
1858 ;; @item A1 @tab A2 @tab A3
1859 ;; @item B1 @tab B2 @tab B3
1860 ;; @end multitable
1861 ;;
1862 ;; where the fractions specify the width of each column as a percent
1863 ;; of the current width of the text (i.e., of the fill-column).
1864 ;;
1865 ;; Long lines of text are filled within columns.
1866 ;;
1867 ;; Using the Emacs Lisp formatter, texinfmt.el,
1868 ;; the whitespace between columns can be increased by setting
1869 ;; `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1870 ;; there is at least one blank space between columns.
1871 ;;
1872 ;; The Emacs Lisp formatter, texinfmt.el, ignores the following four
1873 ;; commands that are defined in texinfo.tex for printed output.
1874 ;;
1875 ;; @multitableparskip,
1876 ;; @multitableparindent,
1877 ;; @multitablecolmargin,
1878 ;; @multitablelinespace.
1879
1880 ;; How @multitable works.
1881 ;; =====================
1882 ;;
1883 ;; `texinfo-multitable' reads the @multitable line and determines from it
1884 ;; how wide each column should be.
1885 ;;
1886 ;; Also, it pushes this information, along with an identifying symbol,
1887 ;; onto the `texinfo-stack'. At the @end multitable command, the stack
1888 ;; is checked for its matching @multitable command, and then popped, or
1889 ;; else an error is signaled. Also, this command pushes the location of
1890 ;; the start of the table onto the stack.
1891 ;;
1892 ;; `texinfo-end-multitable' checks the `texinfo-stack' that the @end
1893 ;; multitable truly is ending a corresponding beginning, and if it is,
1894 ;; pops the stack.
1895 ;;
1896 ;; `texinfo-multitable-widths' is called by `texinfo-multitable'.
1897 ;; The function returns a list of the widths of each column in a
1898 ;; multi-column table, based on the information supplied by the arguments
1899 ;; to the @multitable command (by arguments, I mean the text on the rest
1900 ;; of the @multitable line, not the remainder of the multi-column table
1901 ;; environment).
1902 ;;
1903 ;; `texinfo-multitable-item' formats a row within a multicolumn table.
1904 ;; This command is executed when texinfmt sees @item inside @multitable.
1905 ;; Cells in row are separated by `@tab's. Widths of cells are specified
1906 ;; by the arguments in the @multitable line. Cells are filled. All cells
1907 ;; are made to be the same height by padding their bottoms, as needed,
1908 ;; with blanks.
1909 ;;
1910 ;; `texinfo-multitable-extract-row' is called by `texinfo-multitable-item'.
1911 ;; This function returns the text in a multitable row, as a string.
1912 ;; The start of a row is marked by an @item and the end of row is the
1913 ;; beginning of next @item or beginning of the @end multitable line.
1914 ;; Cells within a row are separated by @tab.
1915 ;;
1916 ;; Note that @tab, the cell separators, are not treated as independent
1917 ;; Texinfo commands.
1918
1919 (defvar texinfo-extra-inter-column-width 0
1920 "*Number of extra spaces between entries (columns) in @multitable.")
1921
1922 (defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
1923 (defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
1924
1925 ;; These commands are defined in texinfo.tex for printed output.
1926 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
1927 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
1928 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
1929 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
1930
1931 (put 'multitable 'texinfo-format 'texinfo-multitable)
1932
1933 (defun texinfo-multitable ()
1934 "Produce multi-column tables.
1935
1936 A multi-column table has this template:
1937
1938 @multitable {A1} {A2} {A3}
1939 @item A1 @tab A2 @tab A3
1940 @item B1 @tab B2 @tab B3
1941 @item C1 @tab C2 @tab C3
1942 @end multitable
1943
1944 where the width of the text in brackets specifies the width of the
1945 respective column.
1946
1947 Or else:
1948
1949 @multitable @columnfractions .25 .3 .45
1950 @item A1 @tab A2 @tab A3
1951 @item B1 @tab B2 @tab B3
1952 @end multitable
1953
1954 where the fractions specify the width of each column as a percent
1955 of the current width of the text (i.e., of the `fill-column').
1956
1957 Long lines of text are filled within columns.
1958
1959 Using the Emacs Lisp formatter, texinfmt.el,
1960 the whitespace between columns can be increased by setting
1961 `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1962 there is at least one blank space between columns.
1963
1964 The Emacs Lisp formatter, texinfmt.el, ignores the following four
1965 commands that are defined in texinfo.tex for printed output.
1966
1967 @multitableparskip,
1968 @multitableparindent,
1969 @multitablecolmargin,
1970 @multitablelinespace."
1971
1972 ;; This function pushes information onto the `texinfo-stack'.
1973 ;; A stack element consists of:
1974 ;; - type-of-command, i.e., multitable
1975 ;; - the information about column widths, and
1976 ;; - the position of texinfo-command-start.
1977 ;; e.g., ('multitable (1 2 3 4) 123)
1978 ;; The command line is then deleted.
1979 (texinfo-push-stack
1980 'multitable
1981 ;; push width information on stack
1982 (texinfo-multitable-widths))
1983 (texinfo-discard-line-with-args))
1984
1985 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
1986 (defun texinfo-end-multitable ()
1987 "Discard the @end multitable line and pop the stack of multitable."
1988 (texinfo-discard-command)
1989 (texinfo-pop-stack 'multitable))
1990
1991 (defun texinfo-multitable-widths ()
1992 "Return list of widths of each column in a multi-column table."
1993 (let (texinfo-multitable-width-list)
1994 ;; Fractions format:
1995 ;; @multitable @columnfractions .25 .3 .45
1996 ;;
1997 ;; Template format:
1998 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
1999 ;; Place point before first argument
2000 (skip-chars-forward " \t")
2001 (cond
2002 ;; Check for common misspelling
2003 ((looking-at "@columnfraction ")
2004 (error "In @multitable, @columnfractions misspelled"))
2005 ;; Case 1: @columnfractions .25 .3 .45
2006 ((looking-at "@columnfractions")
2007 (forward-word 1)
2008 (while (not (eolp))
2009 (push (truncate
2010 (1-
2011 (* fill-column (read (get-buffer (current-buffer))))))
2012 texinfo-multitable-width-list)))
2013 ;;
2014 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
2015 ((looking-at "{")
2016 (let ((start-of-templates (point)))
2017 (while (not (eolp))
2018 (skip-chars-forward " \t")
2019 (let* ((start-of-template (1+ (point)))
2020 (end-of-template
2021 ;; forward-sexp works with braces in Texinfo mode
2022 (progn (forward-sexp 1) (1- (point)))))
2023 (push (- end-of-template start-of-template)
2024 texinfo-multitable-width-list)
2025 ;; Remove carriage return from within a template, if any.
2026 ;; This helps those those who want to use more than
2027 ;; one line's worth of words in @multitable line.
2028 (narrow-to-region start-of-template end-of-template)
2029 (goto-char (point-min))
2030 (while (search-forward "
2031 " nil t)
2032 (delete-char -1))
2033 (goto-char (point-max))
2034 (widen)
2035 (forward-char 1)))))
2036 ;;
2037 ;; Case 3: Trouble
2038 (t
2039 (error
2040 "You probably need to specify column widths for @multitable correctly.")))
2041 ;; Check whether columns fit on page.
2042 (let ((desired-columns
2043 (+
2044 ;; between column spaces
2045 (length texinfo-multitable-width-list)
2046 ;; additional between column spaces, if any
2047 texinfo-extra-inter-column-width
2048 ;; sum of spaces for each entry
2049 (apply '+ texinfo-multitable-width-list))))
2050 (if (> desired-columns fill-column)
2051 (error
2052 "Multi-column table width, %d chars, is greater than page width, %d chars."
2053 desired-columns fill-column)))
2054 texinfo-multitable-width-list))
2055
2056 ;; @item A1 @tab A2 @tab A3
2057 (defun texinfo-multitable-extract-row ()
2058 "Return multitable row, as a string.
2059 End of row is beginning of next @item or beginning of @end.
2060 Cells within rows are separated by @tab."
2061 (skip-chars-forward " \t")
2062 (let* ((start (point))
2063 (end (progn
2064 (re-search-forward "@item\\|@end")
2065 (match-beginning 0)))
2066 (row (progn (goto-char end)
2067 (skip-chars-backward " ")
2068 ;; remove whitespace at end of argument
2069 (delete-region (point) end)
2070 (buffer-substring-no-properties start (point)))))
2071 (delete-region texinfo-command-start end)
2072 row))
2073
2074 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
2075 (defun texinfo-multitable-item ()
2076 "Format a row within a multicolumn table.
2077 Cells in row are separated by @tab.
2078 Widths of cells are specified by the arguments in the @multitable line.
2079 All cells are made to be the same height.
2080 This command is executed when texinfmt sees @item inside @multitable."
2081 (let ((original-buffer (current-buffer))
2082 (table-widths (reverse (car (cdr (car texinfo-stack)))))
2083 (existing-fill-column fill-column)
2084 start
2085 end
2086 (table-column 0)
2087 (table-entry-height 0)
2088 ;; unformatted row looks like: A1 @tab A2 @tab A3
2089 ;; extract-row command deletes the source line in the table.
2090 (unformated-row (texinfo-multitable-extract-row)))
2091 ;; Use a temporary buffer
2092 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
2093 (delete-region (point-min) (point-max))
2094 (insert unformated-row)
2095 (goto-char (point-min))
2096 ;; 1. Check for correct number of @tab in line.
2097 (let ((tab-number 1)) ; one @tab between two columns
2098 (while (search-forward "@tab" nil t)
2099 (setq tab-number (1+ tab-number)))
2100 (let ((needed-tabs (- (length table-widths) tab-number)))
2101 (when (> needed-tabs 0)
2102 (goto-char (point-min))
2103 (end-of-line)
2104 (while (> needed-tabs 0)
2105 (insert "@w{ }\n@tab")
2106 (setq needed-tabs (1- needed-tabs))
2107 (message
2108 "Added @tabs and empty spaces to a @multitable row")))))
2109 (goto-char (point-min))
2110 ;; 2. Format each cell, and copy to a rectangle
2111 ;; buffer looks like this: A1 @tab A2 @tab A3
2112 ;; Cell #1: format up to @tab
2113 ;; Cell #2: format up to @tab
2114 ;; Cell #3: format up to eob
2115 (while (not (eobp))
2116 (setq start (point))
2117 (setq end (save-excursion
2118 (if (search-forward "@tab" nil 'move)
2119 ;; Delete the @tab command, including the @-sign
2120 (delete-region
2121 (point)
2122 (progn (forward-word -1) (1- (point)))))
2123 (point)))
2124 ;; Set fill-column *wider* than needed to produce inter-column space
2125 (setq fill-column (+ 1
2126 texinfo-extra-inter-column-width
2127 (nth table-column table-widths)))
2128 (narrow-to-region start end)
2129 ;; Remove whitespace before and after entry.
2130 (skip-chars-forward " ")
2131 (delete-region (point) (line-beginning-position))
2132 (goto-char (point-max))
2133 (skip-chars-backward " ")
2134 (delete-region (point) (line-end-position))
2135 ;; Temporarily set texinfo-stack to nil so texinfo-format-scan
2136 ;; does not see an unterminated @multitable.
2137 (let (texinfo-stack) ; nil
2138 (texinfo-format-scan))
2139 (let (fill-prefix) ; no fill prefix
2140 (fill-region (point-min) (point-max)))
2141 (setq table-entry-height
2142 (max table-entry-height (count-lines (point-min) (point-max))))
2143 ;; 3. Move point to end of bottom line, and pad that line to fill column.
2144 (goto-char (point-min))
2145 (forward-line (1- table-entry-height))
2146 (let* ((beg (point)) ; beginning of line
2147 ;; add one more space for inter-column spacing
2148 (needed-whitespace
2149 (1+
2150 (- fill-column
2151 (-
2152 (progn (end-of-line) (point)) ; end of existing line
2153 beg)))))
2154 (insert (make-string
2155 (if (> needed-whitespace 0) needed-whitespace 1)
2156 ? )))
2157 ;; now, put formatted cell into a rectangle
2158 (set (intern (concat texinfo-multitable-rectangle-name
2159 (int-to-string table-column)))
2160 (extract-rectangle (point-min) (point)))
2161 (delete-region (point-min) (point))
2162 (goto-char (point-max))
2163 (setq table-column (1+ table-column))
2164 (widen))
2165 ;; 4. Add extra lines to rectangles so all are of same height
2166 (let ((total-number-of-columns table-column)
2167 (column-number 0)
2168 here)
2169 (while (> table-column 0)
2170 (let ((this-rectangle (int-to-string table-column)))
2171 (while (< (length this-rectangle) table-entry-height)
2172 (setq this-rectangle (append this-rectangle '("")))))
2173 (setq table-column (1- table-column)))
2174 ;; 5. Insert formatted rectangles in original buffer
2175 (switch-to-buffer original-buffer)
2176 (open-line table-entry-height)
2177 (while (< column-number total-number-of-columns)
2178 (setq here (point))
2179 (insert-rectangle
2180 (eval (intern
2181 (concat texinfo-multitable-rectangle-name
2182 (int-to-string column-number)))))
2183 (goto-char here)
2184 (end-of-line)
2185 (setq column-number (1+ column-number))))
2186 (kill-buffer texinfo-multitable-buffer-name)
2187 (setq fill-column existing-fill-column)))
2188
2189 \f
2190 ;;; @image
2191 ;; Use only the FILENAME argument to the command.
2192 ;; In Info, ignore the other arguments.
2193
2194 (put 'image 'texinfo-format 'texinfo-format-image)
2195 (defun texinfo-format-image ()
2196 "Insert an image from an an file ending in .txt.
2197 Use only the FILENAME arg; for Info, ignore the other arguments to @image."
2198 (let ((args (texinfo-format-parse-args))
2199 filename)
2200 (when (null (nth 0 args))
2201 (error "Invalid image command"))
2202 (texinfo-discard-command)
2203 ;; makeinfo uses FILENAME.txt
2204 (setq filename (format "%s.txt" (nth 0 args)))
2205 (message "Reading included file: %s" filename)
2206 ;; verbatim for Info output
2207 (goto-char (+ (point) (cadr (insert-file-contents filename))))
2208 (message "Reading included file: %s...done" filename)))
2209
2210 \f
2211 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html, @ifplaintext, @ifxml, @xml
2212 ;; @ifnottex, @ifnotinfo, @ifnothtml, @ifnotplaintext, @ifnotxml
2213
2214 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
2215 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
2216
2217 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
2218 (defun texinfo-format-iftex ()
2219 (delete-region texinfo-command-start
2220 (re-search-forward "@end iftex[ \t]*\n")))
2221
2222 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
2223 (defun texinfo-format-ifhtml ()
2224 (delete-region texinfo-command-start
2225 (re-search-forward "@end ifhtml[ \t]*\n")))
2226
2227 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
2228 (defun texinfo-format-ifplaintext ()
2229 (delete-region texinfo-command-start
2230 (re-search-forward "@end ifplaintext[ \t]*\n")))
2231
2232 (put 'ifxml 'texinfo-format 'texinfo-format-ifxml)
2233 (defun texinfo-format-ifxml ()
2234 (delete-region texinfo-command-start
2235 (progn (re-search-forward "^@end ifxml[ \t]*\n")
2236 (point))))
2237
2238 (put 'tex 'texinfo-format 'texinfo-format-tex)
2239 (defun texinfo-format-tex ()
2240 (delete-region texinfo-command-start
2241 (re-search-forward "@end tex[ \t]*\n")))
2242
2243 (put 'html 'texinfo-format 'texinfo-format-html)
2244 (defun texinfo-format-html ()
2245 (delete-region texinfo-command-start
2246 (re-search-forward "@end html[ \t]*\n")))
2247
2248 (put 'xml 'texinfo-format 'texinfo-format-xml)
2249 (defun texinfo-format-xml ()
2250 (delete-region texinfo-command-start
2251 (progn (re-search-forward "^@end xml[ \t]*\n")
2252 (point))))
2253
2254 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
2255 (defun texinfo-format-ifnotinfo ()
2256 (delete-region texinfo-command-start
2257 (re-search-forward "@end ifnotinfo[ \t]*\n")))
2258
2259 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
2260 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
2261
2262 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
2263 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
2264
2265 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
2266 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
2267
2268 (put 'ifnotxml 'texinfo-format 'texinfo-discard-line)
2269 (put 'ifnotxml 'texinfo-end 'texinfo-discard-command)
2270
2271 \f
2272 ;;; @titlepage
2273
2274 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
2275 (defun texinfo-format-titlepage ()
2276 (delete-region texinfo-command-start
2277 (re-search-forward "@end titlepage[ \t]*\n")))
2278
2279 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
2280
2281 ;; @titlespec an alternative titling command; ignored by Info
2282
2283 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
2284 (defun texinfo-format-titlespec ()
2285 (delete-region texinfo-command-start
2286 (re-search-forward "@end titlespec[ \t]*\n")))
2287
2288 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
2289
2290 \f
2291 ;;; @today
2292
2293 (put 'today 'texinfo-format 'texinfo-format-today)
2294
2295 ;; Produces Day Month Year style of output. eg `1 Jan 1900'
2296 ;; The `@today{}' command requires a pair of braces, like `@dots{}'.
2297 (defun texinfo-format-today ()
2298 (texinfo-parse-arg-discard)
2299 (insert (format-time-string "%e %b %Y")))
2300
2301 \f
2302 ;;; @timestamp{}
2303 ;; Produce `Day Month Year Hour:Min' style of output.
2304 ;; eg `1 Jan 1900 13:52'
2305
2306 (put 'timestamp 'texinfo-format 'texinfo-format-timestamp)
2307
2308 ;; The `@timestamp{}' command requires a pair of braces, like `@dots{}'.
2309 (defun texinfo-format-timestamp ()
2310 "Insert the current local time and date."
2311 (texinfo-parse-arg-discard)
2312 ;; For seconds and time zone, replace format string with "%e %b %Y %T %Z"
2313 (insert (format-time-string "%e %b %Y %R")))
2314
2315 \f
2316 ;;; @ignore
2317
2318 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
2319 (defun texinfo-format-ignore ()
2320 (delete-region texinfo-command-start
2321 (re-search-forward "@end ignore[ \t]*\n")))
2322
2323 (put 'endignore 'texinfo-format 'texinfo-discard-line)
2324
2325 \f
2326 ;;; Define the Info enclosure command: @definfoenclose
2327
2328 ;; A `@definfoenclose' command may be used to define a highlighting
2329 ;; command for Info, but not for TeX. A command defined using
2330 ;; `@definfoenclose' marks text by enclosing it in strings that precede
2331 ;; and follow the text.
2332 ;;
2333 ;; Presumably, if you define a command with `@definfoenclose` for Info,
2334 ;; you will also define the same command in the TeX definitions file,
2335 ;; `texinfo.tex' in a manner appropriate for typesetting.
2336 ;;
2337 ;; Write a `@definfoenclose' command on a line and follow it with three
2338 ;; arguments separated by commas (commas are used as separators in an
2339 ;; `@node' line in the same way). The first argument to
2340 ;; `@definfoenclose' is the @-command name \(without the `@'\); the
2341 ;; second argument is the Info start delimiter string; and the third
2342 ;; argument is the Info end delimiter string. The latter two arguments
2343 ;; enclose the highlighted text in the Info file. A delimiter string
2344 ;; may contain spaces. Neither the start nor end delimiter is
2345 ;; required. However, if you do not provide a start delimiter, you
2346 ;; must follow the command name with two commas in a row; otherwise,
2347 ;; the Info formatting commands will misinterpret the end delimiter
2348 ;; string as a start delimiter string.
2349 ;;
2350 ;; If you do a @definfoenclose{} on the name of a pre-defined macro (such
2351 ;; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
2352 ;; override the built-in definition.
2353 ;;
2354 ;; An enclosure command defined this way takes one argument in braces.
2355 ;;
2356 ;; For example, you can write:
2357 ;;
2358 ;; @ifinfo
2359 ;; @definfoenclose phoo, //, \\
2360 ;; @end ifinfo
2361 ;;
2362 ;; near the beginning of a Texinfo file at the beginning of the lines
2363 ;; to define `@phoo' as an Info formatting command that inserts `//'
2364 ;; before and `\\' after the argument to `@phoo'. You can then write
2365 ;; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
2366 ;;
2367 ;; Also, for TeX formatting, you could write
2368 ;;
2369 ;; @iftex
2370 ;; @global@let@phoo=@i
2371 ;; @end iftex
2372 ;;
2373 ;; to define `@phoo' as a command that causes TeX to typeset
2374 ;; the argument to `@phoo' in italics.
2375 ;;
2376 ;; Note that each definition applies to its own formatter: one for TeX,
2377 ;; the other for texinfo-format-buffer or texinfo-format-region.
2378 ;;
2379 ;; Here is another example: write
2380 ;;
2381 ;; @definfoenclose headword, , :
2382 ;;
2383 ;; near the beginning of the file, to define `@headword' as an Info
2384 ;; formatting command that inserts nothing before and a colon after the
2385 ;; argument to `@headword'.
2386
2387 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
2388 (defun texinfo-define-info-enclosure ()
2389 (let* ((args (texinfo-format-parse-line-args))
2390 (command-name (nth 0 args))
2391 (beginning-delimiter (or (nth 1 args) ""))
2392 (end-delimiter (or (nth 2 args) "")))
2393 (texinfo-discard-command)
2394 (push (list command-name
2395 (list
2396 beginning-delimiter
2397 end-delimiter))
2398 texinfo-enclosure-list)))
2399
2400 \f
2401 ;;; @alias
2402
2403 (put 'alias 'texinfo-format 'texinfo-alias)
2404 (defun texinfo-alias ()
2405 (let ((start (1- (point)))
2406 args)
2407 (skip-chars-forward " ")
2408 (setq texinfo-command-end (line-end-position))
2409 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
2410 (error "Invalid alias command")
2411 (push (cons
2412 (match-string-no-properties 1)
2413 (match-string-no-properties 2))
2414 texinfo-alias-list)
2415 (texinfo-discard-command))))
2416
2417 \f
2418 ;;; @var, @code and the like
2419
2420 (put 'var 'texinfo-format 'texinfo-format-var)
2421 ;; @sc a small caps font for TeX; formatted as `var' in Info
2422 (put 'sc 'texinfo-format 'texinfo-format-var)
2423 ;; @acronym for abbreviations in all caps, such as `NASA'.
2424 ;; Convert all letters to uppercase if they are not already.
2425 (put 'acronym 'texinfo-format 'texinfo-format-var)
2426 (defun texinfo-format-var ()
2427 (let ((arg (texinfo-parse-expanded-arg)))
2428 (texinfo-discard-command)
2429 (insert (upcase arg))))
2430
2431 (put 'cite 'texinfo-format 'texinfo-format-code)
2432 (put 'code 'texinfo-format 'texinfo-format-code)
2433 ;; @command (for command names)
2434 (put 'command 'texinfo-format 'texinfo-format-code)
2435 ;; @env (for environment variables)
2436 (put 'env 'texinfo-format 'texinfo-format-code)
2437 (put 'file 'texinfo-format 'texinfo-format-code)
2438 (put 'samp 'texinfo-format 'texinfo-format-code)
2439 (put 'url 'texinfo-format 'texinfo-format-code)
2440 (defun texinfo-format-code ()
2441 (insert "`" (texinfo-parse-arg-discard) "'")
2442 (goto-char texinfo-command-start))
2443
2444 ;; @option (for command-line options) must be different from @code
2445 ;; because of its special formatting in @table; namely that it does
2446 ;; not lead to inserted ` ... ' in a table, but does elsewhere.
2447 (put 'option 'texinfo-format 'texinfo-format-option)
2448 (defun texinfo-format-option ()
2449 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
2450 ;; `looking-at-backward' not available in v. 18.57, 20.2
2451 (if (not (search-backward "\b" ; searched-for character is a control-H
2452 (line-beginning-position)
2453 t))
2454 (insert "`" (texinfo-parse-arg-discard) "'")
2455 (insert (texinfo-parse-arg-discard)))
2456 (goto-char texinfo-command-start))
2457
2458 (put 'emph 'texinfo-format 'texinfo-format-emph)
2459 (put 'strong 'texinfo-format 'texinfo-format-emph)
2460 (defun texinfo-format-emph ()
2461 (insert "*" (texinfo-parse-arg-discard) "*")
2462 (goto-char texinfo-command-start))
2463
2464 (put 'dfn 'texinfo-format 'texinfo-format-defn)
2465 (put 'defn 'texinfo-format 'texinfo-format-defn)
2466 (defun texinfo-format-defn ()
2467 (insert "\"" (texinfo-parse-arg-discard) "\"")
2468 (goto-char texinfo-command-start))
2469
2470 (put 'email 'texinfo-format 'texinfo-format-email)
2471 (defun texinfo-format-email ()
2472 "Format email address and optional following full name.
2473 Insert full name, if present, followed by email address
2474 surrounded by in angle brackets."
2475 (let ((args (texinfo-format-parse-args)))
2476 (texinfo-discard-command)
2477 ;; if full-name
2478 (if (nth 1 args)
2479 (insert (nth 1 args) " "))
2480 (insert "<" (nth 0 args) ">")))
2481
2482 (put 'key 'texinfo-format 'texinfo-format-key)
2483 ;; I've decided not want to have angle brackets around these -- rms.
2484 (defun texinfo-format-key ()
2485 (insert (texinfo-parse-arg-discard))
2486 (goto-char texinfo-command-start))
2487
2488 ;; @verb{<char>TEXT<char>} (in `makeinfo' 4.1 and later)
2489 (put 'verb 'texinfo-format 'texinfo-format-verb)
2490 (defun texinfo-format-verb ()
2491 "Format text between non-quoted unique delimiter characters verbatim.
2492 Enclose the verbatim text, including the delimiters, in braces. Print
2493 text exactly as written (but not the delimiters) in a fixed-width.
2494
2495 For example, @verb\{|@|\} results in @ and
2496 @verb\{+@'e?`!`+} results in @'e?`!`."
2497
2498 (let ((delimiter (buffer-substring-no-properties
2499 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
2500 (unless (looking-at "{")
2501 (error "Not found: @verb start brace"))
2502 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
2503 (search-forward delimiter))
2504 (delete-char -1)
2505 (unless (looking-at "}")
2506 (error "Not found: @verb end brace"))
2507 (delete-char 1))
2508
2509 ;; as of 2002 Dec 10
2510 ;; see (texinfo)Block Enclosing Commands
2511 ;; need: @verbatim
2512
2513 ;; as of 2002 Dec 10
2514 ;; see (texinfo)verbatiminclude
2515 ;; need: @verbatiminclude FILENAME
2516
2517 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
2518 (defun texinfo-format-bullet ()
2519 "Insert an asterisk.
2520 If used within a line, follow `@bullet' with braces."
2521 (texinfo-optional-braces-discard)
2522 (insert "*"))
2523
2524 \f
2525 ;;; @kbd
2526
2527 ;; Inside of @example ... @end example and similar environments,
2528 ;; @kbd does nothing; but outside of such environments, it places
2529 ;; single quotation marks around its argument.
2530
2531 (defvar texinfo-format-kbd-regexp
2532 (concat
2533 "^@"
2534 "\\("
2535 "display\\|"
2536 "example\\|"
2537 "smallexample\\|"
2538 "lisp\\|"
2539 "smalllisp"
2540 "\\)")
2541 "Regexp matching environments in which @kbd does not put `...' around arg.")
2542
2543 (defvar texinfo-format-kbd-end-regexp
2544 (concat
2545 "^@end "
2546 "\\("
2547 "display\\|"
2548 "example\\|"
2549 "smallexample\\|"
2550 "lisp\\|"
2551 "smalllisp"
2552 "\\)")
2553 "Regexp specifying end of environments in which @kbd does not put `...'
2554 around argument. (See `texinfo-format-kbd-regexp')")
2555
2556 (put 'kbd 'texinfo-format 'texinfo-format-kbd)
2557 (defun texinfo-format-kbd ()
2558 "Place single quote marks around arg, except in @example and similar."
2559 ;; Search forward for @end example closer than an @example.
2560 ;; Can stop search at nearest @node or texinfo-section-types-regexp
2561 (let* ((stop
2562 (save-excursion
2563 (re-search-forward
2564 (concat "^@node\\|\\(" texinfo-section-types-regexp "\\)")
2565 nil
2566 'move-to-end) ; if necessary, return point at end of buffer
2567 (point)))
2568 (example-location
2569 (save-excursion
2570 (re-search-forward texinfo-format-kbd-regexp stop 'move-to-end)
2571 (point)))
2572 (end-example-location
2573 (save-excursion
2574 (re-search-forward texinfo-format-kbd-end-regexp stop 'move-to-end)
2575 (point))))
2576 ;; If inside @example, @end example will be closer than @example
2577 ;; or end of search i.e., end-example-location less than example-location
2578 (if (>= end-example-location example-location)
2579 ;; outside an @example or equivalent
2580 (insert "`" (texinfo-parse-arg-discard) "'")
2581 ;; else, in @example; do not surround with `...'
2582 (insert (texinfo-parse-arg-discard)))
2583 (goto-char texinfo-command-start)))
2584
2585 \f
2586 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample,
2587 ;; @smalldisplay
2588
2589 (put 'display 'texinfo-format 'texinfo-format-example)
2590 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
2591 (put 'example 'texinfo-format 'texinfo-format-example)
2592 (put 'lisp 'texinfo-format 'texinfo-format-example)
2593 (put 'quotation 'texinfo-format 'texinfo-format-example)
2594 (put 'smallexample 'texinfo-format 'texinfo-format-example)
2595 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
2596 (defun texinfo-format-example ()
2597 (texinfo-push-stack 'example nil)
2598 (setq fill-column (- fill-column 5))
2599 (texinfo-discard-line))
2600
2601 (put 'example 'texinfo-end 'texinfo-end-example)
2602 (put 'display 'texinfo-end 'texinfo-end-example)
2603 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
2604 (put 'lisp 'texinfo-end 'texinfo-end-example)
2605 (put 'quotation 'texinfo-end 'texinfo-end-example)
2606 (put 'smallexample 'texinfo-end 'texinfo-end-example)
2607 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
2608 (defun texinfo-end-example ()
2609 (setq fill-column (+ fill-column 5))
2610 (texinfo-discard-command)
2611 (let ((stacktop
2612 (texinfo-pop-stack 'example)))
2613 (texinfo-do-itemize (nth 1 stacktop))))
2614
2615 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
2616 (defun texinfo-format-exdent ()
2617 (texinfo-discard-command)
2618 (delete-region (point)
2619 (progn
2620 (skip-chars-forward " ")
2621 (point)))
2622 (insert ?\b)
2623 ;; Cancel out the deletion that texinfo-do-itemize
2624 ;; is going to do at the end of this line.
2625 (save-excursion
2626 (end-of-line)
2627 (insert "\n ")))
2628
2629 \f
2630 ;; @direntry and @dircategory
2631
2632 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
2633 (defun texinfo-format-direntry ()
2634 (texinfo-push-stack 'direntry nil)
2635 (texinfo-discard-line)
2636 (insert "START-INFO-DIR-ENTRY\n"))
2637
2638 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
2639 (defun texinfo-end-direntry ()
2640 (texinfo-discard-command)
2641 (insert "END-INFO-DIR-ENTRY\n\n")
2642 (texinfo-pop-stack 'direntry))
2643
2644 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
2645 (defun texinfo-format-dircategory ()
2646 (let ((str (texinfo-parse-arg-discard)))
2647 (delete-region (point)
2648 (progn
2649 (skip-chars-forward " ")
2650 (point)))
2651 (insert "INFO-DIR-SECTION " str "\n")))
2652 \f
2653 ;;; @cartouche
2654
2655 ;; The @cartouche command is a noop in Info; in a printed manual,
2656 ;; it makes a box with rounded corners.
2657
2658 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
2659 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
2660
2661 \f
2662 ;;; @flushleft and @format
2663
2664 ;; The @flushleft command left justifies every line but leaves the
2665 ;; right end ragged. As far as Info is concerned, @flushleft is a
2666 ;; `do-nothing' command
2667
2668 ;; The @format command is similar to @example except that it does not
2669 ;; indent; this means that in Info, @format is similar to @flushleft.
2670
2671 (put 'format 'texinfo-format 'texinfo-format-flushleft)
2672 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
2673 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
2674 (defun texinfo-format-flushleft ()
2675 (texinfo-discard-line))
2676
2677 (put 'format 'texinfo-end 'texinfo-end-flushleft)
2678 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
2679 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
2680 (defun texinfo-end-flushleft ()
2681 (texinfo-discard-command))
2682
2683 \f
2684 ;;; @flushright
2685
2686 ;; The @flushright command right justifies every line but leaves the
2687 ;; left end ragged. Spaces and tabs at the right ends of lines are
2688 ;; removed so that visible text lines up on the right side.
2689
2690 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
2691 (defun texinfo-format-flushright ()
2692 (texinfo-push-stack 'flushright nil)
2693 (texinfo-discard-line))
2694
2695 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
2696 (defun texinfo-end-flushright ()
2697 (texinfo-discard-command)
2698
2699 (let ((stacktop
2700 (texinfo-pop-stack 'flushright)))
2701
2702 (texinfo-do-flushright (nth 1 stacktop))))
2703
2704 (defun texinfo-do-flushright (from)
2705 (save-excursion
2706 (while (progn (forward-line -1)
2707 (>= (point) from))
2708
2709 (beginning-of-line)
2710 (insert
2711 (make-string
2712 (- fill-column
2713 (save-excursion
2714 (end-of-line)
2715 (skip-chars-backward " \t")
2716 (delete-region (point) (progn (end-of-line) (point)))
2717 (current-column)))
2718 ? )))))
2719
2720 \f
2721 ;;; @ctrl, @TeX, @copyright, @minus, @dots, @enddots, @pounds
2722
2723 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
2724 (defun texinfo-format-ctrl ()
2725 (let ((str (texinfo-parse-arg-discard)))
2726 (insert (logand 31 (aref str 0)))))
2727
2728 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
2729 (defun texinfo-format-TeX ()
2730 (texinfo-parse-arg-discard)
2731 (insert "TeX"))
2732
2733 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
2734 (defun texinfo-format-copyright ()
2735 (texinfo-parse-arg-discard)
2736 (insert "(C)"))
2737
2738 (put 'minus 'texinfo-format 'texinfo-format-minus)
2739 (defun texinfo-format-minus ()
2740 "Insert a minus sign.
2741 If used within a line, follow `@minus' with braces."
2742 (texinfo-optional-braces-discard)
2743 (insert "-"))
2744
2745 (put 'dots 'texinfo-format 'texinfo-format-dots)
2746 (defun texinfo-format-dots ()
2747 (texinfo-parse-arg-discard)
2748 (insert "..."))
2749
2750 (put 'enddots 'texinfo-format 'texinfo-format-enddots)
2751 (defun texinfo-format-enddots ()
2752 (texinfo-parse-arg-discard)
2753 (insert "...."))
2754
2755 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
2756 (defun texinfo-format-pounds ()
2757 (texinfo-parse-arg-discard)
2758 (insert "#"))
2759
2760 \f
2761 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
2762
2763 ;; Indent only those paragraphs that are refilled as a result of an
2764 ;; @refill command.
2765
2766 ;; * If the value is `asis', do not change the existing indentation at
2767 ;; the starts of paragraphs.
2768
2769 ;; * If the value zero, delete any existing indentation.
2770
2771 ;; * If the value is greater than zero, indent each paragraph by that
2772 ;; number of spaces.
2773
2774 ;; But do not refill paragraphs with an @refill command that are
2775 ;; preceded by @noindent or are part of a table, list, or deffn.
2776
2777 (defvar texinfo-paragraph-indent "asis"
2778 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
2779
2780 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
2781
2782 (defun texinfo-paragraphindent ()
2783 "Specify the number of spaces for @refill to indent a paragraph.
2784 Default is to leave the number of spaces as is."
2785 (let ((arg (texinfo-parse-arg-discard)))
2786 (if (string= "asis" arg)
2787 (setq texinfo-paragraph-indent "asis")
2788 (setq texinfo-paragraph-indent (string-to-number arg)))))
2789
2790 (put 'refill 'texinfo-format 'texinfo-format-refill)
2791 (defun texinfo-format-refill ()
2792 "Refill paragraph. Also, indent first line as set by @paragraphindent.
2793 Default is to leave paragraph indentation as is."
2794 (texinfo-discard-command)
2795 (let ((position (point-marker)))
2796 (forward-paragraph -1)
2797 (if (looking-at "[ \t\n]*$") (forward-line 1))
2798 ;; Do not indent if an entry in a list, table, or deffn,
2799 ;; or if paragraph is preceded by @noindent.
2800 ;; Otherwise, indent
2801 (cond
2802 ;; delete a @noindent line and do not indent paragraph
2803 ((save-excursion (forward-line -1)
2804 (looking-at "^@noindent"))
2805 (forward-line -1)
2806 (delete-region (point) (progn (forward-line 1) (point))))
2807 ;; do nothing if "asis"
2808 ((equal texinfo-paragraph-indent "asis"))
2809 ;; do no indenting in list, etc.
2810 ((> texinfo-stack-depth 0))
2811 ;; otherwise delete existing whitespace and indent
2812 (t
2813 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2814 (insert (make-string texinfo-paragraph-indent ? ))))
2815 (forward-paragraph 1)
2816 (forward-line -1)
2817 (end-of-line)
2818 ;; Do not fill a section title line with asterisks, hyphens, etc. that
2819 ;; are used to underline it. This could occur if the line following
2820 ;; the underlining is not an index entry and has text within it.
2821 (let* ((previous-paragraph-separate paragraph-separate)
2822 (paragraph-separate
2823 (concat paragraph-separate "\\|[-=.]+\\|\\*\\*+"))
2824 (previous-paragraph-start paragraph-start)
2825 (paragraph-start
2826 (concat paragraph-start "\\|[-=.]+\\|\\*\\*+")))
2827 (unwind-protect
2828 (fill-paragraph nil)
2829 (setq paragraph-separate previous-paragraph-separate)
2830 (setq paragraph-start previous-paragraph-start)))
2831 (goto-char position)))
2832
2833 (put 'noindent 'texinfo-format 'texinfo-noindent)
2834 (defun texinfo-noindent ()
2835 (save-excursion
2836 (forward-paragraph 1)
2837 (if (search-backward "@refill" (line-beginning-position 0) t)
2838 () ; leave @noindent command so @refill command knows not to indent
2839 ;; else
2840 (texinfo-discard-line))))
2841
2842 \f
2843 ;;; Index generation
2844
2845 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
2846 (defun texinfo-format-vindex ()
2847 (texinfo-index 'texinfo-vindex))
2848
2849 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
2850 (defun texinfo-format-cindex ()
2851 (texinfo-index 'texinfo-cindex))
2852
2853 (put 'findex 'texinfo-format 'texinfo-format-findex)
2854 (defun texinfo-format-findex ()
2855 (texinfo-index 'texinfo-findex))
2856
2857 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
2858 (defun texinfo-format-pindex ()
2859 (texinfo-index 'texinfo-pindex))
2860
2861 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
2862 (defun texinfo-format-tindex ()
2863 (texinfo-index 'texinfo-tindex))
2864
2865 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
2866 (defun texinfo-format-kindex ()
2867 (texinfo-index 'texinfo-kindex))
2868
2869 (defun texinfo-index (indexvar)
2870 (let ((arg (texinfo-parse-expanded-arg)))
2871 (texinfo-discard-command)
2872 (set indexvar
2873 (cons (list arg
2874 texinfo-last-node
2875 ;; Region formatting may not provide last node position.
2876 (if texinfo-last-node-pos
2877 (1+ (count-lines texinfo-last-node-pos (point)))
2878 1))
2879 (symbol-value indexvar)))))
2880
2881 (defvar texinfo-indexvar-alist
2882 '(("cp" . texinfo-cindex)
2883 ("fn" . texinfo-findex)
2884 ("vr" . texinfo-vindex)
2885 ("tp" . texinfo-tindex)
2886 ("pg" . texinfo-pindex)
2887 ("ky" . texinfo-kindex)))
2888
2889 \f
2890 ;;; @defindex @defcodeindex
2891 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
2892 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
2893
2894 (defun texinfo-format-defindex ()
2895 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
2896 (indexing-command (intern (concat index-name "index")))
2897 (index-formatting-command ; eg: `texinfo-format-aaindex'
2898 (intern (concat "texinfo-format-" index-name "index")))
2899 (index-alist-name ; eg: `texinfo-aaindex'
2900 (intern (concat "texinfo-" index-name "index"))))
2901
2902 (set index-alist-name nil)
2903
2904 (put indexing-command ; eg, aaindex
2905 'texinfo-format
2906 index-formatting-command) ; eg, texinfo-format-aaindex
2907
2908 ;; eg: "aa" . texinfo-aaindex
2909 (or (assoc index-name texinfo-indexvar-alist)
2910 (push (cons index-name
2911 index-alist-name)
2912 texinfo-indexvar-alist))
2913
2914 (fset index-formatting-command
2915 (list 'lambda 'nil
2916 (list 'texinfo-index
2917 (list 'quote index-alist-name))))))
2918
2919 \f
2920 ;;; @synindex @syncodeindex
2921
2922 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
2923 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
2924
2925 (defun texinfo-format-synindex ()
2926 (let* ((args (texinfo-parse-arg-discard))
2927 (second (cdr (read-from-string args)))
2928 (joiner (symbol-name (car (read-from-string args))))
2929 (joined (symbol-name (car (read-from-string args second)))))
2930
2931 (if (assoc joiner texinfo-short-index-cmds-alist)
2932 (put
2933 (cdr (assoc joiner texinfo-short-index-cmds-alist))
2934 'texinfo-format
2935 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
2936 (intern (concat "texinfo-format-" joined "index"))))
2937 (put
2938 (intern (concat joiner "index"))
2939 'texinfo-format
2940 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
2941 (intern (concat "texinfo-format-" joined "index")))))))
2942
2943 (defconst texinfo-short-index-cmds-alist
2944 '(("cp" . cindex)
2945 ("fn" . findex)
2946 ("vr" . vindex)
2947 ("tp" . tindex)
2948 ("pg" . pindex)
2949 ("ky" . kindex)))
2950
2951 (defconst texinfo-short-index-format-cmds-alist
2952 '(("cp" . texinfo-format-cindex)
2953 ("fn" . texinfo-format-findex)
2954 ("vr" . texinfo-format-vindex)
2955 ("tp" . texinfo-format-tindex)
2956 ("pg" . texinfo-format-pindex)
2957 ("ky" . texinfo-format-kindex)))
2958
2959 \f
2960 ;;; @printindex
2961
2962 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
2963
2964 (defun texinfo-format-printindex ()
2965 (let* ((arg (texinfo-parse-arg-discard))
2966 (fmt (cdr (assoc arg texinfo-short-index-format-cmds-alist)))
2967 (index-list (delq nil (mapcar (lambda (e)
2968 (and (eq fmt (get (cdr e) 'texinfo-format))
2969 (cdr (assoc (car e) texinfo-indexvar-alist))))
2970 texinfo-short-index-cmds-alist)))
2971 (indexelts (apply #'append nil (mapcar #'symbol-value index-list)))
2972 opoint)
2973 (insert "\n* Menu:\n\n")
2974 (setq opoint (point))
2975 (texinfo-print-index nil indexelts)
2976 (shell-command-on-region opoint (point) "sort -fd" 1)))
2977
2978 (defun texinfo-print-index (file indexelts)
2979 (while indexelts
2980 (if (stringp (car (car indexelts)))
2981 (progn
2982 (insert "* " (car (car indexelts)) ": " )
2983 (indent-to 32)
2984 (insert
2985 (if file (concat "(" file ")") "")
2986 (nth 1 (car indexelts)) ".")
2987 (indent-to 54)
2988 (insert
2989 (if (nth 2 (car indexelts))
2990 (format " (line %3d)" (1+ (nth 2 (car indexelts))))
2991 "")
2992 "\n"))
2993 ;; index entries from @include'd file
2994 (texinfo-print-index (nth 1 (car indexelts))
2995 (nth 2 (car indexelts))))
2996 (setq indexelts (cdr indexelts))))
2997
2998 \f
2999 ;;; Glyphs: @equiv, @error, etc
3000
3001 ;; @equiv to show that two expressions are equivalent
3002 ;; @error to show an error message
3003 ;; @expansion to show what a macro expands to
3004 ;; @point to show the location of point in an example
3005 ;; @print to show what an evaluated expression prints
3006 ;; @result to indicate the value returned by an expression
3007
3008 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
3009 (defun texinfo-format-equiv ()
3010 (texinfo-parse-arg-discard)
3011 (insert "=="))
3012
3013 (put 'error 'texinfo-format 'texinfo-format-error)
3014 (defun texinfo-format-error ()
3015 (texinfo-parse-arg-discard)
3016 (insert "error-->"))
3017
3018 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
3019 (defun texinfo-format-expansion ()
3020 (texinfo-parse-arg-discard)
3021 (insert "==>"))
3022
3023 (put 'point 'texinfo-format 'texinfo-format-point)
3024 (defun texinfo-format-point ()
3025 (texinfo-parse-arg-discard)
3026 (insert "-!-"))
3027
3028 (put 'print 'texinfo-format 'texinfo-format-print)
3029 (defun texinfo-format-print ()
3030 (texinfo-parse-arg-discard)
3031 (insert "-|"))
3032
3033 (put 'result 'texinfo-format 'texinfo-format-result)
3034 (defun texinfo-format-result ()
3035 (texinfo-parse-arg-discard)
3036 (insert "=>"))
3037
3038 \f
3039 ;;; Accent commands
3040
3041 ;; Info presumes a plain ASCII output, so the accented characters do
3042 ;; not look as they would if typeset, or output with a different
3043 ;; character set.
3044
3045 ;; See the `texinfo-accent-commands' variable
3046 ;; in the section for `texinfo-append-refill'.
3047 ;; Also, see the defun for `texinfo-format-scan'
3048 ;; for single-character accent commands.
3049
3050 ;; Command Info output Name
3051
3052 ;; These do not have braces:
3053 ;; @^ ==> ^ circumflex accent
3054 ;; @` ==> ` grave accent
3055 ;; @' ==> ' acute accent
3056 ;; @" ==> " umlaut accent
3057 ;; @= ==> = overbar accent
3058 ;; @~ ==> ~ tilde accent
3059
3060 ;; These have braces, but take no argument:
3061 ;; @OE{} ==> OE French-OE-ligature
3062 ;; @oe{} ==> oe
3063 ;; @AA{} ==> AA Scandinavian-A-with-circle
3064 ;; @aa{} ==> aa
3065 ;; @AE{} ==> AE Latin-Scandinavian-AE
3066 ;; @ae{} ==> ae
3067 ;; @ss{} ==> ss German-sharp-S
3068
3069 ;; @questiondown{} ==> ? upside-down-question-mark
3070 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
3071 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
3072 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
3073 ;; @O{} ==> O/ Scandinavian O-with-slash
3074 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
3075
3076 ;; These have braces, and take an argument:
3077 ;; @,{c} ==> c, cedilla accent
3078 ;; @dotaccent{o} ==> .o overdot-accent
3079 ;; @ubaraccent{o} ==> _o underbar-accent
3080 ;; @udotaccent{o} ==> o-. underdot-accent
3081 ;; @H{o} ==> ""o long Hungarian umlaut
3082 ;; @ringaccent{o} ==> *o ring accent
3083 ;; @tieaccent{oo} ==> [oo tie after accent
3084 ;; @u{o} ==> (o breve accent
3085 ;; @v{o} ==> <o hacek accent
3086 ;; @dotless{i} ==> i dotless i and dotless j
3087
3088 ;; ==========
3089
3090 ;; Note: The defun texinfo-format-scan
3091 ;; looks at "[@{}^'`\",=~ *?!-]"
3092 ;; In the case of @*, a line break is inserted;
3093 ;; in the other cases, the characters are simply quoted and the @ is deleted.
3094 ;; Thus, `texinfo-format-scan' handles the following
3095 ;; single-character accent commands: @^ @` @' @" @, @- @= @~
3096
3097 ;; @^ ==> ^ circumflex accent
3098 ;; (put '^ 'texinfo-format 'texinfo-format-circumflex-accent)
3099 ;; (defun texinfo-format-circumflex-accent ()
3100 ;; (texinfo-discard-command)
3101 ;; (insert "^"))
3102 ;;
3103 ;; @` ==> ` grave accent
3104 ;; (put '\` 'texinfo-format 'texinfo-format-grave-accent)
3105 ;; (defun texinfo-format-grave-accent ()
3106 ;; (texinfo-discard-command)
3107 ;; (insert "\`"))
3108 ;;
3109 ;; @' ==> ' acute accent
3110 ;; (put '\' 'texinfo-format 'texinfo-format-acute-accent)
3111 ;; (defun texinfo-format-acute-accent ()
3112 ;; (texinfo-discard-command)
3113 ;; (insert "'"))
3114 ;;
3115 ;; @" ==> " umlaut accent
3116 ;; (put '\" 'texinfo-format 'texinfo-format-umlaut-accent)
3117 ;; (defun texinfo-format-umlaut-accent ()
3118 ;; (texinfo-discard-command)
3119 ;; (insert "\""))
3120 ;;
3121 ;; @= ==> = overbar accent
3122 ;; (put '= 'texinfo-format 'texinfo-format-overbar-accent)
3123 ;; (defun texinfo-format-overbar-accent ()
3124 ;; (texinfo-discard-command)
3125 ;; (insert "="))
3126 ;;
3127 ;; @~ ==> ~ tilde accent
3128 ;; (put '~ 'texinfo-format 'texinfo-format-tilde-accent)
3129 ;; (defun texinfo-format-tilde-accent ()
3130 ;; (texinfo-discard-command)
3131 ;; (insert "~"))
3132
3133 ;; @OE{} ==> OE French-OE-ligature
3134 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
3135 (defun texinfo-format-French-OE-ligature ()
3136 (insert "OE" (texinfo-parse-arg-discard))
3137 (goto-char texinfo-command-start))
3138
3139 ;; @oe{} ==> oe
3140 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
3141 (defun texinfo-format-French-oe-ligature () ; lower case
3142 (insert "oe" (texinfo-parse-arg-discard))
3143 (goto-char texinfo-command-start))
3144
3145 ;; @AA{} ==> AA Scandinavian-A-with-circle
3146 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
3147 (defun texinfo-format-Scandinavian-A-with-circle ()
3148 (insert "AA" (texinfo-parse-arg-discard))
3149 (goto-char texinfo-command-start))
3150
3151 ;; @aa{} ==> aa
3152 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
3153 (defun texinfo-format-Scandinavian-a-with-circle () ; lower case
3154 (insert "aa" (texinfo-parse-arg-discard))
3155 (goto-char texinfo-command-start))
3156
3157 ;; @AE{} ==> AE Latin-Scandinavian-AE
3158 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
3159 (defun texinfo-format-Latin-Scandinavian-AE ()
3160 (insert "AE" (texinfo-parse-arg-discard))
3161 (goto-char texinfo-command-start))
3162
3163 ;; @ae{} ==> ae
3164 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
3165 (defun texinfo-format-Latin-Scandinavian-ae () ; lower case
3166 (insert "ae" (texinfo-parse-arg-discard))
3167 (goto-char texinfo-command-start))
3168
3169 ;; @ss{} ==> ss German-sharp-S
3170 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
3171 (defun texinfo-format-German-sharp-S ()
3172 (insert "ss" (texinfo-parse-arg-discard))
3173 (goto-char texinfo-command-start))
3174
3175 ;; @questiondown{} ==> ? upside-down-question-mark
3176 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
3177 (defun texinfo-format-upside-down-question-mark ()
3178 (insert "?" (texinfo-parse-arg-discard))
3179 (goto-char texinfo-command-start))
3180
3181 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
3182 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
3183 (defun texinfo-format-upside-down-exclamation-mark ()
3184 (insert "!" (texinfo-parse-arg-discard))
3185 (goto-char texinfo-command-start))
3186
3187 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
3188 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
3189 (defun texinfo-format-Polish-suppressed-L ()
3190 (insert (texinfo-parse-arg-discard) "/L")
3191 (goto-char texinfo-command-start))
3192
3193 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
3194 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
3195 (defun texinfo-format-Polish-suppressed-l-lower-case ()
3196 (insert (texinfo-parse-arg-discard) "/l")
3197 (goto-char texinfo-command-start))
3198
3199
3200 ;; @O{} ==> O/ Scandinavian O-with-slash
3201 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
3202 (defun texinfo-format-Scandinavian-O-with-slash ()
3203 (insert (texinfo-parse-arg-discard) "O/")
3204 (goto-char texinfo-command-start))
3205
3206 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
3207 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
3208 (defun texinfo-format-Scandinavian-o-with-slash-lower-case ()
3209 (insert (texinfo-parse-arg-discard) "o/")
3210 (goto-char texinfo-command-start))
3211
3212 ;; Take arguments
3213
3214 ;; @,{c} ==> c, cedilla accent
3215 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
3216 (defun texinfo-format-cedilla-accent ()
3217 (insert (texinfo-parse-arg-discard) ",")
3218 (goto-char texinfo-command-start))
3219
3220
3221 ;; @dotaccent{o} ==> .o overdot-accent
3222 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
3223 (defun texinfo-format-overdot-accent ()
3224 (insert "." (texinfo-parse-arg-discard))
3225 (goto-char texinfo-command-start))
3226
3227 ;; @ubaraccent{o} ==> _o underbar-accent
3228 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
3229 (defun texinfo-format-underbar-accent ()
3230 (insert "_" (texinfo-parse-arg-discard))
3231 (goto-char texinfo-command-start))
3232
3233 ;; @udotaccent{o} ==> o-. underdot-accent
3234 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
3235 (defun texinfo-format-underdot-accent ()
3236 (insert (texinfo-parse-arg-discard) "-.")
3237 (goto-char texinfo-command-start))
3238
3239 ;; @H{o} ==> ""o long Hungarian umlaut
3240 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
3241 (defun texinfo-format-long-Hungarian-umlaut ()
3242 (insert "\"\"" (texinfo-parse-arg-discard))
3243 (goto-char texinfo-command-start))
3244
3245 ;; @ringaccent{o} ==> *o ring accent
3246 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
3247 (defun texinfo-format-ring-accent ()
3248 (insert "*" (texinfo-parse-arg-discard))
3249 (goto-char texinfo-command-start))
3250
3251 ;; @tieaccent{oo} ==> [oo tie after accent
3252 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
3253 (defun texinfo-format-tie-after-accent ()
3254 (insert "[" (texinfo-parse-arg-discard))
3255 (goto-char texinfo-command-start))
3256
3257
3258 ;; @u{o} ==> (o breve accent
3259 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
3260 (defun texinfo-format-breve-accent ()
3261 (insert "(" (texinfo-parse-arg-discard))
3262 (goto-char texinfo-command-start))
3263
3264 ;; @v{o} ==> <o hacek accent
3265 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
3266 (defun texinfo-format-hacek-accent ()
3267 (insert "<" (texinfo-parse-arg-discard))
3268 (goto-char texinfo-command-start))
3269
3270
3271 ;; @dotless{i} ==> i dotless i and dotless j
3272 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
3273 (defun texinfo-format-dotless ()
3274 (insert (texinfo-parse-arg-discard))
3275 (goto-char texinfo-command-start))
3276
3277 \f
3278 ;;; Definition formatting: @deffn, @defun, etc
3279
3280 ;; What definition formatting produces:
3281 ;;
3282 ;; @deffn category name args...
3283 ;; In Info, `Category: name ARGS'
3284 ;; In index: name: node. line#.
3285 ;;
3286 ;; @defvr category name
3287 ;; In Info, `Category: name'
3288 ;; In index: name: node. line#.
3289 ;;
3290 ;; @deftp category name attributes...
3291 ;; `category name attributes...' Note: @deftp args in lower case.
3292 ;; In index: name: node. line#.
3293 ;;
3294 ;; Specialized function-like or variable-like entity:
3295 ;;
3296 ;; @defun, @defmac, @defspec, @defvar, @defopt
3297 ;;
3298 ;; @defun name args In Info, `Function: name ARGS'
3299 ;; @defmac name args In Info, `Macro: name ARGS'
3300 ;; @defvar name In Info, `Variable: name'
3301 ;; etc.
3302 ;; In index: name: node. line#.
3303 ;;
3304 ;; Generalized typed-function-like or typed-variable-like entity:
3305 ;; @deftypefn category data-type name args...
3306 ;; In Info, `Category: data-type name args...'
3307 ;; @deftypevr category data-type name
3308 ;; In Info, `Category: data-type name'
3309 ;; In index: name: node. line#.
3310 ;;
3311 ;; Specialized typed-function-like or typed-variable-like entity:
3312 ;; @deftypefun data-type name args...
3313 ;; In Info, `Function: data-type name ARGS'
3314 ;; In index: name: node. line#.
3315 ;;
3316 ;; @deftypevar data-type name
3317 ;; In Info, `Variable: data-type name'
3318 ;; In index: name: node. line#. but include args after name!?
3319 ;;
3320 ;; Generalized object oriented entity:
3321 ;; @defop category class name args...
3322 ;; In Info, `Category on class: name ARG'
3323 ;; In index: name on class: node. line#.
3324 ;;
3325 ;; @defcv category class name
3326 ;; In Info, `Category of class: name'
3327 ;; In index: name of class: node. line#.
3328 ;;
3329 ;; Specialized object oriented entity:
3330 ;; @defmethod class name args...
3331 ;; In Info, `Method on class: name ARGS'
3332 ;; In index: name on class: node. line#.
3333 ;;
3334 ;; @defivar class name
3335 ;; In Info, `Instance variable of class: name'
3336 ;; In index: name of class: node. line#.
3337
3338 \f
3339 ;;; The definition formatting functions
3340
3341 (defun texinfo-format-defun ()
3342 (texinfo-push-stack 'defun nil)
3343 (setq fill-column (- fill-column 5))
3344 (texinfo-format-defun-1 t))
3345
3346 (defun texinfo-end-defun ()
3347 (setq fill-column (+ fill-column 5))
3348 (texinfo-discard-command)
3349 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
3350 (texinfo-do-itemize start)
3351 ;; Delete extra newline inserted after header.
3352 (save-excursion
3353 (goto-char start)
3354 (delete-char -1))))
3355
3356 (defun texinfo-format-defunx ()
3357 (texinfo-format-defun-1 nil))
3358
3359 (defun texinfo-format-defun-1 (first-p)
3360 (let ((parse-args (texinfo-format-parse-defun-args))
3361 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
3362 (texinfo-discard-command)
3363 ;; Delete extra newline inserted after previous header line.
3364 (if (not first-p)
3365 (delete-char -1))
3366 (funcall
3367 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
3368 ;; Insert extra newline so that paragraph filling does not mess
3369 ;; with header line.
3370 (insert "\n\n")
3371 (rplaca (cdr (cdr (car texinfo-stack))) (point))
3372 (funcall
3373 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
3374
3375 ;;; Formatting the first line of a definition
3376
3377 ;; @deffn, @defvr, @deftp
3378 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3379 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3380 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3381 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3382 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3383 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3384 (defun texinfo-format-deffn (parsed-args)
3385 ;; Generalized function-like, variable-like, or generic data-type entity:
3386 ;; @deffn category name args...
3387 ;; In Info, `Category: name ARGS'
3388 ;; @deftp category name attributes...
3389 ;; `category name attributes...' Note: @deftp args in lower case.
3390 (let ((category (car parsed-args))
3391 (name (car (cdr parsed-args)))
3392 (args (cdr (cdr parsed-args))))
3393 (insert " -- " category ": " name)
3394 (while args
3395 (insert " "
3396 (if (or (= ?& (aref (car args) 0))
3397 (eq (eval (car texinfo-defun-type)) 'deftp-type))
3398 (car args)
3399 (upcase (car args))))
3400 (setq args (cdr args)))))
3401
3402 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
3403 (put 'defun 'texinfo-deffn-formatting-property
3404 'texinfo-format-specialized-defun)
3405 (put 'defunx 'texinfo-deffn-formatting-property
3406 'texinfo-format-specialized-defun)
3407 (put 'defmac 'texinfo-deffn-formatting-property
3408 'texinfo-format-specialized-defun)
3409 (put 'defmacx 'texinfo-deffn-formatting-property
3410 'texinfo-format-specialized-defun)
3411 (put 'defspec 'texinfo-deffn-formatting-property
3412 'texinfo-format-specialized-defun)
3413 (put 'defspecx 'texinfo-deffn-formatting-property
3414 'texinfo-format-specialized-defun)
3415 (put 'defvar 'texinfo-deffn-formatting-property
3416 'texinfo-format-specialized-defun)
3417 (put 'defvarx 'texinfo-deffn-formatting-property
3418 'texinfo-format-specialized-defun)
3419 (put 'defopt 'texinfo-deffn-formatting-property
3420 'texinfo-format-specialized-defun)
3421 (put 'defoptx 'texinfo-deffn-formatting-property
3422 'texinfo-format-specialized-defun)
3423 (defun texinfo-format-specialized-defun (parsed-args)
3424 ;; Specialized function-like or variable-like entity:
3425 ;; @defun name args In Info, `Function: Name ARGS'
3426 ;; @defmac name args In Info, `Macro: Name ARGS'
3427 ;; @defvar name In Info, `Variable: Name'
3428 ;; Use cdr of texinfo-defun-type to determine category:
3429 (let ((category (car (cdr texinfo-defun-type)))
3430 (name (car parsed-args))
3431 (args (cdr parsed-args)))
3432 (insert " -- " category ": " name)
3433 (while args
3434 (insert " "
3435 (if (= ?& (aref (car args) 0))
3436 (car args)
3437 (upcase (car args))))
3438 (setq args (cdr args)))))
3439
3440 ;; @deftypefn, @deftypevr: Generalized typed
3441 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3442 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3443 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3444 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3445 (defun texinfo-format-deftypefn (parsed-args)
3446 ;; Generalized typed-function-like or typed-variable-like entity:
3447 ;; @deftypefn category data-type name args...
3448 ;; In Info, `Category: data-type name args...'
3449 ;; @deftypevr category data-type name
3450 ;; In Info, `Category: data-type name'
3451 ;; Note: args in lower case, unless modified in command line.
3452 (let ((category (car parsed-args))
3453 (data-type (car (cdr parsed-args)))
3454 (name (car (cdr (cdr parsed-args))))
3455 (args (cdr (cdr (cdr parsed-args)))))
3456 (insert " -- " category ": " data-type " " name)
3457 (while args
3458 (insert " " (car args))
3459 (setq args (cdr args)))))
3460
3461 ;; @deftypefun, @deftypevar: Specialized typed
3462 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3463 (put 'deftypefunx 'texinfo-deffn-formatting-property
3464 'texinfo-format-deftypefun)
3465 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3466 (put 'deftypevarx 'texinfo-deffn-formatting-property
3467 'texinfo-format-deftypefun)
3468 (defun texinfo-format-deftypefun (parsed-args)
3469 ;; Specialized typed-function-like or typed-variable-like entity:
3470 ;; @deftypefun data-type name args...
3471 ;; In Info, `Function: data-type name ARGS'
3472 ;; @deftypevar data-type name
3473 ;; In Info, `Variable: data-type name'
3474 ;; Note: args in lower case, unless modified in command line.
3475 ;; Use cdr of texinfo-defun-type to determine category:
3476 (let ((category (car (cdr texinfo-defun-type)))
3477 (data-type (car parsed-args))
3478 (name (car (cdr parsed-args)))
3479 (args (cdr (cdr parsed-args))))
3480 (insert " -- " category ": " data-type " " name)
3481 (while args
3482 (insert " " (car args))
3483 (setq args (cdr args)))))
3484
3485 ;; @defop: Generalized object-oriented
3486 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3487 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3488 (defun texinfo-format-defop (parsed-args)
3489 ;; Generalized object oriented entity:
3490 ;; @defop category class name args...
3491 ;; In Info, `Category on class: name ARG'
3492 ;; Note: args in upper case; use of `on'
3493 (let ((category (car parsed-args))
3494 (class (car (cdr parsed-args)))
3495 (name (car (cdr (cdr parsed-args))))
3496 (args (cdr (cdr (cdr parsed-args)))))
3497 (insert " -- " category " on " class ": " name)
3498 (while args
3499 (insert " " (upcase (car args)))
3500 (setq args (cdr args)))))
3501
3502 ;; @defcv: Generalized object-oriented
3503 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3504 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3505 (defun texinfo-format-defcv (parsed-args)
3506 ;; Generalized object oriented entity:
3507 ;; @defcv category class name
3508 ;; In Info, `Category of class: name'
3509 ;; Note: args in upper case; use of `of'
3510 (let ((category (car parsed-args))
3511 (class (car (cdr parsed-args)))
3512 (name (car (cdr (cdr parsed-args))))
3513 (args (cdr (cdr (cdr parsed-args)))))
3514 (insert " -- " category " of " class ": " name)
3515 (while args
3516 (insert " " (upcase (car args)))
3517 (setq args (cdr args)))))
3518
3519 ;; @defmethod: Specialized object-oriented
3520 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3521 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3522 (defun texinfo-format-defmethod (parsed-args)
3523 ;; Specialized object oriented entity:
3524 ;; @defmethod class name args...
3525 ;; In Info, `Method on class: name ARGS'
3526 ;; Note: args in upper case; use of `on'
3527 ;; Use cdr of texinfo-defun-type to determine category:
3528 (let ((category (car (cdr texinfo-defun-type)))
3529 (class (car parsed-args))
3530 (name (car (cdr parsed-args)))
3531 (args (cdr (cdr parsed-args))))
3532 (insert " -- " category " on " class ": " name)
3533 (while args
3534 (insert " " (upcase (car args)))
3535 (setq args (cdr args)))))
3536
3537 ;; @defivar: Specialized object-oriented
3538 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3539 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3540 (defun texinfo-format-defivar (parsed-args)
3541 ;; Specialized object oriented entity:
3542 ;; @defivar class name
3543 ;; In Info, `Instance variable of class: name'
3544 ;; Note: args in upper case; use of `of'
3545 ;; Use cdr of texinfo-defun-type to determine category:
3546 (let ((category (car (cdr texinfo-defun-type)))
3547 (class (car parsed-args))
3548 (name (car (cdr parsed-args)))
3549 (args (cdr (cdr parsed-args))))
3550 (insert " -- " category " of " class ": " name)
3551 (while args
3552 (insert " " (upcase (car args)))
3553 (setq args (cdr args)))))
3554
3555 \f
3556 ;;; Indexing for definitions
3557
3558 ;; An index entry has three parts: the `entry proper', the node name, and the
3559 ;; line number. Depending on the which command is used, the entry is
3560 ;; formatted differently:
3561 ;;
3562 ;; @defun,
3563 ;; @defmac,
3564 ;; @defspec,
3565 ;; @defvar,
3566 ;; @defopt all use their 1st argument as the entry-proper
3567 ;;
3568 ;; @deffn,
3569 ;; @defvr,
3570 ;; @deftp
3571 ;; @deftypefun
3572 ;; @deftypevar all use their 2nd argument as the entry-proper
3573 ;;
3574 ;; @deftypefn,
3575 ;; @deftypevr both use their 3rd argument as the entry-proper
3576 ;;
3577 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
3578 ;; formatted: NAME on CLASS
3579
3580 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
3581 ;; formatted: NAME on CLASS
3582 ;;
3583 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
3584 ;; formatted: NAME of CLASS
3585 ;;
3586 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
3587 ;; formatted: NAME of CLASS
3588
3589 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
3590 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3591 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
3592 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3593 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
3594 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3595 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
3596 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3597 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
3598 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3599 (defun texinfo-index-defun (parsed-args)
3600 ;; use 1st parsed-arg as entry-proper
3601 ;; `index-list' will be texinfo-findex or the like
3602 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3603 (set index-list
3604 (cons
3605 ;; Three elements: entry-proper, node-name, line-number
3606 (list
3607 (car parsed-args)
3608 texinfo-last-node
3609 ;; Region formatting may not provide last node position.
3610 (if texinfo-last-node-pos
3611 (1+ (count-lines texinfo-last-node-pos (point)))
3612 1))
3613 (symbol-value index-list)))))
3614
3615 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3616 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3617 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3618 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3619 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3620 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3621 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3622 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3623 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3624 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3625 (defun texinfo-index-deffn (parsed-args)
3626 ;; use 2nd parsed-arg as entry-proper
3627 ;; `index-list' will be texinfo-findex or the like
3628 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3629 (set index-list
3630 (cons
3631 ;; Three elements: entry-proper, node-name, line-number
3632 (list
3633 (car (cdr parsed-args))
3634 texinfo-last-node
3635 ;; Region formatting may not provide last node position.
3636 (if texinfo-last-node-pos
3637 (1+ (count-lines texinfo-last-node-pos (point)))
3638 1))
3639 (symbol-value index-list)))))
3640
3641 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3642 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3643 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3644 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3645 (defun texinfo-index-deftypefn (parsed-args)
3646 ;; use 3rd parsed-arg as entry-proper
3647 ;; `index-list' will be texinfo-findex or the like
3648 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3649 (set index-list
3650 (cons
3651 ;; Three elements: entry-proper, node-name, line-number
3652 (list
3653 (car (cdr (cdr parsed-args)))
3654 texinfo-last-node
3655 ;; Region formatting may not provide last node position.
3656 (if texinfo-last-node-pos
3657 (1+ (count-lines texinfo-last-node-pos (point)))
3658 1))
3659 (symbol-value index-list)))))
3660
3661 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3662 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3663 (defun texinfo-index-defmethod (parsed-args)
3664 ;; use 2nd on 1st parsed-arg as entry-proper
3665 ;; `index-list' will be texinfo-findex or the like
3666 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3667 (set index-list
3668 (cons
3669 ;; Three elements: entry-proper, node-name, line-number
3670 (list
3671 (format "%s on %s"
3672 (car (cdr parsed-args))
3673 (car parsed-args))
3674 texinfo-last-node
3675 ;; Region formatting may not provide last node position.
3676 (if texinfo-last-node-pos
3677 (1+ (count-lines texinfo-last-node-pos (point)))
3678 1))
3679 (symbol-value index-list)))))
3680
3681 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
3682 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
3683 (defun texinfo-index-defop (parsed-args)
3684 ;; use 3rd on 2nd parsed-arg as entry-proper
3685 ;; `index-list' will be texinfo-findex or the like
3686 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3687 (set index-list
3688 (cons
3689 ;; Three elements: entry-proper, node-name, line-number
3690 (list
3691 (format "%s on %s"
3692 (car (cdr (cdr parsed-args)))
3693 (car (cdr parsed-args)))
3694 texinfo-last-node
3695 ;; Region formatting may not provide last node position.
3696 (if texinfo-last-node-pos
3697 (1+ (count-lines texinfo-last-node-pos (point)))
3698 1))
3699 (symbol-value index-list)))))
3700
3701 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3702 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3703 (defun texinfo-index-defivar (parsed-args)
3704 ;; use 2nd of 1st parsed-arg as entry-proper
3705 ;; `index-list' will be texinfo-findex or the like
3706 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3707 (set index-list
3708 (cons
3709 ;; Three elements: entry-proper, node-name, line-number
3710 (list
3711 (format "%s of %s"
3712 (car (cdr parsed-args))
3713 (car parsed-args))
3714 texinfo-last-node
3715 ;; Region formatting may not provide last node position.
3716 (if texinfo-last-node-pos
3717 (1+ (count-lines texinfo-last-node-pos (point)))
3718 1))
3719 (symbol-value index-list)))))
3720
3721 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3722 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3723 (defun texinfo-index-defcv (parsed-args)
3724 ;; use 3rd of 2nd parsed-arg as entry-proper
3725 ;; `index-list' will be texinfo-findex or the like
3726 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3727 (set index-list
3728 (cons
3729 ;; Three elements: entry-proper, node-name, line-number
3730 (list
3731 (format "%s of %s"
3732 (car (cdr (cdr parsed-args)))
3733 (car (cdr parsed-args)))
3734 texinfo-last-node
3735 ;; Region formatting may not provide last node position.
3736 (if texinfo-last-node-pos
3737 (1+ (count-lines texinfo-last-node-pos (point)))
3738 1))
3739 (symbol-value index-list)))))
3740
3741 \f
3742 ;;; Properties for definitions
3743
3744 ;; Each definition command has six properties:
3745 ;;
3746 ;; 1. texinfo-deffn-formatting-property to format definition line
3747 ;; 2. texinfo-defun-indexing-property to create index entry
3748 ;; 3. texinfo-format formatting command
3749 ;; 4. texinfo-end end formatting command
3750 ;; 5. texinfo-defun-type type of deffn to format
3751 ;; 6. texinfo-defun-index type of index to use
3752 ;;
3753 ;; The `x' forms of each definition command are used for the second
3754 ;; and subsequent header lines.
3755
3756 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
3757 ;; are listed just before the appropriate formatting and indexing commands.
3758
3759 (put 'deffn 'texinfo-format 'texinfo-format-defun)
3760 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
3761 (put 'deffn 'texinfo-end 'texinfo-end-defun)
3762 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
3763 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
3764 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
3765 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
3766
3767 (put 'defun 'texinfo-format 'texinfo-format-defun)
3768 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
3769 (put 'defun 'texinfo-end 'texinfo-end-defun)
3770 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
3771 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
3772 (put 'defun 'texinfo-defun-index 'texinfo-findex)
3773 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
3774
3775 (put 'defmac 'texinfo-format 'texinfo-format-defun)
3776 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
3777 (put 'defmac 'texinfo-end 'texinfo-end-defun)
3778 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
3779 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
3780 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
3781 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
3782
3783 (put 'defspec 'texinfo-format 'texinfo-format-defun)
3784 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
3785 (put 'defspec 'texinfo-end 'texinfo-end-defun)
3786 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
3787 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
3788 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
3789 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
3790
3791 (put 'defvr 'texinfo-format 'texinfo-format-defun)
3792 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
3793 (put 'defvr 'texinfo-end 'texinfo-end-defun)
3794 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
3795 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
3796 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
3797 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
3798
3799 (put 'defvar 'texinfo-format 'texinfo-format-defun)
3800 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
3801 (put 'defvar 'texinfo-end 'texinfo-end-defun)
3802 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
3803 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
3804 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
3805 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
3806
3807 (put 'defconst 'texinfo-format 'texinfo-format-defun)
3808 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
3809 (put 'defconst 'texinfo-end 'texinfo-end-defun)
3810 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
3811 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
3812 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
3813 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
3814
3815 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
3816 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
3817 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
3818 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
3819 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
3820 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
3821 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
3822
3823 (put 'defopt 'texinfo-format 'texinfo-format-defun)
3824 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
3825 (put 'defopt 'texinfo-end 'texinfo-end-defun)
3826 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
3827 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
3828 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
3829 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
3830
3831 (put 'deftp 'texinfo-format 'texinfo-format-defun)
3832 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
3833 (put 'deftp 'texinfo-end 'texinfo-end-defun)
3834 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
3835 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
3836 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
3837 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
3838
3839 ;;; Object-oriented stuff is a little hairier.
3840
3841 (put 'defop 'texinfo-format 'texinfo-format-defun)
3842 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
3843 (put 'defop 'texinfo-end 'texinfo-end-defun)
3844 (put 'defop 'texinfo-defun-type '('defop-type nil))
3845 (put 'defopx 'texinfo-defun-type '('defop-type nil))
3846 (put 'defop 'texinfo-defun-index 'texinfo-findex)
3847 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
3848
3849 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
3850 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
3851 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
3852 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
3853 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
3854 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
3855 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
3856
3857 (put 'defcv 'texinfo-format 'texinfo-format-defun)
3858 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
3859 (put 'defcv 'texinfo-end 'texinfo-end-defun)
3860 (put 'defcv 'texinfo-defun-type '('defop-type nil))
3861 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
3862 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
3863 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
3864
3865 (put 'defivar 'texinfo-format 'texinfo-format-defun)
3866 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
3867 (put 'defivar 'texinfo-end 'texinfo-end-defun)
3868 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
3869 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
3870 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
3871 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
3872
3873 ;;; Typed functions and variables
3874
3875 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
3876 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
3877 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
3878 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
3879 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
3880 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
3881 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
3882
3883 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
3884 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
3885 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
3886 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
3887 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
3888 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
3889 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
3890
3891 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
3892 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
3893 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
3894 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
3895 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
3896 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
3897 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
3898
3899 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
3900 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
3901 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
3902 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
3903 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
3904 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
3905 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
3906
3907 \f
3908 ;;; @set, @clear, @ifset, @ifclear
3909
3910 ;; If a flag is set with @set FLAG, then text between @ifset and @end
3911 ;; ifset is formatted normally, but if the flag is is cleared with
3912 ;; @clear FLAG, then the text is not formatted; it is ignored.
3913
3914 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
3915 ;; and @end ifclear is formatted normally, but if the flag is is set with
3916 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
3917 ;; is the opposite of @ifset.
3918
3919 ;; If a flag is set to a string with @set FLAG,
3920 ;; replace @value{FLAG} with the string.
3921 ;; If a flag with a value is cleared,
3922 ;; @value{FLAG} is invalid,
3923 ;; as if there had never been any @set FLAG previously.
3924
3925 (put 'clear 'texinfo-format 'texinfo-clear)
3926 (defun texinfo-clear ()
3927 "Clear the value of the flag."
3928 (let* ((arg (texinfo-parse-arg-discard))
3929 (flag (car (read-from-string arg)))
3930 (value (substring arg (cdr (read-from-string arg)))))
3931 (put flag 'texinfo-whether-setp 'flag-cleared)
3932 (put flag 'texinfo-set-value "")))
3933
3934 (put 'set 'texinfo-format 'texinfo-set)
3935 (defun texinfo-set ()
3936 "Set the value of the flag, optionally to a string.
3937 The command `@set foo This is a string.'
3938 sets flag foo to the value: `This is a string.'
3939 The command `@value{foo}' expands to the value."
3940 (let* ((arg (texinfo-parse-arg-discard))
3941 (flag (car (read-from-string arg)))
3942 (value (substring arg (cdr (read-from-string arg)))))
3943 (if (string-match "^[ \t]+" value)
3944 (setq value (substring value (match-end 0))))
3945 (put flag 'texinfo-whether-setp 'flag-set)
3946 (put flag 'texinfo-set-value value)))
3947
3948 (put 'value 'texinfo-format 'texinfo-value)
3949 (defun texinfo-value ()
3950 "Insert the string to which the flag is set.
3951 The command `@set foo This is a string.'
3952 sets flag foo to the value: `This is a string.'
3953 The command `@value{foo}' expands to the value."
3954 (let ((arg (texinfo-parse-arg-discard)))
3955 (cond ((and
3956 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3957 'flag-set)
3958 (get (car (read-from-string arg)) 'texinfo-set-value))
3959 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
3960 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3961 'flag-cleared)
3962 (insert (format "{No value for \"%s\"}" arg)))
3963 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
3964 (insert (format "{No value for \"%s\"}" arg))))))
3965
3966 (put 'ifset 'texinfo-end 'texinfo-discard-command)
3967 (put 'ifset 'texinfo-format 'texinfo-if-set)
3968 (defun texinfo-if-set ()
3969 "If set, continue formatting; else do not format region up to @end ifset."
3970 (let ((arg (texinfo-parse-arg-discard)))
3971 (cond
3972 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3973 'flag-set)
3974 ;; Format the text (i.e., do not remove it); do nothing here.
3975 ())
3976 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3977 'flag-cleared)
3978 ;; Clear region (i.e., cause the text to be ignored).
3979 (delete-region texinfo-command-start
3980 (re-search-forward "@end ifset[ \t]*\n")))
3981 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3982 nil)
3983 ;; In this case flag is neither set nor cleared.
3984 ;; Act as if set, i.e. do nothing.
3985 ()))))
3986
3987 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
3988 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
3989 (defun texinfo-if-clear ()
3990 "If clear, continue formatting; if set, do not format up to @end ifset."
3991 (let ((arg (texinfo-parse-arg-discard)))
3992 (cond
3993 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3994 'flag-set)
3995 ;; Clear region (i.e., cause the text to be ignored).
3996 (delete-region texinfo-command-start
3997 (re-search-forward "@end ifclear[ \t]*\n")))
3998 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
3999 'flag-cleared)
4000 ;; Format the text (i.e., do not remove it); do nothing here.
4001 ())
4002 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4003 nil)
4004 ;; In this case flag is neither set nor cleared.
4005 ;; Act as if clear, i.e. do nothing.
4006 ()))))
4007 \f
4008 ;;; @ifeq
4009
4010 (put 'ifeq 'texinfo-format 'texinfo-format-ifeq)
4011 (defun texinfo-format-ifeq ()
4012 "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND.
4013 Otherwise produces no output.
4014
4015 Thus:
4016 @ifeq{ arg1 , arg1 , @code{foo}} bar
4017
4018 ==> `foo' bar.
4019 but
4020 @ifeq{ arg1 , arg2 , @code{foo}} bar
4021
4022 ==> bar
4023
4024 Note that the Texinfo command and its arguments must be arguments to
4025 the @ifeq command."
4026 ;; compare-buffer-substrings does not exist in version 18; don't use
4027 (goto-char texinfo-command-end)
4028 (let* ((case-fold-search t)
4029 (stop (save-excursion (forward-sexp 1) (point)))
4030 start end
4031 ;; @ifeq{arg1, arg2, @command{optional-args}}
4032 (arg1
4033 (progn
4034 (forward-char 1)
4035 (skip-chars-forward " ")
4036 (setq start (point))
4037 (search-forward "," stop t)
4038 (skip-chars-backward ", ")
4039 (buffer-substring-no-properties start (point))))
4040 (arg2
4041 (progn
4042 (search-forward "," stop t)
4043 (skip-chars-forward " ")
4044 (setq start (point))
4045 (search-forward "," stop t)
4046 (skip-chars-backward ", ")
4047 (buffer-substring-no-properties start (point))))
4048 (texinfo-command
4049 (progn
4050 (search-forward "," stop t)
4051 (skip-chars-forward " ")
4052 (setq start (point))
4053 (goto-char (1- stop))
4054 (skip-chars-backward " ")
4055 (buffer-substring-no-properties start (point)))))
4056 (delete-region texinfo-command-start stop)
4057 (if (equal arg1 arg2)
4058 (insert texinfo-command))
4059 (goto-char texinfo-command-start)))
4060
4061 \f
4062 ;;; Process included files: `@include' command
4063
4064 ;; Updated 19 October 1990
4065 ;; In the original version, include files were ignored by Info but
4066 ;; incorporated in to the printed manual. To make references to the
4067 ;; included file, the Texinfo source file has to refer to the included
4068 ;; files using the `(filename)nodename' format for referring to other
4069 ;; Info files. Also, the included files had to be formatted on their
4070 ;; own. It was just like they were another file.
4071
4072 ;; Currently, include files are inserted into the buffer that is
4073 ;; formatted for Info. If large, the resulting info file is split and
4074 ;; tagified. For current include files to work, the master menu must
4075 ;; refer to all the nodes, and the highest level nodes in the include
4076 ;; files must have the correct next, prev, and up pointers.
4077
4078 ;; The included file may have an @setfilename and even an @settitle,
4079 ;; but not an `\input texinfo' line.
4080
4081 ;; Updated 24 March 1993
4082 ;; In order for @raisesections and @lowersections to work, included
4083 ;; files must be inserted into the buffer holding the outer file
4084 ;; before other Info formatting takes place. So @include is no longer
4085 ;; is treated like other @-commands.
4086 (put 'include 'texinfo-format 'texinfo-format-noop)
4087
4088 ;; Original definition:
4089 ;; (defun texinfo-format-include ()
4090 ;; (let ((filename (texinfo-parse-arg-discard))
4091 ;; (default-directory input-directory)
4092 ;; subindex)
4093 ;; (setq subindex
4094 ;; (save-excursion
4095 ;; (progn (find-file
4096 ;; (cond ((file-readable-p (concat filename ".texinfo"))
4097 ;; (concat filename ".texinfo"))
4098 ;; ((file-readable-p (concat filename ".texi"))
4099 ;; (concat filename ".texi"))
4100 ;; ((file-readable-p (concat filename ".tex"))
4101 ;; (concat filename ".tex"))
4102 ;; ((file-readable-p filename)
4103 ;; filename)
4104 ;; (t (error "@include'd file %s not found"
4105 ;; filename))))
4106 ;; (texinfo-format-buffer-1))))
4107 ;; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
4108 ;; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
4109 ;; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
4110 ;; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
4111 ;; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
4112 ;; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
4113 ;;
4114 ;;(defun texinfo-subindex (indexvar file content)
4115 ;; (set indexvar (cons (list 'recurse file content)
4116 ;; (symbol-value indexvar))))
4117
4118 ;; Second definition:
4119 ;; (put 'include 'texinfo-format 'texinfo-format-include)
4120 ;; (defun texinfo-format-include ()
4121 ;; (let ((filename (concat input-directory
4122 ;; (texinfo-parse-arg-discard)))
4123 ;; (default-directory input-directory))
4124 ;; (message "Reading: %s" filename)
4125 ;; (save-excursion
4126 ;; (save-restriction
4127 ;; (narrow-to-region
4128 ;; (point)
4129 ;; (+ (point) (car (cdr (insert-file-contents filename)))))
4130 ;; (goto-char (point-min))
4131 ;; (texinfo-append-refill)
4132 ;; (texinfo-format-convert (point-min) (point-max))))
4133 ;; (setq last-input-buffer input-buffer) ; to bypass setfilename
4134 ;; ))
4135
4136 \f
4137 ;;; Numerous commands do nothing in Info
4138 ;; These commands are defined in texinfo.tex for printed output.
4139
4140 \f
4141 ;;; various noops, such as @b{foo}, that take arguments in braces
4142
4143 (put 'b 'texinfo-format 'texinfo-format-noop)
4144 (put 'i 'texinfo-format 'texinfo-format-noop)
4145 (put 'r 'texinfo-format 'texinfo-format-noop)
4146 (put 't 'texinfo-format 'texinfo-format-noop)
4147 (put 'w 'texinfo-format 'texinfo-format-noop)
4148 (put 'asis 'texinfo-format 'texinfo-format-noop)
4149 (put 'dmn 'texinfo-format 'texinfo-format-noop)
4150 (put 'math 'texinfo-format 'texinfo-format-noop)
4151 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
4152 (defun texinfo-format-noop ()
4153 (insert (texinfo-parse-arg-discard))
4154 (goto-char texinfo-command-start))
4155
4156 ;; @hyphenation command discards an argument within braces
4157 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
4158 (defun texinfo-discard-command-and-arg ()
4159 "Discard both @-command and its argument in braces."
4160 (goto-char texinfo-command-end)
4161 (forward-list 1)
4162 (setq texinfo-command-end (point))
4163 (delete-region texinfo-command-start texinfo-command-end))
4164
4165 \f
4166 ;;; Do nothing commands, such as @smallbook, that have no args and no braces
4167 ;; These must appear on a line of their own
4168
4169 (put 'bye 'texinfo-format 'texinfo-discard-line)
4170 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
4171 (put 'finalout 'texinfo-format 'texinfo-discard-line)
4172 (put 'overfullrule 'texinfo-format 'texinfo-discard-line)
4173 (put 'smallbreak 'texinfo-format 'texinfo-discard-line)
4174 (put 'medbreak 'texinfo-format 'texinfo-discard-line)
4175 (put 'bigbreak 'texinfo-format 'texinfo-discard-line)
4176 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
4177 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
4178 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
4179 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
4180
4181 \f
4182 ;;; These noop commands discard the rest of the line.
4183
4184 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
4185 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
4186 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
4187 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
4188 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
4189 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
4190 (put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args)
4191 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
4192 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
4193 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
4194 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
4195 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
4196
4197 ;; @novalidate suppresses cross-reference checking and auxiliary file
4198 ;; creation with TeX. The Info-validate command checks that every
4199 ;; node pointer points to an existing node. Since this Info command
4200 ;; is not invoked automatically, the @novalidate command is irrelevant
4201 ;; and not supported by texinfmt.el
4202 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
4203
4204 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
4205 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
4206 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
4207 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
4208 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
4209
4210 (put 'setcontentsaftertitlepage
4211 'texinfo-format 'texinfo-discard-line-with-args)
4212 (put 'setshortcontentsaftertitlepage
4213 'texinfo-format 'texinfo-discard-line-with-args)
4214
4215 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
4216 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
4217 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
4218 (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args)
4219 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
4220 (put 'input 'texinfo-format 'texinfo-discard-line-with-args)
4221
4222 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
4223 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
4224
4225
4226 \f
4227 ;;; Some commands cannot be handled
4228
4229 (defun texinfo-unsupported ()
4230 (error "%s is not handled by texinfo"
4231 (buffer-substring-no-properties texinfo-command-start texinfo-command-end)))
4232 \f
4233 ;;; Batch formatting
4234
4235 (defun batch-texinfo-format ()
4236 "Run `texinfo-format-buffer' on the files remaining on the command line.
4237 Must be used only with -batch, and kills Emacs on completion.
4238 Each file will be processed even if an error occurred previously.
4239 For example, invoke
4240 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
4241 (if (not noninteractive)
4242 (error "batch-texinfo-format may only be used -batch"))
4243 (let ((version-control t)
4244 (auto-save-default nil)
4245 (find-file-run-dired nil)
4246 (kept-old-versions 259259)
4247 (kept-new-versions 259259))
4248 (let ((error 0)
4249 file
4250 (files ()))
4251 (while command-line-args-left
4252 (setq file (expand-file-name (car command-line-args-left)))
4253 (cond ((not (file-exists-p file))
4254 (message ">> %s does not exist!" file)
4255 (setq error 1
4256 command-line-args-left (cdr command-line-args-left)))
4257 ((file-directory-p file)
4258 (setq command-line-args-left
4259 (nconc (directory-files file)
4260 (cdr command-line-args-left))))
4261 (t
4262 (push file files)
4263 (setq command-line-args-left (cdr command-line-args-left)))))
4264 (while files
4265 (setq file (car files)
4266 files (cdr files))
4267 (condition-case err
4268 (progn
4269 (if buffer-file-name (kill-buffer (current-buffer)))
4270 (find-file file)
4271 (buffer-disable-undo (current-buffer))
4272 (set-buffer-modified-p nil)
4273 (texinfo-mode)
4274 (message "texinfo formatting %s..." file)
4275 (texinfo-format-buffer nil)
4276 (if (buffer-modified-p)
4277 (progn (message "Saving modified %s" (buffer-file-name))
4278 (save-buffer))))
4279 (error
4280 (message ">> Error: %s" (prin1-to-string err))
4281 (message ">> point at")
4282 (let ((s (buffer-substring-no-properties (point)
4283 (min (+ (point) 100)
4284 (point-max))))
4285 (tem 0))
4286 (while (setq tem (string-match "\n+" s tem))
4287 (setq s (concat (substring s 0 (match-beginning 0))
4288 "\n>> "
4289 (substring s (match-end 0)))
4290 tem (1+ tem)))
4291 (message ">> %s" s))
4292 (setq error 1))))
4293 (kill-emacs error))))
4294
4295 \f
4296 ;;; Place `provide' at end of file.
4297 (provide 'texinfmt)
4298
4299 ;;; texinfmt.el ends here