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