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