(texinfo-mode-menu): Add an explicit shortcut for update all.
[emacs.git] / lisp / textmodes / texinfo.el
blobf0d1fdc5b05ef5f77fab05d58e8d2310f9f62b07
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)
42 ;;; Autoloads:
44 (autoload 'makeinfo-region
45 "makeinfo"
46 "Make Info file from region of current Texinfo file, and switch to it.
48 This command does not offer the `next-error' feature since it would
49 apply to a temporary file, not the original; use the `makeinfo-buffer'
50 command to gain use of `next-error'."
51 t nil)
53 (autoload 'makeinfo-buffer
54 "makeinfo"
55 "Make Info file from current buffer.
57 Use the \\[next-error] command to move to the next error
58 \(if there are errors\)."
59 t nil)
61 (autoload 'kill-compilation
62 "compile"
63 "Kill the process made by the \\[compile] command."
64 t nil)
66 (autoload 'makeinfo-recenter-compilation-buffer
67 "makeinfo"
68 "Redisplay `*compilation*' buffer so most recent output can be seen.
69 The last line of the buffer is displayed on
70 line LINE of the window, or centered if LINE is nil."
71 t nil)
73 (autoload 'texinfo-update-node
74 "texnfo-upd"
75 "Without any prefix argument, update the node in which point is located.
76 Non-nil argument (prefix, if interactive) means update the nodes in the
77 marked region.
79 The functions for creating or updating nodes and menus, and their
80 keybindings, are:
82 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
83 texinfo-every-node-update () \\[texinfo-every-node-update]
84 texinfo-sequential-node-update (&optional region-p)
86 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
87 texinfo-all-menus-update () \\[texinfo-all-menus-update]
88 texinfo-master-menu ()
90 texinfo-indent-menu-description (column &optional region-p)
92 The `texinfo-column-for-description' variable specifies the column to
93 which menu descriptions are indented. Its default value is 32."
94 t nil)
96 (autoload 'texinfo-every-node-update
97 "texnfo-upd"
98 "Update every node in a Texinfo file."
99 t nil)
101 (autoload 'texinfo-sequential-node-update
102 "texnfo-upd"
103 "Update one node (or many) in a Texinfo file with sequential pointers.
105 This function causes the `Next' or `Previous' pointer to point to the
106 immediately preceding or following node, even if it is at a higher or
107 lower hierarchical level in the document. Continually pressing `n' or
108 `p' takes you straight through the file.
110 Without any prefix argument, update the node in which point is located.
111 Non-nil argument (prefix, if interactive) means update the nodes in the
112 marked region.
114 This command makes it awkward to navigate among sections and
115 subsections; it should be used only for those documents that are meant
116 to be read like a novel rather than a reference, and for which the
117 Info `g*' command is inadequate."
118 t nil)
120 (autoload 'texinfo-make-menu
121 "texnfo-upd"
122 "Without any prefix argument, make or update a menu.
123 Make the menu for the section enclosing the node found following point.
125 Non-nil argument (prefix, if interactive) means make or update menus
126 for nodes within or part of the marked region.
128 Whenever a menu exists, and is being updated, the descriptions that
129 are associated with node names in the pre-existing menu are
130 incorporated into the new menu. Otherwise, the nodes' section titles
131 are inserted as descriptions."
132 t nil)
134 (autoload 'texinfo-all-menus-update
135 "texnfo-upd"
136 "Update every regular menu in a Texinfo file.
137 Remove pre-existing master menu, if there is one.
139 If called with a non-nil argument, this function first updates all the
140 nodes in the buffer before updating the menus."
141 t nil)
143 (autoload 'texinfo-master-menu
144 "texnfo-upd"
145 "Make a master menu for a whole Texinfo file.
146 Non-nil argument (prefix, if interactive) means first update all
147 existing nodes and menus. Remove pre-existing master menu, if there is one.
149 This function creates a master menu that follows the top node. The
150 master menu includes every entry from all the other menus. It
151 replaces any existing ordinary menu that follows the top node.
153 If called with a non-nil argument, this function first updates all the
154 menus in the buffer (incorporating descriptions from pre-existing
155 menus) before it constructs the master menu.
157 The function removes the detailed part of an already existing master
158 menu. This action depends on the pre-existing master menu using the
159 standard `texinfo-master-menu-header'.
161 The master menu has the following format, which is adapted from the
162 recommendation in the Texinfo Manual:
164 * The first part contains the major nodes in the Texinfo file: the
165 nodes for the chapters, chapter-like sections, and the major
166 appendices. This includes the indices, so long as they are in
167 chapter-like sections, such as unnumbered sections.
169 * The second and subsequent parts contain a listing of the other,
170 lower level menus, in order. This way, an inquirer can go
171 directly to a particular node if he or she is searching for
172 specific information.
174 Each of the menus in the detailed node listing is introduced by the
175 title of the section containing the menu."
176 t nil)
178 (autoload 'texinfo-indent-menu-description
179 "texnfo-upd"
180 "Indent every description in menu following point to COLUMN.
181 Non-nil argument (prefix, if interactive) means indent every
182 description in every menu in the region. Does not indent second and
183 subsequent lines of a multi-line description."
184 t nil)
186 (autoload 'texinfo-insert-node-lines
187 "texnfo-upd"
188 "Insert missing `@node' lines in region of Texinfo file.
189 Non-nil argument (prefix, if interactive) means also to insert the
190 section titles as node names; and also to insert the section titles as
191 node names in pre-existing @node lines that lack names."
192 t nil)
194 (autoload 'texinfo-start-menu-description
195 "texnfo-upd"
196 "In this menu entry, insert the node's section title as a description.
197 Position point at beginning of description ready for editing.
198 Do not insert a title if the line contains an existing description.
200 You will need to edit the inserted text since a useful description
201 complements the node name rather than repeats it as a title does."
202 t nil)
204 (autoload 'texinfo-multiple-files-update
205 "texnfo-upd"
206 "Update first node pointers in each file included in OUTER-FILE;
207 create or update main menu in the outer file that refers to such nodes.
208 This does not create or update menus or pointers within the included files.
210 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
211 insert a master menu in OUTER-FILE. This does not create or update
212 menus or pointers within the included files.
214 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
215 interactive), update all the menus and all the `Next', `Previous', and
216 `Up' pointers of all the files included in OUTER-FILE before inserting
217 a master menu in OUTER-FILE.
219 The command also updates the `Top' level node pointers of OUTER-FILE.
221 Notes:
223 * this command does NOT save any files--you must save the
224 outer file and any modified, included files.
226 * except for the `Top' node, this command does NOT handle any
227 pre-existing nodes in the outer file; hence, indices must be
228 enclosed in an included file.
230 Requirements:
232 * each of the included files must contain exactly one highest
233 hierarchical level node,
234 * this highest node must be the first node in the included file,
235 * each highest hierarchical level node must be of the same type.
237 Thus, normally, each included file contains one, and only one,
238 chapter."
239 t nil)
242 ;;; Code:
244 ;;; Don't you dare insert any `require' calls at top level in this file--rms.
246 (defvar texinfo-section-list
247 '(("top" 1)
248 ("majorheading" 1)
249 ("chapter" 2)
250 ("unnumbered" 2)
251 ("appendix" 2)
252 ("chapheading" 2)
253 ("section" 3)
254 ("unnumberedsec" 3)
255 ("appendixsec" 3)
256 ("heading" 3)
257 ("subsection" 4)
258 ("unnumberedsubsec" 4)
259 ("appendixsubsec" 4)
260 ("subheading" 4)
261 ("subsubsection" 5)
262 ("unnumberedsubsubsec" 5)
263 ("appendixsubsubsec" 5)
264 ("subsubheading" 5))
265 "Alist of sectioning commands and their relative level.")
267 ;;; Syntax table
269 (defvar texinfo-mode-syntax-table nil)
271 (if texinfo-mode-syntax-table
273 (setq texinfo-mode-syntax-table (make-syntax-table))
274 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
275 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
276 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
277 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
278 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
279 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
280 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
281 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
282 (modify-syntax-entry ?\n ">" texinfo-mode-syntax-table)
283 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
285 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
286 ;; To override this example, set either `imenu-generic-expression'
287 ;; or `imenu-create-index-function'.
288 (defvar texinfo-imenu-generic-expression
289 '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
290 ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
291 "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
293 (defvar texinfo-font-lock-syntactic-keywords
294 '(("\\(@\\)c\\(omment\\)?\\>" (1 '(11)))
295 ("^\\(@\\)ignore\\>" (1 '(2097163)))
296 ("^@end ignore\\(\n\\)" (1 '(2097164))))
297 "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
299 (defface texinfo-heading-face
300 '((t (:inherit font-lock-function-name-face)))
301 "Face used for section headings in `texinfo-mode'.")
302 (defvar texinfo-heading-face 'texinfo-heading-face)
304 (defvar texinfo-font-lock-keywords
305 `(;; All but the first had an OVERRIDE of t.
306 ;; It didn't seem to be any better, and it's slower--simon.
307 ;; Robert J. Chassell <bob@gnu.org> says remove this line.
308 ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
309 ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
310 ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
311 ("@\\(emph\\|strong\\|b\\|i\\|sc\\){\\([^}]+\\)" 2 font-lock-comment-face)
312 ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
313 ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
314 2 font-lock-variable-name-face)
315 ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face)
316 ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
317 (,(concat "^@" (regexp-opt (mapcar 'car texinfo-section-list) t)
318 ".*\n") 0 texinfo-heading-face t))
319 "Additional expressions to highlight in TeXinfo mode.")
321 (defun texinfo-outline-level ()
322 ;; Calculate level of current texinfo outline heading.
323 (save-excursion
324 (if (bobp)
326 (forward-char 1)
327 (let* ((word (buffer-substring-no-properties
328 (point) (progn (forward-word 1) (point))))
329 (entry (assoc word texinfo-section-list)))
330 (if entry
331 (nth 1 entry)
332 5)))))
335 ;;; Keybindings
336 (defvar texinfo-mode-map nil)
338 ;;; Keys common both to Texinfo mode and to TeX shell.
340 (defun texinfo-define-common-keys (keymap)
341 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
342 (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
343 (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
344 (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
345 (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
346 (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
347 (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
348 (define-key keymap "\C-c\C-t\C-v" 'texinfo-tex-view)
349 (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
351 (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
352 (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
354 ;; Mode documentation displays commands in reverse order
355 ;; from how they are listed in the texinfo-mode-map.
357 (if texinfo-mode-map
359 (setq texinfo-mode-map (make-sparse-keymap))
361 ;; bindings for `texnfo-tex.el'
362 (texinfo-define-common-keys texinfo-mode-map)
364 (define-key texinfo-mode-map "\"" 'texinfo-insert-quote)
366 ;; bindings for `makeinfo.el'
367 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
368 (define-key texinfo-mode-map "\C-c\C-m\C-l"
369 'makeinfo-recenter-compilation-buffer)
370 (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
371 (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
373 ;; bindings for `texinfmt.el'
374 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
375 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
377 ;; AUCTeX-like bindings
378 (define-key texinfo-mode-map "\e\r" 'texinfo-insert-@item)
380 ;; bindings for updating nodes and menus
382 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
384 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
385 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
386 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
387 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
389 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
391 (define-key texinfo-mode-map "\C-c}" 'up-list)
392 (define-key texinfo-mode-map "\C-c]" 'up-list)
393 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
395 ;; bindings for inserting strings
396 (define-key texinfo-mode-map "\C-c\C-o" 'texinfo-insert-block)
397 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
398 (define-key texinfo-mode-map "\C-c\C-c\C-s" 'texinfo-insert-@strong)
399 (define-key texinfo-mode-map "\C-c\C-c\C-e" 'texinfo-insert-@emph)
401 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
402 (define-key texinfo-mode-map "\C-c\C-cu" 'texinfo-insert-@url)
403 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
404 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
405 ;; (define-key texinfo-mode-map "\C-c\C-cr" 'texinfo-insert-@uref)
406 (define-key texinfo-mode-map "\C-c\C-cq" 'texinfo-insert-@quotation)
407 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
408 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
409 (define-key texinfo-mode-map "\C-c\C-cm" 'texinfo-insert-@email)
410 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
411 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
412 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
413 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
414 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
415 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
416 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
418 (easy-menu-define texinfo-mode-menu
419 texinfo-mode-map
420 "Menu used for `texinfo-mode'."
421 '("Texinfo"
422 ["Insert block" texinfo-insert-block t]
423 ;; ["Insert node" texinfo-insert-@node t]
424 "----"
425 ["Update All" (lambda () (interactive) (texinfo-master-menu t))
426 :keys "\\[universal-argument] \\[texinfo-master-menu]"]
427 ["Update every node" texinfo-every-node-update t]
428 ["Update node" texinfo-update-node t]
429 ["Make Master menu" texinfo-master-menu t]
430 ["Make menu" texinfo-make-menu t]
431 ["Update all menus" texinfo-all-menus-update t]
432 "----"
433 ["Show structure" texinfo-show-structure t]
434 ["Format region" texinfo-format-region t]
435 ["Format buffer" texinfo-format-buffer t]
436 ["Makeinfo region" makeinfo-region t]
437 ["Makeinfo buffer" makeinfo-buffer t]))
440 ;;; Texinfo mode
442 ;; Also defined in texnfo-upd.el but copied here to avoid having
443 ;; to require texnfo-upd.el.
444 (defvar texinfo-chapter-level-regexp
445 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
446 "Regular expression matching Texinfo chapter-level headings.
447 This does not match `@node' and does not match the `@top' command.")
449 ;;;###autoload
450 (define-derived-mode texinfo-mode text-mode "Texinfo"
451 "Major mode for editing Texinfo files.
453 It has these extra commands:
454 \\{texinfo-mode-map}
456 These are files that are used as input for TeX to make printed manuals
457 and also to be turned into Info files with \\[makeinfo-buffer] or
458 the `makeinfo' program. These files must be written in a very restricted and
459 modified version of TeX input format.
461 Editing commands are like text-mode except that the syntax table is
462 set up so expression commands skip Texinfo bracket groups. To see
463 what the Info version of a region of the Texinfo file will look like,
464 use \\[makeinfo-region], which runs `makeinfo' on the current region.
466 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
467 This command shows the structure of a Texinfo file by listing the
468 lines with the @-sign commands for @chapter, @section, and the like.
469 These lines are displayed in another window called the *Occur* window.
470 In that window, you can position the cursor over one of the lines and
471 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
472 in the Texinfo file.
474 In addition, Texinfo mode provides commands that insert various
475 frequently used @-sign commands into the buffer. You can use these
476 commands to save keystrokes. And you can insert balanced braces with
477 \\[texinfo-insert-braces] and later use the command \\[up-list] to
478 move forward past the closing brace.
480 Also, Texinfo mode provides functions for automatically creating or
481 updating menus and node pointers. These functions
483 * insert the `Next', `Previous' and `Up' pointers of a node,
484 * insert or update the menu for a section, and
485 * create a master menu for a Texinfo source file.
487 Here are the functions:
489 texinfo-update-node \\[texinfo-update-node]
490 texinfo-every-node-update \\[texinfo-every-node-update]
491 texinfo-sequential-node-update
493 texinfo-make-menu \\[texinfo-make-menu]
494 texinfo-all-menus-update \\[texinfo-all-menus-update]
495 texinfo-master-menu
497 texinfo-indent-menu-description (column &optional region-p)
499 The `texinfo-column-for-description' variable specifies the column to
500 which menu descriptions are indented.
502 Passed an argument (a prefix argument, if interactive), the
503 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
504 in the region.
506 To use the updating commands, you must structure your Texinfo file
507 hierarchically, such that each `@node' line, with the exception of the
508 Top node, is accompanied by some kind of section line, such as an
509 `@chapter' or `@section' line.
511 If the file has a `top' node, it must be called `top' or `Top' and
512 be the first node in the file.
514 Entering Texinfo mode calls the value of `text-mode-hook', and then the
515 value of `texinfo-mode-hook'."
516 (make-local-variable 'page-delimiter)
517 (setq page-delimiter
518 (concat
519 "^@node [ \t]*[Tt]op\\|^@\\("
520 texinfo-chapter-level-regexp
521 "\\)"))
522 (make-local-variable 'require-final-newline)
523 (setq require-final-newline t)
524 (make-local-variable 'indent-tabs-mode)
525 (setq indent-tabs-mode nil)
526 (make-local-variable 'paragraph-separate)
527 (setq paragraph-separate
528 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
529 (make-local-variable 'paragraph-start)
530 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
531 (make-local-variable 'adaptive-fill-mode)
532 (setq adaptive-fill-mode nil)
533 (make-local-variable 'fill-column)
534 (setq fill-column 72)
535 (make-local-variable 'comment-start)
536 (setq comment-start "@c ")
537 (make-local-variable 'comment-start-skip)
538 (setq comment-start-skip "@c +\\|@comment +")
539 (make-local-variable 'words-include-escapes)
540 (setq words-include-escapes t)
541 (make-local-variable 'imenu-generic-expression)
542 (setq imenu-generic-expression texinfo-imenu-generic-expression)
543 (setq imenu-case-fold-search nil)
544 (make-local-variable 'font-lock-defaults)
545 (setq font-lock-defaults
546 '(texinfo-font-lock-keywords nil nil nil nil
547 (font-lock-syntactic-keywords
548 . texinfo-font-lock-syntactic-keywords)))
549 (set (make-local-variable 'parse-sexp-lookup-properties) t)
550 (make-local-variable 'outline-regexp)
551 (setq outline-regexp
552 (concat "@" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\>"))
553 (make-local-variable 'outline-level)
554 (setq outline-level 'texinfo-outline-level)
555 (make-local-variable 'tex-start-of-header)
556 (setq tex-start-of-header "%\\*\\*start")
557 (make-local-variable 'tex-end-of-header)
558 (setq tex-end-of-header "%\\*\\*end")
559 (make-local-variable 'tex-first-line-header-regexp)
560 (setq tex-first-line-header-regexp "^\\\\input")
561 (make-local-variable 'tex-trailer)
562 (setq tex-trailer "@bye\n")
564 ;; Prevent filling certain lines, in addition to ones specified
565 ;; by the user.
566 (let ((prevent-filling "^@\\(def\\|multitable\\)"))
567 (make-local-variable 'auto-fill-inhibit-regexp)
568 (if (null auto-fill-inhibit-regexp)
569 (setq auto-fill-inhibit-regexp prevent-filling)
570 (setq auto-fill-inhibit-regexp
571 (concat "\\(" auto-fill-inhibit-regexp "\\)\\|\\("
572 prevent-filling "\\)")))))
576 ;;; Insert string commands
578 (defconst texinfo-environments
579 '("cartouche"
580 "defcv"
581 "deffn"
582 "defivar"
583 "defmac"
584 "defmethod"
585 "defop"
586 "defopt"
587 "defspec"
588 "deftp"
589 "deftypefn"
590 "deftypefun"
591 "deftypevar"
592 "deftypevr"
593 "defun"
594 "defvar"
595 "defvr"
596 "description"
597 "display"
598 "enumerate"
599 "example"
600 "flushleft"
601 "flushright"
602 "format"
603 "ftable"
604 "group"
605 "ifclear"
606 "ifset"
607 "ifhtml"
608 "ifinfo"
609 "ifnothtml"
610 "ifnotinfo"
611 "ifnottex"
612 "iftex"
613 "ignore"
614 "itemize"
615 "lisp"
616 "macro"
617 "multitable"
618 "quotation"
619 "smalldisplay"
620 "smallexample"
621 "smallformat"
622 "smalllisp"
623 "table"
624 "tex"
625 "titlepage"
626 "vtable")
627 "List of TeXinfo environments.")
629 ;; Keep as concatenated lists for ease of maintenance
630 (defconst texinfo-environment-regexp
631 (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
632 "Regexp for environment-like TexInfo list commands.
633 Subexpression 1 is what goes into the corresponding `@end' statement.")
635 (define-skeleton texinfo-insert-block
636 "Create a matching pair @<cmd> .. @end <cmd> at point.
637 Puts point on a blank line between them."
638 (completing-read "Block name: " (mapcar 'list texinfo-environments))
639 "@" str \n _ \n "@end " str \n)
641 (defun texinfo-inside-macro-p (macro &optional bound)
642 "Non-nil if inside a macro matching the regexp MACRO."
643 (ignore-errors
644 (save-excursion
645 (save-restriction
646 (narrow-to-region bound (point))
647 (while (progn
648 (up-list -1)
649 (not (ignore-errors
650 (save-excursion
651 (backward-sexp 1)
652 (looking-at macro))))))
653 t))))
655 (defun texinfo-inside-env-p (env &optional bound)
656 "Non-nil if inside an environment matching the regexp @ENV."
657 (save-excursion
658 (and (re-search-backward (concat "@\\(end\\s +\\)?" env) bound t)
659 (looking-at (concat "@" env)))))
661 (autoload 'tex-insert-quote "tex-mode" nil t)
662 (defun texinfo-insert-quote (&optional arg)
663 "Insert the appropriate quote mark for TeXinfo.
664 Inserts a plain \" if inside @code or @example, else inserts `` or ''
665 by calling `tex-insert-quote'."
666 (interactive "*P")
667 (let ((top (or (save-excursion (re-search-backward "@node\\>" nil t))
668 (point-min))))
669 (if (or (texinfo-inside-env-p "example\\>" top)
670 (texinfo-inside-macro-p "@code\\>" top))
671 (self-insert-command (prefix-numeric-value arg))
672 (tex-insert-quote arg))))
674 ;; The following texinfo-insert-@end command not only inserts a SPC
675 ;; after the @end, but tries to find out what belongs there. It is
676 ;; not very smart: it does not understand nested lists.
678 (defun texinfo-insert-@end ()
679 "Insert the matching `@end' for the last Texinfo command that needs one."
680 (interactive)
681 (let ((depth 1) string)
682 (save-excursion
683 (while (and (> depth 0)
684 (re-search-backward texinfo-environment-regexp nil t))
685 (if (looking-at "@end")
686 (setq depth (1+ depth))
687 (setq depth (1- depth))))
688 (looking-at texinfo-environment-regexp)
689 (if (zerop depth)
690 (setq string
691 (buffer-substring (match-beginning 1)
692 (match-end 1)))))
693 (insert "@end ")
694 (if string (insert string "\n"))))
696 ;; The following insert commands accept a prefix arg N, which is the
697 ;; number of words (actually s-exprs) that should be surrounded by
698 ;; braces. Thus you can first paste a variable name into a .texinfo
699 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
700 ;; pasted variable name to put @var{...} *around* the variable name.
701 ;; Operate on previous word or words with negative arg.
703 ;; These commands use texinfo-insert-@-with-arg
704 (defun texinfo-insert-@-with-arg (string &optional arg)
705 (if arg
706 (progn
707 (setq arg (prefix-numeric-value arg))
708 (if (< arg 0)
709 (progn
710 (skip-chars-backward " \t\n\r\f")
711 (save-excursion
712 (forward-sexp arg)
713 (insert "@" string "{"))
714 (insert "}"))
715 (skip-chars-forward " \t\n\r\f")
716 (insert "@" string "{")
717 (forward-sexp arg)
718 (insert "}")))
719 (insert "@" string "{}")
720 (backward-char)))
722 (defun texinfo-insert-braces ()
723 "Make a pair of braces and be poised to type inside of them.
724 Use \\[up-list] to move forward out of the braces."
725 (interactive)
726 (insert "{}")
727 (backward-char))
729 (defun texinfo-insert-@code (&optional arg)
730 "Insert a `@code{...}' command in a Texinfo buffer.
731 A numeric argument says how many words the braces should surround.
732 The default is not to surround any existing words with the braces."
733 (interactive "P")
734 (texinfo-insert-@-with-arg "code" arg))
736 (defun texinfo-insert-@dfn (&optional arg)
737 "Insert a `@dfn{...}' command in a Texinfo buffer.
738 A numeric argument says how many words the braces should surround.
739 The default is not to surround any existing words with the braces."
740 (interactive "P")
741 (texinfo-insert-@-with-arg "dfn" arg))
743 (defun texinfo-insert-@email (&optional arg)
744 "Insert a `@email{...}' command in a Texinfo buffer.
745 A numeric argument says how many words the braces should surround.
746 The default is not to surround any existing words with the braces."
747 (interactive "P")
748 (texinfo-insert-@-with-arg "email" arg))
750 (defun texinfo-insert-@emph (&optional arg)
751 "Insert a `@emph{...}' command in a Texinfo buffer.
752 A numeric argument says how many words the braces should surround.
753 The default is not to surround any existing words with the braces."
754 (interactive "P")
755 (texinfo-insert-@-with-arg "emph" arg))
757 (defun texinfo-insert-@example ()
758 "Insert the string `@example' in a Texinfo buffer."
759 (interactive)
760 (insert "@example\n"))
762 (defun texinfo-insert-@file (&optional arg)
763 "Insert a `@file{...}' command in a Texinfo buffer.
764 A numeric argument says how many words the braces should surround.
765 The default is not to surround any existing words with the braces."
766 (interactive "P")
767 (texinfo-insert-@-with-arg "file" arg))
769 (defun texinfo-insert-@item ()
770 "Insert the string `@item' in a Texinfo buffer."
771 (interactive)
772 (insert "@item")
773 (newline))
775 (defun texinfo-insert-@kbd (&optional arg)
776 "Insert a `@kbd{...}' command in a Texinfo buffer.
777 A numeric argument says how many words the braces should surround.
778 The default is not to surround any existing words with the braces."
779 (interactive "P")
780 (texinfo-insert-@-with-arg "kbd" arg))
782 (defun texinfo-insert-@node ()
783 "Insert the string `@node' in a Texinfo buffer.
784 This also inserts on the following line a comment indicating
785 the order of arguments to @node."
786 (interactive)
787 (insert "@node \n@comment node-name, next, previous, up")
788 (forward-line -1)
789 (forward-char 6))
791 (defun texinfo-insert-@noindent ()
792 "Insert the string `@noindent' in a Texinfo buffer."
793 (interactive)
794 (insert "@noindent\n"))
796 (defun texinfo-insert-@quotation ()
797 "Insert the string `@quotation' in a Texinfo buffer."
798 (interactive)
799 (insert "@quotation\n"))
801 (defun texinfo-insert-@samp (&optional arg)
802 "Insert a `@samp{...}' command in a Texinfo buffer.
803 A numeric argument says how many words the braces should surround.
804 The default is not to surround any existing words with the braces."
805 (interactive "P")
806 (texinfo-insert-@-with-arg "samp" arg))
808 (defun texinfo-insert-@strong (&optional arg)
809 "Insert a `@strong{...}' command in a Texinfo buffer.
810 A numeric argument says how many words the braces should surround.
811 The default is not to surround any existing words with the braces."
812 (interactive "P")
813 (texinfo-insert-@-with-arg "strong" arg))
815 (defun texinfo-insert-@table (&optional arg)
816 "Insert the string `@table' in a Texinfo buffer."
817 (interactive "P")
818 (insert "@table "))
820 (defun texinfo-insert-@var (&optional arg)
821 "Insert a `@var{}' command in a Texinfo buffer.
822 A numeric argument says how many words the braces should surround.
823 The default is not to surround any existing words with the braces."
824 (interactive "P")
825 (texinfo-insert-@-with-arg "var" arg))
827 (defun texinfo-insert-@url (&optional arg)
828 "Insert a `@url{}' command in a Texinfo buffer.
829 A numeric argument says how many words the braces should surround.
830 The default is not to surround any existing words with the braces."
831 (interactive "P")
832 (texinfo-insert-@-with-arg "url" arg))
834 ;;; Texinfo file structure
836 (defun texinfo-show-structure (&optional nodes-too)
837 "Show the structure of a Texinfo file.
838 List the lines in the file that begin with the @-sign commands for
839 @chapter, @section, and the like.
841 With optional argument (prefix if interactive), list both the lines
842 with @-sign commands for @chapter, @section, and the like, and list
843 @node lines.
845 Lines with structuring commands beginning in them are displayed in
846 another buffer named `*Occur*'. In that buffer, you can move point to
847 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
848 to jump to the corresponding spot in the Texinfo source file."
850 (interactive "P")
851 (save-excursion
852 (goto-char (point-min))
853 (if nodes-too
854 (occur (concat "^@node\\>\\|" outline-regexp))
855 (occur outline-regexp)))
856 (pop-to-buffer "*Occur*")
857 (goto-char (point-min))
858 (let ((inhibit-read-only t))
859 (flush-lines "-----")
860 ;; Now format the "*Occur*" buffer to show the structure.
861 ;; Thanks to ceder@signum.se (Per Cederqvist)
862 (goto-char (point-max))
863 (let (level)
864 (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil 0)
865 (goto-char (1- (match-beginning 1)))
866 (setq level (or (cadr (assoc (match-string 1) texinfo-section-list)) 2))
867 (indent-to-column (+ (current-column) (* 4 (- level 2))))
868 (beginning-of-line)))))
870 ;;; The tex and print function definitions:
872 (defcustom texinfo-texi2dvi-command "texi2dvi"
873 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
874 :type 'string
875 :group 'texinfo)
877 (defcustom texinfo-tex-command "tex"
878 "*Command used by `texinfo-tex-region' to run TeX on a region."
879 :type 'string
880 :group 'texinfo)
882 (defcustom texinfo-texindex-command "texindex"
883 "*Command used by `texinfo-texindex' to sort unsorted index files."
884 :type 'string
885 :group 'texinfo)
887 (defcustom texinfo-delete-from-print-queue-command "lprm"
888 "*Command string used to delete a job from the line printer queue.
889 Command is used by \\[texinfo-delete-from-print-queue] based on
890 number provided by a previous \\[tex-show-print-queue]
891 command."
892 :type 'string
893 :group 'texinfo)
895 (defvar texinfo-tex-trailer "@bye"
896 "String appended after a region sent to TeX by `texinfo-tex-region'.")
898 (defun texinfo-tex-region (beg end)
899 "Run TeX on the current region.
900 This works by writing a temporary file (`tex-zap-file') in the directory
901 that is the value of `tex-directory', then running TeX on that file.
903 The first line of the buffer is copied to the
904 temporary file; and if the buffer has a header, it is written to the
905 temporary file before the region itself. The buffer's header is all lines
906 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
907 inclusive. The header must start in the first 100 lines.
909 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
910 (interactive "r")
911 (require 'tex-mode)
912 (let ((tex-command texinfo-tex-command)
913 (tex-trailer texinfo-tex-trailer))
914 (tex-region beg end)))
916 (defun texinfo-tex-buffer ()
917 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
918 (interactive)
919 (require 'tex-mode)
920 (let ((tex-command texinfo-texi2dvi-command)
921 ;; Disable tex-start-options-string. texi2dvi would not
922 ;; understand anything specified here.
923 (tex-start-options-string ""))
924 (tex-buffer)))
926 (defun texinfo-texindex ()
927 "Run `texindex' on unsorted index files.
928 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
929 This runs the shell command defined by `texinfo-texindex-command'."
930 (interactive)
931 (require 'tex-mode)
932 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
933 ;; alternatively
934 ;; (send-string "tex-shell"
935 ;; (concat texinfo-texindex-command
936 ;; " " tex-zap-file ".??" "\n"))
937 (tex-recenter-output-buffer nil))
939 (defun texinfo-tex-print ()
940 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
941 This runs the shell command defined by `tex-dvi-print-command'."
942 (interactive)
943 (require 'tex-mode)
944 (tex-print))
946 (defun texinfo-tex-view ()
947 "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
948 This runs the shell command defined by `tex-dvi-view-command'."
949 (interactive)
950 (require 'tex-mode)
951 (tex-view))
953 (defun texinfo-quit-job ()
954 "Quit currently running TeX job, by sending an `x' to it."
955 (interactive)
956 (if (not (get-process "tex-shell"))
957 (error "No TeX shell running"))
958 (tex-send-command "x"))
959 ;; alternatively:
960 ;; save-excursion
961 ;; (set-buffer (get-buffer "*tex-shell*"))
962 ;; (goto-char (point-max))
963 ;; (insert "x")
964 ;; (comint-send-input)
966 (defun texinfo-delete-from-print-queue (job-number)
967 "Delete job from the line printer spooling queue.
968 You are prompted for the job number (use a number shown by a previous
969 \\[tex-show-print-queue] command)."
970 (interactive "nPrinter job number for deletion: ")
971 (require 'tex-mode)
972 (if (tex-shell-running)
973 (tex-kill-job)
974 (tex-start-shell))
975 (tex-send-command texinfo-delete-from-print-queue-command job-number)
976 ;; alternatively
977 ;; (send-string "tex-shell"
978 ;; (concat
979 ;; texinfo-delete-from-print-queue-command
980 ;; " "
981 ;; job-number"\n"))
982 (tex-recenter-output-buffer nil))
984 (provide 'texinfo)
986 ;;; texinfo.el ends here