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