]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfo.el
(bibtex-autokey-names): Change number tag to integer.
[gnu-emacs] / lisp / textmodes / texinfo.el
1 ;;; texinfo.el --- major mode for editing Texinfo files
2
3 ;; Copyright (C) 1985, '88, '89, '90, '91,
4 ;; '92, '93, '96, '97 Free Software Foundation, Inc.
5
6 ;; Author: Robert J. Chassell
7 ;; Date: [Set date below for texinfo-version]
8 ;; Maintainer: bug-texinfo@prep.ai.mit.edu
9 ;; Keywords: maint, tex, docs
10
11 ;; This file is part of GNU Emacs.
12
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)
16 ;; any later version.
17
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.
22
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.
27
28 ;;; Code:
29
30 (or (fboundp 'defgroup)
31 (defmacro defgroup (&rest ignore) nil))
32
33 (or (fboundp 'defcustom)
34 (defmacro defcustom (var value doc &rest ignore)
35 `(defvar ,var ,value ,doc)))
36
37 (defgroup texinfo nil
38 "Texinfo Mode"
39 :group 'docs)
40
41 (defvar texinfo-version "2.37 of 24 May 1997")
42
43 (defun texinfo-version (&optional here)
44 "Show the version of texinfo.el in the minibuffer.
45 If optional argument HERE is non-nil, insert info at point."
46 (interactive "P")
47 (let ((version-string
48 (format "Version of \`texinfo.el\': %s" texinfo-version)))
49 (if here
50 (insert version-string)
51 (if (interactive-p)
52 (message "%s" version-string)
53 version-string))))
54
55 \f
56 ;;; Autoloads:
57
58 (autoload 'makeinfo-region
59 "makeinfo"
60 "Make Info file from region of current Texinfo file, and switch to it.
61
62 This command does not offer the `next-error' feature since it would
63 apply to a temporary file, not the original; use the `makeinfo-buffer'
64 command to gain use of `next-error'."
65 t nil)
66
67 (autoload 'makeinfo-buffer
68 "makeinfo"
69 "Make Info file from current buffer.
70
71 Use the \\[next-error] command to move to the next error
72 \(if there are errors\)."
73 t nil)
74
75 (autoload 'kill-compilation
76 "compile"
77 "Kill the process made by the \\[compile] command."
78 t nil)
79
80 (autoload 'makeinfo-recenter-compilation-buffer
81 "makeinfo"
82 "Redisplay `*compilation*' buffer so most recent output can be seen.
83 The last line of the buffer is displayed on
84 line LINE of the window, or centered if LINE is nil."
85 t nil)
86
87 (autoload 'texinfo-update-node
88 "texnfo-upd"
89 "Without any prefix argument, update the node in which point is located.
90 Non-nil argument (prefix, if interactive) means update the nodes in the
91 marked region.
92
93 The functions for creating or updating nodes and menus, and their
94 keybindings, are:
95
96 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
97 texinfo-every-node-update () \\[texinfo-every-node-update]
98 texinfo-sequential-node-update (&optional region-p)
99
100 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
101 texinfo-all-menus-update () \\[texinfo-all-menus-update]
102 texinfo-master-menu ()
103
104 texinfo-indent-menu-description (column &optional region-p)
105
106 The `texinfo-column-for-description' variable specifies the column to
107 which menu descriptions are indented. Its default value is 32."
108 t nil)
109
110 (autoload 'texinfo-every-node-update
111 "texnfo-upd"
112 "Update every node in a Texinfo file."
113 t nil)
114
115 (autoload 'texinfo-sequential-node-update
116 "texnfo-upd"
117 "Update one node (or many) in a Texinfo file with sequential pointers.
118
119 This function causes the `Next' or `Previous' pointer to point to the
120 immediately preceding or following node, even if it is at a higher or
121 lower hierarchical level in the document. Continually pressing `n' or
122 `p' takes you straight through the file.
123
124 Without any prefix argument, update the node in which point is located.
125 Non-nil argument (prefix, if interactive) means update the nodes in the
126 marked region.
127
128 This command makes it awkward to navigate among sections and
129 subsections; it should be used only for those documents that are meant
130 to be read like a novel rather than a reference, and for which the
131 Info `g*' command is inadequate."
132 t nil)
133
134 (autoload 'texinfo-make-menu
135 "texnfo-upd"
136 "Without any prefix argument, make or update a menu.
137 Make the menu for the section enclosing the node found following point.
138
139 Non-nil argument (prefix, if interactive) means make or update menus
140 for nodes within or part of the marked region.
141
142 Whenever a menu exists, and is being updated, the descriptions that
143 are associated with node names in the pre-existing menu are
144 incorporated into the new menu. Otherwise, the nodes' section titles
145 are inserted as descriptions."
146 t nil)
147
148 (autoload 'texinfo-all-menus-update
149 "texnfo-upd"
150 "Update every regular menu in a Texinfo file.
151 Remove pre-existing master menu, if there is one.
152
153 If called with a non-nil argument, this function first updates all the
154 nodes in the buffer before updating the menus."
155 t nil)
156
157 (autoload 'texinfo-master-menu
158 "texnfo-upd"
159 "Make a master menu for a whole Texinfo file.
160 Non-nil argument (prefix, if interactive) means first update all
161 existing nodes and menus. Remove pre-existing master menu, if there is one.
162
163 This function creates a master menu that follows the top node. The
164 master menu includes every entry from all the other menus. It
165 replaces any existing ordinary menu that follows the top node.
166
167 If called with a non-nil argument, this function first updates all the
168 menus in the buffer (incorporating descriptions from pre-existing
169 menus) before it constructs the master menu.
170
171 The function removes the detailed part of an already existing master
172 menu. This action depends on the pre-existing master menu using the
173 standard `texinfo-master-menu-header'.
174
175 The master menu has the following format, which is adapted from the
176 recommendation in the Texinfo Manual:
177
178 * The first part contains the major nodes in the Texinfo file: the
179 nodes for the chapters, chapter-like sections, and the major
180 appendices. This includes the indices, so long as they are in
181 chapter-like sections, such as unnumbered sections.
182
183 * The second and subsequent parts contain a listing of the other,
184 lower level menus, in order. This way, an inquirer can go
185 directly to a particular node if he or she is searching for
186 specific information.
187
188 Each of the menus in the detailed node listing is introduced by the
189 title of the section containing the menu."
190 t nil)
191
192 (autoload 'texinfo-indent-menu-description
193 "texnfo-upd"
194 "Indent every description in menu following point to COLUMN.
195 Non-nil argument (prefix, if interactive) means indent every
196 description in every menu in the region. Does not indent second and
197 subsequent lines of a multi-line description."
198 t nil)
199
200 (autoload 'texinfo-insert-node-lines
201 "texnfo-upd"
202 "Insert missing `@node' lines in region of Texinfo file.
203 Non-nil argument (prefix, if interactive) means also to insert the
204 section titles as node names; and also to insert the section titles as
205 node names in pre-existing @node lines that lack names."
206 t nil)
207
208 (autoload 'texinfo-start-menu-description
209 "texnfo-upd"
210 "In this menu entry, insert the node's section title as a description.
211 Position point at beginning of description ready for editing.
212 Do not insert a title if the line contains an existing description.
213
214 You will need to edit the inserted text since a useful description
215 complements the node name rather than repeats it as a title does."
216 t nil)
217
218 (autoload 'texinfo-multiple-files-update
219 "texnfo-upd"
220 "Update first node pointers in each file included in OUTER-FILE;
221 create or update main menu in the outer file that refers to such nodes.
222 This does not create or update menus or pointers within the included files.
223
224 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
225 insert a master menu in OUTER-FILE. This does not create or update
226 menus or pointers within the included files.
227
228 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
229 interactive), update all the menus and all the `Next', `Previous', and
230 `Up' pointers of all the files included in OUTER-FILE before inserting
231 a master menu in OUTER-FILE.
232
233 The command also updates the `Top' level node pointers of OUTER-FILE.
234
235 Notes:
236
237 * this command does NOT save any files--you must save the
238 outer file and any modified, included files.
239
240 * except for the `Top' node, this command does NOT handle any
241 pre-existing nodes in the outer file; hence, indices must be
242 enclosed in an included file.
243
244 Requirements:
245
246 * each of the included files must contain exactly one highest
247 hierarchical level node,
248 * this highest node must be the first node in the included file,
249 * each highest hierarchical level node must be of the same type.
250
251 Thus, normally, each included file contains one, and only one,
252 chapter."
253 t nil)
254
255 \f
256 ;;; Code:
257
258 ;;; Don't you dare insert any `require' calls at top level in this file--rms.
259
260 ;;; Syntax table
261
262 (defvar texinfo-mode-syntax-table nil)
263
264 (if texinfo-mode-syntax-table
265 nil
266 (setq texinfo-mode-syntax-table (make-syntax-table))
267 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
268 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
269 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
270 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
271 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
272 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
273 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
274 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
275 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
276
277 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
278 ;; To override this example, set either `imenu-generic-expression'
279 ;; or `imenu-create-index-function'.
280 (defvar texinfo-imenu-generic-expression
281 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
282 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
283
284 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
285
286 (defvar texinfo-font-lock-keywords
287 '(;; All but the first 2 had an OVERRIDE of t.
288 ;; It didn't seem to be any better, and it's slower--simon.
289 ("^\\(@c\\|@comment\\)\\>.*" . font-lock-comment-face) ;comments
290 ;; Robert J. Chassell <bob@gnu.ai.mit.edu> says remove this line.
291 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
292 ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
293 ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
294 ("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face)
295 ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
296 ("@\\(samp\\|code\\|var\\|math\\){\\([^}]+\\)"
297 2 font-lock-variable-name-face)
298 ("@\\(cite\\|xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-reference-face)
299 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
300 )
301 "Additional expressions to highlight in TeXinfo mode.")
302
303 (defvar texinfo-section-list
304 '(("top" 1)
305 ("majorheading" 1)
306 ("chapter" 2)
307 ("unnumbered" 2)
308 ("appendix" 2)
309 ("chapheading" 2)
310 ("section" 3)
311 ("unnumberedsec" 3)
312 ("appendixsec" 3)
313 ("heading" 3)
314 ("subsection" 4)
315 ("unnumberedsubsec" 4)
316 ("appendixsubsec" 4)
317 ("subheading" 4)
318 ("subsubsection" 5)
319 ("unnumberedsubsubsec" 5)
320 ("appendixsubsubsec" 5)
321 ("subsubheading" 5))
322 "Alist of sectioning commands and their relative level.")
323
324 (defun texinfo-outline-level ()
325 ;; Calculate level of current texinfo outline heading.
326 (save-excursion
327 (if (bobp)
328 0
329 (forward-char 1)
330 (let* ((word (buffer-substring-no-properties
331 (point) (progn (forward-word 1) (point))))
332 (entry (assoc word texinfo-section-list)))
333 (if entry
334 (nth 1 entry)
335 5)))))
336
337 \f
338 ;;; Keybindings
339 (defvar texinfo-mode-map nil)
340
341 ;;; Keys common both to Texinfo mode and to TeX shell.
342
343 (defun texinfo-define-common-keys (keymap)
344 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
345 (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
346 (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
347 (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
348 (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
349 (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
350 (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
351 (define-key keymap "\C-c\C-t\C-v" 'texinfo-tex-view)
352 (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
353
354 (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
355 (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
356
357 ;; Mode documentation displays commands in reverse order
358 ;; from how they are listed in the texinfo-mode-map.
359
360 (if texinfo-mode-map
361 nil
362 (setq texinfo-mode-map (make-sparse-keymap))
363
364 ;; bindings for `texnfo-tex.el'
365 (texinfo-define-common-keys texinfo-mode-map)
366
367 ;; bindings for `makeinfo.el'
368 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
369 (define-key texinfo-mode-map "\C-c\C-m\C-l"
370 'makeinfo-recenter-compilation-buffer)
371 (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
372 (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
373
374 ;; bindings for `texinfmt.el'
375 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
376 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
377
378 ;; bindings for updating nodes and menus
379
380 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
381
382 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
383 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
384 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
385 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
386
387 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
388
389 (define-key texinfo-mode-map "\C-c}" 'up-list)
390 (define-key texinfo-mode-map "\C-c]" 'up-list)
391 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
392
393 ;; bindings for inserting strings
394
395 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
396
397 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
398 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
399 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
400 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
401 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
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))
409
410 \f
411 ;;; Texinfo mode
412
413 (defvar texinfo-chapter-level-regexp
414 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
415 "Regular expression matching Texinfo chapter-level headings.
416 This does not match `@node' and does not match the `@top' command.")
417
418 ;;;###autoload
419 (defun texinfo-mode ()
420 "Major mode for editing Texinfo files.
421
422 It has these extra commands:
423 \\{texinfo-mode-map}
424
425 These are files that are used as input for TeX to make printed manuals
426 and also to be turned into Info files with \\[makeinfo-buffer] or
427 the `makeinfo' program. These files must be written in a very restricted and
428 modified version of TeX input format.
429
430 Editing commands are like text-mode except that the syntax table is
431 set up so expression commands skip Texinfo bracket groups. To see
432 what the Info version of a region of the Texinfo file will look like,
433 use \\[makeinfo-region], which runs `makeinfo' on the current region.
434
435 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
436 This command shows the structure of a Texinfo file by listing the
437 lines with the @-sign commands for @chapter, @section, and the like.
438 These lines are displayed in another window called the *Occur* window.
439 In that window, you can position the cursor over one of the lines and
440 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
441 in the Texinfo file.
442
443 In addition, Texinfo mode provides commands that insert various
444 frequently used @-sign commands into the buffer. You can use these
445 commands to save keystrokes. And you can insert balanced braces with
446 \\[texinfo-insert-braces] and later use the command \\[up-list] to
447 move forward past the closing brace.
448
449 Also, Texinfo mode provides functions for automatically creating or
450 updating menus and node pointers. These functions
451
452 * insert the `Next', `Previous' and `Up' pointers of a node,
453 * insert or update the menu for a section, and
454 * create a master menu for a Texinfo source file.
455
456 Here are the functions:
457
458 texinfo-update-node \\[texinfo-update-node]
459 texinfo-every-node-update \\[texinfo-every-node-update]
460 texinfo-sequential-node-update
461
462 texinfo-make-menu \\[texinfo-make-menu]
463 texinfo-all-menus-update \\[texinfo-all-menus-update]
464 texinfo-master-menu
465
466 texinfo-indent-menu-description (column &optional region-p)
467
468 The `texinfo-column-for-description' variable specifies the column to
469 which menu descriptions are indented.
470
471 Passed an argument (a prefix argument, if interactive), the
472 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
473 in the region.
474
475 To use the updating commands, you must structure your Texinfo file
476 hierarchically, such that each `@node' line, with the exception of the
477 Top node, is accompanied by some kind of section line, such as an
478 `@chapter' or `@section' line.
479
480 If the file has a `top' node, it must be called `top' or `Top' and
481 be the first node in the file.
482
483 Entering Texinfo mode calls the value of text-mode-hook, and then the
484 value of texinfo-mode-hook."
485 (interactive)
486 (text-mode)
487 (setq mode-name "Texinfo")
488 (setq major-mode 'texinfo-mode)
489 (use-local-map texinfo-mode-map)
490 (set-syntax-table texinfo-mode-syntax-table)
491 (make-local-variable 'page-delimiter)
492 (setq page-delimiter
493 (concat
494 "^@node [ \t]*[Tt]op\\|^@\\("
495 texinfo-chapter-level-regexp
496 "\\)"))
497 (make-local-variable 'require-final-newline)
498 (setq require-final-newline t)
499 (make-local-variable 'indent-tabs-mode)
500 (setq indent-tabs-mode nil)
501 (make-local-variable 'paragraph-separate)
502 (setq paragraph-separate
503 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
504 (make-local-variable 'paragraph-start)
505 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
506 (make-local-variable 'adaptive-fill-mode)
507 (setq adaptive-fill-mode nil)
508 (make-local-variable 'fill-column)
509 (setq fill-column 72)
510 (make-local-variable 'comment-start)
511 (setq comment-start "@c ")
512 (make-local-variable 'comment-start-skip)
513 (setq comment-start-skip "@c +")
514 (make-local-variable 'words-include-escapes)
515 (setq words-include-escapes t)
516 (make-local-variable 'imenu-generic-expression)
517 (setq imenu-generic-expression texinfo-imenu-generic-expression)
518 (setq imenu-case-fold-search nil)
519 (make-local-variable 'font-lock-defaults)
520 (setq font-lock-defaults '(texinfo-font-lock-keywords t))
521 (make-local-variable 'outline-regexp)
522 (setq outline-regexp
523 (concat "@\\("
524 (mapconcat 'car texinfo-section-list "\\>\\|")
525 "\\>\\)"))
526 (make-local-variable 'outline-level)
527 (setq outline-level 'texinfo-outline-level)
528 (make-local-variable 'tex-start-of-header)
529 (setq tex-start-of-header "%\\*\\*start")
530 (make-local-variable 'tex-end-of-header)
531 (setq tex-end-of-header "%\\*\\*end")
532 (make-local-variable 'tex-first-line-header-regexp)
533 (setq tex-first-line-header-regexp "^\\\\input")
534 (make-local-variable 'tex-trailer)
535 (setq tex-trailer "@bye\n")
536 (run-hooks 'text-mode-hook 'texinfo-mode-hook))
537
538 \f
539 ;;; Insert string commands
540
541 ;; Keep as concatinated lists for ease of maintenance
542 (defconst texinfo-environment-regexp
543 (concat
544 "^@"
545 "\\("
546 "cartouche\\|"
547 "display\\|"
548 "end\\|"
549 "enumerate\\|"
550 "example\\|"
551 "f?table\\|"
552 "flushleft\\|"
553 "flushright\\|"
554 "format\\|"
555 "group\\|"
556 "ifhtml\\|"
557 "ifinfo\\|"
558 "iftex\\|"
559 "ignore\\|"
560 "itemize\\|"
561 "lisp\\|"
562 "macro\\|"
563 "multitable\\|"
564 "quotation\\|"
565 "smallexample\\|"
566 "smalllisp\\|"
567 "tex"
568 "\\)")
569 "Regexp for environment-like TexInfo list commands.
570 Subexpression 1 is what goes into the corresponding `@end' statement.")
571
572 ;; The following texinfo-insert-@end command not only inserts a SPC
573 ;; after the @end, but tries to find out what belongs there. It is
574 ;; not very smart: it does not understand nested lists.
575
576 (defun texinfo-insert-@end ()
577 "Insert the matching `@end' for the last Texinfo command that needs one."
578 (interactive)
579 (let ((depth 1) string)
580 (save-excursion
581 (while (and (> depth 0)
582 (re-search-backward texinfo-environment-regexp nil t))
583 (if (looking-at "@end")
584 (setq depth (1+ depth))
585 (setq depth (1- depth))))
586 (looking-at texinfo-environment-regexp)
587 (if (zerop depth)
588 (setq string
589 (buffer-substring (match-beginning 1)
590 (match-end 1)))))
591 (insert "@end ")
592 (if string (insert string "\n"))))
593
594 ;; The following insert commands accept a prefix arg N, which is the
595 ;; number of words (actually s-exprs) that should be surrounded by
596 ;; braces. Thus you can first paste a variable name into a .texinfo
597 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
598 ;; pasted variable name to put @var{...} *around* the variable name.
599 ;; Operate on previous word or words with negative arg.
600
601 ;; These commands use texinfo-insert-@-with-arg
602 (defun texinfo-insert-@-with-arg (string &optional arg)
603 (if arg
604 (progn
605 (setq arg (prefix-numeric-value arg))
606 (if (< arg 0)
607 (progn
608 (skip-chars-backward " \t\n\r\f")
609 (save-excursion
610 (forward-sexp arg)
611 (insert "@" string "{"))
612 (insert "}"))
613 (skip-chars-forward " \t\n\r\f")
614 (insert "@" string "{")
615 (forward-sexp arg)
616 (insert "}")))
617 (insert "@" string "{}")
618 (backward-char)))
619
620 (defun texinfo-insert-braces ()
621 "Make a pair of braces and be poised to type inside of them.
622 Use \\[up-list] to move forward out of the braces."
623 (interactive)
624 (insert "{}")
625 (backward-char))
626
627 (defun texinfo-insert-@code (&optional arg)
628 "Insert a `@code{...}' command in a Texinfo buffer.
629 A numeric argument says how many words the braces should surround.
630 The default is not to surround any existing words with the braces."
631 (interactive "P")
632 (texinfo-insert-@-with-arg "code" arg))
633
634 (defun texinfo-insert-@dfn (&optional arg)
635 "Insert a `@dfn{...}' command in a Texinfo buffer.
636 A numeric argument says how many words the braces should surround.
637 The default is not to surround any existing words with the braces."
638 (interactive "P")
639 (texinfo-insert-@-with-arg "dfn" arg))
640
641 (defun texinfo-insert-@example ()
642 "Insert the string `@example' in a Texinfo buffer."
643 (interactive)
644 (insert "@example\n"))
645
646 (defun texinfo-insert-@file (&optional arg)
647 "Insert a `@file{...}' command in a Texinfo buffer.
648 A numeric argument says how many words the braces should surround.
649 The default is not to surround any existing words with the braces."
650 (interactive "P")
651 (texinfo-insert-@-with-arg "file" arg))
652
653 (defun texinfo-insert-@item ()
654 "Insert the string `@item' in a Texinfo buffer."
655 (interactive)
656 (insert "@item")
657 (newline))
658
659 (defun texinfo-insert-@kbd (&optional arg)
660 "Insert a `@kbd{...}' command in a Texinfo buffer.
661 A numeric argument says how many words the braces should surround.
662 The default is not to surround any existing words with the braces."
663 (interactive "P")
664 (texinfo-insert-@-with-arg "kbd" arg))
665
666 (defun texinfo-insert-@node ()
667 "Insert the string `@node' in a Texinfo buffer.
668 This also inserts on the following line a comment indicating
669 the order of arguments to @node."
670 (interactive)
671 (insert "@node \n@comment node-name, next, previous, up")
672 (forward-line -1)
673 (forward-char 6))
674
675 (defun texinfo-insert-@noindent ()
676 "Insert the string `@noindent' in a Texinfo buffer."
677 (interactive)
678 (insert "@noindent\n"))
679
680 (defun texinfo-insert-@samp (&optional arg)
681 "Insert a `@samp{...}' command in a Texinfo buffer.
682 A numeric argument says how many words the braces should surround.
683 The default is not to surround any existing words with the braces."
684 (interactive "P")
685 (texinfo-insert-@-with-arg "samp" arg))
686
687 (defun texinfo-insert-@table (&optional arg)
688 "Insert the string `@table' in a Texinfo buffer."
689 (interactive "P")
690 (insert "@table "))
691
692 (defun texinfo-insert-@var (&optional arg)
693 "Insert a `@var{}' command in a Texinfo buffer.
694 A numeric argument says how many words the braces should surround.
695 The default is not to surround any existing words with the braces."
696 (interactive "P")
697 (texinfo-insert-@-with-arg "var" arg))
698 \f
699 ;;; Texinfo file structure
700
701 ;; These are defined in texnfo-upd.el. defvars here avoid warnings.
702 (defvar texinfo-section-types-regexp)
703 (defvar texinfo-section-level-regexp)
704 (defvar texinfo-subsection-level-regexp)
705 (defvar texinfo-subsubsection-level-regexp)
706
707 (defun texinfo-show-structure (&optional nodes-too)
708 "Show the structure of a Texinfo file.
709 List the lines in the file that begin with the @-sign commands for
710 @chapter, @section, and the like.
711
712 With optional argument (prefix if interactive), list both the lines
713 with @-sign commands for @chapter, @section, and the like, and list
714 @node lines.
715
716 Lines with structuring commands beginning in them are displayed in
717 another buffer named `*Occur*'. In that buffer, you can move point to
718 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
719 to jump to the corresponding spot in the Texinfo source file."
720
721 (interactive "P")
722 (require 'texnfo-upd)
723 (save-excursion
724 (goto-char (point-min))
725 (if nodes-too
726 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
727 (occur texinfo-section-types-regexp)))
728 (pop-to-buffer "*Occur*")
729 (goto-char (point-min))
730 (flush-lines "-----")
731 ;; Now format the "*Occur*" buffer to show the structure.
732 ;; Thanks to ceder@signum.se (Per Cederqvist)
733 (goto-char (point-max))
734 (let ((margin 5))
735 (while (re-search-backward "^ *[0-9]*:" nil 0)
736 (re-search-forward ":")
737 (setq margin
738 (cond
739 ((looking-at
740 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
741 ;; ((looking-at "@chapter ") 5)
742 ;; ((looking-at "@unnumbered ") 5)
743 ;; ((looking-at "@appendix ") 5)
744 ;; ((looking-at "@majorheading ") 5)
745 ;; ((looking-at "@chapheading ") 5)
746
747 ((looking-at
748 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
749 ;; ((looking-at "@section ") 9)
750 ;; ((looking-at "@unnumberedsec ") 9)
751 ;; ((looking-at "@appendixsec ") 9)
752 ;; ((looking-at "@heading ") 9)
753
754 ((looking-at
755 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
756 ;; ((looking-at "@subsection ") 13)
757 ;; ((looking-at "@unnumberedsubsec ") 13)
758 ;; ((looking-at "@appendixsubsec ") 13)
759 ;; ((looking-at "@subheading ") 13)
760
761 ((looking-at
762 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
763 ;; ((looking-at "@subsubsection ") 17)
764 ;; ((looking-at "@unnumberedsubsubsec ") 17)
765 ;; ((looking-at "@appendixsubsubsec ") 17)
766 ;; ((looking-at "@subsubheading ") 17)
767 (t margin)))
768 (indent-to-column margin)
769 (beginning-of-line))))
770 \f
771 ;;; The tex and print function definitions:
772
773 (defcustom texinfo-texi2dvi-command "texi2dvi"
774 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
775 :type 'string
776 :group 'texinfo)
777
778 (defcustom texinfo-tex-command "tex"
779 "*Command used by `texinfo-tex-region' to run TeX on a region."
780 :type 'string
781 :group 'texinfo)
782
783 (defcustom texinfo-texindex-command "texindex"
784 "*Command used by `texinfo-texindex' to sort unsorted index files."
785 :type 'string
786 :group 'texinfo)
787
788 (defcustom texinfo-delete-from-print-queue-command "lprm"
789 "*Command string used to delete a job from the line printer queue.
790 Command is used by \\[texinfo-delete-from-print-queue] based on
791 number provided by a previous \\[tex-show-print-queue]
792 command."
793 :type 'string
794 :group 'texinfo)
795
796 (defvar texinfo-tex-trailer "@bye"
797 "String appended after a region sent to TeX by `texinfo-tex-region'.")
798
799 (defun texinfo-tex-region (beg end)
800 "Run TeX on the current region.
801 This works by writing a temporary file (`tex-zap-file') in the directory
802 that is the value of `tex-directory', then running TeX on that file.
803
804 The first line of the buffer is copied to the
805 temporary file; and if the buffer has a header, it is written to the
806 temporary file before the region itself. The buffer's header is all lines
807 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
808 inclusive. The header must start in the first 100 lines.
809
810 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
811 (interactive "r")
812 (require 'tex-mode)
813 (let ((tex-command texinfo-tex-command)
814 (tex-trailer "@bye\n"))
815 (tex-region beg end)))
816
817 (defun texinfo-tex-buffer ()
818 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
819 (interactive)
820 (require 'tex-mode)
821 (let ((tex-command texinfo-texi2dvi-command))
822 (tex-buffer)))
823
824 (defun texinfo-texindex ()
825 "Run `texindex' on unsorted index files.
826 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
827 This runs the shell command defined by `texinfo-texindex-command'."
828 (interactive)
829 (require 'tex-mode)
830 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
831 ;; alternatively
832 ;; (send-string "tex-shell"
833 ;; (concat texinfo-texindex-command
834 ;; " " tex-zap-file ".??" "\n"))
835 (tex-recenter-output-buffer nil))
836
837 (defun texinfo-tex-print ()
838 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
839 This runs the shell command defined by `tex-dvi-print-command'."
840 (interactive)
841 (require 'tex-mode)
842 (tex-print))
843
844 (defun texinfo-tex-view ()
845 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
846 This runs the shell command defined by `tex-dvi-view-command'."
847 (interactive)
848 (require 'tex-mode)
849 (tex-view))
850
851 (defun texinfo-quit-job ()
852 "Quit currently running TeX job, by sending an `x' to it."
853 (interactive)
854 (if (not (get-process "tex-shell"))
855 (error "No TeX shell running"))
856 (tex-send-command "x"))
857 ;; alternatively:
858 ;; save-excursion
859 ;; (set-buffer (get-buffer "*tex-shell*"))
860 ;; (goto-char (point-max))
861 ;; (insert "x")
862 ;; (comint-send-input)
863
864 (defun texinfo-delete-from-print-queue (job-number)
865 "Delete job from the line printer spooling queue.
866 You are prompted for the job number (use a number shown by a previous
867 \\[tex-show-print-queue] command)."
868 (interactive "nPrinter job number for deletion: ")
869 (require 'tex-mode)
870 (if (tex-shell-running)
871 (tex-kill-job)
872 (tex-start-shell))
873 (tex-send-command texinfo-delete-from-print-queue-command job-number)
874 ;; alternatively
875 ;; (send-string "tex-shell"
876 ;; (concat
877 ;; texinfo-delete-from-print-queue-command
878 ;; " "
879 ;; job-number"\n"))
880 (tex-recenter-output-buffer nil))
881
882 (provide 'texinfo)
883
884 ;;; texinfo.el ends here