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