(texinfo-mode): Undo changes mistakenly added with
[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
235 ;; bindings for updating nodes and menus
952d72ff 236
c6cc04e9 237 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
952d72ff 238
0b7da9ad
RC
239 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
240 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
241 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
242 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
952d72ff
RC
243
244 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
245
c6cc04e9
RS
246 (define-key texinfo-mode-map "\C-c}" 'up-list)
247 (define-key texinfo-mode-map "\C-c]" 'up-list)
248 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
249
250 ;; bindings for inserting strings
251
252 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
952d72ff
RC
253
254 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
c6cc04e9 255 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
952d72ff
RC
256 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
257 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
258 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
259 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
260 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
c6cc04e9 261 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
952d72ff 262 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
c6cc04e9 263 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
952d72ff
RC
264 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
265 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
266
c6cc04e9
RS
267\f
268;;; Texinfo mode
952d72ff 269
c6cc04e9
RS
270(defvar texinfo-chapter-level-regexp
271 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
272 "Regular expression matching Texinfo chapter-level headings.
273This does not match `@node' and does not match the `@top' command.")
952d72ff 274
f9f9507e 275;;;###autoload
952d72ff 276(defun texinfo-mode ()
d5aa8b02 277 "Major mode for editing Texinfo files.
952d72ff
RC
278
279 It has these extra commands:
280\\{texinfo-mode-map}
281
d5aa8b02 282 These are files that are used as input for TeX to make printed manuals
c6cc04e9
RS
283and also to be turned into Info files with \\[makeinfo-buffer] or
284the `makeinfo' program. These files must be written in a very restricted and
d5aa8b02 285modified version of TeX input format.
952d72ff
RC
286
287 Editing commands are like text-mode except that the syntax table is
d5aa8b02
RC
288set up so expression commands skip Texinfo bracket groups. To see
289what the Info version of a region of the Texinfo file will look like,
c6cc04e9 290use \\[makeinfo-region], which runs `makeinfo' on the current region.
952d72ff 291
d5aa8b02
RC
292 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
293This command shows the structure of a Texinfo file by listing the
294lines with the @-sign commands for @chapter, @section, and the like.
295These lines are displayed in another window called the *Occur* window.
296In that window, you can position the cursor over one of the lines and
297use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
298in the Texinfo file.
952d72ff 299
d5aa8b02 300 In addition, Texinfo mode provides commands that insert various
952d72ff
RC
301frequently used @-sign commands into the buffer. You can use these
302commands to save keystrokes. And you can insert balanced braces with
303\\[texinfo-insert-braces] and later use the command \\[up-list] to
304move forward past the closing brace.
305
d5aa8b02 306Also, Texinfo mode provides functions for automatically creating or
952d72ff
RC
307updating menus and node pointers. These functions
308
309 * insert the `Next', `Previous' and `Up' pointers of a node,
310 * insert or update the menu for a section, and
d5aa8b02 311 * create a master menu for a Texinfo source file.
952d72ff
RC
312
313Here are the functions:
314
315 texinfo-update-node \\[texinfo-update-node]
316 texinfo-every-node-update \\[texinfo-every-node-update]
317 texinfo-sequential-node-update
318
319 texinfo-make-menu \\[texinfo-make-menu]
320 texinfo-all-menus-update \\[texinfo-all-menus-update]
321 texinfo-master-menu
322
323 texinfo-indent-menu-description (column &optional region-p)
324
325The `texinfo-column-for-description' variable specifies the column to
326which menu descriptions are indented.
327
328Passed an argument (a prefix argument, if interactive), the
329`texinfo-update-node' and `texinfo-make-menu' functions do their jobs
330in the region.
331
d5aa8b02 332To use the updating commands, you must structure your Texinfo file
952d72ff 333hierarchically, such that each `@node' line, with the exception of the
d5aa8b02 334Top node, is accompanied by some kind of section line, such as an
952d72ff
RC
335`@chapter' or `@section' line.
336
337If the file has a `top' node, it must be called `top' or `Top' and
338be the first node in the file.
339
d5aa8b02 340Entering Texinfo mode calls the value of text-mode-hook, and then the
952d72ff
RC
341value of texinfo-mode-hook."
342 (interactive)
343 (text-mode)
d7c9f762 344 (setq mode-name "Texinfo")
952d72ff
RC
345 (setq major-mode 'texinfo-mode)
346 (use-local-map texinfo-mode-map)
347 (set-syntax-table texinfo-mode-syntax-table)
c6cc04e9
RS
348 (make-local-variable 'page-delimiter)
349 (setq page-delimiter
350 (concat
351 "^@node [ \t]*[Tt]op\\|^@\\("
352 texinfo-chapter-level-regexp
353 "\\)"))
952d72ff
RC
354 (make-local-variable 'require-final-newline)
355 (setq require-final-newline t)
c6cc04e9
RS
356 (make-local-variable 'indent-tabs-mode)
357 (setq indent-tabs-mode nil)
952d72ff
RC
358 (make-local-variable 'paragraph-separate)
359 (setq paragraph-separate (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-separate))
360 (make-local-variable 'paragraph-start)
361 (setq paragraph-start (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-start))
362 (make-local-variable 'fill-column)
363 (setq fill-column 72)
364 (make-local-variable 'comment-start)
365 (setq comment-start "@c ")
366 (make-local-variable 'comment-start-skip)
367 (setq comment-start-skip "@c +")
368 (make-local-variable 'words-include-escapes)
369 (setq words-include-escapes t)
d78fc315 370 (make-local-variable 'tex-start-of-header)
c6cc04e9 371 (setq tex-start-of-header "%**start")
d78fc315 372 (make-local-variable 'tex-end-of-header)
c6cc04e9 373 (setq tex-end-of-header "%**end")
952d72ff
RC
374 (run-hooks 'text-mode-hook 'texinfo-mode-hook))
375
376\f
c6cc04e9
RS
377;;; Insert string commands
378
379(defconst texinfo-environment-regexp
380 "^@\\(f?table\\|enumerate\\|itemize\\|ifinfo\\|iftex\\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|end\\)"
381 "Regexp for environment-like TexInfo list commands.
382Subexpression 1 is what goes into the corresponding `@end' statement.")
383
384;; The following texinfo-insert-@end command not only inserts a SPC
385;; after the @end, but tries to find out what belongs there. It is
386;; not very smart: it does not understand nested lists.
387
388(defun texinfo-insert-@end ()
389 "Insert the matching `@end' for the last Texinfo command that needs one."
390 (interactive)
391 (let ((depth 1) string)
392 (save-excursion
393 (while (and (> depth 0)
394 (re-search-backward texinfo-environment-regexp nil t)
395 (if (looking-at "@end")
396 (setq depth (1+ depth))
397 (setq depth (1- depth)))))
398 (looking-at texinfo-environment-regexp)
399 (setq string
400 (buffer-substring (match-beginning 1)
401 (match-end 1))))
402 (insert "@end ")
403 (if string (insert string "\n"))))
404
405;; The following insert commands accept a prefix arg N, which is the
406;; number of words (actually s-exprs) that should be surrounded by
407;; braces. Thus you can first paste a variable name into a .texinfo
408;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
409;; pasted variable name to put @var{...} *around* the variable name.
410;; Operate on previous word or words with negative arg.
411
412;; These commands use texinfo-insert-@-with-arg
413(defun texinfo-insert-@-with-arg (string &optional arg)
414 (if arg
415 (progn
416 (setq arg (prefix-numeric-value arg))
417 (if (< arg 0)
418 (progn
419 (skip-chars-backward " \t\n\r\f")
420 (save-excursion
421 (forward-sexp arg)
422 (insert "@" string "{"))
423 (insert "}"))
424 (skip-chars-forward " \t\n\r\f")
425 (insert "@" string "{")
426 (forward-sexp arg)
427 (insert "}")))
428 (insert "@" string "{}")
429 (backward-char)))
430
431(defun texinfo-insert-braces ()
432 "Make a pair of braces and be poised to type inside of them.
433Use \\[up-list] to move forward out of the braces."
434 (interactive)
435 (insert "{}")
436 (backward-char))
437
438(defun texinfo-insert-@code (&optional arg)
439 "Insert a `@code{...}' command in a Texinfo buffer.
440A numeric argument says how many words the braces should surround.
441The default is not to surround any existing words with the braces."
442 (interactive "P")
443 (texinfo-insert-@-with-arg "code" arg))
444
445(defun texinfo-insert-@dfn (&optional arg)
446 "Insert a `@dfn{...}' command in a Texinfo buffer.
447A numeric argument says how many words the braces should surround.
448The default is not to surround any existing words with the braces."
449 (interactive "P")
450 (texinfo-insert-@-with-arg "dfn" arg))
952d72ff 451
c6cc04e9
RS
452(defun texinfo-insert-@example ()
453 "Insert the string `@example' in a Texinfo buffer."
454 (interactive)
455 (insert "@example\n"))
456
457(defun texinfo-insert-@file (&optional arg)
458 "Insert a `@file{...}' command in a Texinfo buffer.
459A numeric argument says how many words the braces should surround.
460The default is not to surround any existing words with the braces."
461 (interactive "P")
462 (texinfo-insert-@-with-arg "file" arg))
463
464(defun texinfo-insert-@item ()
465 "Insert the string `@item' in a Texinfo buffer."
466 (interactive)
467 (insert "@item")
468 (newline))
469
470(defun texinfo-insert-@kbd (&optional arg)
471 "Insert a `@kbd{...}' command in a Texinfo buffer.
472A numeric argument says how many words the braces should surround.
473The default is not to surround any existing words with the braces."
474 (interactive "P")
475 (texinfo-insert-@-with-arg "kbd" arg))
476
477(defun texinfo-insert-@node ()
478 "Insert the string `@node' in a Texinfo buffer.
479This also inserts on the following line a comment indicating
480the order of arguments to @node."
481 (interactive)
482 (insert "@node \n@comment node-name, next, previous, up")
483 (forward-line -1)
484 (forward-char 6))
485
486(defun texinfo-insert-@noindent ()
487 "Insert the string `@noindent' in a Texinfo buffer."
488 (interactive)
489 (insert "@noindent\n"))
490
491(defun texinfo-insert-@samp (&optional arg)
492 "Insert a `@samp{...}' command in a Texinfo buffer.
493A numeric argument says how many words the braces should surround.
494The default is not to surround any existing words with the braces."
495 (interactive "P")
496 (texinfo-insert-@-with-arg "samp" arg))
497
498(defun texinfo-insert-@table (&optional arg)
499 "Insert the string `@table' in a Texinfo buffer."
500 (interactive "P")
501 (insert "@table "))
502
503(defun texinfo-insert-@var (&optional arg)
504 "Insert a `@var{}' command in a Texinfo buffer.
505A numeric argument says how many words the braces should surround.
506The default is not to surround any existing words with the braces."
507 (interactive "P")
508 (texinfo-insert-@-with-arg "var" arg))
509\f
510;;; Texinfo file structure
952d72ff 511
d5aa8b02 512(defun texinfo-show-structure (&optional nodes-too)
952d72ff 513 "Show the structure of a Texinfo file.
d5aa8b02
RC
514List the lines in the file that begin with the @-sign commands for
515@chapter, @section, and the like.
516
517With optional argument (prefix if interactive), list both the lines
518with @-sign commands for @chapter, @section, and the like, and list
519@node lines.
952d72ff
RC
520
521Lines with structuring commands beginning in them are displayed in
c6cc04e9
RS
522another buffer named `*Occur*'. In that buffer, you can move point to
523one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
524to jump to the corresponding spot in the Texinfo source file."
952d72ff
RC
525
526 (interactive "P")
c6cc04e9 527 (require 'texnfo-upd)
952d72ff
RC
528 (save-excursion
529 (goto-char (point-min))
d5aa8b02
RC
530 (if nodes-too
531 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
532 (occur texinfo-section-types-regexp)))
952d72ff
RC
533 (pop-to-buffer "*Occur*")
534 (goto-char (point-min))
c6cc04e9
RS
535 (flush-lines "-----")
536 ;; Now format the "*Occur*" buffer to show the structure.
537 ;; Thanks to ceder@signum.se (Per Cederqvist)
538 (goto-char (point-max))
539 (let ((margin 5))
540 (while (re-search-backward "^ *[0-9]*:" nil 0)
541 (re-search-forward ":")
542 (setq margin
543 (cond
544 ((looking-at (concat "@" texinfo-chapter-level-regexp)) 5)
545 ;; ((looking-at "@chapter ") 5)
546 ;; ((looking-at "@unnumbered ") 5)
547 ;; ((looking-at "@appendix ") 5)
548 ;; ((looking-at "@majorheading ") 5)
549 ;; ((looking-at "@chapheading ") 5)
550
551 ((looking-at (concat "@" texinfo-section-level-regexp)) 9)
552 ;; ((looking-at "@section ") 9)
553 ;; ((looking-at "@unnumberedsec ") 9)
554 ;; ((looking-at "@appendixsec ") 9)
555 ;; ((looking-at "@heading ") 9)
556
557 ((looking-at (concat "@" texinfo-subsection-level-regexp)) 13)
558 ;; ((looking-at "@subsection ") 13)
559 ;; ((looking-at "@unnumberedsubsec ") 13)
560 ;; ((looking-at "@appendixsubsec ") 13)
561 ;; ((looking-at "@subheading ") 13)
562
563 ((looking-at (concat "@" texinfo-subsubsection-level-regexp)) 17)
564 ;; ((looking-at "@subsubsection ") 17)
565 ;; ((looking-at "@unnumberedsubsubsec ") 17)
566 ;; ((looking-at "@appendixsubsubsec ") 17)
567 ;; ((looking-at "@subsubheading ") 17)
568 (t margin)))
569 (indent-to-column margin)
570 (beginning-of-line))))
952d72ff
RC
571\f
572;;; The tex and print function definitions:
573
76a66e5e 574(defvar texinfo-tex-command "texi2dvi"
c6cc04e9 575 "*Command used by `texinfo-tex-region' to run TeX on a region.")
952d72ff 576
c6cc04e9
RS
577(defvar texinfo-texindex-command "texindex"
578 "*Command used by `texinfo-texindex' to sort unsorted index files.")
579
580(defvar texinfo-delete-from-print-queue-command "lprm"
581 "*Command string used to delete a job from the line printer queue.
582Command is used by \\[texinfo-delete-from-print-queue] based on
583number provided by a previous \\[tex-show-print-queue]
584command.")
585
586(defvar texinfo-tex-trailer "@bye"
587 "String appended after a region sent to TeX by `texinfo-tex-region'.")
952d72ff
RC
588
589(defun texinfo-tex-region (beg end)
c6cc04e9
RS
590 "Run TeX on the current region.
591This works by writing a temporary file (`tex-zap-file') in the directory
592that is the value of `tex-directory', then running TeX on that file.
593
594The first line of the buffer is copied to the
1433a222
CZ
595temporary file; and if the buffer has a header, it is written to the
596temporary file before the region itself. The buffer's header is all lines
597between the strings defined by `tex-start-of-header' and `tex-end-of-header'
c6cc04e9
RS
598inclusive. The header must start in the first 100 lines.
599
600The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
952d72ff 601 (interactive "r")
e67adf46 602 (require 'tex-mode)
952d72ff
RC
603 (if (get-buffer "*tex-shell*")
604 (tex-kill-job)
605 (tex-start-shell))
606 (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
607 (let ((tex-out-file (concat tex-zap-file ".tex"))
608 (temp-buffer (get-buffer-create " tex-Output-Buffer"))
609 (zap-directory
610 (file-name-as-directory (expand-file-name tex-directory))))
611 (save-excursion
612 (save-restriction
613 (widen)
614 (goto-char (point-min))
615 (forward-line 100)
616 (let ((search-end (point))
617 (hbeg (point-min)) (hend (point-min))
618 (default-directory zap-directory))
619 (goto-char (point-min))
620
621 ;; Copy first line, the `\input texinfo' line, to temp file
622 (write-region (point)
623 (save-excursion (end-of-line) (point))
624 tex-out-file nil nil)
625
626 ;; Don't copy first line twice if region includes it.
627 (forward-line 1)
628 (if (< beg (point)) (setq beg (point)))
629
630 ;; Initialize the temp file with either the header or nothing
631 (if (search-forward tex-start-of-header search-end t)
632 (progn
633 (beginning-of-line)
634 (setq hbeg (point)) ; Mark beginning of header.
635 (if (search-forward tex-end-of-header nil t)
636 (progn (beginning-of-line)
637 (setq hend (point))) ; Mark end of header.
638 (setq hbeg (point-min))))) ; Else no header.
639
640 ;; Copy header to temp file.
641 (write-region (min hbeg beg) hend tex-out-file t nil)
642
643 ;; Copy region to temp file.
644 (write-region (max beg hend) end tex-out-file t nil))
645
646 ;; This is a kludge to insert the tex-trailer into the tex-out-file.
647 ;; We have to create a special buffer in which to insert
648 ;; the tex-trailer first because there is no function with
649 ;; which to append a literal string directly to a file.
c6cc04e9 650 (let ((local-tex-trailer texinfo-tex-trailer))
952d72ff
RC
651 (set-buffer temp-buffer)
652 (erase-buffer)
653 ;; make sure trailer isn't hidden by a comment
654 (insert-string "\n")
655 (if local-tex-trailer (insert-string local-tex-trailer))
c678a343 656 (tex-set-buffer-directory temp-buffer zap-directory)
c6cc04e9
RS
657 (write-region (point-min) (point-max) tex-out-file t nil))
658
659;;; The following is sufficient in Emacs 19.
660;;; (write-region (concat "\n" texinfo-tex-trailer) nil
661;;; tex-out-file t nil)
662 ))
952d72ff 663
c678a343 664 (tex-set-buffer-directory "*tex-shell*" zap-directory)
952d72ff
RC
665 (send-string "tex-shell" (concat tex-shell-cd-command " "
666 zap-directory "\n"))
667 (send-string "tex-shell" (concat texinfo-tex-command " "
668 tex-out-file "\n")))
669 (tex-recenter-output-buffer 0))
670
671(defun texinfo-tex-buffer ()
c6cc04e9
RS
672 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
673 (interactive)
674
675 ;; Make sure TeX shell is running.
676 (if (get-buffer "*tex-shell*")
677 (quit-process (get-process "tex-shell") t)
678 (tex-start-shell))
679
680 (cond ((null buffer-file-name)
681 (error "Buffer not visiting any file!"))
682 ((buffer-modified-p)
683 (error "Buffer has been modified since last saved!")))
684
685 (setq tex-zap-file buffer-file-name)
686
687 (send-string "tex-shell"
688 (concat tex-shell-cd-command
689 " " (file-name-directory tex-zap-file) "\n"))
690
691 (send-string "tex-shell"
692 (concat texinfo-tex-command " " tex-zap-file "\n"))
693
694 (tex-recenter-output-buffer 0))
695
696(defun texinfo-texindex ()
697 "Run `texindex' on unsorted index files.
698The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
699This runs the shell command defined by `texinfo-texindex-command'."
952d72ff 700 (interactive)
c6cc04e9
RS
701 (require 'tex-mode)
702 (send-string "tex-shell"
703 (concat texinfo-texindex-command
704 " " tex-zap-file ".??" "\n"))
705 (tex-recenter-output-buffer nil))
952d72ff
RC
706
707(defun texinfo-tex-print ()
c6cc04e9
RS
708 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
709This runs the shell command defined by `tex-dvi-print-command'."
952d72ff 710 (interactive)
e67adf46 711 (require 'tex-mode)
952d72ff
RC
712 (send-string "tex-shell"
713 (concat tex-dvi-print-command
714 " " tex-zap-file ".dvi" "\n"))
715 (tex-recenter-output-buffer nil))
716
c6cc04e9
RS
717(defun texinfo-quit-job ()
718 "Quit currently running TeX job, by sending an `x' to it."
719 (interactive)
720 (if (not (get-process "tex-shell"))
721 (error "No TeX shell running"))
722 (save-excursion
723 (set-buffer (get-buffer "*tex-shell*"))
724 (goto-char (point-max))
725 (insert "x")
726 (shell-send-input)))
727
728(defun texinfo-delete-from-print-queue (job-number)
729 "Delete job from the line printer spooling queue.
730You are prompted for the job number (use a number shown by a previous
731\\[texinfo-show-tex-print-queue] command)."
732 (interactive "nPrinter job number for deletion: ")
733 (if (tex-shell-running)
734 (tex-kill-job)
735 (tex-start-shell))
736 (send-string "tex-shell"
737 (concat
738 texinfo-delete-from-print-queue-command
739 " "
740 job-number"\n"))
741 (tex-recenter-output-buffer nil))
742
49116ac0
JB
743(provide 'texinfo)
744
d501f516 745;;; texinfo.el ends here