1 ;;;; texinfmt.el --- convert Texinfo files to Info files.
3 ;; Author: Robert J. Chassell <bob@gnu.ai.mit.edu>
5 ;; Last-Modified: 14 Dec 1990
8 ;; Copyright (C) 1985, 1986, 1988, 1990 Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 ;; Updated May 1990 to correspond, more or less, to version 2.8 of
29 ;; texinfo.tex. NOTE: texinfmt.el is being phased out; it is being
30 ;; replaced by makeinfo.c, which is faster and provides better error
32 ;; Robert J. Chassell, bob@ai.mit.edu
36 (defvar texinfo-format-syntax-table nil
)
38 (defvar texinfo-vindex
)
39 (defvar texinfo-findex
)
40 (defvar texinfo-cindex
)
41 (defvar texinfo-pindex
)
42 (defvar texinfo-tindex
)
43 (defvar texinfo-kindex
)
44 (defvar texinfo-last-node
)
45 (defvar texinfo-node-names
)
47 (if texinfo-format-syntax-table
49 (setq texinfo-format-syntax-table
(make-syntax-table))
50 (modify-syntax-entry ?
\" " " texinfo-format-syntax-table
)
51 (modify-syntax-entry ?
\\ " " texinfo-format-syntax-table
)
52 (modify-syntax-entry ?
@ "\\" texinfo-format-syntax-table
)
53 (modify-syntax-entry ?\^q
"\\" texinfo-format-syntax-table
)
54 (modify-syntax-entry ?\
[ "." texinfo-format-syntax-table
)
55 (modify-syntax-entry ?\
] "." texinfo-format-syntax-table
)
56 (modify-syntax-entry ?\
( "." texinfo-format-syntax-table
)
57 (modify-syntax-entry ?\
) "." texinfo-format-syntax-table
)
58 (modify-syntax-entry ?
{ "(}" texinfo-format-syntax-table
)
59 (modify-syntax-entry ?
} "){" texinfo-format-syntax-table
)
60 (modify-syntax-entry ?
\' "." texinfo-format-syntax-table
))
63 (defun texinfo-format-buffer (&optional notagify
)
64 "Process the current buffer as texinfo code, into an Info file.
65 The Info file output is generated in a buffer visiting the Info file
66 names specified in the @setfilename command.
68 Non-nil argument (prefix, if interactive) means don't make tag table
69 and don't split the file if large. You can use Info-tagify and
70 Info-split to do these manually."
72 (let ((lastmessage "Formatting Info file..."))
74 (texinfo-format-buffer-1)
77 (if (> (buffer-size) 30000)
79 (message (setq lastmessage
"Making tags table for Info file..."))
81 (if (> (buffer-size) 100000)
83 (message (setq lastmessage
"Splitting Info file..."))
85 (message (concat lastmessage
86 (if (interactive-p) "done. Now save it." "done.")))))
89 (defun texinfo-format-buffer-1 ()
90 (let (texinfo-format-filename
104 (texinfo-footnote-number 0)
107 (fill-column fill-column
)
108 (input-buffer (current-buffer))
109 (input-directory default-directory
))
111 (goto-char (point-min))
112 (search-forward "@setfilename")
113 (setq texinfo-command-end
(point))
114 (setq outfile
(texinfo-parse-line-arg)))
117 (set-syntax-table texinfo-format-syntax-table
)
119 (insert-buffer-substring input-buffer
)
120 (goto-char (point-min))
121 (search-forward "@setfilename")
123 (delete-region (point-min) (point))
124 ;; Remove @bye at end of file, if it is there.
125 (goto-char (point-max))
126 (if (search-backward "@bye" nil t
)
127 (delete-region (point) (point-max)))
128 ;; Make sure buffer ends in a newline.
129 (or (= (preceding-char) ?
\n)
131 ;; Scan the whole buffer, converting to Info format.
132 (texinfo-format-scan)
133 ;; Return data for indices.
134 (goto-char (point-min))
136 texinfo-vindex texinfo-findex texinfo-cindex
137 texinfo-pindex texinfo-tindex texinfo-kindex
)))
139 (defvar texinfo-region-buffer-name
"*Info Region*"
140 "*Name of the temporary buffer used by \\[texinfo-format-region].")
143 (defun texinfo-format-region (region-beginning region-ending
)
144 "Convert the current region of the Texinfo file to Info format.
145 This lets you see what that part of the file will look like in Info.
146 The command is bound to \\[texinfo-format-region]. The text that is
147 converted to Info is stored in a temporary buffer."
149 (message "Converting region to Info format...")
150 (let (texinfo-command-start
160 texinfo-format-filename
161 texinfo-example-start
164 (texinfo-footnote-number 0)
166 (fill-column fill-column
)
167 (input-buffer (current-buffer))
168 (input-directory default-directory
)
172 ;;; Find a buffer to use.
174 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name
))
176 ;; Insert the region into the buffer.
180 (set-buffer input-buffer
)
184 (goto-char (point-min))
185 ;; Initialize the buffer with the filename
186 ;; or else explain that a filename is needed.
187 (or (search-forward "@setfilename"
188 (save-excursion (forward-line 100) (point)) t
)
189 (error "The texinfo file needs a line saying: @setfilename <name>"))
191 (setq filename-beginning
(point))
193 (setq filename-ending
(point)))))
195 ;; Insert the @setfilename line into the buffer.
196 (insert-buffer-substring input-buffer
197 (min filename-beginning region-beginning
)
200 ;; Insert the region into the buffer.
201 (insert-buffer-substring input-buffer
202 (max region-beginning filename-ending
)
207 ;; Install a syntax table useful for scanning command operands.
208 (set-syntax-table texinfo-format-syntax-table
)
210 ;; If the region includes the effective end of the data,
211 ;; discard everything after that.
212 (goto-char (point-max))
213 (if (re-search-backward "^@bye" nil t
)
214 (delete-region (point) (point-max)))
215 ;; Make sure buffer ends in a newline.
216 (or (= (preceding-char) ?
\n)
219 ;; Now convert for real.
220 (goto-char (point-min))
221 (texinfo-format-scan)
222 (goto-char (point-min)))
227 ;; Perform those texinfo-to-info conversions that apply to the whole input
229 (defun texinfo-format-scan ()
230 ;; Convert left and right quotes to typewriter font quotes.
231 (goto-char (point-min))
232 (while (search-forward "``" nil t
)
233 (replace-match "\""))
234 (goto-char (point-min))
235 (while (search-forward "''" nil t
)
236 (replace-match "\""))
237 ;; Scan for @-commands.
238 (goto-char (point-min))
239 (while (search-forward "@" nil t
)
240 (if (looking-at "[@{}'` *]")
241 ;; Handle a few special @-followed-by-one-char commands.
242 (if (= (following-char) ?
*)
245 (delete-region (1- (point)) (1+ (point)))
246 ;; insert return if not at end of line;
247 ;; else line is already broken.
248 (if (not (= (following-char) ?
\n))
250 ;; The other characters are simply quoted. Delete the @.
253 ;; @ is followed by a command-word; find the end of the word.
254 (setq texinfo-command-start
(1- (point)))
255 (if (= (char-syntax (following-char)) ?w
)
258 (setq texinfo-command-end
(point))
259 ;; Call the handler for this command.
260 (setq texinfo-command-name
261 (intern (buffer-substring (1+ texinfo-command-start
)
262 texinfo-command-end
)))
263 (let ((cmd (get texinfo-command-name
'texinfo-format
)))
264 (if cmd
(funcall cmd
)
265 (texinfo-unsupported)))))
267 (goto-char (nth 2 (car texinfo-stack
)))
268 (error "Unterminated @%s" (car (car texinfo-stack
))))))
270 (put 'begin
'texinfo-format
'texinfo-format-begin
)
271 (defun texinfo-format-begin ()
272 (texinfo-format-begin-end 'texinfo-format
))
274 (put 'end
'texinfo-format
'texinfo-format-end
)
275 (defun texinfo-format-end ()
276 (texinfo-format-begin-end 'texinfo-end
))
278 (defun texinfo-format-begin-end (prop)
279 (setq texinfo-command-name
(intern (texinfo-parse-line-arg)))
280 (setq cmd
(get texinfo-command-name prop
))
281 (if cmd
(funcall cmd
)
282 (texinfo-unsupported)))
284 (defun texinfo-parse-line-arg ()
285 (goto-char texinfo-command-end
)
286 (let ((start (point)))
287 (cond ((looking-at " ")
288 (skip-chars-forward " ")
291 (skip-chars-backward " ")
292 (setq texinfo-command-end
(1+ (point))))
294 (setq start
(1+ (point)))
296 (setq texinfo-command-end
(point))
299 (error "Invalid texinfo command arg format")))
300 (prog1 (buffer-substring start
(point))
301 (if (eolp) (forward-char 1)))))
303 (defun texinfo-parse-expanded-arg ()
304 (goto-char texinfo-command-end
)
305 (let ((start (point))
307 (cond ((looking-at " ")
308 (skip-chars-forward " ")
311 (setq texinfo-command-end
(1+ (point))))
313 (setq start
(1+ (point)))
315 (setq texinfo-command-end
(point))
318 (error "Invalid texinfo command arg format")))
319 (setq marker
(move-marker (make-marker) texinfo-command-end
))
320 (texinfo-format-expand-region start
(point))
321 (setq texinfo-command-end
(marker-position marker
))
322 (move-marker marker nil
)
323 (prog1 (buffer-substring start
(point))
324 (if (eolp) (forward-char 1)))))
326 (defun texinfo-format-expand-region (start end
)
328 (narrow-to-region start end
)
329 (let (texinfo-command-start
333 (texinfo-format-scan))
334 (goto-char (point-max))))
336 (defun texinfo-parse-arg-discard ()
337 (prog1 (texinfo-parse-line-arg)
338 (texinfo-discard-command)))
340 (defun texinfo-discard-command ()
341 (delete-region texinfo-command-start texinfo-command-end
))
343 (defun texinfo-optional-braces-discard ()
344 "Discard braces following command, if any."
345 (goto-char texinfo-command-end
)
346 (let ((start (point)))
347 (cond ((looking-at "[ \t]*\n")) ; do nothing
348 ((looking-at "{") ; remove braces, if any
350 (setq texinfo-command-end
(point)))
353 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
354 (delete-region texinfo-command-start texinfo-command-end
)))
356 (defun texinfo-format-parse-line-args ()
357 (let ((start (1- (point)))
360 (skip-chars-forward " ")
363 (re-search-forward "[\n,]")
365 (if (bolp) (setq next
(1- next
)))
367 (skip-chars-backward " ")
369 (setq args
(cons (if (> end beg
) (buffer-substring beg end
))
372 (skip-chars-forward " "))
373 (if (eolp) (forward-char 1))
374 (setq texinfo-command-end
(point))
377 (defun texinfo-format-parse-args ()
378 (let ((start (1- (point)))
383 (texinfo-format-expand-region
385 (save-excursion (up-list 1) (1- (point)))))
386 (while (/= (preceding-char) ?\
})
387 (skip-chars-forward " \t\n")
389 (re-search-forward "[},]")
392 (skip-chars-backward " \t\n")
396 (while (search-forward "\n" end t
)
397 (replace-match " "))))
398 (setq args
(cons (if (> end beg
) (buffer-substring beg end
))
401 (if (eolp) (forward-char 1))
402 (setq texinfo-command-end
(point))
405 (defun texinfo-format-parse-defun-args ()
406 (goto-char texinfo-command-end
)
407 (let ((start (point)))
409 (setq texinfo-command-end
(1+ (point)))
410 (let ((marker (move-marker (make-marker) texinfo-command-end
)))
411 (texinfo-format-expand-region start
(point))
412 (setq texinfo-command-end
(marker-position marker
))
413 (move-marker marker nil
))
417 (skip-chars-forward " ")
419 (cond ((looking-at "{")
420 (setq beg
(1+ (point)))
422 (setq end
(1- (point))))
425 (re-search-forward "[\n ]")
428 (setq args
(cons (buffer-substring beg end
) args
))
429 (skip-chars-forward " "))
435 ; @setfilename modifed to work with include files; see @include
436 ; (defun texinfo-format-setfilename ()
437 ; (let ((arg (texinfo-parse-arg-discard)))
438 ; (setq texinfo-format-filename
439 ; (file-name-nondirectory (expand-file-name arg)))
440 ; (insert "Info file: "
441 ; texinfo-format-filename ", -*-Text-*-\n"
442 ; "produced by texinfo-format-buffer\nfrom "
443 ; (if (buffer-file-name input-buffer)
445 ; (file-name-sans-versions
446 ; (file-name-nondirectory
447 ; (buffer-file-name input-buffer))))
448 ; (concat "buffer " (buffer-name input-buffer)))
451 (put 'setfilename
'texinfo-format
'texinfo-format-setfilename
)
452 (defun texinfo-format-setfilename ()
453 (let ((arg (texinfo-parse-arg-discard)))
454 (if (eq input-buffer last-input-buffer
)
455 nil
; only use first setfilename in buffer
456 (message "Formatting Info file: %s" arg
)
457 (setq texinfo-format-filename
458 (file-name-nondirectory (expand-file-name arg
)))
459 (insert "Info file: "
460 texinfo-format-filename
", -*-Text-*-\n"
461 "produced by texinfo-format-buffer\nfrom "
462 (if (buffer-file-name input-buffer
)
464 (file-name-sans-versions
465 (file-name-nondirectory
466 (buffer-file-name input-buffer
))))
467 (concat "buffer " (buffer-name input-buffer
)))
470 (put 'node
'texinfo-format
'texinfo-format-node
)
471 (defun texinfo-format-node ()
472 (let* ((args (texinfo-format-parse-line-args))
477 (texinfo-discard-command)
478 (setq texinfo-last-node name
)
479 (let ((tem (downcase name
)))
480 (if (assoc tem texinfo-node-names
)
481 (error "Duplicate node name: %s" name
)
482 (setq texinfo-node-names
(cons (list tem
) texinfo-node-names
))))
483 (setq texinfo-footnote-number
0)
486 (insert "\^_\nFile: " texinfo-format-filename
489 (insert ", Prev: " prev
))
491 (insert ", Up: " up
))
493 (insert ", Next: " next
))
496 (put 'menu
'texinfo-format
'texinfo-format-menu
)
497 (defun texinfo-format-menu ()
498 (texinfo-discard-line)
499 (insert "* Menu:\n\n"))
501 (put 'menu
'texinfo-end
'texinfo-discard-command
)
502 (defun texinfo-discard-line ()
503 (goto-char texinfo-command-end
)
504 (skip-chars-forward " \t")
506 (error "Extraneous text at end of command line."))
507 (goto-char texinfo-command-start
)
509 (error "Extraneous text at beginning of command line."))
510 (delete-region (point) (progn (forward-line 1) (point))))
512 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
513 ; -> *Note FNAME: (FILE)NODE
514 ; If FILE is missing,
516 ; If FNAME is empty and NAME is present
518 ; If both NAME and FNAME are missing
520 ; texinfo ignores the DOCUMENT argument.
521 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
522 ; If FILE is specified, (FILE)NODE is used for xrefs.
523 ; If fifth argument DOCUMENT is specified, produces
524 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
527 ; @ref a reference that does not put `See' or `see' in
528 ; the hardcopy and is the same as @xref in Info
529 (put 'ref
'texinfo-format
'texinfo-format-xref
)
531 (put 'xref
'texinfo-format
'texinfo-format-xref
)
532 (defun texinfo-format-xref ()
533 (let ((args (texinfo-format-parse-args)))
534 (texinfo-discard-command)
536 (let ((fname (or (nth 1 args
) (nth 2 args
))))
537 (if (null (or fname
(nth 3 args
)))
538 (insert (car args
) "::")
539 (insert (or fname
(car args
)) ": ")
541 (insert "(" (nth 3 args
) ")"))
542 (insert (car args
))))))
544 (put 'pxref
'texinfo-format
'texinfo-format-pxref
)
545 (defun texinfo-format-pxref ()
546 (texinfo-format-xref)
552 ;@inforef{NODE, FNAME, FILE}
553 ;Like @xref{NODE, FNAME,,FILE} in texinfo.
554 ;In Tex, generates "See Info file FILE, node NODE"
555 (put 'inforef
'texinfo-format
'texinfo-format-inforef
)
556 (defun texinfo-format-inforef ()
557 (let ((args (texinfo-format-parse-args)))
558 (texinfo-discard-command)
560 (insert "*Note " (nth 1 args
) ": (" (nth 2 args
) ")" (car args
))
561 (insert "*Note " "(" (nth 2 args
) ")" (car args
) "::"))))
563 (put 'chapheading
'texinfo-format
'texinfo-format-chapter
)
564 (put 'ichapter
'texinfo-format
'texinfo-format-chapter
)
565 (put 'chapter
'texinfo-format
'texinfo-format-chapter
)
566 (put 'iappendix
'texinfo-format
'texinfo-format-chapter
)
567 (put 'appendix
'texinfo-format
'texinfo-format-chapter
)
568 (put 'iunnumbered
'texinfo-format
'texinfo-format-chapter
)
569 (put 'unnumbered
'texinfo-format
'texinfo-format-chapter
)
570 (defun texinfo-format-chapter ()
571 (texinfo-format-chapter-1 ?
*))
573 (put 'heading
'texinfo-format
'texinfo-format-section
)
574 (put 'isection
'texinfo-format
'texinfo-format-section
)
575 (put 'section
'texinfo-format
'texinfo-format-section
)
576 (put 'iappendixsection
'texinfo-format
'texinfo-format-section
)
577 (put 'appendixsection
'texinfo-format
'texinfo-format-section
)
578 (put 'iappendixsec
'texinfo-format
'texinfo-format-section
)
579 (put 'appendixsec
'texinfo-format
'texinfo-format-section
)
580 (put 'iunnumberedsec
'texinfo-format
'texinfo-format-section
)
581 (put 'unnumberedsec
'texinfo-format
'texinfo-format-section
)
582 (defun texinfo-format-section ()
583 (texinfo-format-chapter-1 ?
=))
585 (put 'subheading
'texinfo-format
'texinfo-format-subsection
)
586 (put 'isubsection
'texinfo-format
'texinfo-format-subsection
)
587 (put 'subsection
'texinfo-format
'texinfo-format-subsection
)
588 (put 'iappendixsubsec
'texinfo-format
'texinfo-format-subsection
)
589 (put 'appendixsubsec
'texinfo-format
'texinfo-format-subsection
)
590 (put 'iunnumberedsubsec
'texinfo-format
'texinfo-format-subsection
)
591 (put 'unnumberedsubsec
'texinfo-format
'texinfo-format-subsection
)
592 (defun texinfo-format-subsection ()
593 (texinfo-format-chapter-1 ?-
))
595 (put 'subsubheading
'texinfo-format
'texinfo-format-subsubsection
)
596 (put 'isubsubsection
'texinfo-format
'texinfo-format-subsubsection
)
597 (put 'subsubsection
'texinfo-format
'texinfo-format-subsubsection
)
598 (put 'iappendixsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
599 (put 'appendixsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
600 (put 'iunnumberedsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
601 (put 'unnumberedsubsubsec
'texinfo-format
'texinfo-format-subsubsection
)
602 (defun texinfo-format-subsubsection ()
603 (texinfo-format-chapter-1 ?.
))
605 (defun texinfo-format-chapter-1 (belowchar)
606 (let ((arg (texinfo-parse-arg-discard)))
607 (message "Formatting: %s ... " arg
) ; So we can see where we are.
608 (insert ?
\n arg ?
\n "@SectionPAD " belowchar ?
\n)
611 (put 'SectionPAD
'texinfo-format
'texinfo-format-sectionpad
)
612 (defun texinfo-format-sectionpad ()
613 (let ((str (texinfo-parse-arg-discard)))
615 (let ((column (current-column)))
619 (setq column
(1- column
))))
622 (put '\.
'texinfo-format
'texinfo-format-\.
)
623 (defun texinfo-format-\.
()
624 (texinfo-discard-command)
627 (put '\
: 'texinfo-format
'texinfo-format-\
:)
628 (defun texinfo-format-\
: ()
629 (texinfo-discard-command))
631 (put 'center
'texinfo-format
'texinfo-format-center
)
632 (defun texinfo-format-center ()
633 (texinfo-discard-command)
634 (let ((indent-tabs-mode nil
))
637 (put 'sp
'texinfo-format
'texinfo-format-sp
)
638 (defun texinfo-format-sp ()
639 (let* ((arg (texinfo-parse-arg-discard))
641 (insert-char ?
\n num
)))
643 (put 'br
'texinfo-format
'texinfo-format-paragraph-break
)
644 (defun texinfo-format-paragraph-break ()
645 "Force a paragraph break.
646 If used within a line, follow `@br' with braces."
647 (texinfo-optional-braces-discard)
648 ;; insert one return if at end of line;
649 ;; else insert two returns, to generate a blank line.
650 (if (= (following-char) ?
\n)
652 (insert-char ?
\n 2)))
657 ; In Texinfo, footnotes are created with the `@footnote' command.
658 ; This command is followed immediately by a left brace, then by the text of
659 ; the footnote, and then by a terminating right brace. The
660 ; template for a footnote is:
664 ; Info has two footnote styles:
667 ; In the "End Node" style, all the footnotes for a single node
668 ; are placed at the end of that node. The footnotes are
669 ; separated from the rest of the node by a line of dashes with
670 ; the word `Footnotes' within it.
673 ; In the "Make Node" style, all the footnotes for a single node are
674 ; placed in an automatically constructed node of their own.
676 (put 'footnote
'texinfo-format
'texinfo-format-footnote
)
678 (defvar texinfo-footnote-style
'MN
"\
679 *Footnote style, either EN for end node or MN for make node.")
681 (defvar texinfo-footnote-number
)
683 (defun texinfo-format-footnote ()
684 "Format a footnote in either `end node' or `make node' style.
685 The texinfo-footnote-style variable controls which style is used."
686 (setq texinfo-footnote-number
(1+ texinfo-footnote-number
))
687 (cond ((eq texinfo-footnote-style
'EN
) (texinfo-format-end-node))
688 ((eq texinfo-footnote-style
'MN
) (texinfo-format-make-node))))
690 (defun texinfo-format-make-node ()
691 "Format footnote in `MN', Make Node, style with notes in own node.
692 The node is constructed automatically."
694 (arg (texinfo-parse-expanded-arg))
698 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\)*[ \t]+Node:")
703 (progn (goto-char node-name-beginning
) ; skip over node command
704 (skip-chars-forward " \t") ; and over spaces
708 (save-excursion (end-of-line) (point)) t
) ; bound search
710 (end-of-line) (point))))))
711 (texinfo-discard-command)
712 (insert (format "(%d) (*note %s-Footnotes::)"
713 texinfo-footnote-number node-name
))
716 (if (re-search-forward "^@node" nil
'move
)
719 ;; two cases: for the first footnote, we must insert a node header;
720 ;; for the second and subsequent footnotes, we need only insert
721 ;; the text of the footnote.
725 (concat node-name
"-Footnotes, Up: ")
728 (progn ; already at least one footnote
730 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
731 (fill-region start
(point)))
732 ;; else not yet a footnote
733 (insert "\n\^_\nFile: " texinfo-format-filename
734 " Node: " node-name
"-Footnotes, Up: " node-name
"\n")
736 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
737 (fill-region start
(point))))))
739 (defun texinfo-format-end-node ()
740 "Format footnote in `EN', End Node, style with notes at end of node."
742 (arg (texinfo-parse-expanded-arg)))
743 (texinfo-discard-command)
744 (insert (format "(%d) " texinfo-footnote-number
))
747 (if (search-forward "\n--------- Footnotes ---------\n" nil t
)
748 (progn ; already have footnote, put new one before end of node
749 (if (re-search-forward "^@node" nil
'move
)
752 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
753 (fill-region start
(point)))
754 ;; else no prior footnote
755 (if (re-search-forward "^@node" nil
'move
)
757 (insert "\n--------- Footnotes ---------\n")
759 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg
))
760 (fill-region start
(point))))))
763 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
764 ;; @enumerate pushes (enumerate 0 STARTPOS).
765 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
766 ;; For itemize, this puts in and rescans the COMMANDS.
767 ;; For enumerate, this increments the number and puts it in.
768 ;; In either case, it puts a Backspace at the front of the line
769 ;; which marks it not to be indented later.
770 ;; All other lines get indented by 5 when the @end is reached.
772 (defun texinfo-push-stack (check arg
)
774 (cons (list check arg texinfo-command-start
)
777 (defun texinfo-pop-stack (check)
778 (if (null texinfo-stack
)
779 (error "Unmatched @end %s" check
))
780 (if (not (eq (car (car texinfo-stack
)) check
))
781 (error "@end %s matches @%s"
782 check
(car (car texinfo-stack
))))
783 (prog1 (cdr (car texinfo-stack
))
784 (setq texinfo-stack
(cdr texinfo-stack
))))
786 (put 'itemize
'texinfo-format
'texinfo-itemize
)
787 (defun texinfo-itemize ()
788 (texinfo-push-stack 'itemize
(texinfo-parse-arg-discard))
789 (setq fill-column
(- fill-column
5)))
791 (put 'itemize
'texinfo-end
'texinfo-end-itemize
)
792 (defun texinfo-end-itemize ()
793 (setq fill-column
(+ fill-column
5))
794 (texinfo-discard-command)
796 (texinfo-pop-stack 'itemize
)))
797 (texinfo-do-itemize (nth 1 stacktop
))))
799 (put 'enumerate
'texinfo-format
'texinfo-enumerate
)
800 (defun texinfo-enumerate ()
801 (texinfo-push-stack 'enumerate
0)
802 (setq fill-column
(- fill-column
5))
803 (texinfo-discard-line))
805 (put 'enumerate
'texinfo-end
'texinfo-end-enumerate
)
806 (defun texinfo-end-enumerate ()
807 (setq fill-column
(+ fill-column
5))
808 (texinfo-discard-command)
810 (texinfo-pop-stack 'enumerate
)))
811 (texinfo-do-itemize (nth 1 stacktop
))))
813 (put 'table
'texinfo-format
'texinfo-table
)
814 (defun texinfo-table ()
815 (texinfo-push-stack 'table
(texinfo-parse-arg-discard))
816 (setq fill-column
(- fill-column
5)))
818 (put 'ftable
'texinfo-format
'texinfo-ftable
)
819 (defun texinfo-ftable ()
820 (texinfo-push-stack 'table
"@code")
821 (setq fill-column
(- fill-column
5))
822 (texinfo-discard-line))
824 (put 'description
'texinfo-format
'texinfo-description
)
825 (defun texinfo-description ()
826 (texinfo-push-stack 'table
"@asis")
827 (setq fill-column
(- fill-column
5))
828 (texinfo-discard-line))
830 (put 'table
'texinfo-end
'texinfo-end-table
)
831 (put 'ftable
'texinfo-end
'texinfo-end-table
)
832 (put 'description
'texinfo-end
'texinfo-end-table
)
833 (defun texinfo-end-table ()
834 (setq fill-column
(+ fill-column
5))
835 (texinfo-discard-command)
837 (texinfo-pop-stack 'table
)))
838 (texinfo-do-itemize (nth 1 stacktop
))))
840 ;; At the @end, indent all the lines within the construct
841 ;; except those marked with backspace. FROM says where
842 ;; construct started.
843 (defun texinfo-do-itemize (from)
845 (while (progn (forward-line -
1)
847 (if (= (following-char) ?
\b)
852 (if (not (looking-at "[ \t]*$"))
853 (save-excursion (insert " ")))))))
855 (put 'item
'texinfo-format
'texinfo-item
)
856 (put 'itemx
'texinfo-format
'texinfo-item
)
857 (defun texinfo-item ()
858 (funcall (get (car (car texinfo-stack
)) 'texinfo-item
)))
860 (put 'itemize
'texinfo-item
'texinfo-itemize-item
)
861 (defun texinfo-itemize-item ()
862 (texinfo-discard-line)
863 (insert "\b " (nth 1 (car texinfo-stack
)) " \n")
866 (put 'enumerate
'texinfo-item
'texinfo-enumerate-item
)
867 (defun texinfo-enumerate-item ()
868 (texinfo-discard-line)
869 (let ((next (1+ (car (cdr (car texinfo-stack
))))))
870 (setcar (cdr (car texinfo-stack
)) next
)
871 (insert ?
\b (format "%3d. " next
) ?
\n))
874 (put 'table
'texinfo-item
'texinfo-table-item
)
875 (defun texinfo-table-item ()
876 (let ((arg (texinfo-parse-arg-discard))
877 (itemfont (car (cdr (car texinfo-stack
)))))
878 (insert ?
\b itemfont ?\
{ arg
"}\n \n"))
884 ; The `@ftable' command is like the `@table' command but it also
885 ; inserts each item in the first column into the function index.
887 (put 'ftable
'texinfo-format
'texinfo-ftable
)
889 ; The following function presumes that the first column of the table
890 ; should be in `@code' font; but the texinfo.tex source does not
892 ; (defun texinfo-ftable ()
893 ; (texinfo-push-stack 'ftable "@code")
894 ; (setq fill-column (- fill-column 5))
895 ; (texinfo-discard-line))
897 (defun texinfo-ftable ()
898 (texinfo-push-stack 'ftable
(texinfo-parse-arg-discard))
899 (setq fill-column
(- fill-column
5)))
901 (put 'ftable
'texinfo-item
'texinfo-ftable-item
)
902 (defun texinfo-ftable-item ()
903 (let ((item (texinfo-parse-arg-discard))
904 (itemfont (car (cdr (car texinfo-stack
))))
905 (indexvar 'texinfo-findex
))
906 (insert ?
\b itemfont ?\
{ item
"}\n \n")
909 (list item texinfo-last-node
)
910 (symbol-value indexvar
)))
913 (put 'ftable
'texinfo-end
'texinfo-end-ftable
)
914 (defun texinfo-end-ftable ()
915 (setq fill-column
(+ fill-column
5))
916 (texinfo-discard-command)
918 (texinfo-pop-stack 'ftable
)))
919 (texinfo-do-itemize (nth 1 stacktop
))))
922 (put 'ifinfo
'texinfo-format
'texinfo-discard-line
)
923 (put 'ifinfo
'texinfo-end
'texinfo-discard-command
)
925 (put 'iftex
'texinfo-format
'texinfo-format-iftex
)
926 (defun texinfo-format-iftex ()
927 (delete-region texinfo-command-start
928 (progn (re-search-forward "@end iftex\n")
931 (put 'tex
'texinfo-format
'texinfo-format-tex
)
932 (defun texinfo-format-tex ()
933 (delete-region texinfo-command-start
934 (progn (re-search-forward "@end tex\n")
937 (put 'titlepage
'texinfo-format
'texinfo-format-titlepage
)
938 (defun texinfo-format-titlepage ()
939 (delete-region texinfo-command-start
940 (progn (search-forward "@end titlepage\n")
943 (put 'endtitlepage
'texinfo-format
'texinfo-discard-line
)
945 ; @titlespec an alternative titling command; ignored by Info
947 (put 'titlespec
'texinfo-format
'texinfo-format-titlespec
)
948 (defun texinfo-format-titlespec ()
949 (delete-region texinfo-command-start
950 (progn (search-forward "@end titlespec\n")
953 (put 'endtitlespec
'texinfo-format
'texinfo-discard-line
)
957 (put 'today
'texinfo-format
'texinfo-format-today
)
959 ; Produces Day Month Year style of output. eg `1 Jan 1900'
960 ; The `@today{}' command requires a pair of braces, like `@dots{}'.
961 (defun texinfo-format-today ()
962 (texinfo-parse-arg-discard)
963 (insert (format "%s %s %s"
964 (substring (current-time-string) 8 10)
965 (substring (current-time-string) 4 7)
966 (substring (current-time-string) -
4))))
969 (put 'ignore
'texinfo-format
'texinfo-format-ignore
)
970 (defun texinfo-format-ignore ()
971 (delete-region texinfo-command-start
972 (progn (search-forward "@end ignore\n")
975 (put 'endignore
'texinfo-format
'texinfo-discard-line
)
977 (put 'var
'texinfo-format
'texinfo-format-var
)
978 ; @sc a small caps font for TeX; formatted as `var' in Info
979 (put 'sc
'texinfo-format
'texinfo-format-var
)
980 (defun texinfo-format-var ()
981 (insert (upcase (texinfo-parse-arg-discard)))
982 (goto-char texinfo-command-start
))
986 (put 'asis
'texinfo-format
'texinfo-format-noop
)
987 (put 'b
'texinfo-format
'texinfo-format-noop
)
988 (put 't
'texinfo-format
'texinfo-format-noop
)
989 (put 'i
'texinfo-format
'texinfo-format-noop
)
990 (put 'r
'texinfo-format
'texinfo-format-noop
)
991 (put 'titlefont
'texinfo-format
'texinfo-format-noop
)
992 (put 'key
'texinfo-format
'texinfo-format-noop
)
993 (put 'w
'texinfo-format
'texinfo-format-noop
)
994 (defun texinfo-format-noop ()
995 (insert (texinfo-parse-arg-discard))
996 (goto-char texinfo-command-start
))
998 (put 'code
'texinfo-format
'texinfo-format-code
)
999 (put 'samp
'texinfo-format
'texinfo-format-code
)
1000 (put 'file
'texinfo-format
'texinfo-format-code
)
1001 (put 'kbd
'texinfo-format
'texinfo-format-code
)
1002 (put 'cite
'texinfo-format
'texinfo-format-code
)
1003 (defun texinfo-format-code ()
1004 (insert "`" (texinfo-parse-arg-discard) "'")
1005 (goto-char texinfo-command-start
))
1007 (put 'emph
'texinfo-format
'texinfo-format-emph
)
1008 (put 'strong
'texinfo-format
'texinfo-format-emph
)
1009 (defun texinfo-format-emph ()
1010 (insert "*" (texinfo-parse-arg-discard) "*")
1011 (goto-char texinfo-command-start
))
1013 (put 'defn
'texinfo-format
'texinfo-format-defn
)
1014 (put 'dfn
'texinfo-format
'texinfo-format-defn
)
1015 (defun texinfo-format-defn ()
1016 (insert "\"" (texinfo-parse-arg-discard) "\"")
1017 (goto-char texinfo-command-start
))
1019 (put 'bullet
'texinfo-format
'texinfo-format-bullet
)
1020 (defun texinfo-format-bullet ()
1021 "Insert an asterisk.
1022 If used within a line, follow `@bullet' with braces."
1023 (texinfo-optional-braces-discard)
1026 (put 'smallexample
'texinfo-format
'texinfo-format-example
)
1027 (put 'smalllisp
'texinfo-format
'texinfo-format-example
)
1028 (put 'example
'texinfo-format
'texinfo-format-example
)
1029 (put 'quotation
'texinfo-format
'texinfo-format-example
)
1030 (put 'lisp
'texinfo-format
'texinfo-format-example
)
1031 (put 'display
'texinfo-format
'texinfo-format-example
)
1032 (put 'format
'texinfo-format
'texinfo-format-example
)
1033 (put 'flushleft
'texinfo-format
'texinfo-format-example
)
1034 (defun texinfo-format-example ()
1035 (texinfo-push-stack 'example nil
)
1036 (setq fill-column
(- fill-column
5))
1037 (texinfo-discard-line))
1039 (put 'smallexample
'texinfo-end
'texinfo-end-example
)
1040 (put 'example
'texinfo-end
'texinfo-end-example
)
1041 (put 'quotation
'texinfo-end
'texinfo-end-example
)
1042 (put 'lisp
'texinfo-end
'texinfo-end-example
)
1043 (put 'display
'texinfo-end
'texinfo-end-example
)
1044 (put 'format
'texinfo-end
'texinfo-end-example
)
1045 (put 'flushleft
'texinfo-end
'texinfo-end-example
)
1046 (defun texinfo-end-example ()
1047 (setq fill-column
(+ fill-column
5))
1048 (texinfo-discard-command)
1050 (texinfo-pop-stack 'example
)))
1051 (texinfo-do-itemize (nth 1 stacktop
))))
1053 (put 'exdent
'texinfo-format
'texinfo-format-exdent
)
1054 (defun texinfo-format-exdent ()
1055 (texinfo-discard-command)
1056 (delete-region (point)
1058 (skip-chars-forward " ")
1061 ;; Cancel out the deletion that texinfo-do-itemize
1062 ;; is going to do at the end of this line.
1068 ;; @flushright ... @end flushright
1070 ; The @flushright command right justifies every line but leaves the
1073 (put 'flushright
'texinfo-format
'texinfo-format-flushright
)
1074 (defun texinfo-format-flushright ()
1075 (texinfo-push-stack 'flushright nil
)
1076 (texinfo-discard-line))
1078 (put 'flushright
'texinfo-end
'texinfo-end-flushright
)
1079 (defun texinfo-end-flushright ()
1080 (texinfo-discard-command)
1083 (texinfo-pop-stack 'flushright
)))
1085 (texinfo-do-flushright (nth 1 stacktop
))))
1087 (defun texinfo-do-flushright (from)
1089 (while (progn (forward-line -
1)
1102 (put 'ctrl
'texinfo-format
'texinfo-format-ctrl
)
1103 (defun texinfo-format-ctrl ()
1104 (let ((str (texinfo-parse-arg-discard)))
1105 (insert (logand 31 (aref str
0)))))
1107 (put 'TeX
'texinfo-format
'texinfo-format-TeX
)
1108 (defun texinfo-format-TeX ()
1109 (texinfo-parse-arg-discard)
1112 (put 'copyright
'texinfo-format
'texinfo-format-copyright
)
1113 (defun texinfo-format-copyright ()
1114 (texinfo-parse-arg-discard)
1117 (put 'minus
'texinfo-format
'texinfo-format-minus
)
1118 (defun texinfo-format-minus ()
1119 "Insert a minus sign.
1120 If used within a line, follow `@minus' with braces."
1121 (texinfo-optional-braces-discard)
1124 (put 'dots
'texinfo-format
'texinfo-format-dots
)
1125 (defun texinfo-format-dots ()
1126 (texinfo-parse-arg-discard)
1129 (put 'refill
'texinfo-format
'texinfo-format-refill
)
1130 (defun texinfo-format-refill ()
1131 (texinfo-discard-command)
1132 (fill-paragraph nil
))
1135 ;;; Index generation
1137 (put 'vindex
'texinfo-format
'texinfo-format-vindex
)
1138 (defun texinfo-format-vindex ()
1139 (texinfo-index 'texinfo-vindex
))
1141 (put 'cindex
'texinfo-format
'texinfo-format-cindex
)
1142 (defun texinfo-format-cindex ()
1143 (texinfo-index 'texinfo-cindex
))
1145 (put 'findex
'texinfo-format
'texinfo-format-findex
)
1146 (defun texinfo-format-findex ()
1147 (texinfo-index 'texinfo-findex
))
1149 (put 'pindex
'texinfo-format
'texinfo-format-pindex
)
1150 (defun texinfo-format-pindex ()
1151 (texinfo-index 'texinfo-pindex
))
1153 (put 'tindex
'texinfo-format
'texinfo-format-tindex
)
1154 (defun texinfo-format-tindex ()
1155 (texinfo-index 'texinfo-tindex
))
1157 (put 'kindex
'texinfo-format
'texinfo-format-kindex
)
1158 (defun texinfo-format-kindex ()
1159 (texinfo-index 'texinfo-kindex
))
1161 (defun texinfo-index (indexvar)
1162 (let ((arg (texinfo-parse-expanded-arg)))
1163 (texinfo-discard-command)
1165 (cons (list arg texinfo-last-node
)
1166 (symbol-value indexvar
)))))
1168 (defconst texinfo-indexvar-alist
1169 '(("cp" . texinfo-cindex
)
1170 ("fn" . texinfo-findex
)
1171 ("vr" . texinfo-vindex
)
1172 ("tp" . texinfo-tindex
)
1173 ("pg" . texinfo-pindex
)
1174 ("ky" . texinfo-kindex
)))
1177 ;;; @defindex @defcodeindex
1178 (put 'defindex
'texinfo-format
'texinfo-format-defindex
)
1179 (put 'defcodeindex
'texinfo-format
'texinfo-format-defindex
)
1181 (defun texinfo-format-defindex ()
1182 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
1183 (indexing-command (intern (concat index-name
"index")))
1184 (index-formatting-command ; eg: `texinfo-format-aaindex'
1185 (intern (concat "texinfo-format-" index-name
"index")))
1186 (index-alist-name ; eg: `texinfo-aaindex'
1187 (intern (concat "texinfo-" index-name
"index"))))
1189 (set index-alist-name nil
)
1191 (put indexing-command
; eg, aaindex
1193 index-formatting-command
) ; eg, texinfo-format-aaindex
1195 ;; eg: "aa" . texinfo-aaindex
1196 (or (assoc index-name texinfo-indexvar-alist
)
1197 (setq texinfo-indexvar-alist
1201 texinfo-indexvar-alist
)))
1203 (fset index-formatting-command
1205 (list 'texinfo-index
1206 (list 'quote index-alist-name
))))))
1209 ;;; @synindex @syncodeindex
1211 (put 'synindex
'texinfo-format
'texinfo-format-synindex
)
1212 (put 'syncodeindex
'texinfo-format
'texinfo-format-synindex
)
1214 (defun texinfo-format-synindex ()
1215 (let* ((args (texinfo-parse-arg-discard))
1216 (second (cdr (read-from-string args
)))
1217 (joiner (symbol-name (car (read-from-string args
))))
1218 (joined (symbol-name (car (read-from-string args second
)))))
1220 (if (assoc joiner texinfo-short-index-cmds-alist
)
1222 (cdr (assoc joiner texinfo-short-index-cmds-alist
))
1224 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist
))
1225 (intern (concat "texinfo-format-" joined
"index"))))
1227 (intern (concat joiner
"index"))
1229 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist
))
1230 (intern (concat "texinfo-format-" joined
"index")))))))
1232 (defconst texinfo-short-index-cmds-alist
1240 (defconst texinfo-short-index-format-cmds-alist
1241 '(("cp" . texinfo-format-cindex
)
1242 ("fn" . texinfo-format-findex
)
1243 ("vr" . texinfo-format-vindex
)
1244 ("tp" . texinfo-format-tindex
)
1245 ("pg" . texinfo-format-pindex
)
1246 ("ky" . texinfo-format-kindex
)))
1251 (put 'printindex
'texinfo-format
'texinfo-format-printindex
)
1253 (defun texinfo-format-printindex ()
1254 (let ((indexelts (symbol-value
1255 (cdr (assoc (texinfo-parse-arg-discard)
1256 texinfo-indexvar-alist
))))
1258 (insert "\n* Menu:\n\n")
1259 (setq opoint
(point))
1260 (texinfo-print-index nil indexelts
)
1262 (if (eq system-type
'vax-vms
)
1263 (texinfo-sort-region opoint
(point))
1264 (shell-command-on-region opoint
(point) "sort -fd" 1))))
1266 (defun texinfo-print-index (file indexelts
)
1268 (if (stringp (car (car indexelts
)))
1269 (insert "* " (car (car indexelts
))
1270 ": " (if file
(concat "(" file
")") "")
1271 (nth 1 (car indexelts
)) ".\n")
1272 ;; index entries from @include'd file
1273 (texinfo-print-index (nth 1 (car indexelts
))
1274 (nth 2 (car indexelts
))))
1275 (setq indexelts
(cdr indexelts
))))
1278 ;;; NOTATIONS: @equiv, @error, etc
1280 ;; @equiv to show that two expressions are equivalent
1281 ;; @error to show an error message
1282 ;; @expansion to show what a macro expands to
1283 ;; @point to show the location of point in an example
1284 ;; @print to show what an evaluated expression prints
1285 ;; @result to indicate the value returned by an expression
1287 (put 'equiv
'texinfo-format
'texinfo-format-equiv
)
1288 (defun texinfo-format-equiv ()
1289 (texinfo-parse-arg-discard)
1292 (put 'error
'texinfo-format
'texinfo-format-error
)
1293 (defun texinfo-format-error ()
1294 (texinfo-parse-arg-discard)
1295 (insert "error-->"))
1297 (put 'expansion
'texinfo-format
'texinfo-format-expansion
)
1298 (defun texinfo-format-expansion ()
1299 (texinfo-parse-arg-discard)
1302 (put 'point
'texinfo-format
'texinfo-format-point
)
1303 (defun texinfo-format-point ()
1304 (texinfo-parse-arg-discard)
1307 (put 'print
'texinfo-format
'texinfo-format-print
)
1308 (defun texinfo-format-print ()
1309 (texinfo-parse-arg-discard)
1312 (put 'result
'texinfo-format
'texinfo-format-result
)
1313 (defun texinfo-format-result ()
1314 (texinfo-parse-arg-discard)
1318 ;;;; Description formatting: @deffn, @defun, etc
1320 (defun texinfo-format-defun ()
1321 (texinfo-push-stack 'defun
nil)
1322 (setq fill-column
(- fill-column
5))
1323 (texinfo-format-defun-1 t
))
1325 (defun texinfo-format-defunx ()
1326 (texinfo-format-defun-1 nil
))
1328 (defun texinfo-format-defun-1 (first-p)
1329 (let ((args (texinfo-format-parse-defun-args))
1330 (command-type (get texinfo-command-name
'texinfo-defun-type
))
1335 (texinfo-discard-command)
1338 ;; Generalized object oriented entity: `category class name [args...]'
1339 ;; In Info, `Category on class: name ARG'
1340 ((eq (eval (car command-type
)) 'defop-type
)
1341 (setq category
(car args
))
1342 (setq class
(car (cdr args
)))
1343 (setq name
(car args
))
1344 (setq args
(cdr (cdr args
))))
1346 ;; Specialized object oriented entity: @defmethod, @defivar
1347 ;; "Instance Variable" `class name [args...]'
1348 ;; In Info, `Instance variable of class: name'
1349 ((eq (eval (car command-type
)) 'defmethod-type
)
1350 (setq category
(car (cdr command-type
)))
1351 (setq class
(car args
))
1352 (setq name
(car args
))
1353 (setq args
(cdr args
)))
1355 ;; Generalized function-like or variable-like entity:
1356 ;; `category name [args...]'
1357 ;; In Info, `Category: name ARGS'
1358 ((or (eq (eval (car command-type
)) 'deffn-type
)
1359 (eq (eval (car command-type
)) 'deftp-type
))
1360 (setq category
(car args
))
1361 (setq args
(cdr args
))
1362 (setq name
(car args
)))
1364 ;; Specialized function-like or variable-like entity:
1365 ;; "Macro" `name [args...]'
1366 ;; In Info, `Macro: Name ARGS'
1367 ((eq (eval (car command-type
)) 'defun-type
)
1368 (setq category
(car (cdr command-type
)))
1369 (setq name
(car args
)))
1371 ;; Generalized typed-function-like or typed-variable-like entity:
1372 ;; `Classification data-type name [args...]'
1373 ;; In Info, `Classification: data-type name ARGS'
1374 ((or (eq (eval (car command-type
)) 'deftypefn-type
)
1375 (eq (eval (car command-type
)) 'deftypevr-type
))
1376 (setq classification
(car args
))
1377 (setq data-type
(car (cdr args
)))
1378 (setq name
(car (cdr (cdr args
))))
1379 (setq args
(cdr (cdr (cdr args
)))))
1381 ;; Specialized typed-function-like or typed-variable-like entity:
1382 ;; `data-type name [args...]'
1383 ;; In Info, `Function: data-type name ARGS'
1384 ;; or, `Variable: data-type name'
1385 ((or (eq (eval (car command-type
)) 'deftypefun-type
)
1386 (eq (eval (car command-type
)) 'deftypevar-type
))
1387 (setq classification
(car (cdr command-type
)))
1388 (setq data-type
(car args
))
1389 (setq name
(car (cdr args
)))
1390 (setq args
(cdr (cdr args
)))))
1392 ;; Delete extra newline inserted after previous header line.
1396 (let ((formatter (get texinfo-command-name
'texinfo-defun-format-type
)))
1398 ;; if typed function or variable
1399 ((eq formatter
'texinfo-format-deftypefn-type
)
1400 (insert "* " classification
": " data-type
" " name
)
1403 (insert " " (car args
))
1404 (setq args
(cdr args
)))))
1406 ;; and if object oriented, set category
1407 (if (or (eq formatter
'texinfo-format-defop-type
)
1408 (eq formatter
'texinfo-format-defcv-type
))
1409 (setq category
(funcall formatter category class
)))
1410 (insert "* " category
": " name
)
1411 (let ((args (cdr args
)))
1414 (if (or (= ?
& (aref (car args
) 0))
1415 (eq (eval (car command-type
)) 'deftp-type
))
1417 (upcase (car args
))))
1418 (setq args
(cdr args
)))))))
1420 ;; Insert extra newline so that paragraph filling does not mess
1421 ;; with header line.
1423 (rplaca (cdr (cdr (car texinfo-stack
))) (point))
1425 (let ((indexvar (get texinfo-command-name
'texinfo-defun-index
))
1427 (get texinfo-command-name
'texinfo-defun-format-index
)))
1431 ;; if object oriented
1432 ((or (eq index-formatter
'texinfo-format-defop-index
)
1433 (eq index-formatter
'texinfo-format-defcv-index
))
1434 (funcall index-formatter name class
))
1435 ((eq index-formatter
'texinfo-format-deftypefn-index
)
1436 (funcall index-formatter name data-type
))
1439 (symbol-value indexvar
))))))
1441 (defun texinfo-end-defun ()
1442 (setq fill-column
(+ fill-column
5))
1443 (texinfo-discard-command)
1444 (let ((start (nth 1 (texinfo-pop-stack 'defun
))))
1445 (texinfo-do-itemize start
)
1446 ;; Delete extra newline inserted after header.
1451 (defun texinfo-format-defop-type (category class
)
1452 (format "%s on %s" category class
))
1454 (defun texinfo-format-defop-index (name class
)
1455 (format "%s on %s" name class
))
1457 (defun texinfo-format-defcv-type (category class
)
1458 (format "%s of %s" category class
))
1460 (defun texinfo-format-defcv-index (name class
)
1461 (format "%s of %s" name class
))
1463 (put 'deffn
'texinfo-format
'texinfo-format-defun
)
1464 (put 'deffnx
'texinfo-format
'texinfo-format-defunx
)
1465 (put 'deffn
'texinfo-end
'texinfo-end-defun
)
1466 (put 'deffn
'texinfo-defun-type
'('deffn-type nil
))
1467 (put 'deffnx
'texinfo-defun-type
'('deffn-type nil
))
1468 (put 'deffn
'texinfo-defun-index
'texinfo-findex
)
1469 (put 'deffnx
'texinfo-defun-index
'texinfo-findex
)
1471 (put 'defun
'texinfo-format
'texinfo-format-defun
)
1472 (put 'defunx
'texinfo-format
'texinfo-format-defunx
)
1473 (put 'defun
'texinfo-end
'texinfo-end-defun
)
1474 (put 'defun
'texinfo-defun-type
'('defun-type
"Function"))
1475 (put 'defunx
'texinfo-defun-type
'('defun-type
"Function"))
1476 (put 'defun
'texinfo-defun-index
'texinfo-findex
)
1477 (put 'defunx
'texinfo-defun-index
'texinfo-findex
)
1479 (put 'defmac
'texinfo-format
'texinfo-format-defun
)
1480 (put 'defmacx
'texinfo-format
'texinfo-format-defunx
)
1481 (put 'defmac
'texinfo-end
'texinfo-end-defun
)
1482 (put 'defmac
'texinfo-defun-type
'('defun-type
"Macro"))
1483 (put 'defmacx
'texinfo-defun-type
'('defun-type
"Macro"))
1484 (put 'defmac
'texinfo-defun-index
'texinfo-findex
)
1485 (put 'defmacx
'texinfo-defun-index
'texinfo-findex
)
1487 (put 'defspec
'texinfo-format
'texinfo-format-defun
)
1488 (put 'defspecx
'texinfo-format
'texinfo-format-defunx
)
1489 (put 'defspec
'texinfo-end
'texinfo-end-defun
)
1490 (put 'defspec
'texinfo-defun-type
'('defun-type
"Special form"))
1491 (put 'defspecx
'texinfo-defun-type
'('defun-type
"Special form"))
1492 (put 'defspec
'texinfo-defun-index
'texinfo-findex
)
1493 (put 'defspecx
'texinfo-defun-index
'texinfo-findex
)
1495 (put 'defvr
'texinfo-format
'texinfo-format-defun
)
1496 (put 'defvrx
'texinfo-format
'texinfo-format-defunx
)
1497 (put 'defvr
'texinfo-end
'texinfo-end-defun
)
1498 (put 'defvr
'texinfo-defun-type
'('deffn-type nil
))
1499 (put 'defvrx
'texinfo-defun-type
'('deffn-type nil
))
1500 (put 'defvr
'texinfo-defun-index
'texinfo-vindex
)
1501 (put 'defvrx
'texinfo-defun-index
'texinfo-vindex
)
1503 (put 'defvar
'texinfo-format
'texinfo-format-defun
)
1504 (put 'defvarx
'texinfo-format
'texinfo-format-defunx
)
1505 (put 'defvar
'texinfo-end
'texinfo-end-defun
)
1506 (put 'defvar
'texinfo-defun-type
'('defun-type
"Variable"))
1507 (put 'defvarx
'texinfo-defun-type
'('defun-type
"Variable"))
1508 (put 'defvar
'texinfo-defun-index
'texinfo-vindex
)
1509 (put 'defvarx
'texinfo-defun-index
'texinfo-vindex
)
1511 (put 'defconst
'texinfo-format
'texinfo-format-defun
)
1512 (put 'defconstx
'texinfo-format
'texinfo-format-defunx
)
1513 (put 'defconst
'texinfo-end
'texinfo-end-defun
)
1514 (put 'defconst
'texinfo-defun-type
'('defun-type
"Constant"))
1515 (put 'defconstx
'texinfo-defun-type
'('defun-type
"Constant"))
1516 (put 'defconst
'texinfo-defun-index
'texinfo-vindex
)
1517 (put 'defconstx
'texinfo-defun-index
'texinfo-vindex
)
1519 (put 'defcmd
'texinfo-format
'texinfo-format-defun
)
1520 (put 'defcmdx
'texinfo-format
'texinfo-format-defunx
)
1521 (put 'defcmd
'texinfo-end
'texinfo-end-defun
)
1522 (put 'defcmd
'texinfo-defun-type
'('defun-type
"Command"))
1523 (put 'defcmdx
'texinfo-defun-type
'('defun-type
"Command"))
1524 (put 'defcmd
'texinfo-defun-index
'texinfo-findex
)
1525 (put 'defcmdx
'texinfo-defun-index
'texinfo-findex
)
1527 (put 'defopt
'texinfo-format
'texinfo-format-defun
)
1528 (put 'defoptx
'texinfo-format
'texinfo-format-defunx
)
1529 (put 'defopt
'texinfo-end
'texinfo-end-defun
)
1530 (put 'defopt
'texinfo-defun-type
'('defun-type
"User Option"))
1531 (put 'defoptx
'texinfo-defun-type
'('defun-type
"User Option"))
1532 (put 'defopt
'texinfo-defun-index
'texinfo-vindex
)
1533 (put 'defoptx
'texinfo-defun-index
'texinfo-vindex
)
1535 (put 'deftp
'texinfo-format
'texinfo-format-defun
)
1536 (put 'deftpx
'texinfo-format
'texinfo-format-defunx
)
1537 (put 'deftp
'texinfo-end
'texinfo-end-defun
)
1538 (put 'deftp
'texinfo-defun-type
'('deftp-type nil
))
1539 (put 'deftpx
'texinfo-defun-type
'('deftp-type nil
))
1540 (put 'deftp
'texinfo-defun-index
'texinfo-tindex
)
1541 (put 'deftpx
'texinfo-defun-index
'texinfo-tindex
)
1543 ;;; Object-oriented stuff is a little hairier.
1545 (put 'defop
'texinfo-format
'texinfo-format-defun
)
1546 (put 'defopx
'texinfo-format
'texinfo-format-defunx
)
1547 (put 'defop
'texinfo-end
'texinfo-end-defun
)
1548 (put 'defop
'texinfo-defun-type
'('defop-type nil
))
1549 (put 'defopx
'texinfo-defun-type
'('defop-type nil
))
1550 (put 'defop
'texinfo-defun-format-type
'texinfo-format-defop-type
)
1551 (put 'defopx
'texinfo-defun-format-type
'texinfo-format-defop-type
)
1552 (put 'defop
'texinfo-defun-index
'texinfo-findex
)
1553 (put 'defopx
'texinfo-defun-index
'texinfo-findex
)
1554 (put 'defop
'texinfo-defun-format-index
'texinfo-format-defop-index
)
1555 (put 'defopx
'texinfo-defun-format-index
'texinfo-format-defop-index
)
1557 (put 'defmethod
'texinfo-format
'texinfo-format-defun
)
1558 (put 'defmethodx
'texinfo-format
'texinfo-format-defunx
)
1559 (put 'defmethod
'texinfo-end
'texinfo-end-defun
)
1560 (put 'defmethod
'texinfo-defun-type
'('defmethod-type
"Operation"))
1561 (put 'defmethodx
'texinfo-defun-type
'('defmethod-type
"Operation"))
1562 (put 'defmethod
'texinfo-defun-format-type
'texinfo-format-defop-type
)
1563 (put 'defmethodx
'texinfo-defun-format-type
'texinfo-format-defop-type
)
1564 (put 'defmethod
'texinfo-defun-index
'texinfo-findex
)
1565 (put 'defmethodx
'texinfo-defun-index
'texinfo-findex
)
1566 (put 'defmethod
'texinfo-defun-format-index
'texinfo-format-defop-index
)
1567 (put 'defmethodx
'texinfo-defun-format-index
'texinfo-format-defop-index
)
1569 (put 'defcv
'texinfo-format
'texinfo-format-defun
)
1570 (put 'defcvx
'texinfo-format
'texinfo-format-defunx
)
1571 (put 'defcv
'texinfo-end
'texinfo-end-defun
)
1572 (put 'defcv
'texinfo-defun-type
'('defop-type nil
))
1573 (put 'defcvx
'texinfo-defun-type
'('defop-type nil
))
1574 (put 'defcv
'texinfo-defun-format-type
'texinfo-format-defcv-type
)
1575 (put 'defcvx
'texinfo-defun-format-type
'texinfo-format-defcv-type
)
1576 (put 'defcv
'texinfo-defun-index
'texinfo-vindex
)
1577 (put 'defcvx
'texinfo-defun-index
'texinfo-vindex
)
1578 (put 'defcv
'texinfo-defun-format-index
'texinfo-format-defcv-index
)
1579 (put 'defcvx
'texinfo-defun-format-index
'texinfo-format-defcv-index
)
1581 (put 'defivar
'texinfo-format
'texinfo-format-defun
)
1582 (put 'defivarx
'texinfo-format
'texinfo-format-defunx
)
1583 (put 'defivar
'texinfo-end
'texinfo-end-defun
)
1584 (put 'defivar
'texinfo-defun-type
'('defmethod-type
"Instance variable"))
1585 (put 'defivarx
'texinfo-defun-type
'('defmethod-type
"Instance variable"))
1586 (put 'defivar
'texinfo-defun-format-type
'texinfo-format-defcv-type
)
1587 (put 'defivarx
'texinfo-defun-format-type
'texinfo-format-defcv-type
)
1588 (put 'defivar
'texinfo-defun-index
'texinfo-vindex
)
1589 (put 'defivarx
'texinfo-defun-index
'texinfo-vindex
)
1590 (put 'defivar
'texinfo-defun-format-index
'texinfo-format-defcv-index
)
1591 (put 'defivarx
'texinfo-defun-format-index
'texinfo-format-defcv-index
)
1593 ;;; Typed functions and variables
1595 (defun texinfo-format-deftypefn-type (classification data-type
)
1596 (format "%s" classification data-type
))
1598 (defun texinfo-format-deftypefn-index (name data-type
)
1599 (format "%s of type %s" name data-type
))
1602 (put 'deftypefn
'texinfo-format
'texinfo-format-defun
)
1603 (put 'deftypefnx
'texinfo-format
'texinfo-format-defunx
)
1604 (put 'deftypefn
'texinfo-end
'texinfo-end-defun
)
1605 (put 'deftypefn
'texinfo-defun-type
'('deftypefn-type nil
))
1606 (put 'deftypefnx
'texinfo-defun-type
'('deftypefn-type nil
))
1607 (put 'deftypefn
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1608 (put 'deftypefnx
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1609 (put 'deftypefn
'texinfo-defun-index
'texinfo-findex
)
1610 (put 'deftypefnx
'texinfo-defun-index
'texinfo-findex
)
1611 (put 'deftypefn
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1612 (put 'deftypefnx
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1614 (put 'deftypefun
'texinfo-format
'texinfo-format-defun
)
1615 (put 'deftypefunx
'texinfo-format
'texinfo-format-defunx
)
1616 (put 'deftypefun
'texinfo-end
'texinfo-end-defun
)
1617 (put 'deftypefun
'texinfo-defun-type
'('deftypefun-type
"Function"))
1618 (put 'deftypefunx
'texinfo-defun-type
'('deftypefun-type
"Function"))
1619 (put 'deftypefun
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1620 (put 'deftypefunx
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1621 (put 'deftypefun
'texinfo-defun-index
'texinfo-findex
)
1622 (put 'deftypefunx
'texinfo-defun-index
'texinfo-findex
)
1623 (put 'deftypefun
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1624 (put 'deftypefunx
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1626 (put 'deftypevr
'texinfo-format
'texinfo-format-defun
)
1627 (put 'deftypevrx
'texinfo-format
'texinfo-format-defunx
)
1628 (put 'deftypevr
'texinfo-end
'texinfo-end-defun
)
1629 (put 'deftypevr
'texinfo-defun-type
'('deftypefn-type nil
))
1630 (put 'deftypevrx
'texinfo-defun-type
'('deftypefn-type nil
))
1631 (put 'deftypevr
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1632 (put 'deftypevrx
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1633 (put 'deftypevr
'texinfo-defun-index
'texinfo-vindex
)
1634 (put 'deftypevrx
'texinfo-defun-index
'texinfo-vindex
)
1635 (put 'deftypevr
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1636 (put 'deftypevrx
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1638 (put 'deftypevar
'texinfo-format
'texinfo-format-defun
)
1639 (put 'deftypevarx
'texinfo-format
'texinfo-format-defunx
)
1640 (put 'deftypevar
'texinfo-end
'texinfo-end-defun
)
1641 (put 'deftypevar
'texinfo-defun-type
'('deftypevar-type
"Variable"))
1642 (put 'deftypevarx
'texinfo-defun-type
'('deftypevar-type
"Variable"))
1643 (put 'deftypevar
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1644 (put 'deftypevarx
'texinfo-defun-format-type
'texinfo-format-deftypefn-type
)
1645 (put 'deftypevar
'texinfo-defun-index
'texinfo-vindex
)
1646 (put 'deftypevarx
'texinfo-defun-index
'texinfo-vindex
)
1647 (put 'deftypevar
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1648 (put 'deftypevarx
'texinfo-defun-format-index
'texinfo-format-deftypefn-index
)
1651 ;; process included files: `@include' command
1653 ;; Updated 19 October 1990
1654 ;; In the original version, include files were ignored by Info but
1655 ;; incorporated in to the printed manual. To make references to the
1656 ;; included file, the Texinfo source file has to refer to the included
1657 ;; files using the `(filename)nodename' format for refering to other
1658 ;; Info files. Also, the included files had to be formatted on their
1659 ;; own. It was just like they were another file.
1661 ;; Currently, include files are inserted into the buffer that is
1662 ;; formatted for Info. If large, the resulting info file is split and
1663 ;; tagified. For current include files to work, the master menu must
1664 ;; refer to all the nodes, and the highest level nodes in the include
1665 ;; files must have the correct next, prev, and up pointers.
1667 ;; The included file may have an @setfilename and even an @settitle,
1668 ;; but not an /input texinfo
1670 ; Original definition:
1671 ; (defun texinfo-format-include ()
1672 ; (let ((filename (texinfo-parse-arg-discard))
1673 ; (default-directory input-directory)
1678 ; (cond ((file-readable-p (concat filename ".texinfo"))
1679 ; (concat filename ".texinfo"))
1680 ; ((file-readable-p (concat filename ".texi"))
1681 ; (concat filename ".texi"))
1682 ; ((file-readable-p (concat filename ".tex"))
1683 ; (concat filename ".tex"))
1684 ; ((file-readable-p filename)
1686 ; (t (error "@include'd file %s not found"
1688 ; (texinfo-format-buffer-1))))
1689 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
1690 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
1691 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
1692 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
1693 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
1694 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
1696 (defun texinfo-subindex (indexvar file content
)
1697 (set indexvar
(cons (list 'recurse file content
)
1698 (symbol-value indexvar
))))
1700 (put 'include
'texinfo-format
'texinfo-format-include
)
1701 (defun texinfo-format-include ()
1702 (let ((filename (concat input-directory
1703 (texinfo-parse-arg-discard)))
1704 (default-directory input-directory
))
1705 (message "Reading: %s" filename
)
1707 (insert-file-contents filename
)))
1708 (setq last-input-buffer input-buffer
) ; to bypass setfilename
1713 ;; Lots of bolio constructs do nothing in texinfo.
1715 (put 'page
'texinfo-format
'texinfo-discard-line-with-args
)
1716 (put 'c
'texinfo-format
'texinfo-discard-line-with-args
)
1717 (put 'comment
'texinfo-format
'texinfo-discard-line-with-args
)
1718 (put 'setchapternewpage
'texinfo-format
'texinfo-discard-line-with-args
)
1719 (put 'contents
'texinfo-format
'texinfo-discard-line-with-args
)
1720 (put 'summarycontents
'texinfo-format
'texinfo-discard-line-with-args
)
1721 (put 'shortcontents
'texinfo-format
'texinfo-discard-line-with-args
)
1722 (put 'nopara
'texinfo-format
'texinfo-discard-line-with-args
)
1723 (put 'noindent
'texinfo-format
'texinfo-discard-line-with-args
)
1724 (put 'setx
'texinfo-format
'texinfo-discard-line-with-args
)
1725 (put 'setq
'texinfo-format
'texinfo-discard-line-with-args
)
1726 (put 'settitle
'texinfo-format
'texinfo-discard-line-with-args
)
1727 (put 'hsize
'texinfo-format
'texinfo-discard-line-with-args
)
1728 (put 'parindent
'texinfo-format
'texinfo-discard-line-with-args
)
1729 (put 'lispnarrowing
'texinfo-format
'texinfo-discard-line-with-args
)
1730 (put 'itemindent
'texinfo-format
'texinfo-discard-line-with-args
)
1731 (put 'headings
'texinfo-format
'texinfo-discard-line-with-args
)
1732 (put 'group
'texinfo-format
'texinfo-discard-line-with-args
)
1733 (put 'group
'texinfo-end
'texinfo-discard-line-with-args
)
1734 (put 'need
'texinfo-format
'texinfo-discard-line-with-args
)
1735 (put 'bye
'texinfo-format
'texinfo-discard-line
)
1736 (put 'smallbook
'texinfo-format
'texinfo-discard-line
)
1738 (defun texinfo-discard-line-with-args ()
1739 (goto-char texinfo-command-start
)
1740 (delete-region (point) (progn (forward-line 1) (point))))
1742 ;; Sort an index which is in the current buffer between START and END.
1743 ;; Used on VMS, where the `sort' utility is not available.
1744 (defun texinfo-sort-region (start end
)
1747 (narrow-to-region start end
)
1748 (sort-subr nil
'forward-line
'end-of-line
'texinfo-sort-startkeyfun
)))
1750 ;; Subroutine for sorting an index.
1751 ;; At start of a line, return a string to sort the line under.
1752 (defun texinfo-sort-startkeyfun ()
1754 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
1755 ;; Canonicalize whitespace and eliminate funny chars.
1756 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line
)
1757 (setq line
(concat (substring line
0 (match-beginning 0))
1759 (substring line
(match-end 0) (length line
)))))
1762 ;; Some cannot be handled
1764 (defun texinfo-unsupported ()
1765 (error "%s is not handled by texinfo"
1766 (buffer-substring texinfo-command-start texinfo-command-end
)))
1769 (defun batch-texinfo-format ()
1770 "Runs texinfo-format-buffer on the files remaining on the command line.
1771 Must be used only with -batch, and kills emacs on completion.
1772 Each file will be processed even if an error occurred previously.
1774 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
1775 (if (not noninteractive
)
1776 (error "batch-texinfo-format may only be used -batch."))
1777 (let ((version-control t
)
1778 (auto-save-default nil
)
1779 (find-file-run-dired nil
)
1780 (kept-old-versions 259259)
1781 (kept-new-versions 259259))
1785 (while command-line-args-left
1786 (setq file
(expand-file-name (car command-line-args-left
)))
1787 (cond ((not (file-exists-p file
))
1788 (message ">> %s does not exist!" file
)
1790 command-line-args-left
(cdr command-line-args-left
)))
1791 ((file-directory-p file
)
1792 (setq command-line-args-left
1793 (nconc (directory-files file
)
1794 (cdr command-line-args-left
))))
1796 (setq files
(cons file files
)
1797 command-line-args-left
(cdr command-line-args-left
)))))
1799 (setq file
(car files
)
1803 (if buffer-file-name
(kill-buffer (current-buffer)))
1805 (buffer-disable-undo (current-buffer))
1806 (set-buffer-modified-p nil
)
1808 (message "texinfo formatting %s..." file
)
1809 (texinfo-format-buffer nil
)
1810 (if (buffer-modified-p)
1811 (progn (message "Saving modified %s" (buffer-file-name))
1814 (message ">> Error: %s" (prin1-to-string err
))
1815 (message ">> point at")
1816 (let ((s (buffer-substring (point)
1817 (min (+ (point) 100)
1820 (while (setq tem
(string-match "\n+" s tem
))
1821 (setq s
(concat (substring s
0 (match-beginning 0))
1823 (substring s
(match-end 0)))
1825 (message ">> %s" s
))
1827 (kill-emacs error
))))
1829 ;;; texinfmt.el ends here