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