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