1 ;;; texinfmt.el --- format Texinfo files into Info files
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997, 1998, 2000, 2001
5 ;; Free Software Foundation, Inc.
7 ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org>
8 ;; Keywords: maint, tex, docs
10 ;; This file is part of XEmacs.
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 ;;; Synched up with: FSF 21.3.
31 ;; XEmacs Maintainers note:
32 ;; This file is should be kept strictly in synch. The only differences
33 ;; should be due to whitespace (the author doesn't believe in TABs)
34 ;; other than the VM manual fuckage.
42 ;;; Emacs lisp functions to convert Texinfo files to Info files.
44 (or (fboundp 'defgroup)
45 (defmacro defgroup (&rest ignore) nil))
47 (or (fboundp 'defcustom)
48 (defmacro defcustom (var value doc &rest ignore)
49 `(defvar ,var ,value ,doc)))
51 (defvar texinfmt-version "2.41 of 1 Mar 2005")
53 (or (fboundp 'match-string-no-properties) ;; XEmacs: not in 21.4
54 (defun match-string-no-properties (num &optional string)
55 "Return string of text matched by last search, without text properties.
56 NUM specifies which parenthesized expression in the last regexp.
57 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
58 Zero means the entire text matched by the whole regexp or whole string.
59 STRING should be given if the last search was by `string-match' on STRING."
60 (if (match-beginning num)
63 (substring string (match-beginning num) (match-end num))))
64 (set-text-properties 0 (length result) nil result)
66 (buffer-substring-no-properties (match-beginning num)
69 (defvar texinfmt-version "2.40 of 6 Dec 2002")
71 (defun texinfmt-version (&optional here)
72 "Show the version of texinfmt.el in the minibuffer.
73 If optional argument HERE is non-nil, insert info at point."
76 (format "Version of \`texinfmt.el\': %s" texinfmt-version)))
78 (insert version-string)
80 (message "%s" version-string)
83 ;;; Variable definitions
85 (require 'texinfo) ; So `texinfo-footnote-style' is defined.
86 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
88 (defvar texinfo-format-syntax-table nil)
90 (defvar texinfo-vindex)
91 (defvar texinfo-findex)
92 (defvar texinfo-cindex)
93 (defvar texinfo-pindex)
94 (defvar texinfo-tindex)
95 (defvar texinfo-kindex)
96 (defvar texinfo-last-node)
97 (defvar texinfo-node-names)
98 (defvar texinfo-enclosure-list)
99 (defvar texinfo-alias-list)
100 (defvar texinfo-fold-nodename-case nil)
102 (defvar texinfo-command-start)
103 (defvar texinfo-command-end)
104 (defvar texinfo-command-name)
105 (defvar texinfo-defun-type)
106 (defvar texinfo-last-node-pos)
107 (defvar texinfo-stack)
108 (defvar texinfo-short-index-cmds-alist)
109 (defvar texinfo-short-index-format-cmds-alist)
110 (defvar texinfo-format-filename)
111 (defvar texinfo-footnote-number)
112 (defvar texinfo-start-of-header)
113 (defvar texinfo-end-of-header)
114 (defvar texinfo-raisesections-alist)
115 (defvar texinfo-lowersections-alist)
119 (if texinfo-format-syntax-table
121 (setq texinfo-format-syntax-table (make-syntax-table))
122 (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
123 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
124 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
125 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
126 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
127 (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
128 (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
129 (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
130 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
131 (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
132 (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
135 ;;; Top level buffer and region formatting functions
138 (defun texinfo-format-buffer (&optional nosplit)
139 "Process the current buffer as texinfo code, into an Info file.
140 The Info file output is generated in a buffer visiting the Info file
141 name specified in the @setfilename command.
143 Non-nil argument (prefix, if interactive) means don't make tag table
144 and don't split the file if large. You can use Info-tagify and
145 Info-split to do these manually."
147 (let ((lastmessage "Formatting Info file...")
148 ;; XEmacs change removed here 2005-09-25.
149 (coding-system-for-write buffer-file-coding-system))
150 (message lastmessage)
152 (texinfo-format-buffer-1)
156 (if (> (buffer-size) 100000)
158 (message (setq lastmessage "Splitting Info file..."))
160 (message (concat lastmessage
161 (if (interactive-p) "done. Now save it." "done.")))))
163 (defvar texinfo-region-buffer-name "*Info Region*"
164 "*Name of the temporary buffer used by \\[texinfo-format-region].")
166 (defvar texinfo-pre-format-hook nil
167 "Hook called before the conversion of the Texinfo file to Info format.
168 The functions on this hook are called with argument BUFFER, the buffer
169 containing the Texinfo file.")
171 ;; These come from tex-mode.el.
172 (defvar tex-start-of-header)
173 (defvar tex-end-of-header)
176 (defun texinfo-format-region (region-beginning region-end)
177 "Convert the current region of the Texinfo file to Info format.
178 This lets you see what that part of the file will look like in Info.
179 The command is bound to \\[texinfo-format-region]. The text that is
180 converted to Info is stored in a temporary buffer."
182 (message "Converting region to Info format...")
183 (let (texinfo-command-start
193 (texinfo-format-filename "")
194 texinfo-example-start
195 texinfo-last-node-pos
198 (texinfo-footnote-number 0)
200 (fill-column-for-info fill-column)
201 (input-buffer (current-buffer))
202 (input-directory default-directory)
207 ;;; Copy lines between beginning and end of header lines,
208 ;;; if any, or else copy the `@setfilename' line, if any.
212 (goto-char (point-min))
213 (let ((search-end (save-excursion (forward-line 100) (point))))
215 ;; Either copy header text.
218 (search-forward tex-start-of-header search-end t)
220 ;; Mark beginning of header.
221 (setq header-beginning (point)))
223 (search-forward tex-end-of-header nil t)
225 ;; Mark end of header
226 (setq header-end (point))))
227 ;; Or copy @filename line.
229 (goto-char (point-min))
230 (search-forward "@setfilename" search-end t)
232 (setq header-beginning (point))
234 (setq header-end (point))))
238 (buffer-substring-no-properties
239 (min header-beginning region-beginning)
242 ;;; Find a buffer to use.
243 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
245 ;; Insert the header into the buffer.
247 ;; Insert the region into the buffer.
248 (insert-buffer-substring
250 (max region-beginning header-end)
252 (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
253 ;; Make sure region ends in a newline.
254 (or (= (preceding-char) ?\n)
257 (goto-char (point-min))
259 ;; Remove trailing WS like makeinfo does
261 ;;; (unless (equal texinfo-paragraph-indent "asis")
263 (message "Removing trailing whitespace from Info region...")
264 (while (re-search-forward "[ \t]+$" nil t)
265 (replace-match "" nil nil)))
268 (message "Converting region to Info format...")
269 (setq fill-column fill-column-for-info)
270 ;; Install a syntax table useful for scanning command operands.
271 (set-syntax-table texinfo-format-syntax-table)
273 ;; Insert @include files so `texinfo-raise-lower-sections' can
274 ;; work on them without losing track of multiple
275 ;; @raise/@lowersections commands.
276 (while (re-search-forward "^@include" nil t)
277 (setq texinfo-command-end (point))
278 (let ((filename (concat input-directory
279 (texinfo-parse-line-arg))))
280 (re-search-backward "^@include")
281 (delete-region (point) (save-excursion (forward-line 1) (point)))
282 (message "Reading included file: %s" filename)
287 (+ (point) (car (cdr (insert-file-contents filename)))))
288 (goto-char (point-min))
289 ;; Remove `@setfilename' line from included file, if any,
290 ;; so @setfilename command not duplicated.
291 (if (re-search-forward "^@setfilename" (point-at-eol 100) t)
292 (delete-region (point-at-bol 1)
293 (point-at-bol 2)))))))
295 ;; Raise or lower level of each section, if necessary.
296 (goto-char (point-min))
297 (texinfo-raise-lower-sections)
298 ;; Append @refill to appropriate paragraphs for filling.
299 (goto-char (point-min))
300 (texinfo-append-refill)
301 ;; If the region includes the effective end of the data,
302 ;; discard everything after that.
303 (goto-char (point-max))
304 (if (re-search-backward "^@bye" nil t)
305 (delete-region (point) (point-max)))
306 ;; Make sure buffer ends in a newline.
307 (or (= (preceding-char) ?\n)
309 ;; Don't use a previous value of texinfo-enclosure-list.
310 (setq texinfo-enclosure-list nil)
311 (setq texinfo-alias-list nil)
313 (goto-char (point-min))
314 (if (looking-at "\\\\input[ \t]+texinfo")
315 (delete-region (point) (point-at-bol 2)))
317 ;; Insert Info region title text.
318 (goto-char (point-min))
320 "@setfilename" (save-excursion (forward-line 100) (point)) t)
322 (setq texinfo-command-end (point))
324 (setq texinfo-command-start (point))
325 (let ((arg (texinfo-parse-arg-discard)))
327 texinfo-region-buffer-name
329 (insert (file-name-nondirectory (expand-file-name arg)))
330 (insert "', -*-Text-*-\n")))
331 ;; Else no `@setfilename' line
333 texinfo-region-buffer-name
334 " buffer -*-Text-*-\n"))
335 (insert "produced by `texinfo-format-region'\n"
337 (if (buffer-file-name input-buffer)
339 (file-name-sans-versions
340 (file-name-nondirectory
341 (buffer-file-name input-buffer)))
343 (concat "buffer `" (buffer-name input-buffer) "'"))
344 "\nusing `texinfmt.el' version "
348 ;; Now convert for real.
349 (goto-char (point-min))
350 (texinfo-format-scan)
351 (goto-char (point-min))
352 (Info-tagify input-buffer)
353 (goto-char (point-min))
357 (defun texi2info (&optional nosplit)
358 "Convert the current buffer (written in Texinfo code) into an Info file.
359 The Info file output is generated in a buffer visiting the Info file
360 names specified in the @setfilename command.
362 This function automatically updates all node pointers and menus, and
363 creates a master menu. This work is done on a temporary buffer that
364 is automatically removed when the Info file is created. The original
365 Texinfo source buffer is not changed.
367 Non-nil argument (prefix, if interactive) means don't split the file
368 if large. You can use Info-split to do this manually."
370 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" )))
371 (message "First updating nodes and menus, then creating Info file.")
373 (copy-to-buffer temp-buffer (point-min) (point-max))
374 (switch-to-buffer temp-buffer)
375 (texinfo-master-menu t)
376 (message "Now creating Info file.")
378 (texinfo-format-buffer nosplit)
380 (kill-buffer temp-buffer)))
383 ;;; Primary internal formatting function for the whole buffer.
385 (defun texinfo-format-buffer-1 ()
386 (let (texinfo-format-filename
387 texinfo-example-start
388 texinfo-command-start
392 texinfo-last-node-pos
401 (texinfo-footnote-number 0)
404 (fill-column-for-info fill-column)
405 (input-buffer (current-buffer))
406 (input-directory default-directory))
407 (setq texinfo-enclosure-list nil)
408 (setq texinfo-alias-list nil)
410 (goto-char (point-min))
411 (or (search-forward "@setfilename" nil t)
412 (error "Texinfo file needs an `@setfilename FILENAME' line"))
413 (setq texinfo-command-end (point))
414 (setq outfile (texinfo-parse-line-arg)))
419 (buffer-disable-undo)
421 (message "Formatting Info file: %s" outfile)
422 (setq texinfo-format-filename
423 (file-name-nondirectory (expand-file-name outfile)))
425 (setq fill-column fill-column-for-info)
426 (set-syntax-table texinfo-format-syntax-table)
428 (insert-buffer-substring input-buffer)
429 (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
430 (message "Converting %s to Info format..." (buffer-name input-buffer))
432 ;; Insert @include files so `texinfo-raise-lower-sections' can
433 ;; work on them without losing track of multiple
434 ;; @raise/@lowersections commands.
435 (goto-char (point-min))
437 ;; Remove trailing WS like makeinfo does
439 ;;; (unless (equal texinfo-paragraph-indent "asis")
441 (message "Removing trailing whitespace from Info buffer...")
442 (while (re-search-forward "[ \t]+$" nil t)
443 (replace-match "" nil nil)))
445 (while (re-search-forward "^@include" nil t)
446 (setq texinfo-command-end (point))
447 (let ((filename (concat input-directory
448 (texinfo-parse-line-arg))))
449 (re-search-backward "^@include")
450 (delete-region (point) (point-at-bol 2))
451 (message "Reading included file: %s" filename)
456 (+ (point) (car (cdr (insert-file-contents filename)))))
457 (goto-char (point-min))
458 ;; Remove `@setfilename' line from included file, if any,
459 ;; so @setfilename command not duplicated.
460 (if (re-search-forward "^@setfilename" (point-at-eol 100) t)
461 (delete-region (point-at-bol 1)
462 (point-at-bol 2)))))))
463 ;; Raise or lower level of each section, if necessary.
464 (goto-char (point-min))
465 (texinfo-raise-lower-sections)
466 ;; Append @refill to appropriate paragraphs
467 (goto-char (point-min))
468 (texinfo-append-refill)
469 (goto-char (point-min))
470 (search-forward "@setfilename")
472 (delete-region (point-min) (point))
473 ;; Remove @bye at end of file, if it is there.
474 (goto-char (point-max))
475 (if (search-backward "@bye" nil t)
476 (delete-region (point) (point-max)))
477 ;; Make sure buffer ends in a newline.
478 (or (= (preceding-char) ?\n)
480 ;; Scan the whole buffer, converting to Info format.
481 (texinfo-format-scan)
482 (goto-char (point-min))
483 ;; Insert info about how this file was made.
484 (insert "Info file: "
485 texinfo-format-filename ", -*-Text-*-\n"
486 "produced by `texinfo-format-buffer'\n"
487 ;; Date string removed so that regression testing is easier.
489 ;; (insert (format-time-string "%e %b %Y")) " "
491 (if (buffer-file-name input-buffer)
493 (file-name-sans-versions
494 (file-name-nondirectory
495 (buffer-file-name input-buffer)))
497 (concat "buffer `" (buffer-name input-buffer) "'"))
498 "\nusing `texinfmt.el' version "
501 ;; Return data for indices.
503 texinfo-vindex texinfo-findex texinfo-cindex
504 texinfo-pindex texinfo-tindex texinfo-kindex)))
507 ;;; Perform non-@-command file conversions: quotes and hyphens
509 (defun texinfo-format-convert (min max)
510 ;; Convert left and right quotes to typewriter font quotes.
512 (while (search-forward "``" max t)
513 (replace-match "\""))
515 (while (search-forward "''" max t)
516 (replace-match "\""))
517 ;; Convert three hyphens in a row to two.
520 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\|\n\\)" max t)
521 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning 2)))))
524 ;;; Handle paragraph filling
526 ;; Keep as concatinated lists for ease of maintenance
528 (defvar texinfo-no-refill-regexp
532 ;; add "itemize\\|" (from experiment of 2001 Nov 28)
533 ;; because of a problem with @end itemize@refill
534 ;; I don't know if this causes other problems.
535 ;; I suspect itemized lists don't get filled properly and a
536 ;; more precise fix is required. Bob
557 "Regexp specifying environments in which paragraphs are not filled.")
559 (defvar texinfo-accent-commands
592 (defvar texinfo-part-of-para-regexp
630 "@-\\|" ; @- is a descretionary hyphen (not an accent) (a noop).
631 texinfo-accent-commands
634 "Regexp specifying @-commands found within paragraphs.")
636 (defun texinfo-append-refill ()
637 "Append @refill at end of each paragraph that should be filled.
638 Do not append @refill to paragraphs within @example and similar environments.
639 Do not append @refill to paragraphs containing @w{TEXT} or @*."
641 ;; It is necessary to append @refill before other processing because
642 ;; the other processing removes information that tells Texinfo
643 ;; whether the text should or should not be filled.
645 (while (< (point) (point-max))
646 (let ((refill-blank-lines "^[ \t\n]*$")
647 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
649 ;; 1. Skip over blank lines;
650 ;; skip over lines beginning with @-commands,
651 ;; but do not skip over lines
652 ;; that are no-refill environments such as @example or
653 ;; that begin with within-paragraph @-commands such as @code.
654 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
658 texinfo-no-refill-regexp
660 texinfo-part-of-para-regexp
662 (< (point) (point-max)))
664 ;; 2. Skip over @example and similar no-refill environments.
665 (if (looking-at texinfo-no-refill-regexp)
666 (let ((environment (match-string-no-properties 1)))
667 (progn (re-search-forward (concat "^@end " environment) nil t)
670 ;; 3. Do not refill a paragraph containing @w or @*, or ending
671 ;; with @<newline> followed by a newline.
672 (if (or (>= (point) (point-max))
675 (save-excursion (forward-paragraph) (forward-line 1) (point))
677 ;; Go to end of paragraph and do nothing.
679 ;; 4. Else go to end of paragraph and insert @refill
682 (let ((line-beg (point)))
686 (save-excursion (skip-chars-backward " \t") (point)))
688 (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t)
690 (unless (re-search-backward "@refill\\|^[ \t]*@" line-beg t)
692 (forward-line 1))))))
695 ;;; Handle `@raisesections' and `@lowersections' commands
697 ;; These commands change the hierarchical level of chapter structuring
700 ;; @raisesections changes @subsection to @section,
701 ;; @section to @chapter,
704 ;; @lowersections changes @chapter to @section
705 ;; @subsection to @subsubsection,
708 ;; An @raisesections/@lowersections command changes only those
709 ;; structuring commands that follow the @raisesections/@lowersections
712 ;; Repeated @raisesections/@lowersections continue to raise or lower
713 ;; the heading level.
715 ;; An @lowersections command cancels an @raisesections command, and
718 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
719 ;; trying to do so does not elicit an error---you just get more
720 ;; headings that mean the same thing as you keep raising or lowering
721 ;; (for example, after a single @raisesections, both @chapter and
722 ;; @section produce chapter headings).
724 (defun texinfo-raise-lower-sections ()
725 "Raise or lower the hierarchical level of chapters, sections, etc.
727 This function acts according to `@raisesections' and `@lowersections'
728 commands in the Texinfo file.
730 For example, an `@lowersections' command is useful if you wish to
731 include what is written as an outer or standalone Texinfo file in
732 another Texinfo file as an inner, included file. The `@lowersections'
733 command changes chapters to sections, sections to subsections and so
736 @raisesections changes @subsection to @section,
737 @section to @chapter,
738 @heading to @chapheading,
741 @lowersections changes @chapter to @section,
742 @subsection to @subsubsection,
743 @heading to @subheading,
746 An `@raisesections' or `@lowersections' command changes only those
747 structuring commands that follow the `@raisesections' or
748 `@lowersections' command.
750 An `@lowersections' command cancels an `@raisesections' command, and
753 Repeated use of the commands continue to raise or lower the hierarchical
754 level a step at a time.
756 An attempt to raise above `chapters' reproduces chapter commands; an
757 attempt to lower below subsubsections reproduces subsubsection
760 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
761 ;; it is a regexp matching chapter, section, other headings
762 ;; (but not the top node).
764 (let (type (level 0))
768 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
769 texinfo-section-types-regexp
773 (save-excursion (setq type (read (current-buffer))))
776 ;; 1. Increment level
777 ((eq type '@raisesections)
778 (setq level (1+ level))
780 (point) (save-excursion (forward-line 1) (point))))
782 ;; 2. Decrement level
783 ((eq type '@lowersections)
784 (setq level (1- level))
786 (point) (save-excursion (forward-line 1) (point))))
788 ;; Now handle structuring commands
791 ;; 3. Raise level when positive
797 (cdr (assq new-level texinfo-raisesections-alist)))
798 (setq count (1- count)))
800 (insert (symbol-name new-level))))
802 ;; 4. Do nothing except move point when level is zero
803 ((= level 0) (forward-line 1))
805 ;; 5. Lower level when positive
811 (cdr (assq new-level texinfo-lowersections-alist)))
812 (setq count (1+ count)))
814 (insert (symbol-name new-level))))))))))
816 (defvar texinfo-raisesections-alist
817 '((@chapter . @chapter) ; Cannot go higher
818 (@unnumbered . @unnumbered)
819 (@centerchap . @unnumbered)
821 (@majorheading . @majorheading)
822 (@chapheading . @chapheading)
823 (@appendix . @appendix)
825 (@section . @chapter)
826 (@unnumberedsec . @unnumbered)
827 (@heading . @chapheading)
828 (@appendixsec . @appendix)
830 (@subsection . @section)
831 (@unnumberedsubsec . @unnumberedsec)
832 (@subheading . @heading)
833 (@appendixsubsec . @appendixsec)
835 (@subsubsection . @subsection)
836 (@unnumberedsubsubsec . @unnumberedsubsec)
837 (@subsubheading . @subheading)
838 (@appendixsubsubsec . @appendixsubsec))
839 "*An alist of next higher levels for chapters, sections. etc.
840 For example, section to chapter, subsection to section.
841 Used by `texinfo-raise-lower-sections'.
842 The keys specify types of section; the values correspond to the next
845 (defvar texinfo-lowersections-alist
846 '((@chapter . @section)
847 (@unnumbered . @unnumberedsec)
848 (@centerchap . @unnumberedsec)
849 (@majorheading . @heading)
850 (@chapheading . @heading)
851 (@appendix . @appendixsec)
853 (@section . @subsection)
854 (@unnumberedsec . @unnumberedsubsec)
855 (@heading . @subheading)
856 (@appendixsec . @appendixsubsec)
858 (@subsection . @subsubsection)
859 (@unnumberedsubsec . @unnumberedsubsubsec)
860 (@subheading . @subsubheading)
861 (@appendixsubsec . @appendixsubsubsec)
863 (@subsubsection . @subsubsection) ; Cannot go lower.
864 (@unnumberedsubsubsec . @unnumberedsubsubsec)
865 (@subsubheading . @subsubheading)
866 (@appendixsubsubsec . @appendixsubsubsec))
867 "*An alist of next lower levels for chapters, sections. etc.
868 For example, chapter to section, section to subsection.
869 Used by `texinfo-raise-lower-sections'.
870 The keys specify types of section; the values correspond to the next
874 ;;; Perform those texinfo-to-info conversions that apply to the whole input
877 (defun texinfo-format-scan ()
878 (texinfo-format-convert (point-min) (point-max))
879 ;; Search for @copying, which has to be first since the
880 ;; @insertcopying command then inserts the text elsewhere.
881 (goto-char (point-min))
882 (when (search-forward "@copying" nil t)
884 (while (search-forward "@insertcopying" nil t)
885 (delete-region (match-beginning 0) (match-end 0))
887 (texinfo-insertcopying))
888 ;; Scan for other @-commands.
889 (goto-char (point-min))
890 (while (search-forward "@" nil t)
892 ;; These are the single-character accent commands: @^ @` @' @" @= @~
893 ;; In Info, they are simply quoted and the @ deleted.
894 ;; Other single-character commands:
895 ;; @* forces a line break,
896 ;; @- is a discretionary hyphenation point; does nothing in Info.
897 ;; @<space>, @<tab>, @<newline> each produce a single space,
898 ;; unless followed by a newline.
900 ;; Old version 2.34 expression: (looking-at "[@{}^'` *\"?!]")
901 (if (looking-at "[@{}^'`\"=~ \t\n*?!-]")
902 ;; @*, causes a line break.
905 ((= (following-char) ?*)
907 (delete-region (1- (point)) (1+ (point)))
908 ;; insert return if not at end of line;
909 ;; else line is already broken.
910 (if (not (= (following-char) ?\n))
913 ((= (following-char) ?-)
914 (delete-region (1- (point)) (1+ (point))))
915 ;; @<space>, @<tab>, @<newline>: produce a single space,
916 ;; unless followed by a newline.
917 ((= (following-char) ? )
918 (delete-region (1- (point)) (1+ (point)))
919 ;; insert single space if not at end of line;
920 ;; else line is already broken.
921 (if (not (= (following-char) ?\n))
923 ((= (following-char) ?\t)
924 (delete-region (1- (point)) (1+ (point)))
925 ;; insert single space if not at end of line;
926 ;; else line is already broken.
927 (if (not (= (following-char) ?\n))
929 ;; following char is a carriage return
930 ((= (following-char) ?\n)
932 (delete-region (1- (point)) (1+ (point)))
933 ;; insert single space if not at end of line;
934 ;; else line is already broken.
935 (if (not (= (following-char) ?\n))
937 ;; Otherwise: the other characters are simply quoted. Delete the @.
940 ;; Be compatible with makeinfo: if @' and its ilk are
941 ;; followed by a @ without a brace, barf.
942 (if (looking-at "[\"'^`~=]")
944 (if (= (char-after (1+ (point))) ?@)
945 (error "Use braces to give a command as an argument to @%c"
948 ;; @' etc. can optionally accept their argument in
949 ;; braces (makeinfo supports that).
950 (when (looking-at "{")
951 (let ((start (point)))
957 ;; @ is followed by a command-word; find the end of the word.
958 (setq texinfo-command-start (1- (point)))
959 (if (= (char-syntax (following-char)) ?w)
962 (setq texinfo-command-end (point))
963 ;; Detect the case of two @-commands in a row;
964 ;; process just the first one.
965 (goto-char (1+ texinfo-command-start))
966 (skip-chars-forward "^@" texinfo-command-end)
967 (setq texinfo-command-end (point))
968 ;; Handle let aliasing
969 (setq texinfo-command-name
972 (buffer-substring-no-properties
973 (1+ texinfo-command-start) texinfo-command-end)))
974 (while (setq trial (assoc cmdname texinfo-alias-list))
975 (setq cmdname (cdr trial)))
977 ;; Call the handler for this command.
978 (let ((enclosure-type
980 (symbol-name texinfo-command-name)
981 texinfo-enclosure-list)))
985 (car (car (cdr enclosure-type)))
986 (texinfo-parse-arg-discard)
987 (car (cdr (car (cdr enclosure-type)))))
988 (goto-char texinfo-command-start))
989 (let ((cmd (get texinfo-command-name 'texinfo-format)))
990 (if cmd (funcall cmd) (texinfo-unsupported)))))))
993 (goto-char (nth 2 (car texinfo-stack)))
994 (error "Unterminated @%s" (car (car texinfo-stack)))))
996 ;; Remove excess whitespace
997 (let ((whitespace-silent t))
998 (whitespace-cleanup)))
1000 (defvar texinfo-copying-text ""
1001 "Text of the copyright notice and copying permissions.")
1003 (defun texinfo-copying ()
1004 "Copy the copyright notice and copying permissions from the Texinfo file,
1005 as indicated by the @copying ... @end copying command;
1006 insert the text with the @insertcopying command."
1007 (let ((beg (progn (beginning-of-line) (point)))
1008 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
1009 (setq texinfo-copying-text
1010 (buffer-substring-no-properties
1011 (save-excursion (goto-char beg) (forward-line 1) (point))
1012 (save-excursion (goto-char end) (forward-line -1) (point))))
1013 (delete-region beg end)))
1015 (defun texinfo-insertcopying ()
1016 "Insert the copyright notice and copying permissions from the Texinfo file,
1017 which are indicated by the @copying ... @end copying command."
1018 (insert (concat "\n" texinfo-copying-text)))
1020 (put 'begin 'texinfo-format 'texinfo-format-begin)
1021 (defun texinfo-format-begin ()
1022 (texinfo-format-begin-end 'texinfo-format))
1024 (put 'end 'texinfo-format 'texinfo-format-end)
1025 (defun texinfo-format-end ()
1026 (texinfo-format-begin-end 'texinfo-end))
1028 (defun texinfo-format-begin-end (prop)
1029 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
1030 (let ((cmd (get texinfo-command-name prop)))
1031 (if cmd (funcall cmd)
1032 (texinfo-unsupported))))
1034 ;;; Parsing functions
1036 (defun texinfo-parse-line-arg ()
1037 "Return argument of @-command as string.
1038 Argument is separated from command either by a space or by a brace.
1039 If a space, return rest of line, with beginning and ending white
1040 space removed. If a brace, return string between braces.
1041 Leave point after argument."
1042 (goto-char texinfo-command-end)
1043 (let ((start (point)))
1044 (cond ((looking-at " ")
1045 (skip-chars-forward " ")
1046 (setq start (point))
1048 (skip-chars-backward " ")
1049 (delete-region (point) (progn (end-of-line) (point)))
1050 (setq texinfo-command-end (1+ (point))))
1052 (setq start (1+ (point)))
1054 (setq texinfo-command-end (point))
1057 (error "Invalid texinfo command arg format")))
1058 (prog1 (buffer-substring-no-properties start (point))
1059 (if (eolp) (forward-char 1)))))
1061 (defun texinfo-parse-expanded-arg ()
1062 (goto-char texinfo-command-end)
1063 (let ((start (point))
1065 (cond ((looking-at " ")
1066 (skip-chars-forward " ")
1067 (setq start (point))
1069 (setq texinfo-command-end (1+ (point))))
1071 (setq start (1+ (point)))
1073 (setq texinfo-command-end (point))
1076 (error "Invalid texinfo command arg format")))
1077 (setq marker (move-marker (make-marker) texinfo-command-end))
1078 (texinfo-format-expand-region start (point))
1079 (setq texinfo-command-end (marker-position marker))
1080 (move-marker marker nil)
1081 (prog1 (buffer-substring-no-properties start (point))
1082 (if (eolp) (forward-char 1)))))
1084 (defun texinfo-format-expand-region (start end)
1086 (narrow-to-region start end)
1087 (let (texinfo-command-start
1089 texinfo-command-name
1091 (texinfo-format-scan))
1092 (goto-char (point-max))))
1094 (defun texinfo-parse-arg-discard ()
1095 "Delete command and argument; return argument of command."
1096 (prog1 (texinfo-parse-line-arg)
1097 (texinfo-discard-command)))
1099 (defun texinfo-discard-command ()
1100 (delete-region texinfo-command-start texinfo-command-end))
1102 (defun texinfo-optional-braces-discard ()
1103 "Discard braces following command, if any."
1104 (goto-char texinfo-command-end)
1105 (let ((start (point)))
1106 (cond ((looking-at "[ \t]*\n")) ; do nothing
1107 ((looking-at "{") ; remove braces, if any
1109 (setq texinfo-command-end (point)))
1112 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
1113 (delete-region texinfo-command-start texinfo-command-end)))
1115 (defun texinfo-format-parse-line-args ()
1116 (let ((start (1- (point)))
1119 (skip-chars-forward " ")
1122 (re-search-forward "[\n,]")
1124 (if (bolp) (setq next (1- next)))
1126 (skip-chars-backward " ")
1128 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end))
1131 (skip-chars-forward " "))
1132 (if (eolp) (forward-char 1))
1133 (setq texinfo-command-end (point))
1136 (defun texinfo-format-parse-args ()
1137 (let ((start (1- (point)))
1140 (search-forward "{")
1142 (texinfo-format-expand-region
1144 (save-excursion (up-list 1) (1- (point)))))
1145 ;; The following does not handle cross references of the form:
1146 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
1147 ;; re-search-forward finds the first right brace after the second
1149 (while (/= (preceding-char) ?\})
1150 (skip-chars-forward " \t\n")
1152 (re-search-forward "[},]")
1155 (skip-chars-backward " \t\n")
1159 (while (search-forward "\n" end t)
1160 (replace-match " "))))
1161 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end))
1164 ;;(if (eolp) (forward-char 1))
1165 (setq texinfo-command-end (point))
1168 (defun texinfo-format-parse-defun-args ()
1169 (goto-char texinfo-command-end)
1170 (let ((start (point)))
1172 (setq texinfo-command-end (1+ (point)))
1173 (let ((marker (move-marker (make-marker) texinfo-command-end)))
1174 (texinfo-format-expand-region start (point))
1175 (setq texinfo-command-end (marker-position marker))
1176 (move-marker marker nil))
1180 (skip-chars-forward " ")
1182 (cond ((looking-at "{")
1183 (setq beg (1+ (point)))
1185 (setq end (1- (point))))
1188 (re-search-forward "[\n ]")
1190 (setq end (point))))
1191 (setq args (cons (buffer-substring-no-properties beg end) args))
1192 (skip-chars-forward " "))
1196 (defun texinfo-discard-line ()
1197 (goto-char texinfo-command-end)
1198 (skip-chars-forward " \t")
1200 (error "Extraneous text at end of command line"))
1201 (goto-char texinfo-command-start)
1203 (error "Extraneous text at beginning of command line"))
1204 (delete-region (point) (progn (forward-line 1) (point))))
1206 (defun texinfo-discard-line-with-args ()
1207 (goto-char texinfo-command-start)
1208 (delete-region (point) (progn (forward-line 1) (point))))
1213 ;; Only `texinfo-format-buffer' handles @setfilename with this
1214 ;; definition; `texinfo-format-region' handles @setfilename, if any,
1216 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
1217 (defun texinfo-format-setfilename ()
1218 (texinfo-parse-arg-discard))
1220 ;;; @node, @menu, @detailmenu
1222 (put 'node 'texinfo-format 'texinfo-format-node)
1223 (put 'nwnode 'texinfo-format 'texinfo-format-node)
1224 (defun texinfo-format-node ()
1225 (let* ((args (texinfo-format-parse-line-args))
1230 (texinfo-discard-command)
1231 (setq texinfo-last-node name)
1232 (let ((tem (if texinfo-fold-nodename-case (downcase name) name)))
1233 (if (assoc tem texinfo-node-names)
1234 (error "Duplicate node name: %s" name)
1235 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
1236 (setq texinfo-footnote-number 0)
1237 ;; insert "\n\^_" unconditionally since this is what info is looking for
1238 (insert "\n\^_\nFile: " texinfo-format-filename
1241 (insert ", Next: " next))
1243 (insert ", Prev: " prev))
1245 (insert ", Up: " up))
1247 (setq texinfo-last-node-pos (point))))
1249 (put 'anchor 'texinfo-format 'texinfo-anchor)
1250 (defun texinfo-anchor ()
1252 (here (- (point) 7)) ; save location of beginning of `@anchor'
1253 (arg (texinfo-parse-arg-discard)))
1254 (if (looking-at " ") ; since a space may be left after -discard
1257 (let ((end (point)))
1260 (search-forward "@refill" end t))
1261 (setq anchor-string "@anchor-yes-refill")
1262 (setq anchor-string "@anchor-no-refill")))
1264 (insert anchor-string "{" arg "}")))
1266 (put 'menu 'texinfo-format 'texinfo-format-menu)
1267 (defun texinfo-format-menu ()
1268 (texinfo-discard-line)
1269 (insert "* Menu:\n\n"))
1271 (put 'menu 'texinfo-end 'texinfo-discard-command)
1273 ;; The @detailmenu should be removed eventually.
1275 ;; According to Karl Berry, 31 August 1996:
1277 ;; You don't like, I don't like it. I agree, it would be better just to
1278 ;; fix the bug [in `makeinfo']. .. At this point, since inserting those
1279 ;; two commands in the Elisp fn is trivial, I don't especially want to
1280 ;; expend more effort...
1282 ;; I added a couple sentences of documentation to the manual (putting the
1283 ;; blame on makeinfo where it belongs :-().
1285 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
1286 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
1288 ;; (Also see `texnfo-upd.el')
1291 ;;; Cross references
1293 ;; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
1294 ;; -> *Note FNAME: (FILE)NODE
1295 ;; If FILE is missing,
1296 ;; *Note FNAME: NODE
1297 ;; If FNAME is empty and NAME is present
1299 ;; If both NAME and FNAME are missing
1301 ;; texinfo ignores the DOCUMENT argument.
1302 ;; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1303 ;; If FILE is specified, (FILE)NODE is used for xrefs.
1304 ;; If fifth argument DOCUMENT is specified, produces
1305 ;; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1308 ;; @ref a reference that does not put `See' or `see' in
1309 ;; the hardcopy and is the same as @xref in Info
1310 (put 'ref 'texinfo-format 'texinfo-format-xref)
1312 (put 'xref 'texinfo-format 'texinfo-format-xref)
1313 (defun texinfo-format-xref ()
1314 (let ((args (texinfo-format-parse-args)))
1315 (texinfo-discard-command)
1317 (let ((fname (or (nth 1 args) (nth 2 args))))
1318 (if (null (or fname (nth 3 args)))
1319 (insert (car args) "::")
1320 (insert (or fname (car args)) ": ")
1322 (insert "(" (nth 3 args) ")"))
1323 (and (car args) (insert (car args)))))))
1325 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
1326 (defun texinfo-format-pxref ()
1327 (texinfo-format-xref)
1333 ;; @inforef{NODE, FNAME, FILE}
1334 ;; Like @xref{NODE, FNAME,,FILE} in texinfo.
1335 ;; In Tex, generates "See Info file FILE, node NODE"
1336 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
1337 (defun texinfo-format-inforef ()
1338 (let ((args (texinfo-format-parse-args)))
1339 (texinfo-discard-command)
1341 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
1342 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
1345 ;;; URL Reference: @uref
1347 ;; @uref produces a reference to a uniform resource locator (URL).
1348 ;; It takes one mandatory argument, the URL, and one optional argument,
1349 ;; the text to display (the default is the URL itself).
1351 (put 'uref 'texinfo-format 'texinfo-format-uref)
1352 (defun texinfo-format-uref ()
1353 "Format URL and optional URL-TITLE.
1354 Insert ` ... ' around URL if no URL-TITLE argument;
1355 otherwise, insert URL-TITLE followed by URL in parentheses."
1356 (let ((args (texinfo-format-parse-args)))
1357 (texinfo-discard-command)
1360 (insert (nth 1 args) " (" (nth 0 args) ")")
1361 (insert "`" (nth 0 args) "'"))
1363 ;; No need to parse argument. It's already expanded by
1364 ;; texinfo-format-parse-args.
1365 ;; (goto-char texinfo-command-start)
1369 ;;; Section headings
1371 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
1372 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
1373 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
1374 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
1375 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1376 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1377 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1378 (put 'top 'texinfo-format 'texinfo-format-chapter)
1379 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1380 (put 'centerchap 'texinfo-format 'texinfo-format-chapter)
1381 (defun texinfo-format-chapter ()
1382 (texinfo-format-chapter-1 ?*))
1384 (put 'heading 'texinfo-format 'texinfo-format-section)
1385 (put 'isection 'texinfo-format 'texinfo-format-section)
1386 (put 'section 'texinfo-format 'texinfo-format-section)
1387 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1388 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1389 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1390 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1391 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1392 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1393 (defun texinfo-format-section ()
1394 (texinfo-format-chapter-1 ?=))
1396 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1397 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1398 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1399 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1400 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1401 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1402 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1403 (defun texinfo-format-subsection ()
1404 (texinfo-format-chapter-1 ?-))
1406 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1407 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1408 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1409 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1410 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1411 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1412 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1413 (defun texinfo-format-subsubsection ()
1414 (texinfo-format-chapter-1 ?.))
1416 (defun texinfo-format-chapter-1 (belowchar)
1417 (let ((arg (texinfo-parse-arg-discard)))
1418 (message "Formatting: %s ... " arg) ; So we can see where we are.
1419 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1422 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1423 (defun texinfo-format-sectionpad ()
1424 (let ((str (texinfo-parse-arg-discard)))
1426 (let ((column (current-column)))
1430 (setq column (1- column))))
1434 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1436 (put '\. 'texinfo-format 'texinfo-format-\.)
1437 (defun texinfo-format-\. ()
1438 (texinfo-discard-command)
1441 (put '\: 'texinfo-format 'texinfo-format-\:)
1442 (defun texinfo-format-\: ()
1443 (texinfo-discard-command))
1445 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
1446 (defun texinfo-format-soft-hyphen ()
1447 (texinfo-discard-command))
1450 ;;; @kbdinputstyle, @vskip, headings & footings
1451 ;; These commands for not for Info and should never
1452 ;; appear in an Info environment; but if they do,
1453 ;; this causes them to be discarded.
1456 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
1459 (put 'vskip 'texinfo-format 'texinfo-discard-line-with-args)
1461 ;; headings & footings
1462 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
1463 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
1464 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
1465 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
1466 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
1467 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
1470 ;;; @documentdescription ... @end documentdescription
1471 ;; This command is for HTML output and should never
1472 ;; appear in an Info environment; but if it does,
1473 ;; this causes it to be discarded.
1475 (put 'documentdescription 'texinfo-format 'texinfo-format-documentdescription)
1476 (defun texinfo-format-documentdescription ()
1477 (delete-region texinfo-command-start
1478 (progn (re-search-forward "^@end documentdescription[ \t]*\n")
1483 ;;; @center, @sp, and @br
1485 (put 'center 'texinfo-format 'texinfo-format-center)
1486 (defun texinfo-format-center ()
1487 (let ((arg (texinfo-parse-expanded-arg)))
1488 (texinfo-discard-command)
1492 (goto-char (1- (point)))
1493 (let ((indent-tabs-mode nil))
1496 (put 'sp 'texinfo-format 'texinfo-format-sp)
1497 (defun texinfo-format-sp ()
1498 (let* ((arg (texinfo-parse-arg-discard))
1500 (insert-char ?\n num)))
1502 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1503 (defun texinfo-format-paragraph-break ()
1504 "Force a paragraph break.
1505 If used within a line, follow `@br' with braces."
1506 (texinfo-optional-braces-discard)
1507 ;; insert one return if at end of line;
1508 ;; else insert two returns, to generate a blank line.
1509 (if (= (following-char) ?\n)
1511 (insert-char ?\n 2)))
1514 ;;; @footnote and @footnotestyle
1516 ;; In Texinfo, footnotes are created with the `@footnote' command.
1517 ;; This command is followed immediately by a left brace, then by the text of
1518 ;; the footnote, and then by a terminating right brace. The
1519 ;; template for a footnote is:
1523 ;; Info has two footnote styles:
1525 ;; * In the End of node style, all the footnotes for a single node
1526 ;; are placed at the end of that node. The footnotes are
1527 ;; separated from the rest of the node by a line of dashes with
1528 ;; the word `Footnotes' within it.
1530 ;; * In the Separate node style, all the footnotes for a single node
1531 ;; are placed in an automatically constructed node of their own.
1533 ;; Footnote style is specified by the @footnotestyle command, either
1534 ;; @footnotestyle separate
1536 ;; @footnotestyle end
1538 ;; The default is separate
1540 (defvar texinfo-footnote-style "separate"
1541 "Footnote style, either separate or end.")
1543 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1544 (defun texinfo-footnotestyle ()
1545 "Specify whether footnotes are at end of node or in separate nodes.
1546 Argument is either end or separate."
1547 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1549 (defvar texinfo-footnote-number)
1551 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1552 (defun texinfo-format-footnote ()
1553 "Format a footnote in either end of node or separate node style.
1554 The texinfo-footnote-style variable controls which style is used."
1555 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1556 (cond ((string= texinfo-footnote-style "end")
1557 (texinfo-format-end-node))
1558 ((string= texinfo-footnote-style "separate")
1559 (texinfo-format-separate-node))))
1561 (defun texinfo-format-separate-node ()
1562 "Format footnote in Separate node style, with notes in own node.
1563 The node is constructed automatically."
1565 (arg (texinfo-parse-line-arg))
1566 (node-name-beginning
1569 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1573 (buffer-substring-no-properties
1574 (progn (goto-char node-name-beginning) ; skip over node command
1575 (skip-chars-forward " \t") ; and over spaces
1579 (save-excursion (end-of-line) (point)) t) ; bound search
1581 (end-of-line) (point))))))
1582 (texinfo-discard-command) ; remove or insert whitespace, as needed
1583 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1585 (insert (format " (%d) (*Note %s-Footnotes::)"
1586 texinfo-footnote-number node-name))
1587 (fill-paragraph nil)
1589 (if (re-search-forward "^@node" nil 'move)
1592 ;; two cases: for the first footnote, we must insert a node header;
1593 ;; for the second and subsequent footnotes, we need only insert
1594 ;; the text of the footnote.
1598 (concat node-name "-Footnotes, Up: ")
1601 (progn ; already at least one footnote
1602 (setq start (point))
1603 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1604 (fill-region start (point)))
1605 ;; else not yet a footnote
1606 (insert "\n\^_\nFile: " texinfo-format-filename
1607 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1608 (setq start (point))
1609 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1610 (fill-region start (point))))))
1612 (defun texinfo-format-end-node ()
1613 "Format footnote in the End of node style, with notes at end of node."
1615 (arg (texinfo-parse-line-arg)))
1616 (texinfo-discard-command) ; remove or insert whitespace, as needed
1617 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1619 (insert (format " (%d) " texinfo-footnote-number))
1620 (fill-paragraph nil)
1622 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1623 (progn ; already have footnote, put new one before end of node
1624 (if (re-search-forward "^@node" nil 'move)
1626 (setq start (point))
1627 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1628 (fill-region start (point)))
1629 ;; else no prior footnote
1630 (if (re-search-forward "^@node" nil 'move)
1632 (insert "\n--------- Footnotes ---------\n")
1633 (setq start (point))
1634 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1637 ;;; @itemize, @enumerate, and similar commands
1639 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1640 ;; @enumerate pushes (enumerate 0 STARTPOS).
1641 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1642 ;; For itemize, this puts in and rescans the COMMANDS.
1643 ;; For enumerate, this increments the number and puts it in.
1644 ;; In either case, it puts a Backspace at the front of the line
1645 ;; which marks it not to be indented later.
1646 ;; All other lines get indented by 5 when the @end is reached.
1648 (defvar texinfo-stack-depth 0
1649 "Count of number of unpopped texinfo-push-stack calls.
1650 Used by @refill indenting command to avoid indenting within lists, etc.")
1652 (defun texinfo-push-stack (check arg)
1653 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1655 (cons (list check arg texinfo-command-start)
1658 (defun texinfo-pop-stack (check)
1659 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1660 (if (null texinfo-stack)
1661 (error "Unmatched @end %s" check))
1662 (if (not (eq (car (car texinfo-stack)) check))
1663 (error "@end %s matches @%s"
1664 check (car (car texinfo-stack))))
1665 (prog1 (cdr (car texinfo-stack))
1666 (setq texinfo-stack (cdr texinfo-stack))))
1668 (put 'itemize 'texinfo-format 'texinfo-itemize)
1669 (defun texinfo-itemize ()
1672 (progn (skip-chars-forward " \t")
1675 (texinfo-parse-line-arg))))
1676 (texinfo-discard-line-with-args)
1677 (setq fill-column (- fill-column 5)))
1679 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1680 (defun texinfo-end-itemize ()
1681 (setq fill-column (+ fill-column 5))
1682 (texinfo-discard-command)
1684 (texinfo-pop-stack 'itemize)))
1685 (texinfo-do-itemize (nth 1 stacktop))))
1687 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1688 (defun texinfo-enumerate ()
1691 (progn (skip-chars-forward " \t")
1694 (read (current-buffer)))))
1695 (if (and (symbolp (car (cdr (car texinfo-stack))))
1696 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1698 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1699 (texinfo-discard-line-with-args)
1700 (setq fill-column (- fill-column 5)))
1702 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1703 (defun texinfo-end-enumerate ()
1704 (setq fill-column (+ fill-column 5))
1705 (texinfo-discard-command)
1707 (texinfo-pop-stack 'enumerate)))
1708 (texinfo-do-itemize (nth 1 stacktop))))
1710 ;; @alphaenumerate never became a standard part of Texinfo
1711 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1712 (defun texinfo-alphaenumerate ()
1713 (texinfo-push-stack 'alphaenumerate (1- ?a))
1714 (setq fill-column (- fill-column 5))
1715 (texinfo-discard-line))
1717 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1718 (defun texinfo-end-alphaenumerate ()
1719 (setq fill-column (+ fill-column 5))
1720 (texinfo-discard-command)
1722 (texinfo-pop-stack 'alphaenumerate)))
1723 (texinfo-do-itemize (nth 1 stacktop))))
1725 ;; @capsenumerate never became a standard part of Texinfo
1726 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1727 (defun texinfo-capsenumerate ()
1728 (texinfo-push-stack 'capsenumerate (1- ?A))
1729 (setq fill-column (- fill-column 5))
1730 (texinfo-discard-line))
1732 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1733 (defun texinfo-end-capsenumerate ()
1734 (setq fill-column (+ fill-column 5))
1735 (texinfo-discard-command)
1737 (texinfo-pop-stack 'capsenumerate)))
1738 (texinfo-do-itemize (nth 1 stacktop))))
1740 ;; At the @end, indent all the lines within the construct
1741 ;; except those marked with backspace. FROM says where
1742 ;; construct started.
1743 (defun texinfo-do-itemize (from)
1745 (while (progn (forward-line -1)
1747 (if (= (following-char) ?\b)
1752 (if (not (looking-at "[ \t]*$"))
1753 (save-excursion (insert " ")))))))
1755 (put 'item 'texinfo-format 'texinfo-item)
1756 (put 'itemx 'texinfo-format 'texinfo-item)
1757 (defun texinfo-item ()
1758 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1760 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1761 (defun texinfo-itemize-item ()
1762 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1763 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1764 (if (looking-at "[ \t]*[^ \t\n]+")
1765 ;; Text on same line as @item command.
1766 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1767 ;; Else text on next line.
1768 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1771 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1772 (defun texinfo-enumerate-item ()
1773 (texinfo-discard-line)
1774 (let (enumerating-symbol)
1775 (cond ((integerp (car (cdr (car texinfo-stack))))
1776 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1777 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1778 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1779 ((symbolp (car (cdr (car texinfo-stack))))
1780 (setq enumerating-symbol
1781 (symbol-name (car (cdr (car texinfo-stack)))))
1782 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1783 (equal ?\{ (string-to-char enumerating-symbol)))
1785 "Too many items in enumerated list; alphabet ends at Z."))
1786 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1787 (setcar (cdr (car texinfo-stack))
1791 (string-to-char enumerating-symbol))))))
1794 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1797 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1798 (defun texinfo-alphaenumerate-item ()
1799 (texinfo-discard-line)
1800 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1802 (error "More than 26 items in @alphaenumerate; get a bigger alphabet"))
1803 (setcar (cdr (car texinfo-stack)) next)
1804 (insert "\b " next ". \n"))
1807 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1808 (defun texinfo-capsenumerate-item ()
1809 (texinfo-discard-line)
1810 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1812 (error "More than 26 items in @capsenumerate; get a bigger alphabet"))
1813 (setcar (cdr (car texinfo-stack)) next)
1814 (insert "\b " next ". \n"))
1820 ;; The `@table' command produces two-column tables.
1822 (put 'table 'texinfo-format 'texinfo-table)
1823 (defun texinfo-table ()
1826 (progn (skip-chars-forward " \t")
1829 (texinfo-parse-line-arg))))
1830 (texinfo-discard-line-with-args)
1831 (setq fill-column (- fill-column 5)))
1833 (put 'table 'texinfo-item 'texinfo-table-item)
1834 (defun texinfo-table-item ()
1835 (let ((arg (texinfo-parse-arg-discard))
1836 (itemfont (car (cdr (car texinfo-stack)))))
1837 (insert ?\b itemfont ?\{ arg "}\n \n"))
1840 (put 'table 'texinfo-end 'texinfo-end-table)
1841 (defun texinfo-end-table ()
1842 (setq fill-column (+ fill-column 5))
1843 (texinfo-discard-command)
1845 (texinfo-pop-stack 'table)))
1846 (texinfo-do-itemize (nth 1 stacktop))))
1848 ;; @description appears to be an undocumented variant on @table that
1849 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1850 ;; part of makeinfo.c The command appears to be a relic of the past.
1851 (put 'description 'texinfo-end 'texinfo-end-table)
1852 (put 'description 'texinfo-format 'texinfo-description)
1853 (defun texinfo-description ()
1854 (texinfo-push-stack 'table "@asis")
1855 (setq fill-column (- fill-column 5))
1856 (texinfo-discard-line))
1859 ;;; @ftable, @vtable
1861 ;; The `@ftable' and `@vtable' commands are like the `@table' command
1862 ;; but they also insert each entry in the first column of the table
1863 ;; into the function or variable index.
1865 ;; Handle the @ftable and @vtable commands:
1867 (put 'ftable 'texinfo-format 'texinfo-ftable)
1868 (put 'vtable 'texinfo-format 'texinfo-vtable)
1870 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1871 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1873 (defun texinfo-indextable (table-type)
1874 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1875 (setq fill-column (- fill-column 5)))
1877 ;; Handle the @item commands within ftable and vtable:
1879 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1880 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1882 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1883 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1885 (defun texinfo-indextable-item (index-type)
1886 (let ((item (texinfo-parse-arg-discard))
1887 (itemfont (car (cdr (car texinfo-stack))))
1888 (indexvar index-type))
1889 (insert ?\b itemfont ?\{ item "}\n \n")
1892 (list item texinfo-last-node)
1893 (symbol-value indexvar)))
1896 ;; Handle @end ftable, @end vtable
1898 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1899 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1901 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1902 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1904 (defun texinfo-end-indextable (table-type)
1905 (setq fill-column (+ fill-column 5))
1906 (texinfo-discard-command)
1908 (texinfo-pop-stack table-type)))
1909 (texinfo-do-itemize (nth 1 stacktop))))
1912 ;;; @multitable ... @end multitable
1914 ;; Produce a multi-column table, with as many columns as desired.
1916 ;; A multi-column table has this template:
1918 ;; @multitable {A1} {A2} {A3}
1919 ;; @item A1 @tab A2 @tab A3
1920 ;; @item B1 @tab B2 @tab B3
1921 ;; @item C1 @tab C2 @tab C3
1924 ;; where the width of the text in brackets specifies the width of the
1925 ;; respective column.
1929 ;; @multitable @columnfractions .25 .3 .45
1930 ;; @item A1 @tab A2 @tab A3
1931 ;; @item B1 @tab B2 @tab B3
1934 ;; where the fractions specify the width of each column as a percent
1935 ;; of the current width of the text (i.e., of the fill-column).
1937 ;; Long lines of text are filled within columns.
1939 ;; Using the Emacs Lisp formatter, texinfmt.el,
1940 ;; the whitespace between columns can be increased by setting
1941 ;; `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1942 ;; there is at least one blank space between columns.
1944 ;; The Emacs Lisp formatter, texinfmt.el, ignores the following four
1945 ;; commands that are defined in texinfo.tex for printed output.
1947 ;; @multitableparskip,
1948 ;; @multitableparindent,
1949 ;; @multitablecolmargin,
1950 ;; @multitablelinespace.
1952 ;; How @multitable works.
1953 ;; =====================
1955 ;; `texinfo-multitable' reads the @multitable line and determines from it
1956 ;; how wide each column should be.
1958 ;; Also, it pushes this information, along with an identifying symbol,
1959 ;; onto the `texinfo-stack'. At the @end multitable command, the stack
1960 ;; is checked for its matching @multitable command, and then popped, or
1961 ;; else an error is signaled. Also, this command pushes the location of
1962 ;; the start of the table onto the stack.
1964 ;; `texinfo-end-multitable' checks the `texinfo-stack' that the @end
1965 ;; multitable truly is ending a corresponding beginning, and if it is,
1968 ;; `texinfo-multitable-widths' is called by `texinfo-multitable'.
1969 ;; The function returns a list of the widths of each column in a
1970 ;; multi-column table, based on the information supplied by the arguments
1971 ;; to the @multitable command (by arguments, I mean the text on the rest
1972 ;; of the @multitable line, not the remainder of the multi-column table
1975 ;; `texinfo-multitable-item' formats a row within a multicolumn table.
1976 ;; This command is executed when texinfmt sees @item inside @multitable.
1977 ;; Cells in row are separated by `@tab's. Widths of cells are specified
1978 ;; by the arguments in the @multitable line. Cells are filled. All cells
1979 ;; are made to be the same height by padding their bottoms, as needed,
1982 ;; `texinfo-multitable-extract-row' is called by `texinfo-multitable-item'.
1983 ;; This function returns the text in a multitable row, as a string.
1984 ;; The start of a row is marked by an @item and the end of row is the
1985 ;; beginning of next @item or beginning of the @end multitable line.
1986 ;; Cells within a row are separated by @tab.
1988 ;; Note that @tab, the cell separators, are not treated as independent
1989 ;; Texinfo commands.
1991 (defvar texinfo-extra-inter-column-width 0
1992 "*Number of extra spaces between entries (columns) in @multitable.")
1994 (defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
1995 (defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
1997 ;; These commands are defined in texinfo.tex for printed output.
1998 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
1999 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
2000 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
2001 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
2003 (put 'multitable 'texinfo-format 'texinfo-multitable)
2005 (defun texinfo-multitable ()
2006 "Produce multi-column tables.
2008 A multi-column table has this template:
2010 @multitable {A1} {A2} {A3}
2011 @item A1 @tab A2 @tab A3
2012 @item B1 @tab B2 @tab B3
2013 @item C1 @tab C2 @tab C3
2016 where the width of the text in brackets specifies the width of the
2021 @multitable @columnfractions .25 .3 .45
2022 @item A1 @tab A2 @tab A3
2023 @item B1 @tab B2 @tab B3
2026 where the fractions specify the width of each column as a percent
2027 of the current width of the text (i.e., of the fill-column).
2029 Long lines of text are filled within columns.
2031 Using the Emacs Lisp formatter, texinfmt.el,
2032 the whitespace between columns can be increased by setting
2033 `texinfo-extra-inter-column-width' to a value greater than 0. By default,
2034 there is at least one blank space between columns.
2036 The Emacs Lisp formatter, texinfmt.el, ignores the following four
2037 commands that are defined in texinfo.tex for printed output.
2040 @multitableparindent,
2041 @multitablecolmargin,
2042 @multitablelinespace."
2044 ;; This function pushes information onto the `texinfo-stack'.
2045 ;; A stack element consists of:
2046 ;; - type-of-command, i.e., multitable
2047 ;; - the information about column widths, and
2048 ;; - the position of texinfo-command-start.
2049 ;; e.g., ('multitable (1 2 3 4) 123)
2050 ;; The command line is then deleted.
2053 ;; push width information on stack
2054 (texinfo-multitable-widths))
2055 (texinfo-discard-line-with-args))
2057 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
2058 (defun texinfo-end-multitable ()
2059 "Discard the @end multitable line and pop the stack of multitable."
2060 (texinfo-discard-command)
2061 (texinfo-pop-stack 'multitable))
2063 (defun texinfo-multitable-widths ()
2064 "Return list of widths of each column in a multi-column table."
2065 (let (texinfo-multitable-width-list)
2066 ;; Fractions format:
2067 ;; @multitable @columnfractions .25 .3 .45
2070 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
2071 ;; Place point before first argument
2072 (skip-chars-forward " \t")
2074 ;; Check for common misspelling
2075 ((looking-at "@columnfraction ")
2076 (error "In @multitable, @columnfractions misspelled"))
2077 ;; Case 1: @columnfractions .25 .3 .45
2078 ((looking-at "@columnfractions")
2081 (setq texinfo-multitable-width-list
2085 (* fill-column (read (get-buffer (current-buffer))))))
2086 texinfo-multitable-width-list))))
2088 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
2090 (let ((start-of-templates (point)))
2092 (skip-chars-forward " \t")
2093 (let* ((start-of-template (1+ (point)))
2095 ;; forward-sexp works with braces in Texinfo mode
2096 (progn (forward-sexp 1) (1- (point)))))
2097 (setq texinfo-multitable-width-list
2098 (cons (- end-of-template start-of-template)
2099 texinfo-multitable-width-list))
2100 ;; Remove carriage return from within a template, if any.
2101 ;; This helps those those who want to use more than
2102 ;; one line's worth of words in @multitable line.
2103 (narrow-to-region start-of-template end-of-template)
2104 (goto-char (point-min))
2105 (while (search-forward "
2108 (goto-char (point-max))
2110 (forward-char 1)))))
2115 "You probably need to specify column widths for @multitable correctly.")))
2116 ;; Check whether columns fit on page.
2117 (let ((desired-columns
2119 ;; between column spaces
2120 (length texinfo-multitable-width-list)
2121 ;; additional between column spaces, if any
2122 texinfo-extra-inter-column-width
2123 ;; sum of spaces for each entry
2124 (apply '+ texinfo-multitable-width-list))))
2125 (if (> desired-columns fill-column)
2128 "Multi-column table width, %d chars, is greater than page width, %d chars."
2129 desired-columns fill-column))))
2130 texinfo-multitable-width-list))
2132 ;; @item A1 @tab A2 @tab A3
2133 (defun texinfo-multitable-extract-row ()
2134 "Return multitable row, as a string.
2135 End of row is beginning of next @item or beginning of @end.
2136 Cells within rows are separated by @tab."
2137 (skip-chars-forward " \t")
2138 (let* ((start (point))
2140 (re-search-forward "@item\\|@end")
2141 (match-beginning 0)))
2142 (row (progn (goto-char end)
2143 (skip-chars-backward " ")
2144 ;; remove whitespace at end of argument
2145 (delete-region (point) end)
2146 (buffer-substring-no-properties start (point)))))
2147 (delete-region texinfo-command-start end)
2150 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
2151 (defun texinfo-multitable-item ()
2152 "Format a row within a multicolumn table.
2153 Cells in row are separated by @tab.
2154 Widths of cells are specified by the arguments in the @multitable line.
2155 All cells are made to be the same height.
2156 This command is executed when texinfmt sees @item inside @multitable."
2157 (let ((original-buffer (current-buffer))
2158 (table-widths (reverse (car (cdr (car texinfo-stack)))))
2159 (existing-fill-column fill-column)
2163 (table-entry-height 0)
2164 ;; unformatted row looks like: A1 @tab A2 @tab A3
2165 ;; extract-row command deletes the source line in the table.
2166 (unformated-row (texinfo-multitable-extract-row)))
2167 ;; Use a temporary buffer
2168 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
2170 ;; Temporary buffer must use texinfo-format-syntax-table
2171 ;; or it will fail when parsing other commands.
2172 (set-syntax-table texinfo-format-syntax-table)
2173 (delete-region (point-min) (point-max))
2174 (insert unformated-row)
2175 (goto-char (point-min))
2176 ;; 1. Check for correct number of @tab in line.
2177 (let ((tab-number 1)) ; one @tab between two columns
2178 (while (search-forward "@tab" nil t)
2179 (setq tab-number (1+ tab-number)))
2180 (if (/= tab-number (length table-widths))
2181 (error "Wrong number of @tab's in a @multitable row")))
2182 (goto-char (point-min))
2183 ;; 2. Format each cell, and copy to a rectangle
2184 ;; buffer looks like this: A1 @tab A2 @tab A3
2185 ;; Cell #1: format up to @tab
2186 ;; Cell #2: format up to @tab
2187 ;; Cell #3: format up to eob
2189 (setq start (point))
2190 (setq end (save-excursion
2191 (if (search-forward "@tab" nil 'move)
2192 ;; Delete the @tab command, including the @-sign
2195 (progn (forward-word -1) (1- (point)))))
2197 ;; Set fill-column *wider* than needed to produce inter-column space
2198 (setq fill-column (+ 1
2199 texinfo-extra-inter-column-width
2200 (nth table-column table-widths)))
2201 (narrow-to-region start end)
2202 ;; Remove whitespace before and after entry.
2203 (skip-chars-forward " ")
2204 (delete-region (point) (save-excursion (beginning-of-line) (point)))
2205 (goto-char (point-max))
2206 (skip-chars-backward " ")
2207 (delete-region (point) (save-excursion (end-of-line) (point)))
2208 ;; Temporarily set texinfo-stack to nil so texinfo-format-scan
2209 ;; does not see an unterminated @multitable.
2210 (let (texinfo-stack) ; nil
2211 (texinfo-format-scan))
2212 (let (fill-prefix) ; no fill prefix
2213 (fill-region (point-min) (point-max)))
2214 (setq table-entry-height
2215 (max table-entry-height (count-lines (point-min) (point-max))))
2216 ;; 3. Move point to end of bottom line, and pad that line to fill column.
2217 (goto-char (point-min))
2218 (forward-line (1- table-entry-height))
2219 (let* ((beg (point)) ; beginning of line
2220 ;; add one more space for inter-column spacing
2225 (progn (end-of-line) (point)) ; end of existing line
2227 (insert (make-string
2228 (if (> needed-whitespace 0) needed-whitespace 1)
2230 ;; now, put formatted cell into a rectangle
2231 (set (intern (concat texinfo-multitable-rectangle-name
2232 (int-to-string table-column)))
2233 (extract-rectangle (point-min) (point)))
2234 (delete-region (point-min) (point))
2235 (goto-char (point-max))
2236 (setq table-column (1+ table-column))
2238 ;; 4. Add extra lines to rectangles so all are of same height
2239 (let ((total-number-of-columns table-column)
2242 (while (> table-column 0)
2243 (let ((this-rectangle (int-to-string table-column)))
2244 (while (< (length this-rectangle) table-entry-height)
2245 (setq this-rectangle (append this-rectangle '("")))))
2246 (setq table-column (1- table-column)))
2247 ;; 5. Insert formatted rectangles in original buffer
2248 (switch-to-buffer original-buffer)
2249 (open-line table-entry-height)
2250 (while (< column-number total-number-of-columns)
2254 (concat texinfo-multitable-rectangle-name
2255 (int-to-string column-number)))))
2258 (setq column-number (1+ column-number))))
2259 (kill-buffer texinfo-multitable-buffer-name)
2260 (setq fill-column existing-fill-column)))
2264 ;; Use only the FILENAME argument to the command.
2265 ;; In Info, ignore the other arguments.
2267 (put 'image 'texinfo-format 'texinfo-format-image)
2268 (defun texinfo-format-image ()
2269 "Insert an image from an an file ending in .txt.
2270 Use only the FILENAME arg; for Info, ignore the other arguments to @image."
2271 (let ((args (texinfo-format-parse-args))
2273 (when (null (nth 0 args))
2274 (error "Invalid image command"))
2275 (texinfo-discard-command)
2276 ;; makeinfo uses FILENAME.txt
2277 (setq filename (format "%s.txt" (nth 0 args)))
2278 (message "Reading included file: %s" filename)
2279 ;; verbatim for Info output
2280 (goto-char (+ (point) (cadr (insert-file-contents filename))))
2281 (message "Reading included file: %s...done" filename)))
2284 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html, @ifplaintext, @ifxml, @xml
2285 ;; @ifnottex, @ifnotinfo, @ifnothtml, @ifnotplaintext, @ifnotxml
2287 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
2288 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
2290 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
2291 (defun texinfo-format-iftex ()
2292 (delete-region texinfo-command-start
2293 (re-search-forward "@end iftex[ \t]*\n")))
2295 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
2296 (defun texinfo-format-ifhtml ()
2297 (delete-region texinfo-command-start
2298 (re-search-forward "@end ifhtml[ \t]*\n")))
2300 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
2301 (defun texinfo-format-ifplaintext ()
2302 (delete-region texinfo-command-start
2303 (re-search-forward "@end ifplaintext[ \t]*\n")))
2305 (put 'ifxml 'texinfo-format 'texinfo-format-ifxml)
2306 (defun texinfo-format-ifxml ()
2307 (delete-region texinfo-command-start
2308 (progn (re-search-forward "^@end ifxml[ \t]*\n")
2311 (put 'tex 'texinfo-format 'texinfo-format-tex)
2312 (defun texinfo-format-tex ()
2313 (delete-region texinfo-command-start
2314 (re-search-forward "@end tex[ \t]*\n")))
2316 (put 'html 'texinfo-format 'texinfo-format-html)
2317 (defun texinfo-format-html ()
2318 (delete-region texinfo-command-start
2319 (re-search-forward "@end html[ \t]*\n")))
2321 (put 'xml 'texinfo-format 'texinfo-format-xml)
2322 (defun texinfo-format-xml ()
2323 (delete-region texinfo-command-start
2324 (progn (re-search-forward "^@end xml[ \t]*\n")
2327 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
2328 (defun texinfo-format-ifnotinfo ()
2329 (delete-region texinfo-command-start
2330 (re-search-forward "@end ifnotinfo[ \t]*\n")))
2332 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
2333 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
2335 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
2336 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
2338 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
2339 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
2341 (put 'ifnotxml 'texinfo-format 'texinfo-discard-line)
2342 (put 'ifnotxml 'texinfo-end 'texinfo-discard-command)
2347 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
2348 (defun texinfo-format-titlepage ()
2349 (delete-region texinfo-command-start
2350 (re-search-forward "@end titlepage[ \t]*\n")))
2352 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
2354 ;; @titlespec an alternative titling command; ignored by Info
2356 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
2357 (defun texinfo-format-titlespec ()
2358 (delete-region texinfo-command-start
2359 (re-search-forward "@end titlespec[ \t]*\n")))
2361 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
2366 (put 'today 'texinfo-format 'texinfo-format-today)
2368 ;; Produces Day Month Year style of output. eg `1 Jan 1900'
2369 ;; The `@today{}' command requires a pair of braces, like `@dots{}'.
2370 (defun texinfo-format-today ()
2371 (texinfo-parse-arg-discard)
2372 (insert (format-time-string "%e %b %Y")))
2376 ;; Produce `Day Month Year Hour:Min' style of output.
2377 ;; eg `1 Jan 1900 13:52'
2379 (put 'timestamp 'texinfo-format 'texinfo-format-timestamp)
2381 ;; The `@timestamp{}' command requires a pair of braces, like `@dots{}'.
2382 (defun texinfo-format-timestamp ()
2383 "Insert the current local time and date."
2384 (texinfo-parse-arg-discard)
2385 ;; For seconds and time zone, replace format string with "%e %b %Y %T %Z"
2386 (insert (format-time-string "%e %b %Y %R")))
2391 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
2392 (defun texinfo-format-ignore ()
2393 (delete-region texinfo-command-start
2394 (re-search-forward "@end ignore[ \t]*\n")))
2396 (put 'endignore 'texinfo-format 'texinfo-discard-line)
2399 ;;; Define the Info enclosure command: @definfoenclose
2401 ;; A `@definfoenclose' command may be used to define a highlighting
2402 ;; command for Info, but not for TeX. A command defined using
2403 ;; `@definfoenclose' marks text by enclosing it in strings that precede
2404 ;; and follow the text.
2406 ;; Presumably, if you define a command with `@definfoenclose` for Info,
2407 ;; you will also define the same command in the TeX definitions file,
2408 ;; `texinfo.tex' in a manner appropriate for typesetting.
2410 ;; Write a `@definfoenclose' command on a line and follow it with three
2411 ;; arguments separated by commas (commas are used as separators in an
2412 ;; `@node' line in the same way). The first argument to
2413 ;; `@definfoenclose' is the @-command name \(without the `@'\); the
2414 ;; second argument is the Info start delimiter string; and the third
2415 ;; argument is the Info end delimiter string. The latter two arguments
2416 ;; enclose the highlighted text in the Info file. A delimiter string
2417 ;; may contain spaces. Neither the start nor end delimiter is
2418 ;; required. However, if you do not provide a start delimiter, you
2419 ;; must follow the command name with two commas in a row; otherwise,
2420 ;; the Info formatting commands will misinterpret the end delimiter
2421 ;; string as a start delimiter string.
2423 ;; If you do a @definfoenclose{} on the name of a pre-defined macro (such
2424 ;; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
2425 ;; override the built-in definition.
2427 ;; An enclosure command defined this way takes one argument in braces.
2429 ;; For example, you can write:
2432 ;; @definfoenclose phoo, //, \\
2435 ;; near the beginning of a Texinfo file at the beginning of the lines
2436 ;; to define `@phoo' as an Info formatting command that inserts `//'
2437 ;; before and `\\' after the argument to `@phoo'. You can then write
2438 ;; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
2440 ;; Also, for TeX formatting, you could write
2443 ;; @global@let@phoo=@i
2446 ;; to define `@phoo' as a command that causes TeX to typeset
2447 ;; the argument to `@phoo' in italics.
2449 ;; Note that each definition applies to its own formatter: one for TeX,
2450 ;; the other for texinfo-format-buffer or texinfo-format-region.
2452 ;; Here is another example: write
2454 ;; @definfoenclose headword, , :
2456 ;; near the beginning of the file, to define `@headword' as an Info
2457 ;; formatting command that inserts nothing before and a colon after the
2458 ;; argument to `@headword'.
2460 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
2461 (defun texinfo-define-info-enclosure ()
2462 (let* ((args (texinfo-format-parse-line-args))
2463 (command-name (nth 0 args))
2464 (beginning-delimiter (or (nth 1 args) ""))
2465 (end-delimiter (or (nth 2 args) "")))
2466 (texinfo-discard-command)
2467 (setq texinfo-enclosure-list
2473 texinfo-enclosure-list))))
2478 (put 'alias 'texinfo-format 'texinfo-alias)
2479 (defun texinfo-alias ()
2480 (let ((start (1- (point)))
2482 (skip-chars-forward " ")
2483 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
2484 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
2485 (error "Invalid alias command")
2486 (setq texinfo-alias-list
2489 (match-string-no-properties 1)
2490 (match-string-no-properties 2))
2491 texinfo-alias-list))
2492 (texinfo-discard-command))
2497 ;;; @var, @code and the like
2499 (put 'var 'texinfo-format 'texinfo-format-var)
2500 ;; @sc a small caps font for TeX; formatted as `var' in Info
2501 (put 'sc 'texinfo-format 'texinfo-format-var)
2502 ;; @acronym for abbreviations in all caps, such as `NASA'.
2503 ;; Convert all letters to uppercase if they are not already.
2504 (put 'acronym 'texinfo-format 'texinfo-format-var)
2505 (defun texinfo-format-var ()
2506 (let ((arg (texinfo-parse-expanded-arg)))
2507 (texinfo-discard-command)
2508 (insert (upcase arg))))
2510 (put 'cite 'texinfo-format 'texinfo-format-code)
2511 (put 'code 'texinfo-format 'texinfo-format-code)
2512 ;; @command (for command names)
2513 (put 'command 'texinfo-format 'texinfo-format-code)
2514 ;; @env (for environment variables)
2515 (put 'env 'texinfo-format 'texinfo-format-code)
2516 (put 'file 'texinfo-format 'texinfo-format-code)
2517 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
2518 (put 'samp 'texinfo-format 'texinfo-format-code)
2519 (put 'url 'texinfo-format 'texinfo-format-code)
2520 (defun texinfo-format-code ()
2521 (insert "`" (texinfo-parse-arg-discard) "'")
2522 (goto-char texinfo-command-start))
2524 ;; @option (for command-line options) must be different from @code
2525 ;; because of its special formatting in @table; namely that it does
2526 ;; not lead to inserted ` ... ' in a table, but does elsewhere.
2527 (put 'option 'texinfo-format 'texinfo-format-option)
2528 (defun texinfo-format-option ()
2529 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
2530 ;; `looking-at-backward' not available in v. 18.57, 20.2
2531 (if (not (search-backward "
\b" ; searched-for character is a control-H
2532 (save-excursion (beginning-of-line) (point))
2534 (insert "`" (texinfo-parse-arg-discard) "'")
2535 (insert (texinfo-parse-arg-discard)))
2536 (goto-char texinfo-command-start))
2538 (put 'emph 'texinfo-format 'texinfo-format-emph)
2539 (put 'strong 'texinfo-format 'texinfo-format-emph)
2540 (defun texinfo-format-emph ()
2541 (insert "*" (texinfo-parse-arg-discard) "*")
2542 (goto-char texinfo-command-start))
2544 (put 'dfn 'texinfo-format 'texinfo-format-defn)
2545 (put 'defn 'texinfo-format 'texinfo-format-defn)
2546 (defun texinfo-format-defn ()
2547 (insert "\"" (texinfo-parse-arg-discard) "\"")
2548 (goto-char texinfo-command-start))
2550 (put 'email 'texinfo-format 'texinfo-format-email)
2551 (defun texinfo-format-email ()
2552 "Format email address and optional following full name.
2553 Insert full name, if present, followed by email address
2554 surrounded by in angle brackets."
2555 (let ((args (texinfo-format-parse-args)))
2556 (texinfo-discard-command)
2559 (insert (nth 1 args) " "))
2560 (insert "<" (nth 0 args) ">")))
2562 (put 'key 'texinfo-format 'texinfo-format-key)
2563 ;; I've decided not want to have angle brackets around these -- rms.
2564 (defun texinfo-format-key ()
2565 (insert (texinfo-parse-arg-discard))
2566 (goto-char texinfo-command-start))
2568 ;; @verb{<char>TEXT<char>} (in `makeinfo' 4.1 and later)
2569 (put 'verb 'texinfo-format 'texinfo-format-verb)
2570 (defun texinfo-format-verb ()
2571 "Format text between non-quoted unique delimiter characters verbatim.
2572 Enclose the verbatim text, including the delimiters, in braces. Print
2573 text exactly as written (but not the delimiters) in a fixed-width.
2575 For example, @verb\{|@|\} results in @ and
2576 @verb\{+@'e?`!`+} results in @'e?`!`."
2578 (let ((delimiter (buffer-substring-no-properties
2579 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
2580 (unless (looking-at "{")
2581 (error "Not found: @verb start brace"))
2582 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
2583 (search-forward delimiter))
2584 (delete-backward-char 1)
2585 (unless (looking-at "}")
2586 (error "Not found: @verb end brace"))
2589 ;; as of 2002 Dec 10
2590 ;; see (texinfo)Block Enclosing Commands
2593 ;; as of 2002 Dec 10
2594 ;; see (texinfo)verbatiminclude
2595 ;; need: @verbatiminclude FILENAME
2597 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
2598 (defun texinfo-format-bullet ()
2599 "Insert an asterisk.
2600 If used within a line, follow `@bullet' with braces."
2601 (texinfo-optional-braces-discard)
2607 ;; Inside of @example ... @end example and similar environments,
2608 ;; @kbd does nothing; but outside of such environments, it places
2609 ;; single quotation marks around its argument.
2611 (defvar texinfo-format-kbd-regexp
2621 "Regexp specifying environments in which @kbd does not put `...'
2624 (defvar texinfo-format-kbd-end-regexp
2634 "Regexp specifying end of environments in which @kbd does not put `...'
2635 around argument. (See `texinfo-format-kbd-regexp')")
2637 (put 'kbd 'texinfo-format 'texinfo-format-kbd)
2638 (defun texinfo-format-kbd ()
2639 "Place single quote marks around arg, except in @example and similar."
2640 ;; Search forward for @end example closer than an @example.
2641 ;; Can stop search at nearest @node or texinfo-section-types-regexp
2645 (concat "^@node\\|\\(" texinfo-section-types-regexp "\\)")
2647 'move-to-end) ; if necessary, return point at end of buffer
2651 (re-search-forward texinfo-format-kbd-regexp stop 'move-to-end)
2653 (end-example-location
2655 (re-search-forward texinfo-format-kbd-end-regexp stop 'move-to-end)
2657 ;; If inside @example, @end example will be closer than @example
2658 ;; or end of search i.e., end-example-location less than example-location
2659 (if (>= end-example-location example-location)
2660 ;; outside an @example or equivalent
2661 (insert "`" (texinfo-parse-arg-discard) "'")
2662 ;; else, in @example; do not surround with `...'
2663 (insert (texinfo-parse-arg-discard)))
2664 (goto-char texinfo-command-start)))
2667 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample,
2670 (put 'display 'texinfo-format 'texinfo-format-example)
2671 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
2672 (put 'example 'texinfo-format 'texinfo-format-example)
2673 (put 'lisp 'texinfo-format 'texinfo-format-example)
2674 (put 'quotation 'texinfo-format 'texinfo-format-example)
2675 (put 'smallexample 'texinfo-format 'texinfo-format-example)
2676 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
2677 (defun texinfo-format-example ()
2678 (texinfo-push-stack 'example nil)
2679 (setq fill-column (- fill-column 5))
2680 (texinfo-discard-line))
2682 (put 'example 'texinfo-end 'texinfo-end-example)
2683 (put 'display 'texinfo-end 'texinfo-end-example)
2684 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
2685 (put 'lisp 'texinfo-end 'texinfo-end-example)
2686 (put 'quotation 'texinfo-end 'texinfo-end-example)
2687 (put 'smallexample 'texinfo-end 'texinfo-end-example)
2688 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
2689 (defun texinfo-end-example ()
2690 (setq fill-column (+ fill-column 5))
2691 (texinfo-discard-command)
2693 (texinfo-pop-stack 'example)))
2694 (texinfo-do-itemize (nth 1 stacktop))))
2696 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
2697 (defun texinfo-format-exdent ()
2698 (texinfo-discard-command)
2699 (delete-region (point)
2701 (skip-chars-forward " ")
2704 ;; Cancel out the deletion that texinfo-do-itemize
2705 ;; is going to do at the end of this line.
2711 ;; @direntry and @dircategory
2713 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
2714 (defun texinfo-format-direntry ()
2715 (texinfo-push-stack 'direntry nil)
2716 (texinfo-discard-line)
2717 (insert "START-INFO-DIR-ENTRY\n"))
2719 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
2720 (defun texinfo-end-direntry ()
2721 (texinfo-discard-command)
2722 (insert "END-INFO-DIR-ENTRY\n\n")
2723 (texinfo-pop-stack 'direntry))
2725 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
2726 (defun texinfo-format-dircategory ()
2727 (let ((str (texinfo-parse-arg-discard)))
2728 (delete-region (point)
2730 (skip-chars-forward " ")
2732 (insert "INFO-DIR-SECTION " str "\n")))
2736 ;; The @cartouche command is a noop in Info; in a printed manual,
2737 ;; it makes a box with rounded corners.
2739 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
2740 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
2743 ;;; @flushleft and @format
2745 ;; The @flushleft command left justifies every line but leaves the
2746 ;; right end ragged. As far as Info is concerned, @flushleft is a
2747 ;; `do-nothing' command
2749 ;; The @format command is similar to @example except that it does not
2750 ;; indent; this means that in Info, @format is similar to @flushleft.
2752 (put 'format 'texinfo-format 'texinfo-format-flushleft)
2753 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
2754 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
2755 (defun texinfo-format-flushleft ()
2756 (texinfo-discard-line))
2758 (put 'format 'texinfo-end 'texinfo-end-flushleft)
2759 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
2760 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
2761 (defun texinfo-end-flushleft ()
2762 (texinfo-discard-command))
2767 ;; The @flushright command right justifies every line but leaves the
2768 ;; left end ragged. Spaces and tabs at the right ends of lines are
2769 ;; removed so that visible text lines up on the right side.
2771 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
2772 (defun texinfo-format-flushright ()
2773 (texinfo-push-stack 'flushright nil)
2774 (texinfo-discard-line))
2776 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
2777 (defun texinfo-end-flushright ()
2778 (texinfo-discard-command)
2781 (texinfo-pop-stack 'flushright)))
2783 (texinfo-do-flushright (nth 1 stacktop))))
2785 (defun texinfo-do-flushright (from)
2787 (while (progn (forward-line -1)
2796 (skip-chars-backward " \t")
2797 (delete-region (point) (progn (end-of-line) (point)))
2802 ;;; @ctrl, @TeX, @copyright, @minus, @dots, @enddots, @pounds
2804 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
2805 (defun texinfo-format-ctrl ()
2806 (let ((str (texinfo-parse-arg-discard)))
2807 (insert (logand 31 (aref str 0)))))
2809 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
2810 (defun texinfo-format-TeX ()
2811 (texinfo-parse-arg-discard)
2814 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
2815 (defun texinfo-format-copyright ()
2816 (texinfo-parse-arg-discard)
2819 (put 'minus 'texinfo-format 'texinfo-format-minus)
2820 (defun texinfo-format-minus ()
2821 "Insert a minus sign.
2822 If used within a line, follow `@minus' with braces."
2823 (texinfo-optional-braces-discard)
2826 (put 'dots 'texinfo-format 'texinfo-format-dots)
2827 (defun texinfo-format-dots ()
2828 (texinfo-parse-arg-discard)
2831 (put 'enddots 'texinfo-format 'texinfo-format-enddots)
2832 (defun texinfo-format-enddots ()
2833 (texinfo-parse-arg-discard)
2836 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
2837 (defun texinfo-format-pounds ()
2838 (texinfo-parse-arg-discard)
2842 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
2844 ;;; Indent only those paragraphs that are refilled as a result of an
2845 ;;; @refill command.
2847 ;; * If the value is `asis', do not change the existing indentation at
2848 ;; the starts of paragraphs.
2850 ;; * If the value zero, delete any existing indentation.
2852 ;; * If the value is greater than zero, indent each paragraph by that
2853 ;; number of spaces.
2855 ;;; But do not refill paragraphs with an @refill command that are
2856 ;;; preceded by @noindent or are part of a table, list, or deffn.
2858 (defvar texinfo-paragraph-indent "asis"
2859 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
2861 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
2863 (defun texinfo-paragraphindent ()
2864 "Specify the number of spaces for @refill to indent a paragraph.
2865 Default is to leave the number of spaces as is."
2866 (let ((arg (texinfo-parse-arg-discard)))
2867 (if (string= "asis" arg)
2868 (setq texinfo-paragraph-indent "asis")
2869 (setq texinfo-paragraph-indent (string-to-number arg)))))
2871 (put 'refill 'texinfo-format 'texinfo-format-refill)
2872 (defun texinfo-format-refill ()
2873 "Refill paragraph. Also, indent first line as set by @paragraphindent.
2874 Default is to leave paragraph indentation as is."
2875 (texinfo-discard-command)
2876 (let ((position (point-marker)))
2877 (forward-paragraph -1)
2878 (if (looking-at "[ \t\n]*$") (forward-line 1))
2879 ;; Do not indent if an entry in a list, table, or deffn,
2880 ;; or if paragraph is preceded by @noindent.
2881 ;; Otherwise, indent
2883 ;; delete a @noindent line and do not indent paragraph
2884 ((save-excursion (forward-line -1)
2885 (looking-at "^@noindent"))
2887 (delete-region (point) (progn (forward-line 1) (point))))
2888 ;; do nothing if "asis"
2889 ((equal texinfo-paragraph-indent "asis"))
2890 ;; do no indenting in list, etc.
2891 ((> texinfo-stack-depth 0))
2892 ;; otherwise delete existing whitespace and indent
2894 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2895 (insert (make-string texinfo-paragraph-indent ? ))))
2896 (forward-paragraph 1)
2899 ;; Do not fill a section title line with asterisks, hyphens, etc. that
2900 ;; are used to underline it. This could occur if the line following
2901 ;; the underlining is not an index entry and has text within it.
2902 (let* ((previous-paragraph-separate paragraph-separate)
2904 (concat paragraph-separate "\\|[-=.]+\\|\\*\\*+"))
2905 (previous-paragraph-start paragraph-start)
2907 (concat paragraph-start "\\|[-=.]+\\|\\*\\*+")))
2909 (fill-paragraph nil)
2910 (setq paragraph-separate previous-paragraph-separate)
2911 (setq paragraph-start previous-paragraph-start)))
2912 (goto-char position)))
2914 (put 'noindent 'texinfo-format 'texinfo-noindent)
2915 (defun texinfo-noindent ()
2917 (forward-paragraph 1)
2918 (if (search-backward "@refill"
2919 (save-excursion (forward-line -1) (point)) t)
2920 () ; leave @noindent command so @refill command knows not to indent
2922 (texinfo-discard-line))))
2925 ;;; Index generation
2927 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
2928 (defun texinfo-format-vindex ()
2929 (texinfo-index 'texinfo-vindex))
2931 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
2932 (defun texinfo-format-cindex ()
2933 (texinfo-index 'texinfo-cindex))
2935 (put 'findex 'texinfo-format 'texinfo-format-findex)
2936 (defun texinfo-format-findex ()
2937 (texinfo-index 'texinfo-findex))
2939 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
2940 (defun texinfo-format-pindex ()
2941 (texinfo-index 'texinfo-pindex))
2943 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
2944 (defun texinfo-format-tindex ()
2945 (texinfo-index 'texinfo-tindex))
2947 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
2948 (defun texinfo-format-kindex ()
2949 (texinfo-index 'texinfo-kindex))
2951 (defun texinfo-index (indexvar)
2952 (let ((arg (texinfo-parse-expanded-arg)))
2953 (texinfo-discard-command)
2957 ;; Region formatting may not provide last node position.
2958 (if texinfo-last-node-pos
2959 (1+ (count-lines texinfo-last-node-pos (point)))
2961 (symbol-value indexvar)))))
2963 (defconst texinfo-indexvar-alist
2964 '(("cp" . texinfo-cindex)
2965 ("fn" . texinfo-findex)
2966 ("vr" . texinfo-vindex)
2967 ("tp" . texinfo-tindex)
2968 ("pg" . texinfo-pindex)
2969 ("ky" . texinfo-kindex)))
2972 ;;; @defindex @defcodeindex
2973 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
2974 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
2976 (defun texinfo-format-defindex ()
2977 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
2978 (indexing-command (intern (concat index-name "index")))
2979 (index-formatting-command ; eg: `texinfo-format-aaindex'
2980 (intern (concat "texinfo-format-" index-name "index")))
2981 (index-alist-name ; eg: `texinfo-aaindex'
2982 (intern (concat "texinfo-" index-name "index"))))
2984 (set index-alist-name nil)
2986 (put indexing-command ; eg, aaindex
2988 index-formatting-command) ; eg, texinfo-format-aaindex
2990 ;; eg: "aa" . texinfo-aaindex
2991 (or (assoc index-name texinfo-indexvar-alist)
2992 (setq texinfo-indexvar-alist
2996 texinfo-indexvar-alist)))
2998 (fset index-formatting-command
3000 (list 'texinfo-index
3001 (list 'quote index-alist-name))))))
3004 ;;; @synindex @syncodeindex
3006 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
3007 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
3009 (defun texinfo-format-synindex ()
3010 (let* ((args (texinfo-parse-arg-discard))
3011 (second (cdr (read-from-string args)))
3012 (joiner (symbol-name (car (read-from-string args))))
3013 (joined (symbol-name (car (read-from-string args second)))))
3015 (if (assoc joiner texinfo-short-index-cmds-alist)
3017 (cdr (assoc joiner texinfo-short-index-cmds-alist))
3019 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
3020 (intern (concat "texinfo-format-" joined "index"))))
3022 (intern (concat joiner "index"))
3024 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
3025 (intern (concat "texinfo-format-" joined "index")))))))
3027 (defconst texinfo-short-index-cmds-alist
3035 (defconst texinfo-short-index-format-cmds-alist
3036 '(("cp" . texinfo-format-cindex)
3037 ("fn" . texinfo-format-findex)
3038 ("vr" . texinfo-format-vindex)
3039 ("tp" . texinfo-format-tindex)
3040 ("pg" . texinfo-format-pindex)
3041 ("ky" . texinfo-format-kindex)))
3044 ;;; Sort and index (for VMS)
3046 ;; Sort an index which is in the current buffer between START and END.
3047 ;; Used on VMS, where the `sort' utility is not available.
3048 (defun texinfo-sort-region (start end)
3051 (narrow-to-region start end)
3052 (goto-char (point-min))
3053 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
3055 ;; Subroutine for sorting an index.
3056 ;; At start of a line, return a string to sort the line under.
3057 (defun texinfo-sort-startkeyfun ()
3058 (let ((line (buffer-substring-no-properties (point) (point-at-eol))))
3059 ;; Canonicalize whitespace and eliminate funny chars.
3060 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
3061 (setq line (concat (substring line 0 (match-beginning 0))
3063 (substring line (match-end 0)))))
3069 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
3071 (defun texinfo-format-printindex ()
3072 (let ((indexelts (symbol-value
3073 (cdr (assoc (texinfo-parse-arg-discard)
3074 texinfo-indexvar-alist))))
3076 (insert "\n* Menu:\n\n")
3077 (setq opoint (point))
3078 (texinfo-print-index nil indexelts)
3079 (setq npoint (point))
3080 (if (memq system-type '(vax-vms windows-nt ms-dos))
3081 (texinfo-sort-region opoint npoint)
3082 (shell-command-on-region opoint npoint "sort -fd" 1))
3083 (goto-char npoint)))
3085 (defun texinfo-print-index (file indexelts)
3087 (if (stringp (car (car indexelts)))
3089 (insert "* " (car (car indexelts)) ": " )
3092 (if file (concat "(" file ")") "")
3093 (nth 1 (car indexelts)) ".")
3096 (if (nth 2 (car indexelts))
3097 (format " (line %3d)" (1+ (nth 2 (car indexelts))))
3100 ;; index entries from @include'd file
3101 (texinfo-print-index (nth 1 (car indexelts))
3102 (nth 2 (car indexelts))))
3103 (setq indexelts (cdr indexelts))))
3106 ;;; Glyphs: @equiv, @error, etc
3108 ;; @equiv to show that two expressions are equivalent
3109 ;; @error to show an error message
3110 ;; @expansion to show what a macro expands to
3111 ;; @point to show the location of point in an example
3112 ;; @print to show what an evaluated expression prints
3113 ;; @result to indicate the value returned by an expression
3115 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
3116 (defun texinfo-format-equiv ()
3117 (texinfo-parse-arg-discard)
3120 (put 'error 'texinfo-format 'texinfo-format-error)
3121 (defun texinfo-format-error ()
3122 (texinfo-parse-arg-discard)
3123 (insert "error-->"))
3125 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
3126 (defun texinfo-format-expansion ()
3127 (texinfo-parse-arg-discard)
3130 (put 'point 'texinfo-format 'texinfo-format-point)
3131 (defun texinfo-format-point ()
3132 (texinfo-parse-arg-discard)
3135 (put 'print 'texinfo-format 'texinfo-format-print)
3136 (defun texinfo-format-print ()
3137 (texinfo-parse-arg-discard)
3140 (put 'result 'texinfo-format 'texinfo-format-result)
3141 (defun texinfo-format-result ()
3142 (texinfo-parse-arg-discard)
3148 ;; Info presumes a plain ASCII output, so the accented characters do
3149 ;; not look as they would if typeset, or output with a different
3152 ;; See the `texinfo-accent-commands' variable
3153 ;; in the section for `texinfo-append-refill'.
3154 ;; Also, see the defun for `texinfo-format-scan'
3155 ;; for single-character accent commands.
3157 ;; Command Info output Name
3159 ;; These do not have braces:
3160 ;; @^ ==> ^ circumflex accent
3161 ;; @` ==> ` grave accent
3162 ;; @' ==> ' acute accent
3163 ;; @" ==> " umlaut accent
3164 ;; @= ==> = overbar accent
3165 ;; @~ ==> ~ tilde accent
3167 ;; These have braces, but take no argument:
3168 ;; @OE{} ==> OE French-OE-ligature
3170 ;; @AA{} ==> AA Scandinavian-A-with-circle
3172 ;; @AE{} ==> AE Latin-Scandinavian-AE
3174 ;; @ss{} ==> ss German-sharp-S
3176 ;; @questiondown{} ==> ? upside-down-question-mark
3177 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
3178 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
3179 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
3180 ;; @O{} ==> O/ Scandinavian O-with-slash
3181 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
3183 ;; These have braces, and take an argument:
3184 ;; @,{c} ==> c, cedilla accent
3185 ;; @dotaccent{o} ==> .o overdot-accent
3186 ;; @ubaraccent{o} ==> _o underbar-accent
3187 ;; @udotaccent{o} ==> o-. underdot-accent
3188 ;; @H{o} ==> ""o long Hungarian umlaut
3189 ;; @ringaccent{o} ==> *o ring accent
3190 ;; @tieaccent{oo} ==> [oo tie after accent
3191 ;; @u{o} ==> (o breve accent
3192 ;; @v{o} ==> <o hacek accent
3193 ;; @dotless{i} ==> i dotless i and dotless j
3197 ;; Note: The defun texinfo-format-scan
3198 ;; looks at "[@{}^'`\",=~ *?!-]"
3199 ;; In the case of @*, a line break is inserted;
3200 ;; in the other cases, the characters are simply quoted and the @ is deleted.
3201 ;; Thus, `texinfo-format-scan' handles the following
3202 ;; single-character accent commands: @^ @` @' @" @, @- @= @~
3204 ;; @^ ==> ^ circumflex accent
3205 ;; (put '^ 'texinfo-format 'texinfo-format-circumflex-accent)
3206 ;; (defun texinfo-format-circumflex-accent ()
3207 ;; (texinfo-discard-command)
3210 ;; @` ==> ` grave accent
3211 ;; (put '\` 'texinfo-format 'texinfo-format-grave-accent)
3212 ;; (defun texinfo-format-grave-accent ()
3213 ;; (texinfo-discard-command)
3216 ;; @' ==> ' acute accent
3217 ;; (put '\' 'texinfo-format 'texinfo-format-acute-accent)
3218 ;; (defun texinfo-format-acute-accent ()
3219 ;; (texinfo-discard-command)
3222 ;; @" ==> " umlaut accent
3223 ;; (put '\" 'texinfo-format 'texinfo-format-umlaut-accent)
3224 ;; (defun texinfo-format-umlaut-accent ()
3225 ;; (texinfo-discard-command)
3228 ;; @= ==> = overbar accent
3229 ;; (put '= 'texinfo-format 'texinfo-format-overbar-accent)
3230 ;; (defun texinfo-format-overbar-accent ()
3231 ;; (texinfo-discard-command)
3234 ;; @~ ==> ~ tilde accent
3235 ;; (put '~ 'texinfo-format 'texinfo-format-tilde-accent)
3236 ;; (defun texinfo-format-tilde-accent ()
3237 ;; (texinfo-discard-command)
3240 ;; @OE{} ==> OE French-OE-ligature
3241 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
3242 (defun texinfo-format-French-OE-ligature ()
3243 (insert "OE" (texinfo-parse-arg-discard))
3244 (goto-char texinfo-command-start))
3247 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
3248 (defun texinfo-format-French-oe-ligature () ; lower case
3249 (insert "oe" (texinfo-parse-arg-discard))
3250 (goto-char texinfo-command-start))
3252 ;; @AA{} ==> AA Scandinavian-A-with-circle
3253 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
3254 (defun texinfo-format-Scandinavian-A-with-circle ()
3255 (insert "AA" (texinfo-parse-arg-discard))
3256 (goto-char texinfo-command-start))
3259 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
3260 (defun texinfo-format-Scandinavian-a-with-circle () ; lower case
3261 (insert "aa" (texinfo-parse-arg-discard))
3262 (goto-char texinfo-command-start))
3264 ;; @AE{} ==> AE Latin-Scandinavian-AE
3265 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
3266 (defun texinfo-format-Latin-Scandinavian-AE ()
3267 (insert "AE" (texinfo-parse-arg-discard))
3268 (goto-char texinfo-command-start))
3271 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
3272 (defun texinfo-format-Latin-Scandinavian-ae () ; lower case
3273 (insert "ae" (texinfo-parse-arg-discard))
3274 (goto-char texinfo-command-start))
3276 ;; @ss{} ==> ss German-sharp-S
3277 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
3278 (defun texinfo-format-German-sharp-S ()
3279 (insert "ss" (texinfo-parse-arg-discard))
3280 (goto-char texinfo-command-start))
3282 ;; @questiondown{} ==> ? upside-down-question-mark
3283 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
3284 (defun texinfo-format-upside-down-question-mark ()
3285 (insert "?" (texinfo-parse-arg-discard))
3286 (goto-char texinfo-command-start))
3288 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
3289 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
3290 (defun texinfo-format-upside-down-exclamation-mark ()
3291 (insert "!" (texinfo-parse-arg-discard))
3292 (goto-char texinfo-command-start))
3294 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
3295 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
3296 (defun texinfo-format-Polish-suppressed-L ()
3297 (insert (texinfo-parse-arg-discard) "/L")
3298 (goto-char texinfo-command-start))
3300 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
3301 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
3302 (defun texinfo-format-Polish-suppressed-l-lower-case ()
3303 (insert (texinfo-parse-arg-discard) "/l")
3304 (goto-char texinfo-command-start))
3307 ;; @O{} ==> O/ Scandinavian O-with-slash
3308 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
3309 (defun texinfo-format-Scandinavian-O-with-slash ()
3310 (insert (texinfo-parse-arg-discard) "O/")
3311 (goto-char texinfo-command-start))
3313 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
3314 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
3315 (defun texinfo-format-Scandinavian-o-with-slash-lower-case ()
3316 (insert (texinfo-parse-arg-discard) "o/")
3317 (goto-char texinfo-command-start))
3321 ;; @,{c} ==> c, cedilla accent
3322 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
3323 (defun texinfo-format-cedilla-accent ()
3324 (insert (texinfo-parse-arg-discard) ",")
3325 (goto-char texinfo-command-start))
3328 ;; @dotaccent{o} ==> .o overdot-accent
3329 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
3330 (defun texinfo-format-overdot-accent ()
3331 (insert "." (texinfo-parse-arg-discard))
3332 (goto-char texinfo-command-start))
3334 ;; @ubaraccent{o} ==> _o underbar-accent
3335 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
3336 (defun texinfo-format-underbar-accent ()
3337 (insert "_" (texinfo-parse-arg-discard))
3338 (goto-char texinfo-command-start))
3340 ;; @udotaccent{o} ==> o-. underdot-accent
3341 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
3342 (defun texinfo-format-underdot-accent ()
3343 (insert (texinfo-parse-arg-discard) "-.")
3344 (goto-char texinfo-command-start))
3346 ;; @H{o} ==> ""o long Hungarian umlaut
3347 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
3348 (defun texinfo-format-long-Hungarian-umlaut ()
3349 (insert "\"\"" (texinfo-parse-arg-discard))
3350 (goto-char texinfo-command-start))
3352 ;; @ringaccent{o} ==> *o ring accent
3353 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
3354 (defun texinfo-format-ring-accent ()
3355 (insert "*" (texinfo-parse-arg-discard))
3356 (goto-char texinfo-command-start))
3358 ;; @tieaccent{oo} ==> [oo tie after accent
3359 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
3360 (defun texinfo-format-tie-after-accent ()
3361 (insert "[" (texinfo-parse-arg-discard))
3362 (goto-char texinfo-command-start))
3365 ;; @u{o} ==> (o breve accent
3366 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
3367 (defun texinfo-format-breve-accent ()
3368 (insert "(" (texinfo-parse-arg-discard))
3369 (goto-char texinfo-command-start))
3371 ;; @v{o} ==> <o hacek accent
3372 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
3373 (defun texinfo-format-hacek-accent ()
3374 (insert "<" (texinfo-parse-arg-discard))
3375 (goto-char texinfo-command-start))
3378 ;; @dotless{i} ==> i dotless i and dotless j
3379 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
3380 (defun texinfo-format-dotless ()
3381 (insert (texinfo-parse-arg-discard))
3382 (goto-char texinfo-command-start))
3385 ;;; Definition formatting: @deffn, @defun, etc
3387 ;; What definition formatting produces:
3389 ;; @deffn category name args...
3390 ;; In Info, `Category: name ARGS'
3391 ;; In index: name: node. line#.
3393 ;; @defvr category name
3394 ;; In Info, `Category: name'
3395 ;; In index: name: node. line#.
3397 ;; @deftp category name attributes...
3398 ;; `category name attributes...' Note: @deftp args in lower case.
3399 ;; In index: name: node. line#.
3401 ;; Specialized function-like or variable-like entity:
3403 ;; @defun, @defmac, @defspec, @defvar, @defopt
3405 ;; @defun name args In Info, `Function: name ARGS'
3406 ;; @defmac name args In Info, `Macro: name ARGS'
3407 ;; @defvar name In Info, `Variable: name'
3409 ;; In index: name: node. line#.
3411 ;; Generalized typed-function-like or typed-variable-like entity:
3412 ;; @deftypefn category data-type name args...
3413 ;; In Info, `Category: data-type name args...'
3414 ;; @deftypevr category data-type name
3415 ;; In Info, `Category: data-type name'
3416 ;; In index: name: node. line#.
3418 ;; Specialized typed-function-like or typed-variable-like entity:
3419 ;; @deftypefun data-type name args...
3420 ;; In Info, `Function: data-type name ARGS'
3421 ;; In index: name: node. line#.
3423 ;; @deftypevar data-type name
3424 ;; In Info, `Variable: data-type name'
3425 ;; In index: name: node. line#. but include args after name!?
3427 ;; Generalized object oriented entity:
3428 ;; @defop category class name args...
3429 ;; In Info, `Category on class: name ARG'
3430 ;; In index: name on class: node. line#.
3432 ;; @defcv category class name
3433 ;; In Info, `Category of class: name'
3434 ;; In index: name of class: node. line#.
3436 ;; Specialized object oriented entity:
3437 ;; @defmethod class name args...
3438 ;; In Info, `Method on class: name ARGS'
3439 ;; In index: name on class: node. line#.
3441 ;; @defivar class name
3442 ;; In Info, `Instance variable of class: name'
3443 ;; In index: name of class: node. line#.
3446 ;;; The definition formatting functions
3448 (defun texinfo-format-defun ()
3449 (texinfo-push-stack 'defun nil)
3450 (setq fill-column (- fill-column 5))
3451 (texinfo-format-defun-1 t))
3453 (defun texinfo-end-defun ()
3454 (setq fill-column (+ fill-column 5))
3455 (texinfo-discard-command)
3456 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
3457 (texinfo-do-itemize start)
3458 ;; Delete extra newline inserted after header.
3463 (defun texinfo-format-defunx ()
3464 (texinfo-format-defun-1 nil))
3466 (defun texinfo-format-defun-1 (first-p)
3467 (let ((parse-args (texinfo-format-parse-defun-args))
3468 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
3469 (texinfo-discard-command)
3470 ;; Delete extra newline inserted after previous header line.
3474 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
3475 ;; Insert extra newline so that paragraph filling does not mess
3476 ;; with header line.
3478 (rplaca (cdr (cdr (car texinfo-stack))) (point))
3480 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
3482 ;;; Formatting the first line of a definition
3484 ;; @deffn, @defvr, @deftp
3485 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3486 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3487 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3488 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3489 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3490 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3491 (defun texinfo-format-deffn (parsed-args)
3492 ;; Generalized function-like, variable-like, or generic data-type entity:
3493 ;; @deffn category name args...
3494 ;; In Info, `Category: name ARGS'
3495 ;; @deftp category name attributes...
3496 ;; `category name attributes...' Note: @deftp args in lower case.
3497 (let ((category (car parsed-args))
3498 (name (car (cdr parsed-args)))
3499 (args (cdr (cdr parsed-args))))
3500 (insert " -- " category ": " name)
3503 (if (or (= ?& (aref (car args) 0))
3504 (eq (eval (car texinfo-defun-type)) 'deftp-type))
3506 (upcase (car args))))
3507 (setq args (cdr args)))))
3509 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
3510 (put 'defun 'texinfo-deffn-formatting-property
3511 'texinfo-format-specialized-defun)
3512 (put 'defunx 'texinfo-deffn-formatting-property
3513 'texinfo-format-specialized-defun)
3514 (put 'defmac 'texinfo-deffn-formatting-property
3515 'texinfo-format-specialized-defun)
3516 (put 'defmacx 'texinfo-deffn-formatting-property
3517 'texinfo-format-specialized-defun)
3518 (put 'defspec 'texinfo-deffn-formatting-property
3519 'texinfo-format-specialized-defun)
3520 (put 'defspecx 'texinfo-deffn-formatting-property
3521 'texinfo-format-specialized-defun)
3522 (put 'defvar 'texinfo-deffn-formatting-property
3523 'texinfo-format-specialized-defun)
3524 (put 'defvarx 'texinfo-deffn-formatting-property
3525 'texinfo-format-specialized-defun)
3526 (put 'defopt 'texinfo-deffn-formatting-property
3527 'texinfo-format-specialized-defun)
3528 (put 'defoptx 'texinfo-deffn-formatting-property
3529 'texinfo-format-specialized-defun)
3530 (defun texinfo-format-specialized-defun (parsed-args)
3531 ;; Specialized function-like or variable-like entity:
3532 ;; @defun name args In Info, `Function: Name ARGS'
3533 ;; @defmac name args In Info, `Macro: Name ARGS'
3534 ;; @defvar name In Info, `Variable: Name'
3535 ;; Use cdr of texinfo-defun-type to determine category:
3536 (let ((category (car (cdr texinfo-defun-type)))
3537 (name (car parsed-args))
3538 (args (cdr parsed-args)))
3539 (insert " -- " category ": " name)
3542 (if (= ?& (aref (car args) 0))
3544 (upcase (car args))))
3545 (setq args (cdr args)))))
3547 ;; @deftypefn, @deftypevr: Generalized typed
3548 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3549 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3550 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3551 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3552 (defun texinfo-format-deftypefn (parsed-args)
3553 ;; Generalized typed-function-like or typed-variable-like entity:
3554 ;; @deftypefn category data-type name args...
3555 ;; In Info, `Category: data-type name args...'
3556 ;; @deftypevr category data-type name
3557 ;; In Info, `Category: data-type name'
3558 ;; Note: args in lower case, unless modified in command line.
3559 (let ((category (car parsed-args))
3560 (data-type (car (cdr parsed-args)))
3561 (name (car (cdr (cdr parsed-args))))
3562 (args (cdr (cdr (cdr parsed-args)))))
3563 (insert " -- " category ": " data-type " " name)
3565 (insert " " (car args))
3566 (setq args (cdr args)))))
3568 ;; @deftypefun, @deftypevar: Specialized typed
3569 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3570 (put 'deftypefunx 'texinfo-deffn-formatting-property
3571 'texinfo-format-deftypefun)
3572 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3573 (put 'deftypevarx 'texinfo-deffn-formatting-property
3574 'texinfo-format-deftypefun)
3575 (defun texinfo-format-deftypefun (parsed-args)
3576 ;; Specialized typed-function-like or typed-variable-like entity:
3577 ;; @deftypefun data-type name args...
3578 ;; In Info, `Function: data-type name ARGS'
3579 ;; @deftypevar data-type name
3580 ;; In Info, `Variable: data-type name'
3581 ;; Note: args in lower case, unless modified in command line.
3582 ;; Use cdr of texinfo-defun-type to determine category:
3583 (let ((category (car (cdr texinfo-defun-type)))
3584 (data-type (car parsed-args))
3585 (name (car (cdr parsed-args)))
3586 (args (cdr (cdr parsed-args))))
3587 (insert " -- " category ": " data-type " " name)
3589 (insert " " (car args))
3590 (setq args (cdr args)))))
3592 ;; @defop: Generalized object-oriented
3593 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3594 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3595 (defun texinfo-format-defop (parsed-args)
3596 ;; Generalized object oriented entity:
3597 ;; @defop category class name args...
3598 ;; In Info, `Category on class: name ARG'
3599 ;; Note: args in upper case; use of `on'
3600 (let ((category (car parsed-args))
3601 (class (car (cdr parsed-args)))
3602 (name (car (cdr (cdr parsed-args))))
3603 (args (cdr (cdr (cdr parsed-args)))))
3604 (insert " -- " category " on " class ": " name)
3606 (insert " " (upcase (car args)))
3607 (setq args (cdr args)))))
3609 ;; @defcv: Generalized object-oriented
3610 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3611 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3612 (defun texinfo-format-defcv (parsed-args)
3613 ;; Generalized object oriented entity:
3614 ;; @defcv category class name
3615 ;; In Info, `Category of class: name'
3616 ;; Note: args in upper case; use of `of'
3617 (let ((category (car parsed-args))
3618 (class (car (cdr parsed-args)))
3619 (name (car (cdr (cdr parsed-args))))
3620 (args (cdr (cdr (cdr parsed-args)))))
3621 (insert " -- " category " of " class ": " name)
3623 (insert " " (upcase (car args)))
3624 (setq args (cdr args)))))
3626 ;; @defmethod: Specialized object-oriented
3627 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3628 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3629 (defun texinfo-format-defmethod (parsed-args)
3630 ;; Specialized object oriented entity:
3631 ;; @defmethod class name args...
3632 ;; In Info, `Method on class: name ARGS'
3633 ;; Note: args in upper case; use of `on'
3634 ;; Use cdr of texinfo-defun-type to determine category:
3635 (let ((category (car (cdr texinfo-defun-type)))
3636 (class (car parsed-args))
3637 (name (car (cdr parsed-args)))
3638 (args (cdr (cdr parsed-args))))
3639 (insert " -- " category " on " class ": " name)
3641 (insert " " (upcase (car args)))
3642 (setq args (cdr args)))))
3644 ;; @defivar: Specialized object-oriented
3645 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3646 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3647 (defun texinfo-format-defivar (parsed-args)
3648 ;; Specialized object oriented entity:
3649 ;; @defivar class name
3650 ;; In Info, `Instance variable of class: name'
3651 ;; Note: args in upper case; use of `of'
3652 ;; Use cdr of texinfo-defun-type to determine category:
3653 (let ((category (car (cdr texinfo-defun-type)))
3654 (class (car parsed-args))
3655 (name (car (cdr parsed-args)))
3656 (args (cdr (cdr parsed-args))))
3657 (insert " -- " category " of " class ": " name)
3659 (insert " " (upcase (car args)))
3660 (setq args (cdr args)))))
3663 ;;; Indexing for definitions
3665 ;; An index entry has three parts: the `entry proper', the node name, and the
3666 ;; line number. Depending on the which command is used, the entry is
3667 ;; formatted differently:
3673 ;; @defopt all use their 1st argument as the entry-proper
3679 ;; @deftypevar all use their 2nd argument as the entry-proper
3682 ;; @deftypevr both use their 3rd argument as the entry-proper
3684 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
3685 ;; formatted: NAME on CLASS
3687 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
3688 ;; formatted: NAME on CLASS
3690 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
3691 ;; formatted: NAME of CLASS
3693 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
3694 ;; formatted: NAME of CLASS
3696 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
3697 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3698 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
3699 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3700 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
3701 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3702 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
3703 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3704 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
3705 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3706 (defun texinfo-index-defun (parsed-args)
3707 ;; use 1st parsed-arg as entry-proper
3708 ;; `index-list' will be texinfo-findex or the like
3709 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3712 ;; Three elements: entry-proper, node-name, line-number
3716 ;; Region formatting may not provide last node position.
3717 (if texinfo-last-node-pos
3718 (1+ (count-lines texinfo-last-node-pos (point)))
3720 (symbol-value index-list)))))
3722 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3723 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3724 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3725 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3726 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3727 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3728 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3729 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3730 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3731 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3732 (defun texinfo-index-deffn (parsed-args)
3733 ;; use 2nd parsed-arg as entry-proper
3734 ;; `index-list' will be texinfo-findex or the like
3735 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3738 ;; Three elements: entry-proper, node-name, line-number
3740 (car (cdr parsed-args))
3742 ;; Region formatting may not provide last node position.
3743 (if texinfo-last-node-pos
3744 (1+ (count-lines texinfo-last-node-pos (point)))
3746 (symbol-value index-list)))))
3748 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3749 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3750 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3751 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3752 (defun texinfo-index-deftypefn (parsed-args)
3753 ;; use 3rd parsed-arg as entry-proper
3754 ;; `index-list' will be texinfo-findex or the like
3755 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3758 ;; Three elements: entry-proper, node-name, line-number
3760 (car (cdr (cdr parsed-args)))
3762 ;; Region formatting may not provide last node position.
3763 (if texinfo-last-node-pos
3764 (1+ (count-lines texinfo-last-node-pos (point)))
3766 (symbol-value index-list)))))
3768 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3769 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3770 (defun texinfo-index-defmethod (parsed-args)
3771 ;; use 2nd on 1st parsed-arg as entry-proper
3772 ;; `index-list' will be texinfo-findex or the like
3773 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3776 ;; Three elements: entry-proper, node-name, line-number
3779 (car (cdr parsed-args))
3782 ;; Region formatting may not provide last node position.
3783 (if texinfo-last-node-pos
3784 (1+ (count-lines texinfo-last-node-pos (point)))
3786 (symbol-value index-list)))))
3788 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
3789 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
3790 (defun texinfo-index-defop (parsed-args)
3791 ;; use 3rd on 2nd parsed-arg as entry-proper
3792 ;; `index-list' will be texinfo-findex or the like
3793 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3796 ;; Three elements: entry-proper, node-name, line-number
3799 (car (cdr (cdr parsed-args)))
3800 (car (cdr parsed-args)))
3802 ;; Region formatting may not provide last node position.
3803 (if texinfo-last-node-pos
3804 (1+ (count-lines texinfo-last-node-pos (point)))
3806 (symbol-value index-list)))))
3808 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3809 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3810 (defun texinfo-index-defivar (parsed-args)
3811 ;; use 2nd of 1st parsed-arg as entry-proper
3812 ;; `index-list' will be texinfo-findex or the like
3813 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3816 ;; Three elements: entry-proper, node-name, line-number
3819 (car (cdr parsed-args))
3822 ;; Region formatting may not provide last node position.
3823 (if texinfo-last-node-pos
3824 (1+ (count-lines texinfo-last-node-pos (point)))
3826 (symbol-value index-list)))))
3828 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3829 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3830 (defun texinfo-index-defcv (parsed-args)
3831 ;; use 3rd of 2nd parsed-arg as entry-proper
3832 ;; `index-list' will be texinfo-findex or the like
3833 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3836 ;; Three elements: entry-proper, node-name, line-number
3839 (car (cdr (cdr parsed-args)))
3840 (car (cdr parsed-args)))
3842 ;; Region formatting may not provide last node position.
3843 (if texinfo-last-node-pos
3844 (1+ (count-lines texinfo-last-node-pos (point)))
3846 (symbol-value index-list)))))
3849 ;;; Properties for definitions
3851 ;; Each definition command has six properties:
3853 ;; 1. texinfo-deffn-formatting-property to format definition line
3854 ;; 2. texinfo-defun-indexing-property to create index entry
3855 ;; 3. texinfo-format formatting command
3856 ;; 4. texinfo-end end formatting command
3857 ;; 5. texinfo-defun-type type of deffn to format
3858 ;; 6. texinfo-defun-index type of index to use
3860 ;; The `x' forms of each definition command are used for the second
3861 ;; and subsequent header lines.
3863 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
3864 ;; are listed just before the appropriate formatting and indexing commands.
3866 (put 'deffn 'texinfo-format 'texinfo-format-defun)
3867 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
3868 (put 'deffn 'texinfo-end 'texinfo-end-defun)
3869 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
3870 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
3871 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
3872 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
3874 (put 'defun 'texinfo-format 'texinfo-format-defun)
3875 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
3876 (put 'defun 'texinfo-end 'texinfo-end-defun)
3877 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
3878 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
3879 (put 'defun 'texinfo-defun-index 'texinfo-findex)
3880 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
3882 (put 'defmac 'texinfo-format 'texinfo-format-defun)
3883 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
3884 (put 'defmac 'texinfo-end 'texinfo-end-defun)
3885 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
3886 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
3887 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
3888 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
3890 (put 'defspec 'texinfo-format 'texinfo-format-defun)
3891 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
3892 (put 'defspec 'texinfo-end 'texinfo-end-defun)
3893 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
3894 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
3895 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
3896 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
3898 (put 'defvr 'texinfo-format 'texinfo-format-defun)
3899 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
3900 (put 'defvr 'texinfo-end 'texinfo-end-defun)
3901 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
3902 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
3903 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
3904 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
3906 (put 'defvar 'texinfo-format 'texinfo-format-defun)
3907 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
3908 (put 'defvar 'texinfo-end 'texinfo-end-defun)
3909 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
3910 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
3911 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
3912 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
3914 (put 'defconst 'texinfo-format 'texinfo-format-defun)
3915 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
3916 (put 'defconst 'texinfo-end 'texinfo-end-defun)
3917 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
3918 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
3919 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
3920 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
3922 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
3923 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
3924 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
3925 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
3926 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
3927 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
3928 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
3930 (put 'defopt 'texinfo-format 'texinfo-format-defun)
3931 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
3932 (put 'defopt 'texinfo-end 'texinfo-end-defun)
3933 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
3934 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
3935 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
3936 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
3938 (put 'deftp 'texinfo-format 'texinfo-format-defun)
3939 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
3940 (put 'deftp 'texinfo-end 'texinfo-end-defun)
3941 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
3942 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
3943 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
3944 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
3946 ;;; Object-oriented stuff is a little hairier.
3948 (put 'defop 'texinfo-format 'texinfo-format-defun)
3949 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
3950 (put 'defop 'texinfo-end 'texinfo-end-defun)
3951 (put 'defop 'texinfo-defun-type '('defop-type nil))
3952 (put 'defopx 'texinfo-defun-type '('defop-type nil))
3953 (put 'defop 'texinfo-defun-index 'texinfo-findex)
3954 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
3956 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
3957 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
3958 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
3959 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
3960 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
3961 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
3962 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
3964 (put 'defcv 'texinfo-format 'texinfo-format-defun)
3965 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
3966 (put 'defcv 'texinfo-end 'texinfo-end-defun)
3967 (put 'defcv 'texinfo-defun-type '('defop-type nil))
3968 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
3969 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
3970 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
3972 (put 'defivar 'texinfo-format 'texinfo-format-defun)
3973 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
3974 (put 'defivar 'texinfo-end 'texinfo-end-defun)
3975 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
3976 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
3977 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
3978 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
3980 ;;; Typed functions and variables
3982 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
3983 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
3984 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
3985 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
3986 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
3987 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
3988 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
3990 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
3991 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
3992 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
3993 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
3994 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
3995 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
3996 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
3998 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
3999 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
4000 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
4001 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
4002 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
4003 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
4004 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
4006 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
4007 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
4008 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
4009 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
4010 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
4011 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
4012 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
4015 ;;; @set, @clear, @ifset, @ifclear
4017 ;; If a flag is set with @set FLAG, then text between @ifset and @end
4018 ;; ifset is formatted normally, but if the flag is cleared with
4019 ;; @clear FLAG, then the text is not formatted; it is ignored.
4021 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
4022 ;; and @end ifclear is formatted normally, but if the flag is set with
4023 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
4024 ;; is the opposite of @ifset.
4026 ;; If a flag is set to a string with @set FLAG,
4027 ;; replace @value{FLAG} with the string.
4028 ;; If a flag with a value is cleared,
4029 ;; @value{FLAG} is invalid,
4030 ;; as if there had never been any @set FLAG previously.
4032 (put 'clear 'texinfo-format 'texinfo-clear)
4033 (defun texinfo-clear ()
4034 "Clear the value of the flag."
4035 (let* ((arg (texinfo-parse-arg-discard))
4036 (flag (car (read-from-string arg)))
4037 (value (substring arg (cdr (read-from-string arg)))))
4038 (put flag 'texinfo-whether-setp 'flag-cleared)
4039 (put flag 'texinfo-set-value "")))
4041 (put 'set 'texinfo-format 'texinfo-set)
4042 (defun texinfo-set ()
4043 "Set the value of the flag, optionally to a string.
4044 The command `@set foo This is a string.'
4045 sets flag foo to the value: `This is a string.'
4046 The command `@value{foo}' expands to the value."
4047 (let* ((arg (texinfo-parse-arg-discard))
4048 (flag (car (read-from-string arg)))
4049 (value (substring arg (cdr (read-from-string arg)))))
4050 (if (string-match "^[ \t]+" value)
4051 (setq value (substring value (match-end 0))))
4052 (put flag 'texinfo-whether-setp 'flag-set)
4053 (put flag 'texinfo-set-value value)))
4055 (put 'value 'texinfo-format 'texinfo-value)
4056 (defun texinfo-value ()
4057 "Insert the string to which the flag is set.
4058 The command `@set foo This is a string.'
4059 sets flag foo to the value: `This is a string.'
4060 The command `@value{foo}' expands to the value."
4061 (let ((arg (texinfo-parse-arg-discard)))
4063 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4065 (get (car (read-from-string arg)) 'texinfo-set-value))
4066 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
4067 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4069 (insert (format "{No value for \"%s\"}" arg)))
4070 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
4071 (insert (format "{No value for \"%s\"}" arg))))))
4073 (put 'ifset 'texinfo-end 'texinfo-discard-command)
4074 (put 'ifset 'texinfo-format 'texinfo-if-set)
4075 (defun texinfo-if-set ()
4076 "If set, continue formatting; else do not format region up to @end ifset"
4077 (let ((arg (texinfo-parse-arg-discard)))
4079 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4081 ;; Format the text (i.e., do not remove it); do nothing here.
4083 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4085 ;; Clear region (i.e., cause the text to be ignored).
4086 (delete-region texinfo-command-start
4087 (re-search-forward "@end ifset[ \t]*\n")))
4088 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4090 ;; In this case flag is neither set nor cleared.
4091 ;; Act as if set, i.e. do nothing.
4094 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
4095 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
4096 (defun texinfo-if-clear ()
4097 "If clear, continue formatting; if set, do not format up to @end ifset"
4098 (let ((arg (texinfo-parse-arg-discard)))
4100 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4102 ;; Clear region (i.e., cause the text to be ignored).
4103 (delete-region texinfo-command-start
4104 (re-search-forward "@end ifclear[ \t]*\n")))
4105 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4107 ;; Format the text (i.e., do not remove it); do nothing here.
4109 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4111 ;; In this case flag is neither set nor cleared.
4112 ;; Act as if clear, i.e. do nothing.
4117 (put 'ifeq 'texinfo-format 'texinfo-format-ifeq)
4118 (defun texinfo-format-ifeq ()
4119 "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND.
4120 Otherwise produces no output.
4123 @ifeq{ arg1 , arg1 , @code{foo}} bar
4127 @ifeq{ arg1 , arg2 , @code{foo}} bar
4131 Note that the Texinfo command and its arguments must be arguments to
4133 ;; compare-buffer-substrings does not exist in version 18; don't use
4134 (goto-char texinfo-command-end)
4135 (let* ((case-fold-search t)
4136 (stop (save-excursion (forward-sexp 1) (point)))
4138 ;; @ifeq{arg1, arg2, @command{optional-args}}
4142 (skip-chars-forward " ")
4143 (setq start (point))
4144 (search-forward "," stop t)
4145 (skip-chars-backward ", ")
4146 (buffer-substring-no-properties start (point))))
4149 (search-forward "," stop t)
4150 (skip-chars-forward " ")
4151 (setq start (point))
4152 (search-forward "," stop t)
4153 (skip-chars-backward ", ")
4154 (buffer-substring-no-properties start (point))))
4157 (search-forward "," stop t)
4158 (skip-chars-forward " ")
4159 (setq start (point))
4160 (goto-char (1- stop))
4161 (skip-chars-backward " ")
4162 (buffer-substring-no-properties start (point)))))
4163 (delete-region texinfo-command-start stop)
4164 (if (equal arg1 arg2)
4165 (insert texinfo-command))
4166 (goto-char texinfo-command-start)))
4169 ;;; Process included files: `@include' command
4171 ;; Updated 19 October 1990
4172 ;; In the original version, include files were ignored by Info but
4173 ;; incorporated in to the printed manual. To make references to the
4174 ;; included file, the Texinfo source file has to refer to the included
4175 ;; files using the `(filename)nodename' format for referring to other
4176 ;; Info files. Also, the included files had to be formatted on their
4177 ;; own. It was just like they were another file.
4179 ;; Currently, include files are inserted into the buffer that is
4180 ;; formatted for Info. If large, the resulting info file is split and
4181 ;; tagified. For current include files to work, the master menu must
4182 ;; refer to all the nodes, and the highest level nodes in the include
4183 ;; files must have the correct next, prev, and up pointers.
4185 ;; The included file may have an @setfilename and even an @settitle,
4186 ;; but not an `\input texinfo' line.
4188 ;; Updated 24 March 1993
4189 ;; In order for @raisesections and @lowersections to work, included
4190 ;; files must be inserted into the buffer holding the outer file
4191 ;; before other Info formatting takes place. So @include is no longer
4192 ;; is treated like other @-commands.
4193 (put 'include 'texinfo-format 'texinfo-format-noop)
4195 ;; Original definition:
4196 ;; (defun texinfo-format-include ()
4197 ;; (let ((filename (texinfo-parse-arg-discard))
4198 ;; (default-directory input-directory)
4202 ;; (progn (find-file
4203 ;; (cond ((file-readable-p (concat filename ".texinfo"))
4204 ;; (concat filename ".texinfo"))
4205 ;; ((file-readable-p (concat filename ".texi"))
4206 ;; (concat filename ".texi"))
4207 ;; ((file-readable-p (concat filename ".tex"))
4208 ;; (concat filename ".tex"))
4209 ;; ((file-readable-p filename)
4211 ;; (t (error "@include'd file %s not found"
4213 ;; (texinfo-format-buffer-1))))
4214 ;; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
4215 ;; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
4216 ;; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
4217 ;; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
4218 ;; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
4219 ;; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
4221 ;;(defun texinfo-subindex (indexvar file content)
4222 ;; (set indexvar (cons (list 'recurse file content)
4223 ;; (symbol-value indexvar))))
4225 ;; Second definition:
4226 ;; (put 'include 'texinfo-format 'texinfo-format-include)
4227 ;; (defun texinfo-format-include ()
4228 ;; (let ((filename (concat input-directory
4229 ;; (texinfo-parse-arg-discard)))
4230 ;; (default-directory input-directory))
4231 ;; (message "Reading: %s" filename)
4233 ;; (save-restriction
4234 ;; (narrow-to-region
4236 ;; (+ (point) (car (cdr (insert-file-contents filename)))))
4237 ;; (goto-char (point-min))
4238 ;; (texinfo-append-refill)
4239 ;; (texinfo-format-convert (point-min) (point-max))))
4240 ;; (setq last-input-buffer input-buffer) ; to bypass setfilename
4244 ;;; Numerous commands do nothing in Info
4245 ;; These commands are defined in texinfo.tex for printed output.
4248 ;;; various noops, such as @b{foo}, that take arguments in braces
4250 (put 'b 'texinfo-format 'texinfo-format-noop)
4251 (put 'i 'texinfo-format 'texinfo-format-noop)
4252 (put 'r 'texinfo-format 'texinfo-format-noop)
4253 (put 't 'texinfo-format 'texinfo-format-noop)
4254 (put 'w 'texinfo-format 'texinfo-format-noop)
4255 (put 'asis 'texinfo-format 'texinfo-format-noop)
4256 (put 'dmn 'texinfo-format 'texinfo-format-noop)
4257 (put 'math 'texinfo-format 'texinfo-format-noop)
4258 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
4259 (defun texinfo-format-noop ()
4260 (insert (texinfo-parse-arg-discard))
4261 (goto-char texinfo-command-start))
4263 ;; @hyphenation command discards an argument within braces
4264 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
4265 (defun texinfo-discard-command-and-arg ()
4266 "Discard both @-command and its argument in braces."
4267 (goto-char texinfo-command-end)
4269 (setq texinfo-command-end (point))
4270 (delete-region texinfo-command-start texinfo-command-end))
4273 ;;; Do nothing commands, such as @smallbook, that have no args and no braces
4274 ;; These must appear on a line of their own
4276 (put 'bye 'texinfo-format 'texinfo-discard-line)
4277 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
4278 (put 'finalout 'texinfo-format 'texinfo-discard-line)
4279 (put 'overfullrule 'texinfo-format 'texinfo-discard-line)
4280 (put 'smallbreak 'texinfo-format 'texinfo-discard-line)
4281 (put 'medbreak 'texinfo-format 'texinfo-discard-line)
4282 (put 'bigbreak 'texinfo-format 'texinfo-discard-line)
4283 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
4284 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
4285 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
4286 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
4289 ;;; These noop commands discard the rest of the line.
4291 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
4292 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
4293 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
4294 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
4295 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
4296 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
4297 (put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args)
4298 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
4299 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
4300 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
4301 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
4302 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
4304 ;; @novalidate suppresses cross-reference checking and auxiliary file
4305 ;; creation with TeX. The Info-validate command checks that every
4306 ;; node pointer points to an existing node. Since this Info command
4307 ;; is not invoked automatically, the @novalidate command is irrelevant
4308 ;; and not supported by texinfmt.el
4309 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
4311 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
4312 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
4313 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
4314 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
4315 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
4317 (put 'setcontentsaftertitlepage
4318 'texinfo-format 'texinfo-discard-line-with-args)
4319 (put 'setshortcontentsaftertitlepage
4320 'texinfo-format 'texinfo-discard-line-with-args)
4322 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
4323 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
4324 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
4325 (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args)
4326 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
4327 (put 'input 'texinfo-format 'texinfo-discard-line-with-args)
4329 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
4330 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
4334 ;;; Some commands cannot be handled
4336 (defun texinfo-unsupported ()
4337 (error "%s is not handled by texinfo"
4338 (buffer-substring-no-properties texinfo-command-start texinfo-command-end)))
4340 ;;; Batch formatting
4342 (defun batch-texinfo-format ()
4343 "Runs texinfo-format-buffer on the files remaining on the command line.
4344 Must be used only with -batch, and kills emacs on completion.
4345 Each file will be processed even if an error occurred previously.
4347 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
4348 (if (not noninteractive)
4349 (error "batch-texinfo-format may only be used -batch"))
4350 (let ((version-control t)
4351 (auto-save-default nil)
4352 (find-file-run-dired nil)
4353 (kept-old-versions 259259)
4354 (kept-new-versions 259259))
4358 (while command-line-args-left
4359 (setq file (expand-file-name (car command-line-args-left)))
4360 (cond ((not (file-exists-p file))
4361 (message ">> %s does not exist!" file)
4363 command-line-args-left (cdr command-line-args-left)))
4364 ((file-directory-p file)
4366 (setq command-line-args-left
4367 (nconc (directory-files
4370 ;; Match only files registered for
4371 ;; texinfo-mode in auto-mode-alist.
4372 ;; This also fixes infinite recursion of
4373 ;; this function when called on
4375 ;; NB: (directory-files ...) returns
4376 ;; "." and ".." as well.
4384 (if (equal (cdr a) 'texinfo-mode)
4389 (cdr command-line-args-left))))
4391 (setq files (cons file files)
4392 command-line-args-left (cdr command-line-args-left)))))
4394 (setq file (car files)
4398 (if buffer-file-name (kill-buffer (current-buffer)))
4400 (buffer-disable-undo (current-buffer))
4401 (set-buffer-modified-p nil)
4403 (message "texinfo formatting %s..." file)
4404 (texinfo-format-buffer nil)
4405 (if (buffer-modified-p)
4406 (progn (message "Saving modified %s" (buffer-file-name))
4409 (message ">> Error: %s" (prin1-to-string err))
4410 (message ">> point at")
4411 (let ((s (buffer-substring-no-properties (point)
4412 (min (+ (point) 100)
4415 (while (setq tem (string-match "\n+" s tem))
4416 (setq s (concat (substring s 0 (match-beginning 0))
4418 (substring s (match-end 0)))
4420 (message ">> %s" s))
4422 (kill-emacs error))))
4425 ;;; Place `provide' at end of file.
4428 ;;; texinfmt.el ends here