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