1 ;;; texinfmt.el --- format Texinfo files into Info files.
3 ;; Copyright (C) 1985, 1986, 1988,
4 ;; 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
6 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;;; Emacs lisp functions to convert Texinfo files to Info files.
28 (defvar texinfmt-version
"2.32 of 19 November 1993")
30 ;;; Variable definitions
32 (require 'texinfo
) ; So `texinfo-footnote-style' is defined.
33 (require 'texnfo-upd
) ; So `texinfo-section-types-regexp' is defined.
35 (defvar texinfo-format-syntax-table nil
)
37 (defvar texinfo-vindex
)
38 (defvar texinfo-findex
)
39 (defvar texinfo-cindex
)
40 (defvar texinfo-pindex
)
41 (defvar texinfo-tindex
)
42 (defvar texinfo-kindex
)
43 (defvar texinfo-last-node
)
44 (defvar texinfo-node-names
)
45 (defvar texinfo-enclosure-list
)
46 (defvar texinfo-alias-list
)
48 (defvar texinfo-command-start
)
49 (defvar texinfo-command-end
)
50 (defvar texinfo-command-name
)
51 (defvar texinfo-defun-type
)
52 (defvar texinfo-last-node-pos
)
53 (defvar texinfo-stack
)
54 (defvar texinfo-short-index-cmds-alist
)
55 (defvar texinfo-short-index-format-cmds-alist
)
56 (defvar texinfo-format-filename
)
57 (defvar texinfo-footnote-number
)
58 (defvar texinfo-start-of-header
)
59 (defvar texinfo-end-of-header
)
60 (defvar texinfo-raisesections-alist
)
61 (defvar texinfo-lowersections-alist
)
65 (if texinfo-format-syntax-table
67 (setq texinfo-format-syntax-table
(make-syntax-table))
68 (modify-syntax-entry ?
\" " " texinfo-format-syntax-table
)
69 (modify-syntax-entry ?
\\ " " texinfo-format-syntax-table
)
70 (modify-syntax-entry ?
@ "\\" texinfo-format-syntax-table
)
71 (modify-syntax-entry ?\^q
"\\" texinfo-format-syntax-table
)
72 (modify-syntax-entry ?\
[ "." texinfo-format-syntax-table
)
73 (modify-syntax-entry ?\
] "." texinfo-format-syntax-table
)
74 (modify-syntax-entry ?\
( "." texinfo-format-syntax-table
)
75 (modify-syntax-entry ?\
) "." texinfo-format-syntax-table
)
76 (modify-syntax-entry ?
{ "(}" texinfo-format-syntax-table
)
77 (modify-syntax-entry ?
} "){" texinfo-format-syntax-table
)
78 (modify-syntax-entry ?
\' "." texinfo-format-syntax-table
))
81 ;;; Top level buffer and region formatting functions
84 (defun texinfo-format-buffer (&optional notagify
)
85 "Process the current buffer as texinfo code, into an Info file.
86 The Info file output is generated in a buffer visiting the Info file
87 names specified in the @setfilename command.
89 Non-nil argument (prefix, if interactive) means don't make tag table
90 and don't split the file if large. You can use Info-tagify and
91 Info-split to do these manually."
93 (let ((lastmessage "Formatting Info file..."))
95 (texinfo-format-buffer-1)
98 (if (> (buffer-size) 30000)
100 (message (setq lastmessage
"Making tags table for Info file..."))
102 (if (> (buffer-size) 100000)
104 (message (setq lastmessage
"Splitting Info file..."))
106 (message (concat lastmessage
107 (if (interactive-p) "done. Now save it." "done.")))))
109 (defvar texinfo-region-buffer-name
"*Info Region*"
110 "*Name of the temporary buffer used by \\[texinfo-format-region].")
113 (defun texinfo-format-region (region-beginning region-end
)
114 "Convert the current region of the Texinfo file to Info format.
115 This lets you see what that part of the file will look like in Info.
116 The command is bound to \\[texinfo-format-region]. The text that is
117 converted to Info is stored in a temporary buffer."
119 (message "Converting region to Info format...")
120 (let (texinfo-command-start
130 (texinfo-format-filename "")
131 texinfo-example-start
132 texinfo-last-node-pos
135 (texinfo-footnote-number 0)
137 (fill-column-for-info fill-column
)
138 (input-buffer (current-buffer))
139 (input-directory default-directory
)
144 ;;; Copy lines between beginning and end of header lines,
145 ;;; if any, or else copy the `@setfilename' line, if any.
149 (goto-char (point-min))
150 (let ((search-end (save-excursion (forward-line 100) (point))))
152 ;; Either copy header text.
155 (search-forward tex-start-of-header search-end t
)
157 ;; Mark beginning of header.
158 (setq header-beginning
(point)))
160 (search-forward tex-end-of-header nil t
)
162 ;; Mark end of header
163 (setq header-end
(point))))
164 ;; Or copy @filename line.
166 (goto-char (point-min))
167 (search-forward "@setfilename" search-end t
)
169 (setq header-beginning
(point))
171 (setq header-end
(point))))
176 (min header-beginning region-beginning
)
179 ;;; Find a buffer to use.
180 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name
))
182 ;; Insert the header into the buffer.
184 ;; Insert the region into the buffer.
185 (insert-buffer-substring
187 (max region-beginning header-end
)
189 ;; Make sure region ends in a newline.
190 (or (= (preceding-char) ?
\n)
193 (goto-char (point-min))
195 (message "Converting region to Info format...")
196 (setq fill-column fill-column-for-info
)
197 ;; Install a syntax table useful for scanning command operands.
198 (set-syntax-table texinfo-format-syntax-table
)
200 ;; Insert @include files so `texinfo-raise-lower-sections' can
201 ;; work on them without losing track of multiple
202 ;; @raise/@lowersections commands.
203 (while (re-search-forward "^@include" nil t
)
204 (setq texinfo-command-end
(point))
205 (let ((filename (concat input-directory
206 (texinfo-parse-line-arg))))
207 (re-search-backward "^@include")
208 (delete-region (point) (save-excursion (forward-line 1) (point)))
209 (message "Reading included file: %s" filename
)
214 (+ (point) (car (cdr (insert-file-contents filename
)))))
215 (goto-char (point-min))
216 ;; Remove `@setfilename' line from included file, if any,
217 ;; so @setfilename command not duplicated.
218 (if (re-search-forward
219 "^@setfilename" (save-excursion (forward-line 100) (point)) t
)
223 (point) (save-excursion (forward-line 1) (point)))))))))
225 ;; Raise or lower level of each section, if necessary.
226 (goto-char (point-min))
227 (texinfo-raise-lower-sections)
228 ;; Append @refill to appropriate paragraphs for filling.
229 (goto-char (point-min))
230 (texinfo-append-refill)
231 ;; If the region includes the effective end of the data,
232 ;; discard everything after that.
233 (goto-char (point-max))
234 (if (re-search-backward "^@bye" nil t
)
235 (delete-region (point) (point-max)))
236 ;; Make sure buffer ends in a newline.
237 (or (= (preceding-char) ?
\n)
239 ;; Don't use a previous value of texinfo-enclosure-list.
240 (setq texinfo-enclosure-list nil
)
241 (setq texinfo-alias-list nil
)
243 (goto-char (point-min))
244 (if (looking-at "\\\\input[ \t]+texinfo")
245 (delete-region (point) (save-excursion (forward-line 1) (point))))
247 ;; Insert Info region title text.
248 (goto-char (point-min))
250 "@setfilename" (save-excursion (forward-line 100) (point)) t
)
252 (setq texinfo-command-end
(point))
254 (setq texinfo-command-start
(point))
255 (let ((arg (texinfo-parse-arg-discard)))
257 texinfo-region-buffer-name
259 (insert (file-name-nondirectory (expand-file-name arg
)))
260 (insert "', -*-Text-*-\n")))
261 ;; Else no `@setfilename' line
263 texinfo-region-buffer-name
264 " buffer -*-Text-*-\n"))
265 (insert "produced by `texinfo-format-region'\n"
267 (if (buffer-file-name input-buffer
)
269 (file-name-sans-versions
270 (file-name-nondirectory
271 (buffer-file-name input-buffer
)))
273 (concat "buffer `" (buffer-name input-buffer
) "'"))
274 "\nusing `texinfmt.el' version "
278 ;; Now convert for real.
279 (goto-char (point-min))
280 (texinfo-format-scan)
281 (goto-char (point-min))
286 ;;; Primary internal formatting function for the whole buffer.
288 (defun texinfo-format-buffer-1 ()
289 (let (texinfo-format-filename
290 texinfo-example-start
291 texinfo-command-start
295 texinfo-last-node-pos
304 (texinfo-footnote-number 0)
307 (fill-column-for-info fill-column
)
308 (input-buffer (current-buffer))
309 (input-directory default-directory
))
310 (setq texinfo-enclosure-list nil
)
311 (setq texinfo-alias-list nil
)
313 (goto-char (point-min))
314 (or (search-forward "@setfilename" nil t
)
315 (error "Texinfo file needs an `@setfilename FILENAME' line."))
316 (setq texinfo-command-end
(point))
317 (setq outfile
(texinfo-parse-line-arg)))
320 (setq fill-column fill-column-for-info
)
321 (set-syntax-table texinfo-format-syntax-table
)
323 (insert-buffer-substring input-buffer
)
324 (message "Converting %s to Info format..." (buffer-name input-buffer
))
326 ;; Insert @include files so `texinfo-raise-lower-sections' can
327 ;; work on them without losing track of multiple
328 ;; @raise/@lowersections commands.
329 (goto-char (point-min))
330 (while (re-search-forward "^@include" nil t
)
331 (setq texinfo-command-end
(point))
332 (let ((filename (concat input-directory
333 (texinfo-parse-line-arg))))
334 (re-search-backward "^@include")
335 (delete-region (point) (save-excursion (forward-line 1) (point)))
336 (message "Reading included file: %s" filename
)
341 (+ (point) (car (cdr (insert-file-contents filename
)))))
342 (goto-char (point-min))
343 ;; Remove `@setfilename' line from included file, if any,
344 ;; so @setfilename command not duplicated.
345 (if (re-search-forward
347 (save-excursion (forward-line 100) (point)) t
)
351 (point) (save-excursion (forward-line 1) (point)))))))))
352 ;; Raise or lower level of each section, if necessary.
353 (goto-char (point-min))
354 (texinfo-raise-lower-sections)
355 ;; Append @refill to appropriate paragraphs
356 (goto-char (point-min))
357 (texinfo-append-refill)
358 (goto-char (point-min))
359 (search-forward "@setfilename")
361 (delete-region (point-min) (point))
362 ;; Remove @bye at end of file, if it is there.
363 (goto-char (point-max))
364 (if (search-backward "@bye" nil t
)
365 (delete-region (point) (point-max)))
366 ;; Make sure buffer ends in a newline.
367 (or (= (preceding-char) ?
\n)
369 ;; Scan the whole buffer, converting to Info format.
370 (texinfo-format-scan)
371 ;; Return data for indices.
372 (goto-char (point-min))
374 texinfo-vindex texinfo-findex texinfo-cindex
375 texinfo-pindex texinfo-tindex texinfo-kindex
)))
378 ;;; Perform non-@-command file conversions: quotes and hyphens
380 (defun texinfo-format-convert (min max
)
381 ;; Convert left and right quotes to typewriter font quotes.
383 (while (search-forward "``" max t
)
384 (replace-match "\""))
386 (while (search-forward "''" max t
)
387 (replace-match "\""))
388 ;; Convert three hyphens in a row to two.
390 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t
)
391 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
395 ;;; Handle paragraph filling
397 (defvar texinfo-no-refill-regexp
398 "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|ifhtml\\|tex\\|html\\)"
399 "Regexp specifying environments in which paragraphs are not filled.")
401 (defvar texinfo-part-of-para-regexp
402 "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
403 "Regexp specifying @-commands found within paragraphs.")
405 (defun texinfo-append-refill ()
406 "Append @refill at end of each paragraph that should be filled.
407 Do not append @refill to paragraphs within @example and similar environments.
408 Do not append @refill to paragraphs containing @w{TEXT} or @*."
410 ;; It is necessary to append @refill before other processing because
411 ;; the other processing removes information that tells Texinfo
412 ;; whether the text should or should not be filled.
414 (while (< (point) (point-max))
415 (let ((refill-blank-lines "^[ \t\n]*$")
416 (case-fold-search nil
)) ; Don't confuse @TeX and @tex....
418 ;; 1. Skip over blank lines;
419 ;; skip over lines beginning with @-commands,
420 ;; but do not skip over lines
421 ;; that are no-refill environments such as @example or
422 ;; that begin with within-paragraph @-commands such as @code.
423 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines
))
427 texinfo-no-refill-regexp
429 texinfo-part-of-para-regexp
431 (< (point) (point-max)))
433 ;; 2. Skip over @example and similar no-refill environments.
434 (if (looking-at texinfo-no-refill-regexp
)
436 (buffer-substring (match-beginning 1) (match-end 1))))
437 (progn (re-search-forward (concat "^@end " environment
) nil t
)
439 ;; 3. Do not refill a paragraph containing @w or @*
441 (>= (point) (point-max))
443 "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t
))
444 ;; Go to end of paragraph and do nothing.
446 ;; 4. Else go to end of paragraph and insert @refill
452 (save-excursion (skip-chars-backward " \t") (point)))
453 ;; `looking-at-backward' not available in v. 18.57
454 ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
455 (if (not (re-search-backward
457 (save-excursion (beginning-of-line) (point))
460 (forward-line 1))))))
463 ;;; Handle `@raisesections' and `@lowersections' commands
465 ;; These commands change the hierarchical level of chapter structuring
468 ;; @raisesections changes @subsection to @section,
469 ;; @section to @chapter,
472 ;; @lowersections changes @chapter to @section
473 ;; @subsection to @subsubsection,
476 ;; An @raisesections/@lowersections command changes only those
477 ;; structuring commands that follow the @raisesections/@lowersections
480 ;; Repeated @raisesections/@lowersections continue to raise or lower
481 ;; the heading level.
483 ;; An @lowersections command cancels an @raisesections command, and
486 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
487 ;; trying to do so does not elicit an error---you just get more
488 ;; headings that mean the same thing as you keep raising or lowering
489 ;; (for example, after a single @raisesections, both @chapter and
490 ;; @section produce chapter headings).
492 (defun texinfo-raise-lower-sections ()
493 "Raise or lower the hierarchical level of chapters, sections, etc.
495 This function acts according to `@raisesections' and `@lowersections'
496 commands in the Texinfo file.
498 For example, an `@lowersections' command is useful if you wish to
499 include what is written as an outer or standalone Texinfo file in
500 another Texinfo file as an inner, included file. The `@lowersections'
501 command changes chapters to sections, sections to subsections and so
504 @raisesections changes @subsection to @section,
505 @section to @chapter,
506 @heading to @chapheading,
509 @lowersections changes @chapter to @section,
510 @subsection to @subsubsection,
511 @heading to @subheading,
514 An `@raisesections' or `@lowersections' command changes only those
515 structuring commands that follow the `@raisesections' or
516 `@lowersections' command.
518 An `@lowersections' command cancels an `@raisesections' command, and
521 Repeated use of the commands continue to raise or lower the hierarchical
522 level a step at a time.
524 An attempt to raise above `chapters' reproduces chapter commands; an
525 attempt to lower below subsubsections reproduces subsubsection
528 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
529 ;; it is a regexp matching chapter, section, other headings
530 ;; (but not the top node).
532 (let (type (level 0))
536 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
537 texinfo-section-types-regexp
541 (save-excursion (setq type
(read (current-buffer))))
544 ;; 1. Increment level
545 ((eq type
'@raisesections
)
546 (setq level
(1+ level
))
548 (point) (save-excursion (forward-line 1) (point))))
550 ;; 2. Decrement level
551 ((eq type
'@lowersections
)
552 (setq level
(1- level
))
554 (point) (save-excursion (forward-line 1) (point))))
556 ;; Now handle structuring commands
559 ;; 3. Raise level when positive
565 (cdr (assq new-level texinfo-raisesections-alist
)))
566 (setq count
(1- count
)))
568 (insert (symbol-name new-level
))))
570 ;; 4. Do nothing except move point when level is zero
571 ((= level
0) (forward-line 1))
573 ;; 5. Lower level when positive
579 (cdr (assq new-level texinfo-lowersections-alist
)))
580 (setq count
(1+ count
)))
582 (insert (symbol-name new-level
))))))))))
584 (defvar texinfo-raisesections-alist
585 '((@chapter .
@chapter
) ; Cannot go higher
586 (@unnumbered .
@unnumbered
)
588 (@majorheading .
@majorheading
)
589 (@chapheading .
@chapheading
)
590 (@appendix .
@appendix
)
592 (@section .
@chapter
)
593 (@unnumberedsec .
@unnumbered
)
594 (@heading .
@chapheading
)
595 (@appendixsec .
@appendix
)
597 (@subsection .
@section
)
598 (@unnumberedsubsec .
@unnumberedsec
)
599 (@subheading .
@heading
)
600 (@appendixsubsec .
@appendixsec
)
602 (@subsubsection .
@subsection
)
603 (@unnumberedsubsubsec .
@unnumberedsubsec
)
604 (@subsubheading .
@subheading
)
605 (@appendixsubsubsec .
@appendixsubsec
))
606 "*An alist of next higher levels for chapters, sections. etc.
607 For example, section to chapter, subsection to section.
608 Used by `texinfo-raise-lower-sections'.
609 The keys specify types of section; the values correspond to the next
612 (defvar texinfo-lowersections-alist
613 '((@chapter .
@section
)
614 (@unnumbered .
@unnumberedsec
)
615 (@majorheading .
@heading
)
616 (@chapheading .
@heading
)
617 (@appendix .
@appendixsec
)
619 (@section .
@subsection
)
620 (@unnumberedsec .
@unnumberedsubsec
)
621 (@heading .
@subheading
)
622 (@appendixsec .
@appendixsubsec
)
624 (@subsection .
@subsubsection
)
625 (@unnumberedsubsec .
@unnumberedsubsubsec
)
626 (@subheading .
@subsubheading
)
627 (@appendixsubsec .
@appendixsubsubsec
)
629 (@subsubsection .
@subsubsection
) ; Cannot go lower.
630 (@unnumberedsubsubsec .
@unnumberedsubsubsec
)
631 (@subsubheading .
@subsubheading
)
632 (@appendixsubsubsec .
@appendixsubsubsec
))
633 "*An alist of next lower levels for chapters, sections. etc.
634 For example, chapter to section, section to subsection.
635 Used by `texinfo-raise-lower-sections'.
636 The keys specify types of section; the values correspond to the next
640 ;;; Perform those texinfo-to-info conversions that apply to the whole input
643 (defun texinfo-format-scan ()
644 (texinfo-format-convert (point-min) (point-max))
645 ;; Scan for @-commands.
646 (goto-char (point-min))
647 (while (search-forward "@" nil t
)
648 (if (looking-at "[@{}^'` *\"?!]")
649 ;; Handle a few special @-followed-by-one-char commands.
650 (if (= (following-char) ?
*)
653 (delete-region (1- (point)) (1+ (point)))
654 ;; insert return if not at end of line;
655 ;; else line is already broken.
656 (if (not (= (following-char) ?
\n))
658 ;; The other characters are simply quoted. Delete the @.
661 ;; @ is followed by a command-word; find the end of the word.
662 (setq texinfo-command-start
(1- (point)))
663 (if (= (char-syntax (following-char)) ?w
)
666 (setq texinfo-command-end
(point))
667 ;; Handle let aliasing
668 (setq texinfo-command-name
672 (1+ texinfo-command-start
) texinfo-command-end
)))
673 (while (setq trial
(assoc cmdname texinfo-alias-list
))
674 (setq cmdname
(cdr trial
)))
676 ;; Call the handler for this command.
677 (let ((enclosure-type
679 (symbol-name texinfo-command-name
)
680 texinfo-enclosure-list
)))
684 (car (car (cdr enclosure-type
)))
685 (texinfo-parse-arg-discard)
686 (car (cdr (car (cdr enclosure-type
)))))
687 (goto-char texinfo-command-start
))
688 (let ((cmd (get texinfo-command-name
'texinfo-format
)))
689 (if cmd
(funcall cmd
) (texinfo-unsupported)))))))
692 (goto-char (nth 2 (car texinfo-stack
)))
693 (error "Unterminated @%s" (car (car texinfo-stack
))))))
695 (put 'begin
'texinfo-format
'texinfo-format-begin
)
696 (defun texinfo-format-begin ()
697 (texinfo-format-begin-end 'texinfo-format
))
699 (put 'end
'texinfo-format
'texinfo-format-end
)
700 (defun texinfo-format-end ()
701 (texinfo-format-begin-end 'texinfo-end
))
703 (defun texinfo-format-begin-end (prop)
704 (setq texinfo-command-name
(intern (texinfo-parse-line-arg)))
705 (let ((cmd (get texinfo-command-name prop
)))
706 (if cmd
(funcall cmd
)
707 (texinfo-unsupported))))
709 ;;; Parsing functions
711 (defun texinfo-parse-line-arg ()
712 (goto-char texinfo-command-end
)
713 (let ((start (point)))
714 (cond ((looking-at " ")
715 (skip-chars-forward " ")
718 (skip-chars-backward " ")
719 (delete-region (point) (progn (end-of-line) (point)))
720 (setq texinfo-command-end
(1+ (point))))
722 (setq start
(1+ (point)))
724 (setq texinfo-command-end
(point))
727 (error "Invalid texinfo command arg format")))
728 (prog1 (buffer-substring start
(point))
729 (if (eolp) (forward-char 1)))))
731 (defun texinfo-parse-expanded-arg ()
732 (goto-char texinfo-command-end
)
733 (let ((start (point))
735 (cond ((looking-at " ")
736 (skip-chars-forward " ")
739 (setq texinfo-command-end
(1+ (point))))
741 (setq start
(1+ (point)))
743 (setq texinfo-command-end
(point))
746 (error "Invalid texinfo command arg format")))
747 (setq marker
(move-marker (make-marker) texinfo-command-end
))
748 (texinfo-format-expand-region start
(point))
749 (setq texinfo-command-end
(marker-position marker
))
750 (move-marker marker nil
)
751 (prog1 (buffer-substring start
(point))
752 (if (eolp) (forward-char 1)))))
754 (defun texinfo-format-expand-region (start end
)
756 (narrow-to-region start end
)
757 (let (texinfo-command-start
761 (texinfo-format-scan))
762 (goto-char (point-max))))
764 (defun texinfo-parse-arg-discard ()
765 (prog1 (texinfo-parse-line-arg)
766 (texinfo-discard-command)))
768 (defun texinfo-discard-command ()
769 (delete-region texinfo-command-start texinfo-command-end
))
771 (defun texinfo-optional-braces-discard ()
772 "Discard braces following command, if any."
773 (goto-char texinfo-command-end
)
774 (let ((start (point)))
775 (cond ((looking-at "[ \t]*\n")) ; do nothing
776 ((looking-at "{") ; remove braces, if any
778 (setq texinfo-command-end
(point)))
781 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
782 (delete-region texinfo-command-start texinfo-command-end
)))
784 (defun texinfo-format-parse-line-args ()
785 (let ((start (1- (point)))
788 (skip-chars-forward " ")
791 (re-search-forward "[\n,]")
793 (if (bolp) (setq next
(1- next
)))
795 (skip-chars-backward " ")
797 (setq args
(cons (if (> end beg
) (buffer-substring beg end
))
800 (skip-chars-forward " "))
801 (if (eolp) (forward-char 1))
802 (setq texinfo-command-end
(point))
805 (defun texinfo-format-parse-args ()
806 (let ((start (1- (point)))
811 (texinfo-format-expand-region
813 (save-excursion (up-list 1) (1- (point)))))
814 ;; The following does not handle cross references of the form:
815 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
816 ;; re-search-forward finds the first right brace after the second
818 (while (/= (preceding-char) ?\
})
819 (skip-chars-forward " \t\n")
821 (re-search-forward "[},]")
824 (skip-chars-backward " \t\n")
828 (while (search-forward "\n" end t
)
829 (replace-match " "))))
830 (setq args
(cons (if (> end beg
) (buffer-substring beg end
))
833 (if (eolp) (forward-char 1))
834 (setq texinfo-command-end
(point))
837 (defun texinfo-format-parse-defun-args ()
838 (goto-char texinfo-command-end
)
839 (let ((start (point)))
841 (setq texinfo-command-end
(1+ (point)))
842 (let ((marker (move-marker (make-marker) texinfo-command-end
)))
843 (texinfo-format-expand-region start
(point))
844 (setq texinfo-command-end
(marker-position marker
))
845 (move-marker marker nil
))
849 (skip-chars-forward " ")
851 (cond ((looking-at "{")
852 (setq beg
(1+ (point)))
854 (setq end
(1- (point))))
857 (re-search-forward "[\n ]")
860 (setq args
(cons (buffer-substring beg end
) args
))
861 (skip-chars-forward " "))
865 (defun texinfo-discard-line ()
866 (goto-char texinfo-command-end
)
867 (skip-chars-forward " \t")
869 (error "Extraneous text at end of command line."))
870 (goto-char texinfo-command-start
)
872 (error "Extraneous text at beginning of command line."))
873 (delete-region (point) (progn (forward-line 1) (point))))
875 (defun texinfo-discard-line-with-args ()
876 (goto-char texinfo-command-start
)
877 (delete-region (point) (progn (forward-line 1) (point))))
882 ;; Only `texinfo-format-buffer' handles @setfilename with this
883 ;; definition; `texinfo-format-region' handles @setfilename, if any,
885 (put 'setfilename
'texinfo-format
'texinfo-format-setfilename
)
886 (defun texinfo-format-setfilename ()
887 (let ((arg (texinfo-parse-arg-discard)))
888 (message "Formatting Info file: %s" arg
)
889 (setq texinfo-format-filename
890 (file-name-nondirectory (expand-file-name arg
)))
891 (insert "Info file: "
892 texinfo-format-filename
", -*-Text-*-\n"
893 ;; Date string removed so that regression testing is easier.
895 ;; (substring (current-time-string) 8 10) " "
896 ;; (substring (current-time-string) 4 7) " "
897 ;; (substring (current-time-string) -4) " "
898 "produced by `texinfo-format-buffer'\n"
900 (if (buffer-file-name input-buffer
)
902 (file-name-sans-versions
903 (file-name-nondirectory
904 (buffer-file-name input-buffer
)))
906 (concat "buffer `" (buffer-name input-buffer
) "'"))
907 "\nusing `texinfmt.el' version "
913 (put 'node
'texinfo-format
'texinfo-format-node
)
914 (put 'nwnode
'texinfo-format
'texinfo-format-node
)
915 (defun texinfo-format-node ()
916 (let* ((args (texinfo-format-parse-line-args))
921 (texinfo-discard-command)
922 (setq texinfo-last-node name
)
923 (let ((tem (downcase name
)))
924 (if (assoc tem texinfo-node-names
)
925 (error "Duplicate node name: %s" name
)
926 (setq texinfo-node-names
(cons (list tem
) texinfo-node-names
))))
927 (setq texinfo-footnote-number
0)
928 ;; insert "\n\^_" unconditionally since this is what info is looking for
929 (insert "\n\^_\nFile: " texinfo-format-filename
932 (insert ", Next: " next
))
934 (insert ", Prev: " prev
))
936 (insert ", Up: " up
))
938 (setq texinfo-last-node-pos
(point))))
940 (put 'menu
'texinfo-format
'texinfo-format-menu
)
941 (defun texinfo-format-menu ()
942 (texinfo-discard-line)
943 (insert "* Menu:\n\n"))
945 (put 'menu
'texinfo-end
'texinfo-discard-command
)
950 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
951 ; -> *Note FNAME: (FILE)NODE
952 ; If FILE is missing,
954 ; If FNAME is empty and NAME is present
956 ; If both NAME and FNAME are missing
958 ; texinfo ignores the DOCUMENT argument.
959 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
960 ; If FILE is specified, (FILE)NODE is used for xrefs.
961 ; If fifth argument DOCUMENT is specified, produces
962 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
965 ; @ref a reference that does not put `See' or `see' in
966 ; the hardcopy and is the same as @xref in Info
967 (put 'ref
'texinfo-format
'texinfo-format-xref
)
969 (put 'xref
'texinfo-format
'texinfo-format-xref
)
970 (defun texinfo-format-xref ()
971 (let ((args (texinfo-format-parse-args)))
972 (texinfo-discard-command)
974 (let ((fname (or (nth 1 args
) (nth 2 args
))))
975 (if (null (or fname
(nth 3 args
)))
976 (insert (car args
) "::")
977 (insert (or fname
(car args
)) ": ")
979 (insert "(" (nth 3 args
) ")"))
980 (insert (car args
))))))
982 (put 'pxref
'texinfo-format
'texinfo-format-pxref
)
983 (defun texinfo-format-pxref ()
984 (texinfo-format-xref)
990 ;@inforef{NODE, FNAME, FILE}
991 ;Like @xref{NODE, FNAME,,FILE} in texinfo.
992 ;In Tex, generates "See Info file FILE, node NODE"
993 (put 'inforef
'texinfo-format
'texinfo-format-inforef
)
994 (defun texinfo-format-inforef ()
995 (let ((args (texinfo-format-parse-args)))
996 (texinfo-discard-command)
998 (insert "*Note " (nth 1 args
) ": (" (nth 2 args
) ")" (car args
))
999 (insert "*Note " "(" (nth 2 args
) ")" (car args
) "::"))))
1002 ;;; Section headings
1004 (put 'majorheading
'texinfo-format
'texinfo-format-chapter
)
1005 (put 'chapheading
'texinfo-format
'texinfo-format-chapter
)
1006 (put 'ichapter
'texinfo-format
'texinfo-format-chapter
)
1007 (put 'chapter
'texinfo-format
'texinfo-format-chapter
)
1008 (put 'iappendix
'texinfo-format
'texinfo-format-chapter
)
1009 (put 'appendix
'texinfo-format
'texinfo-format-chapter
)
1010 (put 'iunnumbered
'texinfo-format
'texinfo-format-chapter
)
1011 (put 'top
'texinfo-format
'texinfo-format-chapter
)
1012 (put 'unnumbered
'texinfo-format
'texinfo-format-chapter
)
1013 (defun texinfo-format-chapter ()
1014 (texinfo-format-chapter-1 ?
*))
1016 (put 'heading
'texinfo-format
'texinfo-format-section
)
1017 (put 'isection
'texinfo-format
'texinfo-format-section
)
1018 (put 'section
'texinfo-format
'texinfo-format-section
)
1019 (put 'iappendixsection
'texinfo-format
'texinfo-format-section
)
1020 (put 'appendixsection
'texinfo-format
'texinfo-format-section
)
1021 (put 'iappendixsec
'texinfo-format
'texinfo-format-section
)
1022 (put 'appendixsec
'texinfo-format
'texinfo-format-section
)
1023 (put 'iunnumberedsec
'texinfo-format
'texinfo-format-section
)
1024 (put 'unnumberedsec
'texinfo-format
'texinfo-format-section
)
1025 (defun texinfo-format-section ()
1026 (texinfo-format-chapter-1 ?
=))
1028 (put 'subheading
'texinfo-format
'texinfo-format-subsection
)
1029 (put 'isubsection
'texinfo-format
'texinfo-format-subsection
)
1030 (put 'subsection
'texinfo-format
'texinfo-format-subsection
)
1031 (put 'iappendixsubsec
'texinfo-format
'texinfo-format-subsection
)
1032 (put 'appendixsubsec
'texinfo-format
'texinfo-format-subsection
)
1033 (put 'iunnumberedsubsec
'texinfo-format
'texinfo-format-subsection
)
1034 (put 'unnumberedsubsec
'texinfo-format
'texinfo-format-subsection
)
1035 (defun texinfo-format-subsection ()
1036 (texinfo-format-chapter-1 ?-
))
1038 (put 'subsubheading
'texinfo-format
'texinfo-format-subsubsection
)
1039 (put 'isubsubsection
'texinfo-format
'texinfo-format-subsubsection
)
1040 (put 'subsubsection
'texinfo-format
'texinfo-format-subsubsection
)
1041 (put 'iappendixsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
1042 (put 'appendixsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
1043 (put 'iunnumberedsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
1044 (put 'unnumberedsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
1045 (defun texinfo-format-subsubsection ()
1046 (texinfo-format-chapter-1 ?.
))
1048 (defun texinfo-format-chapter-1 (belowchar)
1049 (let ((arg (texinfo-parse-arg-discard)))
1050 (message "Formatting: %s ... " arg
) ; So we can see where we are.
1051 (insert ?
\n arg ?
\n "@SectionPAD " belowchar ?
\n)
1054 (put 'SectionPAD
'texinfo-format
'texinfo-format-sectionpad
)
1055 (defun texinfo-format-sectionpad ()
1056 (let ((str (texinfo-parse-arg-discard)))
1058 (let ((column (current-column)))
1062 (setq column
(1- column
))))
1066 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1068 (put '\.
'texinfo-format
'texinfo-format-\.
)
1069 (defun texinfo-format-\.
()
1070 (texinfo-discard-command)
1073 (put '\
: 'texinfo-format
'texinfo-format-\
:)
1074 (defun texinfo-format-\
: ()
1075 (texinfo-discard-command))
1077 (put '\-
'texinfo-format
'texinfo-format-soft-hyphen
)
1078 (defun texinfo-format-soft-hyphen ()
1079 (texinfo-discard-command))
1082 ;;; @center, @sp, and @br
1084 (put 'center
'texinfo-format
'texinfo-format-center
)
1085 (defun texinfo-format-center ()
1086 (let ((arg (texinfo-parse-expanded-arg)))
1087 (texinfo-discard-command)
1091 (goto-char (1- (point)))
1092 (let ((indent-tabs-mode nil
))
1095 (put 'sp
'texinfo-format
'texinfo-format-sp
)
1096 (defun texinfo-format-sp ()
1097 (let* ((arg (texinfo-parse-arg-discard))
1099 (insert-char ?
\n num
)))
1101 (put 'br
'texinfo-format
'texinfo-format-paragraph-break
)
1102 (defun texinfo-format-paragraph-break ()
1103 "Force a paragraph break.
1104 If used within a line, follow `@br' with braces."
1105 (texinfo-optional-braces-discard)
1106 ;; insert one return if at end of line;
1107 ;; else insert two returns, to generate a blank line.
1108 (if (= (following-char) ?
\n)
1110 (insert-char ?
\n 2)))
1113 ;;; @footnote and @footnotestyle
1115 ; In Texinfo, footnotes are created with the `@footnote' command.
1116 ; This command is followed immediately by a left brace, then by the text of
1117 ; the footnote, and then by a terminating right brace. The
1118 ; template for a footnote is:
1122 ; Info has two footnote styles:
1124 ; * In the End of node style, all the footnotes for a single node
1125 ; are placed at the end of that node. The footnotes are
1126 ; separated from the rest of the node by a line of dashes with
1127 ; the word `Footnotes' within it.
1129 ; * In the Separate node style, all the footnotes for a single node
1130 ; are placed in an automatically constructed node of their own.
1132 ; Footnote style is specified by the @footnotestyle command, either
1133 ; @footnotestyle separate
1135 ; @footnotestyle end
1137 ; The default is separate
1139 (defvar texinfo-footnote-style
"separate"
1140 "Footnote style, either separate or end.")
1142 (put 'footnotestyle
'texinfo-format
'texinfo-footnotestyle
)
1143 (defun texinfo-footnotestyle ()
1144 "Specify whether footnotes are at end of node or in separate nodes.
1145 Argument is either end or separate."
1146 (setq texinfo-footnote-style
(texinfo-parse-arg-discard)))
1148 (defvar texinfo-footnote-number
)
1150 (put 'footnote
'texinfo-format
'texinfo-format-footnote
)
1151 (defun texinfo-format-footnote ()
1152 "Format a footnote in either end of node or separate node style.
1153 The texinfo-footnote-style variable controls which style is used."
1154 (setq texinfo-footnote-number
(1+ texinfo-footnote-number
))
1155 (cond ((string= texinfo-footnote-style
"end")
1156 (texinfo-format-end-node))
1157 ((string= texinfo-footnote-style
"separate")
1158 (texinfo-format-separate-node))))
1160 (defun texinfo-format-separate-node ()
1161 "Format footnote in Separate node style, with notes in own node.
1162 The node is constructed automatically."
1164 (arg (texinfo-parse-line-arg))
1165 (node-name-beginning
1168 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1173 (progn (goto-char node-name-beginning
) ; skip over node command
1174 (skip-chars-forward " \t") ; and over spaces
1178 (save-excursion (end-of-line) (point)) t
) ; bound search
1180 (end-of-line) (point))))))
1181 (texinfo-discard-command) ; remove or insert whitespace, as needed
1182 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1184 (insert (format " (%d) (*Note %s-Footnotes::)"
1185 texinfo-footnote-number node-name
))
1186 (fill-paragraph nil
)
1188 (if (re-search-forward "^@node" nil
'move
)
1191 ;; two cases: for the first footnote, we must insert a node header;
1192 ;; for the second and subsequent footnotes, we need only insert
1193 ;; the text of the footnote.
1197 (concat node-name
"-Footnotes, Up: ")
1200 (progn ; already at least one footnote
1201 (setq start
(point))
1202 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
1203 (fill-region start
(point)))
1204 ;; else not yet a footnote
1205 (insert "\n\^_\nFile: " texinfo-format-filename
1206 " Node: " node-name
"-Footnotes, Up: " node-name
"\n")
1207 (setq start
(point))
1208 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
1209 (fill-region start
(point))))))
1211 (defun texinfo-format-end-node ()
1212 "Format footnote in the End of node style, with notes at end of node."
1214 (arg (texinfo-parse-line-arg)))
1215 (texinfo-discard-command) ; remove or insert whitespace, as needed
1216 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1218 (insert (format " (%d) " texinfo-footnote-number
))
1219 (fill-paragraph nil
)
1221 (if (search-forward "\n--------- Footnotes ---------\n" nil t
)
1222 (progn ; already have footnote, put new one before end of node
1223 (if (re-search-forward "^@node" nil
'move
)
1225 (setq start
(point))
1226 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
1227 (fill-region start
(point)))
1228 ;; else no prior footnote
1229 (if (re-search-forward "^@node" nil
'move
)
1231 (insert "\n--------- Footnotes ---------\n")
1232 (setq start
(point))
1233 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))))))
1236 ;;; @itemize, @enumerate, and similar commands
1238 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1239 ;; @enumerate pushes (enumerate 0 STARTPOS).
1240 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1241 ;; For itemize, this puts in and rescans the COMMANDS.
1242 ;; For enumerate, this increments the number and puts it in.
1243 ;; In either case, it puts a Backspace at the front of the line
1244 ;; which marks it not to be indented later.
1245 ;; All other lines get indented by 5 when the @end is reached.
1247 (defvar texinfo-stack-depth
0
1248 "Count of number of unpopped texinfo-push-stack calls.
1249 Used by @refill indenting command to avoid indenting within lists, etc.")
1251 (defun texinfo-push-stack (check arg
)
1252 (setq texinfo-stack-depth
(1+ texinfo-stack-depth
))
1254 (cons (list check arg texinfo-command-start
)
1257 (defun texinfo-pop-stack (check)
1258 (setq texinfo-stack-depth
(1- texinfo-stack-depth
))
1259 (if (null texinfo-stack
)
1260 (error "Unmatched @end %s" check
))
1261 (if (not (eq (car (car texinfo-stack
)) check
))
1262 (error "@end %s matches @%s"
1263 check
(car (car texinfo-stack
))))
1264 (prog1 (cdr (car texinfo-stack
))
1265 (setq texinfo-stack
(cdr texinfo-stack
))))
1267 (put 'itemize
'texinfo-format
'texinfo-itemize
)
1268 (defun texinfo-itemize ()
1271 (progn (skip-chars-forward " \t")
1274 (texinfo-parse-line-arg))))
1275 (texinfo-discard-line-with-args)
1276 (setq fill-column
(- fill-column
5)))
1278 (put 'itemize
'texinfo-end
'texinfo-end-itemize
)
1279 (defun texinfo-end-itemize ()
1280 (setq fill-column
(+ fill-column
5))
1281 (texinfo-discard-command)
1283 (texinfo-pop-stack 'itemize
)))
1284 (texinfo-do-itemize (nth 1 stacktop
))))
1286 (put 'enumerate
'texinfo-format
'texinfo-enumerate
)
1287 (defun texinfo-enumerate ()
1290 (progn (skip-chars-forward " \t")
1293 (read (current-buffer)))))
1294 (if (and (symbolp (car (cdr (car texinfo-stack
))))
1295 (> 1 (length (symbol-name (car (cdr (car texinfo-stack
)))))))
1297 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1298 (texinfo-discard-line-with-args)
1299 (setq fill-column
(- fill-column
5)))
1301 (put 'enumerate
'texinfo-end
'texinfo-end-enumerate
)
1302 (defun texinfo-end-enumerate ()
1303 (setq fill-column
(+ fill-column
5))
1304 (texinfo-discard-command)
1306 (texinfo-pop-stack 'enumerate
)))
1307 (texinfo-do-itemize (nth 1 stacktop
))))
1309 ;; @alphaenumerate never became a standard part of Texinfo
1310 (put 'alphaenumerate
'texinfo-format
'texinfo-alphaenumerate
)
1311 (defun texinfo-alphaenumerate ()
1312 (texinfo-push-stack 'alphaenumerate
(1- ?a
))
1313 (setq fill-column
(- fill-column
5))
1314 (texinfo-discard-line))
1316 (put 'alphaenumerate
'texinfo-end
'texinfo-end-alphaenumerate
)
1317 (defun texinfo-end-alphaenumerate ()
1318 (setq fill-column
(+ fill-column
5))
1319 (texinfo-discard-command)
1321 (texinfo-pop-stack 'alphaenumerate
)))
1322 (texinfo-do-itemize (nth 1 stacktop
))))
1324 ;; @capsenumerate never became a standard part of Texinfo
1325 (put 'capsenumerate
'texinfo-format
'texinfo-capsenumerate
)
1326 (defun texinfo-capsenumerate ()
1327 (texinfo-push-stack 'capsenumerate
(1- ?A
))
1328 (setq fill-column
(- fill-column
5))
1329 (texinfo-discard-line))
1331 (put 'capsenumerate
'texinfo-end
'texinfo-end-capsenumerate
)
1332 (defun texinfo-end-capsenumerate ()
1333 (setq fill-column
(+ fill-column
5))
1334 (texinfo-discard-command)
1336 (texinfo-pop-stack 'capsenumerate
)))
1337 (texinfo-do-itemize (nth 1 stacktop
))))
1339 ;; At the @end, indent all the lines within the construct
1340 ;; except those marked with backspace. FROM says where
1341 ;; construct started.
1342 (defun texinfo-do-itemize (from)
1344 (while (progn (forward-line -
1)
1346 (if (= (following-char) ?
\b)
1351 (if (not (looking-at "[ \t]*$"))
1352 (save-excursion (insert " ")))))))
1354 (put 'item
'texinfo-format
'texinfo-item
)
1355 (put 'itemx
'texinfo-format
'texinfo-item
)
1356 (defun texinfo-item ()
1357 (funcall (get (car (car texinfo-stack
)) 'texinfo-item
)))
1359 (put 'itemize
'texinfo-item
'texinfo-itemize-item
)
1360 (defun texinfo-itemize-item ()
1361 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1362 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1363 (if (looking-at "[ \t]*[^ \t\n]+")
1364 ;; Text on same line as @item command.
1365 (insert "\b " (nth 1 (car texinfo-stack
)) " \n")
1366 ;; Else text on next line.
1367 (insert "\b " (nth 1 (car texinfo-stack
)) " "))
1370 (put 'enumerate
'texinfo-item
'texinfo-enumerate-item
)
1371 (defun texinfo-enumerate-item ()
1372 (texinfo-discard-line)
1373 (let (enumerating-symbol)
1374 (cond ((integerp (car (cdr (car texinfo-stack
))))
1375 (setq enumerating-symbol
(car (cdr (car texinfo-stack
))))
1376 (insert ?
\b (format "%3d. " enumerating-symbol
) ?
\n)
1377 (setcar (cdr (car texinfo-stack
)) (1+ enumerating-symbol
)))
1378 ((symbolp (car (cdr (car texinfo-stack
))))
1379 (setq enumerating-symbol
1380 (symbol-name (car (cdr (car texinfo-stack
)))))
1381 (if (or (equal ?\
[ (string-to-char enumerating-symbol
))
1382 (equal ?\
{ (string-to-char enumerating-symbol
)))
1384 "Too many items in enumerated list; alphabet ends at Z."))
1385 (insert ?
\b (format "%3s. " enumerating-symbol
) ?
\n)
1386 (setcar (cdr (car texinfo-stack
))
1390 (string-to-char enumerating-symbol
))))))
1393 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1396 (put 'alphaenumerate
'texinfo-item
'texinfo-alphaenumerate-item
)
1397 (defun texinfo-alphaenumerate-item ()
1398 (texinfo-discard-line)
1399 (let ((next (1+ (car (cdr (car texinfo-stack
))))))
1401 (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
1402 (setcar (cdr (car texinfo-stack
)) next
)
1403 (insert "\b " next
". \n"))
1406 (put 'capsenumerate
'texinfo-item
'texinfo-capsenumerate-item
)
1407 (defun texinfo-capsenumerate-item ()
1408 (texinfo-discard-line)
1409 (let ((next (1+ (car (cdr (car texinfo-stack
))))))
1411 (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
1412 (setcar (cdr (car texinfo-stack
)) next
)
1413 (insert "\b " next
". \n"))
1419 ; The `@table' command produces two-column tables.
1421 (put 'table
'texinfo-format
'texinfo-table
)
1422 (defun texinfo-table ()
1425 (progn (skip-chars-forward " \t")
1428 (texinfo-parse-line-arg))))
1429 (texinfo-discard-line-with-args)
1430 (setq fill-column
(- fill-column
5)))
1432 (put 'table
'texinfo-item
'texinfo-table-item
)
1433 (defun texinfo-table-item ()
1434 (let ((arg (texinfo-parse-arg-discard))
1435 (itemfont (car (cdr (car texinfo-stack
)))))
1436 (insert ?
\b itemfont ?\
{ arg
"}\n \n"))
1439 (put 'table
'texinfo-end
'texinfo-end-table
)
1440 (defun texinfo-end-table ()
1441 (setq fill-column
(+ fill-column
5))
1442 (texinfo-discard-command)
1444 (texinfo-pop-stack 'table
)))
1445 (texinfo-do-itemize (nth 1 stacktop
))))
1447 ;; @description appears to be an undocumented variant on @table that
1448 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1449 ;; part of makeinfo.c The command appears to be a relic of the past.
1450 (put 'description
'texinfo-end
'texinfo-end-table
)
1451 (put 'description
'texinfo-format
'texinfo-description
)
1452 (defun texinfo-description ()
1453 (texinfo-push-stack 'table
"@asis")
1454 (setq fill-column
(- fill-column
5))
1455 (texinfo-discard-line))
1458 ;;; @ftable, @vtable
1460 ; The `@ftable' and `@vtable' commands are like the `@table' command
1461 ; but they also insert each entry in the first column of the table
1462 ; into the function or variable index.
1464 ;; Handle the @ftable and @vtable commands:
1466 (put 'ftable
'texinfo-format
'texinfo-ftable
)
1467 (put 'vtable
'texinfo-format
'texinfo-vtable
)
1469 (defun texinfo-ftable () (texinfo-indextable 'ftable
))
1470 (defun texinfo-vtable () (texinfo-indextable 'vtable
))
1472 (defun texinfo-indextable (table-type)
1473 (texinfo-push-stack table-type
(texinfo-parse-arg-discard))
1474 (setq fill-column
(- fill-column
5)))
1476 ;; Handle the @item commands within ftable and vtable:
1478 (put 'ftable
'texinfo-item
'texinfo-ftable-item
)
1479 (put 'vtable
'texinfo-item
'texinfo-vtable-item
)
1481 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex
))
1482 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex
))
1484 (defun texinfo-indextable-item (index-type)
1485 (let ((item (texinfo-parse-arg-discard))
1486 (itemfont (car (cdr (car texinfo-stack
))))
1487 (indexvar index-type
))
1488 (insert ?
\b itemfont ?\
{ item
"}\n \n")
1491 (list item texinfo-last-node
)
1492 (symbol-value indexvar
)))
1495 ;; Handle @end ftable, @end vtable
1497 (put 'ftable
'texinfo-end
'texinfo-end-ftable
)
1498 (put 'vtable
'texinfo-end
'texinfo-end-vtable
)
1500 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable
))
1501 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable
))
1503 (defun texinfo-end-indextable (table-type)
1504 (setq fill-column
(+ fill-column
5))
1505 (texinfo-discard-command)
1507 (texinfo-pop-stack table-type
)))
1508 (texinfo-do-itemize (nth 1 stacktop
))))
1511 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html
1513 (put 'ifinfo
'texinfo-format
'texinfo-discard-line
)
1514 (put 'ifinfo
'texinfo-end
'texinfo-discard-command
)
1516 (put 'iftex
'texinfo-format
'texinfo-format-iftex
)
1517 (defun texinfo-format-iftex ()
1518 (delete-region texinfo-command-start
1519 (progn (re-search-forward "@end iftex[ \t]*\n")
1522 (put 'ifhtml
'texinfo-format
'texinfo-format-ifhtml
)
1523 (defun texinfo-format-ifhtml ()
1524 (delete-region texinfo-command-start
1525 (progn (re-search-forward "@end ifhtml[ \t]*\n")
1528 (put 'tex
'texinfo-format
'texinfo-format-tex
)
1529 (defun texinfo-format-tex ()
1530 (delete-region texinfo-command-start
1531 (progn (re-search-forward "@end tex[ \t]*\n")
1534 (put 'html
'texinfo-format
'texinfo-format-html
)
1535 (defun texinfo-format-html ()
1536 (delete-region texinfo-command-start
1537 (progn (re-search-forward "@end html[ \t]*\n")
1543 (put 'titlepage
'texinfo-format
'texinfo-format-titlepage
)
1544 (defun texinfo-format-titlepage ()
1545 (delete-region texinfo-command-start
1546 (progn (re-search-forward "@end titlepage[ \t]*\n")
1549 (put 'endtitlepage
'texinfo-format
'texinfo-discard-line
)
1551 ; @titlespec an alternative titling command; ignored by Info
1553 (put 'titlespec
'texinfo-format
'texinfo-format-titlespec
)
1554 (defun texinfo-format-titlespec ()
1555 (delete-region texinfo-command-start
1556 (progn (re-search-forward "@end titlespec[ \t]*\n")
1559 (put 'endtitlespec
'texinfo-format
'texinfo-discard-line
)
1564 (put 'today
'texinfo-format
'texinfo-format-today
)
1566 ; Produces Day Month Year style of output. eg `1 Jan 1900'
1567 ; The `@today{}' command requires a pair of braces, like `@dots{}'.
1568 (defun texinfo-format-today ()
1569 (texinfo-parse-arg-discard)
1570 (insert (format "%s %s %s"
1571 (substring (current-time-string) 8 10)
1572 (substring (current-time-string) 4 7)
1573 (substring (current-time-string) -
4))))
1578 (put 'ignore
'texinfo-format
'texinfo-format-ignore
)
1579 (defun texinfo-format-ignore ()
1580 (delete-region texinfo-command-start
1581 (progn (re-search-forward "@end ignore[ \t]*\n")
1584 (put 'endignore
'texinfo-format
'texinfo-discard-line
)
1587 ;;; Define the Info enclosure command: @definfoenclose
1589 ; A `@definfoenclose' command may be used to define a highlighting
1590 ; command for Info, but not for TeX. A command defined using
1591 ; `@definfoenclose' marks text by enclosing it in strings that precede
1592 ; and follow the text.
1594 ; Presumably, if you define a command with `@definfoenclose` for Info,
1595 ; you will also define the same command in the TeX definitions file,
1596 ; `texinfo.tex' in a manner appropriate for typesetting.
1598 ; Write a `@definfoenclose' command on a line and follow it with three
1599 ; arguments separated by commas (commas are used as separators in an
1600 ; `@node' line in the same way). The first argument to
1601 ; `@definfoenclose' is the @-command name \(without the `@'\); the
1602 ; second argument is the Info start delimiter string; and the third
1603 ; argument is the Info end delimiter string. The latter two arguments
1604 ; enclose the highlighted text in the Info file. A delimiter string
1605 ; may contain spaces. Neither the start nor end delimiter is
1606 ; required. However, if you do not provide a start delimiter, you
1607 ; must follow the command name with two commas in a row; otherwise,
1608 ; the Info formatting commands will misinterpret the end delimiter
1609 ; string as a start delimiter string.
1611 ; If you do a @definfoenclose{} on the name of a pre-defined macro (such
1612 ; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
1613 ; override the built-in definition.
1615 ; An enclosure command defined this way takes one argument in braces.
1617 ; For example, you can write:
1620 ; @definfoenclose phoo, //, \\
1623 ; near the beginning of a Texinfo file at the beginning of the lines
1624 ; to define `@phoo' as an Info formatting command that inserts `//'
1625 ; before and `\\' after the argument to `@phoo'. You can then write
1626 ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
1628 ; Also, for TeX formatting, you could write
1631 ; @global@let@phoo=@i
1634 ; to define `@phoo' as a command that causes TeX to typeset
1635 ; the argument to `@phoo' in italics.
1637 ; Note that each definition applies to its own formatter: one for TeX,
1638 ; the other for texinfo-format-buffer or texinfo-format-region.
1640 ; Here is another example: write
1642 ; @definfoenclose headword, , :
1644 ; near the beginning of the file, to define `@headword' as an Info
1645 ; formatting command that inserts nothing before and a colon after the
1646 ; argument to `@headword'.
1648 (put 'definfoenclose
'texinfo-format
'texinfo-define-info-enclosure
)
1649 (defun texinfo-define-info-enclosure ()
1650 (let* ((args (texinfo-format-parse-line-args))
1651 (command-name (nth 0 args
))
1652 (beginning-delimiter (or (nth 1 args
) ""))
1653 (end-delimiter (or (nth 2 args
) "")))
1654 (texinfo-discard-command)
1655 (setq texinfo-enclosure-list
1661 texinfo-enclosure-list
))))
1664 ;;; @var, @code and the like
1666 (put 'var
'texinfo-format
'texinfo-format-var
)
1667 ; @sc a small caps font for TeX; formatted as `var' in Info
1668 (put 'sc
'texinfo-format
'texinfo-format-var
)
1669 (defun texinfo-format-var ()
1670 (insert (upcase (texinfo-parse-arg-discard)))
1671 (goto-char texinfo-command-start
))
1675 (put 'b
'texinfo-format
'texinfo-format-noop
)
1676 (put 'i
'texinfo-format
'texinfo-format-noop
)
1677 (put 'r
'texinfo-format
'texinfo-format-noop
)
1678 (put 't
'texinfo-format
'texinfo-format-noop
)
1679 (put 'w
'texinfo-format
'texinfo-format-noop
)
1680 (put 'asis
'texinfo-format
'texinfo-format-noop
)
1681 (put 'dmn
'texinfo-format
'texinfo-format-noop
)
1682 (put 'key
'texinfo-format
'texinfo-format-noop
)
1683 (put 'math
'texinfo-format
'texinfo-format-noop
)
1684 (put 'titlefont
'texinfo-format
'texinfo-format-noop
)
1685 (defun texinfo-format-noop ()
1686 (insert (texinfo-parse-arg-discard))
1687 (goto-char texinfo-command-start
))
1689 (put 'cite
'texinfo-format
'texinfo-format-code
)
1690 (put 'code
'texinfo-format
'texinfo-format-code
)
1691 (put 'file
'texinfo-format
'texinfo-format-code
)
1692 (put 'kbd
'texinfo-format
'texinfo-format-code
)
1693 (put 'samp
'texinfo-format
'texinfo-format-code
)
1694 (defun texinfo-format-code ()
1695 (insert "`" (texinfo-parse-arg-discard) "'")
1696 (goto-char texinfo-command-start
))
1698 (put 'emph
'texinfo-format
'texinfo-format-emph
)
1699 (put 'strong
'texinfo-format
'texinfo-format-emph
)
1700 (defun texinfo-format-emph ()
1701 (insert "*" (texinfo-parse-arg-discard) "*")
1702 (goto-char texinfo-command-start
))
1704 (put 'dfn
'texinfo-format
'texinfo-format-defn
)
1705 (put 'defn
'texinfo-format
'texinfo-format-defn
)
1706 (defun texinfo-format-defn ()
1707 (insert "\"" (texinfo-parse-arg-discard) "\"")
1708 (goto-char texinfo-command-start
))
1710 (put 'bullet
'texinfo-format
'texinfo-format-bullet
)
1711 (defun texinfo-format-bullet ()
1712 "Insert an asterisk.
1713 If used within a line, follow `@bullet' with braces."
1714 (texinfo-optional-braces-discard)
1718 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
1720 (put 'display
'texinfo-format
'texinfo-format-example
)
1721 (put 'example
'texinfo-format
'texinfo-format-example
)
1722 (put 'lisp
'texinfo-format
'texinfo-format-example
)
1723 (put 'quotation
'texinfo-format
'texinfo-format-example
)
1724 (put 'smallexample
'texinfo-format
'texinfo-format-example
)
1725 (put 'smalllisp
'texinfo-format
'texinfo-format-example
)
1726 (defun texinfo-format-example ()
1727 (texinfo-push-stack 'example nil
)
1728 (setq fill-column
(- fill-column
5))
1729 (texinfo-discard-line))
1731 (put 'example
'texinfo-end
'texinfo-end-example
)
1732 (put 'display
'texinfo-end
'texinfo-end-example
)
1733 (put 'lisp
'texinfo-end
'texinfo-end-example
)
1734 (put 'quotation
'texinfo-end
'texinfo-end-example
)
1735 (put 'smallexample
'texinfo-end
'texinfo-end-example
)
1736 (put 'smalllisp
'texinfo-end
'texinfo-end-example
)
1737 (defun texinfo-end-example ()
1738 (setq fill-column
(+ fill-column
5))
1739 (texinfo-discard-command)
1741 (texinfo-pop-stack 'example
)))
1742 (texinfo-do-itemize (nth 1 stacktop
))))
1744 (put 'exdent
'texinfo-format
'texinfo-format-exdent
)
1745 (defun texinfo-format-exdent ()
1746 (texinfo-discard-command)
1747 (delete-region (point)
1749 (skip-chars-forward " ")
1752 ;; Cancel out the deletion that texinfo-do-itemize
1753 ;; is going to do at the end of this line.
1761 ; The @cartouche command is a noop in Info; in a printed manual,
1762 ; it makes a box with rounded corners.
1764 (put 'cartouche
'texinfo-format
'texinfo-discard-line
)
1765 (put 'cartouche
'texinfo-end
'texinfo-discard-command
)
1768 ;;; @flushleft and @format
1770 ; The @flushleft command left justifies every line but leaves the
1771 ; right end ragged. As far as Info is concerned, @flushleft is a
1772 ; `do-nothing' command
1774 ; The @format command is similar to @example except that it does not
1775 ; indent; this means that in Info, @format is similar to @flushleft.
1777 (put 'format
'texinfo-format
'texinfo-format-flushleft
)
1778 (put 'flushleft
'texinfo-format
'texinfo-format-flushleft
)
1779 (defun texinfo-format-flushleft ()
1780 (texinfo-discard-line))
1782 (put 'format
'texinfo-end
'texinfo-end-flushleft
)
1783 (put 'flushleft
'texinfo-end
'texinfo-end-flushleft
)
1784 (defun texinfo-end-flushleft ()
1785 (texinfo-discard-command))
1790 ; The @flushright command right justifies every line but leaves the
1791 ; left end ragged. Spaces and tabs at the right ends of lines are
1792 ; removed so that visible text lines up on the right side.
1794 (put 'flushright
'texinfo-format
'texinfo-format-flushright
)
1795 (defun texinfo-format-flushright ()
1796 (texinfo-push-stack 'flushright nil
)
1797 (texinfo-discard-line))
1799 (put 'flushright
'texinfo-end
'texinfo-end-flushright
)
1800 (defun texinfo-end-flushright ()
1801 (texinfo-discard-command)
1804 (texinfo-pop-stack 'flushright
)))
1806 (texinfo-do-flushright (nth 1 stacktop
))))
1808 (defun texinfo-do-flushright (from)
1810 (while (progn (forward-line -
1)
1819 (skip-chars-backward " \t")
1820 (delete-region (point) (progn (end-of-line) (point)))
1825 ;;; @ctrl, @TeX, @copyright, @minus, @dots
1827 (put 'ctrl
'texinfo-format
'texinfo-format-ctrl
)
1828 (defun texinfo-format-ctrl ()
1829 (let ((str (texinfo-parse-arg-discard)))
1830 (insert (logand 31 (aref str
0)))))
1832 (put 'TeX
'texinfo-format
'texinfo-format-TeX
)
1833 (defun texinfo-format-TeX ()
1834 (texinfo-parse-arg-discard)
1837 (put 'copyright
'texinfo-format
'texinfo-format-copyright
)
1838 (defun texinfo-format-copyright ()
1839 (texinfo-parse-arg-discard)
1842 (put 'minus
'texinfo-format
'texinfo-format-minus
)
1843 (defun texinfo-format-minus ()
1844 "Insert a minus sign.
1845 If used within a line, follow `@minus' with braces."
1846 (texinfo-optional-braces-discard)
1849 (put 'dots
'texinfo-format
'texinfo-format-dots
)
1850 (defun texinfo-format-dots ()
1851 (texinfo-parse-arg-discard)
1854 (put 'enddots
'texinfo-format
'texinfo-format-enddots
)
1855 (defun texinfo-format-enddots ()
1856 (texinfo-parse-arg-discard)
1860 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
1862 ;;; Indent only those paragraphs that are refilled as a result of an
1863 ;;; @refill command.
1865 ; * If the value is `asis', do not change the existing indentation at
1866 ; the starts of paragraphs.
1868 ; * If the value zero, delete any existing indentation.
1870 ; * If the value is greater than zero, indent each paragraph by that
1873 ;;; But do not refill paragraphs with an @refill command that are
1874 ;;; preceded by @noindent or are part of a table, list, or deffn.
1876 (defvar texinfo-paragraph-indent
"asis"
1877 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
1879 (put 'paragraphindent
'texinfo-format
'texinfo-paragraphindent
)
1881 (defun texinfo-paragraphindent ()
1882 "Specify the number of spaces for @refill to indent a paragraph.
1883 Default is to leave the number of spaces as is."
1884 (let ((arg (texinfo-parse-arg-discard)))
1885 (if (string= "asis" arg
)
1886 (setq texinfo-paragraph-indent
"asis")
1887 (setq texinfo-paragraph-indent
(string-to-int arg
)))))
1889 (put 'refill
'texinfo-format
'texinfo-format-refill
)
1890 (defun texinfo-format-refill ()
1891 "Refill paragraph. Also, indent first line as set by @paragraphindent.
1892 Default is to leave paragraph indentation as is."
1893 (texinfo-discard-command)
1894 (forward-paragraph -
1)
1895 (if (looking-at "[ \t\n]*$") (forward-line 1))
1896 ;; Do not indent if an entry in a list, table, or deffn,
1897 ;; or if paragraph is preceded by @noindent.
1898 ;; Otherwise, indent
1900 ;; delete a @noindent line and do not indent paragraph
1901 ((save-excursion (forward-line -
1)
1902 (looking-at "^@noindent"))
1904 (delete-region (point) (progn (forward-line 1) (point))))
1905 ;; do nothing if "asis"
1906 ((equal texinfo-paragraph-indent
"asis"))
1907 ;; do no indenting in list, etc.
1908 ((> texinfo-stack-depth
0))
1909 ;; otherwise delete existing whitespace and indent
1911 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
1912 (insert (make-string texinfo-paragraph-indent ?
))))
1913 (forward-paragraph 1)
1916 ;; Do not fill a section title line with asterisks, hyphens, etc. that
1917 ;; are used to underline it. This could occur if the line following
1918 ;; the underlining is not an index entry and has text within it.
1919 (let* ((previous-paragraph-separate paragraph-separate
)
1920 (paragraph-separate (concat paragraph-separate
"\\|[-=*.]+"))
1921 (previous-paragraph-start paragraph-start
)
1922 (paragraph-start (concat paragraph-start
"\\|[-=*.]+")))
1924 (fill-paragraph nil
)
1925 (setq paragraph-separate previous-paragraph-separate
)
1926 (setq paragraph-start previous-paragraph-start
))))
1928 (put 'noindent
'texinfo-format
'texinfo-noindent
)
1929 (defun texinfo-noindent ()
1931 (forward-paragraph 1)
1932 (if (search-backward "@refill"
1933 (save-excursion (forward-line -
1) (point)) t
)
1934 () ; leave @noindent command so @refill command knows not to indent
1936 (texinfo-discard-line))))
1939 ;;; Index generation
1941 (put 'vindex
'texinfo-format
'texinfo-format-vindex
)
1942 (defun texinfo-format-vindex ()
1943 (texinfo-index 'texinfo-vindex
))
1945 (put 'cindex
'texinfo-format
'texinfo-format-cindex
)
1946 (defun texinfo-format-cindex ()
1947 (texinfo-index 'texinfo-cindex
))
1949 (put 'findex
'texinfo-format
'texinfo-format-findex
)
1950 (defun texinfo-format-findex ()
1951 (texinfo-index 'texinfo-findex
))
1953 (put 'pindex
'texinfo-format
'texinfo-format-pindex
)
1954 (defun texinfo-format-pindex ()
1955 (texinfo-index 'texinfo-pindex
))
1957 (put 'tindex
'texinfo-format
'texinfo-format-tindex
)
1958 (defun texinfo-format-tindex ()
1959 (texinfo-index 'texinfo-tindex
))
1961 (put 'kindex
'texinfo-format
'texinfo-format-kindex
)
1962 (defun texinfo-format-kindex ()
1963 (texinfo-index 'texinfo-kindex
))
1965 (defun texinfo-index (indexvar)
1966 (let ((arg (texinfo-parse-expanded-arg)))
1967 (texinfo-discard-command)
1971 ;; Region formatting may not provide last node position.
1972 (if texinfo-last-node-pos
1973 (1+ (count-lines texinfo-last-node-pos
(point)))
1975 (symbol-value indexvar
)))))
1977 (defconst texinfo-indexvar-alist
1978 '(("cp" . texinfo-cindex
)
1979 ("fn" . texinfo-findex
)
1980 ("vr" . texinfo-vindex
)
1981 ("tp" . texinfo-tindex
)
1982 ("pg" . texinfo-pindex
)
1983 ("ky" . texinfo-kindex
)))
1986 ;;; @defindex @defcodeindex
1987 (put 'defindex
'texinfo-format
'texinfo-format-defindex
)
1988 (put 'defcodeindex
'texinfo-format
'texinfo-format-defindex
)
1990 (defun texinfo-format-defindex ()
1991 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
1992 (indexing-command (intern (concat index-name
"index")))
1993 (index-formatting-command ; eg: `texinfo-format-aaindex'
1994 (intern (concat "texinfo-format-" index-name
"index")))
1995 (index-alist-name ; eg: `texinfo-aaindex'
1996 (intern (concat "texinfo-" index-name
"index"))))
1998 (set index-alist-name nil
)
2000 (put indexing-command
; eg, aaindex
2002 index-formatting-command
) ; eg, texinfo-format-aaindex
2004 ;; eg: "aa" . texinfo-aaindex
2005 (or (assoc index-name texinfo-indexvar-alist
)
2006 (setq texinfo-indexvar-alist
2010 texinfo-indexvar-alist
)))
2012 (fset index-formatting-command
2014 (list 'texinfo-index
2015 (list 'quote index-alist-name
))))))
2018 ;;; @synindex @syncodeindex
2020 (put 'synindex
'texinfo-format
'texinfo-format-synindex
)
2021 (put 'syncodeindex
'texinfo-format
'texinfo-format-synindex
)
2023 (defun texinfo-format-synindex ()
2024 (let* ((args (texinfo-parse-arg-discard))
2025 (second (cdr (read-from-string args
)))
2026 (joiner (symbol-name (car (read-from-string args
))))
2027 (joined (symbol-name (car (read-from-string args second
)))))
2029 (if (assoc joiner texinfo-short-index-cmds-alist
)
2031 (cdr (assoc joiner texinfo-short-index-cmds-alist
))
2033 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist
))
2034 (intern (concat "texinfo-format-" joined
"index"))))
2036 (intern (concat joiner
"index"))
2038 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist
))
2039 (intern (concat "texinfo-format-" joined
"index")))))))
2041 (defconst texinfo-short-index-cmds-alist
2049 (defconst texinfo-short-index-format-cmds-alist
2050 '(("cp" . texinfo-format-cindex
)
2051 ("fn" . texinfo-format-findex
)
2052 ("vr" . texinfo-format-vindex
)
2053 ("tp" . texinfo-format-tindex
)
2054 ("pg" . texinfo-format-pindex
)
2055 ("ky" . texinfo-format-kindex
)))
2058 ;;; Sort and index (for VMS)
2060 ;; Sort an index which is in the current buffer between START and END.
2061 ;; Used on VMS, where the `sort' utility is not available.
2062 (defun texinfo-sort-region (start end
)
2065 (narrow-to-region start end
)
2066 (sort-subr nil
'forward-line
'end-of-line
'texinfo-sort-startkeyfun
)))
2068 ;; Subroutine for sorting an index.
2069 ;; At start of a line, return a string to sort the line under.
2070 (defun texinfo-sort-startkeyfun ()
2072 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
2073 ;; Canonicalize whitespace and eliminate funny chars.
2074 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line
)
2075 (setq line
(concat (substring line
0 (match-beginning 0))
2077 (substring line
(match-end 0) (length line
)))))
2083 (put 'printindex
'texinfo-format
'texinfo-format-printindex
)
2085 (defun texinfo-format-printindex ()
2086 (let ((indexelts (symbol-value
2087 (cdr (assoc (texinfo-parse-arg-discard)
2088 texinfo-indexvar-alist
))))
2090 (insert "\n* Menu:\n\n")
2091 (setq opoint
(point))
2092 (texinfo-print-index nil indexelts
)
2094 (if (eq system-type
'vax-vms
)
2095 (texinfo-sort-region opoint
(point))
2096 (shell-command-on-region opoint
(point) "sort -fd" 1))))
2098 (defun texinfo-print-index (file indexelts
)
2100 (if (stringp (car (car indexelts
)))
2102 (insert "* " (car (car indexelts
)) ": " )
2105 (if file
(concat "(" file
")") "")
2106 (nth 1 (car indexelts
)) ".")
2109 (if (nth 2 (car indexelts
))
2110 (format " %d." (nth 2 (car indexelts
)))
2113 ;; index entries from @include'd file
2114 (texinfo-print-index (nth 1 (car indexelts
))
2115 (nth 2 (car indexelts
))))
2116 (setq indexelts
(cdr indexelts
))))
2119 ;;; Glyphs: @equiv, @error, etc
2121 ;; @equiv to show that two expressions are equivalent
2122 ;; @error to show an error message
2123 ;; @expansion to show what a macro expands to
2124 ;; @point to show the location of point in an example
2125 ;; @print to show what an evaluated expression prints
2126 ;; @result to indicate the value returned by an expression
2128 (put 'equiv
'texinfo-format
'texinfo-format-equiv
)
2129 (defun texinfo-format-equiv ()
2130 (texinfo-parse-arg-discard)
2133 (put 'error
'texinfo-format
'texinfo-format-error
)
2134 (defun texinfo-format-error ()
2135 (texinfo-parse-arg-discard)
2136 (insert "error-->"))
2138 (put 'expansion
'texinfo-format
'texinfo-format-expansion
)
2139 (defun texinfo-format-expansion ()
2140 (texinfo-parse-arg-discard)
2143 (put 'point
'texinfo-format
'texinfo-format-point
)
2144 (defun texinfo-format-point ()
2145 (texinfo-parse-arg-discard)
2148 (put 'print
'texinfo-format
'texinfo-format-print
)
2149 (defun texinfo-format-print ()
2150 (texinfo-parse-arg-discard)
2153 (put 'result
'texinfo-format
'texinfo-format-result
)
2154 (defun texinfo-format-result ()
2155 (texinfo-parse-arg-discard)
2159 ;;; Definition formatting: @deffn, @defun, etc
2161 ;; What definition formatting produces:
2163 ;; @deffn category name args...
2164 ;; In Info, `Category: name ARGS'
2165 ;; In index: name: node. line#.
2167 ;; @defvr category name
2168 ;; In Info, `Category: name'
2169 ;; In index: name: node. line#.
2171 ;; @deftp category name attributes...
2172 ;; `category name attributes...' Note: @deftp args in lower case.
2173 ;; In index: name: node. line#.
2175 ;; Specialized function-like or variable-like entity:
2177 ;; @defun, @defmac, @defspec, @defvar, @defopt
2179 ;; @defun name args In Info, `Function: name ARGS'
2180 ;; @defmac name args In Info, `Macro: name ARGS'
2181 ;; @defvar name In Info, `Variable: name'
2183 ;; In index: name: node. line#.
2185 ;; Generalized typed-function-like or typed-variable-like entity:
2186 ;; @deftypefn category data-type name args...
2187 ;; In Info, `Category: data-type name args...'
2188 ;; @deftypevr category data-type name
2189 ;; In Info, `Category: data-type name'
2190 ;; In index: name: node. line#.
2192 ;; Specialized typed-function-like or typed-variable-like entity:
2193 ;; @deftypefun data-type name args...
2194 ;; In Info, `Function: data-type name ARGS'
2195 ;; In index: name: node. line#.
2197 ;; @deftypevar data-type name
2198 ;; In Info, `Variable: data-type name'
2199 ;; In index: name: node. line#. but include args after name!?
2201 ;; Generalized object oriented entity:
2202 ;; @defop category class name args...
2203 ;; In Info, `Category on class: name ARG'
2204 ;; In index: name on class: node. line#.
2206 ;; @defcv category class name
2207 ;; In Info, `Category of class: name'
2208 ;; In index: name of class: node. line#.
2210 ;; Specialized object oriented entity:
2211 ;; @defmethod class name args...
2212 ;; In Info, `Method on class: name ARGS'
2213 ;; In index: name on class: node. line#.
2215 ;; @defivar class name
2216 ;; In Info, `Instance variable of class: name'
2217 ;; In index: name of class: node. line#.
2220 ;;; The definition formatting functions
2222 (defun texinfo-format-defun ()
2223 (texinfo-push-stack 'defun
nil)
2224 (setq fill-column
(- fill-column
5))
2225 (texinfo-format-defun-1 t
))
2227 (defun texinfo-end-defun ()
2228 (setq fill-column
(+ fill-column
5))
2229 (texinfo-discard-command)
2230 (let ((start (nth 1 (texinfo-pop-stack 'defun
))))
2231 (texinfo-do-itemize start
)
2232 ;; Delete extra newline inserted after header.
2237 (defun texinfo-format-defunx ()
2238 (texinfo-format-defun-1 nil
))
2240 (defun texinfo-format-defun-1 (first-p)
2241 (let ((parse-args (texinfo-format-parse-defun-args))
2242 (texinfo-defun-type (get texinfo-command-name
'texinfo-defun-type
)))
2243 (texinfo-discard-command)
2244 ;; Delete extra newline inserted after previous header line.
2248 (get texinfo-command-name
'texinfo-deffn-formatting-property
) parse-args
)
2249 ;; Insert extra newline so that paragraph filling does not mess
2250 ;; with header line.
2252 (rplaca (cdr (cdr (car texinfo-stack
))) (point))
2254 (get texinfo-command-name
'texinfo-defun-indexing-property
) parse-args
)))
2256 ;;; Formatting the first line of a definition
2258 ;; @deffn, @defvr, @deftp
2259 (put 'deffn
'texinfo-deffn-formatting-property
'texinfo-format-deffn
)
2260 (put 'deffnx
'texinfo-deffn-formatting-property
'texinfo-format-deffn
)
2261 (put 'defvr
'texinfo-deffn-formatting-property
'texinfo-format-deffn
)
2262 (put 'defvrx
'texinfo-deffn-formatting-property
'texinfo-format-deffn
)
2263 (put 'deftp
'texinfo-deffn-formatting-property
'texinfo-format-deffn
)
2264 (put 'deftpx
'texinfo-deffn-formatting-property
'texinfo-format-deffn
)
2265 (defun texinfo-format-deffn (parsed-args)
2266 ;; Generalized function-like, variable-like, or generic data-type entity:
2267 ;; @deffn category name args...
2268 ;; In Info, `Category: name ARGS'
2269 ;; @deftp category name attributes...
2270 ;; `category name attributes...' Note: @deftp args in lower case.
2271 (let ((category (car parsed-args
))
2272 (name (car (cdr parsed-args
)))
2273 (args (cdr (cdr parsed-args
))))
2274 (insert " -- " category
": " name
)
2277 (if (or (= ?
& (aref (car args
) 0))
2278 (eq (eval (car texinfo-defun-type
)) 'deftp-type
))
2280 (upcase (car args
))))
2281 (setq args
(cdr args
)))))
2283 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
2284 (put 'defun
'texinfo-deffn-formatting-property
2285 'texinfo-format-specialized-defun
)
2286 (put 'defunx
'texinfo-deffn-formatting-property
2287 'texinfo-format-specialized-defun
)
2288 (put 'defmac
'texinfo-deffn-formatting-property
2289 'texinfo-format-specialized-defun
)
2290 (put 'defmacx
'texinfo-deffn-formatting-property
2291 'texinfo-format-specialized-defun
)
2292 (put 'defspec
'texinfo-deffn-formatting-property
2293 'texinfo-format-specialized-defun
)
2294 (put 'defspecx
'texinfo-deffn-formatting-property
2295 'texinfo-format-specialized-defun
)
2296 (put 'defvar
'texinfo-deffn-formatting-property
2297 'texinfo-format-specialized-defun
)
2298 (put 'defvarx
'texinfo-deffn-formatting-property
2299 'texinfo-format-specialized-defun
)
2300 (put 'defopt
'texinfo-deffn-formatting-property
2301 'texinfo-format-specialized-defun
)
2302 (put 'defoptx
'texinfo-deffn-formatting-property
2303 'texinfo-format-specialized-defun
)
2304 (defun texinfo-format-specialized-defun (parsed-args)
2305 ;; Specialized function-like or variable-like entity:
2306 ;; @defun name args In Info, `Function: Name ARGS'
2307 ;; @defmac name args In Info, `Macro: Name ARGS'
2308 ;; @defvar name In Info, `Variable: Name'
2309 ;; Use cdr of texinfo-defun-type to determine category:
2310 (let ((category (car (cdr texinfo-defun-type
)))
2311 (name (car parsed-args
))
2312 (args (cdr parsed-args
)))
2313 (insert " -- " category
": " name
)
2316 (if (= ?
& (aref (car args
) 0))
2318 (upcase (car args
))))
2319 (setq args
(cdr args
)))))
2321 ;; @deftypefn, @deftypevr: Generalized typed
2322 (put 'deftypefn
'texinfo-deffn-formatting-property
'texinfo-format-deftypefn
)
2323 (put 'deftypefnx
'texinfo-deffn-formatting-property
'texinfo-format-deftypefn
)
2324 (put 'deftypevr
'texinfo-deffn-formatting-property
'texinfo-format-deftypefn
)
2325 (put 'deftypevrx
'texinfo-deffn-formatting-property
'texinfo-format-deftypefn
)
2326 (defun texinfo-format-deftypefn (parsed-args)
2327 ;; Generalized typed-function-like or typed-variable-like entity:
2328 ;; @deftypefn category data-type name args...
2329 ;; In Info, `Category: data-type name args...'
2330 ;; @deftypevr category data-type name
2331 ;; In Info, `Category: data-type name'
2332 ;; Note: args in lower case, unless modified in command line.
2333 (let ((category (car parsed-args
))
2334 (data-type (car (cdr parsed-args
)))
2335 (name (car (cdr (cdr parsed-args
))))
2336 (args (cdr (cdr (cdr parsed-args
)))))
2337 (insert " -- " category
": " data-type
" " name
)
2339 (insert " " (car args
))
2340 (setq args
(cdr args
)))))
2342 ;; @deftypefun, @deftypevar: Specialized typed
2343 (put 'deftypefun
'texinfo-deffn-formatting-property
'texinfo-format-deftypefun
)
2344 (put 'deftypefunx
'texinfo-deffn-formatting-property
2345 'texinfo-format-deftypefun
)
2346 (put 'deftypevar
'texinfo-deffn-formatting-property
'texinfo-format-deftypefun
)
2347 (put 'deftypevarx
'texinfo-deffn-formatting-property
2348 'texinfo-format-deftypefun
)
2349 (defun texinfo-format-deftypefun (parsed-args)
2350 ;; Specialized typed-function-like or typed-variable-like entity:
2351 ;; @deftypefun data-type name args...
2352 ;; In Info, `Function: data-type name ARGS'
2353 ;; @deftypevar data-type name
2354 ;; In Info, `Variable: data-type name'
2355 ;; Note: args in lower case, unless modified in command line.
2356 ;; Use cdr of texinfo-defun-type to determine category:
2357 (let ((category (car (cdr texinfo-defun-type
)))
2358 (data-type (car parsed-args
))
2359 (name (car (cdr parsed-args
)))
2360 (args (cdr (cdr parsed-args
))))
2361 (insert " -- " category
": " data-type
" " name
)
2363 (insert " " (car args
))
2364 (setq args
(cdr args
)))))
2366 ;; @defop: Generalized object-oriented
2367 (put 'defop
'texinfo-deffn-formatting-property
'texinfo-format-defop
)
2368 (put 'defopx
'texinfo-deffn-formatting-property
'texinfo-format-defop
)
2369 (defun texinfo-format-defop (parsed-args)
2370 ;; Generalized object oriented entity:
2371 ;; @defop category class name args...
2372 ;; In Info, `Category on class: name ARG'
2373 ;; Note: args in upper case; use of `on'
2374 (let ((category (car parsed-args
))
2375 (class (car (cdr parsed-args
)))
2376 (name (car (cdr (cdr parsed-args
))))
2377 (args (cdr (cdr (cdr parsed-args
)))))
2378 (insert " -- " category
" on " class
": " name
)
2380 (insert " " (upcase (car args
)))
2381 (setq args
(cdr args
)))))
2383 ;; @defcv: Generalized object-oriented
2384 (put 'defcv
'texinfo-deffn-formatting-property
'texinfo-format-defcv
)
2385 (put 'defcvx
'texinfo-deffn-formatting-property
'texinfo-format-defcv
)
2386 (defun texinfo-format-defcv (parsed-args)
2387 ;; Generalized object oriented entity:
2388 ;; @defcv category class name
2389 ;; In Info, `Category of class: name'
2390 ;; Note: args in upper case; use of `of'
2391 (let ((category (car parsed-args
))
2392 (class (car (cdr parsed-args
)))
2393 (name (car (cdr (cdr parsed-args
))))
2394 (args (cdr (cdr (cdr parsed-args
)))))
2395 (insert " -- " category
" of " class
": " name
)
2397 (insert " " (upcase (car args
)))
2398 (setq args
(cdr args
)))))
2400 ;; @defmethod: Specialized object-oriented
2401 (put 'defmethod
'texinfo-deffn-formatting-property
'texinfo-format-defmethod
)
2402 (put 'defmethodx
'texinfo-deffn-formatting-property
'texinfo-format-defmethod
)
2403 (defun texinfo-format-defmethod (parsed-args)
2404 ;; Specialized object oriented entity:
2405 ;; @defmethod class name args...
2406 ;; In Info, `Method on class: name ARGS'
2407 ;; Note: args in upper case; use of `on'
2408 ;; Use cdr of texinfo-defun-type to determine category:
2409 (let ((category (car (cdr texinfo-defun-type
)))
2410 (class (car parsed-args
))
2411 (name (car (cdr parsed-args
)))
2412 (args (cdr (cdr parsed-args
))))
2413 (insert " -- " category
" on " class
": " name
)
2415 (insert " " (upcase (car args
)))
2416 (setq args
(cdr args
)))))
2418 ;; @defivar: Specialized object-oriented
2419 (put 'defivar
'texinfo-deffn-formatting-property
'texinfo-format-defivar
)
2420 (put 'defivarx
'texinfo-deffn-formatting-property
'texinfo-format-defivar
)
2421 (defun texinfo-format-defivar (parsed-args)
2422 ;; Specialized object oriented entity:
2423 ;; @defivar class name
2424 ;; In Info, `Instance variable of class: name'
2425 ;; Note: args in upper case; use of `of'
2426 ;; Use cdr of texinfo-defun-type to determine category:
2427 (let ((category (car (cdr texinfo-defun-type
)))
2428 (class (car parsed-args
))
2429 (name (car (cdr parsed-args
)))
2430 (args (cdr (cdr parsed-args
))))
2431 (insert " -- " category
" of " class
": " name
)
2433 (insert " " (upcase (car args
)))
2434 (setq args
(cdr args
)))))
2437 ;;; Indexing for definitions
2439 ;; An index entry has three parts: the `entry proper', the node name, and the
2440 ;; line number. Depending on the which command is used, the entry is
2441 ;; formatted differently:
2447 ;; @defopt all use their 1st argument as the entry-proper
2453 ;; @deftypevar all use their 2nd argument as the entry-proper
2456 ;; @deftypevr both use their 3rd argument as the entry-proper
2458 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
2459 ;; formatted: NAME on CLASS
2461 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
2462 ;; formatted: NAME on CLASS
2464 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
2465 ;; formatted: NAME of CLASS
2467 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
2468 ;; formatted: NAME of CLASS
2470 (put 'defun
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2471 (put 'defunx
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2472 (put 'defmac
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2473 (put 'defmacx
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2474 (put 'defspec
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2475 (put 'defspecx
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2476 (put 'defvar
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2477 (put 'defvarx
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2478 (put 'defopt
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2479 (put 'defoptx
'texinfo-defun-indexing-property
'texinfo-index-defun
)
2480 (defun texinfo-index-defun (parsed-args)
2481 ;; use 1st parsed-arg as entry-proper
2482 ;; `index-list' will be texinfo-findex or the like
2483 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2486 ;; Three elements: entry-proper, node-name, line-number
2490 ;; Region formatting may not provide last node position.
2491 (if texinfo-last-node-pos
2492 (1+ (count-lines texinfo-last-node-pos
(point)))
2494 (symbol-value index-list
)))))
2496 (put 'deffn
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2497 (put 'deffnx
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2498 (put 'defvr
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2499 (put 'defvrx
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2500 (put 'deftp
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2501 (put 'deftpx
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2502 (put 'deftypefun
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2503 (put 'deftypefunx
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2504 (put 'deftypevar
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2505 (put 'deftypevarx
'texinfo-defun-indexing-property
'texinfo-index-deffn
)
2506 (defun texinfo-index-deffn (parsed-args)
2507 ;; use 2nd parsed-arg as entry-proper
2508 ;; `index-list' will be texinfo-findex or the like
2509 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2512 ;; Three elements: entry-proper, node-name, line-number
2514 (car (cdr parsed-args
))
2516 ;; Region formatting may not provide last node position.
2517 (if texinfo-last-node-pos
2518 (1+ (count-lines texinfo-last-node-pos
(point)))
2520 (symbol-value index-list
)))))
2522 (put 'deftypefn
'texinfo-defun-indexing-property
'texinfo-index-deftypefn
)
2523 (put 'deftypefnx
'texinfo-defun-indexing-property
'texinfo-index-deftypefn
)
2524 (put 'deftypevr
'texinfo-defun-indexing-property
'texinfo-index-deftypefn
)
2525 (put 'deftypevrx
'texinfo-defun-indexing-property
'texinfo-index-deftypefn
)
2526 (defun texinfo-index-deftypefn (parsed-args)
2527 ;; use 3rd parsed-arg as entry-proper
2528 ;; `index-list' will be texinfo-findex or the like
2529 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2532 ;; Three elements: entry-proper, node-name, line-number
2534 (car (cdr (cdr parsed-args
)))
2536 ;; Region formatting may not provide last node position.
2537 (if texinfo-last-node-pos
2538 (1+ (count-lines texinfo-last-node-pos
(point)))
2540 (symbol-value index-list
)))))
2542 (put 'defmethod
'texinfo-defun-indexing-property
'texinfo-index-defmethod
)
2543 (put 'defmethodx
'texinfo-defun-indexing-property
'texinfo-index-defmethod
)
2544 (defun texinfo-index-defmethod (parsed-args)
2545 ;; use 2nd on 1st parsed-arg as entry-proper
2546 ;; `index-list' will be texinfo-findex or the like
2547 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2550 ;; Three elements: entry-proper, node-name, line-number
2553 (car (cdr parsed-args
))
2556 ;; Region formatting may not provide last node position.
2557 (if texinfo-last-node-pos
2558 (1+ (count-lines texinfo-last-node-pos
(point)))
2560 (symbol-value index-list
)))))
2562 (put 'defop
'texinfo-defun-indexing-property
'texinfo-index-defop
)
2563 (put 'defopx
'texinfo-defun-indexing-property
'texinfo-index-defop
)
2564 (defun texinfo-index-defop (parsed-args)
2565 ;; use 3rd on 2nd parsed-arg as entry-proper
2566 ;; `index-list' will be texinfo-findex or the like
2567 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2570 ;; Three elements: entry-proper, node-name, line-number
2573 (car (cdr (cdr parsed-args
)))
2574 (car (cdr parsed-args
)))
2576 ;; Region formatting may not provide last node position.
2577 (if texinfo-last-node-pos
2578 (1+ (count-lines texinfo-last-node-pos
(point)))
2580 (symbol-value index-list
)))))
2582 (put 'defivar
'texinfo-defun-indexing-property
'texinfo-index-defivar
)
2583 (put 'defivarx
'texinfo-defun-indexing-property
'texinfo-index-defivar
)
2584 (defun texinfo-index-defivar (parsed-args)
2585 ;; use 2nd of 1st parsed-arg as entry-proper
2586 ;; `index-list' will be texinfo-findex or the like
2587 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2590 ;; Three elements: entry-proper, node-name, line-number
2593 (car (cdr parsed-args
))
2596 ;; Region formatting may not provide last node position.
2597 (if texinfo-last-node-pos
2598 (1+ (count-lines texinfo-last-node-pos
(point)))
2600 (symbol-value index-list
)))))
2602 (put 'defcv
'texinfo-defun-indexing-property
'texinfo-index-defcv
)
2603 (put 'defcvx
'texinfo-defun-indexing-property
'texinfo-index-defcv
)
2604 (defun texinfo-index-defcv (parsed-args)
2605 ;; use 3rd of 2nd parsed-arg as entry-proper
2606 ;; `index-list' will be texinfo-findex or the like
2607 (let ((index-list (get texinfo-command-name
'texinfo-defun-index
)))
2610 ;; Three elements: entry-proper, node-name, line-number
2613 (car (cdr (cdr parsed-args
)))
2614 (car (cdr parsed-args
)))
2616 ;; Region formatting may not provide last node position.
2617 (if texinfo-last-node-pos
2618 (1+ (count-lines texinfo-last-node-pos
(point)))
2620 (symbol-value index-list
)))))
2623 ;;; Properties for definitions
2625 ;; Each definition command has six properties:
2627 ;; 1. texinfo-deffn-formatting-property to format definition line
2628 ;; 2. texinfo-defun-indexing-property to create index entry
2629 ;; 3. texinfo-format formatting command
2630 ;; 4. texinfo-end end formatting command
2631 ;; 5. texinfo-defun-type type of deffn to format
2632 ;; 6. texinfo-defun-index type of index to use
2634 ;; The `x' forms of each definition command are used for the second
2635 ;; and subsequent header lines.
2637 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
2638 ;; are listed just before the appropriate formatting and indexing commands.
2640 (put 'deffn
'texinfo-format
'texinfo-format-defun
)
2641 (put 'deffnx
'texinfo-format
'texinfo-format-defunx
)
2642 (put 'deffn
'texinfo-end
'texinfo-end-defun
)
2643 (put 'deffn
'texinfo-defun-type
'('deffn-type nil
))
2644 (put 'deffnx
'texinfo-defun-type
'('deffn-type nil
))
2645 (put 'deffn
'texinfo-defun-index
'texinfo-findex
)
2646 (put 'deffnx
'texinfo-defun-index
'texinfo-findex
)
2648 (put 'defun
'texinfo-format
'texinfo-format-defun
)
2649 (put 'defunx
'texinfo-format
'texinfo-format-defunx
)
2650 (put 'defun
'texinfo-end
'texinfo-end-defun
)
2651 (put 'defun
'texinfo-defun-type
'('defun-type
"Function"))
2652 (put 'defunx
'texinfo-defun-type
'('defun-type
"Function"))
2653 (put 'defun
'texinfo-defun-index
'texinfo-findex
)
2654 (put 'defunx
'texinfo-defun-index
'texinfo-findex
)
2656 (put 'defmac
'texinfo-format
'texinfo-format-defun
)
2657 (put 'defmacx
'texinfo-format
'texinfo-format-defunx
)
2658 (put 'defmac
'texinfo-end
'texinfo-end-defun
)
2659 (put 'defmac
'texinfo-defun-type
'('defun-type
"Macro"))
2660 (put 'defmacx
'texinfo-defun-type
'('defun-type
"Macro"))
2661 (put 'defmac
'texinfo-defun-index
'texinfo-findex
)
2662 (put 'defmacx
'texinfo-defun-index
'texinfo-findex
)
2664 (put 'defspec
'texinfo-format
'texinfo-format-defun
)
2665 (put 'defspecx
'texinfo-format
'texinfo-format-defunx
)
2666 (put 'defspec
'texinfo-end
'texinfo-end-defun
)
2667 (put 'defspec
'texinfo-defun-type
'('defun-type
"Special form"))
2668 (put 'defspecx
'texinfo-defun-type
'('defun-type
"Special form"))
2669 (put 'defspec
'texinfo-defun-index
'texinfo-findex
)
2670 (put 'defspecx
'texinfo-defun-index
'texinfo-findex
)
2672 (put 'defvr
'texinfo-format
'texinfo-format-defun
)
2673 (put 'defvrx
'texinfo-format
'texinfo-format-defunx
)
2674 (put 'defvr
'texinfo-end
'texinfo-end-defun
)
2675 (put 'defvr
'texinfo-defun-type
'('deffn-type nil
))
2676 (put 'defvrx
'texinfo-defun-type
'('deffn-type nil
))
2677 (put 'defvr
'texinfo-defun-index
'texinfo-vindex
)
2678 (put 'defvrx
'texinfo-defun-index
'texinfo-vindex
)
2680 (put 'defvar
'texinfo-format
'texinfo-format-defun
)
2681 (put 'defvarx
'texinfo-format
'texinfo-format-defunx
)
2682 (put 'defvar
'texinfo-end
'texinfo-end-defun
)
2683 (put 'defvar
'texinfo-defun-type
'('defun-type
"Variable"))
2684 (put 'defvarx
'texinfo-defun-type
'('defun-type
"Variable"))
2685 (put 'defvar
'texinfo-defun-index
'texinfo-vindex
)
2686 (put 'defvarx
'texinfo-defun-index
'texinfo-vindex
)
2688 (put 'defconst
'texinfo-format
'texinfo-format-defun
)
2689 (put 'defconstx
'texinfo-format
'texinfo-format-defunx
)
2690 (put 'defconst
'texinfo-end
'texinfo-end-defun
)
2691 (put 'defconst
'texinfo-defun-type
'('defun-type
"Constant"))
2692 (put 'defconstx
'texinfo-defun-type
'('defun-type
"Constant"))
2693 (put 'defconst
'texinfo-defun-index
'texinfo-vindex
)
2694 (put 'defconstx
'texinfo-defun-index
'texinfo-vindex
)
2696 (put 'defcmd
'texinfo-format
'texinfo-format-defun
)
2697 (put 'defcmdx
'texinfo-format
'texinfo-format-defunx
)
2698 (put 'defcmd
'texinfo-end
'texinfo-end-defun
)
2699 (put 'defcmd
'texinfo-defun-type
'('defun-type
"Command"))
2700 (put 'defcmdx
'texinfo-defun-type
'('defun-type
"Command"))
2701 (put 'defcmd
'texinfo-defun-index
'texinfo-findex
)
2702 (put 'defcmdx
'texinfo-defun-index
'texinfo-findex
)
2704 (put 'defopt
'texinfo-format
'texinfo-format-defun
)
2705 (put 'defoptx
'texinfo-format
'texinfo-format-defunx
)
2706 (put 'defopt
'texinfo-end
'texinfo-end-defun
)
2707 (put 'defopt
'texinfo-defun-type
'('defun-type
"User Option"))
2708 (put 'defoptx
'texinfo-defun-type
'('defun-type
"User Option"))
2709 (put 'defopt
'texinfo-defun-index
'texinfo-vindex
)
2710 (put 'defoptx
'texinfo-defun-index
'texinfo-vindex
)
2712 (put 'deftp
'texinfo-format
'texinfo-format-defun
)
2713 (put 'deftpx
'texinfo-format
'texinfo-format-defunx
)
2714 (put 'deftp
'texinfo-end
'texinfo-end-defun
)
2715 (put 'deftp
'texinfo-defun-type
'('deftp-type nil
))
2716 (put 'deftpx
'texinfo-defun-type
'('deftp-type nil
))
2717 (put 'deftp
'texinfo-defun-index
'texinfo-tindex
)
2718 (put 'deftpx
'texinfo-defun-index
'texinfo-tindex
)
2720 ;;; Object-oriented stuff is a little hairier.
2722 (put 'defop
'texinfo-format
'texinfo-format-defun
)
2723 (put 'defopx
'texinfo-format
'texinfo-format-defunx
)
2724 (put 'defop
'texinfo-end
'texinfo-end-defun
)
2725 (put 'defop
'texinfo-defun-type
'('defop-type nil
))
2726 (put 'defopx
'texinfo-defun-type
'('defop-type nil
))
2727 (put 'defop
'texinfo-defun-index
'texinfo-findex
)
2728 (put 'defopx
'texinfo-defun-index
'texinfo-findex
)
2730 (put 'defmethod
'texinfo-format
'texinfo-format-defun
)
2731 (put 'defmethodx
'texinfo-format
'texinfo-format-defunx
)
2732 (put 'defmethod
'texinfo-end
'texinfo-end-defun
)
2733 (put 'defmethod
'texinfo-defun-type
'('defmethod-type
"Method"))
2734 (put 'defmethodx
'texinfo-defun-type
'('defmethod-type
"Method"))
2735 (put 'defmethod
'texinfo-defun-index
'texinfo-findex
)
2736 (put 'defmethodx
'texinfo-defun-index
'texinfo-findex
)
2738 (put 'defcv
'texinfo-format
'texinfo-format-defun
)
2739 (put 'defcvx
'texinfo-format
'texinfo-format-defunx
)
2740 (put 'defcv
'texinfo-end
'texinfo-end-defun
)
2741 (put 'defcv
'texinfo-defun-type
'('defop-type nil
))
2742 (put 'defcvx
'texinfo-defun-type
'('defop-type nil
))
2743 (put 'defcv
'texinfo-defun-index
'texinfo-vindex
)
2744 (put 'defcvx
'texinfo-defun-index
'texinfo-vindex
)
2746 (put 'defivar
'texinfo-format
'texinfo-format-defun
)
2747 (put 'defivarx
'texinfo-format
'texinfo-format-defunx
)
2748 (put 'defivar
'texinfo-end
'texinfo-end-defun
)
2749 (put 'defivar
'texinfo-defun-type
'('defmethod-type
"Instance variable"))
2750 (put 'defivarx
'texinfo-defun-type
'('defmethod-type
"Instance variable"))
2751 (put 'defivar
'texinfo-defun-index
'texinfo-vindex
)
2752 (put 'defivarx
'texinfo-defun-index
'texinfo-vindex
)
2754 ;;; Typed functions and variables
2756 (put 'deftypefn
'texinfo-format
'texinfo-format-defun
)
2757 (put 'deftypefnx
'texinfo-format
'texinfo-format-defunx
)
2758 (put 'deftypefn
'texinfo-end
'texinfo-end-defun
)
2759 (put 'deftypefn
'texinfo-defun-type
'('deftypefn-type nil
))
2760 (put 'deftypefnx
'texinfo-defun-type
'('deftypefn-type nil
))
2761 (put 'deftypefn
'texinfo-defun-index
'texinfo-findex
)
2762 (put 'deftypefnx
'texinfo-defun-index
'texinfo-findex
)
2764 (put 'deftypefun
'texinfo-format
'texinfo-format-defun
)
2765 (put 'deftypefunx
'texinfo-format
'texinfo-format-defunx
)
2766 (put 'deftypefun
'texinfo-end
'texinfo-end-defun
)
2767 (put 'deftypefun
'texinfo-defun-type
'('deftypefun-type
"Function"))
2768 (put 'deftypefunx
'texinfo-defun-type
'('deftypefun-type
"Function"))
2769 (put 'deftypefun
'texinfo-defun-index
'texinfo-findex
)
2770 (put 'deftypefunx
'texinfo-defun-index
'texinfo-findex
)
2772 (put 'deftypevr
'texinfo-format
'texinfo-format-defun
)
2773 (put 'deftypevrx
'texinfo-format
'texinfo-format-defunx
)
2774 (put 'deftypevr
'texinfo-end
'texinfo-end-defun
)
2775 (put 'deftypevr
'texinfo-defun-type
'('deftypefn-type nil
))
2776 (put 'deftypevrx
'texinfo-defun-type
'('deftypefn-type nil
))
2777 (put 'deftypevr
'texinfo-defun-index
'texinfo-vindex
)
2778 (put 'deftypevrx
'texinfo-defun-index
'texinfo-vindex
)
2780 (put 'deftypevar
'texinfo-format
'texinfo-format-defun
)
2781 (put 'deftypevarx
'texinfo-format
'texinfo-format-defunx
)
2782 (put 'deftypevar
'texinfo-end
'texinfo-end-defun
)
2783 (put 'deftypevar
'texinfo-defun-type
'('deftypevar-type
"Variable"))
2784 (put 'deftypevarx
'texinfo-defun-type
'('deftypevar-type
"Variable"))
2785 (put 'deftypevar
'texinfo-defun-index
'texinfo-vindex
)
2786 (put 'deftypevarx
'texinfo-defun-index
'texinfo-vindex
)
2789 ;;; @set, @clear, @ifset, @ifclear
2791 ;; If a flag is set with @set FLAG, then text between @ifset and @end
2792 ;; ifset is formatted normally, but if the flag is is cleared with
2793 ;; @clear FLAG, then the text is not formatted; it is ignored.
2795 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
2796 ;; and @end ifclear is formatted normally, but if the flag is is set with
2797 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
2798 ;; is the opposite of @ifset.
2800 ;; If a flag is set to a string with @set FLAG,
2801 ;; replace @value{FLAG} with the string.
2802 ;; If a flag with a value is cleared,
2803 ;; @value{FLAG} is invalid,
2804 ;; as if there had never been any @set FLAG previously.
2806 (put 'clear
'texinfo-format
'texinfo-clear
)
2807 (defun texinfo-clear ()
2808 "Clear the value of the flag."
2809 (let* ((arg (texinfo-parse-arg-discard))
2810 (flag (car (read-from-string arg
)))
2811 (value (substring arg
(cdr (read-from-string arg
)))))
2812 (put flag
'texinfo-whether-setp
'flag-cleared
)
2813 (put flag
'texinfo-set-value
"")))
2815 (put 'set
'texinfo-format
'texinfo-set
)
2816 (defun texinfo-set ()
2817 "Set the value of the flag, optionally to a string.
2818 The command `@set foo This is a string.'
2819 sets flag foo to the value: `This is a string.'
2820 The command `@value{foo}' expands to the value."
2821 (let* ((arg (texinfo-parse-arg-discard))
2822 (flag (car (read-from-string arg
)))
2823 (value (substring arg
(cdr (read-from-string arg
)))))
2824 (put flag
'texinfo-whether-setp
'flag-set
)
2825 (put flag
'texinfo-set-value value
)))
2827 (put 'value
'texinfo-format
'texinfo-value
)
2828 (defun texinfo-value ()
2829 "Insert the string to which the flag is set.
2830 The command `@set foo This is a string.'
2831 sets flag foo to the value: `This is a string.'
2832 The command `@value{foo}' expands to the value."
2833 (let ((arg (texinfo-parse-arg-discard)))
2835 (eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2837 (get (car (read-from-string arg
)) 'texinfo-set-value
))
2838 (insert (get (car (read-from-string arg
)) 'texinfo-set-value
)))
2839 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2841 (insert (format "{No value for \"%s\"}" arg
)))
2842 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
) nil
)
2843 (insert (format "{No value for \"%s\"}" arg
))))))
2845 (put 'ifset
'texinfo-end
'texinfo-discard-command
)
2846 (put 'ifset
'texinfo-format
'texinfo-if-set
)
2847 (defun texinfo-if-set ()
2848 "If set, continue formatting; else do not format region up to @end ifset"
2849 (let ((arg (texinfo-parse-arg-discard)))
2851 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2853 ;; Format the text (i.e., do not remove it); do nothing here.
2855 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2857 ;; Clear region (i.e., cause the text to be ignored).
2858 (delete-region texinfo-command-start
2859 (progn (re-search-forward "@end ifset[ \t]*\n")
2861 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2863 ;; In this case flag is neither set nor cleared.
2864 ;; Act as if set, i.e. do nothing.
2867 (put 'ifclear
'texinfo-end
'texinfo-discard-command
)
2868 (put 'ifclear
'texinfo-format
'texinfo-if-clear
)
2869 (defun texinfo-if-clear ()
2870 "If clear, continue formatting; if set, do not format up to @end ifset"
2871 (let ((arg (texinfo-parse-arg-discard)))
2873 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2875 ;; Clear region (i.e., cause the text to be ignored).
2876 (delete-region texinfo-command-start
2877 (progn (re-search-forward "@end ifclear[ \t]*\n")
2879 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2881 ;; Format the text (i.e., do not remove it); do nothing here.
2883 ((eq (get (car (read-from-string arg
)) 'texinfo-whether-setp
)
2885 ;; In this case flag is neither set nor cleared.
2886 ;; Act as if clear, i.e. do nothing.
2890 ;;; Process included files: `@include' command
2892 ;; Updated 19 October 1990
2893 ;; In the original version, include files were ignored by Info but
2894 ;; incorporated in to the printed manual. To make references to the
2895 ;; included file, the Texinfo source file has to refer to the included
2896 ;; files using the `(filename)nodename' format for refering to other
2897 ;; Info files. Also, the included files had to be formatted on their
2898 ;; own. It was just like they were another file.
2900 ;; Currently, include files are inserted into the buffer that is
2901 ;; formatted for Info. If large, the resulting info file is split and
2902 ;; tagified. For current include files to work, the master menu must
2903 ;; refer to all the nodes, and the highest level nodes in the include
2904 ;; files must have the correct next, prev, and up pointers.
2906 ;; The included file may have an @setfilename and even an @settitle,
2907 ;; but not an `\input texinfo' line.
2909 ;; Updated 24 March 1993
2910 ;; In order for @raisesections and @lowersections to work, included
2911 ;; files must be inserted into the buffer holding the outer file
2912 ;; before other Info formatting takes place. So @include is no longer
2913 ;; is treated like other @-commands.
2914 (put 'include
'texinfo-format
'texinfo-format-noop
)
2916 ; Original definition:
2917 ; (defun texinfo-format-include ()
2918 ; (let ((filename (texinfo-parse-arg-discard))
2919 ; (default-directory input-directory)
2924 ; (cond ((file-readable-p (concat filename ".texinfo"))
2925 ; (concat filename ".texinfo"))
2926 ; ((file-readable-p (concat filename ".texi"))
2927 ; (concat filename ".texi"))
2928 ; ((file-readable-p (concat filename ".tex"))
2929 ; (concat filename ".tex"))
2930 ; ((file-readable-p filename)
2932 ; (t (error "@include'd file %s not found"
2934 ; (texinfo-format-buffer-1))))
2935 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
2936 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
2937 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
2938 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
2939 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
2940 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
2942 ;(defun texinfo-subindex (indexvar file content)
2943 ; (set indexvar (cons (list 'recurse file content)
2944 ; (symbol-value indexvar))))
2946 ; Second definition:
2947 ; (put 'include 'texinfo-format 'texinfo-format-include)
2948 ; (defun texinfo-format-include ()
2949 ; (let ((filename (concat input-directory
2950 ; (texinfo-parse-arg-discard)))
2951 ; (default-directory input-directory))
2952 ; (message "Reading: %s" filename)
2957 ; (+ (point) (car (cdr (insert-file-contents filename)))))
2958 ; (goto-char (point-min))
2959 ; (texinfo-append-refill)
2960 ; (texinfo-format-convert (point-min) (point-max))))
2961 ; (setq last-input-buffer input-buffer) ; to bypass setfilename
2965 ;;; Numerous commands do nothing in Texinfo
2967 ;; These commands are defined in texinfo.tex for printed output.
2969 (put 'bye
'texinfo-format
'texinfo-discard-line
)
2970 (put 'c
'texinfo-format
'texinfo-discard-line-with-args
)
2971 (put 'comment
'texinfo-format
'texinfo-discard-line-with-args
)
2972 (put 'contents
'texinfo-format
'texinfo-discard-line-with-args
)
2973 (put 'finalout
'texinfo-format
'texinfo-discard-line
)
2974 (put 'group
'texinfo-end
'texinfo-discard-line-with-args
)
2975 (put 'group
'texinfo-format
'texinfo-discard-line-with-args
)
2976 (put 'headings
'texinfo-format
'texinfo-discard-line-with-args
)
2977 (put 'hsize
'texinfo-format
'texinfo-discard-line-with-args
)
2978 (put 'itemindent
'texinfo-format
'texinfo-discard-line-with-args
)
2979 (put 'lispnarrowing
'texinfo-format
'texinfo-discard-line-with-args
)
2980 (put 'need
'texinfo-format
'texinfo-discard-line-with-args
)
2981 (put 'nopara
'texinfo-format
'texinfo-discard-line-with-args
)
2982 (put 'page
'texinfo-format
'texinfo-discard-line-with-args
)
2983 (put 'parindent
'texinfo-format
'texinfo-discard-line-with-args
)
2984 (put 'setchapternewpage
'texinfo-format
'texinfo-discard-line-with-args
)
2985 (put 'setq
'texinfo-format
'texinfo-discard-line-with-args
)
2986 (put 'settitle
'texinfo-format
'texinfo-discard-line-with-args
)
2987 (put 'setx
'texinfo-format
'texinfo-discard-line-with-args
)
2988 (put 'shortcontents
'texinfo-format
'texinfo-discard-line-with-args
)
2989 (put 'smallbook
'texinfo-format
'texinfo-discard-line
)
2990 (put 'summarycontents
'texinfo-format
'texinfo-discard-line-with-args
)
2993 ;;; Some commands cannot be handled
2995 (defun texinfo-unsupported ()
2996 (error "%s is not handled by texinfo"
2997 (buffer-substring texinfo-command-start texinfo-command-end
)))
2999 ;;; Batch formatting
3001 (defun batch-texinfo-format ()
3002 "Runs texinfo-format-buffer on the files remaining on the command line.
3003 Must be used only with -batch, and kills emacs on completion.
3004 Each file will be processed even if an error occurred previously.
3006 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
3007 (if (not noninteractive
)
3008 (error "batch-texinfo-format may only be used -batch."))
3009 (let ((version-control t
)
3010 (auto-save-default nil
)
3011 (find-file-run-dired nil
)
3012 (kept-old-versions 259259)
3013 (kept-new-versions 259259))
3017 (while command-line-args-left
3018 (setq file
(expand-file-name (car command-line-args-left
)))
3019 (cond ((not (file-exists-p file
))
3020 (message ">> %s does not exist!" file
)
3022 command-line-args-left
(cdr command-line-args-left
)))
3023 ((file-directory-p file
)
3024 (setq command-line-args-left
3025 (nconc (directory-files file
)
3026 (cdr command-line-args-left
))))
3028 (setq files
(cons file files
)
3029 command-line-args-left
(cdr command-line-args-left
)))))
3031 (setq file
(car files
)
3035 (if buffer-file-name
(kill-buffer (current-buffer)))
3037 (buffer-disable-undo (current-buffer))
3038 (set-buffer-modified-p nil
)
3040 (message "texinfo formatting %s..." file
)
3041 (texinfo-format-buffer nil
)
3042 (if (buffer-modified-p)
3043 (progn (message "Saving modified %s" (buffer-file-name))
3046 (message ">> Error: %s" (prin1-to-string err
))
3047 (message ">> point at")
3048 (let ((s (buffer-substring (point)
3049 (min (+ (point) 100)
3052 (while (setq tem
(string-match "\n+" s tem
))
3053 (setq s
(concat (substring s
0 (match-beginning 0))
3055 (substring s
(match-end 0)))
3057 (message ">> %s" s
))
3059 (kill-emacs error
))))
3062 ;;; Place `provide' at end of file.
3065 ;;; texinfmt.el ends here.