(reftex-customize): Added call to customize browse.
[bpt/emacs.git] / 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 (make-local-variable 'font-lock-defaults)
519 (setq font-lock-defaults '(texinfo-font-lock-keywords t))
520 (make-local-variable 'outline-regexp)
521 (setq outline-regexp
522 (concat "@\\("
523 (mapconcat 'car texinfo-section-list "\\>\\|")
524 "\\>\\)"))
525 (make-local-variable 'outline-level)
526 (setq outline-level 'texinfo-outline-level)
527 (make-local-variable 'tex-start-of-header)
528 (setq tex-start-of-header "%\\*\\*start")
529 (make-local-variable 'tex-end-of-header)
530 (setq tex-end-of-header "%\\*\\*end")
531 (make-local-variable 'tex-first-line-header-regexp)
532 (setq tex-first-line-header-regexp "^\\\\input")
533 (make-local-variable 'tex-trailer)
534 (setq tex-trailer "@bye\n")
535 (run-hooks 'text-mode-hook 'texinfo-mode-hook))
536
537 \f
538 ;;; Insert string commands
539
540 ;; Keep as concatinated lists for ease of maintenance
541 (defconst texinfo-environment-regexp
542 (concat
543 "^@"
544 "\\("
545 "cartouche\\|"
546 "display\\|"
547 "end\\|"
548 "enumerate\\|"
549 "example\\|"
550 "f?table\\|"
551 "flushleft\\|"
552 "flushright\\|"
553 "format\\|"
554 "group\\|"
555 "ifhtml\\|"
556 "ifinfo\\|"
557 "iftex\\|"
558 "ignore\\|"
559 "itemize\\|"
560 "lisp\\|"
561 "macro\\|"
562 "multitable\\|"
563 "quotation\\|"
564 "smallexample\\|"
565 "smalllisp\\|"
566 "tex"
567 "\\)")
568 "Regexp for environment-like TexInfo list commands.
569 Subexpression 1 is what goes into the corresponding `@end' statement.")
570
571 ;; The following texinfo-insert-@end command not only inserts a SPC
572 ;; after the @end, but tries to find out what belongs there. It is
573 ;; not very smart: it does not understand nested lists.
574
575 (defun texinfo-insert-@end ()
576 "Insert the matching `@end' for the last Texinfo command that needs one."
577 (interactive)
578 (let ((depth 1) string)
579 (save-excursion
580 (while (and (> depth 0)
581 (re-search-backward texinfo-environment-regexp nil t))
582 (if (looking-at "@end")
583 (setq depth (1+ depth))
584 (setq depth (1- depth))))
585 (looking-at texinfo-environment-regexp)
586 (if (zerop depth)
587 (setq string
588 (buffer-substring (match-beginning 1)
589 (match-end 1)))))
590 (insert "@end ")
591 (if string (insert string "\n"))))
592
593 ;; The following insert commands accept a prefix arg N, which is the
594 ;; number of words (actually s-exprs) that should be surrounded by
595 ;; braces. Thus you can first paste a variable name into a .texinfo
596 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
597 ;; pasted variable name to put @var{...} *around* the variable name.
598 ;; Operate on previous word or words with negative arg.
599
600 ;; These commands use texinfo-insert-@-with-arg
601 (defun texinfo-insert-@-with-arg (string &optional arg)
602 (if arg
603 (progn
604 (setq arg (prefix-numeric-value arg))
605 (if (< arg 0)
606 (progn
607 (skip-chars-backward " \t\n\r\f")
608 (save-excursion
609 (forward-sexp arg)
610 (insert "@" string "{"))
611 (insert "}"))
612 (skip-chars-forward " \t\n\r\f")
613 (insert "@" string "{")
614 (forward-sexp arg)
615 (insert "}")))
616 (insert "@" string "{}")
617 (backward-char)))
618
619 (defun texinfo-insert-braces ()
620 "Make a pair of braces and be poised to type inside of them.
621 Use \\[up-list] to move forward out of the braces."
622 (interactive)
623 (insert "{}")
624 (backward-char))
625
626 (defun texinfo-insert-@code (&optional arg)
627 "Insert a `@code{...}' command in a Texinfo buffer.
628 A numeric argument says how many words the braces should surround.
629 The default is not to surround any existing words with the braces."
630 (interactive "P")
631 (texinfo-insert-@-with-arg "code" arg))
632
633 (defun texinfo-insert-@dfn (&optional arg)
634 "Insert a `@dfn{...}' command in a Texinfo buffer.
635 A numeric argument says how many words the braces should surround.
636 The default is not to surround any existing words with the braces."
637 (interactive "P")
638 (texinfo-insert-@-with-arg "dfn" arg))
639
640 (defun texinfo-insert-@example ()
641 "Insert the string `@example' in a Texinfo buffer."
642 (interactive)
643 (insert "@example\n"))
644
645 (defun texinfo-insert-@file (&optional arg)
646 "Insert a `@file{...}' command in a Texinfo buffer.
647 A numeric argument says how many words the braces should surround.
648 The default is not to surround any existing words with the braces."
649 (interactive "P")
650 (texinfo-insert-@-with-arg "file" arg))
651
652 (defun texinfo-insert-@item ()
653 "Insert the string `@item' in a Texinfo buffer."
654 (interactive)
655 (insert "@item")
656 (newline))
657
658 (defun texinfo-insert-@kbd (&optional arg)
659 "Insert a `@kbd{...}' command in a Texinfo buffer.
660 A numeric argument says how many words the braces should surround.
661 The default is not to surround any existing words with the braces."
662 (interactive "P")
663 (texinfo-insert-@-with-arg "kbd" arg))
664
665 (defun texinfo-insert-@node ()
666 "Insert the string `@node' in a Texinfo buffer.
667 This also inserts on the following line a comment indicating
668 the order of arguments to @node."
669 (interactive)
670 (insert "@node \n@comment node-name, next, previous, up")
671 (forward-line -1)
672 (forward-char 6))
673
674 (defun texinfo-insert-@noindent ()
675 "Insert the string `@noindent' in a Texinfo buffer."
676 (interactive)
677 (insert "@noindent\n"))
678
679 (defun texinfo-insert-@samp (&optional arg)
680 "Insert a `@samp{...}' command in a Texinfo buffer.
681 A numeric argument says how many words the braces should surround.
682 The default is not to surround any existing words with the braces."
683 (interactive "P")
684 (texinfo-insert-@-with-arg "samp" arg))
685
686 (defun texinfo-insert-@table (&optional arg)
687 "Insert the string `@table' in a Texinfo buffer."
688 (interactive "P")
689 (insert "@table "))
690
691 (defun texinfo-insert-@var (&optional arg)
692 "Insert a `@var{}' command in a Texinfo buffer.
693 A numeric argument says how many words the braces should surround.
694 The default is not to surround any existing words with the braces."
695 (interactive "P")
696 (texinfo-insert-@-with-arg "var" arg))
697 \f
698 ;;; Texinfo file structure
699
700 ;; These are defined in texnfo-upd.el. defvars here avoid warnings.
701 (defvar texinfo-section-types-regexp)
702 (defvar texinfo-section-level-regexp)
703 (defvar texinfo-subsection-level-regexp)
704 (defvar texinfo-subsubsection-level-regexp)
705
706 (defun texinfo-show-structure (&optional nodes-too)
707 "Show the structure of a Texinfo file.
708 List the lines in the file that begin with the @-sign commands for
709 @chapter, @section, and the like.
710
711 With optional argument (prefix if interactive), list both the lines
712 with @-sign commands for @chapter, @section, and the like, and list
713 @node lines.
714
715 Lines with structuring commands beginning in them are displayed in
716 another buffer named `*Occur*'. In that buffer, you can move point to
717 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
718 to jump to the corresponding spot in the Texinfo source file."
719
720 (interactive "P")
721 (require 'texnfo-upd)
722 (save-excursion
723 (goto-char (point-min))
724 (if nodes-too
725 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
726 (occur texinfo-section-types-regexp)))
727 (pop-to-buffer "*Occur*")
728 (goto-char (point-min))
729 (flush-lines "-----")
730 ;; Now format the "*Occur*" buffer to show the structure.
731 ;; Thanks to ceder@signum.se (Per Cederqvist)
732 (goto-char (point-max))
733 (let ((margin 5))
734 (while (re-search-backward "^ *[0-9]*:" nil 0)
735 (re-search-forward ":")
736 (setq margin
737 (cond
738 ((looking-at
739 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
740 ;; ((looking-at "@chapter ") 5)
741 ;; ((looking-at "@unnumbered ") 5)
742 ;; ((looking-at "@appendix ") 5)
743 ;; ((looking-at "@majorheading ") 5)
744 ;; ((looking-at "@chapheading ") 5)
745
746 ((looking-at
747 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
748 ;; ((looking-at "@section ") 9)
749 ;; ((looking-at "@unnumberedsec ") 9)
750 ;; ((looking-at "@appendixsec ") 9)
751 ;; ((looking-at "@heading ") 9)
752
753 ((looking-at
754 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
755 ;; ((looking-at "@subsection ") 13)
756 ;; ((looking-at "@unnumberedsubsec ") 13)
757 ;; ((looking-at "@appendixsubsec ") 13)
758 ;; ((looking-at "@subheading ") 13)
759
760 ((looking-at
761 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
762 ;; ((looking-at "@subsubsection ") 17)
763 ;; ((looking-at "@unnumberedsubsubsec ") 17)
764 ;; ((looking-at "@appendixsubsubsec ") 17)
765 ;; ((looking-at "@subsubheading ") 17)
766 (t margin)))
767 (indent-to-column margin)
768 (beginning-of-line))))
769 \f
770 ;;; The tex and print function definitions:
771
772 (defcustom texinfo-texi2dvi-command "texi2dvi"
773 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
774 :type 'string
775 :group 'texinfo)
776
777 (defcustom texinfo-tex-command "tex"
778 "*Command used by `texinfo-tex-region' to run TeX on a region."
779 :type 'string
780 :group 'texinfo)
781
782 (defcustom texinfo-texindex-command "texindex"
783 "*Command used by `texinfo-texindex' to sort unsorted index files."
784 :type 'string
785 :group 'texinfo)
786
787 (defcustom texinfo-delete-from-print-queue-command "lprm"
788 "*Command string used to delete a job from the line printer queue.
789 Command is used by \\[texinfo-delete-from-print-queue] based on
790 number provided by a previous \\[tex-show-print-queue]
791 command."
792 :type 'string
793 :group 'texinfo)
794
795 (defvar texinfo-tex-trailer "@bye"
796 "String appended after a region sent to TeX by `texinfo-tex-region'.")
797
798 (defun texinfo-tex-region (beg end)
799 "Run TeX on the current region.
800 This works by writing a temporary file (`tex-zap-file') in the directory
801 that is the value of `tex-directory', then running TeX on that file.
802
803 The first line of the buffer is copied to the
804 temporary file; and if the buffer has a header, it is written to the
805 temporary file before the region itself. The buffer's header is all lines
806 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
807 inclusive. The header must start in the first 100 lines.
808
809 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
810 (interactive "r")
811 (require 'tex-mode)
812 (let ((tex-command texinfo-tex-command)
813 (tex-trailer "@bye\n"))
814 (tex-region beg end)))
815
816 (defun texinfo-tex-buffer ()
817 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
818 (interactive)
819 (require 'tex-mode)
820 (let ((tex-command texinfo-texi2dvi-command))
821 (tex-buffer)))
822
823 (defun texinfo-texindex ()
824 "Run `texindex' on unsorted index files.
825 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
826 This runs the shell command defined by `texinfo-texindex-command'."
827 (interactive)
828 (require 'tex-mode)
829 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
830 ;; alternatively
831 ;; (send-string "tex-shell"
832 ;; (concat texinfo-texindex-command
833 ;; " " tex-zap-file ".??" "\n"))
834 (tex-recenter-output-buffer nil))
835
836 (defun texinfo-tex-print ()
837 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
838 This runs the shell command defined by `tex-dvi-print-command'."
839 (interactive)
840 (require 'tex-mode)
841 (tex-print))
842
843 (defun texinfo-tex-view ()
844 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
845 This runs the shell command defined by `tex-dvi-view-command'."
846 (interactive)
847 (require 'tex-mode)
848 (tex-view))
849
850 (defun texinfo-quit-job ()
851 "Quit currently running TeX job, by sending an `x' to it."
852 (interactive)
853 (if (not (get-process "tex-shell"))
854 (error "No TeX shell running"))
855 (tex-send-command "x"))
856 ;; alternatively:
857 ;; save-excursion
858 ;; (set-buffer (get-buffer "*tex-shell*"))
859 ;; (goto-char (point-max))
860 ;; (insert "x")
861 ;; (comint-send-input)
862
863 (defun texinfo-delete-from-print-queue (job-number)
864 "Delete job from the line printer spooling queue.
865 You are prompted for the job number (use a number shown by a previous
866 \\[tex-show-print-queue] command)."
867 (interactive "nPrinter job number for deletion: ")
868 (require 'tex-mode)
869 (if (tex-shell-running)
870 (tex-kill-job)
871 (tex-start-shell))
872 (tex-send-command texinfo-delete-from-print-queue-command job-number)
873 ;; alternatively
874 ;; (send-string "tex-shell"
875 ;; (concat
876 ;; texinfo-delete-from-print-queue-command
877 ;; " "
878 ;; job-number"\n"))
879 (tex-recenter-output-buffer nil))
880
881 (provide 'texinfo)
882
883 ;;; texinfo.el ends here