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