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