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