*** empty log message ***
[bpt/emacs.git] / lisp / textmodes / texinfmt.el
CommitLineData
d501f516 1;;;; texinfmt.el --- convert Texinfo files to Info files.
4dd29d03 2
e5167999
ER
3;; Author: Robert J. Chassell <bob@gnu.ai.mit.edu>
4;; Version: 2.00
5;; Last-Modified: 14 Dec 1990
d7b4d18f 6;; Keywords: tex, help
4dd29d03
BP
7
8;; Copyright (C) 1985, 1986, 1988, 1990 Free Software Foundation, Inc.
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
e5167999 14;; the Free Software Foundation; either version 2, or (at your option)
4dd29d03
BP
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to
24;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
e5167999
ER
26;;; Commentary:
27
4dd29d03
BP
28;; Updated May 1990 to correspond, more or less, to version 2.8 of
29;; texinfo.tex. NOTE: texinfmt.el is being phased out; it is being
30;; replaced by makeinfo.c, which is faster and provides better error
31;; checking.
32;; Robert J. Chassell, bob@ai.mit.edu
33
e5167999
ER
34;;; Code:
35
4dd29d03
BP
36(defvar texinfo-format-syntax-table nil)
37
38(defvar texinfo-vindex)
39(defvar texinfo-findex)
40(defvar texinfo-cindex)
41(defvar texinfo-pindex)
42(defvar texinfo-tindex)
43(defvar texinfo-kindex)
44(defvar texinfo-last-node)
45(defvar texinfo-node-names)
46
47(if texinfo-format-syntax-table
48 nil
49 (setq texinfo-format-syntax-table (make-syntax-table))
50 (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
51 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
52 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
53 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
54 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
55 (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
56 (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
57 (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
58 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
59 (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
60 (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
61
f9f9507e 62;;;###autoload
4dd29d03
BP
63(defun texinfo-format-buffer (&optional notagify)
64 "Process the current buffer as texinfo code, into an Info file.
65The Info file output is generated in a buffer visiting the Info file
66names specified in the @setfilename command.
67
68Non-nil argument (prefix, if interactive) means don't make tag table
69and don't split the file if large. You can use Info-tagify and
70Info-split to do these manually."
71 (interactive "P")
72 (let ((lastmessage "Formatting Info file..."))
73 (message lastmessage)
74 (texinfo-format-buffer-1)
75 (if notagify
76 nil
77 (if (> (buffer-size) 30000)
78 (progn
79 (message (setq lastmessage "Making tags table for Info file..."))
80 (Info-tagify)))
81 (if (> (buffer-size) 100000)
82 (progn
83 (message (setq lastmessage "Splitting Info file..."))
84 (Info-split))))
85 (message (concat lastmessage
86 (if (interactive-p) "done. Now save it." "done.")))))
87
88\f
89(defun texinfo-format-buffer-1 ()
90 (let (texinfo-format-filename
91 texinfo-example-start
92 texinfo-command-start
93 texinfo-command-end
94 texinfo-command-name
95 texinfo-last-node
96 texinfo-vindex
97 texinfo-findex
98 texinfo-cindex
99 texinfo-pindex
100 texinfo-tindex
101 texinfo-kindex
102 texinfo-stack
103 texinfo-node-names
104 (texinfo-footnote-number 0)
105 last-input-buffer
106 outfile
107 (fill-column fill-column)
108 (input-buffer (current-buffer))
109 (input-directory default-directory))
110 (save-excursion
111 (goto-char (point-min))
112 (search-forward "@setfilename")
113 (setq texinfo-command-end (point))
114 (setq outfile (texinfo-parse-line-arg)))
115 (find-file outfile)
116 (texinfo-mode)
117 (set-syntax-table texinfo-format-syntax-table)
118 (erase-buffer)
119 (insert-buffer-substring input-buffer)
120 (goto-char (point-min))
121 (search-forward "@setfilename")
122 (beginning-of-line)
123 (delete-region (point-min) (point))
124 ;; Remove @bye at end of file, if it is there.
125 (goto-char (point-max))
126 (if (search-backward "@bye" nil t)
127 (delete-region (point) (point-max)))
128 ;; Make sure buffer ends in a newline.
129 (or (= (preceding-char) ?\n)
130 (insert "\n"))
131 ;; Scan the whole buffer, converting to Info format.
132 (texinfo-format-scan)
133 ;; Return data for indices.
134 (goto-char (point-min))
135 (list outfile
136 texinfo-vindex texinfo-findex texinfo-cindex
137 texinfo-pindex texinfo-tindex texinfo-kindex)))
138
139(defvar texinfo-region-buffer-name "*Info Region*"
140 "*Name of the temporary buffer used by \\[texinfo-format-region].")
141
f9f9507e 142;;;###autoload
4dd29d03
BP
143(defun texinfo-format-region (region-beginning region-ending)
144 "Convert the current region of the Texinfo file to Info format.
145This lets you see what that part of the file will look like in Info.
146The command is bound to \\[texinfo-format-region]. The text that is
147converted to Info is stored in a temporary buffer."
148 (interactive "r")
149 (message "Converting region to Info format...")
150 (let (texinfo-command-start
151 texinfo-command-end
152 texinfo-command-name
153 texinfo-vindex
154 texinfo-findex
155 texinfo-cindex
156 texinfo-pindex
157 texinfo-tindex
158 texinfo-kindex
159 texinfo-stack
160 texinfo-format-filename
161 texinfo-example-start
162 texinfo-last-node
163 texinfo-node-names
164 (texinfo-footnote-number 0)
165 last-input-buffer
166 (fill-column fill-column)
167 (input-buffer (current-buffer))
168 (input-directory default-directory)
169 filename-beginning
170 filename-ending)
171
172;;; Find a buffer to use.
173
174 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
175
176 ;; Insert the region into the buffer.
177 (erase-buffer)
178
179 (save-excursion
180 (set-buffer input-buffer)
181 (save-excursion
182 (save-restriction
183 (widen)
184 (goto-char (point-min))
185 ;; Initialize the buffer with the filename
186 ;; or else explain that a filename is needed.
187 (or (search-forward "@setfilename"
188 (save-excursion (forward-line 100) (point)) t)
189 (error "The texinfo file needs a line saying: @setfilename <name>"))
190 (beginning-of-line)
191 (setq filename-beginning (point))
192 (forward-line 1)
193 (setq filename-ending (point)))))
194
195 ;; Insert the @setfilename line into the buffer.
196 (insert-buffer-substring input-buffer
197 (min filename-beginning region-beginning)
198 filename-ending)
199
200 ;; Insert the region into the buffer.
201 (insert-buffer-substring input-buffer
202 (max region-beginning filename-ending)
203 region-ending)
204
205 (texinfo-mode)
206
207 ;; Install a syntax table useful for scanning command operands.
208 (set-syntax-table texinfo-format-syntax-table)
209
210 ;; If the region includes the effective end of the data,
211 ;; discard everything after that.
212 (goto-char (point-max))
213 (if (re-search-backward "^@bye" nil t)
214 (delete-region (point) (point-max)))
215 ;; Make sure buffer ends in a newline.
216 (or (= (preceding-char) ?\n)
217 (insert "\n"))
218
219 ;; Now convert for real.
220 (goto-char (point-min))
221 (texinfo-format-scan)
222 (goto-char (point-min)))
223
224 (message "Done."))
225
226\f
227;; Perform those texinfo-to-info conversions that apply to the whole input
228;; uniformly.
229(defun texinfo-format-scan ()
230 ;; Convert left and right quotes to typewriter font quotes.
231 (goto-char (point-min))
232 (while (search-forward "``" nil t)
233 (replace-match "\""))
234 (goto-char (point-min))
235 (while (search-forward "''" nil t)
236 (replace-match "\""))
237 ;; Scan for @-commands.
238 (goto-char (point-min))
239 (while (search-forward "@" nil t)
240 (if (looking-at "[@{}'` *]")
241 ;; Handle a few special @-followed-by-one-char commands.
242 (if (= (following-char) ?*)
243 (progn
244 ;; remove command
245 (delete-region (1- (point)) (1+ (point)))
246 ;; insert return if not at end of line;
247 ;; else line is already broken.
248 (if (not (= (following-char) ?\n))
249 (insert ?\n)))
250 ;; The other characters are simply quoted. Delete the @.
251 (delete-char -1)
252 (forward-char 1))
253 ;; @ is followed by a command-word; find the end of the word.
254 (setq texinfo-command-start (1- (point)))
255 (if (= (char-syntax (following-char)) ?w)
256 (forward-word 1)
257 (forward-char 1))
258 (setq texinfo-command-end (point))
259 ;; Call the handler for this command.
260 (setq texinfo-command-name
261 (intern (buffer-substring (1+ texinfo-command-start)
262 texinfo-command-end)))
263 (let ((cmd (get texinfo-command-name 'texinfo-format)))
264 (if cmd (funcall cmd)
265 (texinfo-unsupported)))))
266 (cond (texinfo-stack
267 (goto-char (nth 2 (car texinfo-stack)))
268 (error "Unterminated @%s" (car (car texinfo-stack))))))
269
270(put 'begin 'texinfo-format 'texinfo-format-begin)
271(defun texinfo-format-begin ()
272 (texinfo-format-begin-end 'texinfo-format))
273
274(put 'end 'texinfo-format 'texinfo-format-end)
275(defun texinfo-format-end ()
276 (texinfo-format-begin-end 'texinfo-end))
277
278(defun texinfo-format-begin-end (prop)
279 (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
280 (setq cmd (get texinfo-command-name prop))
281 (if cmd (funcall cmd)
282 (texinfo-unsupported)))
283\f
284(defun texinfo-parse-line-arg ()
285 (goto-char texinfo-command-end)
286 (let ((start (point)))
287 (cond ((looking-at " ")
288 (skip-chars-forward " ")
289 (setq start (point))
290 (end-of-line)
291 (skip-chars-backward " ")
292 (setq texinfo-command-end (1+ (point))))
293 ((looking-at "{")
294 (setq start (1+ (point)))
295 (forward-list 1)
296 (setq texinfo-command-end (point))
297 (forward-char -1))
298 (t
299 (error "Invalid texinfo command arg format")))
300 (prog1 (buffer-substring start (point))
301 (if (eolp) (forward-char 1)))))
302
303(defun texinfo-parse-expanded-arg ()
304 (goto-char texinfo-command-end)
305 (let ((start (point))
306 marker)
307 (cond ((looking-at " ")
308 (skip-chars-forward " ")
309 (setq start (point))
310 (end-of-line)
311 (setq texinfo-command-end (1+ (point))))
312 ((looking-at "{")
313 (setq start (1+ (point)))
314 (forward-list 1)
315 (setq texinfo-command-end (point))
316 (forward-char -1))
317 (t
318 (error "Invalid texinfo command arg format")))
319 (setq marker (move-marker (make-marker) texinfo-command-end))
320 (texinfo-format-expand-region start (point))
321 (setq texinfo-command-end (marker-position marker))
322 (move-marker marker nil)
323 (prog1 (buffer-substring start (point))
324 (if (eolp) (forward-char 1)))))
325
326(defun texinfo-format-expand-region (start end)
327 (save-restriction
328 (narrow-to-region start end)
329 (let (texinfo-command-start
330 texinfo-command-end
331 texinfo-command-name
332 texinfo-stack)
333 (texinfo-format-scan))
334 (goto-char (point-max))))
335
336(defun texinfo-parse-arg-discard ()
337 (prog1 (texinfo-parse-line-arg)
338 (texinfo-discard-command)))
339
340(defun texinfo-discard-command ()
341 (delete-region texinfo-command-start texinfo-command-end))
342
343(defun texinfo-optional-braces-discard ()
344 "Discard braces following command, if any."
345 (goto-char texinfo-command-end)
346 (let ((start (point)))
347 (cond ((looking-at "[ \t]*\n")) ; do nothing
348 ((looking-at "{") ; remove braces, if any
349 (forward-list 1)
350 (setq texinfo-command-end (point)))
351 (t
352 (error
353 "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
354 (delete-region texinfo-command-start texinfo-command-end)))
355
356(defun texinfo-format-parse-line-args ()
357 (let ((start (1- (point)))
358 next beg end
359 args)
360 (skip-chars-forward " ")
361 (while (not (eolp))
362 (setq beg (point))
363 (re-search-forward "[\n,]")
364 (setq next (point))
365 (if (bolp) (setq next (1- next)))
366 (forward-char -1)
367 (skip-chars-backward " ")
368 (setq end (point))
369 (setq args (cons (if (> end beg) (buffer-substring beg end))
370 args))
371 (goto-char next)
372 (skip-chars-forward " "))
373 (if (eolp) (forward-char 1))
374 (setq texinfo-command-end (point))
375 (nreverse args)))
376
377(defun texinfo-format-parse-args ()
378 (let ((start (1- (point)))
379 next beg end
380 args)
381 (search-forward "{")
382 (save-excursion
383 (texinfo-format-expand-region
384 (point)
385 (save-excursion (up-list 1) (1- (point)))))
386 (while (/= (preceding-char) ?\})
387 (skip-chars-forward " \t\n")
388 (setq beg (point))
389 (re-search-forward "[},]")
390 (setq next (point))
391 (forward-char -1)
392 (skip-chars-backward " \t\n")
393 (setq end (point))
394 (cond ((< beg end)
395 (goto-char beg)
396 (while (search-forward "\n" end t)
397 (replace-match " "))))
398 (setq args (cons (if (> end beg) (buffer-substring beg end))
399 args))
400 (goto-char next))
401 (if (eolp) (forward-char 1))
402 (setq texinfo-command-end (point))
403 (nreverse args)))
404
405(defun texinfo-format-parse-defun-args ()
406 (goto-char texinfo-command-end)
407 (let ((start (point)))
408 (end-of-line)
409 (setq texinfo-command-end (1+ (point)))
410 (let ((marker (move-marker (make-marker) texinfo-command-end)))
411 (texinfo-format-expand-region start (point))
412 (setq texinfo-command-end (marker-position marker))
413 (move-marker marker nil))
414 (goto-char start)
415 (let ((args '())
416 beg end)
417 (skip-chars-forward " ")
418 (while (not (eolp))
419 (cond ((looking-at "{")
420 (setq beg (1+ (point)))
421 (forward-list 1)
422 (setq end (1- (point))))
423 (t
424 (setq beg (point))
425 (re-search-forward "[\n ]")
426 (forward-char -1)
427 (setq end (point))))
428 (setq args (cons (buffer-substring beg end) args))
429 (skip-chars-forward " "))
430 (forward-char 1)
431 (nreverse args))))
432\f
433
434; 19 October 1990
435; @setfilename modifed to work with include files; see @include
436; (defun texinfo-format-setfilename ()
437; (let ((arg (texinfo-parse-arg-discard)))
438; (setq texinfo-format-filename
439; (file-name-nondirectory (expand-file-name arg)))
440; (insert "Info file: "
441; texinfo-format-filename ", -*-Text-*-\n"
442; "produced by texinfo-format-buffer\nfrom "
443; (if (buffer-file-name input-buffer)
444; (concat "file: "
445; (file-name-sans-versions
446; (file-name-nondirectory
447; (buffer-file-name input-buffer))))
448; (concat "buffer " (buffer-name input-buffer)))
449; "\n\n")))
450
451(put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
452(defun texinfo-format-setfilename ()
453 (let ((arg (texinfo-parse-arg-discard)))
454 (if (eq input-buffer last-input-buffer)
455 nil ; only use first setfilename in buffer
456 (message "Formatting Info file: %s" arg)
457 (setq texinfo-format-filename
458 (file-name-nondirectory (expand-file-name arg)))
459 (insert "Info file: "
460 texinfo-format-filename ", -*-Text-*-\n"
461 "produced by texinfo-format-buffer\nfrom "
462 (if (buffer-file-name input-buffer)
463 (concat "file: "
464 (file-name-sans-versions
465 (file-name-nondirectory
466 (buffer-file-name input-buffer))))
467 (concat "buffer " (buffer-name input-buffer)))
468 "\n\n"))))
469
470(put 'node 'texinfo-format 'texinfo-format-node)
471(defun texinfo-format-node ()
472 (let* ((args (texinfo-format-parse-line-args))
473 (name (nth 0 args))
474 (next (nth 1 args))
475 (prev (nth 2 args))
476 (up (nth 3 args)))
477 (texinfo-discard-command)
478 (setq texinfo-last-node name)
479 (let ((tem (downcase name)))
480 (if (assoc tem texinfo-node-names)
481 (error "Duplicate node name: %s" name)
482 (setq texinfo-node-names (cons (list tem) texinfo-node-names))))
483 (setq texinfo-footnote-number 0)
484 (or (bolp)
485 (insert ?\n))
486 (insert "\^_\nFile: " texinfo-format-filename
487 " Node: " name)
488 (if prev
489 (insert ", Prev: " prev))
490 (if up
491 (insert ", Up: " up))
492 (if next
493 (insert ", Next: " next))
494 (insert ?\n)))
495
496(put 'menu 'texinfo-format 'texinfo-format-menu)
497(defun texinfo-format-menu ()
498 (texinfo-discard-line)
499 (insert "* Menu:\n\n"))
500
501(put 'menu 'texinfo-end 'texinfo-discard-command)
502(defun texinfo-discard-line ()
503 (goto-char texinfo-command-end)
504 (skip-chars-forward " \t")
505 (or (eolp)
506 (error "Extraneous text at end of command line."))
507 (goto-char texinfo-command-start)
508 (or (bolp)
509 (error "Extraneous text at beginning of command line."))
510 (delete-region (point) (progn (forward-line 1) (point))))
511
512; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
513; -> *Note FNAME: (FILE)NODE
514; If FILE is missing,
515; *Note FNAME: NODE
516; If FNAME is empty and NAME is present
517; *Note NAME: Node
518; If both NAME and FNAME are missing
519; *Note NODE::
520; texinfo ignores the DOCUMENT argument.
521; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
522; If FILE is specified, (FILE)NODE is used for xrefs.
523; If fifth argument DOCUMENT is specified, produces
524; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
525; of DOCUMENT
526
527; @ref a reference that does not put `See' or `see' in
528; the hardcopy and is the same as @xref in Info
529(put 'ref 'texinfo-format 'texinfo-format-xref)
530
531(put 'xref 'texinfo-format 'texinfo-format-xref)
532(defun texinfo-format-xref ()
533 (let ((args (texinfo-format-parse-args)))
534 (texinfo-discard-command)
535 (insert "*Note ")
536 (let ((fname (or (nth 1 args) (nth 2 args))))
537 (if (null (or fname (nth 3 args)))
538 (insert (car args) "::")
539 (insert (or fname (car args)) ": ")
540 (if (nth 3 args)
541 (insert "(" (nth 3 args) ")"))
542 (insert (car args))))))
543
544(put 'pxref 'texinfo-format 'texinfo-format-pxref)
545(defun texinfo-format-pxref ()
546 (texinfo-format-xref)
547 (or (save-excursion
548 (forward-char -2)
549 (looking-at "::"))
550 (insert ".")))
551
552;@inforef{NODE, FNAME, FILE}
553;Like @xref{NODE, FNAME,,FILE} in texinfo.
554;In Tex, generates "See Info file FILE, node NODE"
555(put 'inforef 'texinfo-format 'texinfo-format-inforef)
556(defun texinfo-format-inforef ()
557 (let ((args (texinfo-format-parse-args)))
558 (texinfo-discard-command)
559 (if (nth 1 args)
560 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
561 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
562
563(put 'chapheading 'texinfo-format 'texinfo-format-chapter)
564(put 'ichapter 'texinfo-format 'texinfo-format-chapter)
565(put 'chapter 'texinfo-format 'texinfo-format-chapter)
566(put 'iappendix 'texinfo-format 'texinfo-format-chapter)
567(put 'appendix 'texinfo-format 'texinfo-format-chapter)
568(put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
569(put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
570(defun texinfo-format-chapter ()
571 (texinfo-format-chapter-1 ?*))
572
573(put 'heading 'texinfo-format 'texinfo-format-section)
574(put 'isection 'texinfo-format 'texinfo-format-section)
575(put 'section 'texinfo-format 'texinfo-format-section)
576(put 'iappendixsection 'texinfo-format 'texinfo-format-section)
577(put 'appendixsection 'texinfo-format 'texinfo-format-section)
578(put 'iappendixsec 'texinfo-format 'texinfo-format-section)
579(put 'appendixsec 'texinfo-format 'texinfo-format-section)
580(put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
581(put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
582(defun texinfo-format-section ()
583 (texinfo-format-chapter-1 ?=))
584
585(put 'subheading 'texinfo-format 'texinfo-format-subsection)
586(put 'isubsection 'texinfo-format 'texinfo-format-subsection)
587(put 'subsection 'texinfo-format 'texinfo-format-subsection)
588(put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
589(put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
590(put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
591(put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
592(defun texinfo-format-subsection ()
593 (texinfo-format-chapter-1 ?-))
594
595(put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
596(put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
597(put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
598(put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
599(put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
600(put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
601(put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
602(defun texinfo-format-subsubsection ()
603 (texinfo-format-chapter-1 ?.))
604
605(defun texinfo-format-chapter-1 (belowchar)
606 (let ((arg (texinfo-parse-arg-discard)))
607 (message "Formatting: %s ... " arg) ; So we can see where we are.
608 (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
609 (forward-line -2)))
610
611(put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
612(defun texinfo-format-sectionpad ()
613 (let ((str (texinfo-parse-arg-discard)))
614 (forward-char -1)
615 (let ((column (current-column)))
616 (forward-char 1)
617 (while (> column 0)
618 (insert str)
619 (setq column (1- column))))
620 (insert ?\n)))
621
622(put '\. 'texinfo-format 'texinfo-format-\.)
623(defun texinfo-format-\. ()
624 (texinfo-discard-command)
625 (insert "."))
626
627(put '\: 'texinfo-format 'texinfo-format-\:)
628(defun texinfo-format-\: ()
629 (texinfo-discard-command))
630
631(put 'center 'texinfo-format 'texinfo-format-center)
632(defun texinfo-format-center ()
633 (texinfo-discard-command)
634 (let ((indent-tabs-mode nil))
635 (center-line)))
636
637(put 'sp 'texinfo-format 'texinfo-format-sp)
638(defun texinfo-format-sp ()
639 (let* ((arg (texinfo-parse-arg-discard))
640 (num (read arg)))
641 (insert-char ?\n num)))
642
643(put 'br 'texinfo-format 'texinfo-format-paragraph-break)
644(defun texinfo-format-paragraph-break ()
645 "Force a paragraph break.
646If used within a line, follow `@br' with braces."
647 (texinfo-optional-braces-discard)
648 ;; insert one return if at end of line;
649 ;; else insert two returns, to generate a blank line.
650 (if (= (following-char) ?\n)
651 (insert ?\n)
652 (insert-char ?\n 2)))
653
654\f
655;;; @footnote
656
657; In Texinfo, footnotes are created with the `@footnote' command.
658; This command is followed immediately by a left brace, then by the text of
659; the footnote, and then by a terminating right brace. The
660; template for a footnote is:
661;
662; @footnote{TEXT}
663;
664; Info has two footnote styles:
665;
666; `End Node'
667; In the "End Node" style, all the footnotes for a single node
668; are placed at the end of that node. The footnotes are
669; separated from the rest of the node by a line of dashes with
670; the word `Footnotes' within it.
671;
672; `Make Node'
673; In the "Make Node" style, all the footnotes for a single node are
674; placed in an automatically constructed node of their own.
675
676(put 'footnote 'texinfo-format 'texinfo-format-footnote)
677
678(defvar texinfo-footnote-style 'MN "\
679*Footnote style, either EN for end node or MN for make node.")
680
681(defvar texinfo-footnote-number)
682
683(defun texinfo-format-footnote ()
684 "Format a footnote in either `end node' or `make node' style.
685The texinfo-footnote-style variable controls which style is used."
686 (setq texinfo-footnote-number (1+ texinfo-footnote-number))
687 (cond ((eq texinfo-footnote-style 'EN) (texinfo-format-end-node))
688 ((eq texinfo-footnote-style 'MN) (texinfo-format-make-node))))
689
690(defun texinfo-format-make-node ()
691 "Format footnote in `MN', Make Node, style with notes in own node.
692The node is constructed automatically."
693 (let* (start
694 (arg (texinfo-parse-expanded-arg))
695 (node-name-beginning
696 (save-excursion
697 (re-search-backward
698 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\)*[ \t]+Node:")
699 (match-end 0)))
700 (node-name
701 (save-excursion
702 (buffer-substring
703 (progn (goto-char node-name-beginning) ; skip over node command
704 (skip-chars-forward " \t") ; and over spaces
705 (point))
706 (if (search-forward
707 ","
708 (save-excursion (end-of-line) (point)) t) ; bound search
709 (1- (point))
710 (end-of-line) (point))))))
711 (texinfo-discard-command)
712 (insert (format "(%d) (*note %s-Footnotes::)"
713 texinfo-footnote-number node-name))
714 (fill-paragraph nil)
715 (save-excursion
716 (if (re-search-forward "^@node" nil 'move)
717 (forward-line -1))
718
719 ;; two cases: for the first footnote, we must insert a node header;
720 ;; for the second and subsequent footnotes, we need only insert
721 ;; the text of the footnote.
722
723 (if (save-excursion
724 (re-search-backward
725 (concat node-name "-Footnotes, Up: ")
726 node-name-beginning
727 t))
728 (progn ; already at least one footnote
729 (setq start (point))
730 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
731 (fill-region start (point)))
732 ;; else not yet a footnote
733 (insert "\n\^_\nFile: " texinfo-format-filename
734 " Node: " node-name "-Footnotes, Up: " node-name "\n")
735 (setq start (point))
736 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
737 (fill-region start (point))))))
738
739(defun texinfo-format-end-node ()
740 "Format footnote in `EN', End Node, style with notes at end of node."
741 (let (start
742 (arg (texinfo-parse-expanded-arg)))
743 (texinfo-discard-command)
744 (insert (format "(%d) " texinfo-footnote-number))
745 (fill-paragraph nil)
746 (save-excursion
747 (if (search-forward "\n--------- Footnotes ---------\n" nil t)
748 (progn ; already have footnote, put new one before end of node
749 (if (re-search-forward "^@node" nil 'move)
750 (forward-line -1))
751 (setq start (point))
752 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
753 (fill-region start (point)))
754 ;; else no prior footnote
755 (if (re-search-forward "^@node" nil 'move)
756 (forward-line -1))
757 (insert "\n--------- Footnotes ---------\n")
758 (setq start (point))
759 (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
760 (fill-region start (point))))))
761
762\f
763;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
764;; @enumerate pushes (enumerate 0 STARTPOS).
765;; @item dispatches to the texinfo-item prop of the first elt of the list.
766;; For itemize, this puts in and rescans the COMMANDS.
767;; For enumerate, this increments the number and puts it in.
768;; In either case, it puts a Backspace at the front of the line
769;; which marks it not to be indented later.
770;; All other lines get indented by 5 when the @end is reached.
771
772(defun texinfo-push-stack (check arg)
773 (setq texinfo-stack
774 (cons (list check arg texinfo-command-start)
775 texinfo-stack)))
776
777(defun texinfo-pop-stack (check)
778 (if (null texinfo-stack)
779 (error "Unmatched @end %s" check))
780 (if (not (eq (car (car texinfo-stack)) check))
781 (error "@end %s matches @%s"
782 check (car (car texinfo-stack))))
783 (prog1 (cdr (car texinfo-stack))
784 (setq texinfo-stack (cdr texinfo-stack))))
785
786(put 'itemize 'texinfo-format 'texinfo-itemize)
787(defun texinfo-itemize ()
788 (texinfo-push-stack 'itemize (texinfo-parse-arg-discard))
789 (setq fill-column (- fill-column 5)))
790
791(put 'itemize 'texinfo-end 'texinfo-end-itemize)
792(defun texinfo-end-itemize ()
793 (setq fill-column (+ fill-column 5))
794 (texinfo-discard-command)
795 (let ((stacktop
796 (texinfo-pop-stack 'itemize)))
797 (texinfo-do-itemize (nth 1 stacktop))))
798
799(put 'enumerate 'texinfo-format 'texinfo-enumerate)
800(defun texinfo-enumerate ()
801 (texinfo-push-stack 'enumerate 0)
802 (setq fill-column (- fill-column 5))
803 (texinfo-discard-line))
804
805(put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
806(defun texinfo-end-enumerate ()
807 (setq fill-column (+ fill-column 5))
808 (texinfo-discard-command)
809 (let ((stacktop
810 (texinfo-pop-stack 'enumerate)))
811 (texinfo-do-itemize (nth 1 stacktop))))
812
813(put 'table 'texinfo-format 'texinfo-table)
814(defun texinfo-table ()
815 (texinfo-push-stack 'table (texinfo-parse-arg-discard))
816 (setq fill-column (- fill-column 5)))
817
818(put 'ftable 'texinfo-format 'texinfo-ftable)
819(defun texinfo-ftable ()
820 (texinfo-push-stack 'table "@code")
821 (setq fill-column (- fill-column 5))
822 (texinfo-discard-line))
823
824(put 'description 'texinfo-format 'texinfo-description)
825(defun texinfo-description ()
826 (texinfo-push-stack 'table "@asis")
827 (setq fill-column (- fill-column 5))
828 (texinfo-discard-line))
829
830(put 'table 'texinfo-end 'texinfo-end-table)
831(put 'ftable 'texinfo-end 'texinfo-end-table)
832(put 'description 'texinfo-end 'texinfo-end-table)
833(defun texinfo-end-table ()
834 (setq fill-column (+ fill-column 5))
835 (texinfo-discard-command)
836 (let ((stacktop
837 (texinfo-pop-stack 'table)))
838 (texinfo-do-itemize (nth 1 stacktop))))
839
840;; At the @end, indent all the lines within the construct
841;; except those marked with backspace. FROM says where
842;; construct started.
843(defun texinfo-do-itemize (from)
844 (save-excursion
845 (while (progn (forward-line -1)
846 (>= (point) from))
847 (if (= (following-char) ?\b)
848 (save-excursion
849 (delete-char 1)
850 (end-of-line)
851 (delete-char 6))
852 (if (not (looking-at "[ \t]*$"))
853 (save-excursion (insert " ")))))))
854
855(put 'item 'texinfo-format 'texinfo-item)
856(put 'itemx 'texinfo-format 'texinfo-item)
857(defun texinfo-item ()
858 (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
859
860(put 'itemize 'texinfo-item 'texinfo-itemize-item)
861(defun texinfo-itemize-item ()
862 (texinfo-discard-line)
863 (insert "\b " (nth 1 (car texinfo-stack)) " \n")
864 (forward-line -1))
865
866(put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
867(defun texinfo-enumerate-item ()
868 (texinfo-discard-line)
869 (let ((next (1+ (car (cdr (car texinfo-stack))))))
870 (setcar (cdr (car texinfo-stack)) next)
871 (insert ?\b (format "%3d. " next) ?\n))
872 (forward-line -1))
873
874(put 'table 'texinfo-item 'texinfo-table-item)
875(defun texinfo-table-item ()
876 (let ((arg (texinfo-parse-arg-discard))
877 (itemfont (car (cdr (car texinfo-stack)))))
878 (insert ?\b itemfont ?\{ arg "}\n \n"))
879 (forward-line -2))
880
881\f
882; @ftable
883
884; The `@ftable' command is like the `@table' command but it also
885; inserts each item in the first column into the function index.
886
887(put 'ftable 'texinfo-format 'texinfo-ftable)
888
889; The following function presumes that the first column of the table
890; should be in `@code' font; but the texinfo.tex source does not
891; presume this.
892; (defun texinfo-ftable ()
893; (texinfo-push-stack 'ftable "@code")
894; (setq fill-column (- fill-column 5))
895; (texinfo-discard-line))
896
897(defun texinfo-ftable ()
898 (texinfo-push-stack 'ftable (texinfo-parse-arg-discard))
899 (setq fill-column (- fill-column 5)))
900
901(put 'ftable 'texinfo-item 'texinfo-ftable-item)
902(defun texinfo-ftable-item ()
903 (let ((item (texinfo-parse-arg-discard))
904 (itemfont (car (cdr (car texinfo-stack))))
905 (indexvar 'texinfo-findex))
906 (insert ?\b itemfont ?\{ item "}\n \n")
907 (set indexvar
908 (cons
909 (list item texinfo-last-node)
910 (symbol-value indexvar)))
911 (forward-line -2)))
912
913(put 'ftable 'texinfo-end 'texinfo-end-ftable)
914(defun texinfo-end-ftable ()
915 (setq fill-column (+ fill-column 5))
916 (texinfo-discard-command)
917 (let ((stacktop
918 (texinfo-pop-stack 'ftable)))
919 (texinfo-do-itemize (nth 1 stacktop))))
920
921\f
922(put 'ifinfo 'texinfo-format 'texinfo-discard-line)
923(put 'ifinfo 'texinfo-end 'texinfo-discard-command)
924
925(put 'iftex 'texinfo-format 'texinfo-format-iftex)
926(defun texinfo-format-iftex ()
927 (delete-region texinfo-command-start
928 (progn (re-search-forward "@end iftex\n")
929 (point))))
930
931(put 'tex 'texinfo-format 'texinfo-format-tex)
932(defun texinfo-format-tex ()
933 (delete-region texinfo-command-start
934 (progn (re-search-forward "@end tex\n")
935 (point))))
936
937(put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
938(defun texinfo-format-titlepage ()
939 (delete-region texinfo-command-start
940 (progn (search-forward "@end titlepage\n")
941 (point))))
942
943(put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
944
945; @titlespec an alternative titling command; ignored by Info
946
947(put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
948(defun texinfo-format-titlespec ()
949 (delete-region texinfo-command-start
950 (progn (search-forward "@end titlespec\n")
951 (point))))
952
953(put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
954
955; @today{}
956
957(put 'today 'texinfo-format 'texinfo-format-today)
958
959; Produces Day Month Year style of output. eg `1 Jan 1900'
960; The `@today{}' command requires a pair of braces, like `@dots{}'.
961(defun texinfo-format-today ()
962 (texinfo-parse-arg-discard)
963 (insert (format "%s %s %s"
964 (substring (current-time-string) 8 10)
965 (substring (current-time-string) 4 7)
966 (substring (current-time-string) -4))))
967
968
969(put 'ignore 'texinfo-format 'texinfo-format-ignore)
970(defun texinfo-format-ignore ()
971 (delete-region texinfo-command-start
972 (progn (search-forward "@end ignore\n")
973 (point))))
974
975(put 'endignore 'texinfo-format 'texinfo-discard-line)
976
977(put 'var 'texinfo-format 'texinfo-format-var)
978; @sc a small caps font for TeX; formatted as `var' in Info
979(put 'sc 'texinfo-format 'texinfo-format-var)
980(defun texinfo-format-var ()
981 (insert (upcase (texinfo-parse-arg-discard)))
982 (goto-char texinfo-command-start))
983
984; various noops
985
986(put 'asis 'texinfo-format 'texinfo-format-noop)
987(put 'b 'texinfo-format 'texinfo-format-noop)
988(put 't 'texinfo-format 'texinfo-format-noop)
989(put 'i 'texinfo-format 'texinfo-format-noop)
990(put 'r 'texinfo-format 'texinfo-format-noop)
991(put 'titlefont 'texinfo-format 'texinfo-format-noop)
992(put 'key 'texinfo-format 'texinfo-format-noop)
993(put 'w 'texinfo-format 'texinfo-format-noop)
994(defun texinfo-format-noop ()
995 (insert (texinfo-parse-arg-discard))
996 (goto-char texinfo-command-start))
997
998(put 'code 'texinfo-format 'texinfo-format-code)
999(put 'samp 'texinfo-format 'texinfo-format-code)
1000(put 'file 'texinfo-format 'texinfo-format-code)
1001(put 'kbd 'texinfo-format 'texinfo-format-code)
1002(put 'cite 'texinfo-format 'texinfo-format-code)
1003(defun texinfo-format-code ()
1004 (insert "`" (texinfo-parse-arg-discard) "'")
1005 (goto-char texinfo-command-start))
1006
1007(put 'emph 'texinfo-format 'texinfo-format-emph)
1008(put 'strong 'texinfo-format 'texinfo-format-emph)
1009(defun texinfo-format-emph ()
1010 (insert "*" (texinfo-parse-arg-discard) "*")
1011 (goto-char texinfo-command-start))
1012
1013(put 'defn 'texinfo-format 'texinfo-format-defn)
1014(put 'dfn 'texinfo-format 'texinfo-format-defn)
1015(defun texinfo-format-defn ()
1016 (insert "\"" (texinfo-parse-arg-discard) "\"")
1017 (goto-char texinfo-command-start))
1018
1019(put 'bullet 'texinfo-format 'texinfo-format-bullet)
1020(defun texinfo-format-bullet ()
1021 "Insert an asterisk.
1022If used within a line, follow `@bullet' with braces."
1023 (texinfo-optional-braces-discard)
1024 (insert "*"))
1025
1026(put 'smallexample 'texinfo-format 'texinfo-format-example)
1027(put 'smalllisp 'texinfo-format 'texinfo-format-example)
1028(put 'example 'texinfo-format 'texinfo-format-example)
1029(put 'quotation 'texinfo-format 'texinfo-format-example)
1030(put 'lisp 'texinfo-format 'texinfo-format-example)
1031(put 'display 'texinfo-format 'texinfo-format-example)
1032(put 'format 'texinfo-format 'texinfo-format-example)
1033(put 'flushleft 'texinfo-format 'texinfo-format-example)
1034(defun texinfo-format-example ()
1035 (texinfo-push-stack 'example nil)
1036 (setq fill-column (- fill-column 5))
1037 (texinfo-discard-line))
1038
1039(put 'smallexample 'texinfo-end 'texinfo-end-example)
1040(put 'example 'texinfo-end 'texinfo-end-example)
1041(put 'quotation 'texinfo-end 'texinfo-end-example)
1042(put 'lisp 'texinfo-end 'texinfo-end-example)
1043(put 'display 'texinfo-end 'texinfo-end-example)
1044(put 'format 'texinfo-end 'texinfo-end-example)
1045(put 'flushleft 'texinfo-end 'texinfo-end-example)
1046(defun texinfo-end-example ()
1047 (setq fill-column (+ fill-column 5))
1048 (texinfo-discard-command)
1049 (let ((stacktop
1050 (texinfo-pop-stack 'example)))
1051 (texinfo-do-itemize (nth 1 stacktop))))
1052
1053(put 'exdent 'texinfo-format 'texinfo-format-exdent)
1054(defun texinfo-format-exdent ()
1055 (texinfo-discard-command)
1056 (delete-region (point)
1057 (progn
1058 (skip-chars-forward " ")
1059 (point)))
1060 (insert ?\b)
1061 ;; Cancel out the deletion that texinfo-do-itemize
1062 ;; is going to do at the end of this line.
1063 (save-excursion
1064 (end-of-line)
1065 (insert "\n ")))
1066
1067\f
1068;; @flushright ... @end flushright
1069
1070; The @flushright command right justifies every line but leaves the
1071; left end ragged.
1072
1073(put 'flushright 'texinfo-format 'texinfo-format-flushright)
1074(defun texinfo-format-flushright ()
1075 (texinfo-push-stack 'flushright nil)
1076 (texinfo-discard-line))
1077
1078(put 'flushright 'texinfo-end 'texinfo-end-flushright)
1079(defun texinfo-end-flushright ()
1080 (texinfo-discard-command)
1081
1082 (let ((stacktop
1083 (texinfo-pop-stack 'flushright)))
1084
1085 (texinfo-do-flushright (nth 1 stacktop))))
1086
1087(defun texinfo-do-flushright (from)
1088 (save-excursion
1089 (while (progn (forward-line -1)
1090 (>= (point) from))
1091
1092 (beginning-of-line)
1093 (insert
1094 (make-string
1095 (- fill-column
1096 (save-excursion
1097 (end-of-line)
1098 (current-column)))
1099 ? )))))
1100
1101\f
1102(put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
1103(defun texinfo-format-ctrl ()
1104 (let ((str (texinfo-parse-arg-discard)))
1105 (insert (logand 31 (aref str 0)))))
1106
1107(put 'TeX 'texinfo-format 'texinfo-format-TeX)
1108(defun texinfo-format-TeX ()
1109 (texinfo-parse-arg-discard)
1110 (insert "TeX"))
1111
1112(put 'copyright 'texinfo-format 'texinfo-format-copyright)
1113(defun texinfo-format-copyright ()
1114 (texinfo-parse-arg-discard)
1115 (insert "(C)"))
1116
1117(put 'minus 'texinfo-format 'texinfo-format-minus)
1118(defun texinfo-format-minus ()
1119 "Insert a minus sign.
1120If used within a line, follow `@minus' with braces."
1121 (texinfo-optional-braces-discard)
1122 (insert "-"))
1123
1124(put 'dots 'texinfo-format 'texinfo-format-dots)
1125(defun texinfo-format-dots ()
1126 (texinfo-parse-arg-discard)
1127 (insert "..."))
1128
1129(put 'refill 'texinfo-format 'texinfo-format-refill)
1130(defun texinfo-format-refill ()
1131 (texinfo-discard-command)
1132 (fill-paragraph nil))
1133
1134\f
1135;;; Index generation
1136
1137(put 'vindex 'texinfo-format 'texinfo-format-vindex)
1138(defun texinfo-format-vindex ()
1139 (texinfo-index 'texinfo-vindex))
1140
1141(put 'cindex 'texinfo-format 'texinfo-format-cindex)
1142(defun texinfo-format-cindex ()
1143 (texinfo-index 'texinfo-cindex))
1144
1145(put 'findex 'texinfo-format 'texinfo-format-findex)
1146(defun texinfo-format-findex ()
1147 (texinfo-index 'texinfo-findex))
1148
1149(put 'pindex 'texinfo-format 'texinfo-format-pindex)
1150(defun texinfo-format-pindex ()
1151 (texinfo-index 'texinfo-pindex))
1152
1153(put 'tindex 'texinfo-format 'texinfo-format-tindex)
1154(defun texinfo-format-tindex ()
1155 (texinfo-index 'texinfo-tindex))
1156
1157(put 'kindex 'texinfo-format 'texinfo-format-kindex)
1158(defun texinfo-format-kindex ()
1159 (texinfo-index 'texinfo-kindex))
1160
1161(defun texinfo-index (indexvar)
1162 (let ((arg (texinfo-parse-expanded-arg)))
1163 (texinfo-discard-command)
1164 (set indexvar
1165 (cons (list arg texinfo-last-node)
1166 (symbol-value indexvar)))))
1167
1168(defconst texinfo-indexvar-alist
1169 '(("cp" . texinfo-cindex)
1170 ("fn" . texinfo-findex)
1171 ("vr" . texinfo-vindex)
1172 ("tp" . texinfo-tindex)
1173 ("pg" . texinfo-pindex)
1174 ("ky" . texinfo-kindex)))
1175
1176\f
1177;;; @defindex @defcodeindex
1178(put 'defindex 'texinfo-format 'texinfo-format-defindex)
1179(put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
1180
1181(defun texinfo-format-defindex ()
1182 (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
1183 (indexing-command (intern (concat index-name "index")))
1184 (index-formatting-command ; eg: `texinfo-format-aaindex'
1185 (intern (concat "texinfo-format-" index-name "index")))
1186 (index-alist-name ; eg: `texinfo-aaindex'
1187 (intern (concat "texinfo-" index-name "index"))))
1188
1189 (set index-alist-name nil)
1190
1191 (put indexing-command ; eg, aaindex
1192 'texinfo-format
1193 index-formatting-command) ; eg, texinfo-format-aaindex
1194
1195 ;; eg: "aa" . texinfo-aaindex
1196 (or (assoc index-name texinfo-indexvar-alist)
1197 (setq texinfo-indexvar-alist
1198 (cons
1199 (cons index-name
1200 index-alist-name)
1201 texinfo-indexvar-alist)))
1202
1203 (fset index-formatting-command
1204 (list 'lambda 'nil
1205 (list 'texinfo-index
1206 (list 'quote index-alist-name))))))
1207
1208\f
1209;;; @synindex @syncodeindex
1210
1211(put 'synindex 'texinfo-format 'texinfo-format-synindex)
1212(put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
1213
1214(defun texinfo-format-synindex ()
1215 (let* ((args (texinfo-parse-arg-discard))
1216 (second (cdr (read-from-string args)))
1217 (joiner (symbol-name (car (read-from-string args))))
1218 (joined (symbol-name (car (read-from-string args second)))))
1219
1220 (if (assoc joiner texinfo-short-index-cmds-alist)
1221 (put
1222 (cdr (assoc joiner texinfo-short-index-cmds-alist))
1223 'texinfo-format
1224 (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
1225 (intern (concat "texinfo-format-" joined "index"))))
1226 (put
1227 (intern (concat joiner "index"))
1228 'texinfo-format
1229 (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
1230 (intern (concat "texinfo-format-" joined "index")))))))
1231
1232(defconst texinfo-short-index-cmds-alist
1233 '(("cp" . cindex)
1234 ("fn" . findex)
1235 ("vr" . vindex)
1236 ("tp" . tindex)
1237 ("pg" . pindex)
1238 ("ky" . kindex)))
1239
1240(defconst texinfo-short-index-format-cmds-alist
1241 '(("cp" . texinfo-format-cindex)
1242 ("fn" . texinfo-format-findex)
1243 ("vr" . texinfo-format-vindex)
1244 ("tp" . texinfo-format-tindex)
1245 ("pg" . texinfo-format-pindex)
1246 ("ky" . texinfo-format-kindex)))
1247
1248\f
1249;;; @printindex
1250
1251(put 'printindex 'texinfo-format 'texinfo-format-printindex)
1252
1253(defun texinfo-format-printindex ()
1254 (let ((indexelts (symbol-value
1255 (cdr (assoc (texinfo-parse-arg-discard)
1256 texinfo-indexvar-alist))))
1257 opoint)
1258 (insert "\n* Menu:\n\n")
1259 (setq opoint (point))
1260 (texinfo-print-index nil indexelts)
1261
1262 (if (eq system-type 'vax-vms)
1263 (texinfo-sort-region opoint (point))
1264 (shell-command-on-region opoint (point) "sort -fd" 1))))
1265
1266(defun texinfo-print-index (file indexelts)
1267 (while indexelts
1268 (if (stringp (car (car indexelts)))
1269 (insert "* " (car (car indexelts))
1270 ": " (if file (concat "(" file ")") "")
1271 (nth 1 (car indexelts)) ".\n")
1272 ;; index entries from @include'd file
1273 (texinfo-print-index (nth 1 (car indexelts))
1274 (nth 2 (car indexelts))))
1275 (setq indexelts (cdr indexelts))))
1276
1277\f
1278;;; NOTATIONS: @equiv, @error, etc
1279
1280;; @equiv to show that two expressions are equivalent
1281;; @error to show an error message
1282;; @expansion to show what a macro expands to
1283;; @point to show the location of point in an example
1284;; @print to show what an evaluated expression prints
1285;; @result to indicate the value returned by an expression
1286
1287(put 'equiv 'texinfo-format 'texinfo-format-equiv)
1288(defun texinfo-format-equiv ()
1289 (texinfo-parse-arg-discard)
1290 (insert "=="))
1291
1292(put 'error 'texinfo-format 'texinfo-format-error)
1293(defun texinfo-format-error ()
1294 (texinfo-parse-arg-discard)
1295 (insert "error-->"))
1296
1297(put 'expansion 'texinfo-format 'texinfo-format-expansion)
1298(defun texinfo-format-expansion ()
1299 (texinfo-parse-arg-discard)
1300 (insert "==>"))
1301
1302(put 'point 'texinfo-format 'texinfo-format-point)
1303(defun texinfo-format-point ()
1304 (texinfo-parse-arg-discard)
1305 (insert "-!-"))
1306
1307(put 'print 'texinfo-format 'texinfo-format-print)
1308(defun texinfo-format-print ()
1309 (texinfo-parse-arg-discard)
1310 (insert "-|"))
1311
1312(put 'result 'texinfo-format 'texinfo-format-result)
1313(defun texinfo-format-result ()
1314 (texinfo-parse-arg-discard)
1315 (insert "=>"))
1316
1317\f
1318;;;; Description formatting: @deffn, @defun, etc
1319
1320(defun texinfo-format-defun ()
1321 (texinfo-push-stack 'defun nil)
1322 (setq fill-column (- fill-column 5))
1323 (texinfo-format-defun-1 t))
1324
1325(defun texinfo-format-defunx ()
1326 (texinfo-format-defun-1 nil))
1327
1328(defun texinfo-format-defun-1 (first-p)
1329 (let ((args (texinfo-format-parse-defun-args))
1330 (command-type (get texinfo-command-name 'texinfo-defun-type))
1331 (class "")
1332 (name "")
1333 (classification "")
1334 (data-type ""))
1335 (texinfo-discard-command)
1336
1337 (cond
1338 ;; Generalized object oriented entity: `category class name [args...]'
1339 ;; In Info, `Category on class: name ARG'
1340 ((eq (eval (car command-type)) 'defop-type)
1341 (setq category (car args))
1342 (setq class (car (cdr args)))
1343 (setq name (car args))
1344 (setq args (cdr (cdr args))))
1345
1346 ;; Specialized object oriented entity: @defmethod, @defivar
1347 ;; "Instance Variable" `class name [args...]'
1348 ;; In Info, `Instance variable of class: name'
1349 ((eq (eval (car command-type)) 'defmethod-type)
1350 (setq category (car (cdr command-type)))
1351 (setq class (car args))
1352 (setq name (car args))
1353 (setq args (cdr args)))
1354
1355 ;; Generalized function-like or variable-like entity:
1356 ;; `category name [args...]'
1357 ;; In Info, `Category: name ARGS'
1358 ((or (eq (eval (car command-type)) 'deffn-type)
1359 (eq (eval (car command-type)) 'deftp-type))
1360 (setq category (car args))
1361 (setq args (cdr args))
1362 (setq name (car args)))
1363
1364 ;; Specialized function-like or variable-like entity:
1365 ;; "Macro" `name [args...]'
1366 ;; In Info, `Macro: Name ARGS'
1367 ((eq (eval (car command-type)) 'defun-type)
1368 (setq category (car (cdr command-type)))
1369 (setq name (car args)))
1370
1371 ;; Generalized typed-function-like or typed-variable-like entity:
1372 ;; `Classification data-type name [args...]'
1373 ;; In Info, `Classification: data-type name ARGS'
1374 ((or (eq (eval (car command-type)) 'deftypefn-type)
1375 (eq (eval (car command-type)) 'deftypevr-type))
1376 (setq classification (car args))
1377 (setq data-type (car (cdr args)))
1378 (setq name (car (cdr (cdr args))))
1379 (setq args (cdr (cdr (cdr args)))))
1380
1381 ;; Specialized typed-function-like or typed-variable-like entity:
1382 ;; `data-type name [args...]'
1383 ;; In Info, `Function: data-type name ARGS'
1384 ;; or, `Variable: data-type name'
1385 ((or (eq (eval (car command-type)) 'deftypefun-type)
1386 (eq (eval (car command-type)) 'deftypevar-type))
1387 (setq classification (car (cdr command-type)))
1388 (setq data-type (car args))
1389 (setq name (car (cdr args)))
1390 (setq args (cdr (cdr args)))))
1391
1392 ;; Delete extra newline inserted after previous header line.
1393 (if (not first-p)
1394 (delete-char -1))
1395
1396 (let ((formatter (get texinfo-command-name 'texinfo-defun-format-type)))
1397 (cond
1398 ;; if typed function or variable
1399 ((eq formatter 'texinfo-format-deftypefn-type)
1400 (insert "* " classification ": " data-type " " name)
1401 (let ((args args))
1402 (while args
1403 (insert " " (car args))
1404 (setq args (cdr args)))))
1405 (t
1406 ;; and if object oriented, set category
1407 (if (or (eq formatter 'texinfo-format-defop-type)
1408 (eq formatter 'texinfo-format-defcv-type))
1409 (setq category (funcall formatter category class)))
1410 (insert "* " category ": " name)
1411 (let ((args (cdr args)))
1412 (while args
1413 (insert " "
1414 (if (or (= ?& (aref (car args) 0))
1415 (eq (eval (car command-type)) 'deftp-type))
1416 (car args)
1417 (upcase (car args))))
1418 (setq args (cdr args)))))))
1419
1420 ;; Insert extra newline so that paragraph filling does not mess
1421 ;; with header line.
1422 (insert "\n\n")
1423 (rplaca (cdr (cdr (car texinfo-stack))) (point))
1424
1425 (let ((indexvar (get texinfo-command-name 'texinfo-defun-index))
1426 (index-formatter
1427 (get texinfo-command-name 'texinfo-defun-format-index)))
1428 (set indexvar
1429 (cons (list
1430 (cond
1431 ;; if object oriented
1432 ((or (eq index-formatter 'texinfo-format-defop-index)
1433 (eq index-formatter 'texinfo-format-defcv-index))
1434 (funcall index-formatter name class))
1435 ((eq index-formatter 'texinfo-format-deftypefn-index)
1436 (funcall index-formatter name data-type))
1437 (t (car args)))
1438 texinfo-last-node)
1439 (symbol-value indexvar))))))
1440
1441(defun texinfo-end-defun ()
1442 (setq fill-column (+ fill-column 5))
1443 (texinfo-discard-command)
1444 (let ((start (nth 1 (texinfo-pop-stack 'defun))))
1445 (texinfo-do-itemize start)
1446 ;; Delete extra newline inserted after header.
1447 (save-excursion
1448 (goto-char start)
1449 (delete-char -1))))
1450
1451(defun texinfo-format-defop-type (category class)
1452 (format "%s on %s" category class))
1453
1454(defun texinfo-format-defop-index (name class)
1455 (format "%s on %s" name class))
1456
1457(defun texinfo-format-defcv-type (category class)
1458 (format "%s of %s" category class))
1459
1460(defun texinfo-format-defcv-index (name class)
1461 (format "%s of %s" name class))
1462
1463(put 'deffn 'texinfo-format 'texinfo-format-defun)
1464(put 'deffnx 'texinfo-format 'texinfo-format-defunx)
1465(put 'deffn 'texinfo-end 'texinfo-end-defun)
1466(put 'deffn 'texinfo-defun-type '('deffn-type nil))
1467(put 'deffnx 'texinfo-defun-type '('deffn-type nil))
1468(put 'deffn 'texinfo-defun-index 'texinfo-findex)
1469(put 'deffnx 'texinfo-defun-index 'texinfo-findex)
1470
1471(put 'defun 'texinfo-format 'texinfo-format-defun)
1472(put 'defunx 'texinfo-format 'texinfo-format-defunx)
1473(put 'defun 'texinfo-end 'texinfo-end-defun)
1474(put 'defun 'texinfo-defun-type '('defun-type "Function"))
1475(put 'defunx 'texinfo-defun-type '('defun-type "Function"))
1476(put 'defun 'texinfo-defun-index 'texinfo-findex)
1477(put 'defunx 'texinfo-defun-index 'texinfo-findex)
1478
1479(put 'defmac 'texinfo-format 'texinfo-format-defun)
1480(put 'defmacx 'texinfo-format 'texinfo-format-defunx)
1481(put 'defmac 'texinfo-end 'texinfo-end-defun)
1482(put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
1483(put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
1484(put 'defmac 'texinfo-defun-index 'texinfo-findex)
1485(put 'defmacx 'texinfo-defun-index 'texinfo-findex)
1486
1487(put 'defspec 'texinfo-format 'texinfo-format-defun)
1488(put 'defspecx 'texinfo-format 'texinfo-format-defunx)
1489(put 'defspec 'texinfo-end 'texinfo-end-defun)
1490(put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
1491(put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
1492(put 'defspec 'texinfo-defun-index 'texinfo-findex)
1493(put 'defspecx 'texinfo-defun-index 'texinfo-findex)
1494
1495(put 'defvr 'texinfo-format 'texinfo-format-defun)
1496(put 'defvrx 'texinfo-format 'texinfo-format-defunx)
1497(put 'defvr 'texinfo-end 'texinfo-end-defun)
1498(put 'defvr 'texinfo-defun-type '('deffn-type nil))
1499(put 'defvrx 'texinfo-defun-type '('deffn-type nil))
1500(put 'defvr 'texinfo-defun-index 'texinfo-vindex)
1501(put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
1502
1503(put 'defvar 'texinfo-format 'texinfo-format-defun)
1504(put 'defvarx 'texinfo-format 'texinfo-format-defunx)
1505(put 'defvar 'texinfo-end 'texinfo-end-defun)
1506(put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
1507(put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
1508(put 'defvar 'texinfo-defun-index 'texinfo-vindex)
1509(put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
1510
1511(put 'defconst 'texinfo-format 'texinfo-format-defun)
1512(put 'defconstx 'texinfo-format 'texinfo-format-defunx)
1513(put 'defconst 'texinfo-end 'texinfo-end-defun)
1514(put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
1515(put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
1516(put 'defconst 'texinfo-defun-index 'texinfo-vindex)
1517(put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
1518
1519(put 'defcmd 'texinfo-format 'texinfo-format-defun)
1520(put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
1521(put 'defcmd 'texinfo-end 'texinfo-end-defun)
1522(put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
1523(put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
1524(put 'defcmd 'texinfo-defun-index 'texinfo-findex)
1525(put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
1526
1527(put 'defopt 'texinfo-format 'texinfo-format-defun)
1528(put 'defoptx 'texinfo-format 'texinfo-format-defunx)
1529(put 'defopt 'texinfo-end 'texinfo-end-defun)
1530(put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
1531(put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
1532(put 'defopt 'texinfo-defun-index 'texinfo-vindex)
1533(put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
1534
1535(put 'deftp 'texinfo-format 'texinfo-format-defun)
1536(put 'deftpx 'texinfo-format 'texinfo-format-defunx)
1537(put 'deftp 'texinfo-end 'texinfo-end-defun)
1538(put 'deftp 'texinfo-defun-type '('deftp-type nil))
1539(put 'deftpx 'texinfo-defun-type '('deftp-type nil))
1540(put 'deftp 'texinfo-defun-index 'texinfo-tindex)
1541(put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
1542
1543;;; Object-oriented stuff is a little hairier.
1544
1545(put 'defop 'texinfo-format 'texinfo-format-defun)
1546(put 'defopx 'texinfo-format 'texinfo-format-defunx)
1547(put 'defop 'texinfo-end 'texinfo-end-defun)
1548(put 'defop 'texinfo-defun-type '('defop-type nil))
1549(put 'defopx 'texinfo-defun-type '('defop-type nil))
1550(put 'defop 'texinfo-defun-format-type 'texinfo-format-defop-type)
1551(put 'defopx 'texinfo-defun-format-type 'texinfo-format-defop-type)
1552(put 'defop 'texinfo-defun-index 'texinfo-findex)
1553(put 'defopx 'texinfo-defun-index 'texinfo-findex)
1554(put 'defop 'texinfo-defun-format-index 'texinfo-format-defop-index)
1555(put 'defopx 'texinfo-defun-format-index 'texinfo-format-defop-index)
1556
1557(put 'defmethod 'texinfo-format 'texinfo-format-defun)
1558(put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
1559(put 'defmethod 'texinfo-end 'texinfo-end-defun)
1560(put 'defmethod 'texinfo-defun-type '('defmethod-type "Operation"))
1561(put 'defmethodx 'texinfo-defun-type '('defmethod-type "Operation"))
1562(put 'defmethod 'texinfo-defun-format-type 'texinfo-format-defop-type)
1563(put 'defmethodx 'texinfo-defun-format-type 'texinfo-format-defop-type)
1564(put 'defmethod 'texinfo-defun-index 'texinfo-findex)
1565(put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
1566(put 'defmethod 'texinfo-defun-format-index 'texinfo-format-defop-index)
1567(put 'defmethodx 'texinfo-defun-format-index 'texinfo-format-defop-index)
1568
1569(put 'defcv 'texinfo-format 'texinfo-format-defun)
1570(put 'defcvx 'texinfo-format 'texinfo-format-defunx)
1571(put 'defcv 'texinfo-end 'texinfo-end-defun)
1572(put 'defcv 'texinfo-defun-type '('defop-type nil))
1573(put 'defcvx 'texinfo-defun-type '('defop-type nil))
1574(put 'defcv 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1575(put 'defcvx 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1576(put 'defcv 'texinfo-defun-index 'texinfo-vindex)
1577(put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
1578(put 'defcv 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1579(put 'defcvx 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1580
1581(put 'defivar 'texinfo-format 'texinfo-format-defun)
1582(put 'defivarx 'texinfo-format 'texinfo-format-defunx)
1583(put 'defivar 'texinfo-end 'texinfo-end-defun)
1584(put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
1585(put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
1586(put 'defivar 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1587(put 'defivarx 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1588(put 'defivar 'texinfo-defun-index 'texinfo-vindex)
1589(put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
1590(put 'defivar 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1591(put 'defivarx 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1592
1593;;; Typed functions and variables
1594
1595(defun texinfo-format-deftypefn-type (classification data-type)
1596 (format "%s" classification data-type))
1597
1598(defun texinfo-format-deftypefn-index (name data-type)
1599 (format "%s of type %s" name data-type))
1600
1601
1602(put 'deftypefn 'texinfo-format 'texinfo-format-defun)
1603(put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
1604(put 'deftypefn 'texinfo-end 'texinfo-end-defun)
1605(put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
1606(put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
1607(put 'deftypefn 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1608(put 'deftypefnx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1609(put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
1610(put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
1611(put 'deftypefn 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1612(put 'deftypefnx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1613
1614(put 'deftypefun 'texinfo-format 'texinfo-format-defun)
1615(put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
1616(put 'deftypefun 'texinfo-end 'texinfo-end-defun)
1617(put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
1618(put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
1619(put 'deftypefun 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1620(put 'deftypefunx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1621(put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
1622(put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
1623(put 'deftypefun 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1624(put 'deftypefunx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1625
1626(put 'deftypevr 'texinfo-format 'texinfo-format-defun)
1627(put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
1628(put 'deftypevr 'texinfo-end 'texinfo-end-defun)
1629(put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
1630(put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
1631(put 'deftypevr 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1632(put 'deftypevrx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1633(put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
1634(put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
1635(put 'deftypevr 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1636(put 'deftypevrx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1637
1638(put 'deftypevar 'texinfo-format 'texinfo-format-defun)
1639(put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
1640(put 'deftypevar 'texinfo-end 'texinfo-end-defun)
1641(put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
1642(put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
1643(put 'deftypevar 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1644(put 'deftypevarx 'texinfo-defun-format-type 'texinfo-format-deftypefn-type)
1645(put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
1646(put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
1647(put 'deftypevar 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1648(put 'deftypevarx 'texinfo-defun-format-index 'texinfo-format-deftypefn-index)
1649
1650\f
1651;; process included files: `@include' command
1652
1653;; Updated 19 October 1990
1654;; In the original version, include files were ignored by Info but
1655;; incorporated in to the printed manual. To make references to the
1656;; included file, the Texinfo source file has to refer to the included
1657;; files using the `(filename)nodename' format for refering to other
1658;; Info files. Also, the included files had to be formatted on their
1659;; own. It was just like they were another file.
1660
1661;; Currently, include files are inserted into the buffer that is
1662;; formatted for Info. If large, the resulting info file is split and
1663;; tagified. For current include files to work, the master menu must
1664;; refer to all the nodes, and the highest level nodes in the include
1665;; files must have the correct next, prev, and up pointers.
1666
1667;; The included file may have an @setfilename and even an @settitle,
1668;; but not an /input texinfo
1669
1670; Original definition:
1671; (defun texinfo-format-include ()
1672; (let ((filename (texinfo-parse-arg-discard))
1673; (default-directory input-directory)
1674; subindex)
1675; (setq subindex
1676; (save-excursion
1677; (progn (find-file
1678; (cond ((file-readable-p (concat filename ".texinfo"))
1679; (concat filename ".texinfo"))
1680; ((file-readable-p (concat filename ".texi"))
1681; (concat filename ".texi"))
1682; ((file-readable-p (concat filename ".tex"))
1683; (concat filename ".tex"))
1684; ((file-readable-p filename)
1685; filename)
1686; (t (error "@include'd file %s not found"
1687; filename))))
1688; (texinfo-format-buffer-1))))
1689; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
1690; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
1691; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
1692; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
1693; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
1694; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
1695
1696(defun texinfo-subindex (indexvar file content)
1697 (set indexvar (cons (list 'recurse file content)
1698 (symbol-value indexvar))))
1699
1700(put 'include 'texinfo-format 'texinfo-format-include)
1701(defun texinfo-format-include ()
1702 (let ((filename (concat input-directory
1703 (texinfo-parse-arg-discard)))
1704 (default-directory input-directory))
1705 (message "Reading: %s" filename)
1706 (save-excursion
1707 (insert-file-contents filename)))
1708 (setq last-input-buffer input-buffer) ; to bypass setfilename
1709 )
1710
1711
1712\f
1713;; Lots of bolio constructs do nothing in texinfo.
1714
1715(put 'page 'texinfo-format 'texinfo-discard-line-with-args)
1716(put 'c 'texinfo-format 'texinfo-discard-line-with-args)
1717(put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
1718(put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
1719(put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
1720(put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
1721(put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
1722(put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
1723(put 'noindent 'texinfo-format 'texinfo-discard-line-with-args)
1724(put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
1725(put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
1726(put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
1727(put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
1728(put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
1729(put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
1730(put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
1731(put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
1732(put 'group 'texinfo-format 'texinfo-discard-line-with-args)
1733(put 'group 'texinfo-end 'texinfo-discard-line-with-args)
1734(put 'need 'texinfo-format 'texinfo-discard-line-with-args)
1735(put 'bye 'texinfo-format 'texinfo-discard-line)
1736(put 'smallbook 'texinfo-format 'texinfo-discard-line)
1737
1738(defun texinfo-discard-line-with-args ()
1739 (goto-char texinfo-command-start)
1740 (delete-region (point) (progn (forward-line 1) (point))))
1741
1742;; Sort an index which is in the current buffer between START and END.
1743;; Used on VMS, where the `sort' utility is not available.
1744(defun texinfo-sort-region (start end)
1745 (require 'sort)
1746 (save-restriction
1747 (narrow-to-region start end)
1748 (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
1749
1750;; Subroutine for sorting an index.
1751;; At start of a line, return a string to sort the line under.
1752(defun texinfo-sort-startkeyfun ()
1753 (let ((line
1754 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
1755 ;; Canonicalize whitespace and eliminate funny chars.
1756 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
1757 (setq line (concat (substring line 0 (match-beginning 0))
1758 " "
1759 (substring line (match-end 0) (length line)))))
1760 line))
1761
1762;; Some cannot be handled
1763
1764(defun texinfo-unsupported ()
1765 (error "%s is not handled by texinfo"
1766 (buffer-substring texinfo-command-start texinfo-command-end)))
1767\f
f9f9507e 1768;;;###autoload
4dd29d03
BP
1769(defun batch-texinfo-format ()
1770 "Runs texinfo-format-buffer on the files remaining on the command line.
1771Must be used only with -batch, and kills emacs on completion.
1772Each file will be processed even if an error occurred previously.
1773For example, invoke
1774 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
1775 (if (not noninteractive)
1776 (error "batch-texinfo-format may only be used -batch."))
1777 (let ((version-control t)
1778 (auto-save-default nil)
1779 (find-file-run-dired nil)
1780 (kept-old-versions 259259)
1781 (kept-new-versions 259259))
1782 (let ((error 0)
1783 file
1784 (files ()))
1785 (while command-line-args-left
1786 (setq file (expand-file-name (car command-line-args-left)))
1787 (cond ((not (file-exists-p file))
1788 (message ">> %s does not exist!" file)
1789 (setq error 1
1790 command-line-args-left (cdr command-line-args-left)))
1791 ((file-directory-p file)
1792 (setq command-line-args-left
1793 (nconc (directory-files file)
1794 (cdr command-line-args-left))))
1795 (t
1796 (setq files (cons file files)
1797 command-line-args-left (cdr command-line-args-left)))))
1798 (while files
1799 (setq file (car files)
1800 files (cdr files))
1801 (condition-case err
1802 (progn
1803 (if buffer-file-name (kill-buffer (current-buffer)))
1804 (find-file file)
1805 (buffer-disable-undo (current-buffer))
1806 (set-buffer-modified-p nil)
1807 (texinfo-mode)
1808 (message "texinfo formatting %s..." file)
1809 (texinfo-format-buffer nil)
1810 (if (buffer-modified-p)
1811 (progn (message "Saving modified %s" (buffer-file-name))
1812 (save-buffer))))
1813 (error
1814 (message ">> Error: %s" (prin1-to-string err))
1815 (message ">> point at")
1816 (let ((s (buffer-substring (point)
1817 (min (+ (point) 100)
1818 (point-max))))
1819 (tem 0))
1820 (while (setq tem (string-match "\n+" s tem))
1821 (setq s (concat (substring s 0 (match-beginning 0))
1822 "\n>> "
1823 (substring s (match-end 0)))
1824 tem (1+ tem)))
1825 (message ">> %s" s))
1826 (setq error 1))))
1827 (kill-emacs error))))
d501f516
ER
1828
1829;;; texinfmt.el ends here