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