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