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