|
|
1.1 root 1: ;; Convert texinfo files to info files.
2: ;; Copyright (C) 1985, 1986, 1988 Free Software Foundation, Inc.
3:
4: ;; This file is part of GNU Emacs.
5:
6: ;; GNU Emacs is distributed in the hope that it will be useful,
7: ;; but WITHOUT ANY WARRANTY. No author or distributor
8: ;; accepts responsibility to anyone for the consequences of using it
9: ;; or for whether it serves any particular purpose or works at all,
10: ;; unless he says so in writing. Refer to the GNU Emacs General Public
11: ;; License for full details.
12:
13: ;; Everyone is granted permission to copy, modify and redistribute
14: ;; GNU Emacs, but only under the conditions described in the
15: ;; GNU Emacs General Public License. A copy of this license is
16: ;; supposed to have been given to you along with GNU Emacs so you
17: ;; can know your rights and responsibilities. It should be in a
18: ;; file named COPYING. Among other things, the copyright notice
19: ;; and this notice must be preserved on all copies.
20:
21:
22: (defvar texinfo-format-syntax-table nil)
23:
24: (defvar texinfo-vindex)
25: (defvar texinfo-findex)
26: (defvar texinfo-cindex)
27: (defvar texinfo-pindex)
28: (defvar texinfo-tindex)
29: (defvar texinfo-kindex)
30: (defvar texinfo-last-node)
31: (defvar texinfo-node-names)
32:
33: (if texinfo-format-syntax-table
34: nil
35: (setq texinfo-format-syntax-table (make-syntax-table))
36: (modify-syntax-entry ?\" " " texinfo-format-syntax-table)
37: (modify-syntax-entry ?\\ " " texinfo-format-syntax-table)
38: (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table)
39: (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table)
40: (modify-syntax-entry ?\[ "." texinfo-format-syntax-table)
41: (modify-syntax-entry ?\] "." texinfo-format-syntax-table)
42: (modify-syntax-entry ?\( "." texinfo-format-syntax-table)
43: (modify-syntax-entry ?\) "." texinfo-format-syntax-table)
44: (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table)
45: (modify-syntax-entry ?} "){" texinfo-format-syntax-table)
46: (modify-syntax-entry ?\' "." texinfo-format-syntax-table))
47:
48: (defun texinfo-format-buffer (&optional notagify)
49: "Process the current buffer as texinfo code, into an Info file.
50: The Info file output is generated in a buffer visiting the Info file
51: names specified in the @setfilename command.
52:
53: Non-nil argument (prefix, if interactive) means don't make tag table
54: and don't split the file if large. You can use Info-tagify and
55: Info-split to do these manually."
56: (interactive "P")
57: (let ((lastmessage "Formatting Info file..."))
58: (message lastmessage)
59: (texinfo-format-buffer-1)
60: (if notagify
61: nil
62: (if (> (buffer-size) 30000)
63: (progn
64: (message (setq lastmessage "Making tags table for Info file..."))
65: (Info-tagify)))
66: (if (> (buffer-size) 100000)
67: (progn
68: (message (setq lastmessage "Splitting Info file..."))
69: (Info-split))))
70: (message (concat lastmessage
71: (if (interactive-p) "done. Now save it." "done.")))))
72:
73: (defun texinfo-format-buffer-1 ()
74: (let (texinfo-format-filename
75: texinfo-example-start
76: texinfo-command-start
77: texinfo-command-end
78: texinfo-command-name
79: texinfo-last-node
80: texinfo-vindex
81: texinfo-findex
82: texinfo-cindex
83: texinfo-pindex
84: texinfo-tindex
85: texinfo-kindex
86: texinfo-stack
87: texinfo-node-names
88: outfile
89: (fill-column fill-column)
90: (input-buffer (current-buffer))
91: (input-directory default-directory))
92: (save-excursion
93: (goto-char (point-min))
94: (search-forward "@setfilename")
95: (setq texinfo-command-end (point))
96: (setq outfile (texinfo-parse-line-arg)))
97: (find-file outfile)
98: (texinfo-mode)
99: (set-syntax-table texinfo-format-syntax-table)
100: (erase-buffer)
101: (insert-buffer-substring input-buffer)
102: (goto-char (point-min))
103: (search-forward "@setfilename")
104: (beginning-of-line)
105: (delete-region (point-min) (point))
106: ;; Remove @bye at end of file, if it is there.
107: (goto-char (point-max))
108: (if (search-backward "@bye" nil t)
109: (delete-region (point) (point-max)))
110: ;; Make sure buffer ends in a newline.
111: (or (= (preceding-char) ?\n)
112: (insert "\n"))
113: ;; Scan the whole buffer, converting to Info format.
114: (texinfo-format-scan)
115: ;; Return data for indices.
116: (goto-char (point-min))
117: (list outfile
118: texinfo-vindex texinfo-findex texinfo-cindex
119: texinfo-pindex texinfo-tindex texinfo-kindex)))
120:
121: (defvar texinfo-region-buffer-name "*Info Region*"
122: "*Name of the temporary buffer used by \\[texinfo-format-region].")
123:
124: (defun texinfo-format-region (region-beginning region-ending)
125: "Convert the the current region of the Texinfo file to Info format.
126: This lets you see what that part of the file will look like in Info.
127: The command is bound to \\[texinfo-format-region]. The text that is
128: converted to Info is stored in a temporary buffer."
129: (interactive "r")
130: (message "Converting region to Info format...")
131: (let (texinfo-command-start
132: texinfo-command-end
133: texinfo-command-name
134: texinfo-vindex
135: texinfo-findex
136: texinfo-cindex
137: texinfo-pindex
138: texinfo-tindex
139: texinfo-kindex
140: texinfo-stack
141: texinfo-format-filename
142: texinfo-example-start
143: texinfo-last-node
144: texinfo-node-names
145: (fill-column fill-column)
146: (input-buffer (current-buffer))
147: (input-directory default-directory)
148: filename-beginning
149: filename-ending)
150:
151: ;;; Find a buffer to use.
152:
153: (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
154:
155: ;; Insert the region into the buffer.
156: (erase-buffer)
157:
158: (save-excursion
159: (set-buffer input-buffer)
160: (save-excursion
161: (save-restriction
162: (widen)
163: (goto-char (point-min))
164: ;; Initialize the buffer with the filename
165: ;; or else explain that a filename is needed.
166: (or (search-forward "@setfilename"
167: (save-excursion (forward-line 100) (point)) t)
168: (error "The texinfo file needs a line saying: @setfilename <name>"))
169: (beginning-of-line)
170: (setq filename-beginning (point))
171: (forward-line 1)
172: (setq filename-ending (point)))))
173:
174: ;; Insert the @setfilename line into the buffer.
175: (insert-buffer-substring input-buffer
176: (min filename-beginning region-beginning)
177: filename-ending)
178:
179: ;; Insert the region into the buffer.
180: (insert-buffer-substring input-buffer
181: (max region-beginning filename-ending)
182: region-ending)
183:
184: (texinfo-mode)
185:
186: ;; Install a syntax table useful for scanning command operands.
187: (set-syntax-table texinfo-format-syntax-table)
188:
189: ;; If the region includes the effective end of the data,
190: ;; discard everything after that.
191: (goto-char (point-max))
192: (if (re-search-backward "^@bye" nil t)
193: (delete-region (point) (point-max)))
194: ;; Make sure buffer ends in a newline.
195: (or (= (preceding-char) ?\n)
196: (insert "\n"))
197:
198: ;; Now convert for real.
199: (goto-char (point-min))
200: (texinfo-format-scan)
201: (goto-char (point-min)))
202:
203: (message "Done."))
204:
205: ;; Perform those texinfo-to-info conversions that apply to the whole input
206: ;; uniformly.
207: (defun texinfo-format-scan ()
208: ;; Convert left and right quotes to typewriter font quotes.
209: (goto-char (point-min))
210: (while (search-forward "``" nil t)
211: (replace-match "\""))
212: (goto-char (point-min))
213: (while (search-forward "''" nil t)
214: (replace-match "\""))
215: ;; Scan for @-commands.
216: (goto-char (point-min))
217: (while (search-forward "@" nil t)
218: (if (looking-at "[@{}'` *]")
219: ;; Handle a few special @-followed-by-one-char commands.
220: (if (= (following-char) ?*)
221: ;; @* has no effect, since we are not filling.
222: (delete-region (1- (point)) (1+ (point)))
223: ;; The other characters are simply quoted. Delete the @.
224: (delete-char -1)
225: (forward-char 1))
226: ;; @ is followed by a command-word; find the end of the word.
227: (setq texinfo-command-start (1- (point)))
228: (if (= (char-syntax (following-char)) ?w)
229: (forward-word 1)
230: (forward-char 1))
231: (setq texinfo-command-end (point))
232: ;; Call the handler for this command.
233: (setq texinfo-command-name
234: (intern (buffer-substring (1+ texinfo-command-start)
235: texinfo-command-end)))
236: (let ((cmd (get texinfo-command-name 'texinfo-format)))
237: (if cmd (funcall cmd)
238: (texinfo-unsupported)))))
239: (cond (texinfo-stack
240: (goto-char (nth 2 (car texinfo-stack)))
241: (error "Unterminated @%s" (car (car texinfo-stack))))))
242:
243: (put 'begin 'texinfo-format 'texinfo-format-begin)
244: (defun texinfo-format-begin ()
245: (texinfo-format-begin-end 'texinfo-format))
246:
247: (put 'end 'texinfo-format 'texinfo-format-end)
248: (defun texinfo-format-end ()
249: (texinfo-format-begin-end 'texinfo-end))
250:
251: (defun texinfo-format-begin-end (prop)
252: (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
253: (setq cmd (get texinfo-command-name prop))
254: (if cmd (funcall cmd)
255: (texinfo-unsupported)))
256:
257: (defun texinfo-parse-line-arg ()
258: (goto-char texinfo-command-end)
259: (let ((start (point)))
260: (cond ((looking-at " ")
261: (skip-chars-forward " ")
262: (setq start (point))
263: (end-of-line)
264: (setq texinfo-command-end (1+ (point))))
265: ((looking-at "{")
266: (setq start (1+ (point)))
267: (forward-list 1)
268: (setq texinfo-command-end (point))
269: (forward-char -1))
270: (t
271: (error "Invalid texinfo command arg format")))
272: (prog1 (buffer-substring start (point))
273: (if (eolp) (forward-char 1)))))
274:
275: (defun texinfo-parse-expanded-arg ()
276: (goto-char texinfo-command-end)
277: (let ((start (point))
278: marker)
279: (cond ((looking-at " ")
280: (skip-chars-forward " ")
281: (setq start (point))
282: (end-of-line)
283: (setq texinfo-command-end (1+ (point))))
284: ((looking-at "{")
285: (setq start (1+ (point)))
286: (forward-list 1)
287: (setq texinfo-command-end (point))
288: (forward-char -1))
289: (t
290: (error "Invalid texinfo command arg format")))
291: (setq marker (move-marker (make-marker) texinfo-command-end))
292: (texinfo-format-expand-region start (point))
293: (setq texinfo-command-end (marker-position marker))
294: (move-marker marker nil)
295: (prog1 (buffer-substring start (point))
296: (if (eolp) (forward-char 1)))))
297:
298: (defun texinfo-format-expand-region (start end)
299: (save-restriction
300: (narrow-to-region start end)
301: (let (texinfo-command-start
302: texinfo-command-end
303: texinfo-command-name
304: texinfo-stack)
305: (texinfo-format-scan))
306: (goto-char (point-max))))
307:
308: (defun texinfo-parse-arg-discard ()
309: (prog1 (texinfo-parse-line-arg)
310: (texinfo-discard-command)))
311:
312: (defun texinfo-discard-command ()
313: (delete-region texinfo-command-start texinfo-command-end))
314:
315: (defun texinfo-format-parse-line-args ()
316: (let ((start (1- (point)))
317: next beg end
318: args)
319: (skip-chars-forward " ")
320: (while (not (eolp))
321: (setq beg (point))
322: (re-search-forward "[\n,]")
323: (setq next (point))
324: (if (bolp) (setq next (1- next)))
325: (forward-char -1)
326: (skip-chars-backward " ")
327: (setq end (point))
328: (setq args (cons (if (> end beg) (buffer-substring beg end))
329: args))
330: (goto-char next)
331: (skip-chars-forward " "))
332: (if (eolp) (forward-char 1))
333: (setq texinfo-command-end (point))
334: (nreverse args)))
335:
336: (defun texinfo-format-parse-args ()
337: (let ((start (1- (point)))
338: next beg end
339: args)
340: (search-forward "{")
341: (while (/= (preceding-char) ?\})
342: (skip-chars-forward " \t\n")
343: (setq beg (point))
344: (re-search-forward "[},]")
345: (setq next (point))
346: (forward-char -1)
347: (skip-chars-backward " \t\n")
348: (setq end (point))
349: (cond ((< beg end)
350: (goto-char beg)
351: (while (search-forward "\n" end t)
352: (replace-match " "))))
353: (setq args (cons (if (> end beg) (buffer-substring beg end))
354: args))
355: (goto-char next))
356: (if (eolp) (forward-char 1))
357: (setq texinfo-command-end (point))
358: (nreverse args)))
359:
360: (defun texinfo-format-parse-defun-args ()
361: (goto-char texinfo-command-end)
362: (let ((start (point)))
363: (end-of-line)
364: (setq texinfo-command-end (1+ (point)))
365: (let ((marker (move-marker (make-marker) texinfo-command-end)))
366: (texinfo-format-expand-region start (point))
367: (setq texinfo-command-end (marker-position marker))
368: (move-marker marker nil))
369: (goto-char start)
370: (let ((args '())
371: beg end)
372: (skip-chars-forward " ")
373: (while (not (eolp))
374: (cond ((looking-at "{")
375: (setq beg (1+ (point)))
376: (forward-list 1)
377: (setq end (1- (point))))
378: (t
379: (setq beg (point))
380: (re-search-forward "[\n ]")
381: (forward-char -1)
382: (setq end (point))))
383: (setq args (cons (buffer-substring beg end) args))
384: (skip-chars-forward " "))
385: (forward-char 1)
386: (nreverse args))))
387:
388: (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
389: (defun texinfo-format-setfilename ()
390: (let ((arg (texinfo-parse-arg-discard)))
391: (setq texinfo-format-filename
392: (file-name-nondirectory (expand-file-name arg)))
393: (insert "Info file: "
394: texinfo-format-filename ", -*-Text-*-\n"
395: "produced by texinfo-format-buffer\nfrom "
396: (if (buffer-file-name input-buffer)
397: (concat "file: "
398: (file-name-sans-versions
399: (file-name-nondirectory
400: (buffer-file-name input-buffer))))
401: (concat "buffer " (buffer-name input-buffer)))
402: "\n\n")))
403:
404: (put 'node 'texinfo-format 'texinfo-format-node)
405: (defun texinfo-format-node ()
406: (let* ((args (texinfo-format-parse-line-args))
407: (name (nth 0 args))
408: (next (nth 1 args))
409: (prev (nth 2 args))
410: (up (nth 3 args)))
411: (texinfo-discard-command)
412: (setq texinfo-last-node name)
413: (let ((tem (downcase name)))
414: (if (assoc tem texinfo-node-names)
415: (error "Duplicate node name: %s" name)
416: (setq texinfo-node-names (cons tem texinfo-node-names))))
417: (or (bolp)
418: (insert ?\n))
419: (insert "\^_\nFile: " texinfo-format-filename
420: " Node: " name)
421: (if prev
422: (insert ", Prev: " prev))
423: (if up
424: (insert ", Up: " up))
425: (if next
426: (insert ", Next: " next))
427: (insert ?\n)))
428:
429: (put 'menu 'texinfo-format 'texinfo-format-menu)
430: (defun texinfo-format-menu ()
431: (texinfo-discard-line)
432: (insert "* Menu:\n\n"))
433:
434: (put 'menu 'texinfo-end 'texinfo-discard-command)
435: (defun texinfo-discard-line ()
436: (goto-char texinfo-command-end)
437: (skip-chars-forward " \t")
438: (or (eolp)
439: (error "Extraneous text at end of command line."))
440: (goto-char texinfo-command-start)
441: (or (bolp)
442: (error "Extraneous text at beginning of command line."))
443: (delete-region (point) (progn (forward-line 1) (point))))
444:
445: ; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
446: ; -> *Note FNAME: (FILE)NODE
447: ; If FILE is missing,
448: ; *Note FNAME: NODE
449: ; If FNAME is empty and NAME is present
450: ; *Note NAME: Node
451: ; If both NAME and FNAME are missing
452: ; *Note NODE::
453: ; texinfo ignores the DOCUMENT argument.
454: ; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
455: ; If FILE is specified, (FILE)NODE is used for xrefs.
456: ; If fifth argument DOCUMENT is specified, produces
457: ; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
458: ; of DOCUMENT
459: (put 'xref 'texinfo-format 'texinfo-format-xref)
460: (defun texinfo-format-xref ()
461: (let ((args (texinfo-format-parse-args)))
462: (texinfo-discard-command)
463: (insert "*Note ")
464: (let ((fname (or (nth 1 args) (nth 2 args))))
465: (if (null (or fname (nth 3 args)))
466: (insert (car args) "::")
467: (insert (or fname (car args)) ": ")
468: (if (nth 3 args)
469: (insert "(" (nth 3 args) ")"))
470: (insert (car args))))))
471:
472: (put 'pxref 'texinfo-format 'texinfo-format-pxref)
473: (defun texinfo-format-pxref ()
474: (texinfo-format-xref)
475: (or (save-excursion
476: (forward-char -2)
477: (looking-at "::"))
478: (insert ".")))
479:
480: ;@inforef{NODE, FNAME, FILE}
481: ;Like @xref{NODE, FNAME,,FILE} in texinfo.
482: ;In Tex, generates "See Info file FILE, node NODE"
483: (put 'inforef 'texinfo-format 'texinfo-format-inforef)
484: (defun texinfo-format-inforef ()
485: (let ((args (texinfo-format-parse-args)))
486: (texinfo-discard-command)
487: (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))))
488:
489: (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
490: (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
491: (put 'chapter 'texinfo-format 'texinfo-format-chapter)
492: (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
493: (put 'appendix 'texinfo-format 'texinfo-format-chapter)
494: (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
495: (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
496: (defun texinfo-format-chapter ()
497: (texinfo-format-chapter-1 ?*))
498:
499: (put 'heading 'texinfo-format 'texinfo-format-section)
500: (put 'isection 'texinfo-format 'texinfo-format-section)
501: (put 'section 'texinfo-format 'texinfo-format-section)
502: (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
503: (put 'appendixsection 'texinfo-format 'texinfo-format-section)
504: (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
505: (put 'appendixsec 'texinfo-format 'texinfo-format-section)
506: (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
507: (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
508: (defun texinfo-format-section ()
509: (texinfo-format-chapter-1 ?=))
510:
511: (put 'subheading 'texinfo-format 'texinfo-format-subsection)
512: (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
513: (put 'subsection 'texinfo-format 'texinfo-format-subsection)
514: (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
515: (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
516: (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
517: (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
518: (defun texinfo-format-subsection ()
519: (texinfo-format-chapter-1 ?-))
520:
521: (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
522: (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
523: (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
524: (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
525: (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
526: (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
527: (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
528: (defun texinfo-format-subsubsection ()
529: (texinfo-format-chapter-1 ?.))
530:
531: (defun texinfo-format-chapter-1 (belowchar)
532: (let ((arg (texinfo-parse-arg-discard)))
533: (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
534: (forward-line -2)))
535:
536: (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
537: (defun texinfo-format-sectionpad ()
538: (let ((str (texinfo-parse-arg-discard)))
539: (forward-char -1)
540: (let ((column (current-column)))
541: (forward-char 1)
542: (while (> column 0)
543: (insert str)
544: (setq column (1- column))))
545: (insert ?\n)))
546:
547: (put '\. 'texinfo-format 'texinfo-format-\.)
548: (defun texinfo-format-\. ()
549: (texinfo-discard-command)
550: (insert "."))
551:
552: (put '\: 'texinfo-format 'texinfo-format-\:)
553: (defun texinfo-format-\: ()
554: (texinfo-discard-command))
555:
556: (put 'center 'texinfo-format 'texinfo-format-center)
557: (defun texinfo-format-center ()
558: (texinfo-discard-command)
559: (let ((indent-tabs-mode nil))
560: (center-line)))
561:
562: ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
563: ;; @enumerate pushes (enumerate 0 STARTPOS).
564: ;; @item dispatches to the texinfo-item prop of the first elt of the list.
565: ;; For itemize, this puts in and rescans the COMMANDS.
566: ;; For enumerate, this increments the number and puts it in.
567: ;; In either case, it puts a Backspace at the front of the line
568: ;; which marks it not to be indented later.
569: ;; All other lines get indented by 5 when the @end is reached.
570:
571: (defun texinfo-push-stack (check arg)
572: (setq texinfo-stack
573: (cons (list check arg texinfo-command-start)
574: texinfo-stack)))
575:
576: (defun texinfo-pop-stack (check)
577: (if (null texinfo-stack)
578: (error "Unmatched @end %s" check))
579: (if (not (eq (car (car texinfo-stack)) check))
580: (error "@end %s matches @%s"
581: check (car (car texinfo-stack))))
582: (prog1 (cdr (car texinfo-stack))
583: (setq texinfo-stack (cdr texinfo-stack))))
584:
585: (put 'itemize 'texinfo-format 'texinfo-itemize)
586: (defun texinfo-itemize ()
587: (texinfo-push-stack 'itemize (texinfo-parse-arg-discard))
588: (setq fill-column (- fill-column 5)))
589:
590: (put 'itemize 'texinfo-end 'texinfo-end-itemize)
591: (defun texinfo-end-itemize ()
592: (setq fill-column (+ fill-column 5))
593: (texinfo-discard-command)
594: (let ((stacktop
595: (texinfo-pop-stack 'itemize)))
596: (texinfo-do-itemize (nth 1 stacktop))))
597:
598: (put 'enumerate 'texinfo-format 'texinfo-enumerate)
599: (defun texinfo-enumerate ()
600: (texinfo-push-stack 'enumerate 0)
601: (setq fill-column (- fill-column 5))
602: (texinfo-discard-line))
603:
604: (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
605: (defun texinfo-end-enumerate ()
606: (setq fill-column (+ fill-column 5))
607: (texinfo-discard-command)
608: (let ((stacktop
609: (texinfo-pop-stack 'enumerate)))
610: (texinfo-do-itemize (nth 1 stacktop))))
611:
612: (put 'table 'texinfo-format 'texinfo-table)
613: (defun texinfo-table ()
614: (texinfo-push-stack 'table (texinfo-parse-arg-discard))
615: (setq fill-column (- fill-column 5)))
616:
617: (put 'ftable 'texinfo-format 'texinfo-ftable)
618: (defun texinfo-ftable ()
619: (texinfo-push-stack 'table "@code")
620: (setq fill-column (- fill-column 5))
621: (texinfo-discard-line))
622:
623: (put 'description 'texinfo-format 'texinfo-description)
624: (defun texinfo-description ()
625: (texinfo-push-stack 'table "@asis")
626: (setq fill-column (- fill-column 5))
627: (texinfo-discard-line))
628:
629: (put 'table 'texinfo-end 'texinfo-end-table)
630: (put 'ftable 'texinfo-end 'texinfo-end-table)
631: (put 'description 'texinfo-end 'texinfo-end-table)
632: (defun texinfo-end-table ()
633: (setq fill-column (+ fill-column 5))
634: (texinfo-discard-command)
635: (let ((stacktop
636: (texinfo-pop-stack 'table)))
637: (texinfo-do-itemize (nth 1 stacktop))))
638:
639: ;; At the @end, indent all the lines within the construct
640: ;; except those marked with backspace. FROM says where
641: ;; construct started.
642: (defun texinfo-do-itemize (from)
643: (save-excursion
644: (while (progn (forward-line -1)
645: (>= (point) from))
646: (if (= (following-char) ?\b)
647: (save-excursion
648: (delete-char 1)
649: (end-of-line)
650: (delete-char 6))
651: (if (not (looking-at "[ \t]*$"))
652: (save-excursion (insert " ")))))))
653:
654: (put 'item 'texinfo-format 'texinfo-item)
655: (put 'itemx 'texinfo-format 'texinfo-item)
656: (defun texinfo-item ()
657: (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
658:
659: (put 'itemize 'texinfo-item 'texinfo-itemize-item)
660: (defun texinfo-itemize-item ()
661: (texinfo-discard-line)
662: (insert "\b " (nth 1 (car texinfo-stack)) " \n")
663: (forward-line -1))
664:
665: (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
666: (defun texinfo-enumerate-item ()
667: (texinfo-discard-line)
668: (let ((next (1+ (car (cdr (car texinfo-stack))))))
669: (setcar (cdr (car texinfo-stack)) next)
670: (insert ?\b (format "%3d. " next) ?\n))
671: (forward-line -1))
672:
673: (put 'table 'texinfo-item 'texinfo-table-item)
674: (defun texinfo-table-item ()
675: (let ((arg (texinfo-parse-arg-discard))
676: (itemfont (car (cdr (car texinfo-stack)))))
677: (insert ?\b itemfont ?\{ arg "}\n \n"))
678: (forward-line -2))
679:
680: (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
681: (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
682:
683: (put 'iftex 'texinfo-format 'texinfo-format-iftex)
684: (defun texinfo-format-iftex ()
685: (delete-region texinfo-command-start
686: (progn (re-search-forward "@end iftex\n")
687: (point))))
688:
689: (put 'tex 'texinfo-format 'texinfo-format-tex)
690: (defun texinfo-format-tex ()
691: (delete-region texinfo-command-start
692: (progn (re-search-forward "@end tex\n")
693: (point))))
694:
695: (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
696: (defun texinfo-format-titlepage ()
697: (delete-region texinfo-command-start
698: (progn (search-forward "@end titlepage\n")
699: (point))))
700:
701: (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
702:
703: (put 'ignore 'texinfo-format 'texinfo-format-ignore)
704: (defun texinfo-format-ignore ()
705: (delete-region texinfo-command-start
706: (progn (search-forward "@end ignore\n")
707: (point))))
708:
709: (put 'endignore 'texinfo-format 'texinfo-discard-line)
710:
711: (put 'var 'texinfo-format 'texinfo-format-var)
712: (defun texinfo-format-var ()
713: (insert (upcase (texinfo-parse-arg-discard)))
714: (goto-char texinfo-command-start))
715:
716: (put 'asis 'texinfo-format 'texinfo-format-noop)
717: (put 'b 'texinfo-format 'texinfo-format-noop)
718: (put 't 'texinfo-format 'texinfo-format-noop)
719: (put 'i 'texinfo-format 'texinfo-format-noop)
720: (put 'r 'texinfo-format 'texinfo-format-noop)
721: (put 'key 'texinfo-format 'texinfo-format-noop)
722: (put 'w 'texinfo-format 'texinfo-format-noop)
723: (defun texinfo-format-noop ()
724: (insert (texinfo-parse-arg-discard))
725: (goto-char texinfo-command-start))
726:
727: (put 'code 'texinfo-format 'texinfo-format-code)
728: (put 'samp 'texinfo-format 'texinfo-format-code)
729: (put 'file 'texinfo-format 'texinfo-format-code)
730: (put 'kbd 'texinfo-format 'texinfo-format-code)
731: (put 'cite 'texinfo-format 'texinfo-format-code)
732: (defun texinfo-format-code ()
733: (insert "`" (texinfo-parse-arg-discard) "'")
734: (goto-char texinfo-command-start))
735:
736: (put 'emph 'texinfo-format 'texinfo-format-emph)
737: (put 'strong 'texinfo-format 'texinfo-format-emph)
738: (defun texinfo-format-emph ()
739: (insert "*" (texinfo-parse-arg-discard) "*")
740: (goto-char texinfo-command-start))
741:
742: (put 'defn 'texinfo-format 'texinfo-format-defn)
743: (put 'dfn 'texinfo-format 'texinfo-format-defn)
744: (defun texinfo-format-defn ()
745: (insert "\"" (texinfo-parse-arg-discard) "\"")
746: (goto-char texinfo-command-start))
747:
748: (put 'bullet 'texinfo-format 'texinfo-format-bullet)
749: (defun texinfo-format-bullet ()
750: (texinfo-discard-command)
751: (insert "*"))
752:
753: (put 'smallexample 'texinfo-format 'texinfo-format-example)
754: (put 'example 'texinfo-format 'texinfo-format-example)
755: (put 'quotation 'texinfo-format 'texinfo-format-example)
756: (put 'lisp 'texinfo-format 'texinfo-format-example)
757: (put 'display 'texinfo-format 'texinfo-format-example)
758: (put 'format 'texinfo-format 'texinfo-format-example)
759: (put 'flushleft 'texinfo-format 'texinfo-format-example)
760: (defun texinfo-format-example ()
761: (texinfo-push-stack 'example nil)
762: (setq fill-column (- fill-column 5))
763: (texinfo-discard-line))
764:
765: (put 'smallexample 'texinfo-end 'texinfo-end-example)
766: (put 'example 'texinfo-end 'texinfo-end-example)
767: (put 'quotation 'texinfo-end 'texinfo-end-example)
768: (put 'lisp 'texinfo-end 'texinfo-end-example)
769: (put 'display 'texinfo-end 'texinfo-end-example)
770: (put 'format 'texinfo-end 'texinfo-end-example)
771: (put 'flushleft 'texinfo-end 'texinfo-end-example)
772: (defun texinfo-end-example ()
773: (setq fill-column (+ fill-column 5))
774: (texinfo-discard-command)
775: (let ((stacktop
776: (texinfo-pop-stack 'example)))
777: (texinfo-do-itemize (nth 1 stacktop))))
778:
779: (put 'exdent 'texinfo-format 'texinfo-format-exdent)
780: (defun texinfo-format-exdent ()
781: (texinfo-discard-command)
782: (delete-region (point)
783: (progn
784: (skip-chars-forward " ")
785: (point)))
786: (insert ?\b)
787: ;; Cancel out the deletion that texinfo-do-itemize
788: ;; is going to do at the end of this line.
789: (save-excursion
790: (end-of-line)
791: (insert "\n ")))
792:
793: (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
794: (defun texinfo-format-ctrl ()
795: (let ((str (texinfo-parse-arg-discard)))
796: (insert (logand 31 (aref str 0)))))
797:
798: (put 'TeX 'texinfo-format 'texinfo-format-TeX)
799: (defun texinfo-format-TeX ()
800: (texinfo-parse-arg-discard)
801: (insert "TeX"))
802:
803: (put 'copyright 'texinfo-format 'texinfo-format-copyright)
804: (defun texinfo-format-copyright ()
805: (texinfo-parse-arg-discard)
806: (insert "(C)"))
807:
808: (put 'minus 'texinfo-format 'texinfo-format-minus)
809: (defun texinfo-format-minus ()
810: (texinfo-parse-arg-discard)
811: (insert "-"))
812:
813: (put 'dots 'texinfo-format 'texinfo-format-dots)
814: (defun texinfo-format-dots ()
815: (texinfo-parse-arg-discard)
816: (insert "..."))
817:
818: (put 'refill 'texinfo-format 'texinfo-format-refill)
819: (defun texinfo-format-refill ()
820: (texinfo-discard-command)
821: (fill-paragraph nil))
822:
823: ;; Index generation
824:
825: (put 'vindex 'texinfo-format 'texinfo-format-vindex)
826: (defun texinfo-format-vindex ()
827: (texinfo-index 'texinfo-vindex))
828:
829: (put 'cindex 'texinfo-format 'texinfo-format-cindex)
830: (defun texinfo-format-cindex ()
831: (texinfo-index 'texinfo-cindex))
832:
833: (put 'findex 'texinfo-format 'texinfo-format-findex)
834: (defun texinfo-format-findex ()
835: (texinfo-index 'texinfo-findex))
836:
837: (put 'pindex 'texinfo-format 'texinfo-format-pindex)
838: (defun texinfo-format-pindex ()
839: (texinfo-index 'texinfo-pindex))
840:
841: (put 'tindex 'texinfo-format 'texinfo-format-tindex)
842: (defun texinfo-format-tindex ()
843: (texinfo-index 'texinfo-tindex))
844:
845: (put 'kindex 'texinfo-format 'texinfo-format-kindex)
846: (defun texinfo-format-kindex ()
847: (texinfo-index 'texinfo-kindex))
848:
849: (defun texinfo-index (indexvar)
850: (let ((arg (texinfo-parse-expanded-arg)))
851: (texinfo-discard-command)
852: (set indexvar
853: (cons (list arg texinfo-last-node)
854: (symbol-value indexvar)))))
855:
856: (defconst texinfo-indexvar-alist
857: '(("cp" . texinfo-cindex)
858: ("fn" . texinfo-findex)
859: ("vr" . texinfo-vindex)
860: ("tp" . texinfo-tindex)
861: ("pg" . texinfo-pindex)
862: ("ky" . texinfo-kindex)))
863:
864: (put 'printindex 'texinfo-format 'texinfo-format-printindex)
865: (defun texinfo-format-printindex ()
866: (let ((indexelts (symbol-value
867: (cdr (assoc (texinfo-parse-arg-discard)
868: texinfo-indexvar-alist))))
869: opoint)
870: (insert "\n* Menu:\n\n")
871: (setq opoint (point))
872: (texinfo-print-index nil indexelts)
873: (if (eq system-type 'vax-vms)
874: (texinfo-sort-region opoint (point))
875: (shell-command-on-region opoint (point) "sort -fd" 1))))
876:
877: (defun texinfo-print-index (file indexelts)
878: (while indexelts
879: (if (stringp (car (car indexelts)))
880: (insert "* " (car (car indexelts))
881: ": " (if file (concat "(" file ")") "")
882: (nth 1 (car indexelts)) ".\n")
883: ;; index entries from @include'd file
884: (texinfo-print-index (nth 1 (car indexelts))
885: (nth 2 (car indexelts))))
886: (setq indexelts (cdr indexelts))))
887:
888:
889: ;;;; Lisp Definitions
890:
891: (defun texinfo-format-defun ()
892: (texinfo-push-stack 'defun nil)
893: (setq fill-column (- fill-column 5))
894: (texinfo-format-defun-1 t))
895:
896: (defun texinfo-format-defunx ()
897: (texinfo-format-defun-1 nil))
898:
899: (defun texinfo-format-defun-1 (first-p)
900: (let ((args (texinfo-format-parse-defun-args))
901: (type (get texinfo-command-name 'texinfo-defun-type)))
902: (texinfo-discard-command)
903: (if (eq type 'arg)
904: (progn (setq type (car args))
905: (setq args (cdr args))))
906: (let ((formatter (get texinfo-command-name 'texinfo-defun-format-type)))
907: (if formatter
908: (setq type (funcall formatter type args))))
909: ;; Delete extra newline inserted after previous header line.
910: (if (not first-p)
911: (delete-char -1))
912: (insert "* " type ": " (car args))
913: (let ((args (cdr args)))
914: (while args
915: (insert " "
916: (if (= ?& (aref (car args) 0))
917: (car args)
918: (upcase (car args))))
919: (setq args (cdr args))))
920: ;; Insert extra newline so that paragraph filling does not mess
921: ;; with header line.
922: (insert "\n\n")
923: (rplaca (cdr (cdr (car texinfo-stack))) (point))
924: (let ((indexvar (get texinfo-command-name 'texinfo-defun-index))
925: (formatter (get texinfo-command-name 'texinfo-defun-format-index)))
926: (set indexvar
927: (cons (list (if formatter (funcall formatter type args) (car args))
928: texinfo-last-node)
929: (symbol-value indexvar))))))
930:
931: (defun texinfo-end-defun ()
932: (setq fill-column (+ fill-column 5))
933: (texinfo-discard-command)
934: (let ((start (nth 1 (texinfo-pop-stack 'defun))))
935: (texinfo-do-itemize start)
936: ;; Delete extra newline inserted after header.
937: (save-excursion
938: (goto-char start)
939: (delete-char -1))))
940:
941: (put 'deffn 'texinfo-format 'texinfo-format-defun)
942: (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
943: (put 'deffn 'texinfo-end 'texinfo-end-defun)
944: (put 'deffn 'texinfo-defun-type 'arg)
945: (put 'deffnx 'texinfo-defun-type 'arg)
946: (put 'deffn 'texinfo-defun-index 'texinfo-findex)
947: (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
948:
949: (put 'defun 'texinfo-format 'texinfo-format-defun)
950: (put 'defunx 'texinfo-format 'texinfo-format-defunx)
951: (put 'defun 'texinfo-end 'texinfo-end-defun)
952: (put 'defun 'texinfo-defun-type "Function")
953: (put 'defunx 'texinfo-defun-type "Function")
954: (put 'defun 'texinfo-defun-index 'texinfo-findex)
955: (put 'defunx 'texinfo-defun-index 'texinfo-findex)
956:
957: (put 'defmac 'texinfo-format 'texinfo-format-defun)
958: (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
959: (put 'defmac 'texinfo-end 'texinfo-end-defun)
960: (put 'defmac 'texinfo-defun-type "Macro")
961: (put 'defmacx 'texinfo-defun-type "Macro")
962: (put 'defmac 'texinfo-defun-index 'texinfo-findex)
963: (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
964:
965: (put 'defspec 'texinfo-format 'texinfo-format-defun)
966: (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
967: (put 'defspec 'texinfo-end 'texinfo-end-defun)
968: (put 'defspec 'texinfo-defun-type "Special form")
969: (put 'defspecx 'texinfo-defun-type "Special form")
970: (put 'defspec 'texinfo-defun-index 'texinfo-findex)
971: (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
972:
973: (put 'defvr 'texinfo-format 'texinfo-format-defun)
974: (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
975: (put 'defvr 'texinfo-end 'texinfo-end-defun)
976: (put 'defvr 'texinfo-defun-type 'arg)
977: (put 'defvrx 'texinfo-defun-type 'arg)
978: (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
979: (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
980:
981: (put 'defvar 'texinfo-format 'texinfo-format-defun)
982: (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
983: (put 'defvar 'texinfo-end 'texinfo-end-defun)
984: (put 'defvar 'texinfo-defun-type "Variable")
985: (put 'defvarx 'texinfo-defun-type "Variable")
986: (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
987: (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
988:
989: (put 'defopt 'texinfo-format 'texinfo-format-defun)
990: (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
991: (put 'defopt 'texinfo-end 'texinfo-end-defun)
992: (put 'defopt 'texinfo-defun-type "User Option")
993: (put 'defoptx 'texinfo-defun-type "User Option")
994: (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
995: (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
996:
997: (put 'deftp 'texinfo-format 'texinfo-format-defun)
998: (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
999: (put 'deftp 'texinfo-end 'texinfo-end-defun)
1000: (put 'deftp 'texinfo-defun-type 'arg)
1001: (put 'deftpx 'texinfo-defun-type 'arg)
1002: (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
1003: (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
1004:
1005: ;;; Object-oriented stuff is a little hairier.
1006:
1007: (put 'defop 'texinfo-format 'texinfo-format-defun)
1008: (put 'defopx 'texinfo-format 'texinfo-format-defunx)
1009: (put 'defop 'texinfo-end 'texinfo-end-defun)
1010: (put 'defop 'texinfo-defun-type 'arg)
1011: (put 'defopx 'texinfo-defun-type 'arg)
1012: (put 'defop 'texinfo-defun-format-type 'texinfo-format-defop-type)
1013: (put 'defopx 'texinfo-defun-format-type 'texinfo-format-defop-type)
1014: (put 'defop 'texinfo-defun-index 'texinfo-findex)
1015: (put 'defopx 'texinfo-defun-index 'texinfo-findex)
1016: (put 'defop 'texinfo-defun-format-index 'texinfo-format-defop-index)
1017: (put 'defopx 'texinfo-defun-format-index 'texinfo-format-defop-index)
1018:
1019: (put 'defmethod 'texinfo-format 'texinfo-format-defun)
1020: (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
1021: (put 'defmethod 'texinfo-end 'texinfo-end-defun)
1022: (put 'defmethod 'texinfo-defun-type "Operation")
1023: (put 'defmethodx 'texinfo-defun-type "Operation")
1024: (put 'defmethod 'texinfo-defun-format-type 'texinfo-format-defop-type)
1025: (put 'defmethodx 'texinfo-defun-format-type 'texinfo-format-defop-type)
1026: (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
1027: (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
1028: (put 'defmethod 'texinfo-defun-format-index 'texinfo-format-defop-index)
1029: (put 'defmethodx 'texinfo-defun-format-index 'texinfo-format-defop-index)
1030:
1031: (defun texinfo-format-defop-type (type args)
1032: (format "%s on %s" type (car args)))
1033:
1034: (defun texinfo-format-defop-index (type args)
1035: (format "%s on %s" (car (cdr args)) (car args)))
1036:
1037: (put 'defcv 'texinfo-format 'texinfo-format-defun)
1038: (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
1039: (put 'defcv 'texinfo-end 'texinfo-end-defun)
1040: (put 'defcv 'texinfo-defun-type 'arg)
1041: (put 'defcvx 'texinfo-defun-type 'arg)
1042: (put 'defcv 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1043: (put 'defcvx 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1044: (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
1045: (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
1046: (put 'defcv 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1047: (put 'defcvx 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1048:
1049: (put 'defivar 'texinfo-format 'texinfo-format-defun)
1050: (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
1051: (put 'defivar 'texinfo-end 'texinfo-end-defun)
1052: (put 'defivar 'texinfo-defun-type "Instance variable")
1053: (put 'defivarx 'texinfo-defun-type "Instance variable")
1054: (put 'defivar 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1055: (put 'defivarx 'texinfo-defun-format-type 'texinfo-format-defcv-type)
1056: (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
1057: (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
1058: (put 'defivar 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1059: (put 'defivarx 'texinfo-defun-format-index 'texinfo-format-defcv-index)
1060:
1061: (defun texinfo-format-defcv-type (type args)
1062: (format "%s of %s" type (car args)))
1063:
1064: (defun texinfo-format-defcv-index (type args)
1065: (format "%s of %s" (car (cdr args)) (car args)))
1066:
1067: ;; process included files
1068: (put 'include 'texinfo-format 'texinfo-format-include)
1069: (defun texinfo-format-include ()
1070: (let ((filename (texinfo-parse-arg-discard))
1071: (default-directory input-directory)
1072: subindex)
1073: (setq subindex
1074: (save-excursion
1075: (progn (find-file
1076: (cond ((file-readable-p (concat filename ".texinfo"))
1077: (concat filename ".texinfo"))
1078: ((file-readable-p (concat filename ".tex"))
1079: (concat filename ".tex"))
1080: ((file-readable-p filename)
1081: filename)
1082: (t (error "@include'd file %s not found"
1083: filename))))
1084: (texinfo-format-buffer-1))))
1085: (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
1086: (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
1087: (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
1088: (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
1089: (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
1090: (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
1091:
1092: (defun texinfo-subindex (indexvar file content)
1093: (set indexvar (cons (list 'recurse file content)
1094: (symbol-value indexvar))))
1095:
1096:
1097: ;; Lots of bolio constructs do nothing in texinfo.
1098:
1099: (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
1100: (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
1101: (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
1102: (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
1103: (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
1104: (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
1105: (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
1106: (put 'noindent 'texinfo-format 'texinfo-discard-line-with-args)
1107: (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
1108: (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
1109: (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
1110: (put 'defindex 'texinfo-format 'texinfo-discard-line-with-args)
1111: (put 'synindex 'texinfo-format 'texinfo-discard-line-with-args)
1112: (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
1113: (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
1114: (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
1115: (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
1116: (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
1117: (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
1118: (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
1119: (put 'bye 'texinfo-format 'texinfo-discard-line)
1120: (put 'smallbook 'texinfo-format 'texinfo-discard-line)
1121:
1122: (defun texinfo-discard-line-with-args ()
1123: (goto-char texinfo-command-start)
1124: (delete-region (point) (progn (forward-line 1) (point))))
1125:
1126: ;; Sort an index which is in the current buffer between START and END.
1127: ;; Used on VMS, where the `sort' utility is not available.
1128: (defun texinfo-sort-region (start end)
1129: (require 'sort)
1130: (save-restriction
1131: (narrow-to-region start end)
1132: (sort-subr nil 'forward-line 'end-of-line 'texinfo-sort-startkeyfun)))
1133:
1134: ;; Subroutine for sorting an index.
1135: ;; At start of a line, return a string to sort the line under.
1136: (defun texinfo-sort-startkeyfun ()
1137: (let ((line
1138: (buffer-substring (point) (save-excursion (end-of-line) (point)))))
1139: ;; Canonicalize whitespace and eliminate funny chars.
1140: (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
1141: (setq line (concat (substring line 0 (match-beginning 0))
1142: " "
1143: (substring line (match-end 0) (length line)))))
1144: line))
1145:
1146: ;; Some cannot be handled
1147:
1148: (defun texinfo-unsupported ()
1149: (error "%s is not handled by texinfo"
1150: (buffer-substring texinfo-command-start texinfo-command-end)))
1151:
1152: (defun batch-texinfo-format ()
1153: "Runs texinfo-format-buffer on the files remaining on the command line.
1154: Must be used only with -batch, and kills emacs on completion.
1155: Each file will be processed even if an error occurred previously.
1156: For example, invoke
1157: \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"."
1158: (if (not noninteractive)
1159: (error "batch-texinfo-format may only be used -batch."))
1160: (let ((version-control t)
1161: (auto-save-default nil)
1162: (find-file-run-dired nil)
1163: (kept-old-versions 259259)
1164: (kept-new-versions 259259))
1165: (let ((error 0)
1166: file
1167: (files ()))
1168: (while command-line-args-left
1169: (setq file (expand-file-name (car command-line-args-left)))
1170: (cond ((not (file-exists-p file))
1171: (message ">> %s does not exist!" file)
1172: (setq error 1
1173: command-line-args-left (cdr command-line-args-left)))
1174: ((file-directory-p file)
1175: (setq command-line-args-left
1176: (nconc (directory-files file)
1177: (cdr command-line-args-left))))
1178: (t
1179: (setq files (cons file files)
1180: command-line-args-left (cdr command-line-args-left)))))
1181: (while files
1182: (setq file (car files)
1183: files (cdr files))
1184: (condition-case err
1185: (progn
1186: (if buffer-file-name (kill-buffer (current-buffer)))
1187: (find-file file)
1188: (buffer-flush-undo (current-buffer))
1189: (set-buffer-modified-p nil)
1190: (texinfo-mode)
1191: (message "texinfo formatting %s..." file)
1192: (texinfo-format-buffer nil)
1193: (if (buffer-modified-p)
1194: (progn (message "Saving modified %s" (buffer-file-name))
1195: (save-buffer))))
1196: (error
1197: (message ">> Error: %s" (prin1-to-string err))
1198: (message ">> point at")
1199: (let ((s (buffer-substring (point)
1200: (min (+ (point) 100)
1201: (point-max))))
1202: (tem 0))
1203: (while (setq tem (string-match "\n+" s tem))
1204: (setq s (concat (substring s 0 (match-beginning 0))
1205: "\n>> "
1206: (substring s (match-end 0)))
1207: tem (1+ tem)))
1208: (message ">> %s" s)))
1209: (setq error 1)))
1210: (kill-emacs error))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.