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