]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfo.el
(fill-context-prefix, unjustify-current-line,
[gnu-emacs] / lisp / textmodes / texinfo.el
1 ;;; texinfo.el --- major mode for editing Texinfo files
2
3 ;; Copyright (C) 1985, '88, '89,
4 ;; '90, '91, '92, '93 Free Software Foundation, Inc.
5
6 ;; Author: Robert J. Chassell
7 ;; Maintainer: FSF
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 \f
26 ;;; Autoloads:
27
28 (autoload 'makeinfo-region
29 "makeinfo"
30 "Make Info file from region of current Texinfo file, and switch to it.
31
32 This command does not offer the `next-error' feature since it would
33 apply to a temporary file, not the original; use the `makeinfo-buffer'
34 command to gain use of `next-error'."
35 t nil)
36
37 (autoload 'makeinfo-buffer
38 "makeinfo"
39 "Make Info file from current buffer.
40
41 Use the \\[next-error] command to move to the next error
42 \(if there are errors\)."
43 t nil)
44
45 (autoload 'kill-compilation
46 "compile"
47 "Kill the process made by the \\[compile] command."
48 t nil)
49
50 (autoload 'makeinfo-recenter-compilation-buffer
51 "makeinfo"
52 "Redisplay `*compilation*' buffer so most recent output can be seen.
53 The last line of the buffer is displayed on
54 line LINE of the window, or centered if LINE is nil."
55 t nil)
56
57 (autoload 'texinfo-make-menu
58 "texnfo-upd"
59 "Without any prefix argument, make or update a menu.
60 Make the menu for the section enclosing the node found following point.
61
62 Non-nil argument (prefix, if interactive) means make or update menus
63 for nodes within or part of the marked region.
64
65 Whenever a menu exists, and is being updated, the descriptions that
66 are associated with node names in the pre-existing menu are
67 incorporated into the new menu. Otherwise, the nodes' section titles
68 are inserted as descriptions."
69 t nil)
70
71 (autoload 'texinfo-all-menus-update
72 "texnfo-upd"
73 "Update every regular menu in a Texinfo file.
74 Remove pre-existing master menu, if there is one.
75
76 If called with a non-nil argument, this function first updates all the
77 nodes in the buffer before updating the menus."
78 t nil)
79
80 (autoload 'texinfo-master-menu
81 "texnfo-upd"
82 "Make a master menu for a whole Texinfo file.
83 Non-nil argument (prefix, if interactive) means first update all
84 existing nodes and menus. Remove pre-existing master menu, if there is one.
85
86 This function creates a master menu that follows the top node. The
87 master menu includes every entry from all the other menus. It
88 replaces any existing ordinary menu that follows the top node.
89
90 If called with a non-nil argument, this function first updates all the
91 menus in the buffer (incorporating descriptions from pre-existing
92 menus) before it constructs the master menu.
93
94 The function removes the detailed part of an already existing master
95 menu. This action depends on the pre-exisitng master menu using the
96 standard `texinfo-master-menu-header'.
97
98 The master menu has the following format, which is adapted from the
99 recommendation in the Texinfo Manual:
100
101 * The first part contains the major nodes in the Texinfo file: the
102 nodes for the chapters, chapter-like sections, and the major
103 appendices. This includes the indices, so long as they are in
104 chapter-like sections, such as unnumbered sections.
105
106 * The second and subsequent parts contain a listing of the other,
107 lower level menus, in order. This way, an inquirer can go
108 directly to a particular node if he or she is searching for
109 specific information.
110
111 Each of the menus in the detailed node listing is introduced by the
112 title of the section containing the menu."
113 t nil)
114
115 (autoload 'texinfo-indent-menu-description
116 "texnfo-upd"
117 "Indent every description in menu following point to COLUMN.
118 Non-nil argument (prefix, if interactive) means indent every
119 description in every menu in the region. Does not indent second and
120 subsequent lines of a multi-line description."
121 t nil)
122
123 (autoload 'texinfo-insert-node-lines
124 "texnfo-upd"
125 "Insert missing `@node' lines in region of Texinfo file.
126 Non-nil argument (prefix, if interactive) means also to insert the
127 section titles as node names; and also to insert the section titles as
128 node names in pre-existing @node lines that lack names."
129 t nil)
130
131 (autoload 'texinfo-start-menu-description
132 "texnfo-upd"
133 "In this menu entry, insert the node's section title as a description.
134 Position point at beginning of description ready for editing.
135 Do not insert a title if the line contains an existing description.
136
137 You will need to edit the inserted text since a useful description
138 complements the node name rather than repeats it as a title does."
139 t nil)
140
141 (autoload 'texinfo-multiple-files-update
142 "texnfo-upd"
143 "Update first node pointers in each file included in OUTER-FILE;
144 create or update main menu in the outer file that refers to such nodes.
145 This does not create or update menus or pointers within the included files.
146
147 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
148 insert a master menu in OUTER-FILE. This does not create or update
149 menus or pointers within the included files.
150
151 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
152 interactive), update all the menus and all the `Next', `Previous', and
153 `Up' pointers of all the files included in OUTER-FILE before inserting
154 a master menu in OUTER-FILE.
155
156 The command also updates the `Top' level node pointers of OUTER-FILE.
157
158 Notes:
159
160 * this command does NOT save any files--you must save the
161 outer file and any modified, included files.
162
163 * except for the `Top' node, this command does NOT handle any
164 pre-existing nodes in the outer file; hence, indices must be
165 enclosed in an included file.
166
167 Requirements:
168
169 * each of the included files must contain exactly one highest
170 hierarchical level node,
171 * this highest node must be the first node in the included file,
172 * each highest hierarchical level node must be of the same type.
173
174 Thus, normally, each included file contains one, and only one,
175 chapter."
176 t nil)
177
178 \f
179 ;;; Code:
180
181 ;;; Don't you dare insert any `require' calls at top level in this file--rms.
182
183 ;;; Syntax table
184
185 (defvar texinfo-mode-syntax-table nil)
186
187 (if texinfo-mode-syntax-table
188 nil
189 (setq texinfo-mode-syntax-table (make-syntax-table))
190 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
191 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
192 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
193 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
194 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
195 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
196 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
197 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
198 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
199
200 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
201 ;; To overide this example, set either `imenu-generic-expression'
202 ;; or `imenu-create-index-function'.
203 (defvar texinfo-imenu-generic-expression
204 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
205 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
206
207 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
208
209 (defvar texinfo-font-lock-keywords
210 (list
211 ;; All but the first 2 had an OVERRIDE of t.
212 ;; It didn't seem to be any better, and it's slower--simon.
213 '("^\\(@c\\|@comment\\)\\>.*" . font-lock-comment-face) ;comments
214 ;; Robert J. Chassell <bob@gnu.ai.mit.edu> says remove this line.
215 ;'("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
216 "@\\(@\\|[^}\t \n{]+\\)" ;commands
217 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
218 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face)
219 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face)
220 '("@\\(samp\\|code\\|var\\|math\\){\\([^}]+\\)"
221 2 font-lock-variable-name-face)
222 '("@\\(cite\\|xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-reference-face)
223 '("@\\(end\\|item\\) *\\(.+\\)" 2 font-lock-function-name-face keep)
224 )
225 "Additional expressions to highlight in TeXinfo mode.")
226 \f
227 ;;; Keybindings
228 (defvar texinfo-mode-map nil)
229
230 ;;; Keys common both to Texinfo mode and to TeX shell.
231
232 (defun texinfo-define-common-keys (keymap)
233 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
234 (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
235 (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
236 (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
237 (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
238 (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
239 (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
240 (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
241
242 (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
243 (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
244
245 ;; Mode documentation displays commands in reverse order
246 ;; from how they are listed in the texinfo-mode-map.
247
248 (if texinfo-mode-map
249 nil
250 (setq texinfo-mode-map (make-sparse-keymap))
251
252 ;; bindings for `texnfo-tex.el'
253 (texinfo-define-common-keys texinfo-mode-map)
254
255 ;; bindings for `makeinfo.el'
256 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
257 (define-key texinfo-mode-map "\C-c\C-m\C-l"
258 'makeinfo-recenter-compilation-buffer)
259 (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
260 (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
261
262 ; Bindings for texinfmt.el.
263 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
264 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
265
266 ;; bindings for updating nodes and menus
267
268 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
269
270 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
271 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
272 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
273 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
274
275 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
276
277 (define-key texinfo-mode-map "\C-c}" 'up-list)
278 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
279
280 ;; bindings for inserting strings
281
282 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
283
284 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
285 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
286 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
287 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
288 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
289 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
290 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
291 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
292 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
293 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
294 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
295 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
296
297 \f
298 ;;; Texinfo mode
299
300 (defvar texinfo-chapter-level-regexp
301 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
302 "Regular expression matching Texinfo chapter-level headings.
303 This does not match `@node' and does not match the `@top' command.")
304
305 ;;;###autoload
306 (defun texinfo-mode ()
307 "Major mode for editing Texinfo files.
308
309 It has these extra commands:
310 \\{texinfo-mode-map}
311
312 These are files that are used as input for TeX to make printed manuals
313 and also to be turned into Info files with \\[makeinfo-buffer] or
314 the `makeinfo' program. These files must be written in a very restricted and
315 modified version of TeX input format.
316
317 Editing commands are like text-mode except that the syntax table is
318 set up so expression commands skip Texinfo bracket groups. To see
319 what the Info version of a region of the Texinfo file will look like,
320 use \\[makeinfo-region], which runs `makeinfo' on the current region.
321
322 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
323 This command shows the structure of a Texinfo file by listing the
324 lines with the @-sign commands for @chapter, @section, and the like.
325 These lines are displayed in another window called the *Occur* window.
326 In that window, you can position the cursor over one of the lines and
327 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
328 in the Texinfo file.
329
330 In addition, Texinfo mode provides commands that insert various
331 frequently used @-sign commands into the buffer. You can use these
332 commands to save keystrokes. And you can insert balanced braces with
333 \\[texinfo-insert-braces] and later use the command \\[up-list] to
334 move forward past the closing brace.
335
336 Also, Texinfo mode provides functions for automatically creating or
337 updating menus and node pointers. These functions
338
339 * insert the `Next', `Previous' and `Up' pointers of a node,
340 * insert or update the menu for a section, and
341 * create a master menu for a Texinfo source file.
342
343 Here are the functions:
344
345 texinfo-update-node \\[texinfo-update-node]
346 texinfo-every-node-update \\[texinfo-every-node-update]
347 texinfo-sequential-node-update
348
349 texinfo-make-menu \\[texinfo-make-menu]
350 texinfo-all-menus-update \\[texinfo-all-menus-update]
351 texinfo-master-menu
352
353 texinfo-indent-menu-description (column &optional region-p)
354
355 The `texinfo-column-for-description' variable specifies the column to
356 which menu descriptions are indented.
357
358 Passed an argument (a prefix argument, if interactive), the
359 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
360 in the region.
361
362 To use the updating commands, you must structure your Texinfo file
363 hierarchically, such that each `@node' line, with the exception of the
364 Top node, is accompanied by some kind of section line, such as an
365 `@chapter' or `@section' line.
366
367 If the file has a `top' node, it must be called `top' or `Top' and
368 be the first node in the file.
369
370 Entering Texinfo mode calls the value of text-mode-hook, and then the
371 value of texinfo-mode-hook."
372 (interactive)
373 (text-mode)
374 (setq mode-name "Texinfo")
375 (setq major-mode 'texinfo-mode)
376 (use-local-map texinfo-mode-map)
377 (set-syntax-table texinfo-mode-syntax-table)
378 (make-local-variable 'page-delimiter)
379 (setq page-delimiter
380 (concat
381 "^@node [ \t]*[Tt]op\\|^@\\("
382 texinfo-chapter-level-regexp
383 "\\)"))
384 (make-local-variable 'require-final-newline)
385 (setq require-final-newline t)
386 (make-local-variable 'indent-tabs-mode)
387 (setq indent-tabs-mode nil)
388 (make-local-variable 'paragraph-separate)
389 (setq paragraph-separate (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
390 (make-local-variable 'paragraph-start)
391 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
392 (make-local-variable 'fill-column)
393 (setq fill-column 72)
394 (make-local-variable 'comment-start)
395 (setq comment-start "@c ")
396 (make-local-variable 'comment-start-skip)
397 (setq comment-start-skip "@c +")
398 (make-local-variable 'words-include-escapes)
399 (setq words-include-escapes t)
400 (make-local-variable 'imenu-generic-expression)
401 (setq imenu-generic-expression texinfo-imenu-generic-expression)
402 (make-local-variable 'font-lock-defaults)
403 (setq font-lock-defaults '(texinfo-font-lock-keywords t))
404 (make-local-variable 'tex-start-of-header)
405 (setq tex-start-of-header "%**start")
406 (make-local-variable 'tex-end-of-header)
407 (setq tex-end-of-header "%**end")
408 (run-hooks 'text-mode-hook 'texinfo-mode-hook))
409
410 \f
411 ;;; Insert string commands
412
413 (defconst texinfo-environment-regexp
414 "^[ \t]*@\\(f?table\\|enumerate\\|itemize\
415 \\|ifhtml\\|ifinfo\\|iftex\\|ifset\\|ifclear\
416 \\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\
417 \\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|html\\|cartouche\\|menu\
418 \\|titlepage\\|end\\|def[a-z]*[a-wyz]\\>\\)"
419 "Regexp for environment-like Texinfo list commands.
420 Subexpression 1 is what goes into the corresponding `@end' statement.")
421
422 (defun texinfo-insert-@end ()
423 "Insert the matching `@end' for the last Texinfo command that needs one."
424 (interactive)
425 (let ((depth 1) string)
426 (save-excursion
427 (while (and (> depth 0)
428 (re-search-backward texinfo-environment-regexp nil t)
429 (if (looking-at "@end")
430 (setq depth (1+ depth))
431 (setq depth (1- depth)))))
432 (looking-at texinfo-environment-regexp)
433 (if (zerop depth)
434 (setq string
435 (buffer-substring (match-beginning 1)
436 (match-end 1)))))
437 (insert "@end ")
438 (if string (insert string "\n"))))
439
440 ;; The following insert commands accept a prefix arg N, which is the
441 ;; number of words (actually s-exprs) that should be surrounded by
442 ;; braces. Thus you can first paste a variable name into a .texinfo
443 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
444 ;; pasted variable name to put @var{...} *around* the variable name.
445 ;; Operate on previous word or words with negative arg.
446
447 ;; These commands use texinfo-insert-@-with-arg
448 (defun texinfo-insert-@-with-arg (string &optional arg)
449 (if arg
450 (progn
451 (setq arg (prefix-numeric-value arg))
452 (if (< arg 0)
453 (progn
454 (skip-chars-backward " \t\n\r\f")
455 (save-excursion
456 (forward-sexp arg)
457 (insert "@" string "{"))
458 (insert "}"))
459 (skip-chars-forward " \t\n\r\f")
460 (insert "@" string "{")
461 (forward-sexp arg)
462 (insert "}")))
463 (insert "@" string "{}")
464 (backward-char)))
465
466 (defun texinfo-insert-braces ()
467 "Make a pair of braces and be poised to type inside of them.
468 Use \\[up-list] to move forward out of the braces."
469 (interactive)
470 (insert "{}")
471 (backward-char))
472
473 (defun texinfo-insert-@code (&optional arg)
474 "Insert a `@code{...}' command in a Texinfo buffer.
475 A numeric argument says how many words the braces should surround.
476 The default is not to surround any existing words with the braces."
477 (interactive "P")
478 (texinfo-insert-@-with-arg "code" arg))
479
480 (defun texinfo-insert-@dfn (&optional arg)
481 "Insert a `@dfn{...}' command in a Texinfo buffer.
482 A numeric argument says how many words the braces should surround.
483 The default is not to surround any existing words with the braces."
484 (interactive "P")
485 (texinfo-insert-@-with-arg "dfn" arg))
486
487 (defun texinfo-insert-@example ()
488 "Insert the string `@example' in a Texinfo buffer."
489 (interactive)
490 (insert "@example\n"))
491
492 (defun texinfo-insert-@file (&optional arg)
493 "Insert a `@file{...}' command in a Texinfo buffer.
494 A numeric argument says how many words the braces should surround.
495 The default is not to surround any existing words with the braces."
496 (interactive "P")
497 (texinfo-insert-@-with-arg "file" arg))
498
499 (defun texinfo-insert-@item ()
500 "Insert the string `@item' in a Texinfo buffer."
501 (interactive)
502 (insert "@item")
503 (newline))
504
505 (defun texinfo-insert-@kbd (&optional arg)
506 "Insert a `@kbd{...}' command in a Texinfo buffer.
507 A numeric argument says how many words the braces should surround.
508 The default is not to surround any existing words with the braces."
509 (interactive "P")
510 (texinfo-insert-@-with-arg "kbd" arg))
511
512 (defun texinfo-insert-@node ()
513 "Insert the string `@node' in a Texinfo buffer.
514 This also inserts on the following line a comment indicating
515 the order of arguments to @node."
516 (interactive)
517 (insert "@node \n@comment node-name, next, previous, up")
518 (forward-line -1)
519 (forward-char 6))
520
521 (defun texinfo-insert-@noindent ()
522 "Insert the string `@noindent' in a Texinfo buffer."
523 (interactive)
524 (insert "@noindent\n"))
525
526 (defun texinfo-insert-@samp (&optional arg)
527 "Insert a `@samp{...}' command in a Texinfo buffer.
528 A numeric argument says how many words the braces should surround.
529 The default is not to surround any existing words with the braces."
530 (interactive "P")
531 (texinfo-insert-@-with-arg "samp" arg))
532
533 (defun texinfo-insert-@table (&optional arg)
534 "Insert the string `@table' in a Texinfo buffer."
535 (interactive "P")
536 (insert "@table "))
537
538 (defun texinfo-insert-@var (&optional arg)
539 "Insert a `@var{}' command in a Texinfo buffer.
540 A numeric argument says how many words the braces should surround.
541 The default is not to surround any existing words with the braces."
542 (interactive "P")
543 (texinfo-insert-@-with-arg "var" arg))
544 \f
545 ;;; Texinfo file structure
546
547 (defun texinfo-show-structure (&optional nodes-too)
548 "Show the structure of a Texinfo file.
549 List the lines in the file that begin with the @-sign commands for
550 @chapter, @section, and the like.
551
552 With optional argument (prefix if interactive), list both the lines
553 with @-sign commands for @chapter, @section, and the like, and list
554 @node lines.
555
556 Lines with structuring commands beginning in them are displayed in
557 another buffer named `*Occur*'. In that buffer, you can move point to
558 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
559 to jump to the corresponding spot in the Texinfo source file."
560
561 (interactive "P")
562 (require 'texnfo-upd)
563 (save-excursion
564 (goto-char (point-min))
565 (if nodes-too
566 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
567 (occur texinfo-section-types-regexp)))
568 (pop-to-buffer "*Occur*")
569 (goto-char (point-min))
570 (flush-lines "-----")
571 ;; Now format the "*Occur*" buffer to show the structure.
572 ;; Thanks to ceder@signum.se (Per Cederqvist)
573 (goto-char (point-max))
574 (let ((margin 5))
575 (while (re-search-backward "^ *[0-9]*:" nil 0)
576 (re-search-forward ":")
577 (setq margin
578 (cond
579 ((looking-at
580 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
581 ;; ((looking-at "@chapter ") 5)
582 ;; ((looking-at "@unnumbered ") 5)
583 ;; ((looking-at "@appendix ") 5)
584 ;; ((looking-at "@majorheading ") 5)
585 ;; ((looking-at "@chapheading ") 5)
586
587 ((looking-at
588 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
589 ;; ((looking-at "@section ") 9)
590 ;; ((looking-at "@unnumberedsec ") 9)
591 ;; ((looking-at "@appendixsec ") 9)
592 ;; ((looking-at "@heading ") 9)
593
594 ((looking-at
595 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
596 ;; ((looking-at "@subsection ") 13)
597 ;; ((looking-at "@unnumberedsubsec ") 13)
598 ;; ((looking-at "@appendixsubsec ") 13)
599 ;; ((looking-at "@subheading ") 13)
600
601 ((looking-at
602 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
603 ;; ((looking-at "@subsubsection ") 17)
604 ;; ((looking-at "@unnumberedsubsubsec ") 17)
605 ;; ((looking-at "@appendixsubsubsec ") 17)
606 ;; ((looking-at "@subsubheading ") 17)
607 (t margin)))
608 (indent-to-column margin)
609 (beginning-of-line))))
610 \f
611 ;;; The tex and print function definitions:
612
613 (defvar texinfo-texi2dvi-command "texi2dvi"
614 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer.")
615
616 (defvar texinfo-tex-command "tex"
617 "*Command used by `texinfo-tex-region' to run TeX on a region.")
618
619 (defvar texinfo-texindex-command "texindex"
620 "*Command used by `texinfo-texindex' to sort unsorted index files.")
621
622 (defvar texinfo-delete-from-print-queue-command "lprm"
623 "*Command string used to delete a job from the line printer queue.
624 Command is used by \\[texinfo-delete-from-print-queue] based on
625 number provided by a previous \\[tex-show-print-queue]
626 command.")
627
628 (defvar texinfo-tex-trailer "@bye"
629 "String appended after a region sent to TeX by `texinfo-tex-region'.")
630
631 (defun texinfo-tex-region (beg end)
632 "Run TeX on the current region.
633 This works by writing a temporary file (`tex-zap-file') in the directory
634 that is the value of `tex-directory', then running TeX on that file.
635
636 The first line of the buffer is copied to the
637 temporary file; and if the buffer has a header, it is written to the
638 temporary file before the region itself. The buffer's header is all lines
639 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
640 inclusive. The header must start in the first 100 lines.
641
642 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
643 (interactive "r")
644 (require 'tex-mode)
645 (if (get-buffer "*tex-shell*")
646 (tex-kill-job)
647 (tex-start-shell))
648 (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
649 (let ((tex-out-file (concat tex-zap-file ".tex"))
650 (temp-buffer (get-buffer-create " tex-Output-Buffer"))
651 (zap-directory
652 (file-name-as-directory (expand-file-name tex-directory))))
653 (save-excursion
654 (save-restriction
655 (widen)
656 (goto-char (point-min))
657 (forward-line 100)
658 (let ((search-end (point))
659 (hbeg (point-min)) (hend (point-min))
660 (default-directory zap-directory))
661 (goto-char (point-min))
662
663 ;; Copy first line, the `\input texinfo' line, to temp file
664 (write-region (point)
665 (save-excursion (end-of-line) (point))
666 tex-out-file nil nil)
667
668 ;; Don't copy first line twice if region includes it.
669 (forward-line 1)
670 (if (< beg (point)) (setq beg (point)))
671
672 ;; Initialize the temp file with either the header or nothing
673 (if (search-forward tex-start-of-header search-end t)
674 (progn
675 (beginning-of-line)
676 (setq hbeg (point)) ; Mark beginning of header.
677 (if (search-forward tex-end-of-header nil t)
678 (progn (beginning-of-line)
679 (setq hend (point))) ; Mark end of header.
680 (setq hbeg (point-min))))) ; Else no header.
681
682 ;; Copy header to temp file.
683 (write-region (min hbeg beg) hend tex-out-file t nil)
684
685 ;; Copy region to temp file.
686 (write-region (max beg hend) end tex-out-file t nil))
687
688 ;; This is a kludge to insert the tex-trailer into the tex-out-file.
689 ;; We have to create a special buffer in which to insert
690 ;; the tex-trailer first because there is no function with
691 ;; which to append a literal string directly to a file.
692 (let ((local-tex-trailer texinfo-tex-trailer))
693 (set-buffer temp-buffer)
694 (erase-buffer)
695 ;; make sure trailer isn't hidden by a comment
696 (insert-string "\n")
697 (if local-tex-trailer (insert-string local-tex-trailer))
698 (tex-set-buffer-directory temp-buffer zap-directory)
699 (write-region (point-min) (point-max) tex-out-file t nil))
700
701 ;;; The following is sufficient in Emacs 19.
702 ;;; (write-region (concat "\n" texinfo-tex-trailer) nil
703 ;;; tex-out-file t nil)
704 ))
705
706 (tex-set-buffer-directory "*tex-shell*" zap-directory)
707 (tex-send-command tex-shell-cd-command zap-directory)
708 (tex-send-command texinfo-tex-command tex-out-file))
709 (tex-recenter-output-buffer 0))
710
711 (defun texinfo-tex-buffer ()
712 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
713 (interactive)
714
715 ;; Make sure TeX shell is running.
716 (require 'tex-mode)
717 (if (get-buffer "*tex-shell*")
718 (quit-process (get-process "tex-shell") t)
719 (tex-start-shell))
720
721 (cond ((null buffer-file-name)
722 (error "Buffer not visiting any file!"))
723 ((buffer-modified-p)
724 (error "Buffer has been modified since last saved!")))
725
726 (setq tex-zap-file buffer-file-name)
727
728 (tex-send-command tex-shell-cd-command (file-name-directory tex-zap-file))
729
730 (tex-send-command texinfo-texi2dvi-command tex-zap-file)
731
732 (tex-recenter-output-buffer 0))
733
734 (defun texinfo-texindex ()
735 "Run `texindex' on unsorted index files.
736 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
737 This runs the shell command defined by `texinfo-texindex-command'."
738 (interactive)
739 (require 'tex-mode)
740 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
741 (tex-recenter-output-buffer nil))
742
743 (defun texinfo-tex-print ()
744 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
745 This runs the shell command defined by `tex-dvi-print-command'."
746 (interactive)
747 (require 'tex-mode)
748 (tex-send-command tex-dvi-print-command (concat tex-zap-file ".dvi"))
749 (tex-recenter-output-buffer nil))
750
751 (defun texinfo-quit-job ()
752 "Quit currently running TeX job, by sending an `x' to it."
753 (interactive)
754 (if (not (get-process "tex-shell"))
755 (error "No TeX shell running"))
756 (tex-send-command "x"))
757
758 (defun texinfo-delete-from-print-queue (job-number)
759 "Delete job from the line printer spooling queue.
760 You are prompted for the job number (use a number shown by a previous
761 \\[texinfo-show-print-queue] command)."
762 (interactive "nPrinter job number for deletion: ")
763 (require 'tex-mode)
764 (if (tex-shell-running)
765 (tex-kill-job)
766 (tex-start-shell))
767 (tex-send-command texinfo-delete-from-print-queue-command job-number)
768 (tex-recenter-output-buffer nil))
769
770 (provide 'texinfo)
771
772 ;;; texinfo.el ends here