]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfo.el
bf1a523ec0e7c9455640f39d04e8f7893dabffbc
[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@gnu.org
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 \f
42 ;;; Autoloads:
43
44 (autoload 'makeinfo-region
45 "makeinfo"
46 "Make Info file from region of current Texinfo file, and switch to it.
47
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'."
51 t nil)
52
53 (autoload 'makeinfo-buffer
54 "makeinfo"
55 "Make Info file from current buffer.
56
57 Use the \\[next-error] command to move to the next error
58 \(if there are errors\)."
59 t nil)
60
61 (autoload 'kill-compilation
62 "compile"
63 "Kill the process made by the \\[compile] command."
64 t nil)
65
66 (autoload 'makeinfo-recenter-compilation-buffer
67 "makeinfo"
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."
71 t nil)
72
73 (autoload 'texinfo-update-node
74 "texnfo-upd"
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
77 marked region.
78
79 The functions for creating or updating nodes and menus, and their
80 keybindings, are:
81
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)
85
86 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
87 texinfo-all-menus-update () \\[texinfo-all-menus-update]
88 texinfo-master-menu ()
89
90 texinfo-indent-menu-description (column &optional region-p)
91
92 The `texinfo-column-for-description' variable specifies the column to
93 which menu descriptions are indented. Its default value is 32."
94 t nil)
95
96 (autoload 'texinfo-every-node-update
97 "texnfo-upd"
98 "Update every node in a Texinfo file."
99 t nil)
100
101 (autoload 'texinfo-sequential-node-update
102 "texnfo-upd"
103 "Update one node (or many) in a Texinfo file with sequential pointers.
104
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.
109
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
112 marked region.
113
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."
118 t nil)
119
120 (autoload 'texinfo-make-menu
121 "texnfo-upd"
122 "Without any prefix argument, make or update a menu.
123 Make the menu for the section enclosing the node found following point.
124
125 Non-nil argument (prefix, if interactive) means make or update menus
126 for nodes within or part of the marked region.
127
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."
132 t nil)
133
134 (autoload 'texinfo-all-menus-update
135 "texnfo-upd"
136 "Update every regular menu in a Texinfo file.
137 Remove pre-existing master menu, if there is one.
138
139 If called with a non-nil argument, this function first updates all the
140 nodes in the buffer before updating the menus."
141 t nil)
142
143 (autoload 'texinfo-master-menu
144 "texnfo-upd"
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.
148
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.
152
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.
156
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'.
160
161 The master menu has the following format, which is adapted from the
162 recommendation in the Texinfo Manual:
163
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.
168
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.
173
174 Each of the menus in the detailed node listing is introduced by the
175 title of the section containing the menu."
176 t nil)
177
178 (autoload 'texinfo-indent-menu-description
179 "texnfo-upd"
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."
184 t nil)
185
186 (autoload 'texinfo-insert-node-lines
187 "texnfo-upd"
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."
192 t nil)
193
194 (autoload 'texinfo-start-menu-description
195 "texnfo-upd"
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.
199
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."
202 t nil)
203
204 (autoload 'texinfo-multiple-files-update
205 "texnfo-upd"
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.
209
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.
213
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.
218
219 The command also updates the `Top' level node pointers of OUTER-FILE.
220
221 Notes:
222
223 * this command does NOT save any files--you must save the
224 outer file and any modified, included files.
225
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.
229
230 Requirements:
231
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.
236
237 Thus, normally, each included file contains one, and only one,
238 chapter."
239 t nil)
240
241 \f
242 ;;; Code:
243
244 ;;; Don't you dare insert any `require' calls at top level in this file--rms.
245
246 ;;; Syntax table
247
248 (defvar texinfo-mode-syntax-table nil)
249
250 (if texinfo-mode-syntax-table
251 nil
252 (setq texinfo-mode-syntax-table (make-syntax-table))
253 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
254 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
255 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
256 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
257 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
258 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
259 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
260 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
261 (modify-syntax-entry ?\n ">" texinfo-mode-syntax-table)
262 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
263
264 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
265 ;; To override this example, set either `imenu-generic-expression'
266 ;; or `imenu-create-index-function'.
267 (defvar texinfo-imenu-generic-expression
268 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
269 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
270
271 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
272
273 (defvar texinfo-font-lock-syntactic-keywords
274 '(("\\(@\\)c\\(omment\\)?\\>" (1 '(11))))
275 "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
276
277 (defvar texinfo-font-lock-keywords
278 '(;; All but the first had an OVERRIDE of t.
279 ;; It didn't seem to be any better, and it's slower--simon.
280 ;; Robert J. Chassell <bob@gnu.org> says remove this line.
281 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
282 ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
283 ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
284 ("@\\(emph\\|strong\\|b\\|i\\|sc\\){\\([^}]+\\)" 2 font-lock-comment-face)
285 ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
286 ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
287 2 font-lock-variable-name-face)
288 ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face)
289 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
290 )
291 "Additional expressions to highlight in TeXinfo mode.")
292
293 (defvar texinfo-section-list
294 '(("top" 1)
295 ("majorheading" 1)
296 ("chapter" 2)
297 ("unnumbered" 2)
298 ("appendix" 2)
299 ("chapheading" 2)
300 ("section" 3)
301 ("unnumberedsec" 3)
302 ("appendixsec" 3)
303 ("heading" 3)
304 ("subsection" 4)
305 ("unnumberedsubsec" 4)
306 ("appendixsubsec" 4)
307 ("subheading" 4)
308 ("subsubsection" 5)
309 ("unnumberedsubsubsec" 5)
310 ("appendixsubsubsec" 5)
311 ("subsubheading" 5))
312 "Alist of sectioning commands and their relative level.")
313
314 (defun texinfo-outline-level ()
315 ;; Calculate level of current texinfo outline heading.
316 (save-excursion
317 (if (bobp)
318 0
319 (forward-char 1)
320 (let* ((word (buffer-substring-no-properties
321 (point) (progn (forward-word 1) (point))))
322 (entry (assoc word texinfo-section-list)))
323 (if entry
324 (nth 1 entry)
325 5)))))
326
327 \f
328 ;;; Keybindings
329 (defvar texinfo-mode-map nil)
330
331 ;;; Keys common both to Texinfo mode and to TeX shell.
332
333 (defun texinfo-define-common-keys (keymap)
334 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
335 (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
336 (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
337 (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
338 (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
339 (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
340 (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
341 (define-key keymap "\C-c\C-t\C-v" 'texinfo-tex-view)
342 (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
343
344 (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
345 (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
346
347 ;; Mode documentation displays commands in reverse order
348 ;; from how they are listed in the texinfo-mode-map.
349
350 (if texinfo-mode-map
351 nil
352 (setq texinfo-mode-map (make-sparse-keymap))
353
354 ;; bindings for `texnfo-tex.el'
355 (texinfo-define-common-keys texinfo-mode-map)
356
357 ;; Bindings from `tex-mode.el'
358 ;; This should still use " when inside @example and @code
359 ;;(define-key texinfo-mode-map "\"" 'tex-insert-quote)
360
361 ;; bindings for `makeinfo.el'
362 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
363 (define-key texinfo-mode-map "\C-c\C-m\C-l"
364 'makeinfo-recenter-compilation-buffer)
365 (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
366 (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
367
368 ;; bindings for `texinfmt.el'
369 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
370 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
371
372 ;; bindings for updating nodes and menus
373
374 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
375
376 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
377 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
378 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
379 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
380
381 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
382
383 (define-key texinfo-mode-map "\C-c}" 'up-list)
384 (define-key texinfo-mode-map "\C-c]" 'up-list)
385 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
386
387 ;; bindings for inserting strings
388 (define-key texinfo-mode-map "\C-c\C-o" 'texinfo-insert-block)
389 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
390
391 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
392 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
393 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
394 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
395 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
396 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
397 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
398 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
399 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
400 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
401 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
402 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
403
404 \f
405 ;;; Texinfo mode
406
407 ;; Also defined in texnfo-upd.el but copied here to avoid having
408 ;; to require texnfo-upd.el.
409 (defvar texinfo-chapter-level-regexp
410 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
411 "Regular expression matching Texinfo chapter-level headings.
412 This does not match `@node' and does not match the `@top' command.")
413
414 ;;;###autoload
415 (define-derived-mode texinfo-mode text-mode "Texinfo"
416 "Major mode for editing Texinfo files.
417
418 It has these extra commands:
419 \\{texinfo-mode-map}
420
421 These are files that are used as input for TeX to make printed manuals
422 and also to be turned into Info files with \\[makeinfo-buffer] or
423 the `makeinfo' program. These files must be written in a very restricted and
424 modified version of TeX input format.
425
426 Editing commands are like text-mode except that the syntax table is
427 set up so expression commands skip Texinfo bracket groups. To see
428 what the Info version of a region of the Texinfo file will look like,
429 use \\[makeinfo-region], which runs `makeinfo' on the current region.
430
431 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
432 This command shows the structure of a Texinfo file by listing the
433 lines with the @-sign commands for @chapter, @section, and the like.
434 These lines are displayed in another window called the *Occur* window.
435 In that window, you can position the cursor over one of the lines and
436 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
437 in the Texinfo file.
438
439 In addition, Texinfo mode provides commands that insert various
440 frequently used @-sign commands into the buffer. You can use these
441 commands to save keystrokes. And you can insert balanced braces with
442 \\[texinfo-insert-braces] and later use the command \\[up-list] to
443 move forward past the closing brace.
444
445 Also, Texinfo mode provides functions for automatically creating or
446 updating menus and node pointers. These functions
447
448 * insert the `Next', `Previous' and `Up' pointers of a node,
449 * insert or update the menu for a section, and
450 * create a master menu for a Texinfo source file.
451
452 Here are the functions:
453
454 texinfo-update-node \\[texinfo-update-node]
455 texinfo-every-node-update \\[texinfo-every-node-update]
456 texinfo-sequential-node-update
457
458 texinfo-make-menu \\[texinfo-make-menu]
459 texinfo-all-menus-update \\[texinfo-all-menus-update]
460 texinfo-master-menu
461
462 texinfo-indent-menu-description (column &optional region-p)
463
464 The `texinfo-column-for-description' variable specifies the column to
465 which menu descriptions are indented.
466
467 Passed an argument (a prefix argument, if interactive), the
468 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
469 in the region.
470
471 To use the updating commands, you must structure your Texinfo file
472 hierarchically, such that each `@node' line, with the exception of the
473 Top node, is accompanied by some kind of section line, such as an
474 `@chapter' or `@section' line.
475
476 If the file has a `top' node, it must be called `top' or `Top' and
477 be the first node in the file.
478
479 Entering Texinfo mode calls the value of `text-mode-hook', and then the
480 value of `texinfo-mode-hook'."
481 (make-local-variable 'page-delimiter)
482 (setq page-delimiter
483 (concat
484 "^@node [ \t]*[Tt]op\\|^@\\("
485 texinfo-chapter-level-regexp
486 "\\)"))
487 (make-local-variable 'require-final-newline)
488 (setq require-final-newline t)
489 (make-local-variable 'indent-tabs-mode)
490 (setq indent-tabs-mode nil)
491 (make-local-variable 'paragraph-separate)
492 (setq paragraph-separate
493 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
494 (make-local-variable 'paragraph-start)
495 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
496 (make-local-variable 'adaptive-fill-mode)
497 (setq adaptive-fill-mode nil)
498 (make-local-variable 'fill-column)
499 (setq fill-column 72)
500 (make-local-variable 'comment-start)
501 (setq comment-start "@c ")
502 (make-local-variable 'comment-start-skip)
503 (setq comment-start-skip "@c +\\|@comment +")
504 (make-local-variable 'words-include-escapes)
505 (setq words-include-escapes t)
506 (make-local-variable 'imenu-generic-expression)
507 (setq imenu-generic-expression texinfo-imenu-generic-expression)
508 (setq imenu-case-fold-search nil)
509 (make-local-variable 'font-lock-defaults)
510 (setq font-lock-defaults
511 '(texinfo-font-lock-keywords nil nil nil nil
512 (font-lock-syntactic-keywords
513 . texinfo-font-lock-syntactic-keywords)))
514 (set (make-local-variable 'parse-sexp-lookup-properties) t)
515 (make-local-variable 'outline-regexp)
516 (setq outline-regexp
517 (concat "@" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\>"))
518 (make-local-variable 'outline-level)
519 (setq outline-level 'texinfo-outline-level)
520 (make-local-variable 'tex-start-of-header)
521 (setq tex-start-of-header "%\\*\\*start")
522 (make-local-variable 'tex-end-of-header)
523 (setq tex-end-of-header "%\\*\\*end")
524 (make-local-variable 'tex-first-line-header-regexp)
525 (setq tex-first-line-header-regexp "^\\\\input")
526 (make-local-variable 'tex-trailer)
527 (setq tex-trailer "@bye\n"))
528
529 \f
530 ;;; Insert string commands
531
532 (defconst texinfo-environments
533 '("cartouche"
534 "defcv"
535 "deffn"
536 "defivar"
537 "defmac"
538 "defmethod"
539 "defop"
540 "defopt"
541 "defspec"
542 "deftp"
543 "deftypefn"
544 "deftypefun"
545 "deftypevar"
546 "deftypevr"
547 "defun"
548 "defvar"
549 "defvr"
550 "description"
551 "display"
552 "enumerate"
553 "example"
554 "flushleft"
555 "flushright"
556 "format"
557 "ftable"
558 "group"
559 "ifclear"
560 "ifset"
561 "ifhtml"
562 "ifinfo"
563 "ifnothtml"
564 "ifnotinfo"
565 "ifnottex"
566 "iftex"
567 "ignore"
568 "itemize"
569 "lisp"
570 "macro"
571 "multitable"
572 "quotation"
573 "smalldisplay"
574 "smallexample"
575 "smallformat"
576 "smalllisp"
577 "table"
578 "tex"
579 "titlepage"
580 "vtable")
581 "List of TeXinfo environments.")
582
583 ;; Keep as concatenated lists for ease of maintenance
584 (defconst texinfo-environment-regexp
585 (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
586 "Regexp for environment-like TexInfo list commands.
587 Subexpression 1 is what goes into the corresponding `@end' statement.")
588
589 (define-skeleton texinfo-insert-block
590 "Create a matching pair @<cmd> .. @end <cmd> at point.
591 Puts point on a blank line between them."
592 (completing-read "Block name: " (mapcar 'list texinfo-environments))
593 "@" str \n _ \n "@end " str \n)
594
595 ;; The following texinfo-insert-@end command not only inserts a SPC
596 ;; after the @end, but tries to find out what belongs there. It is
597 ;; not very smart: it does not understand nested lists.
598
599 (defun texinfo-insert-@end ()
600 "Insert the matching `@end' for the last Texinfo command that needs one."
601 (interactive)
602 (let ((depth 1) string)
603 (save-excursion
604 (while (and (> depth 0)
605 (re-search-backward texinfo-environment-regexp nil t))
606 (if (looking-at "@end")
607 (setq depth (1+ depth))
608 (setq depth (1- depth))))
609 (looking-at texinfo-environment-regexp)
610 (if (zerop depth)
611 (setq string
612 (buffer-substring (match-beginning 1)
613 (match-end 1)))))
614 (insert "@end ")
615 (if string (insert string "\n"))))
616
617 ;; The following insert commands accept a prefix arg N, which is the
618 ;; number of words (actually s-exprs) that should be surrounded by
619 ;; braces. Thus you can first paste a variable name into a .texinfo
620 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
621 ;; pasted variable name to put @var{...} *around* the variable name.
622 ;; Operate on previous word or words with negative arg.
623
624 ;; These commands use texinfo-insert-@-with-arg
625 (defun texinfo-insert-@-with-arg (string &optional arg)
626 (if arg
627 (progn
628 (setq arg (prefix-numeric-value arg))
629 (if (< arg 0)
630 (progn
631 (skip-chars-backward " \t\n\r\f")
632 (save-excursion
633 (forward-sexp arg)
634 (insert "@" string "{"))
635 (insert "}"))
636 (skip-chars-forward " \t\n\r\f")
637 (insert "@" string "{")
638 (forward-sexp arg)
639 (insert "}")))
640 (insert "@" string "{}")
641 (backward-char)))
642
643 (defun texinfo-insert-braces ()
644 "Make a pair of braces and be poised to type inside of them.
645 Use \\[up-list] to move forward out of the braces."
646 (interactive)
647 (insert "{}")
648 (backward-char))
649
650 (defun texinfo-insert-@code (&optional arg)
651 "Insert a `@code{...}' command in a Texinfo buffer.
652 A numeric argument says how many words the braces should surround.
653 The default is not to surround any existing words with the braces."
654 (interactive "P")
655 (texinfo-insert-@-with-arg "code" arg))
656
657 (defun texinfo-insert-@dfn (&optional arg)
658 "Insert a `@dfn{...}' command in a Texinfo buffer.
659 A numeric argument says how many words the braces should surround.
660 The default is not to surround any existing words with the braces."
661 (interactive "P")
662 (texinfo-insert-@-with-arg "dfn" arg))
663
664 (defun texinfo-insert-@example ()
665 "Insert the string `@example' in a Texinfo buffer."
666 (interactive)
667 (insert "@example\n"))
668
669 (defun texinfo-insert-@file (&optional arg)
670 "Insert a `@file{...}' command in a Texinfo buffer.
671 A numeric argument says how many words the braces should surround.
672 The default is not to surround any existing words with the braces."
673 (interactive "P")
674 (texinfo-insert-@-with-arg "file" arg))
675
676 (defun texinfo-insert-@item ()
677 "Insert the string `@item' in a Texinfo buffer."
678 (interactive)
679 (insert "@item")
680 (newline))
681
682 (defun texinfo-insert-@kbd (&optional arg)
683 "Insert a `@kbd{...}' command in a Texinfo buffer.
684 A numeric argument says how many words the braces should surround.
685 The default is not to surround any existing words with the braces."
686 (interactive "P")
687 (texinfo-insert-@-with-arg "kbd" arg))
688
689 (defun texinfo-insert-@node ()
690 "Insert the string `@node' in a Texinfo buffer.
691 This also inserts on the following line a comment indicating
692 the order of arguments to @node."
693 (interactive)
694 (insert "@node \n@comment node-name, next, previous, up")
695 (forward-line -1)
696 (forward-char 6))
697
698 (defun texinfo-insert-@noindent ()
699 "Insert the string `@noindent' in a Texinfo buffer."
700 (interactive)
701 (insert "@noindent\n"))
702
703 (defun texinfo-insert-@samp (&optional arg)
704 "Insert a `@samp{...}' command in a Texinfo buffer.
705 A numeric argument says how many words the braces should surround.
706 The default is not to surround any existing words with the braces."
707 (interactive "P")
708 (texinfo-insert-@-with-arg "samp" arg))
709
710 (defun texinfo-insert-@table (&optional arg)
711 "Insert the string `@table' in a Texinfo buffer."
712 (interactive "P")
713 (insert "@table "))
714
715 (defun texinfo-insert-@var (&optional arg)
716 "Insert a `@var{}' command in a Texinfo buffer.
717 A numeric argument says how many words the braces should surround.
718 The default is not to surround any existing words with the braces."
719 (interactive "P")
720 (texinfo-insert-@-with-arg "var" arg))
721 \f
722 ;;; Texinfo file structure
723
724 ;; These are defined in texnfo-upd.el. defvars here avoid warnings.
725 (defvar texinfo-section-types-regexp)
726 (defvar texinfo-section-level-regexp)
727 (defvar texinfo-subsection-level-regexp)
728 (defvar texinfo-subsubsection-level-regexp)
729
730 (defun texinfo-show-structure (&optional nodes-too)
731 "Show the structure of a Texinfo file.
732 List the lines in the file that begin with the @-sign commands for
733 @chapter, @section, and the like.
734
735 With optional argument (prefix if interactive), list both the lines
736 with @-sign commands for @chapter, @section, and the like, and list
737 @node lines.
738
739 Lines with structuring commands beginning in them are displayed in
740 another buffer named `*Occur*'. In that buffer, you can move point to
741 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
742 to jump to the corresponding spot in the Texinfo source file."
743
744 (interactive "P")
745 (require 'texnfo-upd)
746 (save-excursion
747 (goto-char (point-min))
748 (if nodes-too
749 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
750 (occur texinfo-section-types-regexp)))
751 (pop-to-buffer "*Occur*")
752 (goto-char (point-min))
753 (let ((inhibit-read-only t))
754 (flush-lines "-----")
755 ;; Now format the "*Occur*" buffer to show the structure.
756 ;; Thanks to ceder@signum.se (Per Cederqvist)
757 (goto-char (point-max))
758 (let ((margin 5))
759 (while (re-search-backward "^ *[0-9]*:" nil 0)
760 (re-search-forward ":")
761 (setq margin
762 (cond
763 ((looking-at
764 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
765 ;; ((looking-at "@chapter ") 5)
766 ;; ((looking-at "@unnumbered ") 5)
767 ;; ((looking-at "@appendix ") 5)
768 ;; ((looking-at "@majorheading ") 5)
769 ;; ((looking-at "@chapheading ") 5)
770
771 ((looking-at
772 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
773 ;; ((looking-at "@section ") 9)
774 ;; ((looking-at "@unnumberedsec ") 9)
775 ;; ((looking-at "@appendixsec ") 9)
776 ;; ((looking-at "@heading ") 9)
777
778 ((looking-at
779 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
780 ;; ((looking-at "@subsection ") 13)
781 ;; ((looking-at "@unnumberedsubsec ") 13)
782 ;; ((looking-at "@appendixsubsec ") 13)
783 ;; ((looking-at "@subheading ") 13)
784
785 ((looking-at
786 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
787 ;; ((looking-at "@subsubsection ") 17)
788 ;; ((looking-at "@unnumberedsubsubsec ") 17)
789 ;; ((looking-at "@appendixsubsubsec ") 17)
790 ;; ((looking-at "@subsubheading ") 17)
791 (t margin)))
792 (indent-to-column margin)
793 (beginning-of-line)))))
794 \f
795 ;;; The tex and print function definitions:
796
797 (defcustom texinfo-texi2dvi-command "texi2dvi"
798 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
799 :type 'string
800 :group 'texinfo)
801
802 (defcustom texinfo-tex-command "tex"
803 "*Command used by `texinfo-tex-region' to run TeX on a region."
804 :type 'string
805 :group 'texinfo)
806
807 (defcustom texinfo-texindex-command "texindex"
808 "*Command used by `texinfo-texindex' to sort unsorted index files."
809 :type 'string
810 :group 'texinfo)
811
812 (defcustom texinfo-delete-from-print-queue-command "lprm"
813 "*Command string used to delete a job from the line printer queue.
814 Command is used by \\[texinfo-delete-from-print-queue] based on
815 number provided by a previous \\[tex-show-print-queue]
816 command."
817 :type 'string
818 :group 'texinfo)
819
820 (defvar texinfo-tex-trailer "@bye"
821 "String appended after a region sent to TeX by `texinfo-tex-region'.")
822
823 (defun texinfo-tex-region (beg end)
824 "Run TeX on the current region.
825 This works by writing a temporary file (`tex-zap-file') in the directory
826 that is the value of `tex-directory', then running TeX on that file.
827
828 The first line of the buffer is copied to the
829 temporary file; and if the buffer has a header, it is written to the
830 temporary file before the region itself. The buffer's header is all lines
831 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
832 inclusive. The header must start in the first 100 lines.
833
834 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
835 (interactive "r")
836 (require 'tex-mode)
837 (let ((tex-command texinfo-tex-command)
838 (tex-trailer texinfo-tex-trailer))
839 (tex-region beg end)))
840
841 (defun texinfo-tex-buffer ()
842 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
843 (interactive)
844 (require 'tex-mode)
845 (let ((tex-command texinfo-texi2dvi-command)
846 ;; Disable tex-start-options-string. texi2dvi would not
847 ;; understand anything specified here.
848 (tex-start-options-string ""))
849 (tex-buffer)))
850
851 (defun texinfo-texindex ()
852 "Run `texindex' on unsorted index files.
853 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
854 This runs the shell command defined by `texinfo-texindex-command'."
855 (interactive)
856 (require 'tex-mode)
857 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
858 ;; alternatively
859 ;; (send-string "tex-shell"
860 ;; (concat texinfo-texindex-command
861 ;; " " tex-zap-file ".??" "\n"))
862 (tex-recenter-output-buffer nil))
863
864 (defun texinfo-tex-print ()
865 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
866 This runs the shell command defined by `tex-dvi-print-command'."
867 (interactive)
868 (require 'tex-mode)
869 (tex-print))
870
871 (defun texinfo-tex-view ()
872 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
873 This runs the shell command defined by `tex-dvi-view-command'."
874 (interactive)
875 (require 'tex-mode)
876 (tex-view))
877
878 (defun texinfo-quit-job ()
879 "Quit currently running TeX job, by sending an `x' to it."
880 (interactive)
881 (if (not (get-process "tex-shell"))
882 (error "No TeX shell running"))
883 (tex-send-command "x"))
884 ;; alternatively:
885 ;; save-excursion
886 ;; (set-buffer (get-buffer "*tex-shell*"))
887 ;; (goto-char (point-max))
888 ;; (insert "x")
889 ;; (comint-send-input)
890
891 (defun texinfo-delete-from-print-queue (job-number)
892 "Delete job from the line printer spooling queue.
893 You are prompted for the job number (use a number shown by a previous
894 \\[tex-show-print-queue] command)."
895 (interactive "nPrinter job number for deletion: ")
896 (require 'tex-mode)
897 (if (tex-shell-running)
898 (tex-kill-job)
899 (tex-start-shell))
900 (tex-send-command texinfo-delete-from-print-queue-command job-number)
901 ;; alternatively
902 ;; (send-string "tex-shell"
903 ;; (concat
904 ;; texinfo-delete-from-print-queue-command
905 ;; " "
906 ;; job-number"\n"))
907 (tex-recenter-output-buffer nil))
908
909 (provide 'texinfo)
910
911 ;;; texinfo.el ends here