2 ;;; Copyright (C) 1985, 1986, 1988,
3 ;;; 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
5 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
7 ;;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; Emacs lisp functions to convert Texinfo files to Info files.
27 (defvar texinfmt-version "2.31 of 10 November 1993")
29 ;;; Variable definitions
31 (require 'texinfo) ; So `texinfo-footnote-style' is defined.
32 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
34 (defvar texinfo-format-syntax-table nil)
36 (defvar texinfo-vindex)
37 (defvar texinfo-findex)
38 (defvar texinfo-cindex)
39 (defvar texinfo-pindex)
40 (defvar texinfo-tindex)
41 (defvar texinfo-kindex)
42 (defvar texinfo-last-node)
43 (defvar texinfo-node-names)
44 (defvar texinfo-enclosure-list)
46 (defvar texinfo-command-start)
47 (defvar texinfo-command-end)
48 (defvar texinfo-command-name)
49 (defvar texinfo-defun-type)
50 (defvar texinfo-last-node-pos)
51 (defvar texinfo-stack)
52 (defvar texinfo-short-index-cmds-alist)
53 (defvar texinfo-short-index-format-cmds-alist)
54 (defvar texinfo-format-filename)
55 (defvar texinfo-footnote-number)
56 (defvar texinfo-start-of-header)
57 (defvar texinfo-end-of-header)
58 (defvar texinfo-raisesections-alist)
59 (defvar texinfo-lowersections-alist)
63 (if texinfo-format-syntax-table
65 (setq texinfo-format-syntax-table (make-syntax-table))
66 (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
67 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
68 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
69 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
70 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
71 (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
72 (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
73 (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
74 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
75 (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
76 (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
79 ;;; Top level buffer and region formatting functions
82 (defun texinfo-format-buffer (&optional notagify)
83 "Process the current buffer as texinfo code, into an Info file.
84 The Info file output is generated in a buffer visiting the Info file
85 names specified in the @setfilename command.
87 Non-nil argument (prefix, if interactive) means don't make tag table
88 and don't split the file if large. You can use Info-tagify and
89 Info-split to do these manually."
91 (let ((lastmessage "Formatting Info file..."))
93 (texinfo-format-buffer-1)
96 (if (> (buffer-size) 30000)
98 (message (setq lastmessage "Making tags table for Info file..."))
100 (if (> (buffer-size) 100000)
102 (message (setq lastmessage "Splitting Info file..."))
104 (message (concat lastmessage
105 (if (interactive-p) "done. Now save it." "done.")))))
107 (defvar texinfo-region-buffer-name "*Info Region*"
108 "*Name of the temporary buffer used by \\[texinfo-format-region].")
111 (defun texinfo-format-region (region-beginning region-end)
112 "Convert the current region of the Texinfo file to Info format.
113 This lets you see what that part of the file will look like in Info.
114 The command is bound to \\[texinfo-format-region]. The text that is
115 converted to Info is stored in a temporary buffer."
117 (message "Converting region to Info format...")
118 (let (texinfo-command-start
128 (texinfo-format-filename "")
129 texinfo-example-start
130 texinfo-last-node-pos
133 (texinfo-footnote-number 0)
135 (fill-column-for-info fill-column)
136 (input-buffer (current-buffer))
137 (input-directory default-directory)
142 ;;; Copy lines between beginning and end of header lines,
143 ;;; if any, or else copy the `@setfilename' line, if any.
147 (goto-char (point-min))
148 (let ((search-end (save-excursion (forward-line 100) (point))))
150 ;; Either copy header text.
153 (search-forward tex-start-of-header search-end t)
155 ;; Mark beginning of header.
156 (setq header-beginning (point)))
158 (search-forward tex-end-of-header nil t)
160 ;; Mark end of header
161 (setq header-end (point))))
162 ;; Or copy @filename line.
164 (goto-char (point-min))
165 (search-forward "@setfilename" search-end t)
167 (setq header-beginning (point))
169 (setq header-end (point))))
174 (min header-beginning region-beginning)
177 ;;; Find a buffer to use.
178 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
180 ;; Insert the header into the buffer.
182 ;; Insert the region into the buffer.
183 (insert-buffer-substring
185 (max region-beginning header-end)
187 ;; Make sure region ends in a newline.
188 (or (= (preceding-char) ?\n)
191 (goto-char (point-min))
193 (message "Converting region to Info format...")
194 (setq fill-column fill-column-for-info)
195 ;; Install a syntax table useful for scanning command operands.
196 (set-syntax-table texinfo-format-syntax-table)
198 ;; Insert @include files so `texinfo-raise-lower-sections' can
199 ;; work on them without losing track of multiple
200 ;; @raise/@lowersections commands.
201 (while (re-search-forward "^@include" nil t)
202 (setq texinfo-command-end (point))
203 (let ((filename (concat input-directory
204 (texinfo-parse-line-arg))))
206 (delete-region (point) (save-excursion (forward-line 1) (point)))
207 (message "Reading included file: %s" filename)
212 (+ (point) (car (cdr (insert-file-contents filename)))))
213 (goto-char (point-min))
214 ;; Remove `@setfilename' line from included file, if any,
215 ;; so @setfilename command not duplicated.
216 (if (re-search-forward
217 "^@setfilename" (save-excursion (forward-line 100) (point)) t)
221 (point) (save-excursion (forward-line 1) (point)))))))))
223 ;; Raise or lower level of each section, if necessary.
224 (goto-char (point-min))
225 (texinfo-raise-lower-sections)
226 ;; Append @refill to appropriate paragraphs for filling.
227 (goto-char (point-min))
228 (texinfo-append-refill)
229 ;; If the region includes the effective end of the data,
230 ;; discard everything after that.
231 (goto-char (point-max))
232 (if (re-search-backward "^@bye" nil t)
233 (delete-region (point) (point-max)))
234 ;; Make sure buffer ends in a newline.
235 (or (= (preceding-char) ?\n)
237 ;; Don't use a previous value of texinfo-enclosure-list.
238 (setq texinfo-enclosure-list nil)
240 (goto-char (point-min))
241 (if (looking-at "\\\\input[ \t]+texinfo")
242 (delete-region (point) (save-excursion (forward-line 1) (point))))
244 ;; Insert Info region title text.
245 (goto-char (point-min))
247 "@setfilename" (save-excursion (forward-line 100) (point)) t)
249 (setq texinfo-command-end (point))
251 (setq texinfo-command-start (point))
252 (let ((arg (texinfo-parse-arg-discard)))
254 texinfo-region-buffer-name
256 (insert (file-name-nondirectory (expand-file-name arg)))
257 (insert "', -*-Text-*-\n")))
258 ;; Else no `@setfilename' line
260 texinfo-region-buffer-name
261 " buffer -*-Text-*-\n"))
262 (insert "produced by `texinfo-format-region'\n"
264 (if (buffer-file-name input-buffer)
266 (file-name-sans-versions
267 (file-name-nondirectory
268 (buffer-file-name input-buffer)))
270 (concat "buffer `" (buffer-name input-buffer) "'"))
271 "\nusing `texinfmt.el' version "
275 ;; Now convert for real.
276 (goto-char (point-min))
277 (texinfo-format-scan)
278 (goto-char (point-min))
283 ;;; Primary internal formatting function for the whole buffer.
285 (defun texinfo-format-buffer-1 ()
286 (let (texinfo-format-filename
287 texinfo-example-start
288 texinfo-command-start
292 texinfo-last-node-pos
301 (texinfo-footnote-number 0)
304 (fill-column-for-info fill-column)
305 (input-buffer (current-buffer))
306 (input-directory default-directory))
307 (setq texinfo-enclosure-list nil)
309 (goto-char (point-min))
310 (or (search-forward "@setfilename" nil t)
311 (error "Texinfo file needs an `@setfilename FILENAME' line."))
312 (setq texinfo-command-end (point))
313 (setq outfile (texinfo-parse-line-arg)))
316 (setq fill-column fill-column-for-info)
317 (set-syntax-table texinfo-format-syntax-table)
319 (insert-buffer-substring input-buffer)
320 (message "Converting %s to Info format..." (buffer-name input-buffer))
322 ;; Insert @include files so `texinfo-raise-lower-sections' can
323 ;; work on them without losing track of multiple
324 ;; @raise/@lowersections commands.
325 (goto-char (point-min))
326 (while (re-search-forward "^@include" nil t)
327 (setq texinfo-command-end (point))
328 (let ((filename (concat input-directory
329 (texinfo-parse-line-arg))))
331 (delete-region (point) (save-excursion (forward-line 1) (point)))
332 (message "Reading included file: %s" filename)
337 (+ (point) (car (cdr (insert-file-contents filename)))))
338 (goto-char (point-min))
339 ;; Remove `@setfilename' line from included file, if any,
340 ;; so @setfilename command not duplicated.
341 (if (re-search-forward
343 (save-excursion (forward-line 100) (point)) t)
347 (point) (save-excursion (forward-line 1) (point)))))))))
348 ;; Raise or lower level of each section, if necessary.
349 (goto-char (point-min))
350 (texinfo-raise-lower-sections)
351 ;; Append @refill to appropriate paragraphs
352 (goto-char (point-min))
353 (texinfo-append-refill)
354 (goto-char (point-min))
355 (search-forward "@setfilename")
357 (delete-region (point-min) (point))
358 ;; Remove @bye at end of file, if it is there.
359 (goto-char (point-max))
360 (if (search-backward "@bye" nil t)
361 (delete-region (point) (point-max)))
362 ;; Make sure buffer ends in a newline.
363 (or (= (preceding-char) ?\n)
365 ;; Scan the whole buffer, converting to Info format.
366 (texinfo-format-scan)
367 ;; Return data for indices.
368 (goto-char (point-min))
370 texinfo-vindex texinfo-findex texinfo-cindex
371 texinfo-pindex texinfo-tindex texinfo-kindex)))
374 ;;; Perform non-@-command file conversions: quotes and hyphens
376 (defun texinfo-format-convert (min max)
377 ;; Convert left and right quotes to typewriter font quotes.
379 (while (search-forward "``" max t)
380 (replace-match "\""))
382 (while (search-forward "''" max t)
383 (replace-match "\""))
384 ;; Convert three hyphens in a row to two.
386 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
387 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
391 ;;; Handle paragraph filling
393 (defvar texinfo-no-refill-regexp
394 "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|tex\\)"
395 "Regexp specifying environments in which paragraphs are not filled.")
397 (defvar texinfo-part-of-para-regexp
398 "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
399 "Regexp specifying @-commands found within paragraphs.")
401 (defun texinfo-append-refill ()
402 "Append @refill at end of each paragraph that should be filled.
403 Do not append @refill to paragraphs within @example and similar environments.
404 Do not append @refill to paragraphs containing @w{TEXT} or @*."
406 ;; It is necessary to append @refill before other processing because
407 ;; the other processing removes information that tells Texinfo
408 ;; whether the text should or should not be filled.
410 (while (< (point) (point-max))
411 (let ((refill-blank-lines "^[ \t\n]*$")
412 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
414 ;; 1. Skip over blank lines;
415 ;; skip over lines beginning with @-commands,
416 ;; but do not skip over lines
417 ;; that are no-refill environments such as @example or
418 ;; that begin with within-paragraph @-commands such as @code.
419 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
423 texinfo-no-refill-regexp
425 texinfo-part-of-para-regexp
427 (< (point) (point-max)))
429 ;; 2. Skip over @example and similar no-refill environments.
430 (if (looking-at texinfo-no-refill-regexp)
432 (buffer-substring (match-beginning 1) (match-end 1))))
433 (progn (re-search-forward (concat "^@end " environment) nil t)
435 ;; 3. Do not refill a paragraph containing @w or @*
437 (>= (point) (point-max))
439 "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t))
440 ;; Go to end of paragraph and do nothing.
442 ;; 4. Else go to end of paragraph and insert @refill
448 (save-excursion (skip-chars-backward " \t") (point)))
449 ;; `looking-at-backward' not available in v. 18.57
450 ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
451 (if (not (re-search-backward
453 (save-excursion (beginning-of-line) (point))
456 (forward-line 1))))))
459 ;;; Handle `@raisesections' and `@lowersections' commands
461 ;; These commands change the hierarchical level of chapter structuring
464 ;; @raisesections changes @subsection to @section,
465 ;; @section to @chapter,
468 ;; @lowersections changes @chapter to @section
469 ;; @subsection to @subsubsection,
472 ;; An @raisesections/@lowersections command changes only those
473 ;; structuring commands that follow the @raisesections/@lowersections
476 ;; Repeated @raisesections/@lowersections continue to raise or lower
477 ;; the heading level.
479 ;; An @lowersections command cancels an @raisesections command, and
482 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
483 ;; trying to do so does not elicit an error---you just get more
484 ;; headings that mean the same thing as you keep raising or lowering
485 ;; (for example, after a single @raisesections, both @chapter and
486 ;; @section produce chapter headings).
488 (defun texinfo-raise-lower-sections ()
489 "Raise or lower the hierarchical level of chapters, sections, etc.
491 This function acts according to `@raisesections' and `@lowersections'
492 commands in the Texinfo file.
494 For example, an `@lowersections' command is useful if you wish to
495 include what is written as an outer or standalone Texinfo file in
496 another Texinfo file as an inner, included file. The `@lowersections'
497 command changes chapters to sections, sections to subsections and so
500 @raisesections changes @subsection to @section,
501 @section to @chapter,
502 @heading to @chapheading,
505 @lowersections changes @chapter to @section,
506 @subsection to @subsubsection,
507 @heading to @subheading,
510 An `@raisesections' or `@lowersections' command changes only those
511 structuring commands that follow the `@raisesections' or
512 `@lowersections' command.
514 An `@lowersections' command cancels an `@raisesections' command, and
517 Repeated use of the commands continue to raise or lower the hierarchical
518 level a step at a time.
520 An attempt to raise above `chapters' reproduces chapter commands; an
521 attempt to lower below subsubsections reproduces subsubsection
524 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
525 ;; it is a regexp matching chapter, section, other headings
526 ;; (but not the top node).
528 (let (type (level 0))
532 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
533 texinfo-section-types-regexp
537 (save-excursion (setq type (read (current-buffer))))
540 ;; 1. Increment level
541 ((eq type '@raisesections)
542 (setq level (1+ level))
544 (point) (save-excursion (forward-line 1) (point))))
546 ;; 2. Decrement level
547 ((eq type '@lowersections)
548 (setq level (1- level))
550 (point) (save-excursion (forward-line 1) (point))))
552 ;; Now handle structuring commands
555 ;; 3. Raise level when positive
561 (cdr (assq new-level texinfo-raisesections-alist)))
562 (setq count (1- count)))
564 (insert (symbol-name new-level))))
566 ;; 4. Do nothing except move point when level is zero
567 ((= level 0) (forward-line 1))
569 ;; 5. Lower level when positive
575 (cdr (assq new-level texinfo-lowersections-alist)))
576 (setq count (1+ count)))
578 (insert (symbol-name new-level))))))))))
580 (defvar texinfo-raisesections-alist
581 '((@chapter . @chapter) ; Cannot go higher
582 (@unnumbered . @unnumbered)
584 (@majorheading . @majorheading)
585 (@chapheading . @chapheading)
586 (@appendix . @appendix)
588 (@section . @chapter)
589 (@unnumberedsec . @unnumbered)
590 (@heading . @chapheading)
591 (@appendixsec . @appendix)
593 (@subsection . @section)
594 (@unnumberedsubsec . @unnumberedsec)
595 (@subheading . @heading)
596 (@appendixsubsec . @appendixsec)
598 (@subsubsection . @subsection)
599 (@unnumberedsubsubsec . @unnumberedsubsec)
600 (@subsubheading . @subheading)
601 (@appendixsubsubsec . @appendixsubsec))
602 "*An alist of next higher levels for chapters, sections. etc.
603 For example, section to chapter, subsection to section.
604 Used by `texinfo-raise-lower-sections'.
605 The keys specify types of section; the values correspond to the next
608 (defvar texinfo-lowersections-alist
609 '((@chapter . @section)
610 (@unnumbered . @unnumberedsec)
611 (@majorheading . @heading)
612 (@chapheading . @heading)
613 (@appendix . @appendixsec)
615 (@section . @subsection)
616 (@unnumberedsec . @unnumberedsubsec)
617 (@heading . @subheading)
618 (@appendixsec . @appendixsubsec)
620 (@subsection . @subsubsection)
621 (@unnumberedsubsec . @unnumberedsubsubsec)
622 (@subheading . @subsubheading)
623 (@appendixsubsec . @appendixsubsubsec)
625 (@subsubsection . @subsubsection) ; Cannot go lower.
626 (@unnumberedsubsubsec . @unnumberedsubsubsec)
627 (@subsubheading . @subsubheading)
628 (@appendixsubsubsec . @appendixsubsubsec))
629 "*An alist of next lower levels for chapters, sections. etc.
630 For example, chapter to section, section to subsection.
631 Used by `texinfo-raise-lower-sections'.
632 The keys specify types of section; the values correspond to the next
636 ;;; Perform those texinfo-to-info conversions that apply to the whole input
639 (defun texinfo-format-scan ()
640 (texinfo-format-convert (point-min) (point-max))
641 ;; Scan for @-commands.
642 (goto-char (point-min))
643 (while (search-forward "@" nil t)
644 (if (looking-at "[@{}'` *]")
645 ;; Handle a few special @-followed-by-one-char commands.
646 (if (= (following-char) ?*)
649 (delete-region (1- (point)) (1+ (point)))
650 ;; insert return if not at end of line;
651 ;; else line is already broken.
652 (if (not (= (following-char) ?\n))
654 ;; The other characters are simply quoted. Delete the @.
657 ;; @ is followed by a command-word; find the end of the word.
658 (setq texinfo-command-start (1- (point)))
659 (if (= (char-syntax (following-char)) ?w)
662 (setq texinfo-command-end (point))
663 ;; Call the handler for this command.
664 (setq texinfo-command-name
665 (intern (buffer-substring
666 (1+ texinfo-command-start) texinfo-command-end)))
667 (let ((enclosure-type
669 (symbol-name texinfo-command-name)
670 texinfo-enclosure-list)))
674 (car (car (cdr enclosure-type)))
675 (texinfo-parse-arg-discard)
676 (car (cdr (car (cdr enclosure-type)))))
677 (goto-char texinfo-command-start))
678 (let ((cmd (get texinfo-command-name 'texinfo-format)))
679 (if cmd (funcall cmd) (texinfo-unsupported)))))))
682 (goto-char (nth 2 (car texinfo-stack)))
683 (error "Unterminated @%s" (car (car texinfo-stack))))))
685 (put 'begin 'texinfo-format 'texinfo-format-begin)
686 (defun texinfo-format-begin ()
687 (texinfo-format-begin-end 'texinfo-format))
689 (put 'end 'texinfo-format 'texinfo-format-end)
690 (defun texinfo-format-end ()
691 (texinfo-format-begin-end 'texinfo-end))
693 (defun texinfo-format-begin-end (prop)
694 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
695 (let ((cmd (get texinfo-command-name prop)))
696 (if cmd (funcall cmd)
697 (texinfo-unsupported))))
699 ;;; Parsing functions
701 (defun texinfo-parse-line-arg ()
702 (goto-char texinfo-command-end)
703 (let ((start (point)))
704 (cond ((looking-at " ")
705 (skip-chars-forward " ")
708 (skip-chars-backward " ")
709 (delete-region (point) (progn (end-of-line) (point)))
710 (setq texinfo-command-end (1+ (point))))
712 (setq start (1+ (point)))
714 (setq texinfo-command-end (point))
717 (error "Invalid texinfo command arg format")))
718 (prog1 (buffer-substring start (point))
719 (if (eolp) (forward-char 1)))))
721 (defun texinfo-parse-expanded-arg ()
722 (goto-char texinfo-command-end)
723 (let ((start (point))
725 (cond ((looking-at " ")
726 (skip-chars-forward " ")
729 (setq texinfo-command-end (1+ (point))))
731 (setq start (1+ (point)))
733 (setq texinfo-command-end (point))
736 (error "Invalid texinfo command arg format")))
737 (setq marker (move-marker (make-marker) texinfo-command-end))
738 (texinfo-format-expand-region start (point))
739 (setq texinfo-command-end (marker-position marker))
740 (move-marker marker nil)
741 (prog1 (buffer-substring start (point))
742 (if (eolp) (forward-char 1)))))
744 (defun texinfo-format-expand-region (start end)
746 (narrow-to-region start end)
747 (let (texinfo-command-start
751 (texinfo-format-scan))
752 (goto-char (point-max))))
754 (defun texinfo-parse-arg-discard ()
755 (prog1 (texinfo-parse-line-arg)
756 (texinfo-discard-command)))
758 (defun texinfo-discard-command ()
759 (delete-region texinfo-command-start texinfo-command-end))
761 (defun texinfo-optional-braces-discard ()
762 "Discard braces following command, if any."
763 (goto-char texinfo-command-end)
764 (let ((start (point)))
765 (cond ((looking-at "[ \t]*\n")) ; do nothing
766 ((looking-at "{") ; remove braces, if any
768 (setq texinfo-command-end (point)))
771 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
772 (delete-region texinfo-command-start texinfo-command-end)))
774 (defun texinfo-format-parse-line-args ()
775 (let ((start (1- (point)))
778 (skip-chars-forward " ")
781 (re-search-forward "[\n,]")
783 (if (bolp) (setq next (1- next)))
785 (skip-chars-backward " ")
787 (setq args (cons (if (> end beg) (buffer-substring beg end))
790 (skip-chars-forward " "))
791 (if (eolp) (forward-char 1))
792 (setq texinfo-command-end (point))
795 (defun texinfo-format-parse-args ()
796 (let ((start (1- (point)))
801 (texinfo-format-expand-region
803 (save-excursion (up-list 1) (1- (point)))))
804 ;; The following does not handle cross references of the form:
805 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
806 ;; re-search-forward finds the first right brace after the second
808 (while (/= (preceding-char) ?\})
809 (skip-chars-forward " \t\n")
811 (re-search-forward "[},]")
814 (skip-chars-backward " \t\n")
818 (while (search-forward "\n" end t)
819 (replace-match " "))))
820 (setq args (cons (if (> end beg) (buffer-substring beg end))
823 (if (eolp) (forward-char 1))
824 (setq texinfo-command-end (point))
827 (defun texinfo-format-parse-defun-args ()
828 (goto-char texinfo-command-end)
829 (let ((start (point)))
831 (setq texinfo-command-end (1+ (point)))
832 (let ((marker (move-marker (make-marker) texinfo-command-end)))
833 (texinfo-format-expand-region start (point))
834 (setq texinfo-command-end (marker-position marker))
835 (move-marker marker nil))
839 (skip-chars-forward " ")
841 (cond ((looking-at "{")
842 (setq beg (1+ (point)))
844 (setq end (1- (point))))
847 (re-search-forward "[\n ]")
850 (setq args (cons (buffer-substring beg end) args))
851 (skip-chars-forward " "))
855 (defun texinfo-discard-line ()
856 (goto-char texinfo-command-end)
857 (skip-chars-forward " \t")
859 (error "Extraneous text at end of command line."))
860 (goto-char texinfo-command-start)
862 (error "Extraneous text at beginning of command line."))
863 (delete-region (point) (progn (forward-line 1) (point))))
865 (defun texinfo-discard-line-with-args ()
866 (goto-char texinfo-command-start)
867 (delete-region (point) (progn (forward-line 1) (point))))
872 ;; Only `texinfo-format-buffer' handles @setfilename with this
873 ;; definition; `texinfo-format-region' handles @setfilename, if any,
875 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
876 (defun texinfo-format-setfilename ()
877 (let ((arg (texinfo-parse-arg-discard)))
878 (message "Formatting Info file: %s" arg)
879 (setq texinfo-format-filename
880 (file-name-nondirectory (expand-file-name arg)))
881 (insert "Info file: "
882 texinfo-format-filename ", -*-Text-*-\n"
883 ;; Date string removed so that regression testing is easier.
885 ;; (substring (current-time-string) 8 10) " "
886 ;; (substring (current-time-string) 4 7) " "
887 ;; (substring (current-time-string) -4) " "
888 "produced by `texinfo-format-buffer'\n"
890 (if (buffer-file-name input-buffer)
892 (file-name-sans-versions
893 (file-name-nondirectory
894 (buffer-file-name input-buffer)))
896 (concat "buffer `" (buffer-name input-buffer) "'"))
897 "\nusing `texinfmt.el' version "
903 (put 'node 'texinfo-format 'texinfo-format-node)
904 (put 'nwnode 'texinfo-format 'texinfo-format-node)
905 (defun texinfo-format-node ()
906 (let* ((args (texinfo-format-parse-line-args))
911 (texinfo-discard-command)
912 (setq texinfo-last-node name)
913 (let ((tem (downcase name)))
914 (if (assoc tem texinfo-node-names)
915 (error "Duplicate node name: %s" name)
916 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
917 (setq texinfo-footnote-number 0)
920 (insert "\^_\nFile: " texinfo-format-filename
923 (insert ", Next: " next))
925 (insert ", Prev: " prev))
927 (insert ", Up: " up))
929 (setq texinfo-last-node-pos (point))))
931 (put 'menu 'texinfo-format 'texinfo-format-menu)
932 (defun texinfo-format-menu ()
933 (texinfo-discard-line)
934 (insert "* Menu:\n\n"))
936 (put 'menu 'texinfo-end 'texinfo-discard-command)
941 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
942 ; -> *Note FNAME: (FILE)NODE
943 ; If FILE is missing,
945 ; If FNAME is empty and NAME is present
947 ; If both NAME and FNAME are missing
949 ; texinfo ignores the DOCUMENT argument.
950 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
951 ; If FILE is specified, (FILE)NODE is used for xrefs.
952 ; If fifth argument DOCUMENT is specified, produces
953 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
956 ; @ref a reference that does not put `See' or `see' in
957 ; the hardcopy and is the same as @xref in Info
958 (put 'ref 'texinfo-format 'texinfo-format-xref)
960 (put 'xref 'texinfo-format 'texinfo-format-xref)
961 (defun texinfo-format-xref ()
962 (let ((args (texinfo-format-parse-args)))
963 (texinfo-discard-command)
965 (let ((fname (or (nth 1 args) (nth 2 args))))
966 (if (null (or fname (nth 3 args)))
967 (insert (car args) "::")
968 (insert (or fname (car args)) ": ")
970 (insert "(" (nth 3 args) ")"))
971 (insert (car args))))))
973 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
974 (defun texinfo-format-pxref ()
975 (texinfo-format-xref)
981 ;@inforef{NODE, FNAME, FILE}
982 ;Like @xref{NODE, FNAME,,FILE} in texinfo.
983 ;In Tex, generates "See Info file FILE, node NODE"
984 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
985 (defun texinfo-format-inforef ()
986 (let ((args (texinfo-format-parse-args)))
987 (texinfo-discard-command)
989 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
990 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
995 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
996 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
997 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
998 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
999 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1000 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1001 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1002 (put 'top 'texinfo-format 'texinfo-format-chapter)
1003 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1004 (defun texinfo-format-chapter ()
1005 (texinfo-format-chapter-1 ?*))
1007 (put 'heading 'texinfo-format 'texinfo-format-section)
1008 (put 'isection 'texinfo-format 'texinfo-format-section)
1009 (put 'section 'texinfo-format 'texinfo-format-section)
1010 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1011 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1012 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1013 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1014 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1015 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1016 (defun texinfo-format-section ()
1017 (texinfo-format-chapter-1 ?=))
1019 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1020 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1021 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1022 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1023 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1024 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1025 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1026 (defun texinfo-format-subsection ()
1027 (texinfo-format-chapter-1 ?-))
1029 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1030 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1031 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1032 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1033 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1034 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1035 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1036 (defun texinfo-format-subsubsection ()
1037 (texinfo-format-chapter-1 ?.))
1039 (defun texinfo-format-chapter-1 (belowchar)
1040 (let ((arg (texinfo-parse-arg-discard)))
1041 (message "Formatting: %s ... " arg) ; So we can see where we are.
1042 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1045 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1046 (defun texinfo-format-sectionpad ()
1047 (let ((str (texinfo-parse-arg-discard)))
1049 (let ((column (current-column)))
1053 (setq column (1- column))))
1057 ;;; Space controling commands: @. and @:
1058 (put '\. 'texinfo-format 'texinfo-format-\.)
1059 (defun texinfo-format-\. ()
1060 (texinfo-discard-command)
1063 (put '\: 'texinfo-format 'texinfo-format-\:)
1064 (defun texinfo-format-\: ()
1065 (texinfo-discard-command))
1068 ;;; @center, @sp, and @br
1070 (put 'center 'texinfo-format 'texinfo-format-center)
1071 (defun texinfo-format-center ()
1072 (let ((arg (texinfo-parse-expanded-arg)))
1073 (texinfo-discard-command)
1077 (goto-char (1- (point)))
1078 (let ((indent-tabs-mode nil))
1081 (put 'sp 'texinfo-format 'texinfo-format-sp)
1082 (defun texinfo-format-sp ()
1083 (let* ((arg (texinfo-parse-arg-discard))
1085 (insert-char ?\n num)))
1087 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1088 (defun texinfo-format-paragraph-break ()
1089 "Force a paragraph break.
1090 If used within a line, follow `@br' with braces."
1091 (texinfo-optional-braces-discard)
1092 ;; insert one return if at end of line;
1093 ;; else insert two returns, to generate a blank line.
1094 (if (= (following-char) ?\n)
1096 (insert-char ?\n 2)))
1099 ;;; @footnote and @footnotestyle
1101 ; In Texinfo, footnotes are created with the `@footnote' command.
1102 ; This command is followed immediately by a left brace, then by the text of
1103 ; the footnote, and then by a terminating right brace. The
1104 ; template for a footnote is:
1108 ; Info has two footnote styles:
1110 ; * In the End of node style, all the footnotes for a single node
1111 ; are placed at the end of that node. The footnotes are
1112 ; separated from the rest of the node by a line of dashes with
1113 ; the word `Footnotes' within it.
1115 ; * In the Separate node style, all the footnotes for a single node
1116 ; are placed in an automatically constructed node of their own.
1118 ; Footnote style is specified by the @footnotestyle command, either
1119 ; @footnotestyle separate
1121 ; @footnotestyle end
1123 ; The default is separate
1125 (defvar texinfo-footnote-style "separate"
1126 "Footnote style, either separate or end.")
1128 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1129 (defun texinfo-footnotestyle ()
1130 "Specify whether footnotes are at end of node or in separate nodes.
1131 Argument is either end or separate."
1132 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1134 (defvar texinfo-footnote-number)
1136 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1137 (defun texinfo-format-footnote ()
1138 "Format a footnote in either end of node or separate node style.
1139 The texinfo-footnote-style variable controls which style is used."
1140 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1141 (cond ((string= texinfo-footnote-style "end")
1142 (texinfo-format-end-node))
1143 ((string= texinfo-footnote-style "separate")
1144 (texinfo-format-separate-node))))
1146 (defun texinfo-format-separate-node ()
1147 "Format footnote in Separate node style, with notes in own node.
1148 The node is constructed automatically."
1150 (arg (texinfo-parse-line-arg))
1151 (node-name-beginning
1154 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1159 (progn (goto-char node-name-beginning) ; skip over node command
1160 (skip-chars-forward " \t") ; and over spaces
1164 (save-excursion (end-of-line) (point)) t) ; bound search
1166 (end-of-line) (point))))))
1167 (texinfo-discard-command) ; remove or insert whitespace, as needed
1168 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1170 (insert (format " (%d) (*Note %s-Footnotes::)"
1171 texinfo-footnote-number node-name))
1172 (fill-paragraph nil)
1174 (if (re-search-forward "^@node" nil 'move)
1177 ;; two cases: for the first footnote, we must insert a node header;
1178 ;; for the second and subsequent footnotes, we need only insert
1179 ;; the text of the footnote.
1183 (concat node-name "-Footnotes, Up: ")
1186 (progn ; already at least one footnote
1187 (setq start (point))
1188 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1189 (fill-region start (point)))
1190 ;; else not yet a footnote
1191 (insert "\n\^_\nFile: " texinfo-format-filename
1192 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1193 (setq start (point))
1194 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1195 (fill-region start (point))))))
1197 (defun texinfo-format-end-node ()
1198 "Format footnote in the End of node style, with notes at end of node."
1200 (arg (texinfo-parse-line-arg)))
1201 (texinfo-discard-command) ; remove or insert whitespace, as needed
1202 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1204 (insert (format " (%d) " texinfo-footnote-number))
1205 (fill-paragraph nil)
1207 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1208 (progn ; already have footnote, put new one before end of node
1209 (if (re-search-forward "^@node" nil 'move)
1211 (setq start (point))
1212 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1213 (fill-region start (point)))
1214 ;; else no prior footnote
1215 (if (re-search-forward "^@node" nil 'move)
1217 (insert "\n--------- Footnotes ---------\n")
1218 (setq start (point))
1219 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1222 ;;; @itemize, @enumerate, and similar commands
1224 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1225 ;; @enumerate pushes (enumerate 0 STARTPOS).
1226 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1227 ;; For itemize, this puts in and rescans the COMMANDS.
1228 ;; For enumerate, this increments the number and puts it in.
1229 ;; In either case, it puts a Backspace at the front of the line
1230 ;; which marks it not to be indented later.
1231 ;; All other lines get indented by 5 when the @end is reached.
1233 (defvar texinfo-stack-depth 0
1234 "Count of number of unpopped texinfo-push-stack calls.
1235 Used by @refill indenting command to avoid indenting within lists, etc.")
1237 (defun texinfo-push-stack (check arg)
1238 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1240 (cons (list check arg texinfo-command-start)
1243 (defun texinfo-pop-stack (check)
1244 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1245 (if (null texinfo-stack)
1246 (error "Unmatched @end %s" check))
1247 (if (not (eq (car (car texinfo-stack)) check))
1248 (error "@end %s matches @%s"
1249 check (car (car texinfo-stack))))
1250 (prog1 (cdr (car texinfo-stack))
1251 (setq texinfo-stack (cdr texinfo-stack))))
1253 (put 'itemize 'texinfo-format 'texinfo-itemize)
1254 (defun texinfo-itemize ()
1257 (progn (skip-chars-forward " \t")
1260 (texinfo-parse-line-arg))))
1261 (texinfo-discard-line-with-args)
1262 (setq fill-column (- fill-column 5)))
1264 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1265 (defun texinfo-end-itemize ()
1266 (setq fill-column (+ fill-column 5))
1267 (texinfo-discard-command)
1269 (texinfo-pop-stack 'itemize)))
1270 (texinfo-do-itemize (nth 1 stacktop))))
1272 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1273 (defun texinfo-enumerate ()
1276 (progn (skip-chars-forward " \t")
1279 (read (current-buffer)))))
1280 (if (and (symbolp (car (cdr (car texinfo-stack))))
1281 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1283 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1284 (texinfo-discard-line-with-args)
1285 (setq fill-column (- fill-column 5)))
1287 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1288 (defun texinfo-end-enumerate ()
1289 (setq fill-column (+ fill-column 5))
1290 (texinfo-discard-command)
1292 (texinfo-pop-stack 'enumerate)))
1293 (texinfo-do-itemize (nth 1 stacktop))))
1295 ;; @alphaenumerate never became a standard part of Texinfo
1296 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1297 (defun texinfo-alphaenumerate ()
1298 (texinfo-push-stack 'alphaenumerate (1- ?a))
1299 (setq fill-column (- fill-column 5))
1300 (texinfo-discard-line))
1302 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1303 (defun texinfo-end-alphaenumerate ()
1304 (setq fill-column (+ fill-column 5))
1305 (texinfo-discard-command)
1307 (texinfo-pop-stack 'alphaenumerate)))
1308 (texinfo-do-itemize (nth 1 stacktop))))
1310 ;; @capsenumerate never became a standard part of Texinfo
1311 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1312 (defun texinfo-capsenumerate ()
1313 (texinfo-push-stack 'capsenumerate (1- ?A))
1314 (setq fill-column (- fill-column 5))
1315 (texinfo-discard-line))
1317 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1318 (defun texinfo-end-capsenumerate ()
1319 (setq fill-column (+ fill-column 5))
1320 (texinfo-discard-command)
1322 (texinfo-pop-stack 'capsenumerate)))
1323 (texinfo-do-itemize (nth 1 stacktop))))
1325 ;; At the @end, indent all the lines within the construct
1326 ;; except those marked with backspace. FROM says where
1327 ;; construct started.
1328 (defun texinfo-do-itemize (from)
1330 (while (progn (forward-line -1)
1332 (if (= (following-char) ?\b)
1337 (if (not (looking-at "[ \t]*$"))
1338 (save-excursion (insert " ")))))))
1340 (put 'item 'texinfo-format 'texinfo-item)
1341 (put 'itemx 'texinfo-format 'texinfo-item)
1342 (defun texinfo-item ()
1343 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1345 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1346 (defun texinfo-itemize-item ()
1347 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1348 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1349 (if (looking-at "[ \t]*[^ \t\n]+")
1350 ;; Text on same line as @item command.
1351 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1352 ;; Else text on next line.
1353 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1356 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1357 (defun texinfo-enumerate-item ()
1358 (texinfo-discard-line)
1359 (let (enumerating-symbol)
1360 (cond ((integerp (car (cdr (car texinfo-stack))))
1361 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1362 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1363 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1364 ((symbolp (car (cdr (car texinfo-stack))))
1365 (setq enumerating-symbol
1366 (symbol-name (car (cdr (car texinfo-stack)))))
1367 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1368 (equal ?\{ (string-to-char enumerating-symbol)))
1370 "Too many items in enumerated list; alphabet ends at Z."))
1371 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1372 (setcar (cdr (car texinfo-stack))
1376 (string-to-char enumerating-symbol))))))
1379 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1382 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1383 (defun texinfo-alphaenumerate-item ()
1384 (texinfo-discard-line)
1385 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1387 (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
1388 (setcar (cdr (car texinfo-stack)) next)
1389 (insert "\b " next ". \n"))
1392 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1393 (defun texinfo-capsenumerate-item ()
1394 (texinfo-discard-line)
1395 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1397 (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
1398 (setcar (cdr (car texinfo-stack)) next)
1399 (insert "\b " next ". \n"))
1405 ; The `@table' command produces two-column tables.
1407 (put 'table 'texinfo-format 'texinfo-table)
1408 (defun texinfo-table ()
1411 (progn (skip-chars-forward " \t")
1414 (texinfo-parse-line-arg))))
1415 (texinfo-discard-line-with-args)
1416 (setq fill-column (- fill-column 5)))
1418 (put 'table 'texinfo-item 'texinfo-table-item)
1419 (defun texinfo-table-item ()
1420 (let ((arg (texinfo-parse-arg-discard))
1421 (itemfont (car (cdr (car texinfo-stack)))))
1422 (insert ?\b itemfont ?\{ arg "}\n \n"))
1425 (put 'table 'texinfo-end 'texinfo-end-table)
1426 (defun texinfo-end-table ()
1427 (setq fill-column (+ fill-column 5))
1428 (texinfo-discard-command)
1430 (texinfo-pop-stack 'table)))
1431 (texinfo-do-itemize (nth 1 stacktop))))
1433 ;; @description appears to be an undocumented variant on @table that
1434 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1435 ;; part of makeinfo.c The command appears to be a relic of the past.
1436 (put 'description 'texinfo-end 'texinfo-end-table)
1437 (put 'description 'texinfo-format 'texinfo-description)
1438 (defun texinfo-description ()
1439 (texinfo-push-stack 'table "@asis")
1440 (setq fill-column (- fill-column 5))
1441 (texinfo-discard-line))
1444 ;;; @ftable, @vtable
1446 ; The `@ftable' and `@vtable' commands are like the `@table' command
1447 ; but they also insert each entry in the first column of the table
1448 ; into the function or variable index.
1450 ;; Handle the @ftable and @vtable commands:
1452 (put 'ftable 'texinfo-format 'texinfo-ftable)
1453 (put 'vtable 'texinfo-format 'texinfo-vtable)
1455 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1456 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1458 (defun texinfo-indextable (table-type)
1459 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1460 (setq fill-column (- fill-column 5)))
1462 ;; Handle the @item commands within ftable and vtable:
1464 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1465 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1467 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1468 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1470 (defun texinfo-indextable-item (index-type)
1471 (let ((item (texinfo-parse-arg-discard))
1472 (itemfont (car (cdr (car texinfo-stack))))
1473 (indexvar index-type))
1474 (insert ?\b itemfont ?\{ item "}\n \n")
1477 (list item texinfo-last-node)
1478 (symbol-value indexvar)))
1481 ;; Handle @end ftable, @end vtable
1483 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1484 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1486 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1487 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1489 (defun texinfo-end-indextable (table-type)
1490 (setq fill-column (+ fill-column 5))
1491 (texinfo-discard-command)
1493 (texinfo-pop-stack table-type)))
1494 (texinfo-do-itemize (nth 1 stacktop))))
1497 ;;; @ifinfo, @iftex, @tex
1499 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
1500 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
1502 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
1503 (defun texinfo-format-iftex ()
1504 (delete-region texinfo-command-start
1505 (progn (re-search-forward "@end iftex[ \t]*\n")
1508 (put 'tex 'texinfo-format 'texinfo-format-tex)
1509 (defun texinfo-format-tex ()
1510 (delete-region texinfo-command-start
1511 (progn (re-search-forward "@end tex[ \t]*\n")
1517 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
1518 (defun texinfo-format-titlepage ()
1519 (delete-region texinfo-command-start
1520 (progn (re-search-forward "@end titlepage[ \t]*\n")
1523 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
1525 ; @titlespec an alternative titling command; ignored by Info
1527 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
1528 (defun texinfo-format-titlespec ()
1529 (delete-region texinfo-command-start
1530 (progn (re-search-forward "@end titlespec[ \t]*\n")
1533 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
1538 (put 'today 'texinfo-format 'texinfo-format-today)
1540 ; Produces Day Month Year style of output. eg `1 Jan 1900'
1541 ; The `@today{}' command requires a pair of braces, like `@dots{}'.
1542 (defun texinfo-format-today ()
1543 (texinfo-parse-arg-discard)
1544 (insert (format "%s %s %s"
1545 (substring (current-time-string) 8 10)
1546 (substring (current-time-string) 4 7)
1547 (substring (current-time-string) -4))))
1552 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
1553 (defun texinfo-format-ignore ()
1554 (delete-region texinfo-command-start
1555 (progn (re-search-forward "@end ignore[ \t]*\n")
1558 (put 'endignore 'texinfo-format 'texinfo-discard-line)
1561 ;;; Define the Info enclosure command: @definfoenclose
1563 ; A `@definfoenclose' command may be used to define a highlighting
1564 ; command for Info, but not for TeX. A command defined using
1565 ; `@definfoenclose' marks text by enclosing it in strings that precede
1566 ; and follow the text.
1568 ; Presumably, if you define a command with `@definfoenclose` for Info,
1569 ; you will also define the same command in the TeX definitions file,
1570 ; `texinfo.tex' in a manner appropriate for typesetting.
1572 ; Write a `@definfoenclose' command on a line and follow it with three
1573 ; arguments separated by commas (commas are used as separators in an
1574 ; `@node' line in the same way). The first argument to
1575 ; `@definfoenclose' is the @-command name \(without the `@'\); the
1576 ; second argument is the Info start delimiter string; and the third
1577 ; argument is the Info end delimiter string. The latter two arguments
1578 ; enclose the highlighted text in the Info file. A delimiter string
1579 ; may contain spaces. Neither the start nor end delimiter is
1580 ; required. However, if you do not provide a start delimiter, you
1581 ; must follow the command name with two commas in a row; otherwise,
1582 ; the Info formatting commands will misinterpret the end delimiter
1583 ; string as a start delimiter string.
1585 ; An enclosure command defined this way takes one argument in braces.
1587 ; For example, you can write:
1590 ; @definfoenclose phoo, //, \\
1593 ; near the beginning of a Texinfo file at the beginning of the lines
1594 ; to define `@phoo' as an Info formatting command that inserts `//'
1595 ; before and `\\' after the argument to `@phoo'. You can then write
1596 ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
1598 ; Also, for TeX formatting, you could write
1601 ; @global@let@phoo=@i
1604 ; to define `@phoo' as a command that causes TeX to typeset
1605 ; the argument to `@phoo' in italics.
1607 ; Note that each definition applies to its own formatter: one for TeX,
1608 ; the other for texinfo-format-buffer or texinfo-format-region.
1610 ; Here is another example: write
1612 ; @definfoenclose headword, , :
1614 ; near the beginning of the file, to define `@headword' as an Info
1615 ; formatting command that inserts nothing before and a colon after the
1616 ; argument to `@headword'.
1618 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
1619 (defun texinfo-define-info-enclosure ()
1620 (let* ((args (texinfo-format-parse-line-args))
1621 (command-name (nth 0 args))
1622 (beginning-delimiter (or (nth 1 args) ""))
1623 (end-delimiter (or (nth 2 args) "")))
1624 (texinfo-discard-command)
1625 (setq texinfo-enclosure-list
1631 texinfo-enclosure-list))))
1634 ;;; @var, @code and the like
1636 (put 'var 'texinfo-format 'texinfo-format-var)
1637 ; @sc a small caps font for TeX; formatted as `var' in Info
1638 (put 'sc 'texinfo-format 'texinfo-format-var)
1639 (defun texinfo-format-var ()
1640 (insert (upcase (texinfo-parse-arg-discard)))
1641 (goto-char texinfo-command-start))
1645 (put 'b 'texinfo-format 'texinfo-format-noop)
1646 (put 'i 'texinfo-format 'texinfo-format-noop)
1647 (put 'r 'texinfo-format 'texinfo-format-noop)
1648 (put 't 'texinfo-format 'texinfo-format-noop)
1649 (put 'w 'texinfo-format 'texinfo-format-noop)
1650 (put 'asis 'texinfo-format 'texinfo-format-noop)
1651 (put 'dmn 'texinfo-format 'texinfo-format-noop)
1652 (put 'key 'texinfo-format 'texinfo-format-noop)
1653 (put 'math 'texinfo-format 'texinfo-format-noop)
1654 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
1655 (defun texinfo-format-noop ()
1656 (insert (texinfo-parse-arg-discard))
1657 (goto-char texinfo-command-start))
1659 (put 'cite 'texinfo-format 'texinfo-format-code)
1660 (put 'code 'texinfo-format 'texinfo-format-code)
1661 (put 'file 'texinfo-format 'texinfo-format-code)
1662 (put 'kbd 'texinfo-format 'texinfo-format-code)
1663 (put 'samp 'texinfo-format 'texinfo-format-code)
1664 (defun texinfo-format-code ()
1665 (insert "`" (texinfo-parse-arg-discard) "'")
1666 (goto-char texinfo-command-start))
1668 (put 'emph 'texinfo-format 'texinfo-format-emph)
1669 (put 'strong 'texinfo-format 'texinfo-format-emph)
1670 (defun texinfo-format-emph ()
1671 (insert "*" (texinfo-parse-arg-discard) "*")
1672 (goto-char texinfo-command-start))
1674 (put 'dfn 'texinfo-format 'texinfo-format-defn)
1675 (put 'defn 'texinfo-format 'texinfo-format-defn)
1676 (defun texinfo-format-defn ()
1677 (insert "\"" (texinfo-parse-arg-discard) "\"")
1678 (goto-char texinfo-command-start))
1680 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
1681 (defun texinfo-format-bullet ()
1682 "Insert an asterisk.
1683 If used within a line, follow `@bullet' with braces."
1684 (texinfo-optional-braces-discard)
1688 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
1690 (put 'display 'texinfo-format 'texinfo-format-example)
1691 (put 'example 'texinfo-format 'texinfo-format-example)
1692 (put 'lisp 'texinfo-format 'texinfo-format-example)
1693 (put 'quotation 'texinfo-format 'texinfo-format-example)
1694 (put 'smallexample 'texinfo-format 'texinfo-format-example)
1695 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
1696 (defun texinfo-format-example ()
1697 (texinfo-push-stack 'example nil)
1698 (setq fill-column (- fill-column 5))
1699 (texinfo-discard-line))
1701 (put 'example 'texinfo-end 'texinfo-end-example)
1702 (put 'display 'texinfo-end 'texinfo-end-example)
1703 (put 'lisp 'texinfo-end 'texinfo-end-example)
1704 (put 'quotation 'texinfo-end 'texinfo-end-example)
1705 (put 'smallexample 'texinfo-end 'texinfo-end-example)
1706 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
1707 (defun texinfo-end-example ()
1708 (setq fill-column (+ fill-column 5))
1709 (texinfo-discard-command)
1711 (texinfo-pop-stack 'example)))
1712 (texinfo-do-itemize (nth 1 stacktop))))
1714 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
1715 (defun texinfo-format-exdent ()
1716 (texinfo-discard-command)
1717 (delete-region (point)
1719 (skip-chars-forward " ")
1722 ;; Cancel out the deletion that texinfo-do-itemize
1723 ;; is going to do at the end of this line.
1731 ; The @cartouche command is a noop in Info; in a printed manual,
1732 ; it makes a box with rounded corners.
1734 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
1735 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
1738 ;;; @flushleft and @format
1740 ; The @flushleft command left justifies every line but leaves the
1741 ; right end ragged. As far as Info is concerned, @flushleft is a
1742 ; `do-nothing' command
1744 ; The @format command is similar to @example except that it does not
1745 ; indent; this means that in Info, @format is similar to @flushleft.
1747 (put 'format 'texinfo-format 'texinfo-format-flushleft)
1748 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
1749 (defun texinfo-format-flushleft ()
1750 (texinfo-discard-line))
1752 (put 'format 'texinfo-end 'texinfo-end-flushleft)
1753 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
1754 (defun texinfo-end-flushleft ()
1755 (texinfo-discard-command))
1760 ; The @flushright command right justifies every line but leaves the
1761 ; left end ragged. Spaces and tabs at the right ends of lines are
1762 ; removed so that visible text lines up on the right side.
1764 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
1765 (defun texinfo-format-flushright ()
1766 (texinfo-push-stack 'flushright nil)
1767 (texinfo-discard-line))
1769 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
1770 (defun texinfo-end-flushright ()
1771 (texinfo-discard-command)
1774 (texinfo-pop-stack 'flushright)))
1776 (texinfo-do-flushright (nth 1 stacktop))))
1778 (defun texinfo-do-flushright (from)
1780 (while (progn (forward-line -1)
1789 (skip-chars-backward " \t")
1790 (delete-region (point) (progn (end-of-line) (point)))
1795 ;;; @ctrl, @TeX, @copyright, @minus, @dots
1797 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
1798 (defun texinfo-format-ctrl ()
1799 (let ((str (texinfo-parse-arg-discard)))
1800 (insert (logand 31 (aref str 0)))))
1802 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
1803 (defun texinfo-format-TeX ()
1804 (texinfo-parse-arg-discard)
1807 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
1808 (defun texinfo-format-copyright ()
1809 (texinfo-parse-arg-discard)
1812 (put 'minus 'texinfo-format 'texinfo-format-minus)
1813 (defun texinfo-format-minus ()
1814 "Insert a minus sign.
1815 If used within a line, follow `@minus' with braces."
1816 (texinfo-optional-braces-discard)
1819 (put 'dots 'texinfo-format 'texinfo-format-dots)
1820 (defun texinfo-format-dots ()
1821 (texinfo-parse-arg-discard)
1825 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
1827 ;;; Indent only those paragraphs that are refilled as a result of an
1828 ;;; @refill command.
1830 ; * If the value is `asis', do not change the existing indentation at
1831 ; the starts of paragraphs.
1833 ; * If the value zero, delete any existing indentation.
1835 ; * If the value is greater than zero, indent each paragraph by that
1838 ;;; But do not refill paragraphs with an @refill command that are
1839 ;;; preceded by @noindent or are part of a table, list, or deffn.
1841 (defvar texinfo-paragraph-indent "asis"
1842 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
1844 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
1846 (defun texinfo-paragraphindent ()
1847 "Specify the number of spaces for @refill to indent a paragraph.
1848 Default is to leave the number of spaces as is."
1849 (let ((arg (texinfo-parse-arg-discard)))
1850 (if (string= "asis" arg)
1851 (setq texinfo-paragraph-indent "asis")
1852 (setq texinfo-paragraph-indent (string-to-int arg)))))
1854 (put 'refill 'texinfo-format 'texinfo-format-refill)
1855 (defun texinfo-format-refill ()
1856 "Refill paragraph. Also, indent first line as set by @paragraphindent.
1857 Default is to leave paragraph indentation as is."
1858 (texinfo-discard-command)
1859 (forward-paragraph -1)
1860 (if (looking-at "[ \t\n]*$") (forward-line 1))
1861 ;; Do not indent if an entry in a list, table, or deffn,
1862 ;; or if paragraph is preceded by @noindent.
1863 ;; Otherwise, indent
1865 ;; delete a @noindent line and do not indent paragraph
1866 ((save-excursion (forward-line -1)
1867 (looking-at "^@noindent"))
1869 (delete-region (point) (progn (forward-line 1) (point))))
1870 ;; do nothing if "asis"
1871 ((equal texinfo-paragraph-indent "asis"))
1872 ;; do no indenting in list, etc.
1873 ((> texinfo-stack-depth 0))
1874 ;; otherwise delete existing whitespace and indent
1876 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
1877 (insert (make-string texinfo-paragraph-indent ? ))))
1878 (forward-paragraph 1)
1881 ;; Do not fill a section title line with asterisks, hyphens, etc. that
1882 ;; are used to underline it. This could occur if the line following
1883 ;; the underlining is not an index entry and has text within it.
1884 (let* ((previous-paragraph-separate paragraph-separate)
1885 (paragraph-separate (concat paragraph-separate "\\|^[=*---.]+"))
1886 (previous-paragraph-start paragraph-start)
1887 (paragraph-start (concat paragraph-start "\\|^[=*---.]+")))
1889 (fill-paragraph nil)
1890 (setq paragraph-separate previous-paragraph-separate)
1891 (setq paragraph-start previous-paragraph-start))))
1893 (put 'noindent 'texinfo-format 'texinfo-noindent)
1894 (defun texinfo-noindent ()
1896 (forward-paragraph 1)
1897 (if (search-backward "@refill"
1898 (save-excursion (forward-line -1) (point)) t)
1899 () ; leave @noindent command so @refill command knows not to indent
1901 (texinfo-discard-line))))
1904 ;;; Index generation
1906 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
1907 (defun texinfo-format-vindex ()
1908 (texinfo-index 'texinfo-vindex))
1910 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
1911 (defun texinfo-format-cindex ()
1912 (texinfo-index 'texinfo-cindex))
1914 (put 'findex 'texinfo-format 'texinfo-format-findex)
1915 (defun texinfo-format-findex ()
1916 (texinfo-index 'texinfo-findex))
1918 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
1919 (defun texinfo-format-pindex ()
1920 (texinfo-index 'texinfo-pindex))
1922 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
1923 (defun texinfo-format-tindex ()
1924 (texinfo-index 'texinfo-tindex))
1926 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
1927 (defun texinfo-format-kindex ()
1928 (texinfo-index 'texinfo-kindex))
1930 (defun texinfo-index (indexvar)
1931 (let ((arg (texinfo-parse-expanded-arg)))
1932 (texinfo-discard-command)
1936 ;; Region formatting may not provide last node position.
1937 (if texinfo-last-node-pos
1938 (1+ (count-lines texinfo-last-node-pos (point)))
1940 (symbol-value indexvar)))))
1942 (defconst texinfo-indexvar-alist
1943 '(("cp" . texinfo-cindex)
1944 ("fn" . texinfo-findex)
1945 ("vr" . texinfo-vindex)
1946 ("tp" . texinfo-tindex)
1947 ("pg" . texinfo-pindex)
1948 ("ky" . texinfo-kindex)))
1951 ;;; @defindex @defcodeindex
1952 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
1953 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
1955 (defun texinfo-format-defindex ()
1956 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
1957 (indexing-command (intern (concat index-name "index")))
1958 (index-formatting-command ; eg: `texinfo-format-aaindex'
1959 (intern (concat "texinfo-format-" index-name "index")))
1960 (index-alist-name ; eg: `texinfo-aaindex'
1961 (intern (concat "texinfo-" index-name "index"))))
1963 (set index-alist-name nil)
1965 (put indexing-command ; eg, aaindex
1967 index-formatting-command) ; eg, texinfo-format-aaindex
1969 ;; eg: "aa" . texinfo-aaindex
1970 (or (assoc index-name texinfo-indexvar-alist)
1971 (setq texinfo-indexvar-alist
1975 texinfo-indexvar-alist)))
1977 (fset index-formatting-command
1979 (list 'texinfo-index
1980 (list 'quote index-alist-name))))))
1983 ;;; @synindex @syncodeindex
1985 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
1986 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
1988 (defun texinfo-format-synindex ()
1989 (let* ((args (texinfo-parse-arg-discard))
1990 (second (cdr (read-from-string args)))
1991 (joiner (symbol-name (car (read-from-string args))))
1992 (joined (symbol-name (car (read-from-string args second)))))
1994 (if (assoc joiner texinfo-short-index-cmds-alist)
1996 (cdr (assoc joiner texinfo-short-index-cmds-alist))
1998 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
1999 (intern (concat "texinfo-format-" joined "index"))))
2001 (intern (concat joiner "index"))
2003 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
2004 (intern (concat "texinfo-format-" joined "index")))))))
2006 (defconst texinfo-short-index-cmds-alist
2014 (defconst texinfo-short-index-format-cmds-alist
2015 '(("cp" . texinfo-format-cindex)
2016 ("fn" . texinfo-format-findex)
2017 ("vr" . texinfo-format-vindex)
2018 ("tp" . texinfo-format-tindex)
2019 ("pg" . texinfo-format-pindex)
2020 ("ky" . texinfo-format-kindex)))
2023 ;;; Sort and index (for VMS)
2025 ;; Sort an index which is in the current buffer between START and END.
2026 ;; Used on VMS, where the `sort' utility is not available.
2027 (defun texinfo-sort-region (start end)
2030 (narrow-to-region start end)
2031 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
2033 ;; Subroutine for sorting an index.
2034 ;; At start of a line, return a string to sort the line under.
2035 (defun texinfo-sort-startkeyfun ()
2037 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
2038 ;; Canonicalize whitespace and eliminate funny chars.
2039 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
2040 (setq line (concat (substring line 0 (match-beginning 0))
2042 (substring line (match-end 0) (length line)))))
2048 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
2050 (defun texinfo-format-printindex ()
2051 (let ((indexelts (symbol-value
2052 (cdr (assoc (texinfo-parse-arg-discard)
2053 texinfo-indexvar-alist))))
2055 (insert "\n* Menu:\n\n")
2056 (setq opoint (point))
2057 (texinfo-print-index nil indexelts)
2059 (if (eq system-type 'vax-vms)
2060 (texinfo-sort-region opoint (point))
2061 (shell-command-on-region opoint (point) "sort -fd" 1))))
2063 (defun texinfo-print-index (file indexelts)
2065 (if (stringp (car (car indexelts)))
2067 (insert "* " (car (car indexelts)) ": " )
2070 (if file (concat "(" file ")") "")
2071 (nth 1 (car indexelts)) ".")
2074 (if (nth 2 (car indexelts))
2075 (format " %d." (nth 2 (car indexelts)))
2078 ;; index entries from @include'd file
2079 (texinfo-print-index (nth 1 (car indexelts))
2080 (nth 2 (car indexelts))))
2081 (setq indexelts (cdr indexelts))))
2084 ;;; Glyphs: @equiv, @error, etc
2086 ;; @equiv to show that two expressions are equivalent
2087 ;; @error to show an error message
2088 ;; @expansion to show what a macro expands to
2089 ;; @point to show the location of point in an example
2090 ;; @print to show what an evaluated expression prints
2091 ;; @result to indicate the value returned by an expression
2093 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
2094 (defun texinfo-format-equiv ()
2095 (texinfo-parse-arg-discard)
2098 (put 'error 'texinfo-format 'texinfo-format-error)
2099 (defun texinfo-format-error ()
2100 (texinfo-parse-arg-discard)
2101 (insert "error-->"))
2103 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
2104 (defun texinfo-format-expansion ()
2105 (texinfo-parse-arg-discard)
2108 (put 'point 'texinfo-format 'texinfo-format-point)
2109 (defun texinfo-format-point ()
2110 (texinfo-parse-arg-discard)
2113 (put 'print 'texinfo-format 'texinfo-format-print)
2114 (defun texinfo-format-print ()
2115 (texinfo-parse-arg-discard)
2118 (put 'result 'texinfo-format 'texinfo-format-result)
2119 (defun texinfo-format-result ()
2120 (texinfo-parse-arg-discard)
2124 ;;; Definition formatting: @deffn, @defun, etc
2126 ;; What definition formatting produces:
2128 ;; @deffn category name args...
2129 ;; In Info, `Category: name ARGS'
2130 ;; In index: name: node. line#.
2132 ;; @defvr category name
2133 ;; In Info, `Category: name'
2134 ;; In index: name: node. line#.
2136 ;; @deftp category name attributes...
2137 ;; `category name attributes...' Note: @deftp args in lower case.
2138 ;; In index: name: node. line#.
2140 ;; Specialized function-like or variable-like entity:
2142 ;; @defun, @defmac, @defspec, @defvar, @defopt
2144 ;; @defun name args In Info, `Function: name ARGS'
2145 ;; @defmac name args In Info, `Macro: name ARGS'
2146 ;; @defvar name In Info, `Variable: name'
2148 ;; In index: name: node. line#.
2150 ;; Generalized typed-function-like or typed-variable-like entity:
2151 ;; @deftypefn category data-type name args...
2152 ;; In Info, `Category: data-type name args...'
2153 ;; @deftypevr category data-type name
2154 ;; In Info, `Category: data-type name'
2155 ;; In index: name: node. line#.
2157 ;; Specialized typed-function-like or typed-variable-like entity:
2158 ;; @deftypefun data-type name args...
2159 ;; In Info, `Function: data-type name ARGS'
2160 ;; In index: name: node. line#.
2162 ;; @deftypevar data-type name
2163 ;; In Info, `Variable: data-type name'
2164 ;; In index: name: node. line#. but include args after name!?
2166 ;; Generalized object oriented entity:
2167 ;; @defop category class name args...
2168 ;; In Info, `Category on class: name ARG'
2169 ;; In index: name on class: node. line#.
2171 ;; @defcv category class name
2172 ;; In Info, `Category of class: name'
2173 ;; In index: name of class: node. line#.
2175 ;; Specialized object oriented entity:
2176 ;; @defmethod class name args...
2177 ;; In Info, `Method on class: name ARGS'
2178 ;; In index: name on class: node. line#.
2180 ;; @defivar class name
2181 ;; In Info, `Instance variable of class: name'
2182 ;; In index: name of class: node. line#.
2185 ;;; The definition formatting functions
2187 (defun texinfo-format-defun ()
2188 (texinfo-push-stack 'defun nil)
2189 (setq fill-column (- fill-column 5))
2190 (texinfo-format-defun-1 t))
2192 (defun texinfo-end-defun ()
2193 (setq fill-column (+ fill-column 5))
2194 (texinfo-discard-command)
2195 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
2196 (texinfo-do-itemize start)
2197 ;; Delete extra newline inserted after header.
2202 (defun texinfo-format-defunx ()
2203 (texinfo-format-defun-1 nil))
2205 (defun texinfo-format-defun-1 (first-p)
2206 (let ((parse-args (texinfo-format-parse-defun-args))
2207 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
2208 (texinfo-discard-command)
2209 ;; Delete extra newline inserted after previous header line.
2213 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
2214 ;; Insert extra newline so that paragraph filling does not mess
2215 ;; with header line.
2217 (rplaca (cdr (cdr (car texinfo-stack))) (point))
2219 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
2221 ;;; Formatting the first line of a definition
2223 ;; @deffn, @defvr, @deftp
2224 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2225 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2226 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2227 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2228 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2229 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2230 (defun texinfo-format-deffn (parsed-args)
2231 ;; Generalized function-like, variable-like, or generic data-type entity:
2232 ;; @deffn category name args...
2233 ;; In Info, `Category: name ARGS'
2234 ;; @deftp category name attributes...
2235 ;; `category name attributes...' Note: @deftp args in lower case.
2236 (let ((category (car parsed-args))
2237 (name (car (cdr parsed-args)))
2238 (args (cdr (cdr parsed-args))))
2239 (insert " -- " category ": " name)
2242 (if (or (= ?& (aref (car args) 0))
2243 (eq (eval (car texinfo-defun-type)) 'deftp-type))
2245 (upcase (car args))))
2246 (setq args (cdr args)))))
2248 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
2249 (put 'defun 'texinfo-deffn-formatting-property
2250 'texinfo-format-specialized-defun)
2251 (put 'defunx 'texinfo-deffn-formatting-property
2252 'texinfo-format-specialized-defun)
2253 (put 'defmac 'texinfo-deffn-formatting-property
2254 'texinfo-format-specialized-defun)
2255 (put 'defmacx 'texinfo-deffn-formatting-property
2256 'texinfo-format-specialized-defun)
2257 (put 'defspec 'texinfo-deffn-formatting-property
2258 'texinfo-format-specialized-defun)
2259 (put 'defspecx 'texinfo-deffn-formatting-property
2260 'texinfo-format-specialized-defun)
2261 (put 'defvar 'texinfo-deffn-formatting-property
2262 'texinfo-format-specialized-defun)
2263 (put 'defvarx 'texinfo-deffn-formatting-property
2264 'texinfo-format-specialized-defun)
2265 (put 'defopt 'texinfo-deffn-formatting-property
2266 'texinfo-format-specialized-defun)
2267 (put 'defoptx 'texinfo-deffn-formatting-property
2268 'texinfo-format-specialized-defun)
2269 (defun texinfo-format-specialized-defun (parsed-args)
2270 ;; Specialized function-like or variable-like entity:
2271 ;; @defun name args In Info, `Function: Name ARGS'
2272 ;; @defmac name args In Info, `Macro: Name ARGS'
2273 ;; @defvar name In Info, `Variable: Name'
2274 ;; Use cdr of texinfo-defun-type to determine category:
2275 (let ((category (car (cdr texinfo-defun-type)))
2276 (name (car parsed-args))
2277 (args (cdr parsed-args)))
2278 (insert " -- " category ": " name)
2281 (if (= ?& (aref (car args) 0))
2283 (upcase (car args))))
2284 (setq args (cdr args)))))
2286 ;; @deftypefn, @deftypevr: Generalized typed
2287 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2288 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2289 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2290 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2291 (defun texinfo-format-deftypefn (parsed-args)
2292 ;; Generalized typed-function-like or typed-variable-like entity:
2293 ;; @deftypefn category data-type name args...
2294 ;; In Info, `Category: data-type name args...'
2295 ;; @deftypevr category data-type name
2296 ;; In Info, `Category: data-type name'
2297 ;; Note: args in lower case, unless modified in command line.
2298 (let ((category (car parsed-args))
2299 (data-type (car (cdr parsed-args)))
2300 (name (car (cdr (cdr parsed-args))))
2301 (args (cdr (cdr (cdr parsed-args)))))
2302 (insert " -- " category ": " data-type " " name)
2304 (insert " " (car args))
2305 (setq args (cdr args)))))
2307 ;; @deftypefun, @deftypevar: Specialized typed
2308 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
2309 (put 'deftypefunx 'texinfo-deffn-formatting-property
2310 'texinfo-format-deftypefun)
2311 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
2312 (put 'deftypevarx 'texinfo-deffn-formatting-property
2313 'texinfo-format-deftypefun)
2314 (defun texinfo-format-deftypefun (parsed-args)
2315 ;; Specialized typed-function-like or typed-variable-like entity:
2316 ;; @deftypefun data-type name args...
2317 ;; In Info, `Function: data-type name ARGS'
2318 ;; @deftypevar data-type name
2319 ;; In Info, `Variable: data-type name'
2320 ;; Note: args in lower case, unless modified in command line.
2321 ;; Use cdr of texinfo-defun-type to determine category:
2322 (let ((category (car (cdr texinfo-defun-type)))
2323 (data-type (car parsed-args))
2324 (name (car (cdr parsed-args)))
2325 (args (cdr (cdr parsed-args))))
2326 (insert " -- " category ": " data-type " " name)
2328 (insert " " (car args))
2329 (setq args (cdr args)))))
2331 ;; @defop: Generalized object-oriented
2332 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
2333 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
2334 (defun texinfo-format-defop (parsed-args)
2335 ;; Generalized object oriented entity:
2336 ;; @defop category class name args...
2337 ;; In Info, `Category on class: name ARG'
2338 ;; Note: args in upper case; use of `on'
2339 (let ((category (car parsed-args))
2340 (class (car (cdr parsed-args)))
2341 (name (car (cdr (cdr parsed-args))))
2342 (args (cdr (cdr (cdr parsed-args)))))
2343 (insert " -- " category " on " class ": " name)
2345 (insert " " (upcase (car args)))
2346 (setq args (cdr args)))))
2348 ;; @defcv: Generalized object-oriented
2349 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
2350 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
2351 (defun texinfo-format-defcv (parsed-args)
2352 ;; Generalized object oriented entity:
2353 ;; @defcv category class name
2354 ;; In Info, `Category of class: name'
2355 ;; Note: args in upper case; use of `of'
2356 (let ((category (car parsed-args))
2357 (class (car (cdr parsed-args)))
2358 (name (car (cdr (cdr parsed-args))))
2359 (args (cdr (cdr (cdr parsed-args)))))
2360 (insert " -- " category " of " class ": " name)
2362 (insert " " (upcase (car args)))
2363 (setq args (cdr args)))))
2365 ;; @defmethod: Specialized object-oriented
2366 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
2367 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
2368 (defun texinfo-format-defmethod (parsed-args)
2369 ;; Specialized object oriented entity:
2370 ;; @defmethod class name args...
2371 ;; In Info, `Method on class: name ARGS'
2372 ;; Note: args in upper case; use of `on'
2373 ;; Use cdr of texinfo-defun-type to determine category:
2374 (let ((category (car (cdr texinfo-defun-type)))
2375 (class (car parsed-args))
2376 (name (car (cdr parsed-args)))
2377 (args (cdr (cdr parsed-args))))
2378 (insert " -- " category " on " class ": " name)
2380 (insert " " (upcase (car args)))
2381 (setq args (cdr args)))))
2383 ;; @defivar: Specialized object-oriented
2384 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
2385 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
2386 (defun texinfo-format-defivar (parsed-args)
2387 ;; Specialized object oriented entity:
2388 ;; @defivar class name
2389 ;; In Info, `Instance variable of class: name'
2390 ;; Note: args in upper case; use of `of'
2391 ;; Use cdr of texinfo-defun-type to determine category:
2392 (let ((category (car (cdr texinfo-defun-type)))
2393 (class (car parsed-args))
2394 (name (car (cdr parsed-args)))
2395 (args (cdr (cdr parsed-args))))
2396 (insert " -- " category " of " class ": " name)
2398 (insert " " (upcase (car args)))
2399 (setq args (cdr args)))))
2402 ;;; Indexing for definitions
2404 ;; An index entry has three parts: the `entry proper', the node name, and the
2405 ;; line number. Depending on the which command is used, the entry is
2406 ;; formatted differently:
2412 ;; @defopt all use their 1st argument as the entry-proper
2418 ;; @deftypevar all use their 2nd argument as the entry-proper
2421 ;; @deftypevr both use their 3rd argument as the entry-proper
2423 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
2424 ;; formatted: NAME on CLASS
2426 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
2427 ;; formatted: NAME on CLASS
2429 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
2430 ;; formatted: NAME of CLASS
2432 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
2433 ;; formatted: NAME of CLASS
2435 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
2436 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2437 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
2438 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2439 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
2440 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2441 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
2442 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2443 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
2444 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2445 (defun texinfo-index-defun (parsed-args)
2446 ;; use 1st parsed-arg as entry-proper
2447 ;; `index-list' will be texinfo-findex or the like
2448 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2451 ;; Three elements: entry-proper, node-name, line-number
2455 ;; Region formatting may not provide last node position.
2456 (if texinfo-last-node-pos
2457 (1+ (count-lines texinfo-last-node-pos (point)))
2459 (symbol-value index-list)))))
2461 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2462 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2463 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2464 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2465 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2466 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2467 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2468 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2469 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2470 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2471 (defun texinfo-index-deffn (parsed-args)
2472 ;; use 2nd parsed-arg as entry-proper
2473 ;; `index-list' will be texinfo-findex or the like
2474 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2477 ;; Three elements: entry-proper, node-name, line-number
2479 (car (cdr parsed-args))
2481 ;; Region formatting may not provide last node position.
2482 (if texinfo-last-node-pos
2483 (1+ (count-lines texinfo-last-node-pos (point)))
2485 (symbol-value index-list)))))
2487 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2488 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2489 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2490 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2491 (defun texinfo-index-deftypefn (parsed-args)
2492 ;; use 3rd parsed-arg as entry-proper
2493 ;; `index-list' will be texinfo-findex or the like
2494 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2497 ;; Three elements: entry-proper, node-name, line-number
2499 (car (cdr (cdr parsed-args)))
2501 ;; Region formatting may not provide last node position.
2502 (if texinfo-last-node-pos
2503 (1+ (count-lines texinfo-last-node-pos (point)))
2505 (symbol-value index-list)))))
2507 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
2508 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
2509 (defun texinfo-index-defmethod (parsed-args)
2510 ;; use 2nd on 1st parsed-arg as entry-proper
2511 ;; `index-list' will be texinfo-findex or the like
2512 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2515 ;; Three elements: entry-proper, node-name, line-number
2518 (car (cdr parsed-args))
2521 ;; Region formatting may not provide last node position.
2522 (if texinfo-last-node-pos
2523 (1+ (count-lines texinfo-last-node-pos (point)))
2525 (symbol-value index-list)))))
2527 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
2528 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
2529 (defun texinfo-index-defop (parsed-args)
2530 ;; use 3rd on 2nd parsed-arg as entry-proper
2531 ;; `index-list' will be texinfo-findex or the like
2532 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2535 ;; Three elements: entry-proper, node-name, line-number
2538 (car (cdr (cdr parsed-args)))
2539 (car (cdr parsed-args)))
2541 ;; Region formatting may not provide last node position.
2542 (if texinfo-last-node-pos
2543 (1+ (count-lines texinfo-last-node-pos (point)))
2545 (symbol-value index-list)))))
2547 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
2548 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
2549 (defun texinfo-index-defivar (parsed-args)
2550 ;; use 2nd of 1st parsed-arg as entry-proper
2551 ;; `index-list' will be texinfo-findex or the like
2552 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2555 ;; Three elements: entry-proper, node-name, line-number
2558 (car (cdr parsed-args))
2561 ;; Region formatting may not provide last node position.
2562 (if texinfo-last-node-pos
2563 (1+ (count-lines texinfo-last-node-pos (point)))
2565 (symbol-value index-list)))))
2567 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
2568 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
2569 (defun texinfo-index-defcv (parsed-args)
2570 ;; use 3rd of 2nd parsed-arg as entry-proper
2571 ;; `index-list' will be texinfo-findex or the like
2572 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2575 ;; Three elements: entry-proper, node-name, line-number
2578 (car (cdr (cdr parsed-args)))
2579 (car (cdr parsed-args)))
2581 ;; Region formatting may not provide last node position.
2582 (if texinfo-last-node-pos
2583 (1+ (count-lines texinfo-last-node-pos (point)))
2585 (symbol-value index-list)))))
2588 ;;; Properties for definitions
2590 ;; Each definition command has six properties:
2592 ;; 1. texinfo-deffn-formatting-property to format definition line
2593 ;; 2. texinfo-defun-indexing-property to create index entry
2594 ;; 3. texinfo-format formatting command
2595 ;; 4. texinfo-end end formatting command
2596 ;; 5. texinfo-defun-type type of deffn to format
2597 ;; 6. texinfo-defun-index type of index to use
2599 ;; The `x' forms of each definition command are used for the second
2600 ;; and subsequent header lines.
2602 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
2603 ;; are listed just before the appropriate formatting and indexing commands.
2605 (put 'deffn 'texinfo-format 'texinfo-format-defun)
2606 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
2607 (put 'deffn 'texinfo-end 'texinfo-end-defun)
2608 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
2609 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
2610 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
2611 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
2613 (put 'defun 'texinfo-format 'texinfo-format-defun)
2614 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
2615 (put 'defun 'texinfo-end 'texinfo-end-defun)
2616 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
2617 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
2618 (put 'defun 'texinfo-defun-index 'texinfo-findex)
2619 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
2621 (put 'defmac 'texinfo-format 'texinfo-format-defun)
2622 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
2623 (put 'defmac 'texinfo-end 'texinfo-end-defun)
2624 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
2625 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
2626 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
2627 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
2629 (put 'defspec 'texinfo-format 'texinfo-format-defun)
2630 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
2631 (put 'defspec 'texinfo-end 'texinfo-end-defun)
2632 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
2633 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
2634 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
2635 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
2637 (put 'defvr 'texinfo-format 'texinfo-format-defun)
2638 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
2639 (put 'defvr 'texinfo-end 'texinfo-end-defun)
2640 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
2641 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
2642 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
2643 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
2645 (put 'defvar 'texinfo-format 'texinfo-format-defun)
2646 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
2647 (put 'defvar 'texinfo-end 'texinfo-end-defun)
2648 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
2649 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
2650 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
2651 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
2653 (put 'defconst 'texinfo-format 'texinfo-format-defun)
2654 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
2655 (put 'defconst 'texinfo-end 'texinfo-end-defun)
2656 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
2657 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
2658 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
2659 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
2661 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
2662 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
2663 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
2664 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
2665 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
2666 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
2667 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
2669 (put 'defopt 'texinfo-format 'texinfo-format-defun)
2670 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
2671 (put 'defopt 'texinfo-end 'texinfo-end-defun)
2672 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
2673 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
2674 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
2675 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
2677 (put 'deftp 'texinfo-format 'texinfo-format-defun)
2678 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
2679 (put 'deftp 'texinfo-end 'texinfo-end-defun)
2680 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
2681 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
2682 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
2683 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
2685 ;;; Object-oriented stuff is a little hairier.
2687 (put 'defop 'texinfo-format 'texinfo-format-defun)
2688 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
2689 (put 'defop 'texinfo-end 'texinfo-end-defun)
2690 (put 'defop 'texinfo-defun-type '('defop-type nil))
2691 (put 'defopx 'texinfo-defun-type '('defop-type nil))
2692 (put 'defop 'texinfo-defun-index 'texinfo-findex)
2693 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
2695 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
2696 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
2697 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
2698 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
2699 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
2700 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
2701 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
2703 (put 'defcv 'texinfo-format 'texinfo-format-defun)
2704 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
2705 (put 'defcv 'texinfo-end 'texinfo-end-defun)
2706 (put 'defcv 'texinfo-defun-type '('defop-type nil))
2707 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
2708 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
2709 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
2711 (put 'defivar 'texinfo-format 'texinfo-format-defun)
2712 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
2713 (put 'defivar 'texinfo-end 'texinfo-end-defun)
2714 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
2715 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
2716 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
2717 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
2719 ;;; Typed functions and variables
2721 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
2722 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
2723 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
2724 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
2725 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
2726 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
2727 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
2729 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
2730 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
2731 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
2732 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
2733 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
2734 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
2735 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
2737 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
2738 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
2739 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
2740 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
2741 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
2742 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
2743 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
2745 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
2746 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
2747 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
2748 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
2749 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
2750 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
2751 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
2754 ;;; @set, @clear, @ifset, @ifclear
2756 ;; If a flag is set with @set FLAG, then text between @ifset and @end
2757 ;; ifset is formatted normally, but if the flag is is cleared with
2758 ;; @clear FLAG, then the text is not formatted; it is ignored.
2760 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
2761 ;; and @end ifclear is formatted normally, but if the flag is is set with
2762 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
2763 ;; is the opposite of @ifset.
2765 ;; If a flag is set to a string with @set FLAG,
2766 ;; replace @value{FLAG} with the string.
2767 ;; If a flag with a value is cleared,
2768 ;; @value{FLAG} is invalid,
2769 ;; as if there had never been any @set FLAG previously.
2771 (put 'clear 'texinfo-format 'texinfo-clear)
2772 (defun texinfo-clear ()
2773 "Clear the value of the flag."
2774 (let* ((arg (texinfo-parse-arg-discard))
2775 (flag (car (read-from-string arg)))
2776 (value (substring arg (cdr (read-from-string arg)))))
2777 (put flag 'texinfo-whether-setp 'flag-cleared)
2778 (put flag 'texinfo-set-value "")))
2780 (put 'set 'texinfo-format 'texinfo-set)
2781 (defun texinfo-set ()
2782 "Set the value of the flag, optionally to a string.
2783 The command `@set foo This is a string.'
2784 sets flag foo to the value: `This is a string.'
2785 The command `@value{foo}' expands to the value."
2786 (let* ((arg (texinfo-parse-arg-discard))
2787 (flag (car (read-from-string arg)))
2788 (value (substring arg (cdr (read-from-string arg)))))
2789 (put flag 'texinfo-whether-setp 'flag-set)
2790 (put flag 'texinfo-set-value value)))
2792 (put 'value 'texinfo-format 'texinfo-value)
2793 (defun texinfo-value ()
2794 "Insert the string to which the flag is set.
2795 The command `@set foo This is a string.'
2796 sets flag foo to the value: `This is a string.'
2797 The command `@value{foo}' expands to the value."
2798 (let ((arg (texinfo-parse-arg-discard)))
2800 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2802 (get (car (read-from-string arg)) 'texinfo-set-value))
2803 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
2804 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2806 (insert (format "{No value for \"%s\"}" arg)))
2807 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
2808 (insert (format "{No value for \"%s\"}" arg))))))
2810 (put 'ifset 'texinfo-end 'texinfo-discard-command)
2811 (put 'ifset 'texinfo-format 'texinfo-if-set)
2812 (defun texinfo-if-set ()
2813 "If set, continue formatting; else do not format region up to @end ifset"
2814 (let ((arg (texinfo-parse-arg-discard)))
2816 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2818 ;; Format the text (i.e., do not remove it); do nothing here.
2820 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2822 ;; Clear region (i.e., cause the text to be ignored).
2823 (delete-region texinfo-command-start
2824 (progn (re-search-forward "@end ifset[ \t]*\n")
2826 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2828 (error "@ifset flag `%s' is not defined by @set or @clear." arg)))))
2830 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
2831 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
2832 (defun texinfo-if-clear ()
2833 "If clear, continue formatting; if set, do not format up to @end ifset"
2834 (let ((arg (texinfo-parse-arg-discard)))
2836 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2838 ;; Clear region (i.e., cause the text to be ignored).
2839 (delete-region texinfo-command-start
2840 (progn (re-search-forward "@end ifclear[ \t]*\n")
2842 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2844 ;; Format the text (i.e., do not remove it); do nothing here.
2846 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2848 (error "@ifclear flag `%s' is not defined by @clear or @set." arg)))))
2851 ;;; Process included files: `@include' command
2853 ;; Updated 19 October 1990
2854 ;; In the original version, include files were ignored by Info but
2855 ;; incorporated in to the printed manual. To make references to the
2856 ;; included file, the Texinfo source file has to refer to the included
2857 ;; files using the `(filename)nodename' format for refering to other
2858 ;; Info files. Also, the included files had to be formatted on their
2859 ;; own. It was just like they were another file.
2861 ;; Currently, include files are inserted into the buffer that is
2862 ;; formatted for Info. If large, the resulting info file is split and
2863 ;; tagified. For current include files to work, the master menu must
2864 ;; refer to all the nodes, and the highest level nodes in the include
2865 ;; files must have the correct next, prev, and up pointers.
2867 ;; The included file may have an @setfilename and even an @settitle,
2868 ;; but not an `\input texinfo' line.
2870 ;; Updated 24 March 1993
2871 ;; In order for @raisesections and @lowersections to work, included
2872 ;; files must be inserted into the buffer holding the outer file
2873 ;; before other Info formatting takes place. So @include is no longer
2874 ;; is treated like other @-commands.
2875 (put 'include 'texinfo-format 'texinfo-format-noop)
2877 ; Original definition:
2878 ; (defun texinfo-format-include ()
2879 ; (let ((filename (texinfo-parse-arg-discard))
2880 ; (default-directory input-directory)
2885 ; (cond ((file-readable-p (concat filename ".texinfo"))
2886 ; (concat filename ".texinfo"))
2887 ; ((file-readable-p (concat filename ".texi"))
2888 ; (concat filename ".texi"))
2889 ; ((file-readable-p (concat filename ".tex"))
2890 ; (concat filename ".tex"))
2891 ; ((file-readable-p filename)
2893 ; (t (error "@include'd file %s not found"
2895 ; (texinfo-format-buffer-1))))
2896 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
2897 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
2898 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
2899 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
2900 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
2901 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
2903 ;(defun texinfo-subindex (indexvar file content)
2904 ; (set indexvar (cons (list 'recurse file content)
2905 ; (symbol-value indexvar))))
2907 ; Second definition:
2908 ; (put 'include 'texinfo-format 'texinfo-format-include)
2909 ; (defun texinfo-format-include ()
2910 ; (let ((filename (concat input-directory
2911 ; (texinfo-parse-arg-discard)))
2912 ; (default-directory input-directory))
2913 ; (message "Reading: %s" filename)
2918 ; (+ (point) (car (cdr (insert-file-contents filename)))))
2919 ; (goto-char (point-min))
2920 ; (texinfo-append-refill)
2921 ; (texinfo-format-convert (point-min) (point-max))))
2922 ; (setq last-input-buffer input-buffer) ; to bypass setfilename
2926 ;;; Numerous commands do nothing in Texinfo
2928 ;; These commands are defined in texinfo.tex for printed output.
2930 (put 'bye 'texinfo-format 'texinfo-discard-line)
2931 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
2932 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
2933 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
2934 (put 'finalout 'texinfo-format 'texinfo-discard-line)
2935 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
2936 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
2937 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
2938 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
2939 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
2940 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
2941 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
2942 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
2943 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
2944 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
2945 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
2946 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
2947 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
2948 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
2949 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
2950 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
2951 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
2954 ;;; Some commands cannot be handled
2956 (defun texinfo-unsupported ()
2957 (error "%s is not handled by texinfo"
2958 (buffer-substring texinfo-command-start texinfo-command-end)))
2960 ;;; Batch formatting
2962 (defun batch-texinfo-format ()
2963 "Runs texinfo-format-buffer on the files remaining on the command line.
2964 Must be used only with -batch, and kills emacs on completion.
2965 Each file will be processed even if an error occurred previously.
2967 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
2968 (if (not noninteractive)
2969 (error "batch-texinfo-format may only be used -batch."))
2970 (let ((version-control t)
2971 (auto-save-default nil)
2972 (find-file-run-dired nil)
2973 (kept-old-versions 259259)
2974 (kept-new-versions 259259))
2978 (while command-line-args-left
2979 (setq file (expand-file-name (car command-line-args-left)))
2980 (cond ((not (file-exists-p file))
2981 (message ">> %s does not exist!" file)
2983 command-line-args-left (cdr command-line-args-left)))
2984 ((file-directory-p file)
2985 (setq command-line-args-left
2986 (nconc (directory-files file)
2987 (cdr command-line-args-left))))
2989 (setq files (cons file files)
2990 command-line-args-left (cdr command-line-args-left)))))
2992 (setq file (car files)
2996 (if buffer-file-name (kill-buffer (current-buffer)))
2998 (buffer-disable-undo (current-buffer))
2999 (set-buffer-modified-p nil)
3001 (message "texinfo formatting %s..." file)
3002 (texinfo-format-buffer nil)
3003 (if (buffer-modified-p)
3004 (progn (message "Saving modified %s" (buffer-file-name))
3007 (message ">> Error: %s" (prin1-to-string err))
3008 (message ">> point at")
3009 (let ((s (buffer-substring (point)
3010 (min (+ (point) 100)
3013 (while (setq tem (string-match "\n+" s tem))
3014 (setq s (concat (substring s 0 (match-beginning 0))
3016 (substring s (match-end 0)))
3018 (message ">> %s" s))
3020 (kill-emacs error))))
3023 ;;; Place `provide' at end of file.
3026 ;;; texinfmt.el ends here.