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