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