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