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