(set-hard-newline-properties): New fn.
[bpt/emacs.git] / lisp / textmodes / texinfmt.el
1 ;;; texinfmt.el --- format Texinfo files into Info files.
2
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993 Free Software
4 ;; Foundation, Inc.
5
6 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 ;;; Emacs lisp functions to convert Texinfo files to Info files.
28
29 (defvar texinfmt-version "2.32 of 19 November 1993")
30 \f
31 ;;; Variable definitions
32
33 (require 'texinfo) ; So `texinfo-footnote-style' is defined.
34 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
35
36 (defvar texinfo-format-syntax-table nil)
37
38 (defvar texinfo-vindex)
39 (defvar texinfo-findex)
40 (defvar texinfo-cindex)
41 (defvar texinfo-pindex)
42 (defvar texinfo-tindex)
43 (defvar texinfo-kindex)
44 (defvar texinfo-last-node)
45 (defvar texinfo-node-names)
46 (defvar texinfo-enclosure-list)
47 (defvar texinfo-alias-list)
48
49 (defvar texinfo-command-start)
50 (defvar texinfo-command-end)
51 (defvar texinfo-command-name)
52 (defvar texinfo-defun-type)
53 (defvar texinfo-last-node-pos)
54 (defvar texinfo-stack)
55 (defvar texinfo-short-index-cmds-alist)
56 (defvar texinfo-short-index-format-cmds-alist)
57 (defvar texinfo-format-filename)
58 (defvar texinfo-footnote-number)
59 (defvar texinfo-start-of-header)
60 (defvar texinfo-end-of-header)
61 (defvar texinfo-raisesections-alist)
62 (defvar texinfo-lowersections-alist)
63 \f
64 ;;; Syntax table
65
66 (if texinfo-format-syntax-table
67 nil
68 (setq texinfo-format-syntax-table (make-syntax-table))
69 (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
70 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
71 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
72 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
73 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
74 (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
75 (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
76 (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
77 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
78 (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
79 (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
80
81 \f
82 ;;; Top level buffer and region formatting functions
83
84 ;;;###autoload
85 (defun texinfo-format-buffer (&optional notagify)
86 "Process the current buffer as texinfo code, into an Info file.
87 The Info file output is generated in a buffer visiting the Info file
88 names specified in the @setfilename command.
89
90 Non-nil argument (prefix, if interactive) means don't make tag table
91 and don't split the file if large. You can use Info-tagify and
92 Info-split to do these manually."
93 (interactive "P")
94 (let ((lastmessage "Formatting Info file..."))
95 (message lastmessage)
96 (texinfo-format-buffer-1)
97 (if notagify
98 nil
99 (if (> (buffer-size) 30000)
100 (progn
101 (message (setq lastmessage "Making tags table for Info file..."))
102 (Info-tagify)))
103 (if (> (buffer-size) 100000)
104 (progn
105 (message (setq lastmessage "Splitting Info file..."))
106 (Info-split))))
107 (message (concat lastmessage
108 (if (interactive-p) "done. Now save it." "done.")))))
109
110 (defvar texinfo-region-buffer-name "*Info Region*"
111 "*Name of the temporary buffer used by \\[texinfo-format-region].")
112
113 ;;;###autoload
114 (defun texinfo-format-region (region-beginning region-end)
115 "Convert the current region of the Texinfo file to Info format.
116 This lets you see what that part of the file will look like in Info.
117 The command is bound to \\[texinfo-format-region]. The text that is
118 converted to Info is stored in a temporary buffer."
119 (interactive "r")
120 (message "Converting region to Info format...")
121 (let (texinfo-command-start
122 texinfo-command-end
123 texinfo-command-name
124 texinfo-vindex
125 texinfo-findex
126 texinfo-cindex
127 texinfo-pindex
128 texinfo-tindex
129 texinfo-kindex
130 texinfo-stack
131 (texinfo-format-filename "")
132 texinfo-example-start
133 texinfo-last-node-pos
134 texinfo-last-node
135 texinfo-node-names
136 (texinfo-footnote-number 0)
137 last-input-buffer
138 (fill-column-for-info fill-column)
139 (input-buffer (current-buffer))
140 (input-directory default-directory)
141 (header-text "")
142 (header-beginning 1)
143 (header-end 1))
144
145 ;;; Copy lines between beginning and end of header lines,
146 ;;; if any, or else copy the `@setfilename' line, if any.
147 (save-excursion
148 (save-restriction
149 (widen)
150 (goto-char (point-min))
151 (let ((search-end (save-excursion (forward-line 100) (point))))
152 (if (or
153 ;; Either copy header text.
154 (and
155 (prog1
156 (search-forward tex-start-of-header search-end t)
157 (forward-line 1)
158 ;; Mark beginning of header.
159 (setq header-beginning (point)))
160 (prog1
161 (search-forward tex-end-of-header nil t)
162 (beginning-of-line)
163 ;; Mark end of header
164 (setq header-end (point))))
165 ;; Or copy @filename line.
166 (prog2
167 (goto-char (point-min))
168 (search-forward "@setfilename" search-end t)
169 (beginning-of-line)
170 (setq header-beginning (point))
171 (forward-line 1)
172 (setq header-end (point))))
173
174 ;; Copy header
175 (setq header-text
176 (buffer-substring
177 (min header-beginning region-beginning)
178 header-end))))))
179
180 ;;; Find a buffer to use.
181 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
182 (erase-buffer)
183 ;; Insert the header into the buffer.
184 (insert header-text)
185 ;; Insert the region into the buffer.
186 (insert-buffer-substring
187 input-buffer
188 (max region-beginning header-end)
189 region-end)
190 ;; Make sure region ends in a newline.
191 (or (= (preceding-char) ?\n)
192 (insert "\n"))
193
194 (goto-char (point-min))
195 (texinfo-mode)
196 (message "Converting region to Info format...")
197 (setq fill-column fill-column-for-info)
198 ;; Install a syntax table useful for scanning command operands.
199 (set-syntax-table texinfo-format-syntax-table)
200
201 ;; Insert @include files so `texinfo-raise-lower-sections' can
202 ;; work on them without losing track of multiple
203 ;; @raise/@lowersections commands.
204 (while (re-search-forward "^@include" nil t)
205 (setq texinfo-command-end (point))
206 (let ((filename (concat input-directory
207 (texinfo-parse-line-arg))))
208 (re-search-backward "^@include")
209 (delete-region (point) (save-excursion (forward-line 1) (point)))
210 (message "Reading included file: %s" filename)
211 (save-excursion
212 (save-restriction
213 (narrow-to-region
214 (point)
215 (+ (point) (car (cdr (insert-file-contents filename)))))
216 (goto-char (point-min))
217 ;; Remove `@setfilename' line from included file, if any,
218 ;; so @setfilename command not duplicated.
219 (if (re-search-forward
220 "^@setfilename" (save-excursion (forward-line 100) (point)) t)
221 (progn
222 (beginning-of-line)
223 (delete-region
224 (point) (save-excursion (forward-line 1) (point)))))))))
225
226 ;; Raise or lower level of each section, if necessary.
227 (goto-char (point-min))
228 (texinfo-raise-lower-sections)
229 ;; Append @refill to appropriate paragraphs for filling.
230 (goto-char (point-min))
231 (texinfo-append-refill)
232 ;; If the region includes the effective end of the data,
233 ;; discard everything after that.
234 (goto-char (point-max))
235 (if (re-search-backward "^@bye" nil t)
236 (delete-region (point) (point-max)))
237 ;; Make sure buffer ends in a newline.
238 (or (= (preceding-char) ?\n)
239 (insert "\n"))
240 ;; Don't use a previous value of texinfo-enclosure-list.
241 (setq texinfo-enclosure-list nil)
242 (setq texinfo-alias-list nil)
243
244 (goto-char (point-min))
245 (if (looking-at "\\\\input[ \t]+texinfo")
246 (delete-region (point) (save-excursion (forward-line 1) (point))))
247
248 ;; Insert Info region title text.
249 (goto-char (point-min))
250 (if (search-forward
251 "@setfilename" (save-excursion (forward-line 100) (point)) t)
252 (progn
253 (setq texinfo-command-end (point))
254 (beginning-of-line)
255 (setq texinfo-command-start (point))
256 (let ((arg (texinfo-parse-arg-discard)))
257 (insert " "
258 texinfo-region-buffer-name
259 " buffer for: `")
260 (insert (file-name-nondirectory (expand-file-name arg)))
261 (insert "', -*-Text-*-\n")))
262 ;; Else no `@setfilename' line
263 (insert " "
264 texinfo-region-buffer-name
265 " buffer -*-Text-*-\n"))
266 (insert "produced by `texinfo-format-region'\n"
267 "from a region in: "
268 (if (buffer-file-name input-buffer)
269 (concat "`"
270 (file-name-sans-versions
271 (file-name-nondirectory
272 (buffer-file-name input-buffer)))
273 "'")
274 (concat "buffer `" (buffer-name input-buffer) "'"))
275 "\nusing `texinfmt.el' version "
276 texinfmt-version
277 ".\n\n")
278
279 ;; Now convert for real.
280 (goto-char (point-min))
281 (texinfo-format-scan)
282 (goto-char (point-min))
283
284 (message "Done.")))
285
286 \f
287 ;;; Primary internal formatting function for the whole buffer.
288
289 (defun texinfo-format-buffer-1 ()
290 (let (texinfo-format-filename
291 texinfo-example-start
292 texinfo-command-start
293 texinfo-command-end
294 texinfo-command-name
295 texinfo-last-node
296 texinfo-last-node-pos
297 texinfo-vindex
298 texinfo-findex
299 texinfo-cindex
300 texinfo-pindex
301 texinfo-tindex
302 texinfo-kindex
303 texinfo-stack
304 texinfo-node-names
305 (texinfo-footnote-number 0)
306 last-input-buffer
307 outfile
308 (fill-column-for-info fill-column)
309 (input-buffer (current-buffer))
310 (input-directory default-directory))
311 (setq texinfo-enclosure-list nil)
312 (setq texinfo-alias-list nil)
313 (save-excursion
314 (goto-char (point-min))
315 (or (search-forward "@setfilename" nil t)
316 (error "Texinfo file needs an `@setfilename FILENAME' line."))
317 (setq texinfo-command-end (point))
318 (setq outfile (texinfo-parse-line-arg)))
319 (find-file outfile)
320 (texinfo-mode)
321 (setq fill-column fill-column-for-info)
322 (set-syntax-table texinfo-format-syntax-table)
323 (erase-buffer)
324 (insert-buffer-substring input-buffer)
325 (message "Converting %s to Info format..." (buffer-name input-buffer))
326
327 ;; Insert @include files so `texinfo-raise-lower-sections' can
328 ;; work on them without losing track of multiple
329 ;; @raise/@lowersections commands.
330 (goto-char (point-min))
331 (while (re-search-forward "^@include" nil t)
332 (setq texinfo-command-end (point))
333 (let ((filename (concat input-directory
334 (texinfo-parse-line-arg))))
335 (re-search-backward "^@include")
336 (delete-region (point) (save-excursion (forward-line 1) (point)))
337 (message "Reading included file: %s" filename)
338 (save-excursion
339 (save-restriction
340 (narrow-to-region
341 (point)
342 (+ (point) (car (cdr (insert-file-contents filename)))))
343 (goto-char (point-min))
344 ;; Remove `@setfilename' line from included file, if any,
345 ;; so @setfilename command not duplicated.
346 (if (re-search-forward
347 "^@setfilename"
348 (save-excursion (forward-line 100) (point)) t)
349 (progn
350 (beginning-of-line)
351 (delete-region
352 (point) (save-excursion (forward-line 1) (point)))))))))
353 ;; Raise or lower level of each section, if necessary.
354 (goto-char (point-min))
355 (texinfo-raise-lower-sections)
356 ;; Append @refill to appropriate paragraphs
357 (goto-char (point-min))
358 (texinfo-append-refill)
359 (goto-char (point-min))
360 (search-forward "@setfilename")
361 (beginning-of-line)
362 (delete-region (point-min) (point))
363 ;; Remove @bye at end of file, if it is there.
364 (goto-char (point-max))
365 (if (search-backward "@bye" nil t)
366 (delete-region (point) (point-max)))
367 ;; Make sure buffer ends in a newline.
368 (or (= (preceding-char) ?\n)
369 (insert "\n"))
370 ;; Scan the whole buffer, converting to Info format.
371 (texinfo-format-scan)
372 ;; Return data for indices.
373 (goto-char (point-min))
374 (list outfile
375 texinfo-vindex texinfo-findex texinfo-cindex
376 texinfo-pindex texinfo-tindex texinfo-kindex)))
377
378 \f
379 ;;; Perform non-@-command file conversions: quotes and hyphens
380
381 (defun texinfo-format-convert (min max)
382 ;; Convert left and right quotes to typewriter font quotes.
383 (goto-char min)
384 (while (search-forward "``" max t)
385 (replace-match "\""))
386 (goto-char min)
387 (while (search-forward "''" max t)
388 (replace-match "\""))
389 ;; Convert three hyphens in a row to two.
390 (goto-char min)
391 (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
392 (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning
393 2)))))
394
395 \f
396 ;;; Handle paragraph filling
397
398 (defvar texinfo-no-refill-regexp
399 "^@\\(example\\|smallexample\\|lisp\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|menu\\|titlepage\\|iftex\\|ifhtml\\|tex\\|html\\)"
400 "Regexp specifying environments in which paragraphs are not filled.")
401
402 (defvar texinfo-part-of-para-regexp
403 "^@\\(b{\\|bullet{\\|cite{\\|code{\\|emph{\\|equiv{\\|error{\\|expansion{\\|file{\\|i{\\|inforef{\\|kbd{\\|key{\\|lisp{\\|minus{\\|point{\\|print{\\|pxref{\\|r{\\|ref{\\|result{\\|samp{\\|sc{\\|t{\\|TeX{\\|today{\\|var{\\|w{\\|xref{\\)"
404 "Regexp specifying @-commands found within paragraphs.")
405
406 (defun texinfo-append-refill ()
407 "Append @refill at end of each paragraph that should be filled.
408 Do not append @refill to paragraphs within @example and similar environments.
409 Do not append @refill to paragraphs containing @w{TEXT} or @*."
410
411 ;; It is necessary to append @refill before other processing because
412 ;; the other processing removes information that tells Texinfo
413 ;; whether the text should or should not be filled.
414
415 (while (< (point) (point-max))
416 (let ((refill-blank-lines "^[ \t\n]*$")
417 (case-fold-search nil)) ; Don't confuse @TeX and @tex....
418 (beginning-of-line)
419 ;; 1. Skip over blank lines;
420 ;; skip over lines beginning with @-commands,
421 ;; but do not skip over lines
422 ;; that are no-refill environments such as @example or
423 ;; that begin with within-paragraph @-commands such as @code.
424 (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
425 (not (looking-at
426 (concat
427 "\\("
428 texinfo-no-refill-regexp
429 "\\|"
430 texinfo-part-of-para-regexp
431 "\\)")))
432 (< (point) (point-max)))
433 (forward-line 1))
434 ;; 2. Skip over @example and similar no-refill environments.
435 (if (looking-at texinfo-no-refill-regexp)
436 (let ((environment
437 (buffer-substring (match-beginning 1) (match-end 1))))
438 (progn (re-search-forward (concat "^@end " environment) nil t)
439 (forward-line 1)))
440 ;; 3. Do not refill a paragraph containing @w or @*
441 (if (or
442 (>= (point) (point-max))
443 (re-search-forward
444 "@w{\\|@\\*" (save-excursion (forward-paragraph) (point)) t))
445 ;; Go to end of paragraph and do nothing.
446 (forward-paragraph)
447 ;; 4. Else go to end of paragraph and insert @refill
448 (forward-paragraph)
449 (forward-line -1)
450 (end-of-line)
451 (delete-region
452 (point)
453 (save-excursion (skip-chars-backward " \t") (point)))
454 ;; `looking-at-backward' not available in v. 18.57
455 ;; (if (not (looking-at-backward "@refill\\|@bye")) ;)
456 (if (not (re-search-backward
457 "@refill\\|@bye"
458 (save-excursion (beginning-of-line) (point))
459 t))
460 (insert "@refill"))
461 (forward-line 1))))))
462
463 \f
464 ;;; Handle `@raisesections' and `@lowersections' commands
465
466 ;; These commands change the hierarchical level of chapter structuring
467 ;; commands.
468 ;;
469 ;; @raisesections changes @subsection to @section,
470 ;; @section to @chapter,
471 ;; etc.
472 ;;
473 ;; @lowersections changes @chapter to @section
474 ;; @subsection to @subsubsection,
475 ;; etc.
476 ;;
477 ;; An @raisesections/@lowersections command changes only those
478 ;; structuring commands that follow the @raisesections/@lowersections
479 ;; command.
480 ;;
481 ;; Repeated @raisesections/@lowersections continue to raise or lower
482 ;; the heading level.
483 ;;
484 ;; An @lowersections command cancels an @raisesections command, and
485 ;; vice versa.
486 ;;
487 ;; You cannot raise or lower "beyond" chapters or subsubsections, but
488 ;; trying to do so does not elicit an error---you just get more
489 ;; headings that mean the same thing as you keep raising or lowering
490 ;; (for example, after a single @raisesections, both @chapter and
491 ;; @section produce chapter headings).
492
493 (defun texinfo-raise-lower-sections ()
494 "Raise or lower the hierarchical level of chapters, sections, etc.
495
496 This function acts according to `@raisesections' and `@lowersections'
497 commands in the Texinfo file.
498
499 For example, an `@lowersections' command is useful if you wish to
500 include what is written as an outer or standalone Texinfo file in
501 another Texinfo file as an inner, included file. The `@lowersections'
502 command changes chapters to sections, sections to subsections and so
503 on.
504
505 @raisesections changes @subsection to @section,
506 @section to @chapter,
507 @heading to @chapheading,
508 etc.
509
510 @lowersections changes @chapter to @section,
511 @subsection to @subsubsection,
512 @heading to @subheading,
513 etc.
514
515 An `@raisesections' or `@lowersections' command changes only those
516 structuring commands that follow the `@raisesections' or
517 `@lowersections' command.
518
519 An `@lowersections' command cancels an `@raisesections' command, and
520 vice versa.
521
522 Repeated use of the commands continue to raise or lower the hierarchical
523 level a step at a time.
524
525 An attempt to raise above `chapters' reproduces chapter commands; an
526 attempt to lower below subsubsections reproduces subsubsection
527 commands."
528
529 ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
530 ;; it is a regexp matching chapter, section, other headings
531 ;; (but not the top node).
532
533 (let (type (level 0))
534 (while
535 (re-search-forward
536 (concat
537 "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
538 texinfo-section-types-regexp
539 "\\)\\)")
540 nil t)
541 (beginning-of-line)
542 (save-excursion (setq type (read (current-buffer))))
543 (cond
544
545 ;; 1. Increment level
546 ((eq type '@raisesections)
547 (setq level (1+ level))
548 (delete-region
549 (point) (save-excursion (forward-line 1) (point))))
550
551 ;; 2. Decrement level
552 ((eq type '@lowersections)
553 (setq level (1- level))
554 (delete-region
555 (point) (save-excursion (forward-line 1) (point))))
556
557 ;; Now handle structuring commands
558 ((cond
559
560 ;; 3. Raise level when positive
561 ((> level 0)
562 (let ((count level)
563 (new-level type))
564 (while (> count 0)
565 (setq new-level
566 (cdr (assq new-level texinfo-raisesections-alist)))
567 (setq count (1- count)))
568 (kill-word 1)
569 (insert (symbol-name new-level))))
570
571 ;; 4. Do nothing except move point when level is zero
572 ((= level 0) (forward-line 1))
573
574 ;; 5. Lower level when positive
575 ((< level 0)
576 (let ((count level)
577 (new-level type))
578 (while (< count 0)
579 (setq new-level
580 (cdr (assq new-level texinfo-lowersections-alist)))
581 (setq count (1+ count)))
582 (kill-word 1)
583 (insert (symbol-name new-level))))))))))
584
585 (defvar texinfo-raisesections-alist
586 '((@chapter . @chapter) ; Cannot go higher
587 (@unnumbered . @unnumbered)
588
589 (@majorheading . @majorheading)
590 (@chapheading . @chapheading)
591 (@appendix . @appendix)
592
593 (@section . @chapter)
594 (@unnumberedsec . @unnumbered)
595 (@heading . @chapheading)
596 (@appendixsec . @appendix)
597
598 (@subsection . @section)
599 (@unnumberedsubsec . @unnumberedsec)
600 (@subheading . @heading)
601 (@appendixsubsec . @appendixsec)
602
603 (@subsubsection . @subsection)
604 (@unnumberedsubsubsec . @unnumberedsubsec)
605 (@subsubheading . @subheading)
606 (@appendixsubsubsec . @appendixsubsec))
607 "*An alist of next higher levels for chapters, sections. etc.
608 For example, section to chapter, subsection to section.
609 Used by `texinfo-raise-lower-sections'.
610 The keys specify types of section; the values correspond to the next
611 higher types.")
612
613 (defvar texinfo-lowersections-alist
614 '((@chapter . @section)
615 (@unnumbered . @unnumberedsec)
616 (@majorheading . @heading)
617 (@chapheading . @heading)
618 (@appendix . @appendixsec)
619
620 (@section . @subsection)
621 (@unnumberedsec . @unnumberedsubsec)
622 (@heading . @subheading)
623 (@appendixsec . @appendixsubsec)
624
625 (@subsection . @subsubsection)
626 (@unnumberedsubsec . @unnumberedsubsubsec)
627 (@subheading . @subsubheading)
628 (@appendixsubsec . @appendixsubsubsec)
629
630 (@subsubsection . @subsubsection) ; Cannot go lower.
631 (@unnumberedsubsubsec . @unnumberedsubsubsec)
632 (@subsubheading . @subsubheading)
633 (@appendixsubsubsec . @appendixsubsubsec))
634 "*An alist of next lower levels for chapters, sections. etc.
635 For example, chapter to section, section to subsection.
636 Used by `texinfo-raise-lower-sections'.
637 The keys specify types of section; the values correspond to the next
638 lower types.")
639
640 \f
641 ;;; Perform those texinfo-to-info conversions that apply to the whole input
642 ;;; uniformly.
643
644 (defun texinfo-format-scan ()
645 (texinfo-format-convert (point-min) (point-max))
646 ;; Scan for @-commands.
647 (goto-char (point-min))
648 (while (search-forward "@" nil t)
649 (if (looking-at "[@{}^'` *\"?!]")
650 ;; Handle a few special @-followed-by-one-char commands.
651 (if (= (following-char) ?*)
652 (progn
653 ;; remove command
654 (delete-region (1- (point)) (1+ (point)))
655 ;; insert return if not at end of line;
656 ;; else line is already broken.
657 (if (not (= (following-char) ?\n))
658 (insert ?\n)))
659 ;; The other characters are simply quoted. Delete the @.
660 (delete-char -1)
661 (forward-char 1))
662 ;; @ is followed by a command-word; find the end of the word.
663 (setq texinfo-command-start (1- (point)))
664 (if (= (char-syntax (following-char)) ?w)
665 (forward-word 1)
666 (forward-char 1))
667 (setq texinfo-command-end (point))
668 ;; Handle let aliasing
669 (setq texinfo-command-name
670 (let (trial
671 (cmdname
672 (buffer-substring
673 (1+ texinfo-command-start) texinfo-command-end)))
674 (while (setq trial (assoc cmdname texinfo-alias-list))
675 (setq cmdname (cdr trial)))
676 (intern cmdname)))
677 ;; Call the handler for this command.
678 (let ((enclosure-type
679 (assoc
680 (symbol-name texinfo-command-name)
681 texinfo-enclosure-list)))
682 (if enclosure-type
683 (progn
684 (insert
685 (car (car (cdr enclosure-type)))
686 (texinfo-parse-arg-discard)
687 (car (cdr (car (cdr enclosure-type)))))
688 (goto-char texinfo-command-start))
689 (let ((cmd (get texinfo-command-name 'texinfo-format)))
690 (if cmd (funcall cmd) (texinfo-unsupported)))))))
691
692 (cond (texinfo-stack
693 (goto-char (nth 2 (car texinfo-stack)))
694 (error "Unterminated @%s" (car (car texinfo-stack))))))
695
696 (put 'begin 'texinfo-format 'texinfo-format-begin)
697 (defun texinfo-format-begin ()
698 (texinfo-format-begin-end 'texinfo-format))
699
700 (put 'end 'texinfo-format 'texinfo-format-end)
701 (defun texinfo-format-end ()
702 (texinfo-format-begin-end 'texinfo-end))
703
704 (defun texinfo-format-begin-end (prop)
705 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
706 (let ((cmd (get texinfo-command-name prop)))
707 (if cmd (funcall cmd)
708 (texinfo-unsupported))))
709 \f
710 ;;; Parsing functions
711
712 (defun texinfo-parse-line-arg ()
713 (goto-char texinfo-command-end)
714 (let ((start (point)))
715 (cond ((looking-at " ")
716 (skip-chars-forward " ")
717 (setq start (point))
718 (end-of-line)
719 (skip-chars-backward " ")
720 (delete-region (point) (progn (end-of-line) (point)))
721 (setq texinfo-command-end (1+ (point))))
722 ((looking-at "{")
723 (setq start (1+ (point)))
724 (forward-list 1)
725 (setq texinfo-command-end (point))
726 (forward-char -1))
727 (t
728 (error "Invalid texinfo command arg format")))
729 (prog1 (buffer-substring start (point))
730 (if (eolp) (forward-char 1)))))
731
732 (defun texinfo-parse-expanded-arg ()
733 (goto-char texinfo-command-end)
734 (let ((start (point))
735 marker)
736 (cond ((looking-at " ")
737 (skip-chars-forward " ")
738 (setq start (point))
739 (end-of-line)
740 (setq texinfo-command-end (1+ (point))))
741 ((looking-at "{")
742 (setq start (1+ (point)))
743 (forward-list 1)
744 (setq texinfo-command-end (point))
745 (forward-char -1))
746 (t
747 (error "Invalid texinfo command arg format")))
748 (setq marker (move-marker (make-marker) texinfo-command-end))
749 (texinfo-format-expand-region start (point))
750 (setq texinfo-command-end (marker-position marker))
751 (move-marker marker nil)
752 (prog1 (buffer-substring start (point))
753 (if (eolp) (forward-char 1)))))
754
755 (defun texinfo-format-expand-region (start end)
756 (save-restriction
757 (narrow-to-region start end)
758 (let (texinfo-command-start
759 texinfo-command-end
760 texinfo-command-name
761 texinfo-stack)
762 (texinfo-format-scan))
763 (goto-char (point-max))))
764
765 (defun texinfo-parse-arg-discard ()
766 (prog1 (texinfo-parse-line-arg)
767 (texinfo-discard-command)))
768
769 (defun texinfo-discard-command ()
770 (delete-region texinfo-command-start texinfo-command-end))
771
772 (defun texinfo-optional-braces-discard ()
773 "Discard braces following command, if any."
774 (goto-char texinfo-command-end)
775 (let ((start (point)))
776 (cond ((looking-at "[ \t]*\n")) ; do nothing
777 ((looking-at "{") ; remove braces, if any
778 (forward-list 1)
779 (setq texinfo-command-end (point)))
780 (t
781 (error
782 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
783 (delete-region texinfo-command-start texinfo-command-end)))
784
785 (defun texinfo-format-parse-line-args ()
786 (let ((start (1- (point)))
787 next beg end
788 args)
789 (skip-chars-forward " ")
790 (while (not (eolp))
791 (setq beg (point))
792 (re-search-forward "[\n,]")
793 (setq next (point))
794 (if (bolp) (setq next (1- next)))
795 (forward-char -1)
796 (skip-chars-backward " ")
797 (setq end (point))
798 (setq args (cons (if (> end beg) (buffer-substring beg end))
799 args))
800 (goto-char next)
801 (skip-chars-forward " "))
802 (if (eolp) (forward-char 1))
803 (setq texinfo-command-end (point))
804 (nreverse args)))
805
806 (defun texinfo-format-parse-args ()
807 (let ((start (1- (point)))
808 next beg end
809 args)
810 (search-forward "{")
811 (save-excursion
812 (texinfo-format-expand-region
813 (point)
814 (save-excursion (up-list 1) (1- (point)))))
815 ;; The following does not handle cross references of the form:
816 ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
817 ;; re-search-forward finds the first right brace after the second
818 ;; comma.
819 (while (/= (preceding-char) ?\})
820 (skip-chars-forward " \t\n")
821 (setq beg (point))
822 (re-search-forward "[},]")
823 (setq next (point))
824 (forward-char -1)
825 (skip-chars-backward " \t\n")
826 (setq end (point))
827 (cond ((< beg end)
828 (goto-char beg)
829 (while (search-forward "\n" end t)
830 (replace-match " "))))
831 (setq args (cons (if (> end beg) (buffer-substring beg end))
832 args))
833 (goto-char next))
834 (if (eolp) (forward-char 1))
835 (setq texinfo-command-end (point))
836 (nreverse args)))
837
838 (defun texinfo-format-parse-defun-args ()
839 (goto-char texinfo-command-end)
840 (let ((start (point)))
841 (end-of-line)
842 (setq texinfo-command-end (1+ (point)))
843 (let ((marker (move-marker (make-marker) texinfo-command-end)))
844 (texinfo-format-expand-region start (point))
845 (setq texinfo-command-end (marker-position marker))
846 (move-marker marker nil))
847 (goto-char start)
848 (let ((args '())
849 beg end)
850 (skip-chars-forward " ")
851 (while (not (eolp))
852 (cond ((looking-at "{")
853 (setq beg (1+ (point)))
854 (forward-list 1)
855 (setq end (1- (point))))
856 (t
857 (setq beg (point))
858 (re-search-forward "[\n ]")
859 (forward-char -1)
860 (setq end (point))))
861 (setq args (cons (buffer-substring beg end) args))
862 (skip-chars-forward " "))
863 (forward-char 1)
864 (nreverse args))))
865
866 (defun texinfo-discard-line ()
867 (goto-char texinfo-command-end)
868 (skip-chars-forward " \t")
869 (or (eolp)
870 (error "Extraneous text at end of command line."))
871 (goto-char texinfo-command-start)
872 (or (bolp)
873 (error "Extraneous text at beginning of command line."))
874 (delete-region (point) (progn (forward-line 1) (point))))
875
876 (defun texinfo-discard-line-with-args ()
877 (goto-char texinfo-command-start)
878 (delete-region (point) (progn (forward-line 1) (point))))
879
880 \f
881 ;;; @setfilename
882
883 ;; Only `texinfo-format-buffer' handles @setfilename with this
884 ;; definition; `texinfo-format-region' handles @setfilename, if any,
885 ;; specially.
886 (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
887 (defun texinfo-format-setfilename ()
888 (let ((arg (texinfo-parse-arg-discard)))
889 (message "Formatting Info file: %s" arg)
890 (setq texinfo-format-filename
891 (file-name-nondirectory (expand-file-name arg)))
892 (insert "Info file: "
893 texinfo-format-filename ", -*-Text-*-\n"
894 "produced by `texinfo-format-buffer'\n"
895 "from file"
896 (if (buffer-file-name input-buffer)
897 (concat " `"
898 (file-name-sans-versions
899 (file-name-nondirectory
900 (buffer-file-name input-buffer)))
901 "'")
902 (concat "buffer `" (buffer-name input-buffer) "'"))
903 "\nusing `texinfmt.el' version "
904 texinfmt-version
905 ".\n\n")))
906 \f
907 ;;; @node, @menu
908
909 (put 'node 'texinfo-format 'texinfo-format-node)
910 (put 'nwnode 'texinfo-format 'texinfo-format-node)
911 (defun texinfo-format-node ()
912 (let* ((args (texinfo-format-parse-line-args))
913 (name (nth 0 args))
914 (next (nth 1 args))
915 (prev (nth 2 args))
916 (up (nth 3 args)))
917 (texinfo-discard-command)
918 (setq texinfo-last-node name)
919 (let ((tem (downcase name)))
920 (if (assoc tem texinfo-node-names)
921 (error "Duplicate node name: %s" name)
922 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
923 (setq texinfo-footnote-number 0)
924 ;; insert "\n\^_" unconditionally since this is what info is looking for
925 (insert "\n\^_\nFile: " texinfo-format-filename
926 ", Node: " name)
927 (if next
928 (insert ", Next: " next))
929 (if prev
930 (insert ", Prev: " prev))
931 (if up
932 (insert ", Up: " up))
933 (insert ?\n)
934 (setq texinfo-last-node-pos (point))))
935
936 (put 'menu 'texinfo-format 'texinfo-format-menu)
937 (defun texinfo-format-menu ()
938 (texinfo-discard-line)
939 (insert "* Menu:\n\n"))
940
941 (put 'menu 'texinfo-end 'texinfo-discard-command)
942
943 \f
944 ;;; Cross references
945
946 ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
947 ; -> *Note FNAME: (FILE)NODE
948 ; If FILE is missing,
949 ; *Note FNAME: NODE
950 ; If FNAME is empty and NAME is present
951 ; *Note NAME: Node
952 ; If both NAME and FNAME are missing
953 ; *Note NODE::
954 ; texinfo ignores the DOCUMENT argument.
955 ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
956 ; If FILE is specified, (FILE)NODE is used for xrefs.
957 ; If fifth argument DOCUMENT is specified, produces
958 ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
959 ; of DOCUMENT
960
961 ; @ref a reference that does not put `See' or `see' in
962 ; the hardcopy and is the same as @xref in Info
963 (put 'ref 'texinfo-format 'texinfo-format-xref)
964
965 (put 'xref 'texinfo-format 'texinfo-format-xref)
966 (defun texinfo-format-xref ()
967 (let ((args (texinfo-format-parse-args)))
968 (texinfo-discard-command)
969 (insert "*Note ")
970 (let ((fname (or (nth 1 args) (nth 2 args))))
971 (if (null (or fname (nth 3 args)))
972 (insert (car args) "::")
973 (insert (or fname (car args)) ": ")
974 (if (nth 3 args)
975 (insert "(" (nth 3 args) ")"))
976 (insert (car args))))))
977
978 (put 'pxref 'texinfo-format 'texinfo-format-pxref)
979 (defun texinfo-format-pxref ()
980 (texinfo-format-xref)
981 (or (save-excursion
982 (forward-char -2)
983 (looking-at "::"))
984 (insert ".")))
985
986 ;@inforef{NODE, FNAME, FILE}
987 ;Like @xref{NODE, FNAME,,FILE} in texinfo.
988 ;In Tex, generates "See Info file FILE, node NODE"
989 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
990 (defun texinfo-format-inforef ()
991 (let ((args (texinfo-format-parse-args)))
992 (texinfo-discard-command)
993 (if (nth 1 args)
994 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
995 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
996
997 \f
998 ;;; Section headings
999
1000 (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
1001 (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
1002 (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
1003 (put 'chapter 'texinfo-format 'texinfo-format-chapter)
1004 (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
1005 (put 'appendix 'texinfo-format 'texinfo-format-chapter)
1006 (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
1007 (put 'top 'texinfo-format 'texinfo-format-chapter)
1008 (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
1009 (defun texinfo-format-chapter ()
1010 (texinfo-format-chapter-1 ?*))
1011
1012 (put 'heading 'texinfo-format 'texinfo-format-section)
1013 (put 'isection 'texinfo-format 'texinfo-format-section)
1014 (put 'section 'texinfo-format 'texinfo-format-section)
1015 (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
1016 (put 'appendixsection 'texinfo-format 'texinfo-format-section)
1017 (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
1018 (put 'appendixsec 'texinfo-format 'texinfo-format-section)
1019 (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
1020 (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
1021 (defun texinfo-format-section ()
1022 (texinfo-format-chapter-1 ?=))
1023
1024 (put 'subheading 'texinfo-format 'texinfo-format-subsection)
1025 (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
1026 (put 'subsection 'texinfo-format 'texinfo-format-subsection)
1027 (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
1028 (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
1029 (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1030 (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
1031 (defun texinfo-format-subsection ()
1032 (texinfo-format-chapter-1 ?-))
1033
1034 (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
1035 (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
1036 (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
1037 (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1038 (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1039 (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1040 (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
1041 (defun texinfo-format-subsubsection ()
1042 (texinfo-format-chapter-1 ?.))
1043
1044 (defun texinfo-format-chapter-1 (belowchar)
1045 (let ((arg (texinfo-parse-arg-discard)))
1046 (message "Formatting: %s ... " arg) ; So we can see where we are.
1047 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
1048 (forward-line -2)))
1049
1050 (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
1051 (defun texinfo-format-sectionpad ()
1052 (let ((str (texinfo-parse-arg-discard)))
1053 (forward-char -1)
1054 (let ((column (current-column)))
1055 (forward-char 1)
1056 (while (> column 0)
1057 (insert str)
1058 (setq column (1- column))))
1059 (insert ?\n)))
1060
1061 \f
1062 ;;; Space controlling commands: @. and @:, and the soft hyphen.
1063
1064 (put '\. 'texinfo-format 'texinfo-format-\.)
1065 (defun texinfo-format-\. ()
1066 (texinfo-discard-command)
1067 (insert "."))
1068
1069 (put '\: 'texinfo-format 'texinfo-format-\:)
1070 (defun texinfo-format-\: ()
1071 (texinfo-discard-command))
1072
1073 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
1074 (defun texinfo-format-soft-hyphen ()
1075 (texinfo-discard-command))
1076
1077 \f
1078 ;;; @center, @sp, and @br
1079
1080 (put 'center 'texinfo-format 'texinfo-format-center)
1081 (defun texinfo-format-center ()
1082 (let ((arg (texinfo-parse-expanded-arg)))
1083 (texinfo-discard-command)
1084 (insert arg)
1085 (insert ?\n)
1086 (save-restriction
1087 (goto-char (1- (point)))
1088 (let ((indent-tabs-mode nil))
1089 (center-line)))))
1090
1091 (put 'sp 'texinfo-format 'texinfo-format-sp)
1092 (defun texinfo-format-sp ()
1093 (let* ((arg (texinfo-parse-arg-discard))
1094 (num (read arg)))
1095 (insert-char ?\n num)))
1096
1097 (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
1098 (defun texinfo-format-paragraph-break ()
1099 "Force a paragraph break.
1100 If used within a line, follow `@br' with braces."
1101 (texinfo-optional-braces-discard)
1102 ;; insert one return if at end of line;
1103 ;; else insert two returns, to generate a blank line.
1104 (if (= (following-char) ?\n)
1105 (insert ?\n)
1106 (insert-char ?\n 2)))
1107
1108 \f
1109 ;;; @footnote and @footnotestyle
1110
1111 ; In Texinfo, footnotes are created with the `@footnote' command.
1112 ; This command is followed immediately by a left brace, then by the text of
1113 ; the footnote, and then by a terminating right brace. The
1114 ; template for a footnote is:
1115 ;
1116 ; @footnote{TEXT}
1117 ;
1118 ; Info has two footnote styles:
1119 ;
1120 ; * In the End of node style, all the footnotes for a single node
1121 ; are placed at the end of that node. The footnotes are
1122 ; separated from the rest of the node by a line of dashes with
1123 ; the word `Footnotes' within it.
1124 ;
1125 ; * In the Separate node style, all the footnotes for a single node
1126 ; are placed in an automatically constructed node of their own.
1127
1128 ; Footnote style is specified by the @footnotestyle command, either
1129 ; @footnotestyle separate
1130 ; or
1131 ; @footnotestyle end
1132 ;
1133 ; The default is separate
1134
1135 (defvar texinfo-footnote-style "separate"
1136 "Footnote style, either separate or end.")
1137
1138 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
1139 (defun texinfo-footnotestyle ()
1140 "Specify whether footnotes are at end of node or in separate nodes.
1141 Argument is either end or separate."
1142 (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
1143
1144 (defvar texinfo-footnote-number)
1145
1146 (put 'footnote 'texinfo-format 'texinfo-format-footnote)
1147 (defun texinfo-format-footnote ()
1148 "Format a footnote in either end of node or separate node style.
1149 The texinfo-footnote-style variable controls which style is used."
1150 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
1151 (cond ((string= texinfo-footnote-style "end")
1152 (texinfo-format-end-node))
1153 ((string= texinfo-footnote-style "separate")
1154 (texinfo-format-separate-node))))
1155
1156 (defun texinfo-format-separate-node ()
1157 "Format footnote in Separate node style, with notes in own node.
1158 The node is constructed automatically."
1159 (let* (start
1160 (arg (texinfo-parse-line-arg))
1161 (node-name-beginning
1162 (save-excursion
1163 (re-search-backward
1164 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1165 (match-end 0)))
1166 (node-name
1167 (save-excursion
1168 (buffer-substring
1169 (progn (goto-char node-name-beginning) ; skip over node command
1170 (skip-chars-forward " \t") ; and over spaces
1171 (point))
1172 (if (search-forward
1173 ","
1174 (save-excursion (end-of-line) (point)) t) ; bound search
1175 (1- (point))
1176 (end-of-line) (point))))))
1177 (texinfo-discard-command) ; remove or insert whitespace, as needed
1178 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1179 (point))
1180 (insert (format " (%d) (*Note %s-Footnotes::)"
1181 texinfo-footnote-number node-name))
1182 (fill-paragraph nil)
1183 (save-excursion
1184 (if (re-search-forward "^@node" nil 'move)
1185 (forward-line -1))
1186
1187 ;; two cases: for the first footnote, we must insert a node header;
1188 ;; for the second and subsequent footnotes, we need only insert
1189 ;; the text of the footnote.
1190
1191 (if (save-excursion
1192 (re-search-backward
1193 (concat node-name "-Footnotes, Up: ")
1194 node-name-beginning
1195 t))
1196 (progn ; already at least one footnote
1197 (setq start (point))
1198 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1199 (fill-region start (point)))
1200 ;; else not yet a footnote
1201 (insert "\n\^_\nFile: " texinfo-format-filename
1202 " Node: " node-name "-Footnotes, Up: " node-name "\n")
1203 (setq start (point))
1204 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1205 (fill-region start (point))))))
1206
1207 (defun texinfo-format-end-node ()
1208 "Format footnote in the End of node style, with notes at end of node."
1209 (let (start
1210 (arg (texinfo-parse-line-arg)))
1211 (texinfo-discard-command) ; remove or insert whitespace, as needed
1212 (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
1213 (point))
1214 (insert (format " (%d) " texinfo-footnote-number))
1215 (fill-paragraph nil)
1216 (save-excursion
1217 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
1218 (progn ; already have footnote, put new one before end of node
1219 (if (re-search-forward "^@node" nil 'move)
1220 (forward-line -1))
1221 (setq start (point))
1222 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
1223 (fill-region start (point)))
1224 ;; else no prior footnote
1225 (if (re-search-forward "^@node" nil 'move)
1226 (forward-line -1))
1227 (insert "\n--------- Footnotes ---------\n")
1228 (setq start (point))
1229 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
1230
1231 \f
1232 ;;; @itemize, @enumerate, and similar commands
1233
1234 ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
1235 ;; @enumerate pushes (enumerate 0 STARTPOS).
1236 ;; @item dispatches to the texinfo-item prop of the first elt of the list.
1237 ;; For itemize, this puts in and rescans the COMMANDS.
1238 ;; For enumerate, this increments the number and puts it in.
1239 ;; In either case, it puts a Backspace at the front of the line
1240 ;; which marks it not to be indented later.
1241 ;; All other lines get indented by 5 when the @end is reached.
1242
1243 (defvar texinfo-stack-depth 0
1244 "Count of number of unpopped texinfo-push-stack calls.
1245 Used by @refill indenting command to avoid indenting within lists, etc.")
1246
1247 (defun texinfo-push-stack (check arg)
1248 (setq texinfo-stack-depth (1+ texinfo-stack-depth))
1249 (setq texinfo-stack
1250 (cons (list check arg texinfo-command-start)
1251 texinfo-stack)))
1252
1253 (defun texinfo-pop-stack (check)
1254 (setq texinfo-stack-depth (1- texinfo-stack-depth))
1255 (if (null texinfo-stack)
1256 (error "Unmatched @end %s" check))
1257 (if (not (eq (car (car texinfo-stack)) check))
1258 (error "@end %s matches @%s"
1259 check (car (car texinfo-stack))))
1260 (prog1 (cdr (car texinfo-stack))
1261 (setq texinfo-stack (cdr texinfo-stack))))
1262
1263 (put 'itemize 'texinfo-format 'texinfo-itemize)
1264 (defun texinfo-itemize ()
1265 (texinfo-push-stack
1266 'itemize
1267 (progn (skip-chars-forward " \t")
1268 (if (eolp)
1269 "@bullet"
1270 (texinfo-parse-line-arg))))
1271 (texinfo-discard-line-with-args)
1272 (setq fill-column (- fill-column 5)))
1273
1274 (put 'itemize 'texinfo-end 'texinfo-end-itemize)
1275 (defun texinfo-end-itemize ()
1276 (setq fill-column (+ fill-column 5))
1277 (texinfo-discard-command)
1278 (let ((stacktop
1279 (texinfo-pop-stack 'itemize)))
1280 (texinfo-do-itemize (nth 1 stacktop))))
1281
1282 (put 'enumerate 'texinfo-format 'texinfo-enumerate)
1283 (defun texinfo-enumerate ()
1284 (texinfo-push-stack
1285 'enumerate
1286 (progn (skip-chars-forward " \t")
1287 (if (eolp)
1288 1
1289 (read (current-buffer)))))
1290 (if (and (symbolp (car (cdr (car texinfo-stack))))
1291 (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
1292 (error
1293 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
1294 (texinfo-discard-line-with-args)
1295 (setq fill-column (- fill-column 5)))
1296
1297 (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
1298 (defun texinfo-end-enumerate ()
1299 (setq fill-column (+ fill-column 5))
1300 (texinfo-discard-command)
1301 (let ((stacktop
1302 (texinfo-pop-stack 'enumerate)))
1303 (texinfo-do-itemize (nth 1 stacktop))))
1304
1305 ;; @alphaenumerate never became a standard part of Texinfo
1306 (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
1307 (defun texinfo-alphaenumerate ()
1308 (texinfo-push-stack 'alphaenumerate (1- ?a))
1309 (setq fill-column (- fill-column 5))
1310 (texinfo-discard-line))
1311
1312 (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
1313 (defun texinfo-end-alphaenumerate ()
1314 (setq fill-column (+ fill-column 5))
1315 (texinfo-discard-command)
1316 (let ((stacktop
1317 (texinfo-pop-stack 'alphaenumerate)))
1318 (texinfo-do-itemize (nth 1 stacktop))))
1319
1320 ;; @capsenumerate never became a standard part of Texinfo
1321 (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
1322 (defun texinfo-capsenumerate ()
1323 (texinfo-push-stack 'capsenumerate (1- ?A))
1324 (setq fill-column (- fill-column 5))
1325 (texinfo-discard-line))
1326
1327 (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
1328 (defun texinfo-end-capsenumerate ()
1329 (setq fill-column (+ fill-column 5))
1330 (texinfo-discard-command)
1331 (let ((stacktop
1332 (texinfo-pop-stack 'capsenumerate)))
1333 (texinfo-do-itemize (nth 1 stacktop))))
1334
1335 ;; At the @end, indent all the lines within the construct
1336 ;; except those marked with backspace. FROM says where
1337 ;; construct started.
1338 (defun texinfo-do-itemize (from)
1339 (save-excursion
1340 (while (progn (forward-line -1)
1341 (>= (point) from))
1342 (if (= (following-char) ?\b)
1343 (save-excursion
1344 (delete-char 1)
1345 (end-of-line)
1346 (delete-char 6))
1347 (if (not (looking-at "[ \t]*$"))
1348 (save-excursion (insert " ")))))))
1349
1350 (put 'item 'texinfo-format 'texinfo-item)
1351 (put 'itemx 'texinfo-format 'texinfo-item)
1352 (defun texinfo-item ()
1353 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
1354
1355 (put 'itemize 'texinfo-item 'texinfo-itemize-item)
1356 (defun texinfo-itemize-item ()
1357 ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
1358 (delete-region (1+ (point)) (save-excursion (beginning-of-line) (point)))
1359 (if (looking-at "[ \t]*[^ \t\n]+")
1360 ;; Text on same line as @item command.
1361 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
1362 ;; Else text on next line.
1363 (insert "\b " (nth 1 (car texinfo-stack)) " "))
1364 (forward-line -1))
1365
1366 (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
1367 (defun texinfo-enumerate-item ()
1368 (texinfo-discard-line)
1369 (let (enumerating-symbol)
1370 (cond ((integerp (car (cdr (car texinfo-stack))))
1371 (setq enumerating-symbol (car (cdr (car texinfo-stack))))
1372 (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
1373 (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
1374 ((symbolp (car (cdr (car texinfo-stack))))
1375 (setq enumerating-symbol
1376 (symbol-name (car (cdr (car texinfo-stack)))))
1377 (if (or (equal ?\[ (string-to-char enumerating-symbol))
1378 (equal ?\{ (string-to-char enumerating-symbol)))
1379 (error
1380 "Too many items in enumerated list; alphabet ends at Z."))
1381 (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
1382 (setcar (cdr (car texinfo-stack))
1383 (make-symbol
1384 (char-to-string
1385 (1+
1386 (string-to-char enumerating-symbol))))))
1387 (t
1388 (error
1389 "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
1390 (forward-line -1)))
1391
1392 (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
1393 (defun texinfo-alphaenumerate-item ()
1394 (texinfo-discard-line)
1395 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1396 (if (> next ?z)
1397 (error "More than 26 items in @alphaenumerate; get a bigger alphabet."))
1398 (setcar (cdr (car texinfo-stack)) next)
1399 (insert "\b " next ". \n"))
1400 (forward-line -1))
1401
1402 (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
1403 (defun texinfo-capsenumerate-item ()
1404 (texinfo-discard-line)
1405 (let ((next (1+ (car (cdr (car texinfo-stack))))))
1406 (if (> next ?Z)
1407 (error "More than 26 items in @capsenumerate; get a bigger alphabet."))
1408 (setcar (cdr (car texinfo-stack)) next)
1409 (insert "\b " next ". \n"))
1410 (forward-line -1))
1411
1412 \f
1413 ;;; @table
1414
1415 ; The `@table' command produces two-column tables.
1416
1417 (put 'table 'texinfo-format 'texinfo-table)
1418 (defun texinfo-table ()
1419 (texinfo-push-stack
1420 'table
1421 (progn (skip-chars-forward " \t")
1422 (if (eolp)
1423 "@asis"
1424 (texinfo-parse-line-arg))))
1425 (texinfo-discard-line-with-args)
1426 (setq fill-column (- fill-column 5)))
1427
1428 (put 'table 'texinfo-item 'texinfo-table-item)
1429 (defun texinfo-table-item ()
1430 (let ((arg (texinfo-parse-arg-discard))
1431 (itemfont (car (cdr (car texinfo-stack)))))
1432 (insert ?\b itemfont ?\{ arg "}\n \n"))
1433 (forward-line -2))
1434
1435 (put 'table 'texinfo-end 'texinfo-end-table)
1436 (defun texinfo-end-table ()
1437 (setq fill-column (+ fill-column 5))
1438 (texinfo-discard-command)
1439 (let ((stacktop
1440 (texinfo-pop-stack 'table)))
1441 (texinfo-do-itemize (nth 1 stacktop))))
1442
1443 ;; @description appears to be an undocumented variant on @table that
1444 ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
1445 ;; part of makeinfo.c The command appears to be a relic of the past.
1446 (put 'description 'texinfo-end 'texinfo-end-table)
1447 (put 'description 'texinfo-format 'texinfo-description)
1448 (defun texinfo-description ()
1449 (texinfo-push-stack 'table "@asis")
1450 (setq fill-column (- fill-column 5))
1451 (texinfo-discard-line))
1452
1453 \f
1454 ;;; @ftable, @vtable
1455
1456 ; The `@ftable' and `@vtable' commands are like the `@table' command
1457 ; but they also insert each entry in the first column of the table
1458 ; into the function or variable index.
1459
1460 ;; Handle the @ftable and @vtable commands:
1461
1462 (put 'ftable 'texinfo-format 'texinfo-ftable)
1463 (put 'vtable 'texinfo-format 'texinfo-vtable)
1464
1465 (defun texinfo-ftable () (texinfo-indextable 'ftable))
1466 (defun texinfo-vtable () (texinfo-indextable 'vtable))
1467
1468 (defun texinfo-indextable (table-type)
1469 (texinfo-push-stack table-type (texinfo-parse-arg-discard))
1470 (setq fill-column (- fill-column 5)))
1471
1472 ;; Handle the @item commands within ftable and vtable:
1473
1474 (put 'ftable 'texinfo-item 'texinfo-ftable-item)
1475 (put 'vtable 'texinfo-item 'texinfo-vtable-item)
1476
1477 (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
1478 (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
1479
1480 (defun texinfo-indextable-item (index-type)
1481 (let ((item (texinfo-parse-arg-discard))
1482 (itemfont (car (cdr (car texinfo-stack))))
1483 (indexvar index-type))
1484 (insert ?\b itemfont ?\{ item "}\n \n")
1485 (set indexvar
1486 (cons
1487 (list item texinfo-last-node)
1488 (symbol-value indexvar)))
1489 (forward-line -2)))
1490
1491 ;; Handle @end ftable, @end vtable
1492
1493 (put 'ftable 'texinfo-end 'texinfo-end-ftable)
1494 (put 'vtable 'texinfo-end 'texinfo-end-vtable)
1495
1496 (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
1497 (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
1498
1499 (defun texinfo-end-indextable (table-type)
1500 (setq fill-column (+ fill-column 5))
1501 (texinfo-discard-command)
1502 (let ((stacktop
1503 (texinfo-pop-stack table-type)))
1504 (texinfo-do-itemize (nth 1 stacktop))))
1505
1506 \f
1507 ;;; @ifinfo, @iftex, @tex, @ifhtml, @html
1508
1509 (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
1510 (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
1511
1512 (put 'iftex 'texinfo-format 'texinfo-format-iftex)
1513 (defun texinfo-format-iftex ()
1514 (delete-region texinfo-command-start
1515 (progn (re-search-forward "@end iftex[ \t]*\n")
1516 (point))))
1517
1518 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
1519 (defun texinfo-format-ifhtml ()
1520 (delete-region texinfo-command-start
1521 (progn (re-search-forward "@end ifhtml[ \t]*\n")
1522 (point))))
1523
1524 (put 'tex 'texinfo-format 'texinfo-format-tex)
1525 (defun texinfo-format-tex ()
1526 (delete-region texinfo-command-start
1527 (progn (re-search-forward "@end tex[ \t]*\n")
1528 (point))))
1529
1530 (put 'html 'texinfo-format 'texinfo-format-html)
1531 (defun texinfo-format-html ()
1532 (delete-region texinfo-command-start
1533 (progn (re-search-forward "@end html[ \t]*\n")
1534 (point))))
1535
1536 \f
1537 ;;; @titlepage
1538
1539 (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
1540 (defun texinfo-format-titlepage ()
1541 (delete-region texinfo-command-start
1542 (progn (re-search-forward "@end titlepage[ \t]*\n")
1543 (point))))
1544
1545 (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
1546
1547 ; @titlespec an alternative titling command; ignored by Info
1548
1549 (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
1550 (defun texinfo-format-titlespec ()
1551 (delete-region texinfo-command-start
1552 (progn (re-search-forward "@end titlespec[ \t]*\n")
1553 (point))))
1554
1555 (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
1556
1557 \f
1558 ;;; @today
1559
1560 (put 'today 'texinfo-format 'texinfo-format-today)
1561
1562 ; Produces Day Month Year style of output. eg `1 Jan 1900'
1563 ; The `@today{}' command requires a pair of braces, like `@dots{}'.
1564 (defun texinfo-format-today ()
1565 (texinfo-parse-arg-discard)
1566 (insert (format-time-string "%e %b %Y")))
1567
1568 \f
1569 ;;; @ignore
1570
1571 (put 'ignore 'texinfo-format 'texinfo-format-ignore)
1572 (defun texinfo-format-ignore ()
1573 (delete-region texinfo-command-start
1574 (progn (re-search-forward "@end ignore[ \t]*\n")
1575 (point))))
1576
1577 (put 'endignore 'texinfo-format 'texinfo-discard-line)
1578
1579 \f
1580 ;;; Define the Info enclosure command: @definfoenclose
1581
1582 ; A `@definfoenclose' command may be used to define a highlighting
1583 ; command for Info, but not for TeX. A command defined using
1584 ; `@definfoenclose' marks text by enclosing it in strings that precede
1585 ; and follow the text.
1586 ;
1587 ; Presumably, if you define a command with `@definfoenclose` for Info,
1588 ; you will also define the same command in the TeX definitions file,
1589 ; `texinfo.tex' in a manner appropriate for typesetting.
1590 ;
1591 ; Write a `@definfoenclose' command on a line and follow it with three
1592 ; arguments separated by commas (commas are used as separators in an
1593 ; `@node' line in the same way). The first argument to
1594 ; `@definfoenclose' is the @-command name \(without the `@'\); the
1595 ; second argument is the Info start delimiter string; and the third
1596 ; argument is the Info end delimiter string. The latter two arguments
1597 ; enclose the highlighted text in the Info file. A delimiter string
1598 ; may contain spaces. Neither the start nor end delimiter is
1599 ; required. However, if you do not provide a start delimiter, you
1600 ; must follow the command name with two commas in a row; otherwise,
1601 ; the Info formatting commands will misinterpret the end delimiter
1602 ; string as a start delimiter string.
1603 ;
1604 ; If you do a @definfoenclose{} on the name of a pre-defined macro (such
1605 ; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
1606 ; override the built-in definition.
1607 ;
1608 ; An enclosure command defined this way takes one argument in braces.
1609 ;
1610 ; For example, you can write:
1611 ;
1612 ; @ifinfo
1613 ; @definfoenclose phoo, //, \\
1614 ; @end ifinfo
1615 ;
1616 ; near the beginning of a Texinfo file at the beginning of the lines
1617 ; to define `@phoo' as an Info formatting command that inserts `//'
1618 ; before and `\\' after the argument to `@phoo'. You can then write
1619 ; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
1620 ;
1621 ; Also, for TeX formatting, you could write
1622 ;
1623 ; @iftex
1624 ; @global@let@phoo=@i
1625 ; @end iftex
1626 ;
1627 ; to define `@phoo' as a command that causes TeX to typeset
1628 ; the argument to `@phoo' in italics.
1629 ;
1630 ; Note that each definition applies to its own formatter: one for TeX,
1631 ; the other for texinfo-format-buffer or texinfo-format-region.
1632 ;
1633 ; Here is another example: write
1634 ;
1635 ; @definfoenclose headword, , :
1636 ;
1637 ; near the beginning of the file, to define `@headword' as an Info
1638 ; formatting command that inserts nothing before and a colon after the
1639 ; argument to `@headword'.
1640
1641 (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
1642 (defun texinfo-define-info-enclosure ()
1643 (let* ((args (texinfo-format-parse-line-args))
1644 (command-name (nth 0 args))
1645 (beginning-delimiter (or (nth 1 args) ""))
1646 (end-delimiter (or (nth 2 args) "")))
1647 (texinfo-discard-command)
1648 (setq texinfo-enclosure-list
1649 (cons
1650 (list command-name
1651 (list
1652 beginning-delimiter
1653 end-delimiter))
1654 texinfo-enclosure-list))))
1655
1656 \f
1657 ;;; @var, @code and the like
1658
1659 (put 'var 'texinfo-format 'texinfo-format-var)
1660 ; @sc a small caps font for TeX; formatted as `var' in Info
1661 (put 'sc 'texinfo-format 'texinfo-format-var)
1662 (defun texinfo-format-var ()
1663 (insert (upcase (texinfo-parse-arg-discard)))
1664 (goto-char texinfo-command-start))
1665
1666 ; various noops
1667
1668 (put 'b 'texinfo-format 'texinfo-format-noop)
1669 (put 'i 'texinfo-format 'texinfo-format-noop)
1670 (put 'r 'texinfo-format 'texinfo-format-noop)
1671 (put 't 'texinfo-format 'texinfo-format-noop)
1672 (put 'w 'texinfo-format 'texinfo-format-noop)
1673 (put 'asis 'texinfo-format 'texinfo-format-noop)
1674 (put 'dmn 'texinfo-format 'texinfo-format-noop)
1675 (put 'key 'texinfo-format 'texinfo-format-noop)
1676 (put 'math 'texinfo-format 'texinfo-format-noop)
1677 (put 'titlefont 'texinfo-format 'texinfo-format-noop)
1678 (defun texinfo-format-noop ()
1679 (insert (texinfo-parse-arg-discard))
1680 (goto-char texinfo-command-start))
1681
1682 (put 'cite 'texinfo-format 'texinfo-format-code)
1683 (put 'code 'texinfo-format 'texinfo-format-code)
1684 (put 'file 'texinfo-format 'texinfo-format-code)
1685 (put 'kbd 'texinfo-format 'texinfo-format-code)
1686 (put 'samp 'texinfo-format 'texinfo-format-code)
1687 (defun texinfo-format-code ()
1688 (insert "`" (texinfo-parse-arg-discard) "'")
1689 (goto-char texinfo-command-start))
1690
1691 (put 'emph 'texinfo-format 'texinfo-format-emph)
1692 (put 'strong 'texinfo-format 'texinfo-format-emph)
1693 (defun texinfo-format-emph ()
1694 (insert "*" (texinfo-parse-arg-discard) "*")
1695 (goto-char texinfo-command-start))
1696
1697 (put 'dfn 'texinfo-format 'texinfo-format-defn)
1698 (put 'defn 'texinfo-format 'texinfo-format-defn)
1699 (defun texinfo-format-defn ()
1700 (insert "\"" (texinfo-parse-arg-discard) "\"")
1701 (goto-char texinfo-command-start))
1702
1703 (put 'bullet 'texinfo-format 'texinfo-format-bullet)
1704 (defun texinfo-format-bullet ()
1705 "Insert an asterisk.
1706 If used within a line, follow `@bullet' with braces."
1707 (texinfo-optional-braces-discard)
1708 (insert "*"))
1709
1710 \f
1711 ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample
1712
1713 (put 'display 'texinfo-format 'texinfo-format-example)
1714 (put 'example 'texinfo-format 'texinfo-format-example)
1715 (put 'lisp 'texinfo-format 'texinfo-format-example)
1716 (put 'quotation 'texinfo-format 'texinfo-format-example)
1717 (put 'smallexample 'texinfo-format 'texinfo-format-example)
1718 (put 'smalllisp 'texinfo-format 'texinfo-format-example)
1719 (defun texinfo-format-example ()
1720 (texinfo-push-stack 'example nil)
1721 (setq fill-column (- fill-column 5))
1722 (texinfo-discard-line))
1723
1724 (put 'example 'texinfo-end 'texinfo-end-example)
1725 (put 'display 'texinfo-end 'texinfo-end-example)
1726 (put 'lisp 'texinfo-end 'texinfo-end-example)
1727 (put 'quotation 'texinfo-end 'texinfo-end-example)
1728 (put 'smallexample 'texinfo-end 'texinfo-end-example)
1729 (put 'smalllisp 'texinfo-end 'texinfo-end-example)
1730 (defun texinfo-end-example ()
1731 (setq fill-column (+ fill-column 5))
1732 (texinfo-discard-command)
1733 (let ((stacktop
1734 (texinfo-pop-stack 'example)))
1735 (texinfo-do-itemize (nth 1 stacktop))))
1736
1737 (put 'exdent 'texinfo-format 'texinfo-format-exdent)
1738 (defun texinfo-format-exdent ()
1739 (texinfo-discard-command)
1740 (delete-region (point)
1741 (progn
1742 (skip-chars-forward " ")
1743 (point)))
1744 (insert ?\b)
1745 ;; Cancel out the deletion that texinfo-do-itemize
1746 ;; is going to do at the end of this line.
1747 (save-excursion
1748 (end-of-line)
1749 (insert "\n ")))
1750
1751 \f
1752 ;;; @cartouche
1753
1754 ; The @cartouche command is a noop in Info; in a printed manual,
1755 ; it makes a box with rounded corners.
1756
1757 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
1758 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
1759
1760 \f
1761 ;;; @flushleft and @format
1762
1763 ; The @flushleft command left justifies every line but leaves the
1764 ; right end ragged. As far as Info is concerned, @flushleft is a
1765 ; `do-nothing' command
1766
1767 ; The @format command is similar to @example except that it does not
1768 ; indent; this means that in Info, @format is similar to @flushleft.
1769
1770 (put 'format 'texinfo-format 'texinfo-format-flushleft)
1771 (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
1772 (defun texinfo-format-flushleft ()
1773 (texinfo-discard-line))
1774
1775 (put 'format 'texinfo-end 'texinfo-end-flushleft)
1776 (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
1777 (defun texinfo-end-flushleft ()
1778 (texinfo-discard-command))
1779
1780 \f
1781 ;;; @flushright
1782
1783 ; The @flushright command right justifies every line but leaves the
1784 ; left end ragged. Spaces and tabs at the right ends of lines are
1785 ; removed so that visible text lines up on the right side.
1786
1787 (put 'flushright 'texinfo-format 'texinfo-format-flushright)
1788 (defun texinfo-format-flushright ()
1789 (texinfo-push-stack 'flushright nil)
1790 (texinfo-discard-line))
1791
1792 (put 'flushright 'texinfo-end 'texinfo-end-flushright)
1793 (defun texinfo-end-flushright ()
1794 (texinfo-discard-command)
1795
1796 (let ((stacktop
1797 (texinfo-pop-stack 'flushright)))
1798
1799 (texinfo-do-flushright (nth 1 stacktop))))
1800
1801 (defun texinfo-do-flushright (from)
1802 (save-excursion
1803 (while (progn (forward-line -1)
1804 (>= (point) from))
1805
1806 (beginning-of-line)
1807 (insert
1808 (make-string
1809 (- fill-column
1810 (save-excursion
1811 (end-of-line)
1812 (skip-chars-backward " \t")
1813 (delete-region (point) (progn (end-of-line) (point)))
1814 (current-column)))
1815 ? )))))
1816
1817 \f
1818 ;;; @ctrl, @TeX, @copyright, @minus, @dots
1819
1820 (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
1821 (defun texinfo-format-ctrl ()
1822 (let ((str (texinfo-parse-arg-discard)))
1823 (insert (logand 31 (aref str 0)))))
1824
1825 (put 'TeX 'texinfo-format 'texinfo-format-TeX)
1826 (defun texinfo-format-TeX ()
1827 (texinfo-parse-arg-discard)
1828 (insert "TeX"))
1829
1830 (put 'copyright 'texinfo-format 'texinfo-format-copyright)
1831 (defun texinfo-format-copyright ()
1832 (texinfo-parse-arg-discard)
1833 (insert "(C)"))
1834
1835 (put 'minus 'texinfo-format 'texinfo-format-minus)
1836 (defun texinfo-format-minus ()
1837 "Insert a minus sign.
1838 If used within a line, follow `@minus' with braces."
1839 (texinfo-optional-braces-discard)
1840 (insert "-"))
1841
1842 (put 'dots 'texinfo-format 'texinfo-format-dots)
1843 (defun texinfo-format-dots ()
1844 (texinfo-parse-arg-discard)
1845 (insert "..."))
1846
1847 (put 'enddots 'texinfo-format 'texinfo-format-enddots)
1848 (defun texinfo-format-enddots ()
1849 (texinfo-parse-arg-discard)
1850 (insert "...."))
1851
1852 \f
1853 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
1854
1855 ;;; Indent only those paragraphs that are refilled as a result of an
1856 ;;; @refill command.
1857
1858 ; * If the value is `asis', do not change the existing indentation at
1859 ; the starts of paragraphs.
1860
1861 ; * If the value zero, delete any existing indentation.
1862
1863 ; * If the value is greater than zero, indent each paragraph by that
1864 ; number of spaces.
1865
1866 ;;; But do not refill paragraphs with an @refill command that are
1867 ;;; preceded by @noindent or are part of a table, list, or deffn.
1868
1869 (defvar texinfo-paragraph-indent "asis"
1870 "Number of spaces for @refill to indent a paragraph; else to leave as is.")
1871
1872 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
1873
1874 (defun texinfo-paragraphindent ()
1875 "Specify the number of spaces for @refill to indent a paragraph.
1876 Default is to leave the number of spaces as is."
1877 (let ((arg (texinfo-parse-arg-discard)))
1878 (if (string= "asis" arg)
1879 (setq texinfo-paragraph-indent "asis")
1880 (setq texinfo-paragraph-indent (string-to-int arg)))))
1881
1882 (put 'refill 'texinfo-format 'texinfo-format-refill)
1883 (defun texinfo-format-refill ()
1884 "Refill paragraph. Also, indent first line as set by @paragraphindent.
1885 Default is to leave paragraph indentation as is."
1886 (texinfo-discard-command)
1887 (forward-paragraph -1)
1888 (if (looking-at "[ \t\n]*$") (forward-line 1))
1889 ;; Do not indent if an entry in a list, table, or deffn,
1890 ;; or if paragraph is preceded by @noindent.
1891 ;; Otherwise, indent
1892 (cond
1893 ;; delete a @noindent line and do not indent paragraph
1894 ((save-excursion (forward-line -1)
1895 (looking-at "^@noindent"))
1896 (forward-line -1)
1897 (delete-region (point) (progn (forward-line 1) (point))))
1898 ;; do nothing if "asis"
1899 ((equal texinfo-paragraph-indent "asis"))
1900 ;; do no indenting in list, etc.
1901 ((> texinfo-stack-depth 0))
1902 ;; otherwise delete existing whitespace and indent
1903 (t
1904 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
1905 (insert (make-string texinfo-paragraph-indent ? ))))
1906 (forward-paragraph 1)
1907 (forward-line -1)
1908 (end-of-line)
1909 ;; Do not fill a section title line with asterisks, hyphens, etc. that
1910 ;; are used to underline it. This could occur if the line following
1911 ;; the underlining is not an index entry and has text within it.
1912 (let* ((previous-paragraph-separate paragraph-separate)
1913 (paragraph-separate (concat paragraph-separate "\\|[-=*.]+"))
1914 (previous-paragraph-start paragraph-start)
1915 (paragraph-start (concat paragraph-start "\\|[-=*.]+")))
1916 (unwind-protect
1917 (fill-paragraph nil)
1918 (setq paragraph-separate previous-paragraph-separate)
1919 (setq paragraph-start previous-paragraph-start))))
1920
1921 (put 'noindent 'texinfo-format 'texinfo-noindent)
1922 (defun texinfo-noindent ()
1923 (save-excursion
1924 (forward-paragraph 1)
1925 (if (search-backward "@refill"
1926 (save-excursion (forward-line -1) (point)) t)
1927 () ; leave @noindent command so @refill command knows not to indent
1928 ;; else
1929 (texinfo-discard-line))))
1930
1931 \f
1932 ;;; Index generation
1933
1934 (put 'vindex 'texinfo-format 'texinfo-format-vindex)
1935 (defun texinfo-format-vindex ()
1936 (texinfo-index 'texinfo-vindex))
1937
1938 (put 'cindex 'texinfo-format 'texinfo-format-cindex)
1939 (defun texinfo-format-cindex ()
1940 (texinfo-index 'texinfo-cindex))
1941
1942 (put 'findex 'texinfo-format 'texinfo-format-findex)
1943 (defun texinfo-format-findex ()
1944 (texinfo-index 'texinfo-findex))
1945
1946 (put 'pindex 'texinfo-format 'texinfo-format-pindex)
1947 (defun texinfo-format-pindex ()
1948 (texinfo-index 'texinfo-pindex))
1949
1950 (put 'tindex 'texinfo-format 'texinfo-format-tindex)
1951 (defun texinfo-format-tindex ()
1952 (texinfo-index 'texinfo-tindex))
1953
1954 (put 'kindex 'texinfo-format 'texinfo-format-kindex)
1955 (defun texinfo-format-kindex ()
1956 (texinfo-index 'texinfo-kindex))
1957
1958 (defun texinfo-index (indexvar)
1959 (let ((arg (texinfo-parse-expanded-arg)))
1960 (texinfo-discard-command)
1961 (set indexvar
1962 (cons (list arg
1963 texinfo-last-node
1964 ;; Region formatting may not provide last node position.
1965 (if texinfo-last-node-pos
1966 (1+ (count-lines texinfo-last-node-pos (point)))
1967 1))
1968 (symbol-value indexvar)))))
1969
1970 (defconst texinfo-indexvar-alist
1971 '(("cp" . texinfo-cindex)
1972 ("fn" . texinfo-findex)
1973 ("vr" . texinfo-vindex)
1974 ("tp" . texinfo-tindex)
1975 ("pg" . texinfo-pindex)
1976 ("ky" . texinfo-kindex)))
1977
1978 \f
1979 ;;; @defindex @defcodeindex
1980 (put 'defindex 'texinfo-format 'texinfo-format-defindex)
1981 (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
1982
1983 (defun texinfo-format-defindex ()
1984 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
1985 (indexing-command (intern (concat index-name "index")))
1986 (index-formatting-command ; eg: `texinfo-format-aaindex'
1987 (intern (concat "texinfo-format-" index-name "index")))
1988 (index-alist-name ; eg: `texinfo-aaindex'
1989 (intern (concat "texinfo-" index-name "index"))))
1990
1991 (set index-alist-name nil)
1992
1993 (put indexing-command ; eg, aaindex
1994 'texinfo-format
1995 index-formatting-command) ; eg, texinfo-format-aaindex
1996
1997 ;; eg: "aa" . texinfo-aaindex
1998 (or (assoc index-name texinfo-indexvar-alist)
1999 (setq texinfo-indexvar-alist
2000 (cons
2001 (cons index-name
2002 index-alist-name)
2003 texinfo-indexvar-alist)))
2004
2005 (fset index-formatting-command
2006 (list 'lambda 'nil
2007 (list 'texinfo-index
2008 (list 'quote index-alist-name))))))
2009
2010 \f
2011 ;;; @synindex @syncodeindex
2012
2013 (put 'synindex 'texinfo-format 'texinfo-format-synindex)
2014 (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
2015
2016 (defun texinfo-format-synindex ()
2017 (let* ((args (texinfo-parse-arg-discard))
2018 (second (cdr (read-from-string args)))
2019 (joiner (symbol-name (car (read-from-string args))))
2020 (joined (symbol-name (car (read-from-string args second)))))
2021
2022 (if (assoc joiner texinfo-short-index-cmds-alist)
2023 (put
2024 (cdr (assoc joiner texinfo-short-index-cmds-alist))
2025 'texinfo-format
2026 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
2027 (intern (concat "texinfo-format-" joined "index"))))
2028 (put
2029 (intern (concat joiner "index"))
2030 'texinfo-format
2031 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
2032 (intern (concat "texinfo-format-" joined "index")))))))
2033
2034 (defconst texinfo-short-index-cmds-alist
2035 '(("cp" . cindex)
2036 ("fn" . findex)
2037 ("vr" . vindex)
2038 ("tp" . tindex)
2039 ("pg" . pindex)
2040 ("ky" . kindex)))
2041
2042 (defconst texinfo-short-index-format-cmds-alist
2043 '(("cp" . texinfo-format-cindex)
2044 ("fn" . texinfo-format-findex)
2045 ("vr" . texinfo-format-vindex)
2046 ("tp" . texinfo-format-tindex)
2047 ("pg" . texinfo-format-pindex)
2048 ("ky" . texinfo-format-kindex)))
2049
2050 \f
2051 ;;; Sort and index (for VMS)
2052
2053 ;; Sort an index which is in the current buffer between START and END.
2054 ;; Used on VMS, where the `sort' utility is not available.
2055 (defun texinfo-sort-region (start end)
2056 (require 'sort)
2057 (save-restriction
2058 (narrow-to-region start end)
2059 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
2060
2061 ;; Subroutine for sorting an index.
2062 ;; At start of a line, return a string to sort the line under.
2063 (defun texinfo-sort-startkeyfun ()
2064 (let ((line
2065 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
2066 ;; Canonicalize whitespace and eliminate funny chars.
2067 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
2068 (setq line (concat (substring line 0 (match-beginning 0))
2069 " "
2070 (substring line (match-end 0) (length line)))))
2071 line))
2072
2073 \f
2074 ;;; @printindex
2075
2076 (put 'printindex 'texinfo-format 'texinfo-format-printindex)
2077
2078 (defun texinfo-format-printindex ()
2079 (let ((indexelts (symbol-value
2080 (cdr (assoc (texinfo-parse-arg-discard)
2081 texinfo-indexvar-alist))))
2082 opoint)
2083 (insert "\n* Menu:\n\n")
2084 (setq opoint (point))
2085 (texinfo-print-index nil indexelts)
2086
2087 (if (memq system-type '(vax-vms windows-nt ms-dos))
2088 (texinfo-sort-region opoint (point))
2089 (shell-command-on-region opoint (point) "sort -fd" 1))))
2090
2091 (defun texinfo-print-index (file indexelts)
2092 (while indexelts
2093 (if (stringp (car (car indexelts)))
2094 (progn
2095 (insert "* " (car (car indexelts)) ": " )
2096 (indent-to 32)
2097 (insert
2098 (if file (concat "(" file ")") "")
2099 (nth 1 (car indexelts)) ".")
2100 (indent-to 54)
2101 (insert
2102 (if (nth 2 (car indexelts))
2103 (format " %d." (nth 2 (car indexelts)))
2104 "")
2105 "\n"))
2106 ;; index entries from @include'd file
2107 (texinfo-print-index (nth 1 (car indexelts))
2108 (nth 2 (car indexelts))))
2109 (setq indexelts (cdr indexelts))))
2110
2111 \f
2112 ;;; Glyphs: @equiv, @error, etc
2113
2114 ;; @equiv to show that two expressions are equivalent
2115 ;; @error to show an error message
2116 ;; @expansion to show what a macro expands to
2117 ;; @point to show the location of point in an example
2118 ;; @print to show what an evaluated expression prints
2119 ;; @result to indicate the value returned by an expression
2120
2121 (put 'equiv 'texinfo-format 'texinfo-format-equiv)
2122 (defun texinfo-format-equiv ()
2123 (texinfo-parse-arg-discard)
2124 (insert "=="))
2125
2126 (put 'error 'texinfo-format 'texinfo-format-error)
2127 (defun texinfo-format-error ()
2128 (texinfo-parse-arg-discard)
2129 (insert "error-->"))
2130
2131 (put 'expansion 'texinfo-format 'texinfo-format-expansion)
2132 (defun texinfo-format-expansion ()
2133 (texinfo-parse-arg-discard)
2134 (insert "==>"))
2135
2136 (put 'point 'texinfo-format 'texinfo-format-point)
2137 (defun texinfo-format-point ()
2138 (texinfo-parse-arg-discard)
2139 (insert "-!-"))
2140
2141 (put 'print 'texinfo-format 'texinfo-format-print)
2142 (defun texinfo-format-print ()
2143 (texinfo-parse-arg-discard)
2144 (insert "-|"))
2145
2146 (put 'result 'texinfo-format 'texinfo-format-result)
2147 (defun texinfo-format-result ()
2148 (texinfo-parse-arg-discard)
2149 (insert "=>"))
2150
2151 \f
2152 ;;; Definition formatting: @deffn, @defun, etc
2153
2154 ;; What definition formatting produces:
2155 ;;
2156 ;; @deffn category name args...
2157 ;; In Info, `Category: name ARGS'
2158 ;; In index: name: node. line#.
2159 ;;
2160 ;; @defvr category name
2161 ;; In Info, `Category: name'
2162 ;; In index: name: node. line#.
2163 ;;
2164 ;; @deftp category name attributes...
2165 ;; `category name attributes...' Note: @deftp args in lower case.
2166 ;; In index: name: node. line#.
2167 ;;
2168 ;; Specialized function-like or variable-like entity:
2169 ;;
2170 ;; @defun, @defmac, @defspec, @defvar, @defopt
2171 ;;
2172 ;; @defun name args In Info, `Function: name ARGS'
2173 ;; @defmac name args In Info, `Macro: name ARGS'
2174 ;; @defvar name In Info, `Variable: name'
2175 ;; etc.
2176 ;; In index: name: node. line#.
2177 ;;
2178 ;; Generalized typed-function-like or typed-variable-like entity:
2179 ;; @deftypefn category data-type name args...
2180 ;; In Info, `Category: data-type name args...'
2181 ;; @deftypevr category data-type name
2182 ;; In Info, `Category: data-type name'
2183 ;; In index: name: node. line#.
2184 ;;
2185 ;; Specialized typed-function-like or typed-variable-like entity:
2186 ;; @deftypefun data-type name args...
2187 ;; In Info, `Function: data-type name ARGS'
2188 ;; In index: name: node. line#.
2189 ;;
2190 ;; @deftypevar data-type name
2191 ;; In Info, `Variable: data-type name'
2192 ;; In index: name: node. line#. but include args after name!?
2193 ;;
2194 ;; Generalized object oriented entity:
2195 ;; @defop category class name args...
2196 ;; In Info, `Category on class: name ARG'
2197 ;; In index: name on class: node. line#.
2198 ;;
2199 ;; @defcv category class name
2200 ;; In Info, `Category of class: name'
2201 ;; In index: name of class: node. line#.
2202 ;;
2203 ;; Specialized object oriented entity:
2204 ;; @defmethod class name args...
2205 ;; In Info, `Method on class: name ARGS'
2206 ;; In index: name on class: node. line#.
2207 ;;
2208 ;; @defivar class name
2209 ;; In Info, `Instance variable of class: name'
2210 ;; In index: name of class: node. line#.
2211
2212 \f
2213 ;;; The definition formatting functions
2214
2215 (defun texinfo-format-defun ()
2216 (texinfo-push-stack 'defun nil)
2217 (setq fill-column (- fill-column 5))
2218 (texinfo-format-defun-1 t))
2219
2220 (defun texinfo-end-defun ()
2221 (setq fill-column (+ fill-column 5))
2222 (texinfo-discard-command)
2223 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
2224 (texinfo-do-itemize start)
2225 ;; Delete extra newline inserted after header.
2226 (save-excursion
2227 (goto-char start)
2228 (delete-char -1))))
2229
2230 (defun texinfo-format-defunx ()
2231 (texinfo-format-defun-1 nil))
2232
2233 (defun texinfo-format-defun-1 (first-p)
2234 (let ((parse-args (texinfo-format-parse-defun-args))
2235 (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
2236 (texinfo-discard-command)
2237 ;; Delete extra newline inserted after previous header line.
2238 (if (not first-p)
2239 (delete-char -1))
2240 (funcall
2241 (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
2242 ;; Insert extra newline so that paragraph filling does not mess
2243 ;; with header line.
2244 (insert "\n\n")
2245 (rplaca (cdr (cdr (car texinfo-stack))) (point))
2246 (funcall
2247 (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
2248
2249 ;;; Formatting the first line of a definition
2250
2251 ;; @deffn, @defvr, @deftp
2252 (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2253 (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2254 (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2255 (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2256 (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2257 (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
2258 (defun texinfo-format-deffn (parsed-args)
2259 ;; Generalized function-like, variable-like, or generic data-type entity:
2260 ;; @deffn category name args...
2261 ;; In Info, `Category: name ARGS'
2262 ;; @deftp category name attributes...
2263 ;; `category name attributes...' Note: @deftp args in lower case.
2264 (let ((category (car parsed-args))
2265 (name (car (cdr parsed-args)))
2266 (args (cdr (cdr parsed-args))))
2267 (insert " -- " category ": " name)
2268 (while args
2269 (insert " "
2270 (if (or (= ?& (aref (car args) 0))
2271 (eq (eval (car texinfo-defun-type)) 'deftp-type))
2272 (car args)
2273 (upcase (car args))))
2274 (setq args (cdr args)))))
2275
2276 ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
2277 (put 'defun 'texinfo-deffn-formatting-property
2278 'texinfo-format-specialized-defun)
2279 (put 'defunx 'texinfo-deffn-formatting-property
2280 'texinfo-format-specialized-defun)
2281 (put 'defmac 'texinfo-deffn-formatting-property
2282 'texinfo-format-specialized-defun)
2283 (put 'defmacx 'texinfo-deffn-formatting-property
2284 'texinfo-format-specialized-defun)
2285 (put 'defspec 'texinfo-deffn-formatting-property
2286 'texinfo-format-specialized-defun)
2287 (put 'defspecx 'texinfo-deffn-formatting-property
2288 'texinfo-format-specialized-defun)
2289 (put 'defvar 'texinfo-deffn-formatting-property
2290 'texinfo-format-specialized-defun)
2291 (put 'defvarx 'texinfo-deffn-formatting-property
2292 'texinfo-format-specialized-defun)
2293 (put 'defopt 'texinfo-deffn-formatting-property
2294 'texinfo-format-specialized-defun)
2295 (put 'defoptx 'texinfo-deffn-formatting-property
2296 'texinfo-format-specialized-defun)
2297 (defun texinfo-format-specialized-defun (parsed-args)
2298 ;; Specialized function-like or variable-like entity:
2299 ;; @defun name args In Info, `Function: Name ARGS'
2300 ;; @defmac name args In Info, `Macro: Name ARGS'
2301 ;; @defvar name In Info, `Variable: Name'
2302 ;; Use cdr of texinfo-defun-type to determine category:
2303 (let ((category (car (cdr texinfo-defun-type)))
2304 (name (car parsed-args))
2305 (args (cdr parsed-args)))
2306 (insert " -- " category ": " name)
2307 (while args
2308 (insert " "
2309 (if (= ?& (aref (car args) 0))
2310 (car args)
2311 (upcase (car args))))
2312 (setq args (cdr args)))))
2313
2314 ;; @deftypefn, @deftypevr: Generalized typed
2315 (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2316 (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2317 (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2318 (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
2319 (defun texinfo-format-deftypefn (parsed-args)
2320 ;; Generalized typed-function-like or typed-variable-like entity:
2321 ;; @deftypefn category data-type name args...
2322 ;; In Info, `Category: data-type name args...'
2323 ;; @deftypevr category data-type name
2324 ;; In Info, `Category: data-type name'
2325 ;; Note: args in lower case, unless modified in command line.
2326 (let ((category (car parsed-args))
2327 (data-type (car (cdr parsed-args)))
2328 (name (car (cdr (cdr parsed-args))))
2329 (args (cdr (cdr (cdr parsed-args)))))
2330 (insert " -- " category ": " data-type " " name)
2331 (while args
2332 (insert " " (car args))
2333 (setq args (cdr args)))))
2334
2335 ;; @deftypefun, @deftypevar: Specialized typed
2336 (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
2337 (put 'deftypefunx 'texinfo-deffn-formatting-property
2338 'texinfo-format-deftypefun)
2339 (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
2340 (put 'deftypevarx 'texinfo-deffn-formatting-property
2341 'texinfo-format-deftypefun)
2342 (defun texinfo-format-deftypefun (parsed-args)
2343 ;; Specialized typed-function-like or typed-variable-like entity:
2344 ;; @deftypefun data-type name args...
2345 ;; In Info, `Function: data-type name ARGS'
2346 ;; @deftypevar data-type name
2347 ;; In Info, `Variable: data-type name'
2348 ;; Note: args in lower case, unless modified in command line.
2349 ;; Use cdr of texinfo-defun-type to determine category:
2350 (let ((category (car (cdr texinfo-defun-type)))
2351 (data-type (car parsed-args))
2352 (name (car (cdr parsed-args)))
2353 (args (cdr (cdr parsed-args))))
2354 (insert " -- " category ": " data-type " " name)
2355 (while args
2356 (insert " " (car args))
2357 (setq args (cdr args)))))
2358
2359 ;; @defop: Generalized object-oriented
2360 (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
2361 (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
2362 (defun texinfo-format-defop (parsed-args)
2363 ;; Generalized object oriented entity:
2364 ;; @defop category class name args...
2365 ;; In Info, `Category on class: name ARG'
2366 ;; Note: args in upper case; use of `on'
2367 (let ((category (car parsed-args))
2368 (class (car (cdr parsed-args)))
2369 (name (car (cdr (cdr parsed-args))))
2370 (args (cdr (cdr (cdr parsed-args)))))
2371 (insert " -- " category " on " class ": " name)
2372 (while args
2373 (insert " " (upcase (car args)))
2374 (setq args (cdr args)))))
2375
2376 ;; @defcv: Generalized object-oriented
2377 (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
2378 (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
2379 (defun texinfo-format-defcv (parsed-args)
2380 ;; Generalized object oriented entity:
2381 ;; @defcv category class name
2382 ;; In Info, `Category of class: name'
2383 ;; Note: args in upper case; use of `of'
2384 (let ((category (car parsed-args))
2385 (class (car (cdr parsed-args)))
2386 (name (car (cdr (cdr parsed-args))))
2387 (args (cdr (cdr (cdr parsed-args)))))
2388 (insert " -- " category " of " class ": " name)
2389 (while args
2390 (insert " " (upcase (car args)))
2391 (setq args (cdr args)))))
2392
2393 ;; @defmethod: Specialized object-oriented
2394 (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
2395 (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
2396 (defun texinfo-format-defmethod (parsed-args)
2397 ;; Specialized object oriented entity:
2398 ;; @defmethod class name args...
2399 ;; In Info, `Method on class: name ARGS'
2400 ;; Note: args in upper case; use of `on'
2401 ;; Use cdr of texinfo-defun-type to determine category:
2402 (let ((category (car (cdr texinfo-defun-type)))
2403 (class (car parsed-args))
2404 (name (car (cdr parsed-args)))
2405 (args (cdr (cdr parsed-args))))
2406 (insert " -- " category " on " class ": " name)
2407 (while args
2408 (insert " " (upcase (car args)))
2409 (setq args (cdr args)))))
2410
2411 ;; @defivar: Specialized object-oriented
2412 (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
2413 (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
2414 (defun texinfo-format-defivar (parsed-args)
2415 ;; Specialized object oriented entity:
2416 ;; @defivar class name
2417 ;; In Info, `Instance variable of class: name'
2418 ;; Note: args in upper case; use of `of'
2419 ;; Use cdr of texinfo-defun-type to determine category:
2420 (let ((category (car (cdr texinfo-defun-type)))
2421 (class (car parsed-args))
2422 (name (car (cdr parsed-args)))
2423 (args (cdr (cdr parsed-args))))
2424 (insert " -- " category " of " class ": " name)
2425 (while args
2426 (insert " " (upcase (car args)))
2427 (setq args (cdr args)))))
2428
2429 \f
2430 ;;; Indexing for definitions
2431
2432 ;; An index entry has three parts: the `entry proper', the node name, and the
2433 ;; line number. Depending on the which command is used, the entry is
2434 ;; formatted differently:
2435 ;;
2436 ;; @defun,
2437 ;; @defmac,
2438 ;; @defspec,
2439 ;; @defvar,
2440 ;; @defopt all use their 1st argument as the entry-proper
2441 ;;
2442 ;; @deffn,
2443 ;; @defvr,
2444 ;; @deftp
2445 ;; @deftypefun
2446 ;; @deftypevar all use their 2nd argument as the entry-proper
2447 ;;
2448 ;; @deftypefn,
2449 ;; @deftypevr both use their 3rd argument as the entry-proper
2450 ;;
2451 ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
2452 ;; formatted: NAME on CLASS
2453
2454 ;; @defop uses its 3rd and 2nd arguments as an entry-proper
2455 ;; formatted: NAME on CLASS
2456 ;;
2457 ;; @defivar uses its 2nd and 1st arguments as an entry-proper
2458 ;; formatted: NAME of CLASS
2459 ;;
2460 ;; @defcv uses its 3rd and 2nd argument as an entry-proper
2461 ;; formatted: NAME of CLASS
2462
2463 (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
2464 (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2465 (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
2466 (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2467 (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
2468 (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2469 (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
2470 (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2471 (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
2472 (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
2473 (defun texinfo-index-defun (parsed-args)
2474 ;; use 1st parsed-arg as entry-proper
2475 ;; `index-list' will be texinfo-findex or the like
2476 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2477 (set index-list
2478 (cons
2479 ;; Three elements: entry-proper, node-name, line-number
2480 (list
2481 (car parsed-args)
2482 texinfo-last-node
2483 ;; Region formatting may not provide last node position.
2484 (if texinfo-last-node-pos
2485 (1+ (count-lines texinfo-last-node-pos (point)))
2486 1))
2487 (symbol-value index-list)))))
2488
2489 (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2490 (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2491 (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2492 (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2493 (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2494 (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2495 (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2496 (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2497 (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2498 (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
2499 (defun texinfo-index-deffn (parsed-args)
2500 ;; use 2nd parsed-arg as entry-proper
2501 ;; `index-list' will be texinfo-findex or the like
2502 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2503 (set index-list
2504 (cons
2505 ;; Three elements: entry-proper, node-name, line-number
2506 (list
2507 (car (cdr parsed-args))
2508 texinfo-last-node
2509 ;; Region formatting may not provide last node position.
2510 (if texinfo-last-node-pos
2511 (1+ (count-lines texinfo-last-node-pos (point)))
2512 1))
2513 (symbol-value index-list)))))
2514
2515 (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2516 (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2517 (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2518 (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
2519 (defun texinfo-index-deftypefn (parsed-args)
2520 ;; use 3rd parsed-arg as entry-proper
2521 ;; `index-list' will be texinfo-findex or the like
2522 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2523 (set index-list
2524 (cons
2525 ;; Three elements: entry-proper, node-name, line-number
2526 (list
2527 (car (cdr (cdr parsed-args)))
2528 texinfo-last-node
2529 ;; Region formatting may not provide last node position.
2530 (if texinfo-last-node-pos
2531 (1+ (count-lines texinfo-last-node-pos (point)))
2532 1))
2533 (symbol-value index-list)))))
2534
2535 (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
2536 (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
2537 (defun texinfo-index-defmethod (parsed-args)
2538 ;; use 2nd on 1st parsed-arg as entry-proper
2539 ;; `index-list' will be texinfo-findex or the like
2540 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2541 (set index-list
2542 (cons
2543 ;; Three elements: entry-proper, node-name, line-number
2544 (list
2545 (format "%s on %s"
2546 (car (cdr parsed-args))
2547 (car parsed-args))
2548 texinfo-last-node
2549 ;; Region formatting may not provide last node position.
2550 (if texinfo-last-node-pos
2551 (1+ (count-lines texinfo-last-node-pos (point)))
2552 1))
2553 (symbol-value index-list)))))
2554
2555 (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
2556 (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
2557 (defun texinfo-index-defop (parsed-args)
2558 ;; use 3rd on 2nd parsed-arg as entry-proper
2559 ;; `index-list' will be texinfo-findex or the like
2560 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2561 (set index-list
2562 (cons
2563 ;; Three elements: entry-proper, node-name, line-number
2564 (list
2565 (format "%s on %s"
2566 (car (cdr (cdr parsed-args)))
2567 (car (cdr parsed-args)))
2568 texinfo-last-node
2569 ;; Region formatting may not provide last node position.
2570 (if texinfo-last-node-pos
2571 (1+ (count-lines texinfo-last-node-pos (point)))
2572 1))
2573 (symbol-value index-list)))))
2574
2575 (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
2576 (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
2577 (defun texinfo-index-defivar (parsed-args)
2578 ;; use 2nd of 1st parsed-arg as entry-proper
2579 ;; `index-list' will be texinfo-findex or the like
2580 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2581 (set index-list
2582 (cons
2583 ;; Three elements: entry-proper, node-name, line-number
2584 (list
2585 (format "%s of %s"
2586 (car (cdr parsed-args))
2587 (car parsed-args))
2588 texinfo-last-node
2589 ;; Region formatting may not provide last node position.
2590 (if texinfo-last-node-pos
2591 (1+ (count-lines texinfo-last-node-pos (point)))
2592 1))
2593 (symbol-value index-list)))))
2594
2595 (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
2596 (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
2597 (defun texinfo-index-defcv (parsed-args)
2598 ;; use 3rd of 2nd parsed-arg as entry-proper
2599 ;; `index-list' will be texinfo-findex or the like
2600 (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
2601 (set index-list
2602 (cons
2603 ;; Three elements: entry-proper, node-name, line-number
2604 (list
2605 (format "%s of %s"
2606 (car (cdr (cdr parsed-args)))
2607 (car (cdr parsed-args)))
2608 texinfo-last-node
2609 ;; Region formatting may not provide last node position.
2610 (if texinfo-last-node-pos
2611 (1+ (count-lines texinfo-last-node-pos (point)))
2612 1))
2613 (symbol-value index-list)))))
2614
2615 \f
2616 ;;; Properties for definitions
2617
2618 ;; Each definition command has six properties:
2619 ;;
2620 ;; 1. texinfo-deffn-formatting-property to format definition line
2621 ;; 2. texinfo-defun-indexing-property to create index entry
2622 ;; 3. texinfo-format formatting command
2623 ;; 4. texinfo-end end formatting command
2624 ;; 5. texinfo-defun-type type of deffn to format
2625 ;; 6. texinfo-defun-index type of index to use
2626 ;;
2627 ;; The `x' forms of each definition command are used for the second
2628 ;; and subsequent header lines.
2629
2630 ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
2631 ;; are listed just before the appropriate formatting and indexing commands.
2632
2633 (put 'deffn 'texinfo-format 'texinfo-format-defun)
2634 (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
2635 (put 'deffn 'texinfo-end 'texinfo-end-defun)
2636 (put 'deffn 'texinfo-defun-type '('deffn-type nil))
2637 (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
2638 (put 'deffn 'texinfo-defun-index 'texinfo-findex)
2639 (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
2640
2641 (put 'defun 'texinfo-format 'texinfo-format-defun)
2642 (put 'defunx 'texinfo-format 'texinfo-format-defunx)
2643 (put 'defun 'texinfo-end 'texinfo-end-defun)
2644 (put 'defun 'texinfo-defun-type '('defun-type "Function"))
2645 (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
2646 (put 'defun 'texinfo-defun-index 'texinfo-findex)
2647 (put 'defunx 'texinfo-defun-index 'texinfo-findex)
2648
2649 (put 'defmac 'texinfo-format 'texinfo-format-defun)
2650 (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
2651 (put 'defmac 'texinfo-end 'texinfo-end-defun)
2652 (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
2653 (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
2654 (put 'defmac 'texinfo-defun-index 'texinfo-findex)
2655 (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
2656
2657 (put 'defspec 'texinfo-format 'texinfo-format-defun)
2658 (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
2659 (put 'defspec 'texinfo-end 'texinfo-end-defun)
2660 (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
2661 (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
2662 (put 'defspec 'texinfo-defun-index 'texinfo-findex)
2663 (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
2664
2665 (put 'defvr 'texinfo-format 'texinfo-format-defun)
2666 (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
2667 (put 'defvr 'texinfo-end 'texinfo-end-defun)
2668 (put 'defvr 'texinfo-defun-type '('deffn-type nil))
2669 (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
2670 (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
2671 (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
2672
2673 (put 'defvar 'texinfo-format 'texinfo-format-defun)
2674 (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
2675 (put 'defvar 'texinfo-end 'texinfo-end-defun)
2676 (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
2677 (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
2678 (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
2679 (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
2680
2681 (put 'defconst 'texinfo-format 'texinfo-format-defun)
2682 (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
2683 (put 'defconst 'texinfo-end 'texinfo-end-defun)
2684 (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
2685 (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
2686 (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
2687 (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
2688
2689 (put 'defcmd 'texinfo-format 'texinfo-format-defun)
2690 (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
2691 (put 'defcmd 'texinfo-end 'texinfo-end-defun)
2692 (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
2693 (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
2694 (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
2695 (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
2696
2697 (put 'defopt 'texinfo-format 'texinfo-format-defun)
2698 (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
2699 (put 'defopt 'texinfo-end 'texinfo-end-defun)
2700 (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
2701 (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
2702 (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
2703 (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
2704
2705 (put 'deftp 'texinfo-format 'texinfo-format-defun)
2706 (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
2707 (put 'deftp 'texinfo-end 'texinfo-end-defun)
2708 (put 'deftp 'texinfo-defun-type '('deftp-type nil))
2709 (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
2710 (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
2711 (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
2712
2713 ;;; Object-oriented stuff is a little hairier.
2714
2715 (put 'defop 'texinfo-format 'texinfo-format-defun)
2716 (put 'defopx 'texinfo-format 'texinfo-format-defunx)
2717 (put 'defop 'texinfo-end 'texinfo-end-defun)
2718 (put 'defop 'texinfo-defun-type '('defop-type nil))
2719 (put 'defopx 'texinfo-defun-type '('defop-type nil))
2720 (put 'defop 'texinfo-defun-index 'texinfo-findex)
2721 (put 'defopx 'texinfo-defun-index 'texinfo-findex)
2722
2723 (put 'defmethod 'texinfo-format 'texinfo-format-defun)
2724 (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
2725 (put 'defmethod 'texinfo-end 'texinfo-end-defun)
2726 (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
2727 (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
2728 (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
2729 (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
2730
2731 (put 'defcv 'texinfo-format 'texinfo-format-defun)
2732 (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
2733 (put 'defcv 'texinfo-end 'texinfo-end-defun)
2734 (put 'defcv 'texinfo-defun-type '('defop-type nil))
2735 (put 'defcvx 'texinfo-defun-type '('defop-type nil))
2736 (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
2737 (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
2738
2739 (put 'defivar 'texinfo-format 'texinfo-format-defun)
2740 (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
2741 (put 'defivar 'texinfo-end 'texinfo-end-defun)
2742 (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
2743 (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
2744 (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
2745 (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
2746
2747 ;;; Typed functions and variables
2748
2749 (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
2750 (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
2751 (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
2752 (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
2753 (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
2754 (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
2755 (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
2756
2757 (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
2758 (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
2759 (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
2760 (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
2761 (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
2762 (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
2763 (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
2764
2765 (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
2766 (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
2767 (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
2768 (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
2769 (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
2770 (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
2771 (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
2772
2773 (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
2774 (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
2775 (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
2776 (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
2777 (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
2778 (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
2779 (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
2780
2781 \f
2782 ;;; @set, @clear, @ifset, @ifclear
2783
2784 ;; If a flag is set with @set FLAG, then text between @ifset and @end
2785 ;; ifset is formatted normally, but if the flag is is cleared with
2786 ;; @clear FLAG, then the text is not formatted; it is ignored.
2787
2788 ;; If a flag is cleared with @clear FLAG, then text between @ifclear
2789 ;; and @end ifclear is formatted normally, but if the flag is is set with
2790 ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
2791 ;; is the opposite of @ifset.
2792
2793 ;; If a flag is set to a string with @set FLAG,
2794 ;; replace @value{FLAG} with the string.
2795 ;; If a flag with a value is cleared,
2796 ;; @value{FLAG} is invalid,
2797 ;; as if there had never been any @set FLAG previously.
2798
2799 (put 'clear 'texinfo-format 'texinfo-clear)
2800 (defun texinfo-clear ()
2801 "Clear the value of the flag."
2802 (let* ((arg (texinfo-parse-arg-discard))
2803 (flag (car (read-from-string arg)))
2804 (value (substring arg (cdr (read-from-string arg)))))
2805 (put flag 'texinfo-whether-setp 'flag-cleared)
2806 (put flag 'texinfo-set-value "")))
2807
2808 (put 'set 'texinfo-format 'texinfo-set)
2809 (defun texinfo-set ()
2810 "Set the value of the flag, optionally to a string.
2811 The command `@set foo This is a string.'
2812 sets flag foo to the value: `This is a string.'
2813 The command `@value{foo}' expands to the value."
2814 (let* ((arg (texinfo-parse-arg-discard))
2815 (flag (car (read-from-string arg)))
2816 (value (substring arg (cdr (read-from-string arg)))))
2817 (put flag 'texinfo-whether-setp 'flag-set)
2818 (put flag 'texinfo-set-value value)))
2819
2820 (put 'value 'texinfo-format 'texinfo-value)
2821 (defun texinfo-value ()
2822 "Insert the string to which the flag is set.
2823 The command `@set foo This is a string.'
2824 sets flag foo to the value: `This is a string.'
2825 The command `@value{foo}' expands to the value."
2826 (let ((arg (texinfo-parse-arg-discard)))
2827 (cond ((and
2828 (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2829 'flag-set)
2830 (get (car (read-from-string arg)) 'texinfo-set-value))
2831 (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
2832 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2833 'flag-cleared)
2834 (insert (format "{No value for \"%s\"}" arg)))
2835 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
2836 (insert (format "{No value for \"%s\"}" arg))))))
2837
2838 (put 'ifset 'texinfo-end 'texinfo-discard-command)
2839 (put 'ifset 'texinfo-format 'texinfo-if-set)
2840 (defun texinfo-if-set ()
2841 "If set, continue formatting; else do not format region up to @end ifset"
2842 (let ((arg (texinfo-parse-arg-discard)))
2843 (cond
2844 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2845 'flag-set)
2846 ;; Format the text (i.e., do not remove it); do nothing here.
2847 ())
2848 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2849 'flag-cleared)
2850 ;; Clear region (i.e., cause the text to be ignored).
2851 (delete-region texinfo-command-start
2852 (progn (re-search-forward "@end ifset[ \t]*\n")
2853 (point))))
2854 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2855 nil)
2856 ;; In this case flag is neither set nor cleared.
2857 ;; Act as if set, i.e. do nothing.
2858 ()))))
2859
2860 (put 'ifclear 'texinfo-end 'texinfo-discard-command)
2861 (put 'ifclear 'texinfo-format 'texinfo-if-clear)
2862 (defun texinfo-if-clear ()
2863 "If clear, continue formatting; if set, do not format up to @end ifset"
2864 (let ((arg (texinfo-parse-arg-discard)))
2865 (cond
2866 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2867 'flag-set)
2868 ;; Clear region (i.e., cause the text to be ignored).
2869 (delete-region texinfo-command-start
2870 (progn (re-search-forward "@end ifclear[ \t]*\n")
2871 (point))))
2872 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2873 'flag-cleared)
2874 ;; Format the text (i.e., do not remove it); do nothing here.
2875 ())
2876 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
2877 nil)
2878 ;; In this case flag is neither set nor cleared.
2879 ;; Act as if clear, i.e. do nothing.
2880 ()))))
2881
2882 \f
2883 ;;; Process included files: `@include' command
2884
2885 ;; Updated 19 October 1990
2886 ;; In the original version, include files were ignored by Info but
2887 ;; incorporated in to the printed manual. To make references to the
2888 ;; included file, the Texinfo source file has to refer to the included
2889 ;; files using the `(filename)nodename' format for referring to other
2890 ;; Info files. Also, the included files had to be formatted on their
2891 ;; own. It was just like they were another file.
2892
2893 ;; Currently, include files are inserted into the buffer that is
2894 ;; formatted for Info. If large, the resulting info file is split and
2895 ;; tagified. For current include files to work, the master menu must
2896 ;; refer to all the nodes, and the highest level nodes in the include
2897 ;; files must have the correct next, prev, and up pointers.
2898
2899 ;; The included file may have an @setfilename and even an @settitle,
2900 ;; but not an `\input texinfo' line.
2901
2902 ;; Updated 24 March 1993
2903 ;; In order for @raisesections and @lowersections to work, included
2904 ;; files must be inserted into the buffer holding the outer file
2905 ;; before other Info formatting takes place. So @include is no longer
2906 ;; is treated like other @-commands.
2907 (put 'include 'texinfo-format 'texinfo-format-noop)
2908
2909 ; Original definition:
2910 ; (defun texinfo-format-include ()
2911 ; (let ((filename (texinfo-parse-arg-discard))
2912 ; (default-directory input-directory)
2913 ; subindex)
2914 ; (setq subindex
2915 ; (save-excursion
2916 ; (progn (find-file
2917 ; (cond ((file-readable-p (concat filename ".texinfo"))
2918 ; (concat filename ".texinfo"))
2919 ; ((file-readable-p (concat filename ".texi"))
2920 ; (concat filename ".texi"))
2921 ; ((file-readable-p (concat filename ".tex"))
2922 ; (concat filename ".tex"))
2923 ; ((file-readable-p filename)
2924 ; filename)
2925 ; (t (error "@include'd file %s not found"
2926 ; filename))))
2927 ; (texinfo-format-buffer-1))))
2928 ; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
2929 ; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
2930 ; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
2931 ; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
2932 ; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
2933 ; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
2934 ;
2935 ;(defun texinfo-subindex (indexvar file content)
2936 ; (set indexvar (cons (list 'recurse file content)
2937 ; (symbol-value indexvar))))
2938
2939 ; Second definition:
2940 ; (put 'include 'texinfo-format 'texinfo-format-include)
2941 ; (defun texinfo-format-include ()
2942 ; (let ((filename (concat input-directory
2943 ; (texinfo-parse-arg-discard)))
2944 ; (default-directory input-directory))
2945 ; (message "Reading: %s" filename)
2946 ; (save-excursion
2947 ; (save-restriction
2948 ; (narrow-to-region
2949 ; (point)
2950 ; (+ (point) (car (cdr (insert-file-contents filename)))))
2951 ; (goto-char (point-min))
2952 ; (texinfo-append-refill)
2953 ; (texinfo-format-convert (point-min) (point-max))))
2954 ; (setq last-input-buffer input-buffer) ; to bypass setfilename
2955 ; ))
2956
2957 \f
2958 ;;; Numerous commands do nothing in Texinfo
2959
2960 ;; These commands are defined in texinfo.tex for printed output.
2961
2962 (put 'bye 'texinfo-format 'texinfo-discard-line)
2963 (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
2964 (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
2965 (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
2966 (put 'finalout 'texinfo-format 'texinfo-discard-line)
2967 (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
2968 (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
2969 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
2970 (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
2971 (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
2972 (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
2973 (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
2974 (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
2975 (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
2976 (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
2977 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
2978 (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
2979 (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
2980 (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
2981 (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
2982 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
2983 (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
2984
2985 \f
2986 ;;; Some commands cannot be handled
2987
2988 (defun texinfo-unsupported ()
2989 (error "%s is not handled by texinfo"
2990 (buffer-substring texinfo-command-start texinfo-command-end)))
2991 \f
2992 ;;; Batch formatting
2993
2994 (defun batch-texinfo-format ()
2995 "Runs texinfo-format-buffer on the files remaining on the command line.
2996 Must be used only with -batch, and kills emacs on completion.
2997 Each file will be processed even if an error occurred previously.
2998 For example, invoke
2999 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
3000 (if (not noninteractive)
3001 (error "batch-texinfo-format may only be used -batch."))
3002 (let ((version-control t)
3003 (auto-save-default nil)
3004 (find-file-run-dired nil)
3005 (kept-old-versions 259259)
3006 (kept-new-versions 259259))
3007 (let ((error 0)
3008 file
3009 (files ()))
3010 (while command-line-args-left
3011 (setq file (expand-file-name (car command-line-args-left)))
3012 (cond ((not (file-exists-p file))
3013 (message ">> %s does not exist!" file)
3014 (setq error 1
3015 command-line-args-left (cdr command-line-args-left)))
3016 ((file-directory-p file)
3017 (setq command-line-args-left
3018 (nconc (directory-files file)
3019 (cdr command-line-args-left))))
3020 (t
3021 (setq files (cons file files)
3022 command-line-args-left (cdr command-line-args-left)))))
3023 (while files
3024 (setq file (car files)
3025 files (cdr files))
3026 (condition-case err
3027 (progn
3028 (if buffer-file-name (kill-buffer (current-buffer)))
3029 (find-file file)
3030 (buffer-disable-undo (current-buffer))
3031 (set-buffer-modified-p nil)
3032 (texinfo-mode)
3033 (message "texinfo formatting %s..." file)
3034 (texinfo-format-buffer nil)
3035 (if (buffer-modified-p)
3036 (progn (message "Saving modified %s" (buffer-file-name))
3037 (save-buffer))))
3038 (error
3039 (message ">> Error: %s" (prin1-to-string err))
3040 (message ">> point at")
3041 (let ((s (buffer-substring (point)
3042 (min (+ (point) 100)
3043 (point-max))))
3044 (tem 0))
3045 (while (setq tem (string-match "\n+" s tem))
3046 (setq s (concat (substring s 0 (match-beginning 0))
3047 "\n>> "
3048 (substring s (match-end 0)))
3049 tem (1+ tem)))
3050 (message ">> %s" s))
3051 (setq error 1))))
3052 (kill-emacs error))))
3053
3054 \f
3055 ;;; Place `provide' at end of file.
3056 (provide 'texinfmt)
3057
3058 ;;; texinfmt.el ends here.