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.
246 (defvar texinfo-section-list
258 ("unnumberedsubsec" 4)
262 ("unnumberedsubsubsec" 5)
263 ("appendixsubsubsec" 5)
265 "Alist of sectioning commands and their relative level.")
269 (defvar texinfo-mode-syntax-table nil
)
271 (if texinfo-mode-syntax-table
273 (setq texinfo-mode-syntax-table
(make-syntax-table))
274 (modify-syntax-entry ?
\" " " texinfo-mode-syntax-table
)
275 (modify-syntax-entry ?
\\ " " texinfo-mode-syntax-table
)
276 (modify-syntax-entry ?
@ "\\" texinfo-mode-syntax-table
)
277 (modify-syntax-entry ?\^q
"\\" texinfo-mode-syntax-table
)
278 (modify-syntax-entry ?\
[ "(]" texinfo-mode-syntax-table
)
279 (modify-syntax-entry ?\
] ")[" texinfo-mode-syntax-table
)
280 (modify-syntax-entry ?
{ "(}" texinfo-mode-syntax-table
)
281 (modify-syntax-entry ?
} "){" texinfo-mode-syntax-table
)
282 (modify-syntax-entry ?
\n ">" texinfo-mode-syntax-table
)
283 (modify-syntax-entry ?
\' "w" texinfo-mode-syntax-table
))
285 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
286 ;; To override this example, set either `imenu-generic-expression'
287 ;; or `imenu-create-index-function'.
288 (defvar texinfo-imenu-generic-expression
289 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
290 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
291 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
293 (defvar texinfo-font-lock-syntactic-keywords
294 '(("\\(@\\)c\\(omment\\)?\\>" (1 '(11)))
295 ("^\\(@\\)ignore\\>" (1 '(2097163)))
296 ("^@end ignore\\(\n\\)" (1 '(2097164))))
297 "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
299 (defface texinfo-heading-face
300 '((t (:inherit font-lock-function-name-face
)))
301 "Face used for section headings in `texinfo-mode'.")
302 (defvar texinfo-heading-face
'texinfo-heading-face
)
304 (defvar texinfo-font-lock-keywords
305 `(;; All but the first had an OVERRIDE of t.
306 ;; It didn't seem to be any better, and it's slower--simon.
307 ;; Robert J. Chassell <bob@gnu.org> says remove this line.
308 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
309 ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face
) ;commands
310 ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t
) ;menu items
311 ("@\\(emph\\|strong\\|b\\|i\\|sc\\){\\([^}]+\\)" 2 font-lock-comment-face
)
312 ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face
)
313 ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
314 2 font-lock-variable-name-face
)
315 ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face
)
316 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep
)
317 (,(concat "^@" (regexp-opt (mapcar 'car texinfo-section-list
) t
)
318 ".*\n") 0 texinfo-heading-face t
))
319 "Additional expressions to highlight in TeXinfo mode.")
321 (defun texinfo-outline-level ()
322 ;; Calculate level of current texinfo outline heading.
327 (let* ((word (buffer-substring-no-properties
328 (point) (progn (forward-word 1) (point))))
329 (entry (assoc word texinfo-section-list
)))
336 (defvar texinfo-mode-map nil
)
338 ;;; Keys common both to Texinfo mode and to TeX shell.
340 (defun texinfo-define-common-keys (keymap)
341 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
342 (define-key keymap
"\C-c\C-t\C-k" 'tex-kill-job
)
343 (define-key keymap
"\C-c\C-t\C-x" 'texinfo-quit-job
)
344 (define-key keymap
"\C-c\C-t\C-l" 'tex-recenter-output-buffer
)
345 (define-key keymap
"\C-c\C-t\C-d" 'texinfo-delete-from-print-queue
)
346 (define-key keymap
"\C-c\C-t\C-q" 'tex-show-print-queue
)
347 (define-key keymap
"\C-c\C-t\C-p" 'texinfo-tex-print
)
348 (define-key keymap
"\C-c\C-t\C-v" 'texinfo-tex-view
)
349 (define-key keymap
"\C-c\C-t\C-i" 'texinfo-texindex
)
351 (define-key keymap
"\C-c\C-t\C-r" 'texinfo-tex-region
)
352 (define-key keymap
"\C-c\C-t\C-b" 'texinfo-tex-buffer
))
354 ;; Mode documentation displays commands in reverse order
355 ;; from how they are listed in the texinfo-mode-map.
359 (setq texinfo-mode-map
(make-sparse-keymap))
361 ;; bindings for `texnfo-tex.el'
362 (texinfo-define-common-keys texinfo-mode-map
)
364 (define-key texinfo-mode-map
"\"" 'texinfo-insert-quote
)
366 ;; bindings for `makeinfo.el'
367 (define-key texinfo-mode-map
"\C-c\C-m\C-k" 'kill-compilation
)
368 (define-key texinfo-mode-map
"\C-c\C-m\C-l"
369 'makeinfo-recenter-compilation-buffer
)
370 (define-key texinfo-mode-map
"\C-c\C-m\C-r" 'makeinfo-region
)
371 (define-key texinfo-mode-map
"\C-c\C-m\C-b" 'makeinfo-buffer
)
373 ;; bindings for `texinfmt.el'
374 (define-key texinfo-mode-map
"\C-c\C-e\C-r" 'texinfo-format-region
)
375 (define-key texinfo-mode-map
"\C-c\C-e\C-b" 'texinfo-format-buffer
)
377 ;; AUCTeX-like bindings
378 (define-key texinfo-mode-map
"\e\r" 'texinfo-insert-
@item
)
380 ;; bindings for updating nodes and menus
382 (define-key texinfo-mode-map
"\C-c\C-um" 'texinfo-master-menu
)
384 (define-key texinfo-mode-map
"\C-c\C-u\C-m" 'texinfo-make-menu
)
385 (define-key texinfo-mode-map
"\C-c\C-u\C-n" 'texinfo-update-node
)
386 (define-key texinfo-mode-map
"\C-c\C-u\C-e" 'texinfo-every-node-update
)
387 (define-key texinfo-mode-map
"\C-c\C-u\C-a" 'texinfo-all-menus-update
)
389 (define-key texinfo-mode-map
"\C-c\C-s" 'texinfo-show-structure
)
391 (define-key texinfo-mode-map
"\C-c}" 'up-list
)
392 (define-key texinfo-mode-map
"\C-c]" 'up-list
)
393 (define-key texinfo-mode-map
"\C-c{" 'texinfo-insert-braces
)
395 ;; bindings for inserting strings
396 (define-key texinfo-mode-map
"\C-c\C-o" 'texinfo-insert-block
)
397 (define-key texinfo-mode-map
"\C-c\C-c\C-d" 'texinfo-start-menu-description
)
398 (define-key texinfo-mode-map
"\C-c\C-c\C-s" 'texinfo-insert-
@strong
)
399 (define-key texinfo-mode-map
"\C-c\C-c\C-e" 'texinfo-insert-
@emph
)
401 (define-key texinfo-mode-map
"\C-c\C-cv" 'texinfo-insert-
@var
)
402 (define-key texinfo-mode-map
"\C-c\C-cu" 'texinfo-insert-
@url
)
403 (define-key texinfo-mode-map
"\C-c\C-ct" 'texinfo-insert-
@table
)
404 (define-key texinfo-mode-map
"\C-c\C-cs" 'texinfo-insert-
@samp
)
405 ;; (define-key texinfo-mode-map "\C-c\C-cr" 'texinfo-insert-@uref)
406 (define-key texinfo-mode-map
"\C-c\C-cq" 'texinfo-insert-
@quotation
)
407 (define-key texinfo-mode-map
"\C-c\C-co" 'texinfo-insert-
@noindent
)
408 (define-key texinfo-mode-map
"\C-c\C-cn" 'texinfo-insert-
@node
)
409 (define-key texinfo-mode-map
"\C-c\C-cm" 'texinfo-insert-
@email
)
410 (define-key texinfo-mode-map
"\C-c\C-ck" 'texinfo-insert-
@kbd
)
411 (define-key texinfo-mode-map
"\C-c\C-ci" 'texinfo-insert-
@item
)
412 (define-key texinfo-mode-map
"\C-c\C-cf" 'texinfo-insert-
@file
)
413 (define-key texinfo-mode-map
"\C-c\C-cx" 'texinfo-insert-
@example
)
414 (define-key texinfo-mode-map
"\C-c\C-ce" 'texinfo-insert-
@end
)
415 (define-key texinfo-mode-map
"\C-c\C-cd" 'texinfo-insert-
@dfn
)
416 (define-key texinfo-mode-map
"\C-c\C-cc" 'texinfo-insert-
@code
))
418 (easy-menu-define texinfo-mode-menu
420 "Menu used for `texinfo-mode'."
422 ["Insert block" texinfo-insert-block t
]
423 ;; ["Insert node" texinfo-insert-@node t]
425 ["Update All" (lambda () (interactive) (texinfo-master-menu t
)) t
]
426 ["Update every node" texinfo-every-node-update t
]
427 ["Update node" texinfo-update-node t
]
428 ["Make Master menu" texinfo-master-menu t
]
429 ["Make menu" texinfo-make-menu t
]
430 ["Update all menus" texinfo-all-menus-update t
]
432 ["Show structure" texinfo-show-structure t
]
433 ["Format region" texinfo-format-region t
]
434 ["Format buffer" texinfo-format-buffer t
]
435 ["Makeinfo region" makeinfo-region t
]
436 ["Makeinfo buffer" makeinfo-buffer t
]))
441 ;; Also defined in texnfo-upd.el but copied here to avoid having
442 ;; to require texnfo-upd.el.
443 (defvar texinfo-chapter-level-regexp
444 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
445 "Regular expression matching Texinfo chapter-level headings.
446 This does not match `@node' and does not match the `@top' command.")
449 (define-derived-mode texinfo-mode text-mode
"Texinfo"
450 "Major mode for editing Texinfo files.
452 It has these extra commands:
455 These are files that are used as input for TeX to make printed manuals
456 and also to be turned into Info files with \\[makeinfo-buffer] or
457 the `makeinfo' program. These files must be written in a very restricted and
458 modified version of TeX input format.
460 Editing commands are like text-mode except that the syntax table is
461 set up so expression commands skip Texinfo bracket groups. To see
462 what the Info version of a region of the Texinfo file will look like,
463 use \\[makeinfo-region], which runs `makeinfo' on the current region.
465 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
466 This command shows the structure of a Texinfo file by listing the
467 lines with the @-sign commands for @chapter, @section, and the like.
468 These lines are displayed in another window called the *Occur* window.
469 In that window, you can position the cursor over one of the lines and
470 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
473 In addition, Texinfo mode provides commands that insert various
474 frequently used @-sign commands into the buffer. You can use these
475 commands to save keystrokes. And you can insert balanced braces with
476 \\[texinfo-insert-braces] and later use the command \\[up-list] to
477 move forward past the closing brace.
479 Also, Texinfo mode provides functions for automatically creating or
480 updating menus and node pointers. These functions
482 * insert the `Next', `Previous' and `Up' pointers of a node,
483 * insert or update the menu for a section, and
484 * create a master menu for a Texinfo source file.
486 Here are the functions:
488 texinfo-update-node \\[texinfo-update-node]
489 texinfo-every-node-update \\[texinfo-every-node-update]
490 texinfo-sequential-node-update
492 texinfo-make-menu \\[texinfo-make-menu]
493 texinfo-all-menus-update \\[texinfo-all-menus-update]
496 texinfo-indent-menu-description (column &optional region-p)
498 The `texinfo-column-for-description' variable specifies the column to
499 which menu descriptions are indented.
501 Passed an argument (a prefix argument, if interactive), the
502 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
505 To use the updating commands, you must structure your Texinfo file
506 hierarchically, such that each `@node' line, with the exception of the
507 Top node, is accompanied by some kind of section line, such as an
508 `@chapter' or `@section' line.
510 If the file has a `top' node, it must be called `top' or `Top' and
511 be the first node in the file.
513 Entering Texinfo mode calls the value of `text-mode-hook', and then the
514 value of `texinfo-mode-hook'."
515 (make-local-variable 'page-delimiter
)
518 "^@node [ \t]*[Tt]op\\|^@\\("
519 texinfo-chapter-level-regexp
521 (make-local-variable 'require-final-newline
)
522 (setq require-final-newline t
)
523 (make-local-variable 'indent-tabs-mode
)
524 (setq indent-tabs-mode nil
)
525 (make-local-variable 'paragraph-separate
)
526 (setq paragraph-separate
527 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate
))
528 (make-local-variable 'paragraph-start
)
529 (setq paragraph-start
(concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start
))
530 (make-local-variable 'adaptive-fill-mode
)
531 (setq adaptive-fill-mode nil
)
532 (make-local-variable 'fill-column
)
533 (setq fill-column
72)
534 (make-local-variable 'comment-start
)
535 (setq comment-start
"@c ")
536 (make-local-variable 'comment-start-skip
)
537 (setq comment-start-skip
"@c +\\|@comment +")
538 (make-local-variable 'words-include-escapes
)
539 (setq words-include-escapes t
)
540 (make-local-variable 'imenu-generic-expression
)
541 (setq imenu-generic-expression texinfo-imenu-generic-expression
)
542 (setq imenu-case-fold-search nil
)
543 (make-local-variable 'font-lock-defaults
)
544 (setq font-lock-defaults
545 '(texinfo-font-lock-keywords nil nil nil nil
546 (font-lock-syntactic-keywords
547 . texinfo-font-lock-syntactic-keywords
)))
548 (set (make-local-variable 'parse-sexp-lookup-properties
) t
)
549 (make-local-variable 'outline-regexp
)
551 (concat "@" (regexp-opt (mapcar 'car texinfo-section-list
) t
) "\\>"))
552 (make-local-variable 'outline-level
)
553 (setq outline-level
'texinfo-outline-level
)
554 (make-local-variable 'tex-start-of-header
)
555 (setq tex-start-of-header
"%\\*\\*start")
556 (make-local-variable 'tex-end-of-header
)
557 (setq tex-end-of-header
"%\\*\\*end")
558 (make-local-variable 'tex-first-line-header-regexp
)
559 (setq tex-first-line-header-regexp
"^\\\\input")
560 (make-local-variable 'tex-trailer
)
561 (setq tex-trailer
"@bye\n")
563 ;; Prevent filling certain lines, in addition to ones specified
565 (let ((prevent-filling "^@\\(def\\|multitable\\)"))
566 (make-local-variable 'auto-fill-inhibit-regexp
)
567 (if (null auto-fill-inhibit-regexp
)
568 (setq auto-fill-inhibit-regexp prevent-filling
)
569 (setq auto-fill-inhibit-regexp
570 (concat "\\(" auto-fill-inhibit-regexp
"\\)\\|\\("
571 prevent-filling
"\\)")))))
575 ;;; Insert string commands
577 (defconst texinfo-environments
626 "List of TeXinfo environments.")
628 ;; Keep as concatenated lists for ease of maintenance
629 (defconst texinfo-environment-regexp
630 (concat "^@" (regexp-opt (cons "end" texinfo-environments
) t
) "\\>")
631 "Regexp for environment-like TexInfo list commands.
632 Subexpression 1 is what goes into the corresponding `@end' statement.")
634 (define-skeleton texinfo-insert-block
635 "Create a matching pair @<cmd> .. @end <cmd> at point.
636 Puts point on a blank line between them."
637 (completing-read "Block name: " (mapcar 'list texinfo-environments
))
638 "@" str
\n _
\n "@end " str
\n)
640 (defun texinfo-inside-macro-p (macro &optional bound
)
641 "Non-nil if inside a macro matching the regexp MACRO."
645 (narrow-to-region bound
(point))
651 (looking-at macro
))))))
654 (defun texinfo-inside-env-p (env &optional bound
)
655 "Non-nil if inside an environment matching the regexp @ENV."
657 (and (re-search-backward (concat "@\\(end\\s +\\)?" env
) bound t
)
658 (looking-at (concat "@" env
)))))
660 (autoload 'tex-insert-quote
"tex-mode" nil t
)
661 (defun texinfo-insert-quote (&optional arg
)
662 "Insert the appropriate quote mark for TeXinfo.
663 Inserts a plain \" if inside @code or @example, else inserts `` or ''
664 by calling `tex-insert-quote'."
666 (let ((top (or (save-excursion (re-search-backward "@node\\>" nil t
))
668 (if (or (texinfo-inside-env-p "example\\>" top
)
669 (texinfo-inside-macro-p "@code\\>" top
))
670 (self-insert-command (prefix-numeric-value arg
))
671 (tex-insert-quote arg
))))
673 ;; The following texinfo-insert-@end command not only inserts a SPC
674 ;; after the @end, but tries to find out what belongs there. It is
675 ;; not very smart: it does not understand nested lists.
677 (defun texinfo-insert-@end
()
678 "Insert the matching `@end' for the last Texinfo command that needs one."
680 (let ((depth 1) string
)
682 (while (and (> depth
0)
683 (re-search-backward texinfo-environment-regexp nil t
))
684 (if (looking-at "@end")
685 (setq depth
(1+ depth
))
686 (setq depth
(1- depth
))))
687 (looking-at texinfo-environment-regexp
)
690 (buffer-substring (match-beginning 1)
693 (if string
(insert string
"\n"))))
695 ;; The following insert commands accept a prefix arg N, which is the
696 ;; number of words (actually s-exprs) that should be surrounded by
697 ;; braces. Thus you can first paste a variable name into a .texinfo
698 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
699 ;; pasted variable name to put @var{...} *around* the variable name.
700 ;; Operate on previous word or words with negative arg.
702 ;; These commands use texinfo-insert-@-with-arg
703 (defun texinfo-insert-@-with-arg
(string &optional arg
)
706 (setq arg
(prefix-numeric-value arg
))
709 (skip-chars-backward " \t\n\r\f")
712 (insert "@" string
"{"))
714 (skip-chars-forward " \t\n\r\f")
715 (insert "@" string
"{")
718 (insert "@" string
"{}")
721 (defun texinfo-insert-braces ()
722 "Make a pair of braces and be poised to type inside of them.
723 Use \\[up-list] to move forward out of the braces."
728 (defun texinfo-insert-@code
(&optional arg
)
729 "Insert a `@code{...}' 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
"code" arg
))
735 (defun texinfo-insert-@dfn
(&optional arg
)
736 "Insert a `@dfn{...}' 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
"dfn" arg
))
742 (defun texinfo-insert-@email
(&optional arg
)
743 "Insert a `@email{...}' command in a Texinfo buffer.
744 A numeric argument says how many words the braces should surround.
745 The default is not to surround any existing words with the braces."
747 (texinfo-insert-@-with-arg
"email" arg
))
749 (defun texinfo-insert-@emph
(&optional arg
)
750 "Insert a `@emph{...}' command in a Texinfo buffer.
751 A numeric argument says how many words the braces should surround.
752 The default is not to surround any existing words with the braces."
754 (texinfo-insert-@-with-arg
"emph" arg
))
756 (defun texinfo-insert-@example
()
757 "Insert the string `@example' in a Texinfo buffer."
759 (insert "@example\n"))
761 (defun texinfo-insert-@file
(&optional arg
)
762 "Insert a `@file{...}' command in a Texinfo buffer.
763 A numeric argument says how many words the braces should surround.
764 The default is not to surround any existing words with the braces."
766 (texinfo-insert-@-with-arg
"file" arg
))
768 (defun texinfo-insert-@item
()
769 "Insert the string `@item' in a Texinfo buffer."
774 (defun texinfo-insert-@kbd
(&optional arg
)
775 "Insert a `@kbd{...}' command in a Texinfo buffer.
776 A numeric argument says how many words the braces should surround.
777 The default is not to surround any existing words with the braces."
779 (texinfo-insert-@-with-arg
"kbd" arg
))
781 (defun texinfo-insert-@node
()
782 "Insert the string `@node' in a Texinfo buffer.
783 This also inserts on the following line a comment indicating
784 the order of arguments to @node."
786 (insert "@node \n@comment node-name, next, previous, up")
790 (defun texinfo-insert-@noindent
()
791 "Insert the string `@noindent' in a Texinfo buffer."
793 (insert "@noindent\n"))
795 (defun texinfo-insert-@quotation
()
796 "Insert the string `@quotation' in a Texinfo buffer."
798 (insert "@quotation\n"))
800 (defun texinfo-insert-@samp
(&optional arg
)
801 "Insert a `@samp{...}' command in a Texinfo buffer.
802 A numeric argument says how many words the braces should surround.
803 The default is not to surround any existing words with the braces."
805 (texinfo-insert-@-with-arg
"samp" arg
))
807 (defun texinfo-insert-@strong
(&optional arg
)
808 "Insert a `@strong{...}' command in a Texinfo buffer.
809 A numeric argument says how many words the braces should surround.
810 The default is not to surround any existing words with the braces."
812 (texinfo-insert-@-with-arg
"strong" arg
))
814 (defun texinfo-insert-@table
(&optional arg
)
815 "Insert the string `@table' in a Texinfo buffer."
819 (defun texinfo-insert-@var
(&optional arg
)
820 "Insert a `@var{}' command in a Texinfo buffer.
821 A numeric argument says how many words the braces should surround.
822 The default is not to surround any existing words with the braces."
824 (texinfo-insert-@-with-arg
"var" arg
))
826 (defun texinfo-insert-@url
(&optional arg
)
827 "Insert a `@url{}' command in a Texinfo buffer.
828 A numeric argument says how many words the braces should surround.
829 The default is not to surround any existing words with the braces."
831 (texinfo-insert-@-with-arg
"url" arg
))
833 ;;; Texinfo file structure
835 (defun texinfo-show-structure (&optional nodes-too
)
836 "Show the structure of a Texinfo file.
837 List the lines in the file that begin with the @-sign commands for
838 @chapter, @section, and the like.
840 With optional argument (prefix if interactive), list both the lines
841 with @-sign commands for @chapter, @section, and the like, and list
844 Lines with structuring commands beginning in them are displayed in
845 another buffer named `*Occur*'. In that buffer, you can move point to
846 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
847 to jump to the corresponding spot in the Texinfo source file."
851 (goto-char (point-min))
853 (occur (concat "^@node\\>\\|" outline-regexp
))
854 (occur outline-regexp
)))
855 (pop-to-buffer "*Occur*")
856 (goto-char (point-min))
857 (let ((inhibit-read-only t
))
858 (flush-lines "-----")
859 ;; Now format the "*Occur*" buffer to show the structure.
860 ;; Thanks to ceder@signum.se (Per Cederqvist)
861 (goto-char (point-max))
863 (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil
0)
864 (goto-char (1- (match-beginning 1)))
865 (setq level
(or (cadr (assoc (match-string 1) texinfo-section-list
)) 2))
866 (indent-to-column (+ (current-column) (* 4 (- level
2))))
867 (beginning-of-line)))))
869 ;;; The tex and print function definitions:
871 (defcustom texinfo-texi2dvi-command
"texi2dvi"
872 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
876 (defcustom texinfo-tex-command
"tex"
877 "*Command used by `texinfo-tex-region' to run TeX on a region."
881 (defcustom texinfo-texindex-command
"texindex"
882 "*Command used by `texinfo-texindex' to sort unsorted index files."
886 (defcustom texinfo-delete-from-print-queue-command
"lprm"
887 "*Command string used to delete a job from the line printer queue.
888 Command is used by \\[texinfo-delete-from-print-queue] based on
889 number provided by a previous \\[tex-show-print-queue]
894 (defvar texinfo-tex-trailer
"@bye"
895 "String appended after a region sent to TeX by `texinfo-tex-region'.")
897 (defun texinfo-tex-region (beg end
)
898 "Run TeX on the current region.
899 This works by writing a temporary file (`tex-zap-file') in the directory
900 that is the value of `tex-directory', then running TeX on that file.
902 The first line of the buffer is copied to the
903 temporary file; and if the buffer has a header, it is written to the
904 temporary file before the region itself. The buffer's header is all lines
905 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
906 inclusive. The header must start in the first 100 lines.
908 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
911 (let ((tex-command texinfo-tex-command
)
912 (tex-trailer texinfo-tex-trailer
))
913 (tex-region beg end
)))
915 (defun texinfo-tex-buffer ()
916 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
919 (let ((tex-command texinfo-texi2dvi-command
)
920 ;; Disable tex-start-options-string. texi2dvi would not
921 ;; understand anything specified here.
922 (tex-start-options-string ""))
925 (defun texinfo-texindex ()
926 "Run `texindex' on unsorted index files.
927 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
928 This runs the shell command defined by `texinfo-texindex-command'."
931 (tex-send-command texinfo-texindex-command
(concat tex-zap-file
".??"))
933 ;; (send-string "tex-shell"
934 ;; (concat texinfo-texindex-command
935 ;; " " tex-zap-file ".??" "\n"))
936 (tex-recenter-output-buffer nil
))
938 (defun texinfo-tex-print ()
939 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
940 This runs the shell command defined by `tex-dvi-print-command'."
945 (defun texinfo-tex-view ()
946 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
947 This runs the shell command defined by `tex-dvi-view-command'."
952 (defun texinfo-quit-job ()
953 "Quit currently running TeX job, by sending an `x' to it."
955 (if (not (get-process "tex-shell"))
956 (error "No TeX shell running"))
957 (tex-send-command "x"))
960 ;; (set-buffer (get-buffer "*tex-shell*"))
961 ;; (goto-char (point-max))
963 ;; (comint-send-input)
965 (defun texinfo-delete-from-print-queue (job-number)
966 "Delete job from the line printer spooling queue.
967 You are prompted for the job number (use a number shown by a previous
968 \\[tex-show-print-queue] command)."
969 (interactive "nPrinter job number for deletion: ")
971 (if (tex-shell-running)
974 (tex-send-command texinfo-delete-from-print-queue-command job-number
)
976 ;; (send-string "tex-shell"
978 ;; texinfo-delete-from-print-queue-command
981 (tex-recenter-output-buffer nil
))
985 ;;; texinfo.el ends here