(tex-start-of-header, tex-end-of-header): Add defvars.
[emacs.git] / lisp / textmodes / texinfmt.el
blob182b21d476b54c2e56986341ea0c09d527ddba00
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.40 of 6 Dec 2002")
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 ;; These come from tex-mode.el.
138 (defvar tex-start-of-header)
139 (defvar tex-end-of-header)
141 ;;;###autoload
142 (defun texinfo-format-region (region-beginning region-end)
143 "Convert the current region of the Texinfo file to Info format.
144 This lets you see what that part of the file will look like in Info.
145 The command is bound to \\[texinfo-format-region]. The text that is
146 converted to Info is stored in a temporary buffer."
147 (interactive "r")
148 (message "Converting region to Info format...")
149 (let (texinfo-command-start
150 texinfo-command-end
151 texinfo-command-name
152 texinfo-vindex
153 texinfo-findex
154 texinfo-cindex
155 texinfo-pindex
156 texinfo-tindex
157 texinfo-kindex
158 texinfo-stack
159 (texinfo-format-filename "")
160 texinfo-example-start
161 texinfo-last-node-pos
162 texinfo-last-node
163 texinfo-node-names
164 (texinfo-footnote-number 0)
165 last-input-buffer
166 (fill-column-for-info fill-column)
167 (input-buffer (current-buffer))
168 (input-directory default-directory)
169 (header-text "")
170 (header-beginning 1)
171 (header-end 1))
173 ;;; Copy lines between beginning and end of header lines,
174 ;;; if any, or else copy the `@setfilename' line, if any.
175 (save-excursion
176 (save-restriction
177 (widen)
178 (goto-char (point-min))
179 (let ((search-end (save-excursion (forward-line 100) (point))))
180 (if (or
181 ;; Either copy header text.
182 (and
183 (prog1
184 (search-forward tex-start-of-header search-end t)
185 (forward-line 1)
186 ;; Mark beginning of header.
187 (setq header-beginning (point)))
188 (prog1
189 (search-forward tex-end-of-header nil t)
190 (beginning-of-line)
191 ;; Mark end of header
192 (setq header-end (point))))
193 ;; Or copy @filename line.
194 (prog2
195 (goto-char (point-min))
196 (search-forward "@setfilename" search-end t)
197 (beginning-of-line)
198 (setq header-beginning (point))
199 (forward-line 1)
200 (setq header-end (point))))
202 ;; Copy header
203 (setq header-text
204 (buffer-substring-no-properties
205 (min header-beginning region-beginning)
206 header-end))))))
208 ;;; Find a buffer to use.
209 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
210 (erase-buffer)
211 ;; Insert the header into the buffer.
212 (insert header-text)
213 ;; Insert the region into the buffer.
214 (insert-buffer-substring
215 input-buffer
216 (max region-beginning header-end)
217 region-end)
218 ;; Make sure region ends in a newline.
219 (or (= (preceding-char) ?\n)
220 (insert "\n"))
222 (goto-char (point-min))
223 (texinfo-mode)
224 (message "Converting region to Info format...")
225 (setq fill-column fill-column-for-info)
226 ;; Install a syntax table useful for scanning command operands.
227 (set-syntax-table texinfo-format-syntax-table)
229 ;; Insert @include files so `texinfo-raise-lower-sections' can
230 ;; work on them without losing track of multiple
231 ;; @raise/@lowersections commands.
232 (while (re-search-forward "^@include" nil t)
233 (setq texinfo-command-end (point))
234 (let ((filename (concat input-directory
235 (texinfo-parse-line-arg))))
236 (re-search-backward "^@include")
237 (delete-region (point) (save-excursion (forward-line 1) (point)))
238 (message "Reading included file: %s" filename)
239 (save-excursion
240 (save-restriction
241 (narrow-to-region
242 (point)
243 (+ (point) (car (cdr (insert-file-contents filename)))))
244 (goto-char (point-min))
245 ;; Remove `@setfilename' line from included file, if any,
246 ;; so @setfilename command not duplicated.
247 (if (re-search-forward
248 "^@setfilename" (save-excursion (forward-line 100) (point)) t)
249 (progn
250 (beginning-of-line)
251 (delete-region
252 (point) (save-excursion (forward-line 1) (point)))))))))
254 ;; Raise or lower level of each section, if necessary.
255 (goto-char (point-min))
256 (texinfo-raise-lower-sections)
257 ;; Append @refill to appropriate paragraphs for filling.
258 (goto-char (point-min))
259 (texinfo-append-refill)
260 ;; If the region includes the effective end of the data,
261 ;; discard everything after that.
262 (goto-char (point-max))
263 (if (re-search-backward "^@bye" nil t)
264 (delete-region (point) (point-max)))
265 ;; Make sure buffer ends in a newline.
266 (or (= (preceding-char) ?\n)
267 (insert "\n"))
268 ;; Don't use a previous value of texinfo-enclosure-list.
269 (setq texinfo-enclosure-list nil)
270 (setq texinfo-alias-list nil)
272 (goto-char (point-min))
273 (if (looking-at "\\\\input[ \t]+texinfo")
274 (delete-region (point) (save-excursion (forward-line 1) (point))))
276 ;; Insert Info region title text.
277 (goto-char (point-min))
278 (if (search-forward
279 "@setfilename" (save-excursion (forward-line 100) (point)) t)
280 (progn
281 (setq texinfo-command-end (point))
282 (beginning-of-line)
283 (setq texinfo-command-start (point))
284 (let ((arg (texinfo-parse-arg-discard)))
285 (insert " "
286 texinfo-region-buffer-name
287 " buffer for: `")
288 (insert (file-name-nondirectory (expand-file-name arg)))
289 (insert "', -*-Text-*-\n")))
290 ;; Else no `@setfilename' line
291 (insert " "
292 texinfo-region-buffer-name
293 " buffer -*-Text-*-\n"))
294 (insert "produced by `texinfo-format-region'\n"
295 "from a region in: "
296 (if (buffer-file-name input-buffer)
297 (concat "`"
298 (file-name-sans-versions
299 (file-name-nondirectory
300 (buffer-file-name input-buffer)))
301 "'")
302 (concat "buffer `" (buffer-name input-buffer) "'"))
303 "\nusing `texinfmt.el' version "
304 texinfmt-version
305 ".\n\n")
307 ;; Now convert for real.
308 (goto-char (point-min))
309 (texinfo-format-scan)
310 (goto-char (point-min))
311 (Info-tagify input-buffer)
312 (goto-char (point-min))
313 (message "Done.")))
315 ;;;###autoload
316 (defun texi2info (&optional nosplit)
317 "Convert the current buffer (written in Texinfo code) into an Info file.
318 The Info file output is generated in a buffer visiting the Info file
319 names specified in the @setfilename command.
321 This function automatically updates all node pointers and menus, and
322 creates a master menu. This work is done on a temporary buffer that
323 is automatically removed when the Info file is created. The original
324 Texinfo source buffer is not changed.
326 Non-nil argument (prefix, if interactive) means don't split the file
327 if large. You can use Info-split to do this manually."
328 (interactive "P")
329 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" )))
330 (message "First updating nodes and menus, then creating Info file.")
331 ;; (sit-for 2)
332 (copy-to-buffer temp-buffer (point-min) (point-max))
333 (switch-to-buffer temp-buffer)
334 (texinfo-master-menu t)
335 (message "Now creating Info file.")
336 (sit-for 2)
337 (texinfo-format-buffer nosplit)
338 (save-buffer)
339 (kill-buffer temp-buffer)))
342 ;;; Primary internal formatting function for the whole buffer.
344 (defun texinfo-format-buffer-1 ()
345 (let (texinfo-format-filename
346 texinfo-example-start
347 texinfo-command-start
348 texinfo-command-end
349 texinfo-command-name
350 texinfo-last-node
351 texinfo-last-node-pos
352 texinfo-vindex
353 texinfo-findex
354 texinfo-cindex
355 texinfo-pindex
356 texinfo-tindex
357 texinfo-kindex
358 texinfo-stack
359 texinfo-node-names
360 (texinfo-footnote-number 0)
361 last-input-buffer
362 outfile
363 (fill-column-for-info fill-column)
364 (input-buffer (current-buffer))
365 (input-directory default-directory))
366 (setq texinfo-enclosure-list nil)
367 (setq texinfo-alias-list nil)
368 (save-excursion
369 (goto-char (point-min))
370 (or (search-forward "@setfilename" nil t)
371 (error "Texinfo file needs an `@setfilename FILENAME' line"))
372 (setq texinfo-command-end (point))
373 (setq outfile (texinfo-parse-line-arg)))
375 (find-file outfile)
376 (texinfo-mode)
377 (erase-buffer)
379 (message "Formatting Info file: %s" outfile)
380 (setq texinfo-format-filename
381 (file-name-nondirectory (expand-file-name outfile)))
383 (setq fill-column fill-column-for-info)
384 (set-syntax-table texinfo-format-syntax-table)
386 (insert-buffer-substring input-buffer)
387 (message "Converting %s to Info format..." (buffer-name input-buffer))
389 ;; Insert @include files so `texinfo-raise-lower-sections' can
390 ;; work on them without losing track of multiple
391 ;; @raise/@lowersections commands.
392 (goto-char (point-min))
393 (while (re-search-forward "^@include" nil t)
394 (setq texinfo-command-end (point))
395 (let ((filename (concat input-directory
396 (texinfo-parse-line-arg))))
397 (re-search-backward "^@include")
398 (delete-region (point) (save-excursion (forward-line 1) (point)))
399 (message "Reading included file: %s" filename)
400 (save-excursion
401 (save-restriction
402 (narrow-to-region
403 (point)
404 (+ (point) (car (cdr (insert-file-contents filename)))))
405 (goto-char (point-min))
406 ;; Remove `@setfilename' line from included file, if any,
407 ;; so @setfilename command not duplicated.
408 (if (re-search-forward
409 "^@setfilename"
410 (save-excursion (forward-line 100) (point)) t)
411 (progn
412 (beginning-of-line)
413 (delete-region
414 (point) (save-excursion (forward-line 1) (point)))))))))
415 ;; Raise or lower level of each section, if necessary.
416 (goto-char (point-min))
417 (texinfo-raise-lower-sections)
418 ;; Append @refill to appropriate paragraphs
419 (goto-char (point-min))
420 (texinfo-append-refill)
421 (goto-char (point-min))
422 (search-forward "@setfilename")
423 (beginning-of-line)
424 (delete-region (point-min) (point))
425 ;; Remove @bye at end of file, if it is there.
426 (goto-char (point-max))
427 (if (search-backward "@bye" nil t)
428 (delete-region (point) (point-max)))
429 ;; Make sure buffer ends in a newline.
430 (or (= (preceding-char) ?\n)
431 (insert "\n"))
432 ;; Scan the whole buffer, converting to Info format.
433 (texinfo-format-scan)
434 (goto-char (point-min))
435 ;; Insert info about how this file was made.
436 (insert "Info file: "
437 texinfo-format-filename ", -*-Text-*-\n"
438 "produced by `texinfo-format-buffer'\n"
439 ;; Date string removed so that regression testing is easier.
440 ;; "on "
441 ;; (insert (format-time-string "%e %b %Y")) " "
442 "from file"
443 (if (buffer-file-name input-buffer)
444 (concat " `"
445 (file-name-sans-versions
446 (file-name-nondirectory
447 (buffer-file-name input-buffer)))
448 "'")
449 (concat "buffer `" (buffer-name input-buffer) "'"))
450 "\nusing `texinfmt.el' version "
451 texinfmt-version
452 ".\n\n")
453 ;; Return data for indices.
454 (list outfile
455 texinfo-vindex texinfo-findex texinfo-cindex
456 texinfo-pindex texinfo-tindex texinfo-kindex)))
459 ;;; Perform non-@-command file conversions: quotes and hyphens
461 (defun texinfo-format-convert (min max)
462 ;; Convert left and right quotes to typewriter font quotes.
463 (goto-char min)
464 (while (search-forward "``" max t)
465 (replace-match "\""))
466 (goto-char min)
467 (while (search-forward "''" max t)
468 (replace-match "\""))
469 ;; Convert three hyphens in a row to two.
470 (goto-char min)
471 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
472 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
473 2)))))
476 ;;; Handle paragraph filling
478 ;; Keep as concatinated lists for ease of maintenance
480 (defvar texinfo-no-refill-regexp
481 (concat
482 "^@"
483 "\\("
484 ;; add "itemize\\|" (from experiment of 2001 Nov 28)
485 ;; because of a problem with @end itemize@refill
486 ;; I don't know if this causes other problems.
487 ;; I suspect itemized lists don't get filled properly and a
488 ;; more precise fix is required. Bob
489 "itemize\\|"
490 "direntry\\|"
491 "lisp\\|"
492 "smalllisp\\|"
493 "example\\|"
494 "smallexample\\|"
495 "display\\|"
496 "smalldisplay\\|"
497 "format\\|"
498 "smallformat\\|"
499 "flushleft\\|"
500 "flushright\\|"
501 "menu\\|"
502 "multitable\\|"
503 "titlepage\\|"
504 "iftex\\|"
505 "ifhtml\\|"
506 "tex\\|"
507 "html"
508 "\\)")
509 "Regexp specifying environments in which paragraphs are not filled.")
511 (defvar texinfo-accent-commands
512 (concat
513 "@^\\|"
514 "@`\\|"
515 "@'\\|"
516 "@\"\\|"
517 "@,\\|"
518 "@=\\|"
519 "@~\\|"
520 "@OE{\\|"
521 "@oe{\\|"
522 "@AA{\\|"
523 "@aa{\\|"
524 "@AE{\\|"
525 "@ae{\\|"
526 "@ss{\\|"
527 "@questiondown{\\|"
528 "@exclamdown{\\|"
529 "@L{\\|"
530 "@l{\\|"
531 "@O{\\|"
532 "@o{\\|"
533 "@dotaccent{\\|"
534 "@ubaraccent{\\|"
535 "@d{\\|"
536 "@H{\\|"
537 "@ringaccent{\\|"
538 "@tieaccent{\\|"
539 "@u{\\|"
540 "@v{\\|"
541 "@dotless{"
544 (defvar texinfo-part-of-para-regexp
545 (concat
546 "^@"
547 "\\("
548 "b{\\|"
549 "bullet{\\|"
550 "cite{\\|"
551 "code{\\|"
552 "email{\\|"
553 "emph{\\|"
554 "equiv{\\|"
555 "error{\\|"
556 "expansion{\\|"
557 "file{\\|"
558 "i{\\|"
559 "inforef{\\|"
560 "kbd{\\|"
561 "key{\\|"
562 "lisp{\\|"
563 "minus{\\|"
564 "point{\\|"
565 "print{\\|"
566 "pxref{\\|"
567 "r{\\|"
568 "ref{\\|"
569 "result{\\|"
570 "samp{\\|"
571 "sc{\\|"
572 "t{\\|"
573 "TeX{\\|"
574 "today{\\|"
575 "url{\\|"
576 "var{\\|"
577 "w{\\|"
578 "xref{\\|"
579 "@-\\|" ; @- is a descretionary hyphen (not an accent) (a noop).
580 texinfo-accent-commands
581 "\\)"
583 "Regexp specifying @-commands found within paragraphs.")
585 (defun texinfo-append-refill ()
586 "Append @refill at end of each paragraph that should be filled.
587 Do not append @refill to paragraphs within @example and similar environments.
588 Do not append @refill to paragraphs containing @w{TEXT} or @*."
590 ;; It is necessary to append @refill before other processing because
591 ;; the other processing removes information that tells Texinfo
592 ;; whether the text should or should not be filled.
594 (while (< (point) (point-max))
595 (let ((refill-blank-lines "^[ \t\n]*$")
596 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
597 (beginning-of-line)
598 ;; 1. Skip over blank lines;
599 ;; skip over lines beginning with @-commands,
600 ;; but do not skip over lines
601 ;; that are no-refill environments such as @example or
602 ;; that begin with within-paragraph @-commands such as @code.
603 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
604 (not (looking-at
605 (concat
606 "\\("
607 texinfo-no-refill-regexp
608 "\\|"
609 texinfo-part-of-para-regexp
610 "\\)")))
611 (< (point) (point-max)))
612 (forward-line 1))
613 ;; 2. Skip over @example and similar no-refill environments.
614 (if (looking-at texinfo-no-refill-regexp)
615 (let ((environment
616 (buffer-substring-no-properties (match-beginning 1) (match-end 1))))
617 (progn (re-search-forward (concat "^@end " environment) nil t)
618 (forward-line 1)))
619 ;; Else
620 ;; 3. Do not refill a paragraph containing @w or @*, or ending
621 ;; with @<newline> followed by a newline.
622 (if (or
623 (>= (point) (point-max))
624 (re-search-forward
625 "@w{\\|@\\*\\|@\n\n"
626 (save-excursion
627 (forward-paragraph)
628 (forward-line 1)
629 (point)) t))
630 ;; Go to end of paragraph and do nothing.
631 (forward-paragraph)
632 ;; 4. Else go to end of paragraph and insert @refill
633 (forward-paragraph)
634 (forward-line -1)
635 (let ((line-beg (point)))
636 (end-of-line)
637 (delete-region
638 (point)
639 (save-excursion (skip-chars-backward " \t") (point)))
640 (forward-char 1)
641 (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t)
642 (forward-char -1))
643 (unless (re-search-backward "@refill\\|@bye" line-beg t)
644 (insert "@refill")))
645 (forward-line 1))))))
648 ;;; Handle `@raisesections' and `@lowersections' commands
650 ;; These commands change the hierarchical level of chapter structuring
651 ;; commands.
653 ;; @raisesections changes @subsection to @section,
654 ;; @section to @chapter,
655 ;; etc.
657 ;; @lowersections changes @chapter to @section
658 ;; @subsection to @subsubsection,
659 ;; etc.
661 ;; An @raisesections/@lowersections command changes only those
662 ;; structuring commands that follow the @raisesections/@lowersections
663 ;; command.
665 ;; Repeated @raisesections/@lowersections continue to raise or lower
666 ;; the heading level.
668 ;; An @lowersections command cancels an @raisesections command, and
669 ;; vice versa.
671 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
672 ;; trying to do so does not elicit an error---you just get more
673 ;; headings that mean the same thing as you keep raising or lowering
674 ;; (for example, after a single @raisesections, both @chapter and
675 ;; @section produce chapter headings).
677 (defun texinfo-raise-lower-sections ()
678 "Raise or lower the hierarchical level of chapters, sections, etc.
680 This function acts according to `@raisesections' and `@lowersections'
681 commands in the Texinfo file.
683 For example, an `@lowersections' command is useful if you wish to
684 include what is written as an outer or standalone Texinfo file in
685 another Texinfo file as an inner, included file. The `@lowersections'
686 command changes chapters to sections, sections to subsections and so
689 @raisesections changes @subsection to @section,
690 @section to @chapter,
691 @heading to @chapheading,
692 etc.
694 @lowersections changes @chapter to @section,
695 @subsection to @subsubsection,
696 @heading to @subheading,
697 etc.
699 An `@raisesections' or `@lowersections' command changes only those
700 structuring commands that follow the `@raisesections' or
701 `@lowersections' command.
703 An `@lowersections' command cancels an `@raisesections' command, and
704 vice versa.
706 Repeated use of the commands continue to raise or lower the hierarchical
707 level a step at a time.
709 An attempt to raise above `chapters' reproduces chapter commands; an
710 attempt to lower below subsubsections reproduces subsubsection
711 commands."
713 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
714 ;; it is a regexp matching chapter, section, other headings
715 ;; (but not the top node).
717 (let (type (level 0))
718 (while
719 (re-search-forward
720 (concat
721 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
722 texinfo-section-types-regexp
723 "\\)\\)")
724 nil t)
725 (beginning-of-line)
726 (save-excursion (setq type (read (current-buffer))))
727 (cond
729 ;; 1. Increment level
730 ((eq type '@raisesections)
731 (setq level (1+ level))
732 (delete-region
733 (point) (save-excursion (forward-line 1) (point))))
735 ;; 2. Decrement level
736 ((eq type '@lowersections)
737 (setq level (1- level))
738 (delete-region
739 (point) (save-excursion (forward-line 1) (point))))
741 ;; Now handle structuring commands
742 ((cond
744 ;; 3. Raise level when positive
745 ((> level 0)
746 (let ((count level)
747 (new-level type))
748 (while (> count 0)
749 (setq new-level
750 (cdr (assq new-level texinfo-raisesections-alist)))
751 (setq count (1- count)))
752 (kill-word 1)
753 (insert (symbol-name new-level))))
755 ;; 4. Do nothing except move point when level is zero
756 ((= level 0) (forward-line 1))
758 ;; 5. Lower level when positive
759 ((< level 0)
760 (let ((count level)
761 (new-level type))
762 (while (< count 0)
763 (setq new-level
764 (cdr (assq new-level texinfo-lowersections-alist)))
765 (setq count (1+ count)))
766 (kill-word 1)
767 (insert (symbol-name new-level))))))))))
769 (defvar texinfo-raisesections-alist
770 '((@chapter . @chapter) ; Cannot go higher
771 (@unnumbered . @unnumbered)
772 (@centerchap . @unnumbered)
774 (@majorheading . @majorheading)
775 (@chapheading . @chapheading)
776 (@appendix . @appendix)
778 (@section . @chapter)
779 (@unnumberedsec . @unnumbered)
780 (@heading . @chapheading)
781 (@appendixsec . @appendix)
783 (@subsection . @section)
784 (@unnumberedsubsec . @unnumberedsec)
785 (@subheading . @heading)
786 (@appendixsubsec . @appendixsec)
788 (@subsubsection . @subsection)
789 (@unnumberedsubsubsec . @unnumberedsubsec)
790 (@subsubheading . @subheading)
791 (@appendixsubsubsec . @appendixsubsec))
792 "*An alist of next higher levels for chapters, sections. etc.
793 For example, section to chapter, subsection to section.
794 Used by `texinfo-raise-lower-sections'.
795 The keys specify types of section; the values correspond to the next
796 higher types.")
798 (defvar texinfo-lowersections-alist
799 '((@chapter . @section)
800 (@unnumbered . @unnumberedsec)
801 (@centerchap . @unnumberedsec)
802 (@majorheading . @heading)
803 (@chapheading . @heading)
804 (@appendix . @appendixsec)
806 (@section . @subsection)
807 (@unnumberedsec . @unnumberedsubsec)
808 (@heading . @subheading)
809 (@appendixsec . @appendixsubsec)
811 (@subsection . @subsubsection)
812 (@unnumberedsubsec . @unnumberedsubsubsec)
813 (@subheading . @subsubheading)
814 (@appendixsubsec . @appendixsubsubsec)
816 (@subsubsection . @subsubsection) ; Cannot go lower.
817 (@unnumberedsubsubsec . @unnumberedsubsubsec)
818 (@subsubheading . @subsubheading)
819 (@appendixsubsubsec . @appendixsubsubsec))
820 "*An alist of next lower levels for chapters, sections. etc.
821 For example, chapter to section, section to subsection.
822 Used by `texinfo-raise-lower-sections'.
823 The keys specify types of section; the values correspond to the next
824 lower types.")
827 ;;; Perform those texinfo-to-info conversions that apply to the whole input
828 ;;; uniformly.
830 (defun texinfo-format-scan ()
831 (texinfo-format-convert (point-min) (point-max))
832 ;; Search for @copying, which has to be first since the
833 ;; @insertcopying command then inserts the text elsewhere.
834 (goto-char (point-min))
835 (when (search-forward "@copying" nil t)
836 (texinfo-copying))
837 (while (search-forward "@insertcopying" nil t)
838 (delete-region (match-beginning 0) (match-end 0))
840 (texinfo-insertcopying))
841 ;; Scan for other @-commands.
842 (goto-char (point-min))
843 (while (search-forward "@" nil t)
845 ;; These are the single-character accent commands: @^ @` @' @" @= @~
846 ;; In Info, they are simply quoted and the @ deleted.
847 ;; Other single-character commands:
848 ;; @* forces a line break,
849 ;; @- is a discretionary hyphenation point; does nothing in Info.
850 ;; @<space>, @<tab>, @<newline> each produce a single space,
851 ;; unless followed by a newline.
853 ;; Old version 2.34 expression: (looking-at "[@{}^'` *\"?!]")
854 (if (looking-at "[@{}^'`\"=~ \t\n*?!-]")
855 ;; @*, causes a line break.
856 (cond
857 ;; @*, a line break
858 ((= (following-char) ?*)
859 ;; remove command
860 (delete-region (1- (point)) (1+ (point)))
861 ;; insert return if not at end of line;
862 ;; else line is already broken.
863 (if (not (= (following-char) ?\n))
864 (insert ?\n)))
865 ;; @-, deleted
866 ((= (following-char) ?-)
867 (delete-region (1- (point)) (1+ (point))))
868 ;; @<space>, @<tab>, @<newline>: produce a single space,
869 ;; unless followed by a newline.
870 ((= (following-char) ? )
871 (delete-region (1- (point)) (1+ (point)))
872 ;; insert single space if not at end of line;
873 ;; else line is already broken.
874 (if (not (= (following-char) ?\n))
875 (insert ? )))
876 ((= (following-char) ?\t)
877 (delete-region (1- (point)) (1+ (point)))
878 ;; insert single space if not at end of line;
879 ;; else line is already broken.
880 (if (not (= (following-char) ?\n))
881 (insert ? )))
882 ;; following char is a carriage return
883 ((= (following-char) ?\n)
884 ;; remove command
885 (delete-region (1- (point)) (1+ (point)))
886 ;; insert single space if not at end of line;
887 ;; else line is already broken.
888 (if (not (= (following-char) ?\n))
889 (insert ? )))
890 ;; Otherwise: the other characters are simply quoted. Delete the @.
892 (delete-char -1)
893 ;; Be compatible with makeinfo: if @' and its ilk are
894 ;; followed by a @ without a brace, barf.
895 (if (looking-at "[\"'^`~=]")
896 (progn
897 (if (= (char-after (1+ (point))) ?@)
898 (error "Use braces to give a command as an argument to @%c"
899 (following-char)))
900 (forward-char 1)
901 ;; @' etc. can optionally accept their argument in
902 ;; braces (makeinfo supports that).
903 (when (looking-at "{")
904 (let ((start (point)))
905 (forward-list 1)
906 (delete-char -1)
907 (goto-char start)
908 (delete-char 1))))
909 (forward-char 1))))
910 ;; @ is followed by a command-word; find the end of the word.
911 (setq texinfo-command-start (1- (point)))
912 (if (= (char-syntax (following-char)) ?w)
913 (forward-word 1)
914 (forward-char 1))
915 (setq texinfo-command-end (point))
916 ;; Detect the case of two @-commands in a row;
917 ;; process just the first one.
918 (goto-char (1+ texinfo-command-start))
919 (skip-chars-forward "^@" texinfo-command-end)
920 (setq texinfo-command-end (point))
921 ;; Handle let aliasing
922 (setq texinfo-command-name
923 (let (trial
924 (cmdname
925 (buffer-substring-no-properties
926 (1+ texinfo-command-start) texinfo-command-end)))
927 (while (setq trial (assoc cmdname texinfo-alias-list))
928 (setq cmdname (cdr trial)))
929 (intern cmdname)))
930 ;; Call the handler for this command.
931 (let ((enclosure-type
932 (assoc
933 (symbol-name texinfo-command-name)
934 texinfo-enclosure-list)))
935 (if enclosure-type
936 (progn
937 (insert
938 (car (car (cdr enclosure-type)))
939 (texinfo-parse-arg-discard)
940 (car (cdr (car (cdr enclosure-type)))))
941 (goto-char texinfo-command-start))
942 (let ((cmd (get texinfo-command-name 'texinfo-format)))
943 (if cmd (funcall cmd) (texinfo-unsupported)))))))
945 (cond (texinfo-stack
946 (goto-char (nth 2 (car texinfo-stack)))
947 (error "Unterminated @%s" (car (car texinfo-stack)))))
949 ;; Remove excess whitespace
950 (whitespace-cleanup))
952 (defvar texinfo-copying-text ""
953 "Text of the copyright notice and copying permissions.")
955 (defun texinfo-copying ()
956 "Copy the copyright notice and copying permissions from the Texinfo file,
957 as indicated by the @copying ... @end copying command;
958 insert the text with the @insertcopying command."
959 (let ((beg (progn (beginning-of-line) (point)))
960 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
961 (setq texinfo-copying-text
962 (buffer-substring-no-properties
963 (save-excursion (goto-char beg) (forward-line 1) (point))
964 (save-excursion (goto-char end) (forward-line -1) (point))))
965 (delete-region beg end)))
967 (defun texinfo-insertcopying ()
968 "Insert the copyright notice and copying permissions from the Texinfo file,
969 which are indicated by the @copying ... @end copying command."
970 (insert (concat "\n" texinfo-copying-text)))
972 (put 'begin 'texinfo-format 'texinfo-format-begin)
973 (defun texinfo-format-begin ()
974 (texinfo-format-begin-end 'texinfo-format))
976 (put 'end 'texinfo-format 'texinfo-format-end)
977 (defun texinfo-format-end ()
978 (texinfo-format-begin-end 'texinfo-end))
980 (defun texinfo-format-begin-end (prop)
981 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
982 (let ((cmd (get texinfo-command-name prop)))
983 (if cmd (funcall cmd)
984 (texinfo-unsupported))))
986 ;;; Parsing functions
988 (defun texinfo-parse-line-arg ()
989 "Return argument of @-command as string.
990 Argument is separated from command either by a space or by a brace.
991 If a space, return rest of line, with beginning and ending white
992 space removed. If a brace, return string between braces.
993 Leave point after argument."
994 (goto-char texinfo-command-end)
995 (let ((start (point)))
996 (cond ((looking-at " ")
997 (skip-chars-forward " ")
998 (setq start (point))
999 (end-of-line)
1000 (skip-chars-backward " ")
1001 (delete-region (point) (progn (end-of-line) (point)))
1002 (setq texinfo-command-end (1+ (point))))
1003 ((looking-at "{")
1004 (setq start (1+ (point)))
1005 (forward-list 1)
1006 (setq texinfo-command-end (point))
1007 (forward-char -1))
1009 (error "Invalid texinfo command arg format")))
1010 (prog1 (buffer-substring-no-properties start (point))
1011 (if (eolp) (forward-char 1)))))
1013 (defun texinfo-parse-expanded-arg ()
1014 (goto-char texinfo-command-end)
1015 (let ((start (point))
1016 marker)
1017 (cond ((looking-at " ")
1018 (skip-chars-forward " ")
1019 (setq start (point))
1020 (end-of-line)
1021 (setq texinfo-command-end (1+ (point))))
1022 ((looking-at "{")
1023 (setq start (1+ (point)))
1024 (forward-list 1)
1025 (setq texinfo-command-end (point))
1026 (forward-char -1))
1028 (error "Invalid texinfo command arg format")))
1029 (setq marker (move-marker (make-marker) texinfo-command-end))
1030 (texinfo-format-expand-region start (point))
1031 (setq texinfo-command-end (marker-position marker))
1032 (move-marker marker nil)
1033 (prog1 (buffer-substring-no-properties start (point))
1034 (if (eolp) (forward-char 1)))))
1036 (defun texinfo-format-expand-region (start end)
1037 (save-restriction
1038 (narrow-to-region start end)
1039 (let (texinfo-command-start
1040 texinfo-command-end
1041 texinfo-command-name
1042 texinfo-stack)
1043 (texinfo-format-scan))
1044 (goto-char (point-max))))
1046 (defun texinfo-parse-arg-discard ()
1047 "Delete command and argument; return argument of command."
1048 (prog1 (texinfo-parse-line-arg)
1049 (texinfo-discard-command)))
1051 (defun texinfo-discard-command ()
1052 (delete-region texinfo-command-start texinfo-command-end))
1054 (defun texinfo-optional-braces-discard ()
1055 "Discard braces following command, if any."
1056 (goto-char texinfo-command-end)
1057 (let ((start (point)))
1058 (cond ((looking-at "[ \t]*\n")) ; do nothing
1059 ((looking-at "{") ; remove braces, if any
1060 (forward-list 1)
1061 (setq texinfo-command-end (point)))
1063 (error
1064 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
1065 (delete-region texinfo-command-start texinfo-command-end)))
1067 (defun texinfo-format-parse-line-args ()
1068 (let ((start (1- (point)))
1069 next beg end
1070 args)
1071 (skip-chars-forward " ")
1072 (while (not (eolp))
1073 (setq beg (point))
1074 (re-search-forward "[\n,]")
1075 (setq next (point))
1076 (if (bolp) (setq next (1- next)))
1077 (forward-char -1)
1078 (skip-chars-backward " ")
1079 (setq end (point))
1080 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end))
1081 args))
1082 (goto-char next)
1083 (skip-chars-forward " "))
1084 (if (eolp) (forward-char 1))
1085 (setq texinfo-command-end (point))
1086 (nreverse args)))
1088 (defun texinfo-format-parse-args ()
1089 (let ((start (1- (point)))
1090 next beg end
1091 args)
1092 (search-forward "{")
1093 (save-excursion
1094 (texinfo-format-expand-region
1095 (point)
1096 (save-excursion (up-list 1) (1- (point)))))
1097 ;; The following does not handle cross references of the form:
1098 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
1099 ;; re-search-forward finds the first right brace after the second
1100 ;; comma.
1101 (while (/= (preceding-char) ?\})
1102 (skip-chars-forward " \t\n")
1103 (setq beg (point))
1104 (re-search-forward "[},]")
1105 (setq next (point))
1106 (forward-char -1)
1107 (skip-chars-backward " \t\n")
1108 (setq end (point))
1109 (cond ((< beg end)
1110 (goto-char beg)
1111 (while (search-forward "\n" end t)
1112 (replace-match " "))))
1113 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end))
1114 args))
1115 (goto-char next))
1116 ;;(if (eolp) (forward-char 1))
1117 (setq texinfo-command-end (point))
1118 (nreverse args)))
1120 (defun texinfo-format-parse-defun-args ()
1121 (goto-char texinfo-command-end)
1122 (let ((start (point)))
1123 (end-of-line)
1124 (setq texinfo-command-end (1+ (point)))
1125 (let ((marker (move-marker (make-marker) texinfo-command-end)))
1126 (texinfo-format-expand-region start (point))
1127 (setq texinfo-command-end (marker-position marker))
1128 (move-marker marker nil))
1129 (goto-char start)
1130 (let ((args '())
1131 beg end)
1132 (skip-chars-forward " ")
1133 (while (not (eolp))
1134 (cond ((looking-at "{")
1135 (setq beg (1+ (point)))
1136 (forward-list 1)
1137 (setq end (1- (point))))
1139 (setq beg (point))
1140 (re-search-forward "[\n ]")
1141 (forward-char -1)
1142 (setq end (point))))
1143 (setq args (cons (buffer-substring-no-properties beg end) args))
1144 (skip-chars-forward " "))
1145 (forward-char 1)
1146 (nreverse args))))
1148 (defun texinfo-discard-line ()
1149 (goto-char texinfo-command-end)
1150 (skip-chars-forward " \t")
1151 (or (eolp)
1152 (error "Extraneous text at end of command line"))
1153 (goto-char texinfo-command-start)
1154 (or (bolp)
1155 (error "Extraneous text at beginning of command line"))
1156 (delete-region (point) (progn (forward-line 1) (point))))
1158 (defun texinfo-discard-line-with-args ()
1159 (goto-char texinfo-command-start)
1160 (delete-region (point) (progn (forward-line 1) (point))))
1163 ;;; @setfilename
1165 ;; Only `texinfo-format-buffer' handles @setfilename with this
1166 ;; definition; `texinfo-format-region' handles @setfilename, if any,
1167 ;; specially.
1168 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
1169 (defun texinfo-format-setfilename ()
1170 (texinfo-parse-arg-discard))
1172 ;;; @node, @menu, @detailmenu
1174 (put 'node 'texinfo-format 'texinfo-format-node)
1175 (put 'nwnode 'texinfo-format 'texinfo-format-node)
1176 (defun texinfo-format-node ()
1177 (let* ((args (texinfo-format-parse-line-args))
1178 (name (nth 0 args))
1179 (next (nth 1 args))
1180 (prev (nth 2 args))
1181 (up (nth 3 args)))
1182 (texinfo-discard-command)
1183 (setq texinfo-last-node name)
1184 (let ((tem (if texinfo-fold-nodename-case (downcase name) name)))
1185 (if (assoc tem texinfo-node-names)
1186 (error "Duplicate node name: %s" name)
1187 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
1188 (setq texinfo-footnote-number 0)
1189 ;; insert "\n\^_" unconditionally since this is what info is looking for
1190 (insert "\n\^_\nFile: " texinfo-format-filename
1191 ", Node: " name)
1192 (if next
1193 (insert ", Next: " next))
1194 (if prev
1195 (insert ", Prev: " prev))
1196 (if up
1197 (insert ", Up: " up))
1198 (insert ?\n)
1199 (setq texinfo-last-node-pos (point))))
1201 (put 'anchor 'texinfo-format 'texinfo-anchor)
1202 (defun texinfo-anchor ()
1203 (let (anchor-string
1204 (here (- (point) 7)) ; save location of beginning of `@anchor'
1205 (arg (texinfo-parse-arg-discard)))
1206 (if (looking-at " ") ; since a space may be left after -discard
1207 (delete-char 1))
1208 (forward-paragraph)
1209 (let ((end (point)))
1210 (if (save-excursion
1211 (backward-word 1)
1212 (search-forward "@refill" end t))
1213 (setq anchor-string "@anchor-yes-refill")
1214 (setq anchor-string "@anchor-no-refill")))
1215 (goto-char here)
1216 (insert anchor-string "{" arg "}")))
1218 (put 'menu 'texinfo-format 'texinfo-format-menu)
1219 (defun texinfo-format-menu ()
1220 (texinfo-discard-line)
1221 (insert "* Menu:\n\n"))
1223 (put 'menu 'texinfo-end 'texinfo-discard-command)
1225 ;; The @detailmenu should be removed eventually.
1227 ;; According to Karl Berry, 31 August 1996:
1229 ;; You don't like, I don't like it. I agree, it would be better just to
1230 ;; fix the bug [in `makeinfo']. .. At this point, since inserting those
1231 ;; two commands in the Elisp fn is trivial, I don't especially want to
1232 ;; expend more effort...
1234 ;; I added a couple sentences of documentation to the manual (putting the
1235 ;; blame on makeinfo where it belongs :-().
1237 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
1238 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
1240 ;; (Also see `texnfo-upd.el')
1243 ;;; Cross references
1245 ;; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
1246 ;; -> *Note FNAME: (FILE)NODE
1247 ;; If FILE is missing,
1248 ;; *Note FNAME: NODE
1249 ;; If FNAME is empty and NAME is present
1250 ;; *Note NAME: Node
1251 ;; If both NAME and FNAME are missing
1252 ;; *Note NODE::
1253 ;; texinfo ignores the DOCUMENT argument.
1254 ;; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1255 ;; If FILE is specified, (FILE)NODE is used for xrefs.
1256 ;; If fifth argument DOCUMENT is specified, produces
1257 ;; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
1258 ;; of DOCUMENT
1260 ;; @ref a reference that does not put `See' or `see' in
1261 ;; the hardcopy and is the same as @xref in Info
1262 (put 'ref 'texinfo-format 'texinfo-format-xref)
1264 (put 'xref 'texinfo-format 'texinfo-format-xref)
1265 (defun texinfo-format-xref ()
1266 (let ((args (texinfo-format-parse-args)))
1267 (texinfo-discard-command)
1268 (insert "*Note ")
1269 (let ((fname (or (nth 1 args) (nth 2 args))))
1270 (if (null (or fname (nth 3 args)))
1271 (insert (car args) "::")
1272 (insert (or fname (car args)) ": ")
1273 (if (nth 3 args)
1274 (insert "(" (nth 3 args) ")"))
1275 (and (car args) (insert (car args)))))))
1277 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
1278 (defun texinfo-format-pxref ()
1279 (texinfo-format-xref)
1280 (or (save-excursion
1281 (forward-char -2)
1282 (looking-at "::"))
1283 (insert ".")))
1285 ;; @inforef{NODE, FNAME, FILE}
1286 ;; Like @xref{NODE, FNAME,,FILE} in texinfo.
1287 ;; In Tex, generates "See Info file FILE, node NODE"
1288 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
1289 (defun texinfo-format-inforef ()
1290 (let ((args (texinfo-format-parse-args)))
1291 (texinfo-discard-command)
1292 (if (nth 1 args)
1293 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
1294 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
1297 ;;; URL Reference: @uref
1299 ;; @uref produces a reference to a uniform resource locator (URL).
1300 ;; It takes one mandatory argument, the URL, and one optional argument,
1301 ;; the text to display (the default is the URL itself).
1303 (put 'uref 'texinfo-format 'texinfo-format-uref)
1304 (defun texinfo-format-uref ()
1305 "Format URL and optional URL-TITLE.
1306 Insert ` ... ' around URL if no URL-TITLE argument;
1307 otherwise, insert URL-TITLE followed by URL in parentheses."
1308 (let ((args (texinfo-format-parse-args)))
1309 (texinfo-discard-command)
1310 ;; if url-title
1311 (if (nth 1 args)
1312 (insert (nth 1 args) " (" (nth 0 args) ")")
1313 (insert "`" (nth 0 args) "'"))
1314 (goto-char texinfo-command-start)))
1317 ;;; Section headings
1319 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
1320 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
1321 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
1322 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
1323 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1324 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1325 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1326 (put 'top 'texinfo-format 'texinfo-format-chapter)
1327 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1328 (put 'centerchap 'texinfo-format 'texinfo-format-chapter)
1329 (defun texinfo-format-chapter ()
1330 (texinfo-format-chapter-1 ?*))
1332 (put 'heading 'texinfo-format 'texinfo-format-section)
1333 (put 'isection 'texinfo-format 'texinfo-format-section)
1334 (put 'section 'texinfo-format 'texinfo-format-section)
1335 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1336 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1337 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1338 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1339 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1340 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1341 (defun texinfo-format-section ()
1342 (texinfo-format-chapter-1 ?=))
1344 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1345 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1346 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1347 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1348 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1349 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1350 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1351 (defun texinfo-format-subsection ()
1352 (texinfo-format-chapter-1 ?-))
1354 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1355 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1356 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1357 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1358 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1359 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1360 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1361 (defun texinfo-format-subsubsection ()
1362 (texinfo-format-chapter-1 ?.))
1364 (defun texinfo-format-chapter-1 (belowchar)
1365 (let ((arg (texinfo-parse-arg-discard)))
1366 (message "Formatting: %s ... " arg) ; So we can see where we are.
1367 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1368 (forward-line -2)))
1370 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1371 (defun texinfo-format-sectionpad ()
1372 (let ((str (texinfo-parse-arg-discard)))
1373 (forward-char -1)
1374 (let ((column (current-column)))
1375 (forward-char 1)
1376 (while (> column 0)
1377 (insert str)
1378 (setq column (1- column))))
1379 (insert ?\n)))
1382 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1384 (put '\. 'texinfo-format 'texinfo-format-\.)
1385 (defun texinfo-format-\. ()
1386 (texinfo-discard-command)
1387 (insert "."))
1389 (put '\: 'texinfo-format 'texinfo-format-\:)
1390 (defun texinfo-format-\: ()
1391 (texinfo-discard-command))
1393 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
1394 (defun texinfo-format-soft-hyphen ()
1395 (texinfo-discard-command))
1398 ;;; @kbdinputstyle, @vskip, headings & footings
1399 ;; These commands for not for Info and should never
1400 ;; appear in an Info environment; but if they do,
1401 ;; this causes them to be discarded.
1403 ;; @kbdinputstyle
1404 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
1406 ;; @vskip
1407 (put 'vskip 'texinfo-format 'texinfo-discard-line-with-args)
1409 ;; headings & footings
1410 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
1411 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
1412 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
1413 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
1414 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
1415 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
1418 ;;; @documentdescription ... @end documentdescription
1419 ;; This command is for HTML output and should never
1420 ;; appear in an Info environment; but if it does,
1421 ;; this causes it to be discarded.
1423 (put 'documentdescription 'texinfo-format 'texinfo-format-documentdescription)
1424 (defun texinfo-format-documentdescription ()
1425 (delete-region texinfo-command-start
1426 (progn (re-search-forward "^@end documentdescription[ \t]*\n")
1427 (point))))
1431 ;;; @center, @sp, and @br
1433 (put 'center 'texinfo-format 'texinfo-format-center)
1434 (defun texinfo-format-center ()
1435 (let ((arg (texinfo-parse-expanded-arg)))
1436 (texinfo-discard-command)
1437 (insert arg)
1438 (insert ?\n)
1439 (save-restriction
1440 (goto-char (1- (point)))
1441 (let ((indent-tabs-mode nil))
1442 (center-line)))))
1444 (put 'sp 'texinfo-format 'texinfo-format-sp)
1445 (defun texinfo-format-sp ()
1446 (let* ((arg (texinfo-parse-arg-discard))
1447 (num (read arg)))
1448 (insert-char ?\n num)))
1450 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1451 (defun texinfo-format-paragraph-break ()
1452 "Force a paragraph break.
1453 If used within a line, follow `@br' with braces."
1454 (texinfo-optional-braces-discard)
1455 ;; insert one return if at end of line;
1456 ;; else insert two returns, to generate a blank line.
1457 (if (= (following-char) ?\n)
1458 (insert ?\n)
1459 (insert-char ?\n 2)))
1462 ;;; @footnote and @footnotestyle
1464 ;; In Texinfo, footnotes are created with the `@footnote' command.
1465 ;; This command is followed immediately by a left brace, then by the text of
1466 ;; the footnote, and then by a terminating right brace. The
1467 ;; template for a footnote is:
1469 ;; @footnote{TEXT}
1471 ;; Info has two footnote styles:
1473 ;; * In the End of node style, all the footnotes for a single node
1474 ;; are placed at the end of that node. The footnotes are
1475 ;; separated from the rest of the node by a line of dashes with
1476 ;; the word `Footnotes' within it.
1478 ;; * In the Separate node style, all the footnotes for a single node
1479 ;; are placed in an automatically constructed node of their own.
1481 ;; Footnote style is specified by the @footnotestyle command, either
1482 ;; @footnotestyle separate
1483 ;; or
1484 ;; @footnotestyle end
1486 ;; The default is separate
1488 (defvar texinfo-footnote-style "separate"
1489 "Footnote style, either separate or end.")
1491 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1492 (defun texinfo-footnotestyle ()
1493 "Specify whether footnotes are at end of node or in separate nodes.
1494 Argument is either end or separate."
1495 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1497 (defvar texinfo-footnote-number)
1499 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1500 (defun texinfo-format-footnote ()
1501 "Format a footnote in either end of node or separate node style.
1502 The texinfo-footnote-style variable controls which style is used."
1503 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1504 (cond ((string= texinfo-footnote-style "end")
1505 (texinfo-format-end-node))
1506 ((string= texinfo-footnote-style "separate")
1507 (texinfo-format-separate-node))))
1509 (defun texinfo-format-separate-node ()
1510 "Format footnote in Separate node style, with notes in own node.
1511 The node is constructed automatically."
1512 (let* (start
1513 (arg (texinfo-parse-line-arg))
1514 (node-name-beginning
1515 (save-excursion
1516 (re-search-backward
1517 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1518 (match-end 0)))
1519 (node-name
1520 (save-excursion
1521 (buffer-substring-no-properties
1522 (progn (goto-char node-name-beginning) ; skip over node command
1523 (skip-chars-forward " \t") ; and over spaces
1524 (point))
1525 (if (search-forward
1527 (save-excursion (end-of-line) (point)) t) ; bound search
1528 (1- (point))
1529 (end-of-line) (point))))))
1530 (texinfo-discard-command) ; remove or insert whitespace, as needed
1531 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1532 (point))
1533 (insert (format " (%d) (*Note %s-Footnotes::)"
1534 texinfo-footnote-number node-name))
1535 (fill-paragraph nil)
1536 (save-excursion
1537 (if (re-search-forward "^@node" nil 'move)
1538 (forward-line -1))
1540 ;; two cases: for the first footnote, we must insert a node header;
1541 ;; for the second and subsequent footnotes, we need only insert
1542 ;; the text of the footnote.
1544 (if (save-excursion
1545 (search-backward
1546 (concat node-name "-Footnotes, Up: ")
1547 node-name-beginning
1549 (progn ; already at least one footnote
1550 (setq start (point))
1551 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1552 (fill-region start (point)))
1553 ;; else not yet a footnote
1554 (insert "\n\^_\nFile: " texinfo-format-filename
1555 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1556 (setq start (point))
1557 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1558 (fill-region start (point))))))
1560 (defun texinfo-format-end-node ()
1561 "Format footnote in the End of node style, with notes at end of node."
1562 (let (start
1563 (arg (texinfo-parse-line-arg)))
1564 (texinfo-discard-command) ; remove or insert whitespace, as needed
1565 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1566 (point))
1567 (insert (format " (%d) " texinfo-footnote-number))
1568 (fill-paragraph nil)
1569 (save-excursion
1570 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1571 (progn ; already have footnote, put new one before end of node
1572 (if (re-search-forward "^@node" nil 'move)
1573 (forward-line -1))
1574 (setq start (point))
1575 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1576 (fill-region start (point)))
1577 ;; else no prior footnote
1578 (if (re-search-forward "^@node" nil 'move)
1579 (forward-line -1))
1580 (insert "\n--------- Footnotes ---------\n")
1581 (setq start (point))
1582 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1585 ;;; @itemize, @enumerate, and similar commands
1587 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1588 ;; @enumerate pushes (enumerate 0 STARTPOS).
1589 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1590 ;; For itemize, this puts in and rescans the COMMANDS.
1591 ;; For enumerate, this increments the number and puts it in.
1592 ;; In either case, it puts a Backspace at the front of the line
1593 ;; which marks it not to be indented later.
1594 ;; All other lines get indented by 5 when the @end is reached.
1596 (defvar texinfo-stack-depth 0
1597 "Count of number of unpopped texinfo-push-stack calls.
1598 Used by @refill indenting command to avoid indenting within lists, etc.")
1600 (defun texinfo-push-stack (check arg)
1601 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1602 (setq texinfo-stack
1603 (cons (list check arg texinfo-command-start)
1604 texinfo-stack)))
1606 (defun texinfo-pop-stack (check)
1607 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1608 (if (null texinfo-stack)
1609 (error "Unmatched @end %s" check))
1610 (if (not (eq (car (car texinfo-stack)) check))
1611 (error "@end %s matches @%s"
1612 check (car (car texinfo-stack))))
1613 (prog1 (cdr (car texinfo-stack))
1614 (setq texinfo-stack (cdr texinfo-stack))))
1616 (put 'itemize 'texinfo-format 'texinfo-itemize)
1617 (defun texinfo-itemize ()
1618 (texinfo-push-stack
1619 'itemize
1620 (progn (skip-chars-forward " \t")
1621 (if (eolp)
1622 "@bullet"
1623 (texinfo-parse-line-arg))))
1624 (texinfo-discard-line-with-args)
1625 (setq fill-column (- fill-column 5)))
1627 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1628 (defun texinfo-end-itemize ()
1629 (setq fill-column (+ fill-column 5))
1630 (texinfo-discard-command)
1631 (let ((stacktop
1632 (texinfo-pop-stack 'itemize)))
1633 (texinfo-do-itemize (nth 1 stacktop))))
1635 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1636 (defun texinfo-enumerate ()
1637 (texinfo-push-stack
1638 'enumerate
1639 (progn (skip-chars-forward " \t")
1640 (if (eolp)
1642 (read (current-buffer)))))
1643 (if (and (symbolp (car (cdr (car texinfo-stack))))
1644 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1645 (error
1646 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1647 (texinfo-discard-line-with-args)
1648 (setq fill-column (- fill-column 5)))
1650 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1651 (defun texinfo-end-enumerate ()
1652 (setq fill-column (+ fill-column 5))
1653 (texinfo-discard-command)
1654 (let ((stacktop
1655 (texinfo-pop-stack 'enumerate)))
1656 (texinfo-do-itemize (nth 1 stacktop))))
1658 ;; @alphaenumerate never became a standard part of Texinfo
1659 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1660 (defun texinfo-alphaenumerate ()
1661 (texinfo-push-stack 'alphaenumerate (1- ?a))
1662 (setq fill-column (- fill-column 5))
1663 (texinfo-discard-line))
1665 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1666 (defun texinfo-end-alphaenumerate ()
1667 (setq fill-column (+ fill-column 5))
1668 (texinfo-discard-command)
1669 (let ((stacktop
1670 (texinfo-pop-stack 'alphaenumerate)))
1671 (texinfo-do-itemize (nth 1 stacktop))))
1673 ;; @capsenumerate never became a standard part of Texinfo
1674 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1675 (defun texinfo-capsenumerate ()
1676 (texinfo-push-stack 'capsenumerate (1- ?A))
1677 (setq fill-column (- fill-column 5))
1678 (texinfo-discard-line))
1680 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1681 (defun texinfo-end-capsenumerate ()
1682 (setq fill-column (+ fill-column 5))
1683 (texinfo-discard-command)
1684 (let ((stacktop
1685 (texinfo-pop-stack 'capsenumerate)))
1686 (texinfo-do-itemize (nth 1 stacktop))))
1688 ;; At the @end, indent all the lines within the construct
1689 ;; except those marked with backspace. FROM says where
1690 ;; construct started.
1691 (defun texinfo-do-itemize (from)
1692 (save-excursion
1693 (while (progn (forward-line -1)
1694 (>= (point) from))
1695 (if (= (following-char) ?\b)
1696 (save-excursion
1697 (delete-char 1)
1698 (end-of-line)
1699 (delete-char 6))
1700 (if (not (looking-at "[ \t]*$"))
1701 (save-excursion (insert " ")))))))
1703 (put 'item 'texinfo-format 'texinfo-item)
1704 (put 'itemx 'texinfo-format 'texinfo-item)
1705 (defun texinfo-item ()
1706 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1708 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1709 (defun texinfo-itemize-item ()
1710 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1711 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1712 (if (looking-at "[ \t]*[^ \t\n]+")
1713 ;; Text on same line as @item command.
1714 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1715 ;; Else text on next line.
1716 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1717 (forward-line -1))
1719 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1720 (defun texinfo-enumerate-item ()
1721 (texinfo-discard-line)
1722 (let (enumerating-symbol)
1723 (cond ((integerp (car (cdr (car texinfo-stack))))
1724 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1725 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1726 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1727 ((symbolp (car (cdr (car texinfo-stack))))
1728 (setq enumerating-symbol
1729 (symbol-name (car (cdr (car texinfo-stack)))))
1730 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1731 (equal ?\{ (string-to-char enumerating-symbol)))
1732 (error
1733 "Too many items in enumerated list; alphabet ends at Z."))
1734 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1735 (setcar (cdr (car texinfo-stack))
1736 (make-symbol
1737 (char-to-string
1738 (1+
1739 (string-to-char enumerating-symbol))))))
1741 (error
1742 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1743 (forward-line -1)))
1745 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1746 (defun texinfo-alphaenumerate-item ()
1747 (texinfo-discard-line)
1748 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1749 (if (> next ?z)
1750 (error "More than 26 items in @alphaenumerate; get a bigger alphabet"))
1751 (setcar (cdr (car texinfo-stack)) next)
1752 (insert "\b " next ". \n"))
1753 (forward-line -1))
1755 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1756 (defun texinfo-capsenumerate-item ()
1757 (texinfo-discard-line)
1758 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1759 (if (> next ?Z)
1760 (error "More than 26 items in @capsenumerate; get a bigger alphabet"))
1761 (setcar (cdr (car texinfo-stack)) next)
1762 (insert "\b " next ". \n"))
1763 (forward-line -1))
1766 ;;; @table
1768 ;; The `@table' command produces two-column tables.
1770 (put 'table 'texinfo-format 'texinfo-table)
1771 (defun texinfo-table ()
1772 (texinfo-push-stack
1773 'table
1774 (progn (skip-chars-forward " \t")
1775 (if (eolp)
1776 "@asis"
1777 (texinfo-parse-line-arg))))
1778 (texinfo-discard-line-with-args)
1779 (setq fill-column (- fill-column 5)))
1781 (put 'table 'texinfo-item 'texinfo-table-item)
1782 (defun texinfo-table-item ()
1783 (let ((arg (texinfo-parse-arg-discard))
1784 (itemfont (car (cdr (car texinfo-stack)))))
1785 (insert ?\b itemfont ?\{ arg "}\n \n"))
1786 (forward-line -2))
1788 (put 'table 'texinfo-end 'texinfo-end-table)
1789 (defun texinfo-end-table ()
1790 (setq fill-column (+ fill-column 5))
1791 (texinfo-discard-command)
1792 (let ((stacktop
1793 (texinfo-pop-stack 'table)))
1794 (texinfo-do-itemize (nth 1 stacktop))))
1796 ;; @description appears to be an undocumented variant on @table that
1797 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1798 ;; part of makeinfo.c The command appears to be a relic of the past.
1799 (put 'description 'texinfo-end 'texinfo-end-table)
1800 (put 'description 'texinfo-format 'texinfo-description)
1801 (defun texinfo-description ()
1802 (texinfo-push-stack 'table "@asis")
1803 (setq fill-column (- fill-column 5))
1804 (texinfo-discard-line))
1807 ;;; @ftable, @vtable
1809 ;; The `@ftable' and `@vtable' commands are like the `@table' command
1810 ;; but they also insert each entry in the first column of the table
1811 ;; into the function or variable index.
1813 ;; Handle the @ftable and @vtable commands:
1815 (put 'ftable 'texinfo-format 'texinfo-ftable)
1816 (put 'vtable 'texinfo-format 'texinfo-vtable)
1818 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1819 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1821 (defun texinfo-indextable (table-type)
1822 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1823 (setq fill-column (- fill-column 5)))
1825 ;; Handle the @item commands within ftable and vtable:
1827 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1828 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1830 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1831 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1833 (defun texinfo-indextable-item (index-type)
1834 (let ((item (texinfo-parse-arg-discard))
1835 (itemfont (car (cdr (car texinfo-stack))))
1836 (indexvar index-type))
1837 (insert ?\b itemfont ?\{ item "}\n \n")
1838 (set indexvar
1839 (cons
1840 (list item texinfo-last-node)
1841 (symbol-value indexvar)))
1842 (forward-line -2)))
1844 ;; Handle @end ftable, @end vtable
1846 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1847 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1849 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1850 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1852 (defun texinfo-end-indextable (table-type)
1853 (setq fill-column (+ fill-column 5))
1854 (texinfo-discard-command)
1855 (let ((stacktop
1856 (texinfo-pop-stack table-type)))
1857 (texinfo-do-itemize (nth 1 stacktop))))
1860 ;;; @multitable ... @end multitable
1862 ;; Produce a multi-column table, with as many columns as desired.
1864 ;; A multi-column table has this template:
1866 ;; @multitable {A1} {A2} {A3}
1867 ;; @item A1 @tab A2 @tab A3
1868 ;; @item B1 @tab B2 @tab B3
1869 ;; @item C1 @tab C2 @tab C3
1870 ;; @end multitable
1872 ;; where the width of the text in brackets specifies the width of the
1873 ;; respective column.
1875 ;; Or else:
1877 ;; @multitable @columnfractions .25 .3 .45
1878 ;; @item A1 @tab A2 @tab A3
1879 ;; @item B1 @tab B2 @tab B3
1880 ;; @end multitable
1882 ;; where the fractions specify the width of each column as a percent
1883 ;; of the current width of the text (i.e., of the fill-column).
1885 ;; Long lines of text are filled within columns.
1887 ;; Using the Emacs Lisp formatter, texinfmt.el,
1888 ;; the whitespace between columns can be increased by setting
1889 ;; `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1890 ;; there is at least one blank space between columns.
1892 ;; The Emacs Lisp formatter, texinfmt.el, ignores the following four
1893 ;; commands that are defined in texinfo.tex for printed output.
1895 ;; @multitableparskip,
1896 ;; @multitableparindent,
1897 ;; @multitablecolmargin,
1898 ;; @multitablelinespace.
1900 ;; How @multitable works.
1901 ;; =====================
1903 ;; `texinfo-multitable' reads the @multitable line and determines from it
1904 ;; how wide each column should be.
1906 ;; Also, it pushes this information, along with an identifying symbol,
1907 ;; onto the `texinfo-stack'. At the @end multitable command, the stack
1908 ;; is checked for its matching @multitable command, and then popped, or
1909 ;; else an error is signaled. Also, this command pushes the location of
1910 ;; the start of the table onto the stack.
1912 ;; `texinfo-end-multitable' checks the `texinfo-stack' that the @end
1913 ;; multitable truly is ending a corresponding beginning, and if it is,
1914 ;; pops the stack.
1916 ;; `texinfo-multitable-widths' is called by `texinfo-multitable'.
1917 ;; The function returns a list of the widths of each column in a
1918 ;; multi-column table, based on the information supplied by the arguments
1919 ;; to the @multitable command (by arguments, I mean the text on the rest
1920 ;; of the @multitable line, not the remainder of the multi-column table
1921 ;; environment).
1923 ;; `texinfo-multitable-item' formats a row within a multicolumn table.
1924 ;; This command is executed when texinfmt sees @item inside @multitable.
1925 ;; Cells in row are separated by `@tab's. Widths of cells are specified
1926 ;; by the arguments in the @multitable line. Cells are filled. All cells
1927 ;; are made to be the same height by padding their bottoms, as needed,
1928 ;; with blanks.
1930 ;; `texinfo-multitable-extract-row' is called by `texinfo-multitable-item'.
1931 ;; This function returns the text in a multitable row, as a string.
1932 ;; The start of a row is marked by an @item and the end of row is the
1933 ;; beginning of next @item or beginning of the @end multitable line.
1934 ;; Cells within a row are separated by @tab.
1936 ;; Note that @tab, the cell separators, are not treated as independent
1937 ;; Texinfo commands.
1939 (defvar texinfo-extra-inter-column-width 0
1940 "*Number of extra spaces between entries (columns) in @multitable.")
1942 (defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
1943 (defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
1945 ;; These commands are defined in texinfo.tex for printed output.
1946 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
1947 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
1948 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
1949 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
1951 (put 'multitable 'texinfo-format 'texinfo-multitable)
1953 (defun texinfo-multitable ()
1954 "Produce multi-column tables.
1956 A multi-column table has this template:
1958 @multitable {A1} {A2} {A3}
1959 @item A1 @tab A2 @tab A3
1960 @item B1 @tab B2 @tab B3
1961 @item C1 @tab C2 @tab C3
1962 @end multitable
1964 where the width of the text in brackets specifies the width of the
1965 respective column.
1967 Or else:
1969 @multitable @columnfractions .25 .3 .45
1970 @item A1 @tab A2 @tab A3
1971 @item B1 @tab B2 @tab B3
1972 @end multitable
1974 where the fractions specify the width of each column as a percent
1975 of the current width of the text (i.e., of the fill-column).
1977 Long lines of text are filled within columns.
1979 Using the Emacs Lisp formatter, texinfmt.el,
1980 the whitespace between columns can be increased by setting
1981 `texinfo-extra-inter-column-width' to a value greater than 0. By default,
1982 there is at least one blank space between columns.
1984 The Emacs Lisp formatter, texinfmt.el, ignores the following four
1985 commands that are defined in texinfo.tex for printed output.
1987 @multitableparskip,
1988 @multitableparindent,
1989 @multitablecolmargin,
1990 @multitablelinespace."
1992 ;; This function pushes information onto the `texinfo-stack'.
1993 ;; A stack element consists of:
1994 ;; - type-of-command, i.e., multitable
1995 ;; - the information about column widths, and
1996 ;; - the position of texinfo-command-start.
1997 ;; e.g., ('multitable (1 2 3 4) 123)
1998 ;; The command line is then deleted.
1999 (texinfo-push-stack
2000 'multitable
2001 ;; push width information on stack
2002 (texinfo-multitable-widths))
2003 (texinfo-discard-line-with-args))
2005 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
2006 (defun texinfo-end-multitable ()
2007 "Discard the @end multitable line and pop the stack of multitable."
2008 (texinfo-discard-command)
2009 (texinfo-pop-stack 'multitable))
2011 (defun texinfo-multitable-widths ()
2012 "Return list of widths of each column in a multi-column table."
2013 (let (texinfo-multitable-width-list)
2014 ;; Fractions format:
2015 ;; @multitable @columnfractions .25 .3 .45
2017 ;; Template format:
2018 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
2019 ;; Place point before first argument
2020 (skip-chars-forward " \t")
2021 (cond
2022 ;; Check for common misspelling
2023 ((looking-at "@columnfraction ")
2024 (error "In @multitable, @columnfractions misspelled"))
2025 ;; Case 1: @columnfractions .25 .3 .45
2026 ((looking-at "@columnfractions")
2027 (forward-word 1)
2028 (while (not (eolp))
2029 (setq texinfo-multitable-width-list
2030 (cons
2031 (truncate
2033 (* fill-column (read (get-buffer (current-buffer))))))
2034 texinfo-multitable-width-list))))
2036 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
2037 ((looking-at "{")
2038 (let ((start-of-templates (point)))
2039 (while (not (eolp))
2040 (skip-chars-forward " \t")
2041 (let* ((start-of-template (1+ (point)))
2042 (end-of-template
2043 ;; forward-sexp works with braces in Texinfo mode
2044 (progn (forward-sexp 1) (1- (point)))))
2045 (setq texinfo-multitable-width-list
2046 (cons (- end-of-template start-of-template)
2047 texinfo-multitable-width-list))
2048 ;; Remove carriage return from within a template, if any.
2049 ;; This helps those those who want to use more than
2050 ;; one line's worth of words in @multitable line.
2051 (narrow-to-region start-of-template end-of-template)
2052 (goto-char (point-min))
2053 (while (search-forward "
2054 " nil t)
2055 (delete-char -1))
2056 (goto-char (point-max))
2057 (widen)
2058 (forward-char 1)))))
2060 ;; Case 3: Trouble
2062 (error
2063 "You probably need to specify column widths for @multitable correctly.")))
2064 ;; Check whether columns fit on page.
2065 (let ((desired-columns
2067 ;; between column spaces
2068 (length texinfo-multitable-width-list)
2069 ;; additional between column spaces, if any
2070 texinfo-extra-inter-column-width
2071 ;; sum of spaces for each entry
2072 (apply '+ texinfo-multitable-width-list))))
2073 (if (> desired-columns fill-column)
2074 (error
2075 (format
2076 "Multi-column table width, %d chars, is greater than page width, %d chars."
2077 desired-columns fill-column))))
2078 texinfo-multitable-width-list))
2080 ;; @item A1 @tab A2 @tab A3
2081 (defun texinfo-multitable-extract-row ()
2082 "Return multitable row, as a string.
2083 End of row is beginning of next @item or beginning of @end.
2084 Cells within rows are separated by @tab."
2085 (skip-chars-forward " \t")
2086 (let* ((start (point))
2087 (end (progn
2088 (re-search-forward "@item\\|@end")
2089 (match-beginning 0)))
2090 (row (progn (goto-char end)
2091 (skip-chars-backward " ")
2092 ;; remove whitespace at end of argument
2093 (delete-region (point) end)
2094 (buffer-substring-no-properties start (point)))))
2095 (delete-region texinfo-command-start end)
2096 row))
2098 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
2099 (defun texinfo-multitable-item ()
2100 "Format a row within a multicolumn table.
2101 Cells in row are separated by @tab.
2102 Widths of cells are specified by the arguments in the @multitable line.
2103 All cells are made to be the same height.
2104 This command is executed when texinfmt sees @item inside @multitable."
2105 (let ((original-buffer (current-buffer))
2106 (table-widths (reverse (car (cdr (car texinfo-stack)))))
2107 (existing-fill-column fill-column)
2108 start
2110 (table-column 0)
2111 (table-entry-height 0)
2112 ;; unformatted row looks like: A1 @tab A2 @tab A3
2113 ;; extract-row command deletes the source line in the table.
2114 (unformated-row (texinfo-multitable-extract-row)))
2115 ;; Use a temporary buffer
2116 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
2117 (delete-region (point-min) (point-max))
2118 (insert unformated-row)
2119 (goto-char (point-min))
2120 ;; 1. Check for correct number of @tab in line.
2121 (let ((tab-number 1)) ; one @tab between two columns
2122 (while (search-forward "@tab" nil t)
2123 (setq tab-number (1+ tab-number)))
2124 (if (/= tab-number (length table-widths))
2125 (error "Wrong number of @tab's in a @multitable row")))
2126 (goto-char (point-min))
2127 ;; 2. Format each cell, and copy to a rectangle
2128 ;; buffer looks like this: A1 @tab A2 @tab A3
2129 ;; Cell #1: format up to @tab
2130 ;; Cell #2: format up to @tab
2131 ;; Cell #3: format up to eob
2132 (while (not (eobp))
2133 (setq start (point))
2134 (setq end (save-excursion
2135 (if (search-forward "@tab" nil 'move)
2136 ;; Delete the @tab command, including the @-sign
2137 (delete-region
2138 (point)
2139 (progn (forward-word -1) (1- (point)))))
2140 (point)))
2141 ;; Set fill-column *wider* than needed to produce inter-column space
2142 (setq fill-column (+ 1
2143 texinfo-extra-inter-column-width
2144 (nth table-column table-widths)))
2145 (narrow-to-region start end)
2146 ;; Remove whitespace before and after entry.
2147 (skip-chars-forward " ")
2148 (delete-region (point) (save-excursion (beginning-of-line) (point)))
2149 (goto-char (point-max))
2150 (skip-chars-backward " ")
2151 (delete-region (point) (save-excursion (end-of-line) (point)))
2152 ;; Temporarily set texinfo-stack to nil so texinfo-format-scan
2153 ;; does not see an unterminated @multitable.
2154 (let (texinfo-stack) ; nil
2155 (texinfo-format-scan))
2156 (let (fill-prefix) ; no fill prefix
2157 (fill-region (point-min) (point-max)))
2158 (setq table-entry-height
2159 (max table-entry-height (count-lines (point-min) (point-max))))
2160 ;; 3. Move point to end of bottom line, and pad that line to fill column.
2161 (goto-char (point-min))
2162 (forward-line (1- table-entry-height))
2163 (let* ((beg (point)) ; beginning of line
2164 ;; add one more space for inter-column spacing
2165 (needed-whitespace
2167 (- fill-column
2169 (progn (end-of-line) (point)) ; end of existing line
2170 beg)))))
2171 (insert (make-string
2172 (if (> needed-whitespace 0) needed-whitespace 1)
2173 ? )))
2174 ;; now, put formatted cell into a rectangle
2175 (set (intern (concat texinfo-multitable-rectangle-name
2176 (int-to-string table-column)))
2177 (extract-rectangle (point-min) (point)))
2178 (delete-region (point-min) (point))
2179 (goto-char (point-max))
2180 (setq table-column (1+ table-column))
2181 (widen))
2182 ;; 4. Add extra lines to rectangles so all are of same height
2183 (let ((total-number-of-columns table-column)
2184 (column-number 0)
2185 here)
2186 (while (> table-column 0)
2187 (let ((this-rectangle (int-to-string table-column)))
2188 (while (< (length this-rectangle) table-entry-height)
2189 (setq this-rectangle (append this-rectangle '("")))))
2190 (setq table-column (1- table-column)))
2191 ;; 5. Insert formatted rectangles in original buffer
2192 (switch-to-buffer original-buffer)
2193 (open-line table-entry-height)
2194 (while (< column-number total-number-of-columns)
2195 (setq here (point))
2196 (insert-rectangle
2197 (eval (intern
2198 (concat texinfo-multitable-rectangle-name
2199 (int-to-string column-number)))))
2200 (goto-char here)
2201 (end-of-line)
2202 (setq column-number (1+ column-number))))
2203 (kill-buffer texinfo-multitable-buffer-name)
2204 (setq fill-column existing-fill-column)))
2207 ;;; @image
2208 ;; Use only the FILENAME argument to the command.
2209 ;; In Info, ignore the other arguments.
2211 (put 'image 'texinfo-format 'texinfo-format-image)
2212 (defun texinfo-format-image ()
2213 "Insert an image from an an file ending in .txt.
2214 Use only the FILENAME arg; for Info, ignore the other arguments to @image."
2215 (let ((args (texinfo-format-parse-args))
2216 filename)
2217 (when (null (nth 0 args))
2218 (error "Invalid image command"))
2219 (texinfo-discard-command)
2220 ;; makeinfo uses FILENAME.txt
2221 (setq filename (format "%s.txt" (nth 0 args)))
2222 (message "Reading included file: %s" filename)
2223 ;; verbatim for Info output
2224 (goto-char (+ (point) (cadr (insert-file-contents filename))))
2225 (message "Reading included file: %s...done" filename)))
2228 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html, @ifplaintext, @ifxml, @xml
2229 ;; @ifnottex, @ifnotinfo, @ifnothtml, @ifnotplaintext, @ifnotxml
2231 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
2232 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
2234 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
2235 (defun texinfo-format-iftex ()
2236 (delete-region texinfo-command-start
2237 (progn (re-search-forward "@end iftex[ \t]*\n")
2238 (point))))
2240 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
2241 (defun texinfo-format-ifhtml ()
2242 (delete-region texinfo-command-start
2243 (progn (re-search-forward "@end ifhtml[ \t]*\n")
2244 (point))))
2246 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
2247 (defun texinfo-format-ifplaintext ()
2248 (delete-region texinfo-command-start
2249 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
2250 (point))))
2252 (put 'ifxml 'texinfo-format 'texinfo-format-ifxml)
2253 (defun texinfo-format-ifxml ()
2254 (delete-region texinfo-command-start
2255 (progn (re-search-forward "^@end ifxml[ \t]*\n")
2256 (point))))
2258 (put 'tex 'texinfo-format 'texinfo-format-tex)
2259 (defun texinfo-format-tex ()
2260 (delete-region texinfo-command-start
2261 (progn (re-search-forward "@end tex[ \t]*\n")
2262 (point))))
2264 (put 'html 'texinfo-format 'texinfo-format-html)
2265 (defun texinfo-format-html ()
2266 (delete-region texinfo-command-start
2267 (progn (re-search-forward "@end html[ \t]*\n")
2268 (point))))
2270 (put 'xml 'texinfo-format 'texinfo-format-xml)
2271 (defun texinfo-format-xml ()
2272 (delete-region texinfo-command-start
2273 (progn (re-search-forward "^@end xml[ \t]*\n")
2274 (point))))
2276 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
2277 (defun texinfo-format-ifnotinfo ()
2278 (delete-region texinfo-command-start
2279 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
2280 (point))))
2282 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
2283 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
2285 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
2286 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
2288 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
2289 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
2291 (put 'ifnotxml 'texinfo-format 'texinfo-discard-line)
2292 (put 'ifnotxml 'texinfo-end 'texinfo-discard-command)
2295 ;;; @titlepage
2297 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
2298 (defun texinfo-format-titlepage ()
2299 (delete-region texinfo-command-start
2300 (progn (re-search-forward "@end titlepage[ \t]*\n")
2301 (point))))
2303 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
2305 ;; @titlespec an alternative titling command; ignored by Info
2307 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
2308 (defun texinfo-format-titlespec ()
2309 (delete-region texinfo-command-start
2310 (progn (re-search-forward "@end titlespec[ \t]*\n")
2311 (point))))
2313 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
2316 ;;; @today
2318 (put 'today 'texinfo-format 'texinfo-format-today)
2320 ;; Produces Day Month Year style of output. eg `1 Jan 1900'
2321 ;; The `@today{}' command requires a pair of braces, like `@dots{}'.
2322 (defun texinfo-format-today ()
2323 (texinfo-parse-arg-discard)
2324 (insert (format-time-string "%e %b %Y")))
2327 ;;; @timestamp{}
2328 ;; Produce `Day Month Year Hour:Min' style of output.
2329 ;; eg `1 Jan 1900 13:52'
2331 (put 'timestamp 'texinfo-format 'texinfo-format-timestamp)
2333 ;; The `@timestamp{}' command requires a pair of braces, like `@dots{}'.
2334 (defun texinfo-format-timestamp ()
2335 "Insert the current local time and date."
2336 (texinfo-parse-arg-discard)
2337 ;; For seconds and time zone, replace format string with "%e %b %Y %T %Z"
2338 (insert (format-time-string "%e %b %Y %R")))
2341 ;;; @ignore
2343 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
2344 (defun texinfo-format-ignore ()
2345 (delete-region texinfo-command-start
2346 (progn (re-search-forward "@end ignore[ \t]*\n")
2347 (point))))
2349 (put 'endignore 'texinfo-format 'texinfo-discard-line)
2352 ;;; Define the Info enclosure command: @definfoenclose
2354 ;; A `@definfoenclose' command may be used to define a highlighting
2355 ;; command for Info, but not for TeX. A command defined using
2356 ;; `@definfoenclose' marks text by enclosing it in strings that precede
2357 ;; and follow the text.
2359 ;; Presumably, if you define a command with `@definfoenclose` for Info,
2360 ;; you will also define the same command in the TeX definitions file,
2361 ;; `texinfo.tex' in a manner appropriate for typesetting.
2363 ;; Write a `@definfoenclose' command on a line and follow it with three
2364 ;; arguments separated by commas (commas are used as separators in an
2365 ;; `@node' line in the same way). The first argument to
2366 ;; `@definfoenclose' is the @-command name \(without the `@'\); the
2367 ;; second argument is the Info start delimiter string; and the third
2368 ;; argument is the Info end delimiter string. The latter two arguments
2369 ;; enclose the highlighted text in the Info file. A delimiter string
2370 ;; may contain spaces. Neither the start nor end delimiter is
2371 ;; required. However, if you do not provide a start delimiter, you
2372 ;; must follow the command name with two commas in a row; otherwise,
2373 ;; the Info formatting commands will misinterpret the end delimiter
2374 ;; string as a start delimiter string.
2376 ;; If you do a @definfoenclose{} on the name of a pre-defined macro (such
2377 ;; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
2378 ;; override the built-in definition.
2380 ;; An enclosure command defined this way takes one argument in braces.
2382 ;; For example, you can write:
2384 ;; @ifinfo
2385 ;; @definfoenclose phoo, //, \\
2386 ;; @end ifinfo
2388 ;; near the beginning of a Texinfo file at the beginning of the lines
2389 ;; to define `@phoo' as an Info formatting command that inserts `//'
2390 ;; before and `\\' after the argument to `@phoo'. You can then write
2391 ;; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
2393 ;; Also, for TeX formatting, you could write
2395 ;; @iftex
2396 ;; @global@let@phoo=@i
2397 ;; @end iftex
2399 ;; to define `@phoo' as a command that causes TeX to typeset
2400 ;; the argument to `@phoo' in italics.
2402 ;; Note that each definition applies to its own formatter: one for TeX,
2403 ;; the other for texinfo-format-buffer or texinfo-format-region.
2405 ;; Here is another example: write
2407 ;; @definfoenclose headword, , :
2409 ;; near the beginning of the file, to define `@headword' as an Info
2410 ;; formatting command that inserts nothing before and a colon after the
2411 ;; argument to `@headword'.
2413 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
2414 (defun texinfo-define-info-enclosure ()
2415 (let* ((args (texinfo-format-parse-line-args))
2416 (command-name (nth 0 args))
2417 (beginning-delimiter (or (nth 1 args) ""))
2418 (end-delimiter (or (nth 2 args) "")))
2419 (texinfo-discard-command)
2420 (setq texinfo-enclosure-list
2421 (cons
2422 (list command-name
2423 (list
2424 beginning-delimiter
2425 end-delimiter))
2426 texinfo-enclosure-list))))
2429 ;;; @alias
2431 (put 'alias 'texinfo-format 'texinfo-alias)
2432 (defun texinfo-alias ()
2433 (let ((start (1- (point)))
2434 args)
2435 (skip-chars-forward " ")
2436 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
2437 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
2438 (error "Invalid alias command")
2439 (setq texinfo-alias-list
2440 (cons
2441 (cons
2442 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
2443 (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
2444 texinfo-alias-list))
2445 (texinfo-discard-command))
2450 ;;; @var, @code and the like
2452 (put 'var 'texinfo-format 'texinfo-format-var)
2453 ;; @sc a small caps font for TeX; formatted as `var' in Info
2454 (put 'sc 'texinfo-format 'texinfo-format-var)
2455 ;; @acronym for abbreviations in all caps, such as `NASA'.
2456 ;; Convert all letters to uppercase if they are not already.
2457 (put 'acronym 'texinfo-format 'texinfo-format-var)
2458 (defun texinfo-format-var ()
2459 (let ((arg (texinfo-parse-expanded-arg)))
2460 (texinfo-discard-command)
2461 (insert (upcase arg))))
2463 (put 'cite 'texinfo-format 'texinfo-format-code)
2464 (put 'code 'texinfo-format 'texinfo-format-code)
2465 ;; @command (for command names)
2466 (put 'command 'texinfo-format 'texinfo-format-code)
2467 ;; @env (for environment variables)
2468 (put 'env 'texinfo-format 'texinfo-format-code)
2469 (put 'file 'texinfo-format 'texinfo-format-code)
2470 (put 'samp 'texinfo-format 'texinfo-format-code)
2471 (put 'url 'texinfo-format 'texinfo-format-code)
2472 (defun texinfo-format-code ()
2473 (insert "`" (texinfo-parse-arg-discard) "'")
2474 (goto-char texinfo-command-start))
2476 ;; @option (for command-line options) must be different from @code
2477 ;; because of its special formatting in @table; namely that it does
2478 ;; not lead to inserted ` ... ' in a table, but does elsewhere.
2479 (put 'option 'texinfo-format 'texinfo-format-option)
2480 (defun texinfo-format-option ()
2481 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
2482 ;; `looking-at-backward' not available in v. 18.57, 20.2
2483 (if (not (search-backward "\b" ; searched-for character is a control-H
2484 (save-excursion (beginning-of-line) (point))
2486 (insert "`" (texinfo-parse-arg-discard) "'")
2487 (insert (texinfo-parse-arg-discard)))
2488 (goto-char texinfo-command-start))
2490 (put 'emph 'texinfo-format 'texinfo-format-emph)
2491 (put 'strong 'texinfo-format 'texinfo-format-emph)
2492 (defun texinfo-format-emph ()
2493 (insert "*" (texinfo-parse-arg-discard) "*")
2494 (goto-char texinfo-command-start))
2496 (put 'dfn 'texinfo-format 'texinfo-format-defn)
2497 (put 'defn 'texinfo-format 'texinfo-format-defn)
2498 (defun texinfo-format-defn ()
2499 (insert "\"" (texinfo-parse-arg-discard) "\"")
2500 (goto-char texinfo-command-start))
2502 (put 'email 'texinfo-format 'texinfo-format-email)
2503 (defun texinfo-format-email ()
2504 "Format email address and optional following full name.
2505 Insert full name, if present, followed by email address
2506 surrounded by in angle brackets."
2507 (let ((args (texinfo-format-parse-args)))
2508 (texinfo-discard-command)
2509 ;; if full-name
2510 (if (nth 1 args)
2511 (insert (nth 1 args) " "))
2512 (insert "<" (nth 0 args) ">")))
2514 (put 'key 'texinfo-format 'texinfo-format-key)
2515 ;; I've decided not want to have angle brackets around these -- rms.
2516 (defun texinfo-format-key ()
2517 (insert (texinfo-parse-arg-discard))
2518 (goto-char texinfo-command-start))
2520 ;; @verb{<char>TEXT<char>} (in `makeinfo' 4.1 and later)
2521 (put 'verb 'texinfo-format 'texinfo-format-verb)
2522 (defun texinfo-format-verb ()
2523 "Format text between non-quoted unique delimiter characters verbatim.
2524 Enclose the verbatim text, including the delimiters, in braces. Print
2525 text exactly as written (but not the delimiters) in a fixed-width.
2527 For example, @verb\{|@|\} results in @ and
2528 @verb\{+@'e?`!`+} results in @'e?`!`."
2530 (let ((delimiter (buffer-substring-no-properties
2531 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
2532 (unless (looking-at "{")
2533 (error "Not found: @verb start brace"))
2534 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
2535 (search-forward delimiter))
2536 (delete-backward-char 1)
2537 (unless (looking-at "}")
2538 (error "Not found: @verb end brace"))
2539 (delete-char 1))
2541 ;; as of 2002 Dec 10
2542 ;; see (texinfo)Block Enclosing Commands
2543 ;; need: @verbatim
2545 ;; as of 2002 Dec 10
2546 ;; see (texinfo)verbatiminclude
2547 ;; need: @verbatiminclude FILENAME
2549 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
2550 (defun texinfo-format-bullet ()
2551 "Insert an asterisk.
2552 If used within a line, follow `@bullet' with braces."
2553 (texinfo-optional-braces-discard)
2554 (insert "*"))
2557 ;;; @kbd
2559 ;; Inside of @example ... @end example and similar environments,
2560 ;; @kbd does nothing; but outside of such environments, it places
2561 ;; single quotation marks around its argument.
2563 (defvar texinfo-format-kbd-regexp
2564 (concat
2565 "^@"
2566 "\\("
2567 "display\\|"
2568 "example\\|"
2569 "smallexample\\|"
2570 "lisp\\|"
2571 "smalllisp"
2572 "\\)")
2573 "Regexp specifying environments in which @kbd does not put `...'
2574 around argument.")
2576 (defvar texinfo-format-kbd-end-regexp
2577 (concat
2578 "^@end "
2579 "\\("
2580 "display\\|"
2581 "example\\|"
2582 "smallexample\\|"
2583 "lisp\\|"
2584 "smalllisp"
2585 "\\)")
2586 "Regexp specifying end of environments in which @kbd does not put `...'
2587 around argument. (See `texinfo-format-kbd-regexp')")
2589 (put 'kbd 'texinfo-format 'texinfo-format-kbd)
2590 (defun texinfo-format-kbd ()
2591 "Place single quote marks around arg, except in @example and similar."
2592 ;; Search forward for @end example closer than an @example.
2593 ;; Can stop search at nearest @node or texinfo-section-types-regexp
2594 (let* ((stop
2595 (save-excursion
2596 (re-search-forward
2597 (concat "^@node\\|\\(" texinfo-section-types-regexp "\\)")
2599 'move-to-end) ; if necessary, return point at end of buffer
2600 (point)))
2601 (example-location
2602 (save-excursion
2603 (re-search-forward texinfo-format-kbd-regexp stop 'move-to-end)
2604 (point)))
2605 (end-example-location
2606 (save-excursion
2607 (re-search-forward texinfo-format-kbd-end-regexp stop 'move-to-end)
2608 (point))))
2609 ;; If inside @example, @end example will be closer than @example
2610 ;; or end of search i.e., end-example-location less than example-location
2611 (if (>= end-example-location example-location)
2612 ;; outside an @example or equivalent
2613 (insert "`" (texinfo-parse-arg-discard) "'")
2614 ;; else, in @example; do not surround with `...'
2615 (insert (texinfo-parse-arg-discard)))
2616 (goto-char texinfo-command-start)))
2619 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample,
2620 ;; @smalldisplay
2622 (put 'display 'texinfo-format 'texinfo-format-example)
2623 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
2624 (put 'example 'texinfo-format 'texinfo-format-example)
2625 (put 'lisp 'texinfo-format 'texinfo-format-example)
2626 (put 'quotation 'texinfo-format 'texinfo-format-example)
2627 (put 'smallexample 'texinfo-format 'texinfo-format-example)
2628 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
2629 (defun texinfo-format-example ()
2630 (texinfo-push-stack 'example nil)
2631 (setq fill-column (- fill-column 5))
2632 (texinfo-discard-line))
2634 (put 'example 'texinfo-end 'texinfo-end-example)
2635 (put 'display 'texinfo-end 'texinfo-end-example)
2636 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
2637 (put 'lisp 'texinfo-end 'texinfo-end-example)
2638 (put 'quotation 'texinfo-end 'texinfo-end-example)
2639 (put 'smallexample 'texinfo-end 'texinfo-end-example)
2640 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
2641 (defun texinfo-end-example ()
2642 (setq fill-column (+ fill-column 5))
2643 (texinfo-discard-command)
2644 (let ((stacktop
2645 (texinfo-pop-stack 'example)))
2646 (texinfo-do-itemize (nth 1 stacktop))))
2648 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
2649 (defun texinfo-format-exdent ()
2650 (texinfo-discard-command)
2651 (delete-region (point)
2652 (progn
2653 (skip-chars-forward " ")
2654 (point)))
2655 (insert ?\b)
2656 ;; Cancel out the deletion that texinfo-do-itemize
2657 ;; is going to do at the end of this line.
2658 (save-excursion
2659 (end-of-line)
2660 (insert "\n ")))
2663 ;; @direntry and @dircategory
2665 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
2666 (defun texinfo-format-direntry ()
2667 (texinfo-push-stack 'direntry nil)
2668 (texinfo-discard-line)
2669 (insert "START-INFO-DIR-ENTRY\n"))
2671 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
2672 (defun texinfo-end-direntry ()
2673 (texinfo-discard-command)
2674 (insert "END-INFO-DIR-ENTRY\n\n")
2675 (texinfo-pop-stack 'direntry))
2677 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
2678 (defun texinfo-format-dircategory ()
2679 (let ((str (texinfo-parse-arg-discard)))
2680 (delete-region (point)
2681 (progn
2682 (skip-chars-forward " ")
2683 (point)))
2684 (insert "INFO-DIR-SECTION " str "\n")))
2686 ;;; @cartouche
2688 ;; The @cartouche command is a noop in Info; in a printed manual,
2689 ;; it makes a box with rounded corners.
2691 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
2692 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
2695 ;;; @flushleft and @format
2697 ;; The @flushleft command left justifies every line but leaves the
2698 ;; right end ragged. As far as Info is concerned, @flushleft is a
2699 ;; `do-nothing' command
2701 ;; The @format command is similar to @example except that it does not
2702 ;; indent; this means that in Info, @format is similar to @flushleft.
2704 (put 'format 'texinfo-format 'texinfo-format-flushleft)
2705 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
2706 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
2707 (defun texinfo-format-flushleft ()
2708 (texinfo-discard-line))
2710 (put 'format 'texinfo-end 'texinfo-end-flushleft)
2711 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
2712 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
2713 (defun texinfo-end-flushleft ()
2714 (texinfo-discard-command))
2717 ;;; @flushright
2719 ;; The @flushright command right justifies every line but leaves the
2720 ;; left end ragged. Spaces and tabs at the right ends of lines are
2721 ;; removed so that visible text lines up on the right side.
2723 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
2724 (defun texinfo-format-flushright ()
2725 (texinfo-push-stack 'flushright nil)
2726 (texinfo-discard-line))
2728 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
2729 (defun texinfo-end-flushright ()
2730 (texinfo-discard-command)
2732 (let ((stacktop
2733 (texinfo-pop-stack 'flushright)))
2735 (texinfo-do-flushright (nth 1 stacktop))))
2737 (defun texinfo-do-flushright (from)
2738 (save-excursion
2739 (while (progn (forward-line -1)
2740 (>= (point) from))
2742 (beginning-of-line)
2743 (insert
2744 (make-string
2745 (- fill-column
2746 (save-excursion
2747 (end-of-line)
2748 (skip-chars-backward " \t")
2749 (delete-region (point) (progn (end-of-line) (point)))
2750 (current-column)))
2751 ? )))))
2754 ;;; @ctrl, @TeX, @copyright, @minus, @dots, @enddots, @pounds
2756 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
2757 (defun texinfo-format-ctrl ()
2758 (let ((str (texinfo-parse-arg-discard)))
2759 (insert (logand 31 (aref str 0)))))
2761 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
2762 (defun texinfo-format-TeX ()
2763 (texinfo-parse-arg-discard)
2764 (insert "TeX"))
2766 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
2767 (defun texinfo-format-copyright ()
2768 (texinfo-parse-arg-discard)
2769 (insert "(C)"))
2771 (put 'minus 'texinfo-format 'texinfo-format-minus)
2772 (defun texinfo-format-minus ()
2773 "Insert a minus sign.
2774 If used within a line, follow `@minus' with braces."
2775 (texinfo-optional-braces-discard)
2776 (insert "-"))
2778 (put 'dots 'texinfo-format 'texinfo-format-dots)
2779 (defun texinfo-format-dots ()
2780 (texinfo-parse-arg-discard)
2781 (insert "..."))
2783 (put 'enddots 'texinfo-format 'texinfo-format-enddots)
2784 (defun texinfo-format-enddots ()
2785 (texinfo-parse-arg-discard)
2786 (insert "...."))
2788 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
2789 (defun texinfo-format-pounds ()
2790 (texinfo-parse-arg-discard)
2791 (insert "#"))
2794 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
2796 ;;; Indent only those paragraphs that are refilled as a result of an
2797 ;;; @refill command.
2799 ;; * If the value is `asis', do not change the existing indentation at
2800 ;; the starts of paragraphs.
2802 ;; * If the value zero, delete any existing indentation.
2804 ;; * If the value is greater than zero, indent each paragraph by that
2805 ;; number of spaces.
2807 ;;; But do not refill paragraphs with an @refill command that are
2808 ;;; preceded by @noindent or are part of a table, list, or deffn.
2810 (defvar texinfo-paragraph-indent "asis"
2811 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
2813 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
2815 (defun texinfo-paragraphindent ()
2816 "Specify the number of spaces for @refill to indent a paragraph.
2817 Default is to leave the number of spaces as is."
2818 (let ((arg (texinfo-parse-arg-discard)))
2819 (if (string= "asis" arg)
2820 (setq texinfo-paragraph-indent "asis")
2821 (setq texinfo-paragraph-indent (string-to-int arg)))))
2823 (put 'refill 'texinfo-format 'texinfo-format-refill)
2824 (defun texinfo-format-refill ()
2825 "Refill paragraph. Also, indent first line as set by @paragraphindent.
2826 Default is to leave paragraph indentation as is."
2827 (texinfo-discard-command)
2828 (let ((position (point-marker)))
2829 (forward-paragraph -1)
2830 (if (looking-at "[ \t\n]*$") (forward-line 1))
2831 ;; Do not indent if an entry in a list, table, or deffn,
2832 ;; or if paragraph is preceded by @noindent.
2833 ;; Otherwise, indent
2834 (cond
2835 ;; delete a @noindent line and do not indent paragraph
2836 ((save-excursion (forward-line -1)
2837 (looking-at "^@noindent"))
2838 (forward-line -1)
2839 (delete-region (point) (progn (forward-line 1) (point))))
2840 ;; do nothing if "asis"
2841 ((equal texinfo-paragraph-indent "asis"))
2842 ;; do no indenting in list, etc.
2843 ((> texinfo-stack-depth 0))
2844 ;; otherwise delete existing whitespace and indent
2846 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2847 (insert (make-string texinfo-paragraph-indent ? ))))
2848 (forward-paragraph 1)
2849 (forward-line -1)
2850 (end-of-line)
2851 ;; Do not fill a section title line with asterisks, hyphens, etc. that
2852 ;; are used to underline it. This could occur if the line following
2853 ;; the underlining is not an index entry and has text within it.
2854 (let* ((previous-paragraph-separate paragraph-separate)
2855 (paragraph-separate
2856 (concat paragraph-separate "\\|[-=.]+\\|\\*\\*+"))
2857 (previous-paragraph-start paragraph-start)
2858 (paragraph-start
2859 (concat paragraph-start "\\|[-=.]+\\|\\*\\*+")))
2860 (unwind-protect
2861 (fill-paragraph nil)
2862 (setq paragraph-separate previous-paragraph-separate)
2863 (setq paragraph-start previous-paragraph-start)))
2864 (goto-char position)))
2866 (put 'noindent 'texinfo-format 'texinfo-noindent)
2867 (defun texinfo-noindent ()
2868 (save-excursion
2869 (forward-paragraph 1)
2870 (if (search-backward "@refill"
2871 (save-excursion (forward-line -1) (point)) t)
2872 () ; leave @noindent command so @refill command knows not to indent
2873 ;; else
2874 (texinfo-discard-line))))
2877 ;;; Index generation
2879 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
2880 (defun texinfo-format-vindex ()
2881 (texinfo-index 'texinfo-vindex))
2883 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
2884 (defun texinfo-format-cindex ()
2885 (texinfo-index 'texinfo-cindex))
2887 (put 'findex 'texinfo-format 'texinfo-format-findex)
2888 (defun texinfo-format-findex ()
2889 (texinfo-index 'texinfo-findex))
2891 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
2892 (defun texinfo-format-pindex ()
2893 (texinfo-index 'texinfo-pindex))
2895 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
2896 (defun texinfo-format-tindex ()
2897 (texinfo-index 'texinfo-tindex))
2899 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
2900 (defun texinfo-format-kindex ()
2901 (texinfo-index 'texinfo-kindex))
2903 (defun texinfo-index (indexvar)
2904 (let ((arg (texinfo-parse-expanded-arg)))
2905 (texinfo-discard-command)
2906 (set indexvar
2907 (cons (list arg
2908 texinfo-last-node
2909 ;; Region formatting may not provide last node position.
2910 (if texinfo-last-node-pos
2911 (1+ (count-lines texinfo-last-node-pos (point)))
2913 (symbol-value indexvar)))))
2915 (defconst texinfo-indexvar-alist
2916 '(("cp" . texinfo-cindex)
2917 ("fn" . texinfo-findex)
2918 ("vr" . texinfo-vindex)
2919 ("tp" . texinfo-tindex)
2920 ("pg" . texinfo-pindex)
2921 ("ky" . texinfo-kindex)))
2924 ;;; @defindex @defcodeindex
2925 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
2926 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
2928 (defun texinfo-format-defindex ()
2929 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
2930 (indexing-command (intern (concat index-name "index")))
2931 (index-formatting-command ; eg: `texinfo-format-aaindex'
2932 (intern (concat "texinfo-format-" index-name "index")))
2933 (index-alist-name ; eg: `texinfo-aaindex'
2934 (intern (concat "texinfo-" index-name "index"))))
2936 (set index-alist-name nil)
2938 (put indexing-command ; eg, aaindex
2939 'texinfo-format
2940 index-formatting-command) ; eg, texinfo-format-aaindex
2942 ;; eg: "aa" . texinfo-aaindex
2943 (or (assoc index-name texinfo-indexvar-alist)
2944 (setq texinfo-indexvar-alist
2945 (cons
2946 (cons index-name
2947 index-alist-name)
2948 texinfo-indexvar-alist)))
2950 (fset index-formatting-command
2951 (list 'lambda 'nil
2952 (list 'texinfo-index
2953 (list 'quote index-alist-name))))))
2956 ;;; @synindex @syncodeindex
2958 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
2959 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
2961 (defun texinfo-format-synindex ()
2962 (let* ((args (texinfo-parse-arg-discard))
2963 (second (cdr (read-from-string args)))
2964 (joiner (symbol-name (car (read-from-string args))))
2965 (joined (symbol-name (car (read-from-string args second)))))
2967 (if (assoc joiner texinfo-short-index-cmds-alist)
2968 (put
2969 (cdr (assoc joiner texinfo-short-index-cmds-alist))
2970 'texinfo-format
2971 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
2972 (intern (concat "texinfo-format-" joined "index"))))
2973 (put
2974 (intern (concat joiner "index"))
2975 'texinfo-format
2976 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
2977 (intern (concat "texinfo-format-" joined "index")))))))
2979 (defconst texinfo-short-index-cmds-alist
2980 '(("cp" . cindex)
2981 ("fn" . findex)
2982 ("vr" . vindex)
2983 ("tp" . tindex)
2984 ("pg" . pindex)
2985 ("ky" . kindex)))
2987 (defconst texinfo-short-index-format-cmds-alist
2988 '(("cp" . texinfo-format-cindex)
2989 ("fn" . texinfo-format-findex)
2990 ("vr" . texinfo-format-vindex)
2991 ("tp" . texinfo-format-tindex)
2992 ("pg" . texinfo-format-pindex)
2993 ("ky" . texinfo-format-kindex)))
2996 ;;; Sort and index (for VMS)
2998 ;; Sort an index which is in the current buffer between START and END.
2999 ;; Used on VMS, where the `sort' utility is not available.
3000 (defun texinfo-sort-region (start end)
3001 (require 'sort)
3002 (save-restriction
3003 (narrow-to-region start end)
3004 (goto-char (point-min))
3005 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
3007 ;; Subroutine for sorting an index.
3008 ;; At start of a line, return a string to sort the line under.
3009 (defun texinfo-sort-startkeyfun ()
3010 (let ((line
3011 (buffer-substring-no-properties (point) (save-excursion (end-of-line) (point)))))
3012 ;; Canonicalize whitespace and eliminate funny chars.
3013 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
3014 (setq line (concat (substring line 0 (match-beginning 0))
3016 (substring line (match-end 0) (length line)))))
3017 line))
3020 ;;; @printindex
3022 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
3024 (defun texinfo-format-printindex ()
3025 (let ((indexelts (symbol-value
3026 (cdr (assoc (texinfo-parse-arg-discard)
3027 texinfo-indexvar-alist))))
3028 opoint)
3029 (insert "\n* Menu:\n\n")
3030 (setq opoint (point))
3031 (texinfo-print-index nil indexelts)
3033 (if (memq system-type '(vax-vms windows-nt ms-dos))
3034 (texinfo-sort-region opoint (point))
3035 (shell-command-on-region opoint (point) "sort -fd" 1))))
3037 (defun texinfo-print-index (file indexelts)
3038 (while indexelts
3039 (if (stringp (car (car indexelts)))
3040 (progn
3041 (insert "* " (car (car indexelts)) ": " )
3042 (indent-to 32)
3043 (insert
3044 (if file (concat "(" file ")") "")
3045 (nth 1 (car indexelts)) ".")
3046 (indent-to 54)
3047 (insert
3048 (if (nth 2 (car indexelts))
3049 (format " %d." (nth 2 (car indexelts)))
3051 "\n"))
3052 ;; index entries from @include'd file
3053 (texinfo-print-index (nth 1 (car indexelts))
3054 (nth 2 (car indexelts))))
3055 (setq indexelts (cdr indexelts))))
3058 ;;; Glyphs: @equiv, @error, etc
3060 ;; @equiv to show that two expressions are equivalent
3061 ;; @error to show an error message
3062 ;; @expansion to show what a macro expands to
3063 ;; @point to show the location of point in an example
3064 ;; @print to show what an evaluated expression prints
3065 ;; @result to indicate the value returned by an expression
3067 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
3068 (defun texinfo-format-equiv ()
3069 (texinfo-parse-arg-discard)
3070 (insert "=="))
3072 (put 'error 'texinfo-format 'texinfo-format-error)
3073 (defun texinfo-format-error ()
3074 (texinfo-parse-arg-discard)
3075 (insert "error-->"))
3077 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
3078 (defun texinfo-format-expansion ()
3079 (texinfo-parse-arg-discard)
3080 (insert "==>"))
3082 (put 'point 'texinfo-format 'texinfo-format-point)
3083 (defun texinfo-format-point ()
3084 (texinfo-parse-arg-discard)
3085 (insert "-!-"))
3087 (put 'print 'texinfo-format 'texinfo-format-print)
3088 (defun texinfo-format-print ()
3089 (texinfo-parse-arg-discard)
3090 (insert "-|"))
3092 (put 'result 'texinfo-format 'texinfo-format-result)
3093 (defun texinfo-format-result ()
3094 (texinfo-parse-arg-discard)
3095 (insert "=>"))
3098 ;;; Accent commands
3100 ;; Info presumes a plain ASCII output, so the accented characters do
3101 ;; not look as they would if typeset, or output with a different
3102 ;; character set.
3104 ;; See the `texinfo-accent-commands' variable
3105 ;; in the section for `texinfo-append-refill'.
3106 ;; Also, see the defun for `texinfo-format-scan'
3107 ;; for single-character accent commands.
3109 ;; Command Info output Name
3111 ;; These do not have braces:
3112 ;; @^ ==> ^ circumflex accent
3113 ;; @` ==> ` grave accent
3114 ;; @' ==> ' acute accent
3115 ;; @" ==> " umlaut accent
3116 ;; @= ==> = overbar accent
3117 ;; @~ ==> ~ tilde accent
3119 ;; These have braces, but take no argument:
3120 ;; @OE{} ==> OE French-OE-ligature
3121 ;; @oe{} ==> oe
3122 ;; @AA{} ==> AA Scandinavian-A-with-circle
3123 ;; @aa{} ==> aa
3124 ;; @AE{} ==> AE Latin-Scandinavian-AE
3125 ;; @ae{} ==> ae
3126 ;; @ss{} ==> ss German-sharp-S
3128 ;; @questiondown{} ==> ? upside-down-question-mark
3129 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
3130 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
3131 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
3132 ;; @O{} ==> O/ Scandinavian O-with-slash
3133 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
3135 ;; These have braces, and take an argument:
3136 ;; @,{c} ==> c, cedilla accent
3137 ;; @dotaccent{o} ==> .o overdot-accent
3138 ;; @ubaraccent{o} ==> _o underbar-accent
3139 ;; @udotaccent{o} ==> o-. underdot-accent
3140 ;; @H{o} ==> ""o long Hungarian umlaut
3141 ;; @ringaccent{o} ==> *o ring accent
3142 ;; @tieaccent{oo} ==> [oo tie after accent
3143 ;; @u{o} ==> (o breve accent
3144 ;; @v{o} ==> <o hacek accent
3145 ;; @dotless{i} ==> i dotless i and dotless j
3147 ;; ==========
3149 ;; Note: The defun texinfo-format-scan
3150 ;; looks at "[@{}^'`\",=~ *?!-]"
3151 ;; In the case of @*, a line break is inserted;
3152 ;; in the other cases, the characters are simply quoted and the @ is deleted.
3153 ;; Thus, `texinfo-format-scan' handles the following
3154 ;; single-character accent commands: @^ @` @' @" @, @- @= @~
3156 ;; @^ ==> ^ circumflex accent
3157 ;; (put '^ 'texinfo-format 'texinfo-format-circumflex-accent)
3158 ;; (defun texinfo-format-circumflex-accent ()
3159 ;; (texinfo-discard-command)
3160 ;; (insert "^"))
3162 ;; @` ==> ` grave accent
3163 ;; (put '\` 'texinfo-format 'texinfo-format-grave-accent)
3164 ;; (defun texinfo-format-grave-accent ()
3165 ;; (texinfo-discard-command)
3166 ;; (insert "\`"))
3168 ;; @' ==> ' acute accent
3169 ;; (put '\' 'texinfo-format 'texinfo-format-acute-accent)
3170 ;; (defun texinfo-format-acute-accent ()
3171 ;; (texinfo-discard-command)
3172 ;; (insert "'"))
3174 ;; @" ==> " umlaut accent
3175 ;; (put '\" 'texinfo-format 'texinfo-format-umlaut-accent)
3176 ;; (defun texinfo-format-umlaut-accent ()
3177 ;; (texinfo-discard-command)
3178 ;; (insert "\""))
3180 ;; @= ==> = overbar accent
3181 ;; (put '= 'texinfo-format 'texinfo-format-overbar-accent)
3182 ;; (defun texinfo-format-overbar-accent ()
3183 ;; (texinfo-discard-command)
3184 ;; (insert "="))
3186 ;; @~ ==> ~ tilde accent
3187 ;; (put '~ 'texinfo-format 'texinfo-format-tilde-accent)
3188 ;; (defun texinfo-format-tilde-accent ()
3189 ;; (texinfo-discard-command)
3190 ;; (insert "~"))
3192 ;; @OE{} ==> OE French-OE-ligature
3193 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
3194 (defun texinfo-format-French-OE-ligature ()
3195 (insert "OE" (texinfo-parse-arg-discard))
3196 (goto-char texinfo-command-start))
3198 ;; @oe{} ==> oe
3199 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
3200 (defun texinfo-format-French-oe-ligature () ; lower case
3201 (insert "oe" (texinfo-parse-arg-discard))
3202 (goto-char texinfo-command-start))
3204 ;; @AA{} ==> AA Scandinavian-A-with-circle
3205 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
3206 (defun texinfo-format-Scandinavian-A-with-circle ()
3207 (insert "AA" (texinfo-parse-arg-discard))
3208 (goto-char texinfo-command-start))
3210 ;; @aa{} ==> aa
3211 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
3212 (defun texinfo-format-Scandinavian-a-with-circle () ; lower case
3213 (insert "aa" (texinfo-parse-arg-discard))
3214 (goto-char texinfo-command-start))
3216 ;; @AE{} ==> AE Latin-Scandinavian-AE
3217 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
3218 (defun texinfo-format-Latin-Scandinavian-AE ()
3219 (insert "AE" (texinfo-parse-arg-discard))
3220 (goto-char texinfo-command-start))
3222 ;; @ae{} ==> ae
3223 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
3224 (defun texinfo-format-Latin-Scandinavian-ae () ; lower case
3225 (insert "ae" (texinfo-parse-arg-discard))
3226 (goto-char texinfo-command-start))
3228 ;; @ss{} ==> ss German-sharp-S
3229 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
3230 (defun texinfo-format-German-sharp-S ()
3231 (insert "ss" (texinfo-parse-arg-discard))
3232 (goto-char texinfo-command-start))
3234 ;; @questiondown{} ==> ? upside-down-question-mark
3235 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
3236 (defun texinfo-format-upside-down-question-mark ()
3237 (insert "?" (texinfo-parse-arg-discard))
3238 (goto-char texinfo-command-start))
3240 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
3241 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
3242 (defun texinfo-format-upside-down-exclamation-mark ()
3243 (insert "!" (texinfo-parse-arg-discard))
3244 (goto-char texinfo-command-start))
3246 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
3247 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
3248 (defun texinfo-format-Polish-suppressed-L ()
3249 (insert (texinfo-parse-arg-discard) "/L")
3250 (goto-char texinfo-command-start))
3252 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
3253 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
3254 (defun texinfo-format-Polish-suppressed-l-lower-case ()
3255 (insert (texinfo-parse-arg-discard) "/l")
3256 (goto-char texinfo-command-start))
3259 ;; @O{} ==> O/ Scandinavian O-with-slash
3260 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
3261 (defun texinfo-format-Scandinavian-O-with-slash ()
3262 (insert (texinfo-parse-arg-discard) "O/")
3263 (goto-char texinfo-command-start))
3265 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
3266 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
3267 (defun texinfo-format-Scandinavian-o-with-slash-lower-case ()
3268 (insert (texinfo-parse-arg-discard) "o/")
3269 (goto-char texinfo-command-start))
3271 ;; Take arguments
3273 ;; @,{c} ==> c, cedilla accent
3274 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
3275 (defun texinfo-format-cedilla-accent ()
3276 (insert (texinfo-parse-arg-discard) ",")
3277 (goto-char texinfo-command-start))
3280 ;; @dotaccent{o} ==> .o overdot-accent
3281 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
3282 (defun texinfo-format-overdot-accent ()
3283 (insert "." (texinfo-parse-arg-discard))
3284 (goto-char texinfo-command-start))
3286 ;; @ubaraccent{o} ==> _o underbar-accent
3287 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
3288 (defun texinfo-format-underbar-accent ()
3289 (insert "_" (texinfo-parse-arg-discard))
3290 (goto-char texinfo-command-start))
3292 ;; @udotaccent{o} ==> o-. underdot-accent
3293 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
3294 (defun texinfo-format-underdot-accent ()
3295 (insert (texinfo-parse-arg-discard) "-.")
3296 (goto-char texinfo-command-start))
3298 ;; @H{o} ==> ""o long Hungarian umlaut
3299 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
3300 (defun texinfo-format-long-Hungarian-umlaut ()
3301 (insert "\"\"" (texinfo-parse-arg-discard))
3302 (goto-char texinfo-command-start))
3304 ;; @ringaccent{o} ==> *o ring accent
3305 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
3306 (defun texinfo-format-ring-accent ()
3307 (insert "*" (texinfo-parse-arg-discard))
3308 (goto-char texinfo-command-start))
3310 ;; @tieaccent{oo} ==> [oo tie after accent
3311 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
3312 (defun texinfo-format-tie-after-accent ()
3313 (insert "[" (texinfo-parse-arg-discard))
3314 (goto-char texinfo-command-start))
3317 ;; @u{o} ==> (o breve accent
3318 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
3319 (defun texinfo-format-breve-accent ()
3320 (insert "(" (texinfo-parse-arg-discard))
3321 (goto-char texinfo-command-start))
3323 ;; @v{o} ==> <o hacek accent
3324 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
3325 (defun texinfo-format-hacek-accent ()
3326 (insert "<" (texinfo-parse-arg-discard))
3327 (goto-char texinfo-command-start))
3330 ;; @dotless{i} ==> i dotless i and dotless j
3331 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
3332 (defun texinfo-format-dotless ()
3333 (insert (texinfo-parse-arg-discard))
3334 (goto-char texinfo-command-start))
3337 ;;; Definition formatting: @deffn, @defun, etc
3339 ;; What definition formatting produces:
3341 ;; @deffn category name args...
3342 ;; In Info, `Category: name ARGS'
3343 ;; In index: name: node. line#.
3345 ;; @defvr category name
3346 ;; In Info, `Category: name'
3347 ;; In index: name: node. line#.
3349 ;; @deftp category name attributes...
3350 ;; `category name attributes...' Note: @deftp args in lower case.
3351 ;; In index: name: node. line#.
3353 ;; Specialized function-like or variable-like entity:
3355 ;; @defun, @defmac, @defspec, @defvar, @defopt
3357 ;; @defun name args In Info, `Function: name ARGS'
3358 ;; @defmac name args In Info, `Macro: name ARGS'
3359 ;; @defvar name In Info, `Variable: name'
3360 ;; etc.
3361 ;; In index: name: node. line#.
3363 ;; Generalized typed-function-like or typed-variable-like entity:
3364 ;; @deftypefn category data-type name args...
3365 ;; In Info, `Category: data-type name args...'
3366 ;; @deftypevr category data-type name
3367 ;; In Info, `Category: data-type name'
3368 ;; In index: name: node. line#.
3370 ;; Specialized typed-function-like or typed-variable-like entity:
3371 ;; @deftypefun data-type name args...
3372 ;; In Info, `Function: data-type name ARGS'
3373 ;; In index: name: node. line#.
3375 ;; @deftypevar data-type name
3376 ;; In Info, `Variable: data-type name'
3377 ;; In index: name: node. line#. but include args after name!?
3379 ;; Generalized object oriented entity:
3380 ;; @defop category class name args...
3381 ;; In Info, `Category on class: name ARG'
3382 ;; In index: name on class: node. line#.
3384 ;; @defcv category class name
3385 ;; In Info, `Category of class: name'
3386 ;; In index: name of class: node. line#.
3388 ;; Specialized object oriented entity:
3389 ;; @defmethod class name args...
3390 ;; In Info, `Method on class: name ARGS'
3391 ;; In index: name on class: node. line#.
3393 ;; @defivar class name
3394 ;; In Info, `Instance variable of class: name'
3395 ;; In index: name of class: node. line#.
3398 ;;; The definition formatting functions
3400 (defun texinfo-format-defun ()
3401 (texinfo-push-stack 'defun nil)
3402 (setq fill-column (- fill-column 5))
3403 (texinfo-format-defun-1 t))
3405 (defun texinfo-end-defun ()
3406 (setq fill-column (+ fill-column 5))
3407 (texinfo-discard-command)
3408 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
3409 (texinfo-do-itemize start)
3410 ;; Delete extra newline inserted after header.
3411 (save-excursion
3412 (goto-char start)
3413 (delete-char -1))))
3415 (defun texinfo-format-defunx ()
3416 (texinfo-format-defun-1 nil))
3418 (defun texinfo-format-defun-1 (first-p)
3419 (let ((parse-args (texinfo-format-parse-defun-args))
3420 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
3421 (texinfo-discard-command)
3422 ;; Delete extra newline inserted after previous header line.
3423 (if (not first-p)
3424 (delete-char -1))
3425 (funcall
3426 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
3427 ;; Insert extra newline so that paragraph filling does not mess
3428 ;; with header line.
3429 (insert "\n\n")
3430 (rplaca (cdr (cdr (car texinfo-stack))) (point))
3431 (funcall
3432 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
3434 ;;; Formatting the first line of a definition
3436 ;; @deffn, @defvr, @deftp
3437 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3438 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3439 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3440 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3441 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3442 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
3443 (defun texinfo-format-deffn (parsed-args)
3444 ;; Generalized function-like, variable-like, or generic data-type entity:
3445 ;; @deffn category name args...
3446 ;; In Info, `Category: name ARGS'
3447 ;; @deftp category name attributes...
3448 ;; `category name attributes...' Note: @deftp args in lower case.
3449 (let ((category (car parsed-args))
3450 (name (car (cdr parsed-args)))
3451 (args (cdr (cdr parsed-args))))
3452 (insert " -- " category ": " name)
3453 (while args
3454 (insert " "
3455 (if (or (= ?& (aref (car args) 0))
3456 (eq (eval (car texinfo-defun-type)) 'deftp-type))
3457 (car args)
3458 (upcase (car args))))
3459 (setq args (cdr args)))))
3461 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
3462 (put 'defun 'texinfo-deffn-formatting-property
3463 'texinfo-format-specialized-defun)
3464 (put 'defunx 'texinfo-deffn-formatting-property
3465 'texinfo-format-specialized-defun)
3466 (put 'defmac 'texinfo-deffn-formatting-property
3467 'texinfo-format-specialized-defun)
3468 (put 'defmacx 'texinfo-deffn-formatting-property
3469 'texinfo-format-specialized-defun)
3470 (put 'defspec 'texinfo-deffn-formatting-property
3471 'texinfo-format-specialized-defun)
3472 (put 'defspecx 'texinfo-deffn-formatting-property
3473 'texinfo-format-specialized-defun)
3474 (put 'defvar 'texinfo-deffn-formatting-property
3475 'texinfo-format-specialized-defun)
3476 (put 'defvarx 'texinfo-deffn-formatting-property
3477 'texinfo-format-specialized-defun)
3478 (put 'defopt 'texinfo-deffn-formatting-property
3479 'texinfo-format-specialized-defun)
3480 (put 'defoptx 'texinfo-deffn-formatting-property
3481 'texinfo-format-specialized-defun)
3482 (defun texinfo-format-specialized-defun (parsed-args)
3483 ;; Specialized function-like or variable-like entity:
3484 ;; @defun name args In Info, `Function: Name ARGS'
3485 ;; @defmac name args In Info, `Macro: Name ARGS'
3486 ;; @defvar name In Info, `Variable: Name'
3487 ;; Use cdr of texinfo-defun-type to determine category:
3488 (let ((category (car (cdr texinfo-defun-type)))
3489 (name (car parsed-args))
3490 (args (cdr parsed-args)))
3491 (insert " -- " category ": " name)
3492 (while args
3493 (insert " "
3494 (if (= ?& (aref (car args) 0))
3495 (car args)
3496 (upcase (car args))))
3497 (setq args (cdr args)))))
3499 ;; @deftypefn, @deftypevr: Generalized typed
3500 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3501 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3502 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3503 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
3504 (defun texinfo-format-deftypefn (parsed-args)
3505 ;; Generalized typed-function-like or typed-variable-like entity:
3506 ;; @deftypefn category data-type name args...
3507 ;; In Info, `Category: data-type name args...'
3508 ;; @deftypevr category data-type name
3509 ;; In Info, `Category: data-type name'
3510 ;; Note: args in lower case, unless modified in command line.
3511 (let ((category (car parsed-args))
3512 (data-type (car (cdr parsed-args)))
3513 (name (car (cdr (cdr parsed-args))))
3514 (args (cdr (cdr (cdr parsed-args)))))
3515 (insert " -- " category ": " data-type " " name)
3516 (while args
3517 (insert " " (car args))
3518 (setq args (cdr args)))))
3520 ;; @deftypefun, @deftypevar: Specialized typed
3521 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3522 (put 'deftypefunx 'texinfo-deffn-formatting-property
3523 'texinfo-format-deftypefun)
3524 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
3525 (put 'deftypevarx 'texinfo-deffn-formatting-property
3526 'texinfo-format-deftypefun)
3527 (defun texinfo-format-deftypefun (parsed-args)
3528 ;; Specialized typed-function-like or typed-variable-like entity:
3529 ;; @deftypefun data-type name args...
3530 ;; In Info, `Function: data-type name ARGS'
3531 ;; @deftypevar data-type name
3532 ;; In Info, `Variable: data-type name'
3533 ;; Note: args in lower case, unless modified in command line.
3534 ;; Use cdr of texinfo-defun-type to determine category:
3535 (let ((category (car (cdr texinfo-defun-type)))
3536 (data-type (car parsed-args))
3537 (name (car (cdr parsed-args)))
3538 (args (cdr (cdr parsed-args))))
3539 (insert " -- " category ": " data-type " " name)
3540 (while args
3541 (insert " " (car args))
3542 (setq args (cdr args)))))
3544 ;; @defop: Generalized object-oriented
3545 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3546 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
3547 (defun texinfo-format-defop (parsed-args)
3548 ;; Generalized object oriented entity:
3549 ;; @defop category class name args...
3550 ;; In Info, `Category on class: name ARG'
3551 ;; Note: args in upper case; use of `on'
3552 (let ((category (car parsed-args))
3553 (class (car (cdr parsed-args)))
3554 (name (car (cdr (cdr parsed-args))))
3555 (args (cdr (cdr (cdr parsed-args)))))
3556 (insert " -- " category " on " class ": " name)
3557 (while args
3558 (insert " " (upcase (car args)))
3559 (setq args (cdr args)))))
3561 ;; @defcv: Generalized object-oriented
3562 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3563 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
3564 (defun texinfo-format-defcv (parsed-args)
3565 ;; Generalized object oriented entity:
3566 ;; @defcv category class name
3567 ;; In Info, `Category of class: name'
3568 ;; Note: args in upper case; use of `of'
3569 (let ((category (car parsed-args))
3570 (class (car (cdr parsed-args)))
3571 (name (car (cdr (cdr parsed-args))))
3572 (args (cdr (cdr (cdr parsed-args)))))
3573 (insert " -- " category " of " class ": " name)
3574 (while args
3575 (insert " " (upcase (car args)))
3576 (setq args (cdr args)))))
3578 ;; @defmethod: Specialized object-oriented
3579 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3580 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
3581 (defun texinfo-format-defmethod (parsed-args)
3582 ;; Specialized object oriented entity:
3583 ;; @defmethod class name args...
3584 ;; In Info, `Method on class: name ARGS'
3585 ;; Note: args in upper case; use of `on'
3586 ;; Use cdr of texinfo-defun-type to determine category:
3587 (let ((category (car (cdr texinfo-defun-type)))
3588 (class (car parsed-args))
3589 (name (car (cdr parsed-args)))
3590 (args (cdr (cdr parsed-args))))
3591 (insert " -- " category " on " class ": " name)
3592 (while args
3593 (insert " " (upcase (car args)))
3594 (setq args (cdr args)))))
3596 ;; @defivar: Specialized object-oriented
3597 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3598 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
3599 (defun texinfo-format-defivar (parsed-args)
3600 ;; Specialized object oriented entity:
3601 ;; @defivar class name
3602 ;; In Info, `Instance variable of class: name'
3603 ;; Note: args in upper case; use of `of'
3604 ;; Use cdr of texinfo-defun-type to determine category:
3605 (let ((category (car (cdr texinfo-defun-type)))
3606 (class (car parsed-args))
3607 (name (car (cdr parsed-args)))
3608 (args (cdr (cdr parsed-args))))
3609 (insert " -- " category " of " class ": " name)
3610 (while args
3611 (insert " " (upcase (car args)))
3612 (setq args (cdr args)))))
3615 ;;; Indexing for definitions
3617 ;; An index entry has three parts: the `entry proper', the node name, and the
3618 ;; line number. Depending on the which command is used, the entry is
3619 ;; formatted differently:
3621 ;; @defun,
3622 ;; @defmac,
3623 ;; @defspec,
3624 ;; @defvar,
3625 ;; @defopt all use their 1st argument as the entry-proper
3627 ;; @deffn,
3628 ;; @defvr,
3629 ;; @deftp
3630 ;; @deftypefun
3631 ;; @deftypevar all use their 2nd argument as the entry-proper
3633 ;; @deftypefn,
3634 ;; @deftypevr both use their 3rd argument as the entry-proper
3636 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
3637 ;; formatted: NAME on CLASS
3639 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
3640 ;; formatted: NAME on CLASS
3642 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
3643 ;; formatted: NAME of CLASS
3645 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
3646 ;; formatted: NAME of CLASS
3648 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
3649 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3650 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
3651 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3652 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
3653 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3654 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
3655 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3656 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
3657 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
3658 (defun texinfo-index-defun (parsed-args)
3659 ;; use 1st parsed-arg as entry-proper
3660 ;; `index-list' will be texinfo-findex or the like
3661 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3662 (set index-list
3663 (cons
3664 ;; Three elements: entry-proper, node-name, line-number
3665 (list
3666 (car parsed-args)
3667 texinfo-last-node
3668 ;; Region formatting may not provide last node position.
3669 (if texinfo-last-node-pos
3670 (1+ (count-lines texinfo-last-node-pos (point)))
3672 (symbol-value index-list)))))
3674 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3675 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3676 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3677 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3678 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3679 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3680 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3681 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3682 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3683 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
3684 (defun texinfo-index-deffn (parsed-args)
3685 ;; use 2nd parsed-arg as entry-proper
3686 ;; `index-list' will be texinfo-findex or the like
3687 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3688 (set index-list
3689 (cons
3690 ;; Three elements: entry-proper, node-name, line-number
3691 (list
3692 (car (cdr parsed-args))
3693 texinfo-last-node
3694 ;; Region formatting may not provide last node position.
3695 (if texinfo-last-node-pos
3696 (1+ (count-lines texinfo-last-node-pos (point)))
3698 (symbol-value index-list)))))
3700 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3701 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3702 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3703 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
3704 (defun texinfo-index-deftypefn (parsed-args)
3705 ;; use 3rd parsed-arg as entry-proper
3706 ;; `index-list' will be texinfo-findex or the like
3707 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3708 (set index-list
3709 (cons
3710 ;; Three elements: entry-proper, node-name, line-number
3711 (list
3712 (car (cdr (cdr parsed-args)))
3713 texinfo-last-node
3714 ;; Region formatting may not provide last node position.
3715 (if texinfo-last-node-pos
3716 (1+ (count-lines texinfo-last-node-pos (point)))
3718 (symbol-value index-list)))))
3720 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3721 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
3722 (defun texinfo-index-defmethod (parsed-args)
3723 ;; use 2nd on 1st parsed-arg as entry-proper
3724 ;; `index-list' will be texinfo-findex or the like
3725 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3726 (set index-list
3727 (cons
3728 ;; Three elements: entry-proper, node-name, line-number
3729 (list
3730 (format "%s on %s"
3731 (car (cdr parsed-args))
3732 (car parsed-args))
3733 texinfo-last-node
3734 ;; Region formatting may not provide last node position.
3735 (if texinfo-last-node-pos
3736 (1+ (count-lines texinfo-last-node-pos (point)))
3738 (symbol-value index-list)))))
3740 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
3741 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
3742 (defun texinfo-index-defop (parsed-args)
3743 ;; use 3rd on 2nd parsed-arg as entry-proper
3744 ;; `index-list' will be texinfo-findex or the like
3745 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3746 (set index-list
3747 (cons
3748 ;; Three elements: entry-proper, node-name, line-number
3749 (list
3750 (format "%s on %s"
3751 (car (cdr (cdr parsed-args)))
3752 (car (cdr parsed-args)))
3753 texinfo-last-node
3754 ;; Region formatting may not provide last node position.
3755 (if texinfo-last-node-pos
3756 (1+ (count-lines texinfo-last-node-pos (point)))
3758 (symbol-value index-list)))))
3760 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3761 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
3762 (defun texinfo-index-defivar (parsed-args)
3763 ;; use 2nd of 1st parsed-arg as entry-proper
3764 ;; `index-list' will be texinfo-findex or the like
3765 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3766 (set index-list
3767 (cons
3768 ;; Three elements: entry-proper, node-name, line-number
3769 (list
3770 (format "%s of %s"
3771 (car (cdr parsed-args))
3772 (car parsed-args))
3773 texinfo-last-node
3774 ;; Region formatting may not provide last node position.
3775 (if texinfo-last-node-pos
3776 (1+ (count-lines texinfo-last-node-pos (point)))
3778 (symbol-value index-list)))))
3780 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3781 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
3782 (defun texinfo-index-defcv (parsed-args)
3783 ;; use 3rd of 2nd parsed-arg as entry-proper
3784 ;; `index-list' will be texinfo-findex or the like
3785 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
3786 (set index-list
3787 (cons
3788 ;; Three elements: entry-proper, node-name, line-number
3789 (list
3790 (format "%s of %s"
3791 (car (cdr (cdr parsed-args)))
3792 (car (cdr parsed-args)))
3793 texinfo-last-node
3794 ;; Region formatting may not provide last node position.
3795 (if texinfo-last-node-pos
3796 (1+ (count-lines texinfo-last-node-pos (point)))
3798 (symbol-value index-list)))))
3801 ;;; Properties for definitions
3803 ;; Each definition command has six properties:
3805 ;; 1. texinfo-deffn-formatting-property to format definition line
3806 ;; 2. texinfo-defun-indexing-property to create index entry
3807 ;; 3. texinfo-format formatting command
3808 ;; 4. texinfo-end end formatting command
3809 ;; 5. texinfo-defun-type type of deffn to format
3810 ;; 6. texinfo-defun-index type of index to use
3812 ;; The `x' forms of each definition command are used for the second
3813 ;; and subsequent header lines.
3815 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
3816 ;; are listed just before the appropriate formatting and indexing commands.
3818 (put 'deffn 'texinfo-format 'texinfo-format-defun)
3819 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
3820 (put 'deffn 'texinfo-end 'texinfo-end-defun)
3821 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
3822 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
3823 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
3824 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
3826 (put 'defun 'texinfo-format 'texinfo-format-defun)
3827 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
3828 (put 'defun 'texinfo-end 'texinfo-end-defun)
3829 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
3830 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
3831 (put 'defun 'texinfo-defun-index 'texinfo-findex)
3832 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
3834 (put 'defmac 'texinfo-format 'texinfo-format-defun)
3835 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
3836 (put 'defmac 'texinfo-end 'texinfo-end-defun)
3837 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
3838 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
3839 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
3840 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
3842 (put 'defspec 'texinfo-format 'texinfo-format-defun)
3843 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
3844 (put 'defspec 'texinfo-end 'texinfo-end-defun)
3845 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
3846 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
3847 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
3848 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
3850 (put 'defvr 'texinfo-format 'texinfo-format-defun)
3851 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
3852 (put 'defvr 'texinfo-end 'texinfo-end-defun)
3853 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
3854 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
3855 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
3856 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
3858 (put 'defvar 'texinfo-format 'texinfo-format-defun)
3859 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
3860 (put 'defvar 'texinfo-end 'texinfo-end-defun)
3861 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
3862 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
3863 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
3864 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
3866 (put 'defconst 'texinfo-format 'texinfo-format-defun)
3867 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
3868 (put 'defconst 'texinfo-end 'texinfo-end-defun)
3869 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
3870 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
3871 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
3872 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
3874 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
3875 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
3876 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
3877 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
3878 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
3879 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
3880 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
3882 (put 'defopt 'texinfo-format 'texinfo-format-defun)
3883 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
3884 (put 'defopt 'texinfo-end 'texinfo-end-defun)
3885 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
3886 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
3887 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
3888 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
3890 (put 'deftp 'texinfo-format 'texinfo-format-defun)
3891 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
3892 (put 'deftp 'texinfo-end 'texinfo-end-defun)
3893 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
3894 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
3895 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
3896 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
3898 ;;; Object-oriented stuff is a little hairier.
3900 (put 'defop 'texinfo-format 'texinfo-format-defun)
3901 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
3902 (put 'defop 'texinfo-end 'texinfo-end-defun)
3903 (put 'defop 'texinfo-defun-type '('defop-type nil))
3904 (put 'defopx 'texinfo-defun-type '('defop-type nil))
3905 (put 'defop 'texinfo-defun-index 'texinfo-findex)
3906 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
3908 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
3909 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
3910 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
3911 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
3912 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
3913 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
3914 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
3916 (put 'defcv 'texinfo-format 'texinfo-format-defun)
3917 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
3918 (put 'defcv 'texinfo-end 'texinfo-end-defun)
3919 (put 'defcv 'texinfo-defun-type '('defop-type nil))
3920 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
3921 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
3922 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
3924 (put 'defivar 'texinfo-format 'texinfo-format-defun)
3925 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
3926 (put 'defivar 'texinfo-end 'texinfo-end-defun)
3927 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
3928 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
3929 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
3930 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
3932 ;;; Typed functions and variables
3934 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
3935 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
3936 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
3937 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
3938 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
3939 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
3940 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
3942 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
3943 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
3944 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
3945 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
3946 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
3947 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
3948 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
3950 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
3951 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
3952 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
3953 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
3954 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
3955 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
3956 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
3958 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
3959 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
3960 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
3961 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
3962 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
3963 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
3964 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
3967 ;;; @set, @clear, @ifset, @ifclear
3969 ;; If a flag is set with @set FLAG, then text between @ifset and @end
3970 ;; ifset is formatted normally, but if the flag is is cleared with
3971 ;; @clear FLAG, then the text is not formatted; it is ignored.
3973 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
3974 ;; and @end ifclear is formatted normally, but if the flag is is set with
3975 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
3976 ;; is the opposite of @ifset.
3978 ;; If a flag is set to a string with @set FLAG,
3979 ;; replace @value{FLAG} with the string.
3980 ;; If a flag with a value is cleared,
3981 ;; @value{FLAG} is invalid,
3982 ;; as if there had never been any @set FLAG previously.
3984 (put 'clear 'texinfo-format 'texinfo-clear)
3985 (defun texinfo-clear ()
3986 "Clear the value of the flag."
3987 (let* ((arg (texinfo-parse-arg-discard))
3988 (flag (car (read-from-string arg)))
3989 (value (substring arg (cdr (read-from-string arg)))))
3990 (put flag 'texinfo-whether-setp 'flag-cleared)
3991 (put flag 'texinfo-set-value "")))
3993 (put 'set 'texinfo-format 'texinfo-set)
3994 (defun texinfo-set ()
3995 "Set the value of the flag, optionally to a string.
3996 The command `@set foo This is a string.'
3997 sets flag foo to the value: `This is a string.'
3998 The command `@value{foo}' expands to the value."
3999 (let* ((arg (texinfo-parse-arg-discard))
4000 (flag (car (read-from-string arg)))
4001 (value (substring arg (cdr (read-from-string arg)))))
4002 (if (string-match "^[ \t]+" value)
4003 (setq value (substring value (match-end 0))))
4004 (put flag 'texinfo-whether-setp 'flag-set)
4005 (put flag 'texinfo-set-value value)))
4007 (put 'value 'texinfo-format 'texinfo-value)
4008 (defun texinfo-value ()
4009 "Insert the string to which the flag is set.
4010 The command `@set foo This is a string.'
4011 sets flag foo to the value: `This is a string.'
4012 The command `@value{foo}' expands to the value."
4013 (let ((arg (texinfo-parse-arg-discard)))
4014 (cond ((and
4015 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4016 'flag-set)
4017 (get (car (read-from-string arg)) 'texinfo-set-value))
4018 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
4019 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4020 'flag-cleared)
4021 (insert (format "{No value for \"%s\"}" arg)))
4022 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
4023 (insert (format "{No value for \"%s\"}" arg))))))
4025 (put 'ifset 'texinfo-end 'texinfo-discard-command)
4026 (put 'ifset 'texinfo-format 'texinfo-if-set)
4027 (defun texinfo-if-set ()
4028 "If set, continue formatting; else do not format region up to @end ifset"
4029 (let ((arg (texinfo-parse-arg-discard)))
4030 (cond
4031 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4032 'flag-set)
4033 ;; Format the text (i.e., do not remove it); do nothing here.
4035 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4036 'flag-cleared)
4037 ;; Clear region (i.e., cause the text to be ignored).
4038 (delete-region texinfo-command-start
4039 (progn (re-search-forward "@end ifset[ \t]*\n")
4040 (point))))
4041 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4042 nil)
4043 ;; In this case flag is neither set nor cleared.
4044 ;; Act as if set, i.e. do nothing.
4045 ()))))
4047 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
4048 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
4049 (defun texinfo-if-clear ()
4050 "If clear, continue formatting; if set, do not format up to @end ifset"
4051 (let ((arg (texinfo-parse-arg-discard)))
4052 (cond
4053 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4054 'flag-set)
4055 ;; Clear region (i.e., cause the text to be ignored).
4056 (delete-region texinfo-command-start
4057 (progn (re-search-forward "@end ifclear[ \t]*\n")
4058 (point))))
4059 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4060 'flag-cleared)
4061 ;; Format the text (i.e., do not remove it); do nothing here.
4063 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
4064 nil)
4065 ;; In this case flag is neither set nor cleared.
4066 ;; Act as if clear, i.e. do nothing.
4067 ()))))
4069 ;;; @ifeq
4071 (put 'ifeq 'texinfo-format 'texinfo-format-ifeq)
4072 (defun texinfo-format-ifeq ()
4073 "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND.
4074 Otherwise produces no output.
4076 Thus:
4077 @ifeq{ arg1 , arg1 , @code{foo}} bar
4079 ==> `foo' bar.
4081 @ifeq{ arg1 , arg2 , @code{foo}} bar
4083 ==> bar
4085 Note that the Texinfo command and its arguments must be arguments to
4086 the @ifeq command."
4087 ;; compare-buffer-substrings does not exist in version 18; don't use
4088 (goto-char texinfo-command-end)
4089 (let* ((case-fold-search t)
4090 (stop (save-excursion (forward-sexp 1) (point)))
4091 start end
4092 ;; @ifeq{arg1, arg2, @command{optional-args}}
4093 (arg1
4094 (progn
4095 (forward-char 1)
4096 (skip-chars-forward " ")
4097 (setq start (point))
4098 (search-forward "," stop t)
4099 (skip-chars-backward ", ")
4100 (buffer-substring-no-properties start (point))))
4101 (arg2
4102 (progn
4103 (search-forward "," stop t)
4104 (skip-chars-forward " ")
4105 (setq start (point))
4106 (search-forward "," stop t)
4107 (skip-chars-backward ", ")
4108 (buffer-substring-no-properties start (point))))
4109 (texinfo-command
4110 (progn
4111 (search-forward "," stop t)
4112 (skip-chars-forward " ")
4113 (setq start (point))
4114 (goto-char (1- stop))
4115 (skip-chars-backward " ")
4116 (buffer-substring-no-properties start (point)))))
4117 (delete-region texinfo-command-start stop)
4118 (if (equal arg1 arg2)
4119 (insert texinfo-command))
4120 (goto-char texinfo-command-start)))
4123 ;;; Process included files: `@include' command
4125 ;; Updated 19 October 1990
4126 ;; In the original version, include files were ignored by Info but
4127 ;; incorporated in to the printed manual. To make references to the
4128 ;; included file, the Texinfo source file has to refer to the included
4129 ;; files using the `(filename)nodename' format for referring to other
4130 ;; Info files. Also, the included files had to be formatted on their
4131 ;; own. It was just like they were another file.
4133 ;; Currently, include files are inserted into the buffer that is
4134 ;; formatted for Info. If large, the resulting info file is split and
4135 ;; tagified. For current include files to work, the master menu must
4136 ;; refer to all the nodes, and the highest level nodes in the include
4137 ;; files must have the correct next, prev, and up pointers.
4139 ;; The included file may have an @setfilename and even an @settitle,
4140 ;; but not an `\input texinfo' line.
4142 ;; Updated 24 March 1993
4143 ;; In order for @raisesections and @lowersections to work, included
4144 ;; files must be inserted into the buffer holding the outer file
4145 ;; before other Info formatting takes place. So @include is no longer
4146 ;; is treated like other @-commands.
4147 (put 'include 'texinfo-format 'texinfo-format-noop)
4149 ;; Original definition:
4150 ;; (defun texinfo-format-include ()
4151 ;; (let ((filename (texinfo-parse-arg-discard))
4152 ;; (default-directory input-directory)
4153 ;; subindex)
4154 ;; (setq subindex
4155 ;; (save-excursion
4156 ;; (progn (find-file
4157 ;; (cond ((file-readable-p (concat filename ".texinfo"))
4158 ;; (concat filename ".texinfo"))
4159 ;; ((file-readable-p (concat filename ".texi"))
4160 ;; (concat filename ".texi"))
4161 ;; ((file-readable-p (concat filename ".tex"))
4162 ;; (concat filename ".tex"))
4163 ;; ((file-readable-p filename)
4164 ;; filename)
4165 ;; (t (error "@include'd file %s not found"
4166 ;; filename))))
4167 ;; (texinfo-format-buffer-1))))
4168 ;; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
4169 ;; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
4170 ;; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
4171 ;; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
4172 ;; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
4173 ;; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
4175 ;;(defun texinfo-subindex (indexvar file content)
4176 ;; (set indexvar (cons (list 'recurse file content)
4177 ;; (symbol-value indexvar))))
4179 ;; Second definition:
4180 ;; (put 'include 'texinfo-format 'texinfo-format-include)
4181 ;; (defun texinfo-format-include ()
4182 ;; (let ((filename (concat input-directory
4183 ;; (texinfo-parse-arg-discard)))
4184 ;; (default-directory input-directory))
4185 ;; (message "Reading: %s" filename)
4186 ;; (save-excursion
4187 ;; (save-restriction
4188 ;; (narrow-to-region
4189 ;; (point)
4190 ;; (+ (point) (car (cdr (insert-file-contents filename)))))
4191 ;; (goto-char (point-min))
4192 ;; (texinfo-append-refill)
4193 ;; (texinfo-format-convert (point-min) (point-max))))
4194 ;; (setq last-input-buffer input-buffer) ; to bypass setfilename
4195 ;; ))
4198 ;;; Numerous commands do nothing in Info
4199 ;; These commands are defined in texinfo.tex for printed output.
4202 ;;; various noops, such as @b{foo}, that take arguments in braces
4204 (put 'b 'texinfo-format 'texinfo-format-noop)
4205 (put 'i 'texinfo-format 'texinfo-format-noop)
4206 (put 'r 'texinfo-format 'texinfo-format-noop)
4207 (put 't 'texinfo-format 'texinfo-format-noop)
4208 (put 'w 'texinfo-format 'texinfo-format-noop)
4209 (put 'asis 'texinfo-format 'texinfo-format-noop)
4210 (put 'dmn 'texinfo-format 'texinfo-format-noop)
4211 (put 'math 'texinfo-format 'texinfo-format-noop)
4212 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
4213 (defun texinfo-format-noop ()
4214 (insert (texinfo-parse-arg-discard))
4215 (goto-char texinfo-command-start))
4217 ;; @hyphenation command discards an argument within braces
4218 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
4219 (defun texinfo-discard-command-and-arg ()
4220 "Discard both @-command and its argument in braces."
4221 (goto-char texinfo-command-end)
4222 (forward-list 1)
4223 (setq texinfo-command-end (point))
4224 (delete-region texinfo-command-start texinfo-command-end))
4227 ;;; Do nothing commands, such as @smallbook, that have no args and no braces
4228 ;; These must appear on a line of their own
4230 (put 'bye 'texinfo-format 'texinfo-discard-line)
4231 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
4232 (put 'finalout 'texinfo-format 'texinfo-discard-line)
4233 (put 'overfullrule 'texinfo-format 'texinfo-discard-line)
4234 (put 'smallbreak 'texinfo-format 'texinfo-discard-line)
4235 (put 'medbreak 'texinfo-format 'texinfo-discard-line)
4236 (put 'bigbreak 'texinfo-format 'texinfo-discard-line)
4237 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
4238 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
4239 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
4240 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
4243 ;;; These noop commands discard the rest of the line.
4245 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
4246 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
4247 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
4248 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
4249 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
4250 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
4251 (put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args)
4252 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
4253 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
4254 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
4255 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
4256 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
4258 ;; @novalidate suppresses cross-reference checking and auxiliary file
4259 ;; creation with TeX. The Info-validate command checks that every
4260 ;; node pointer points to an existing node. Since this Info command
4261 ;; is not invoked automatically, the @novalidate command is irrelevant
4262 ;; and not supported by texinfmt.el
4263 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
4265 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
4266 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
4267 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
4268 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
4269 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
4271 (put 'setcontentsaftertitlepage
4272 'texinfo-format 'texinfo-discard-line-with-args)
4273 (put 'setshortcontentsaftertitlepage
4274 'texinfo-format 'texinfo-discard-line-with-args)
4276 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
4277 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
4278 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
4279 (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args)
4280 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
4281 (put 'input 'texinfo-format 'texinfo-discard-line-with-args)
4283 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
4284 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
4288 ;;; Some commands cannot be handled
4290 (defun texinfo-unsupported ()
4291 (error "%s is not handled by texinfo"
4292 (buffer-substring-no-properties texinfo-command-start texinfo-command-end)))
4294 ;;; Batch formatting
4296 (defun batch-texinfo-format ()
4297 "Runs texinfo-format-buffer on the files remaining on the command line.
4298 Must be used only with -batch, and kills emacs on completion.
4299 Each file will be processed even if an error occurred previously.
4300 For example, invoke
4301 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
4302 (if (not noninteractive)
4303 (error "batch-texinfo-format may only be used -batch"))
4304 (let ((version-control t)
4305 (auto-save-default nil)
4306 (find-file-run-dired nil)
4307 (kept-old-versions 259259)
4308 (kept-new-versions 259259))
4309 (let ((error 0)
4310 file
4311 (files ()))
4312 (while command-line-args-left
4313 (setq file (expand-file-name (car command-line-args-left)))
4314 (cond ((not (file-exists-p file))
4315 (message ">> %s does not exist!" file)
4316 (setq error 1
4317 command-line-args-left (cdr command-line-args-left)))
4318 ((file-directory-p file)
4319 (setq command-line-args-left
4320 (nconc (directory-files file)
4321 (cdr command-line-args-left))))
4323 (setq files (cons file files)
4324 command-line-args-left (cdr command-line-args-left)))))
4325 (while files
4326 (setq file (car files)
4327 files (cdr files))
4328 (condition-case err
4329 (progn
4330 (if buffer-file-name (kill-buffer (current-buffer)))
4331 (find-file file)
4332 (buffer-disable-undo (current-buffer))
4333 (set-buffer-modified-p nil)
4334 (texinfo-mode)
4335 (message "texinfo formatting %s..." file)
4336 (texinfo-format-buffer nil)
4337 (if (buffer-modified-p)
4338 (progn (message "Saving modified %s" (buffer-file-name))
4339 (save-buffer))))
4340 (error
4341 (message ">> Error: %s" (prin1-to-string err))
4342 (message ">> point at")
4343 (let ((s (buffer-substring-no-properties (point)
4344 (min (+ (point) 100)
4345 (point-max))))
4346 (tem 0))
4347 (while (setq tem (string-match "\n+" s tem))
4348 (setq s (concat (substring s 0 (match-beginning 0))
4349 "\n>> "
4350 (substring s (match-end 0)))
4351 tem (1+ tem)))
4352 (message ">> %s" s))
4353 (setq error 1))))
4354 (kill-emacs error))))
4357 ;;; Place `provide' at end of file.
4358 (provide 'texinfmt)
4360 ;;; texinfmt.el ends here