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