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