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