]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfo.el
(describe-mode): Test mini-mode symbol for being
[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 (define-key texinfo-mode-map "\C-c\C-c\C-s" 'texinfo-insert-@strong)
391 (define-key texinfo-mode-map "\C-c\C-c\C-e" 'texinfo-insert-@emph)
392
393 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
394 (define-key texinfo-mode-map "\C-c\C-cu" 'texinfo-insert-@url)
395 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
396 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
397 ;; (define-key texinfo-mode-map "\C-c\C-cr" 'texinfo-insert-@uref)
398 (define-key texinfo-mode-map "\C-c\C-cq" 'texinfo-insert-@quotation)
399 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
400 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
401 (define-key texinfo-mode-map "\C-c\C-cm" 'texinfo-insert-@email)
402 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
403 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
404 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
405 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
406 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
407 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
408 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
409
410 \f
411 ;;; Texinfo mode
412
413 ;; Also defined in texnfo-upd.el but copied here to avoid having
414 ;; to require texnfo-upd.el.
415 (defvar texinfo-chapter-level-regexp
416 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
417 "Regular expression matching Texinfo chapter-level headings.
418 This does not match `@node' and does not match the `@top' command.")
419
420 ;;;###autoload
421 (define-derived-mode texinfo-mode text-mode "Texinfo"
422 "Major mode for editing Texinfo files.
423
424 It has these extra commands:
425 \\{texinfo-mode-map}
426
427 These are files that are used as input for TeX to make printed manuals
428 and also to be turned into Info files with \\[makeinfo-buffer] or
429 the `makeinfo' program. These files must be written in a very restricted and
430 modified version of TeX input format.
431
432 Editing commands are like text-mode except that the syntax table is
433 set up so expression commands skip Texinfo bracket groups. To see
434 what the Info version of a region of the Texinfo file will look like,
435 use \\[makeinfo-region], which runs `makeinfo' on the current region.
436
437 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
438 This command shows the structure of a Texinfo file by listing the
439 lines with the @-sign commands for @chapter, @section, and the like.
440 These lines are displayed in another window called the *Occur* window.
441 In that window, you can position the cursor over one of the lines and
442 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
443 in the Texinfo file.
444
445 In addition, Texinfo mode provides commands that insert various
446 frequently used @-sign commands into the buffer. You can use these
447 commands to save keystrokes. And you can insert balanced braces with
448 \\[texinfo-insert-braces] and later use the command \\[up-list] to
449 move forward past the closing brace.
450
451 Also, Texinfo mode provides functions for automatically creating or
452 updating menus and node pointers. These functions
453
454 * insert the `Next', `Previous' and `Up' pointers of a node,
455 * insert or update the menu for a section, and
456 * create a master menu for a Texinfo source file.
457
458 Here are the functions:
459
460 texinfo-update-node \\[texinfo-update-node]
461 texinfo-every-node-update \\[texinfo-every-node-update]
462 texinfo-sequential-node-update
463
464 texinfo-make-menu \\[texinfo-make-menu]
465 texinfo-all-menus-update \\[texinfo-all-menus-update]
466 texinfo-master-menu
467
468 texinfo-indent-menu-description (column &optional region-p)
469
470 The `texinfo-column-for-description' variable specifies the column to
471 which menu descriptions are indented.
472
473 Passed an argument (a prefix argument, if interactive), the
474 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
475 in the region.
476
477 To use the updating commands, you must structure your Texinfo file
478 hierarchically, such that each `@node' line, with the exception of the
479 Top node, is accompanied by some kind of section line, such as an
480 `@chapter' or `@section' line.
481
482 If the file has a `top' node, it must be called `top' or `Top' and
483 be the first node in the file.
484
485 Entering Texinfo mode calls the value of `text-mode-hook', and then the
486 value of `texinfo-mode-hook'."
487 (make-local-variable 'page-delimiter)
488 (setq page-delimiter
489 (concat
490 "^@node [ \t]*[Tt]op\\|^@\\("
491 texinfo-chapter-level-regexp
492 "\\)"))
493 (make-local-variable 'require-final-newline)
494 (setq require-final-newline t)
495 (make-local-variable 'indent-tabs-mode)
496 (setq indent-tabs-mode nil)
497 (make-local-variable 'paragraph-separate)
498 (setq paragraph-separate
499 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
500 (make-local-variable 'paragraph-start)
501 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
502 (make-local-variable 'adaptive-fill-mode)
503 (setq adaptive-fill-mode nil)
504 (make-local-variable 'fill-column)
505 (setq fill-column 72)
506 (make-local-variable 'comment-start)
507 (setq comment-start "@c ")
508 (make-local-variable 'comment-start-skip)
509 (setq comment-start-skip "@c +\\|@comment +")
510 (make-local-variable 'words-include-escapes)
511 (setq words-include-escapes t)
512 (make-local-variable 'imenu-generic-expression)
513 (setq imenu-generic-expression texinfo-imenu-generic-expression)
514 (setq imenu-case-fold-search nil)
515 (make-local-variable 'font-lock-defaults)
516 (setq font-lock-defaults
517 '(texinfo-font-lock-keywords nil nil nil nil
518 (font-lock-syntactic-keywords
519 . texinfo-font-lock-syntactic-keywords)))
520 (set (make-local-variable 'parse-sexp-lookup-properties) t)
521 (make-local-variable 'outline-regexp)
522 (setq outline-regexp
523 (concat "@" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\>"))
524 (make-local-variable 'outline-level)
525 (setq outline-level 'texinfo-outline-level)
526 (make-local-variable 'tex-start-of-header)
527 (setq tex-start-of-header "%\\*\\*start")
528 (make-local-variable 'tex-end-of-header)
529 (setq tex-end-of-header "%\\*\\*end")
530 (make-local-variable 'tex-first-line-header-regexp)
531 (setq tex-first-line-header-regexp "^\\\\input")
532 (make-local-variable 'tex-trailer)
533 (setq tex-trailer "@bye\n"))
534
535 \f
536 ;;; Insert string commands
537
538 (defconst texinfo-environments
539 '("cartouche"
540 "defcv"
541 "deffn"
542 "defivar"
543 "defmac"
544 "defmethod"
545 "defop"
546 "defopt"
547 "defspec"
548 "deftp"
549 "deftypefn"
550 "deftypefun"
551 "deftypevar"
552 "deftypevr"
553 "defun"
554 "defvar"
555 "defvr"
556 "description"
557 "display"
558 "enumerate"
559 "example"
560 "flushleft"
561 "flushright"
562 "format"
563 "ftable"
564 "group"
565 "ifclear"
566 "ifset"
567 "ifhtml"
568 "ifinfo"
569 "ifnothtml"
570 "ifnotinfo"
571 "ifnottex"
572 "iftex"
573 "ignore"
574 "itemize"
575 "lisp"
576 "macro"
577 "multitable"
578 "quotation"
579 "smalldisplay"
580 "smallexample"
581 "smallformat"
582 "smalllisp"
583 "table"
584 "tex"
585 "titlepage"
586 "vtable")
587 "List of TeXinfo environments.")
588
589 ;; Keep as concatenated lists for ease of maintenance
590 (defconst texinfo-environment-regexp
591 (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
592 "Regexp for environment-like TexInfo list commands.
593 Subexpression 1 is what goes into the corresponding `@end' statement.")
594
595 (define-skeleton texinfo-insert-block
596 "Create a matching pair @<cmd> .. @end <cmd> at point.
597 Puts point on a blank line between them."
598 (completing-read "Block name: " (mapcar 'list texinfo-environments))
599 "@" str \n _ \n "@end " str \n)
600
601 ;; The following texinfo-insert-@end command not only inserts a SPC
602 ;; after the @end, but tries to find out what belongs there. It is
603 ;; not very smart: it does not understand nested lists.
604
605 (defun texinfo-insert-@end ()
606 "Insert the matching `@end' for the last Texinfo command that needs one."
607 (interactive)
608 (let ((depth 1) string)
609 (save-excursion
610 (while (and (> depth 0)
611 (re-search-backward texinfo-environment-regexp nil t))
612 (if (looking-at "@end")
613 (setq depth (1+ depth))
614 (setq depth (1- depth))))
615 (looking-at texinfo-environment-regexp)
616 (if (zerop depth)
617 (setq string
618 (buffer-substring (match-beginning 1)
619 (match-end 1)))))
620 (insert "@end ")
621 (if string (insert string "\n"))))
622
623 ;; The following insert commands accept a prefix arg N, which is the
624 ;; number of words (actually s-exprs) that should be surrounded by
625 ;; braces. Thus you can first paste a variable name into a .texinfo
626 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
627 ;; pasted variable name to put @var{...} *around* the variable name.
628 ;; Operate on previous word or words with negative arg.
629
630 ;; These commands use texinfo-insert-@-with-arg
631 (defun texinfo-insert-@-with-arg (string &optional arg)
632 (if arg
633 (progn
634 (setq arg (prefix-numeric-value arg))
635 (if (< arg 0)
636 (progn
637 (skip-chars-backward " \t\n\r\f")
638 (save-excursion
639 (forward-sexp arg)
640 (insert "@" string "{"))
641 (insert "}"))
642 (skip-chars-forward " \t\n\r\f")
643 (insert "@" string "{")
644 (forward-sexp arg)
645 (insert "}")))
646 (insert "@" string "{}")
647 (backward-char)))
648
649 (defun texinfo-insert-braces ()
650 "Make a pair of braces and be poised to type inside of them.
651 Use \\[up-list] to move forward out of the braces."
652 (interactive)
653 (insert "{}")
654 (backward-char))
655
656 (defun texinfo-insert-@code (&optional arg)
657 "Insert a `@code{...}' command in a Texinfo buffer.
658 A numeric argument says how many words the braces should surround.
659 The default is not to surround any existing words with the braces."
660 (interactive "P")
661 (texinfo-insert-@-with-arg "code" arg))
662
663 (defun texinfo-insert-@dfn (&optional arg)
664 "Insert a `@dfn{...}' command in a Texinfo buffer.
665 A numeric argument says how many words the braces should surround.
666 The default is not to surround any existing words with the braces."
667 (interactive "P")
668 (texinfo-insert-@-with-arg "dfn" arg))
669
670 (defun texinfo-insert-@email (&optional arg)
671 "Insert a `@email{...}' command in a Texinfo buffer.
672 A numeric argument says how many words the braces should surround.
673 The default is not to surround any existing words with the braces."
674 (interactive "P")
675 (texinfo-insert-@-with-arg "email" arg))
676
677 (defun texinfo-insert-@emph (&optional arg)
678 "Insert a `@emph{...}' command in a Texinfo buffer.
679 A numeric argument says how many words the braces should surround.
680 The default is not to surround any existing words with the braces."
681 (interactive "P")
682 (texinfo-insert-@-with-arg "emph" arg))
683
684 (defun texinfo-insert-@example ()
685 "Insert the string `@example' in a Texinfo buffer."
686 (interactive)
687 (insert "@example\n"))
688
689 (defun texinfo-insert-@file (&optional arg)
690 "Insert a `@file{...}' command in a Texinfo buffer.
691 A numeric argument says how many words the braces should surround.
692 The default is not to surround any existing words with the braces."
693 (interactive "P")
694 (texinfo-insert-@-with-arg "file" arg))
695
696 (defun texinfo-insert-@item ()
697 "Insert the string `@item' in a Texinfo buffer."
698 (interactive)
699 (insert "@item")
700 (newline))
701
702 (defun texinfo-insert-@kbd (&optional arg)
703 "Insert a `@kbd{...}' command in a Texinfo buffer.
704 A numeric argument says how many words the braces should surround.
705 The default is not to surround any existing words with the braces."
706 (interactive "P")
707 (texinfo-insert-@-with-arg "kbd" arg))
708
709 (defun texinfo-insert-@node ()
710 "Insert the string `@node' in a Texinfo buffer.
711 This also inserts on the following line a comment indicating
712 the order of arguments to @node."
713 (interactive)
714 (insert "@node \n@comment node-name, next, previous, up")
715 (forward-line -1)
716 (forward-char 6))
717
718 (defun texinfo-insert-@noindent ()
719 "Insert the string `@noindent' in a Texinfo buffer."
720 (interactive)
721 (insert "@noindent\n"))
722
723 (defun texinfo-insert-@quotation ()
724 "Insert the string `@quotation' in a Texinfo buffer."
725 (interactive)
726 (insert "@quotation\n"))
727
728 (defun texinfo-insert-@samp (&optional arg)
729 "Insert a `@samp{...}' command in a Texinfo buffer.
730 A numeric argument says how many words the braces should surround.
731 The default is not to surround any existing words with the braces."
732 (interactive "P")
733 (texinfo-insert-@-with-arg "samp" arg))
734
735 (defun texinfo-insert-@strong (&optional arg)
736 "Insert a `@strong{...}' command in a Texinfo buffer.
737 A numeric argument says how many words the braces should surround.
738 The default is not to surround any existing words with the braces."
739 (interactive "P")
740 (texinfo-insert-@-with-arg "strong" arg))
741
742 (defun texinfo-insert-@table (&optional arg)
743 "Insert the string `@table' in a Texinfo buffer."
744 (interactive "P")
745 (insert "@table "))
746
747 (defun texinfo-insert-@var (&optional arg)
748 "Insert a `@var{}' command in a Texinfo buffer.
749 A numeric argument says how many words the braces should surround.
750 The default is not to surround any existing words with the braces."
751 (interactive "P")
752 (texinfo-insert-@-with-arg "var" arg))
753
754 (defun texinfo-insert-@url (&optional arg)
755 "Insert a `@url{}' command in a Texinfo buffer.
756 A numeric argument says how many words the braces should surround.
757 The default is not to surround any existing words with the braces."
758 (interactive "P")
759 (texinfo-insert-@-with-arg "url" arg))
760 \f
761 ;;; Texinfo file structure
762
763 ;; These are defined in texnfo-upd.el. defvars here avoid warnings.
764 (defvar texinfo-section-types-regexp)
765 (defvar texinfo-section-level-regexp)
766 (defvar texinfo-subsection-level-regexp)
767 (defvar texinfo-subsubsection-level-regexp)
768
769 (defun texinfo-show-structure (&optional nodes-too)
770 "Show the structure of a Texinfo file.
771 List the lines in the file that begin with the @-sign commands for
772 @chapter, @section, and the like.
773
774 With optional argument (prefix if interactive), list both the lines
775 with @-sign commands for @chapter, @section, and the like, and list
776 @node lines.
777
778 Lines with structuring commands beginning in them are displayed in
779 another buffer named `*Occur*'. In that buffer, you can move point to
780 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
781 to jump to the corresponding spot in the Texinfo source file."
782
783 (interactive "P")
784 (require 'texnfo-upd)
785 (save-excursion
786 (goto-char (point-min))
787 (if nodes-too
788 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
789 (occur texinfo-section-types-regexp)))
790 (pop-to-buffer "*Occur*")
791 (goto-char (point-min))
792 (let ((inhibit-read-only t))
793 (flush-lines "-----")
794 ;; Now format the "*Occur*" buffer to show the structure.
795 ;; Thanks to ceder@signum.se (Per Cederqvist)
796 (goto-char (point-max))
797 (let ((margin 5))
798 (while (re-search-backward "^ *[0-9]*:" nil 0)
799 (re-search-forward ":")
800 (setq margin
801 (cond
802 ((looking-at
803 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
804 ;; ((looking-at "@chapter ") 5)
805 ;; ((looking-at "@unnumbered ") 5)
806 ;; ((looking-at "@appendix ") 5)
807 ;; ((looking-at "@majorheading ") 5)
808 ;; ((looking-at "@chapheading ") 5)
809
810 ((looking-at
811 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
812 ;; ((looking-at "@section ") 9)
813 ;; ((looking-at "@unnumberedsec ") 9)
814 ;; ((looking-at "@appendixsec ") 9)
815 ;; ((looking-at "@heading ") 9)
816
817 ((looking-at
818 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
819 ;; ((looking-at "@subsection ") 13)
820 ;; ((looking-at "@unnumberedsubsec ") 13)
821 ;; ((looking-at "@appendixsubsec ") 13)
822 ;; ((looking-at "@subheading ") 13)
823
824 ((looking-at
825 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
826 ;; ((looking-at "@subsubsection ") 17)
827 ;; ((looking-at "@unnumberedsubsubsec ") 17)
828 ;; ((looking-at "@appendixsubsubsec ") 17)
829 ;; ((looking-at "@subsubheading ") 17)
830 (t margin)))
831 (indent-to-column margin)
832 (beginning-of-line)))))
833 \f
834 ;;; The tex and print function definitions:
835
836 (defcustom texinfo-texi2dvi-command "texi2dvi"
837 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
838 :type 'string
839 :group 'texinfo)
840
841 (defcustom texinfo-tex-command "tex"
842 "*Command used by `texinfo-tex-region' to run TeX on a region."
843 :type 'string
844 :group 'texinfo)
845
846 (defcustom texinfo-texindex-command "texindex"
847 "*Command used by `texinfo-texindex' to sort unsorted index files."
848 :type 'string
849 :group 'texinfo)
850
851 (defcustom texinfo-delete-from-print-queue-command "lprm"
852 "*Command string used to delete a job from the line printer queue.
853 Command is used by \\[texinfo-delete-from-print-queue] based on
854 number provided by a previous \\[tex-show-print-queue]
855 command."
856 :type 'string
857 :group 'texinfo)
858
859 (defvar texinfo-tex-trailer "@bye"
860 "String appended after a region sent to TeX by `texinfo-tex-region'.")
861
862 (defun texinfo-tex-region (beg end)
863 "Run TeX on the current region.
864 This works by writing a temporary file (`tex-zap-file') in the directory
865 that is the value of `tex-directory', then running TeX on that file.
866
867 The first line of the buffer is copied to the
868 temporary file; and if the buffer has a header, it is written to the
869 temporary file before the region itself. The buffer's header is all lines
870 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
871 inclusive. The header must start in the first 100 lines.
872
873 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
874 (interactive "r")
875 (require 'tex-mode)
876 (let ((tex-command texinfo-tex-command)
877 (tex-trailer texinfo-tex-trailer))
878 (tex-region beg end)))
879
880 (defun texinfo-tex-buffer ()
881 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
882 (interactive)
883 (require 'tex-mode)
884 (let ((tex-command texinfo-texi2dvi-command)
885 ;; Disable tex-start-options-string. texi2dvi would not
886 ;; understand anything specified here.
887 (tex-start-options-string ""))
888 (tex-buffer)))
889
890 (defun texinfo-texindex ()
891 "Run `texindex' on unsorted index files.
892 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
893 This runs the shell command defined by `texinfo-texindex-command'."
894 (interactive)
895 (require 'tex-mode)
896 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
897 ;; alternatively
898 ;; (send-string "tex-shell"
899 ;; (concat texinfo-texindex-command
900 ;; " " tex-zap-file ".??" "\n"))
901 (tex-recenter-output-buffer nil))
902
903 (defun texinfo-tex-print ()
904 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
905 This runs the shell command defined by `tex-dvi-print-command'."
906 (interactive)
907 (require 'tex-mode)
908 (tex-print))
909
910 (defun texinfo-tex-view ()
911 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
912 This runs the shell command defined by `tex-dvi-view-command'."
913 (interactive)
914 (require 'tex-mode)
915 (tex-view))
916
917 (defun texinfo-quit-job ()
918 "Quit currently running TeX job, by sending an `x' to it."
919 (interactive)
920 (if (not (get-process "tex-shell"))
921 (error "No TeX shell running"))
922 (tex-send-command "x"))
923 ;; alternatively:
924 ;; save-excursion
925 ;; (set-buffer (get-buffer "*tex-shell*"))
926 ;; (goto-char (point-max))
927 ;; (insert "x")
928 ;; (comint-send-input)
929
930 (defun texinfo-delete-from-print-queue (job-number)
931 "Delete job from the line printer spooling queue.
932 You are prompted for the job number (use a number shown by a previous
933 \\[tex-show-print-queue] command)."
934 (interactive "nPrinter job number for deletion: ")
935 (require 'tex-mode)
936 (if (tex-shell-running)
937 (tex-kill-job)
938 (tex-start-shell))
939 (tex-send-command texinfo-delete-from-print-queue-command job-number)
940 ;; alternatively
941 ;; (send-string "tex-shell"
942 ;; (concat
943 ;; texinfo-delete-from-print-queue-command
944 ;; " "
945 ;; job-number"\n"))
946 (tex-recenter-output-buffer nil))
947
948 (provide 'texinfo)
949
950 ;;; texinfo.el ends here