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