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