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