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