1 ;;; texinfo.el --- major mode for editing Texinfo files
3 ;; Copyright (C) 1985, '88, '89, '90, '91,
4 ;; '92, '93, '96, '97 Free Software Foundation, Inc.
6 ;; Author: Robert J. Chassell
7 ;; Date: [Set date below for texinfo-version]
8 ;; Maintainer: bug-texinfo@gnu.org
9 ;; Keywords: maint, tex, docs
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 (or (fboundp 'defgroup)
31 (defmacro defgroup (&rest ignore) nil))
33 (or (fboundp 'defcustom)
34 (defmacro defcustom (var value doc &rest ignore)
35 `(defvar ,var ,value ,doc)))
44 (autoload 'makeinfo-region
46 "Make Info file from region of current Texinfo file, and switch to it.
48 This command does not offer the `next-error' feature since it would
49 apply to a temporary file, not the original; use the `makeinfo-buffer'
50 command to gain use of `next-error'."
53 (autoload 'makeinfo-buffer
55 "Make Info file from current buffer.
57 Use the \\[next-error] command to move to the next error
58 \(if there are errors\)."
61 (autoload 'kill-compilation
63 "Kill the process made by the \\[compile] command."
66 (autoload 'makeinfo-recenter-compilation-buffer
68 "Redisplay `*compilation*' buffer so most recent output can be seen.
69 The last line of the buffer is displayed on
70 line LINE of the window, or centered if LINE is nil."
73 (autoload 'texinfo-update-node
75 "Without any prefix argument, update the node in which point is located.
76 Non-nil argument (prefix, if interactive) means update the nodes in the
79 The functions for creating or updating nodes and menus, and their
82 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
83 texinfo-every-node-update () \\[texinfo-every-node-update]
84 texinfo-sequential-node-update (&optional region-p)
86 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
87 texinfo-all-menus-update () \\[texinfo-all-menus-update]
88 texinfo-master-menu ()
90 texinfo-indent-menu-description (column &optional region-p)
92 The `texinfo-column-for-description' variable specifies the column to
93 which menu descriptions are indented. Its default value is 32."
96 (autoload 'texinfo-every-node-update
98 "Update every node in a Texinfo file."
101 (autoload 'texinfo-sequential-node-update
103 "Update one node (or many) in a Texinfo file with sequential pointers.
105 This function causes the `Next' or `Previous' pointer to point to the
106 immediately preceding or following node, even if it is at a higher or
107 lower hierarchical level in the document. Continually pressing `n' or
108 `p' takes you straight through the file.
110 Without any prefix argument, update the node in which point is located.
111 Non-nil argument (prefix, if interactive) means update the nodes in the
114 This command makes it awkward to navigate among sections and
115 subsections; it should be used only for those documents that are meant
116 to be read like a novel rather than a reference, and for which the
117 Info `g*' command is inadequate."
120 (autoload 'texinfo-make-menu
122 "Without any prefix argument, make or update a menu.
123 Make the menu for the section enclosing the node found following point.
125 Non-nil argument (prefix, if interactive) means make or update menus
126 for nodes within or part of the marked region.
128 Whenever a menu exists, and is being updated, the descriptions that
129 are associated with node names in the pre-existing menu are
130 incorporated into the new menu. Otherwise, the nodes' section titles
131 are inserted as descriptions."
134 (autoload 'texinfo-all-menus-update
136 "Update every regular menu in a Texinfo file.
137 Remove pre-existing master menu, if there is one.
139 If called with a non-nil argument, this function first updates all the
140 nodes in the buffer before updating the menus."
143 (autoload 'texinfo-master-menu
145 "Make a master menu for a whole Texinfo file.
146 Non-nil argument (prefix, if interactive) means first update all
147 existing nodes and menus. Remove pre-existing master menu, if there is one.
149 This function creates a master menu that follows the top node. The
150 master menu includes every entry from all the other menus. It
151 replaces any existing ordinary menu that follows the top node.
153 If called with a non-nil argument, this function first updates all the
154 menus in the buffer (incorporating descriptions from pre-existing
155 menus) before it constructs the master menu.
157 The function removes the detailed part of an already existing master
158 menu. This action depends on the pre-existing master menu using the
159 standard `texinfo-master-menu-header'.
161 The master menu has the following format, which is adapted from the
162 recommendation in the Texinfo Manual:
164 * The first part contains the major nodes in the Texinfo file: the
165 nodes for the chapters, chapter-like sections, and the major
166 appendices. This includes the indices, so long as they are in
167 chapter-like sections, such as unnumbered sections.
169 * The second and subsequent parts contain a listing of the other,
170 lower level menus, in order. This way, an inquirer can go
171 directly to a particular node if he or she is searching for
172 specific information.
174 Each of the menus in the detailed node listing is introduced by the
175 title of the section containing the menu."
178 (autoload 'texinfo-indent-menu-description
180 "Indent every description in menu following point to COLUMN.
181 Non-nil argument (prefix, if interactive) means indent every
182 description in every menu in the region. Does not indent second and
183 subsequent lines of a multi-line description."
186 (autoload 'texinfo-insert-node-lines
188 "Insert missing `@node' lines in region of Texinfo file.
189 Non-nil argument (prefix, if interactive) means also to insert the
190 section titles as node names; and also to insert the section titles as
191 node names in pre-existing @node lines that lack names."
194 (autoload 'texinfo-start-menu-description
196 "In this menu entry, insert the node's section title as a description.
197 Position point at beginning of description ready for editing.
198 Do not insert a title if the line contains an existing description.
200 You will need to edit the inserted text since a useful description
201 complements the node name rather than repeats it as a title does."
204 (autoload 'texinfo-multiple-files-update
206 "Update first node pointers in each file included in OUTER-FILE;
207 create or update main menu in the outer file that refers to such nodes.
208 This does not create or update menus or pointers within the included files.
210 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
211 insert a master menu in OUTER-FILE. This does not create or update
212 menus or pointers within the included files.
214 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
215 interactive), update all the menus and all the `Next', `Previous', and
216 `Up' pointers of all the files included in OUTER-FILE before inserting
217 a master menu in OUTER-FILE.
219 The command also updates the `Top' level node pointers of OUTER-FILE.
223 * this command does NOT save any files--you must save the
224 outer file and any modified, included files.
226 * except for the `Top' node, this command does NOT handle any
227 pre-existing nodes in the outer file; hence, indices must be
228 enclosed in an included file.
232 * each of the included files must contain exactly one highest
233 hierarchical level node,
234 * this highest node must be the first node in the included file,
235 * each highest hierarchical level node must be of the same type.
237 Thus, normally, each included file contains one, and only one,
244 ;;; Don't you dare insert any `require' calls at top level in this file--rms.
248 (defvar texinfo-mode-syntax-table nil)
250 (if texinfo-mode-syntax-table
252 (setq texinfo-mode-syntax-table (make-syntax-table))
253 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
254 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
255 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
256 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
257 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
258 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
259 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
260 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
261 (modify-syntax-entry ?\n ">" texinfo-mode-syntax-table)
262 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
264 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
265 ;; To override this example, set either `imenu-generic-expression'
266 ;; or `imenu-create-index-function'.
267 (defvar texinfo-imenu-generic-expression
268 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
269 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
271 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
273 (defvar texinfo-font-lock-syntactic-keywords
274 '(("\\(@\\)c\\(omment\\)?\\>" (1 '(11))))
275 "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
277 (defvar texinfo-font-lock-keywords
278 '(;; All but the first had an OVERRIDE of t.
279 ;; It didn't seem to be any better, and it's slower--simon.
280 ;; Robert J. Chassell <bob@gnu.org> says remove this line.
281 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
282 ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
283 ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
284 ("@\\(emph\\|strong\\|b\\|i\\|sc\\){\\([^}]+\\)" 2 font-lock-comment-face)
285 ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
286 ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
287 2 font-lock-variable-name-face)
288 ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face)
289 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
291 "Additional expressions to highlight in TeXinfo mode.")
293 (defvar texinfo-section-list
305 ("unnumberedsubsec" 4)
309 ("unnumberedsubsubsec" 5)
310 ("appendixsubsubsec" 5)
312 "Alist of sectioning commands and their relative level.")
314 (defun texinfo-outline-level ()
315 ;; Calculate level of current texinfo outline heading.
320 (let* ((word (buffer-substring-no-properties
321 (point) (progn (forward-word 1) (point))))
322 (entry (assoc word texinfo-section-list)))
329 (defvar texinfo-mode-map nil)
331 ;;; Keys common both to Texinfo mode and to TeX shell.
333 (defun texinfo-define-common-keys (keymap)
334 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
335 (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
336 (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
337 (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
338 (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
339 (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
340 (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
341 (define-key keymap "\C-c\C-t\C-v" 'texinfo-tex-view)
342 (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
344 (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
345 (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
347 ;; Mode documentation displays commands in reverse order
348 ;; from how they are listed in the texinfo-mode-map.
352 (setq texinfo-mode-map (make-sparse-keymap))
354 ;; bindings for `texnfo-tex.el'
355 (texinfo-define-common-keys texinfo-mode-map)
357 ;; Bindings from `tex-mode.el'
358 ;; This should still use " when inside @example and @code
359 ;;(define-key texinfo-mode-map "\"" 'tex-insert-quote)
361 ;; bindings for `makeinfo.el'
362 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
363 (define-key texinfo-mode-map "\C-c\C-m\C-l"
364 'makeinfo-recenter-compilation-buffer)
365 (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
366 (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
368 ;; bindings for `texinfmt.el'
369 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
370 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
372 ;; bindings for updating nodes and menus
374 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
376 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
377 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
378 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
379 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
381 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
383 (define-key texinfo-mode-map "\C-c}" 'up-list)
384 (define-key texinfo-mode-map "\C-c]" 'up-list)
385 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
387 ;; bindings for inserting strings
388 (define-key texinfo-mode-map "\C-c\C-o" 'texinfo-insert-block)
389 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
390 (define-key texinfo-mode-map "\C-c\C-c\C-s" 'texinfo-insert-@strong)
391 (define-key texinfo-mode-map "\C-c\C-c\C-e" 'texinfo-insert-@emph)
393 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
394 (define-key texinfo-mode-map "\C-c\C-cu" 'texinfo-insert-@url)
395 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
396 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
397 ;; (define-key texinfo-mode-map "\C-c\C-cr" 'texinfo-insert-@uref)
398 (define-key texinfo-mode-map "\C-c\C-cq" 'texinfo-insert-@quotation)
399 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
400 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
401 (define-key texinfo-mode-map "\C-c\C-cm" 'texinfo-insert-@email)
402 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
403 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
404 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
405 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
406 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
407 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
408 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
413 ;; Also defined in texnfo-upd.el but copied here to avoid having
414 ;; to require texnfo-upd.el.
415 (defvar texinfo-chapter-level-regexp
416 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
417 "Regular expression matching Texinfo chapter-level headings.
418 This does not match `@node' and does not match the `@top' command.")
421 (define-derived-mode texinfo-mode text-mode "Texinfo"
422 "Major mode for editing Texinfo files.
424 It has these extra commands:
427 These are files that are used as input for TeX to make printed manuals
428 and also to be turned into Info files with \\[makeinfo-buffer] or
429 the `makeinfo' program. These files must be written in a very restricted and
430 modified version of TeX input format.
432 Editing commands are like text-mode except that the syntax table is
433 set up so expression commands skip Texinfo bracket groups. To see
434 what the Info version of a region of the Texinfo file will look like,
435 use \\[makeinfo-region], which runs `makeinfo' on the current region.
437 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
438 This command shows the structure of a Texinfo file by listing the
439 lines with the @-sign commands for @chapter, @section, and the like.
440 These lines are displayed in another window called the *Occur* window.
441 In that window, you can position the cursor over one of the lines and
442 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
445 In addition, Texinfo mode provides commands that insert various
446 frequently used @-sign commands into the buffer. You can use these
447 commands to save keystrokes. And you can insert balanced braces with
448 \\[texinfo-insert-braces] and later use the command \\[up-list] to
449 move forward past the closing brace.
451 Also, Texinfo mode provides functions for automatically creating or
452 updating menus and node pointers. These functions
454 * insert the `Next', `Previous' and `Up' pointers of a node,
455 * insert or update the menu for a section, and
456 * create a master menu for a Texinfo source file.
458 Here are the functions:
460 texinfo-update-node \\[texinfo-update-node]
461 texinfo-every-node-update \\[texinfo-every-node-update]
462 texinfo-sequential-node-update
464 texinfo-make-menu \\[texinfo-make-menu]
465 texinfo-all-menus-update \\[texinfo-all-menus-update]
468 texinfo-indent-menu-description (column &optional region-p)
470 The `texinfo-column-for-description' variable specifies the column to
471 which menu descriptions are indented.
473 Passed an argument (a prefix argument, if interactive), the
474 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
477 To use the updating commands, you must structure your Texinfo file
478 hierarchically, such that each `@node' line, with the exception of the
479 Top node, is accompanied by some kind of section line, such as an
480 `@chapter' or `@section' line.
482 If the file has a `top' node, it must be called `top' or `Top' and
483 be the first node in the file.
485 Entering Texinfo mode calls the value of `text-mode-hook', and then the
486 value of `texinfo-mode-hook'."
487 (make-local-variable 'page-delimiter)
490 "^@node [ \t]*[Tt]op\\|^@\\("
491 texinfo-chapter-level-regexp
493 (make-local-variable 'require-final-newline)
494 (setq require-final-newline t)
495 (make-local-variable 'indent-tabs-mode)
496 (setq indent-tabs-mode nil)
497 (make-local-variable 'paragraph-separate)
498 (setq paragraph-separate
499 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
500 (make-local-variable 'paragraph-start)
501 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
502 (make-local-variable 'adaptive-fill-mode)
503 (setq adaptive-fill-mode nil)
504 (make-local-variable 'fill-column)
505 (setq fill-column 72)
506 (make-local-variable 'comment-start)
507 (setq comment-start "@c ")
508 (make-local-variable 'comment-start-skip)
509 (setq comment-start-skip "@c +\\|@comment +")
510 (make-local-variable 'words-include-escapes)
511 (setq words-include-escapes t)
512 (make-local-variable 'imenu-generic-expression)
513 (setq imenu-generic-expression texinfo-imenu-generic-expression)
514 (setq imenu-case-fold-search nil)
515 (make-local-variable 'font-lock-defaults)
516 (setq font-lock-defaults
517 '(texinfo-font-lock-keywords nil nil nil nil
518 (font-lock-syntactic-keywords
519 . texinfo-font-lock-syntactic-keywords)))
520 (set (make-local-variable 'parse-sexp-lookup-properties) t)
521 (make-local-variable 'outline-regexp)
523 (concat "@" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\>"))
524 (make-local-variable 'outline-level)
525 (setq outline-level 'texinfo-outline-level)
526 (make-local-variable 'tex-start-of-header)
527 (setq tex-start-of-header "%\\*\\*start")
528 (make-local-variable 'tex-end-of-header)
529 (setq tex-end-of-header "%\\*\\*end")
530 (make-local-variable 'tex-first-line-header-regexp)
531 (setq tex-first-line-header-regexp "^\\\\input")
532 (make-local-variable 'tex-trailer)
533 (setq tex-trailer "@bye\n"))
536 ;;; Insert string commands
538 (defconst texinfo-environments
587 "List of TeXinfo environments.")
589 ;; Keep as concatenated lists for ease of maintenance
590 (defconst texinfo-environment-regexp
591 (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
592 "Regexp for environment-like TexInfo list commands.
593 Subexpression 1 is what goes into the corresponding `@end' statement.")
595 (define-skeleton texinfo-insert-block
596 "Create a matching pair @<cmd> .. @end <cmd> at point.
597 Puts point on a blank line between them."
598 (completing-read "Block name: " (mapcar 'list texinfo-environments))
599 "@" str \n _ \n "@end " str \n)
601 ;; The following texinfo-insert-@end command not only inserts a SPC
602 ;; after the @end, but tries to find out what belongs there. It is
603 ;; not very smart: it does not understand nested lists.
605 (defun texinfo-insert-@end ()
606 "Insert the matching `@end' for the last Texinfo command that needs one."
608 (let ((depth 1) string)
610 (while (and (> depth 0)
611 (re-search-backward texinfo-environment-regexp nil t))
612 (if (looking-at "@end")
613 (setq depth (1+ depth))
614 (setq depth (1- depth))))
615 (looking-at texinfo-environment-regexp)
618 (buffer-substring (match-beginning 1)
621 (if string (insert string "\n"))))
623 ;; The following insert commands accept a prefix arg N, which is the
624 ;; number of words (actually s-exprs) that should be surrounded by
625 ;; braces. Thus you can first paste a variable name into a .texinfo
626 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
627 ;; pasted variable name to put @var{...} *around* the variable name.
628 ;; Operate on previous word or words with negative arg.
630 ;; These commands use texinfo-insert-@-with-arg
631 (defun texinfo-insert-@-with-arg (string &optional arg)
634 (setq arg (prefix-numeric-value arg))
637 (skip-chars-backward " \t\n\r\f")
640 (insert "@" string "{"))
642 (skip-chars-forward " \t\n\r\f")
643 (insert "@" string "{")
646 (insert "@" string "{}")
649 (defun texinfo-insert-braces ()
650 "Make a pair of braces and be poised to type inside of them.
651 Use \\[up-list] to move forward out of the braces."
656 (defun texinfo-insert-@code (&optional arg)
657 "Insert a `@code{...}' command in a Texinfo buffer.
658 A numeric argument says how many words the braces should surround.
659 The default is not to surround any existing words with the braces."
661 (texinfo-insert-@-with-arg "code" arg))
663 (defun texinfo-insert-@dfn (&optional arg)
664 "Insert a `@dfn{...}' command in a Texinfo buffer.
665 A numeric argument says how many words the braces should surround.
666 The default is not to surround any existing words with the braces."
668 (texinfo-insert-@-with-arg "dfn" arg))
670 (defun texinfo-insert-@email (&optional arg)
671 "Insert a `@email{...}' command in a Texinfo buffer.
672 A numeric argument says how many words the braces should surround.
673 The default is not to surround any existing words with the braces."
675 (texinfo-insert-@-with-arg "email" arg))
677 (defun texinfo-insert-@emph (&optional arg)
678 "Insert a `@emph{...}' command in a Texinfo buffer.
679 A numeric argument says how many words the braces should surround.
680 The default is not to surround any existing words with the braces."
682 (texinfo-insert-@-with-arg "emph" arg))
684 (defun texinfo-insert-@example ()
685 "Insert the string `@example' in a Texinfo buffer."
687 (insert "@example\n"))
689 (defun texinfo-insert-@file (&optional arg)
690 "Insert a `@file{...}' command in a Texinfo buffer.
691 A numeric argument says how many words the braces should surround.
692 The default is not to surround any existing words with the braces."
694 (texinfo-insert-@-with-arg "file" arg))
696 (defun texinfo-insert-@item ()
697 "Insert the string `@item' in a Texinfo buffer."
702 (defun texinfo-insert-@kbd (&optional arg)
703 "Insert a `@kbd{...}' command in a Texinfo buffer.
704 A numeric argument says how many words the braces should surround.
705 The default is not to surround any existing words with the braces."
707 (texinfo-insert-@-with-arg "kbd" arg))
709 (defun texinfo-insert-@node ()
710 "Insert the string `@node' in a Texinfo buffer.
711 This also inserts on the following line a comment indicating
712 the order of arguments to @node."
714 (insert "@node \n@comment node-name, next, previous, up")
718 (defun texinfo-insert-@noindent ()
719 "Insert the string `@noindent' in a Texinfo buffer."
721 (insert "@noindent\n"))
723 (defun texinfo-insert-@quotation ()
724 "Insert the string `@quotation' in a Texinfo buffer."
726 (insert "@quotation\n"))
728 (defun texinfo-insert-@samp (&optional arg)
729 "Insert a `@samp{...}' command in a Texinfo buffer.
730 A numeric argument says how many words the braces should surround.
731 The default is not to surround any existing words with the braces."
733 (texinfo-insert-@-with-arg "samp" arg))
735 (defun texinfo-insert-@strong (&optional arg)
736 "Insert a `@strong{...}' command in a Texinfo buffer.
737 A numeric argument says how many words the braces should surround.
738 The default is not to surround any existing words with the braces."
740 (texinfo-insert-@-with-arg "strong" arg))
742 (defun texinfo-insert-@table (&optional arg)
743 "Insert the string `@table' in a Texinfo buffer."
747 (defun texinfo-insert-@var (&optional arg)
748 "Insert a `@var{}' command in a Texinfo buffer.
749 A numeric argument says how many words the braces should surround.
750 The default is not to surround any existing words with the braces."
752 (texinfo-insert-@-with-arg "var" arg))
754 (defun texinfo-insert-@url (&optional arg)
755 "Insert a `@url{}' command in a Texinfo buffer.
756 A numeric argument says how many words the braces should surround.
757 The default is not to surround any existing words with the braces."
759 (texinfo-insert-@-with-arg "url" arg))
761 ;;; Texinfo file structure
763 ;; These are defined in texnfo-upd.el. defvars here avoid warnings.
764 (defvar texinfo-section-types-regexp)
765 (defvar texinfo-section-level-regexp)
766 (defvar texinfo-subsection-level-regexp)
767 (defvar texinfo-subsubsection-level-regexp)
769 (defun texinfo-show-structure (&optional nodes-too)
770 "Show the structure of a Texinfo file.
771 List the lines in the file that begin with the @-sign commands for
772 @chapter, @section, and the like.
774 With optional argument (prefix if interactive), list both the lines
775 with @-sign commands for @chapter, @section, and the like, and list
778 Lines with structuring commands beginning in them are displayed in
779 another buffer named `*Occur*'. In that buffer, you can move point to
780 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
781 to jump to the corresponding spot in the Texinfo source file."
784 (require 'texnfo-upd)
786 (goto-char (point-min))
788 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
789 (occur texinfo-section-types-regexp)))
790 (pop-to-buffer "*Occur*")
791 (goto-char (point-min))
792 (let ((inhibit-read-only t))
793 (flush-lines "-----")
794 ;; Now format the "*Occur*" buffer to show the structure.
795 ;; Thanks to ceder@signum.se (Per Cederqvist)
796 (goto-char (point-max))
798 (while (re-search-backward "^ *[0-9]*:" nil 0)
799 (re-search-forward ":")
803 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
804 ;; ((looking-at "@chapter ") 5)
805 ;; ((looking-at "@unnumbered ") 5)
806 ;; ((looking-at "@appendix ") 5)
807 ;; ((looking-at "@majorheading ") 5)
808 ;; ((looking-at "@chapheading ") 5)
811 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
812 ;; ((looking-at "@section ") 9)
813 ;; ((looking-at "@unnumberedsec ") 9)
814 ;; ((looking-at "@appendixsec ") 9)
815 ;; ((looking-at "@heading ") 9)
818 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
819 ;; ((looking-at "@subsection ") 13)
820 ;; ((looking-at "@unnumberedsubsec ") 13)
821 ;; ((looking-at "@appendixsubsec ") 13)
822 ;; ((looking-at "@subheading ") 13)
825 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
826 ;; ((looking-at "@subsubsection ") 17)
827 ;; ((looking-at "@unnumberedsubsubsec ") 17)
828 ;; ((looking-at "@appendixsubsubsec ") 17)
829 ;; ((looking-at "@subsubheading ") 17)
831 (indent-to-column margin)
832 (beginning-of-line)))))
834 ;;; The tex and print function definitions:
836 (defcustom texinfo-texi2dvi-command "texi2dvi"
837 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
841 (defcustom texinfo-tex-command "tex"
842 "*Command used by `texinfo-tex-region' to run TeX on a region."
846 (defcustom texinfo-texindex-command "texindex"
847 "*Command used by `texinfo-texindex' to sort unsorted index files."
851 (defcustom texinfo-delete-from-print-queue-command "lprm"
852 "*Command string used to delete a job from the line printer queue.
853 Command is used by \\[texinfo-delete-from-print-queue] based on
854 number provided by a previous \\[tex-show-print-queue]
859 (defvar texinfo-tex-trailer "@bye"
860 "String appended after a region sent to TeX by `texinfo-tex-region'.")
862 (defun texinfo-tex-region (beg end)
863 "Run TeX on the current region.
864 This works by writing a temporary file (`tex-zap-file') in the directory
865 that is the value of `tex-directory', then running TeX on that file.
867 The first line of the buffer is copied to the
868 temporary file; and if the buffer has a header, it is written to the
869 temporary file before the region itself. The buffer's header is all lines
870 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
871 inclusive. The header must start in the first 100 lines.
873 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
876 (let ((tex-command texinfo-tex-command)
877 (tex-trailer texinfo-tex-trailer))
878 (tex-region beg end)))
880 (defun texinfo-tex-buffer ()
881 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
884 (let ((tex-command texinfo-texi2dvi-command)
885 ;; Disable tex-start-options-string. texi2dvi would not
886 ;; understand anything specified here.
887 (tex-start-options-string ""))
890 (defun texinfo-texindex ()
891 "Run `texindex' on unsorted index files.
892 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
893 This runs the shell command defined by `texinfo-texindex-command'."
896 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
898 ;; (send-string "tex-shell"
899 ;; (concat texinfo-texindex-command
900 ;; " " tex-zap-file ".??" "\n"))
901 (tex-recenter-output-buffer nil))
903 (defun texinfo-tex-print ()
904 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
905 This runs the shell command defined by `tex-dvi-print-command'."
910 (defun texinfo-tex-view ()
911 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
912 This runs the shell command defined by `tex-dvi-view-command'."
917 (defun texinfo-quit-job ()
918 "Quit currently running TeX job, by sending an `x' to it."
920 (if (not (get-process "tex-shell"))
921 (error "No TeX shell running"))
922 (tex-send-command "x"))
925 ;; (set-buffer (get-buffer "*tex-shell*"))
926 ;; (goto-char (point-max))
928 ;; (comint-send-input)
930 (defun texinfo-delete-from-print-queue (job-number)
931 "Delete job from the line printer spooling queue.
932 You are prompted for the job number (use a number shown by a previous
933 \\[tex-show-print-queue] command)."
934 (interactive "nPrinter job number for deletion: ")
936 (if (tex-shell-running)
939 (tex-send-command texinfo-delete-from-print-queue-command job-number)
941 ;; (send-string "tex-shell"
943 ;; texinfo-delete-from-print-queue-command
946 (tex-recenter-output-buffer nil))
950 ;;; texinfo.el ends here