0
|
1 ;;; texinfo.el --- major mode for editing Texinfo files
|
|
2
|
|
3 ;; Copyright (C) 1985, '88, '89,
|
|
4 ;; '90, '91, '92, '93 Free Software Foundation, Inc.
|
|
5
|
|
6 ;; Author: Robert J. Chassell
|
|
7 ;; Maintainer: FSF
|
|
8 ;; Keywords: tex wp
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
16
|
23 ;; along with XEmacs; 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.
|
0
|
26
|
|
27 ;;; Synched up with: FSF 19.30.
|
|
28
|
120
|
29 (defgroup texinfo nil
|
|
30 "Texinfo Mode"
|
|
31 :group 'docs)
|
|
32
|
0
|
33
|
|
34 ;;; Autoloads:
|
|
35
|
|
36 (autoload 'makeinfo-region
|
|
37 "makeinfo"
|
|
38 "Make Info file from region of current Texinfo file, and switch to it.
|
|
39
|
|
40 This command does not offer the `next-error' feature since it would
|
|
41 apply to a temporary file, not the original; use the `makeinfo-buffer'
|
|
42 command to gain use of `next-error'."
|
|
43 t nil)
|
|
44
|
|
45 (autoload 'makeinfo-buffer
|
|
46 "makeinfo"
|
|
47 "Make Info file from current buffer.
|
|
48
|
|
49 Use the \\[next-error] command to move to the next error
|
|
50 \(if there are errors\)."
|
|
51 t nil)
|
|
52
|
|
53 (autoload 'kill-compilation
|
|
54 "compile"
|
|
55 "Kill the process made by the \\[compile] command."
|
|
56 t nil)
|
|
57
|
|
58 (autoload 'makeinfo-recenter-compilation-buffer
|
|
59 "makeinfo"
|
|
60 "Redisplay `*compilation*' buffer so most recent output can be seen.
|
|
61 The last line of the buffer is displayed on
|
|
62 line LINE of the window, or centered if LINE is nil."
|
|
63 t nil)
|
|
64
|
|
65 (autoload 'texinfo-make-menu
|
|
66 "texnfo-upd"
|
|
67 "Without any prefix argument, make or update a menu.
|
|
68 Make the menu for the section enclosing the node found following point.
|
|
69
|
|
70 Non-nil argument (prefix, if interactive) means make or update menus
|
|
71 for nodes within or part of the marked region.
|
|
72
|
|
73 Whenever a menu exists, and is being updated, the descriptions that
|
|
74 are associated with node names in the pre-existing menu are
|
|
75 incorporated into the new menu. Otherwise, the nodes' section titles
|
|
76 are inserted as descriptions."
|
|
77 t nil)
|
|
78
|
|
79 (autoload 'texinfo-all-menus-update
|
|
80 "texnfo-upd"
|
|
81 "Update every regular menu in a Texinfo file.
|
|
82 Remove pre-existing master menu, if there is one.
|
|
83
|
|
84 If called with a non-nil argument, this function first updates all the
|
|
85 nodes in the buffer before updating the menus."
|
|
86 t nil)
|
|
87
|
|
88 (autoload 'texinfo-master-menu
|
|
89 "texnfo-upd"
|
|
90 "Make a master menu for a whole Texinfo file.
|
|
91 Non-nil argument (prefix, if interactive) means first update all
|
|
92 existing nodes and menus. Remove pre-existing master menu, if there is one.
|
|
93
|
|
94 This function creates a master menu that follows the top node. The
|
|
95 master menu includes every entry from all the other menus. It
|
|
96 replaces any existing ordinary menu that follows the top node.
|
|
97
|
|
98 If called with a non-nil argument, this function first updates all the
|
|
99 menus in the buffer (incorporating descriptions from pre-existing
|
|
100 menus) before it constructs the master menu.
|
|
101
|
|
102 The function removes the detailed part of an already existing master
|
|
103 menu. This action depends on the pre-exisitng master menu using the
|
|
104 standard `texinfo-master-menu-header'.
|
|
105
|
|
106 The master menu has the following format, which is adapted from the
|
|
107 recommendation in the Texinfo Manual:
|
|
108
|
|
109 * The first part contains the major nodes in the Texinfo file: the
|
|
110 nodes for the chapters, chapter-like sections, and the major
|
|
111 appendices. This includes the indices, so long as they are in
|
|
112 chapter-like sections, such as unnumbered sections.
|
|
113
|
|
114 * The second and subsequent parts contain a listing of the other,
|
|
115 lower level menus, in order. This way, an inquirer can go
|
|
116 directly to a particular node if he or she is searching for
|
|
117 specific information.
|
|
118
|
|
119 Each of the menus in the detailed node listing is introduced by the
|
|
120 title of the section containing the menu."
|
|
121 t nil)
|
|
122
|
|
123 (autoload 'texinfo-indent-menu-description
|
|
124 "texnfo-upd"
|
|
125 "Indent every description in menu following point to COLUMN.
|
|
126 Non-nil argument (prefix, if interactive) means indent every
|
|
127 description in every menu in the region. Does not indent second and
|
|
128 subsequent lines of a multi-line description."
|
|
129 t nil)
|
|
130
|
|
131 (autoload 'texinfo-insert-node-lines
|
|
132 "texnfo-upd"
|
|
133 "Insert missing `@node' lines in region of Texinfo file.
|
|
134 Non-nil argument (prefix, if interactive) means also to insert the
|
|
135 section titles as node names; and also to insert the section titles as
|
|
136 node names in pre-existing @node lines that lack names."
|
|
137 t nil)
|
|
138
|
|
139 (autoload 'texinfo-start-menu-description
|
|
140 "texnfo-upd"
|
|
141 "In this menu entry, insert the node's section title as a description.
|
|
142 Position point at beginning of description ready for editing.
|
|
143 Do not insert a title if the line contains an existing description.
|
|
144
|
|
145 You will need to edit the inserted text since a useful description
|
|
146 complements the node name rather than repeats it as a title does."
|
|
147 t nil)
|
|
148
|
|
149 (autoload 'texinfo-multiple-files-update
|
|
150 "texnfo-upd"
|
|
151 "Update first node pointers in each file included in OUTER-FILE;
|
|
152 create or update main menu in the outer file that refers to such nodes.
|
|
153 This does not create or update menus or pointers within the included files.
|
|
154
|
|
155 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
|
|
156 insert a master menu in OUTER-FILE. This does not create or update
|
|
157 menus or pointers within the included files.
|
|
158
|
|
159 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
|
|
160 interactive), update all the menus and all the `Next', `Previous', and
|
|
161 `Up' pointers of all the files included in OUTER-FILE before inserting
|
|
162 a master menu in OUTER-FILE.
|
|
163
|
|
164 The command also updates the `Top' level node pointers of OUTER-FILE.
|
|
165
|
|
166 Notes:
|
|
167
|
|
168 * this command does NOT save any files--you must save the
|
|
169 outer file and any modified, included files.
|
|
170
|
|
171 * except for the `Top' node, this command does NOT handle any
|
|
172 pre-existing nodes in the outer file; hence, indices must be
|
|
173 enclosed in an included file.
|
|
174
|
|
175 Requirements:
|
|
176
|
|
177 * each of the included files must contain exactly one highest
|
|
178 hierarchical level node,
|
|
179 * this highest node must be the first node in the included file,
|
|
180 * each highest hierarchical level node must be of the same type.
|
|
181
|
|
182 Thus, normally, each included file contains one, and only one,
|
|
183 chapter."
|
|
184 t nil)
|
|
185
|
|
186
|
|
187 ;;; Code:
|
|
188
|
|
189 ;;; Don't you dare insert any `require' calls at top level in this file--rms.
|
|
190
|
|
191 ;;; Syntax table
|
|
192
|
|
193 (defvar texinfo-mode-syntax-table nil)
|
|
194
|
|
195 (if texinfo-mode-syntax-table
|
|
196 nil
|
|
197 (setq texinfo-mode-syntax-table (make-syntax-table))
|
|
198 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
|
|
199 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
|
|
200 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
|
|
201 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
|
|
202 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
|
|
203 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
|
|
204 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
|
|
205 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
|
|
206 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
|
|
207
|
|
208 ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
|
|
209 ;; To overide this example, set either `imenu-generic-expression'
|
|
210 ;; or `imenu-create-index-function'.
|
|
211 ;(defvar texinfo-imenu-generic-expression
|
|
212 ; '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
|
|
213 ; ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
|
|
214
|
|
215 ; "Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
|
|
216
|
|
217 (defvar texinfo-font-lock-keywords
|
|
218 (list
|
|
219 ;; All but the first 2 had an OVERRIDE of t.
|
|
220 ;; It didn't seem to be any better, and it's slower--simon.
|
|
221 '("^\\(@c\\|@comment\\)\\>.*" . font-lock-comment-face) ;comments
|
|
222 ;; Robert J. Chassell <bob@gnu.ai.mit.edu> says remove this line.
|
|
223 ;'("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
|
|
224 "@\\(@\\|[^}\t \n{]+\\)" ;commands
|
|
225 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
|
|
226 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face)
|
|
227 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face)
|
|
228 '("@\\(samp\\|code\\|var\\|math\\){\\([^}]+\\)"
|
|
229 2 font-lock-variable-name-face)
|
|
230 '("@\\(cite\\|xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-reference-face)
|
|
231 '("@\\(end\\|item\\) *\\(.+\\)" 2 font-lock-function-name-face keep)
|
|
232 )
|
|
233 "Additional expressions to highlight in TeXinfo mode.")
|
|
234
|
|
235 ;; An older version.
|
|
236 ;(defconst texinfo-font-lock-keywords (purecopy
|
|
237 ; (list
|
|
238 ; "@\\(@\\|[^}\t \n{]+\\)" ;commands
|
|
239 ; '("^\\(@c\\|@comment\\)[ \t].*$" 0 font-lock-comment-face t) ;comments
|
|
240 ; '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
|
|
241 ; '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t)
|
|
242 ; '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t)
|
|
243 ; '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t)
|
|
244 ; '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t)
|
|
245 ; '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t)
|
|
246 ; '("@item \\(.*\\)$" 1 font-lock-function-name-face t)
|
|
247 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
|
|
248 ; ))
|
|
249 ; "Additional expressions to highlight in TeXinfo mode.")
|
|
250
|
|
251 (put 'texinfo-mode 'font-lock-defaults '(texinfo-font-lock-keywords t))
|
|
252
|
|
253 ;;; Keybindings
|
|
254 (defvar texinfo-mode-map nil)
|
|
255
|
|
256 ;;; Keys common both to Texinfo mode and to TeX shell.
|
|
257
|
|
258 (defun texinfo-define-common-keys (keymap)
|
|
259 "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
|
|
260 (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
|
|
261 (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
|
|
262 (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
|
|
263 (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
|
|
264 (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
|
|
265 (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
|
|
266 (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
|
|
267
|
|
268 (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
|
|
269 (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
|
|
270
|
|
271 ;; Mode documentation displays commands in reverse order
|
|
272 ;; from how they are listed in the texinfo-mode-map.
|
|
273
|
|
274 (if texinfo-mode-map
|
|
275 nil
|
|
276 (setq texinfo-mode-map (make-sparse-keymap))
|
|
277
|
|
278 ;; bindings for `texnfo-tex.el'
|
|
279 (texinfo-define-common-keys texinfo-mode-map)
|
|
280
|
|
281 ;; bindings for `makeinfo.el'
|
|
282 (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
|
|
283 (define-key texinfo-mode-map "\C-c\C-m\C-l"
|
|
284 'makeinfo-recenter-compilation-buffer)
|
|
285 (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
|
|
286 (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
|
|
287
|
|
288 ; Bindings for texinfmt.el.
|
|
289 (define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
|
|
290 (define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
|
|
291
|
|
292 ;; bindings for updating nodes and menus
|
|
293
|
|
294 (define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
|
|
295
|
|
296 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
|
|
297 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
|
|
298 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
|
|
299 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
|
|
300
|
|
301 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
|
|
302
|
|
303 (define-key texinfo-mode-map "\C-c}" 'up-list)
|
|
304 (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
|
|
305
|
|
306 ;; bindings for inserting strings
|
|
307
|
|
308 (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
|
|
309
|
|
310 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
|
|
311 (define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
|
|
312 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
|
|
313 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
|
|
314 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
|
|
315 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
|
|
316 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
|
|
317 (define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
|
|
318 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
|
|
319 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end)
|
|
320 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
|
|
321 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
|
|
322
|
|
323
|
|
324 ;;; Texinfo mode
|
|
325
|
|
326 (defvar texinfo-chapter-level-regexp
|
|
327 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
|
|
328 "Regular expression matching Texinfo chapter-level headings.
|
|
329 This does not match `@node' and does not match the `@top' command.")
|
|
330
|
|
331 ;;;###autoload
|
|
332 (defun texinfo-mode ()
|
|
333 "Major mode for editing Texinfo files.
|
|
334
|
|
335 It has these extra commands:
|
|
336 \\{texinfo-mode-map}
|
|
337
|
|
338 These are files that are used as input for TeX to make printed manuals
|
|
339 and also to be turned into Info files with \\[makeinfo-buffer] or
|
|
340 the `makeinfo' program. These files must be written in a very restricted and
|
|
341 modified version of TeX input format.
|
|
342
|
|
343 Editing commands are like text-mode except that the syntax table is
|
|
344 set up so expression commands skip Texinfo bracket groups. To see
|
|
345 what the Info version of a region of the Texinfo file will look like,
|
|
346 use \\[makeinfo-region], which runs `makeinfo' on the current region.
|
|
347
|
|
348 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
|
|
349 This command shows the structure of a Texinfo file by listing the
|
|
350 lines with the @-sign commands for @chapter, @section, and the like.
|
|
351 These lines are displayed in another window called the *Occur* window.
|
|
352 In that window, you can position the cursor over one of the lines and
|
|
353 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
|
|
354 in the Texinfo file.
|
|
355
|
|
356 In addition, Texinfo mode provides commands that insert various
|
|
357 frequently used @-sign commands into the buffer. You can use these
|
|
358 commands to save keystrokes. And you can insert balanced braces with
|
|
359 \\[texinfo-insert-braces] and later use the command \\[up-list] to
|
|
360 move forward past the closing brace.
|
|
361
|
|
362 Also, Texinfo mode provides functions for automatically creating or
|
|
363 updating menus and node pointers. These functions
|
|
364
|
|
365 * insert the `Next', `Previous' and `Up' pointers of a node,
|
|
366 * insert or update the menu for a section, and
|
|
367 * create a master menu for a Texinfo source file.
|
|
368
|
|
369 Here are the functions:
|
|
370
|
|
371 texinfo-update-node \\[texinfo-update-node]
|
|
372 texinfo-every-node-update \\[texinfo-every-node-update]
|
|
373 texinfo-sequential-node-update
|
|
374
|
|
375 texinfo-make-menu \\[texinfo-make-menu]
|
|
376 texinfo-all-menus-update \\[texinfo-all-menus-update]
|
|
377 texinfo-master-menu
|
|
378
|
|
379 texinfo-indent-menu-description (column &optional region-p)
|
|
380
|
|
381 The `texinfo-column-for-description' variable specifies the column to
|
|
382 which menu descriptions are indented.
|
|
383
|
|
384 Passed an argument (a prefix argument, if interactive), the
|
|
385 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
|
|
386 in the region.
|
|
387
|
|
388 To use the updating commands, you must structure your Texinfo file
|
|
389 hierarchically, such that each `@node' line, with the exception of the
|
|
390 Top node, is accompanied by some kind of section line, such as an
|
|
391 `@chapter' or `@section' line.
|
|
392
|
|
393 If the file has a `top' node, it must be called `top' or `Top' and
|
|
394 be the first node in the file.
|
|
395
|
|
396 Entering Texinfo mode calls the value of text-mode-hook, and then the
|
|
397 value of texinfo-mode-hook."
|
|
398 (interactive)
|
|
399 (text-mode)
|
|
400 (setq mode-name "Texinfo")
|
|
401 (setq major-mode 'texinfo-mode)
|
|
402 (use-local-map texinfo-mode-map)
|
|
403 (set-syntax-table texinfo-mode-syntax-table)
|
|
404 (make-local-variable 'page-delimiter)
|
|
405 (setq page-delimiter
|
|
406 (concat
|
|
407 "^@node [ \t]*[Tt]op\\|^@\\("
|
|
408 texinfo-chapter-level-regexp
|
|
409 "\\)"))
|
|
410 (make-local-variable 'require-final-newline)
|
|
411 (setq require-final-newline t)
|
|
412 (make-local-variable 'indent-tabs-mode)
|
|
413 (setq indent-tabs-mode nil)
|
|
414 (make-local-variable 'paragraph-separate)
|
|
415 (setq paragraph-separate (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
|
|
416 (make-local-variable 'paragraph-start)
|
|
417 (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
|
|
418 (make-local-variable 'fill-column)
|
|
419 (setq fill-column 72)
|
|
420 (make-local-variable 'comment-start)
|
|
421 (setq comment-start "@c ")
|
|
422 (make-local-variable 'comment-start-skip)
|
|
423 (setq comment-start-skip "@c +")
|
|
424 (make-local-variable 'words-include-escapes)
|
|
425 (setq words-include-escapes t)
|
|
426 ; (make-local-variable 'imenu-generic-expression)
|
|
427 ; (setq imenu-generic-expression texinfo-imenu-generic-expression)
|
|
428 (make-local-variable 'tex-start-of-header)
|
|
429 (setq tex-start-of-header "%**start")
|
|
430 (make-local-variable 'tex-end-of-header)
|
|
431 (setq tex-end-of-header "%**end")
|
|
432 (run-hooks 'text-mode-hook 'texinfo-mode-hook))
|
|
433
|
|
434
|
|
435 ;;; Insert string commands
|
|
436
|
|
437 (defconst texinfo-environment-regexp
|
|
438 "^[ \t]*@\\(f?table\\|enumerate\\|itemize\
|
|
439 \\|ifhtml\\|ifinfo\\|iftex\\|ifset\\|ifclear\
|
|
440 \\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\
|
|
441 \\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|html\\|cartouche\\|menu\
|
|
442 \\|titlepage\\|end\\|def[a-z]*[a-wyz]\\>\\)"
|
|
443 "Regexp for environment-like Texinfo list commands.
|
|
444 Subexpression 1 is what goes into the corresponding `@end' statement.")
|
|
445
|
|
446 (defun texinfo-insert-@end ()
|
|
447 "Insert the matching `@end' for the last Texinfo command that needs one."
|
|
448 (interactive)
|
|
449 (let ((depth 1) string)
|
|
450 (save-excursion
|
|
451 (while (and (> depth 0)
|
|
452 (re-search-backward texinfo-environment-regexp nil t)
|
|
453 (if (looking-at "@end")
|
|
454 (setq depth (1+ depth))
|
|
455 (setq depth (1- depth)))))
|
|
456 (looking-at texinfo-environment-regexp)
|
|
457 (if (zerop depth)
|
|
458 (setq string
|
|
459 (buffer-substring (match-beginning 1)
|
|
460 (match-end 1)))))
|
|
461 (insert "@end ")
|
|
462 (if string (insert string "\n"))))
|
|
463
|
|
464 ;; The following insert commands accept a prefix arg N, which is the
|
|
465 ;; number of words (actually s-exprs) that should be surrounded by
|
|
466 ;; braces. Thus you can first paste a variable name into a .texinfo
|
|
467 ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
|
|
468 ;; pasted variable name to put @var{...} *around* the variable name.
|
|
469 ;; Operate on previous word or words with negative arg.
|
|
470
|
|
471 ;; These commands use texinfo-insert-@-with-arg
|
|
472 (defun texinfo-insert-@-with-arg (string &optional arg)
|
|
473 (if arg
|
|
474 (progn
|
|
475 (setq arg (prefix-numeric-value arg))
|
|
476 (if (< arg 0)
|
|
477 (progn
|
|
478 (skip-chars-backward " \t\n\r\f")
|
|
479 (save-excursion
|
|
480 (forward-sexp arg)
|
|
481 (insert "@" string "{"))
|
|
482 (insert "}"))
|
|
483 (skip-chars-forward " \t\n\r\f")
|
|
484 (insert "@" string "{")
|
|
485 (forward-sexp arg)
|
|
486 (insert "}")))
|
|
487 (insert "@" string "{}")
|
|
488 (backward-char)))
|
|
489
|
|
490 (defun texinfo-insert-braces ()
|
|
491 "Make a pair of braces and be poised to type inside of them.
|
|
492 Use \\[up-list] to move forward out of the braces."
|
|
493 (interactive)
|
|
494 (insert "{}")
|
|
495 (backward-char))
|
|
496
|
|
497 (defun texinfo-insert-@code (&optional arg)
|
|
498 "Insert a `@code{...}' command in a Texinfo buffer.
|
|
499 A numeric argument says how many words the braces should surround.
|
|
500 The default is not to surround any existing words with the braces."
|
|
501 (interactive "P")
|
|
502 (texinfo-insert-@-with-arg "code" arg))
|
|
503
|
|
504 (defun texinfo-insert-@dfn (&optional arg)
|
|
505 "Insert a `@dfn{...}' command in a Texinfo buffer.
|
|
506 A numeric argument says how many words the braces should surround.
|
|
507 The default is not to surround any existing words with the braces."
|
|
508 (interactive "P")
|
|
509 (texinfo-insert-@-with-arg "dfn" arg))
|
|
510
|
|
511 (defun texinfo-insert-@example ()
|
|
512 "Insert the string `@example' in a Texinfo buffer."
|
|
513 (interactive)
|
|
514 (insert "@example\n"))
|
|
515
|
|
516 (defun texinfo-insert-@file (&optional arg)
|
|
517 "Insert a `@file{...}' command in a Texinfo buffer.
|
|
518 A numeric argument says how many words the braces should surround.
|
|
519 The default is not to surround any existing words with the braces."
|
|
520 (interactive "P")
|
|
521 (texinfo-insert-@-with-arg "file" arg))
|
|
522
|
|
523 (defun texinfo-insert-@item ()
|
|
524 "Insert the string `@item' in a Texinfo buffer."
|
|
525 (interactive)
|
|
526 (insert "@item")
|
|
527 (newline))
|
|
528
|
|
529 (defun texinfo-insert-@kbd (&optional arg)
|
|
530 "Insert a `@kbd{...}' command in a Texinfo buffer.
|
|
531 A numeric argument says how many words the braces should surround.
|
|
532 The default is not to surround any existing words with the braces."
|
|
533 (interactive "P")
|
|
534 (texinfo-insert-@-with-arg "kbd" arg))
|
|
535
|
|
536 (defun texinfo-insert-@node ()
|
|
537 "Insert the string `@node' in a Texinfo buffer.
|
|
538 This also inserts on the following line a comment indicating
|
|
539 the order of arguments to @node."
|
|
540 (interactive)
|
|
541 (insert "@node \n@comment node-name, next, previous, up")
|
|
542 (forward-line -1)
|
|
543 (forward-char 6))
|
|
544
|
|
545 (defun texinfo-insert-@noindent ()
|
|
546 "Insert the string `@noindent' in a Texinfo buffer."
|
|
547 (interactive)
|
|
548 (insert "@noindent\n"))
|
|
549
|
|
550 (defun texinfo-insert-@samp (&optional arg)
|
|
551 "Insert a `@samp{...}' command in a Texinfo buffer.
|
|
552 A numeric argument says how many words the braces should surround.
|
|
553 The default is not to surround any existing words with the braces."
|
|
554 (interactive "P")
|
|
555 (texinfo-insert-@-with-arg "samp" arg))
|
|
556
|
|
557 (defun texinfo-insert-@table (&optional arg)
|
|
558 "Insert the string `@table' in a Texinfo buffer."
|
|
559 (interactive "P")
|
|
560 (insert "@table "))
|
|
561
|
|
562 (defun texinfo-insert-@var (&optional arg)
|
|
563 "Insert a `@var{}' command in a Texinfo buffer.
|
|
564 A numeric argument says how many words the braces should surround.
|
|
565 The default is not to surround any existing words with the braces."
|
|
566 (interactive "P")
|
|
567 (texinfo-insert-@-with-arg "var" arg))
|
|
568
|
|
569 ;;; Texinfo file structure
|
|
570
|
|
571 (defun texinfo-show-structure (&optional nodes-too)
|
|
572 "Show the structure of a Texinfo file.
|
|
573 List the lines in the file that begin with the @-sign commands for
|
|
574 @chapter, @section, and the like.
|
|
575
|
|
576 With optional argument (prefix if interactive), list both the lines
|
|
577 with @-sign commands for @chapter, @section, and the like, and list
|
|
578 @node lines.
|
|
579
|
|
580 Lines with structuring commands beginning in them are displayed in
|
|
581 another buffer named `*Occur*'. In that buffer, you can move point to
|
|
582 one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
|
|
583 to jump to the corresponding spot in the Texinfo source file."
|
|
584
|
|
585 (interactive "P")
|
|
586 (require 'texnfo-upd)
|
|
587 (save-excursion
|
|
588 (goto-char (point-min))
|
|
589 (if nodes-too
|
|
590 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
|
|
591 (occur texinfo-section-types-regexp)))
|
|
592 (pop-to-buffer "*Occur*")
|
|
593 (goto-char (point-min))
|
|
594 (flush-lines "-----")
|
|
595 ;; Now format the "*Occur*" buffer to show the structure.
|
|
596 ;; Thanks to ceder@signum.se (Per Cederqvist)
|
|
597 (goto-char (point-max))
|
|
598 (let ((margin 5))
|
|
599 (while (re-search-backward "^ *[0-9]*:" nil 0)
|
|
600 (re-search-forward ":")
|
|
601 (setq margin
|
|
602 (cond
|
|
603 ((looking-at
|
|
604 (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
|
|
605 ;; ((looking-at "@chapter ") 5)
|
|
606 ;; ((looking-at "@unnumbered ") 5)
|
|
607 ;; ((looking-at "@appendix ") 5)
|
|
608 ;; ((looking-at "@majorheading ") 5)
|
|
609 ;; ((looking-at "@chapheading ") 5)
|
|
610
|
|
611 ((looking-at
|
|
612 (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
|
|
613 ;; ((looking-at "@section ") 9)
|
|
614 ;; ((looking-at "@unnumberedsec ") 9)
|
|
615 ;; ((looking-at "@appendixsec ") 9)
|
|
616 ;; ((looking-at "@heading ") 9)
|
|
617
|
|
618 ((looking-at
|
|
619 (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
|
|
620 ;; ((looking-at "@subsection ") 13)
|
|
621 ;; ((looking-at "@unnumberedsubsec ") 13)
|
|
622 ;; ((looking-at "@appendixsubsec ") 13)
|
|
623 ;; ((looking-at "@subheading ") 13)
|
|
624
|
|
625 ((looking-at
|
|
626 (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
|
|
627 ;; ((looking-at "@subsubsection ") 17)
|
|
628 ;; ((looking-at "@unnumberedsubsubsec ") 17)
|
|
629 ;; ((looking-at "@appendixsubsubsec ") 17)
|
|
630 ;; ((looking-at "@subsubheading ") 17)
|
|
631 (t margin)))
|
|
632 (indent-to-column margin)
|
|
633 (beginning-of-line))))
|
|
634
|
|
635 ;;; The tex and print function definitions:
|
|
636
|
120
|
637 (defcustom texinfo-texi2dvi-command "texi2dvi"
|
|
638 "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
|
|
639 :type 'string
|
|
640 :group 'texinfo)
|
0
|
641
|
120
|
642 (defcustom texinfo-tex-command "tex"
|
|
643 "*Command used by `texinfo-tex-region' to run TeX on a region."
|
|
644 :type 'string
|
|
645 :group 'texinfo)
|
0
|
646
|
120
|
647 (defcustom texinfo-texindex-command "texindex"
|
|
648 "*Command used by `texinfo-texindex' to sort unsorted index files."
|
|
649 :type 'string
|
|
650 :group 'texinfo)
|
0
|
651
|
120
|
652 (defcustom texinfo-delete-from-print-queue-command "lprm"
|
0
|
653 "*Command string used to delete a job from the line printer queue.
|
|
654 Command is used by \\[texinfo-delete-from-print-queue] based on
|
|
655 number provided by a previous \\[tex-show-print-queue]
|
120
|
656 command."
|
|
657 :type 'string
|
|
658 :group 'texinfo)
|
0
|
659
|
|
660 (defvar texinfo-tex-trailer "@bye"
|
|
661 "String appended after a region sent to TeX by `texinfo-tex-region'.")
|
|
662
|
|
663 (defun texinfo-tex-region (beg end)
|
|
664 "Run TeX on the current region.
|
|
665 This works by writing a temporary file (`tex-zap-file') in the directory
|
|
666 that is the value of `tex-directory', then running TeX on that file.
|
|
667
|
|
668 The first line of the buffer is copied to the
|
|
669 temporary file; and if the buffer has a header, it is written to the
|
|
670 temporary file before the region itself. The buffer's header is all lines
|
|
671 between the strings defined by `tex-start-of-header' and `tex-end-of-header'
|
|
672 inclusive. The header must start in the first 100 lines.
|
|
673
|
|
674 The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
|
|
675 (interactive "r")
|
|
676 (require 'tex-mode)
|
|
677 (if (get-buffer "*tex-shell*")
|
|
678 (tex-kill-job)
|
|
679 (tex-start-shell))
|
|
680 (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
|
|
681 (let ((tex-out-file (concat tex-zap-file ".tex"))
|
|
682 (temp-buffer (get-buffer-create " tex-Output-Buffer"))
|
|
683 (zap-directory
|
|
684 (file-name-as-directory (expand-file-name tex-directory))))
|
|
685 (save-excursion
|
|
686 (save-restriction
|
|
687 (widen)
|
|
688 (goto-char (point-min))
|
|
689 (forward-line 100)
|
|
690 (let ((search-end (point))
|
|
691 (hbeg (point-min)) (hend (point-min))
|
|
692 (default-directory zap-directory))
|
|
693 (goto-char (point-min))
|
|
694
|
|
695 ;; Copy first line, the `\input texinfo' line, to temp file
|
|
696 (write-region (point)
|
|
697 (save-excursion (end-of-line) (point))
|
|
698 tex-out-file nil nil)
|
|
699
|
|
700 ;; Don't copy first line twice if region includes it.
|
|
701 (forward-line 1)
|
|
702 (if (< beg (point)) (setq beg (point)))
|
|
703
|
|
704 ;; Initialize the temp file with either the header or nothing
|
|
705 (if (search-forward tex-start-of-header search-end t)
|
|
706 (progn
|
|
707 (beginning-of-line)
|
|
708 (setq hbeg (point)) ; Mark beginning of header.
|
|
709 (if (search-forward tex-end-of-header nil t)
|
|
710 (progn (beginning-of-line)
|
|
711 (setq hend (point))) ; Mark end of header.
|
|
712 (setq hbeg (point-min))))) ; Else no header.
|
|
713
|
|
714 ;; Copy header to temp file.
|
|
715 (write-region (min hbeg beg) hend tex-out-file t nil)
|
|
716
|
|
717 ;; Copy region to temp file.
|
|
718 (write-region (max beg hend) end tex-out-file t nil))
|
|
719
|
|
720 ;; This is a kludge to insert the tex-trailer into the tex-out-file.
|
|
721 ;; We have to create a special buffer in which to insert
|
|
722 ;; the tex-trailer first because there is no function with
|
|
723 ;; which to append a literal string directly to a file.
|
|
724 (let ((local-tex-trailer texinfo-tex-trailer))
|
|
725 (set-buffer temp-buffer)
|
|
726 (erase-buffer)
|
|
727 ;; make sure trailer isn't hidden by a comment
|
|
728 (insert-string "\n")
|
|
729 (if local-tex-trailer (insert-string local-tex-trailer))
|
|
730 (tex-set-buffer-directory temp-buffer zap-directory)
|
|
731 (write-region (point-min) (point-max) tex-out-file t nil))
|
|
732
|
|
733 ;;; The following is sufficient in Emacs 19.
|
|
734 ;;; (write-region (concat "\n" texinfo-tex-trailer) nil
|
|
735 ;;; tex-out-file t nil)
|
|
736 ))
|
|
737
|
|
738 (tex-set-buffer-directory "*tex-shell*" zap-directory)
|
|
739 (tex-send-command tex-shell-cd-command zap-directory)
|
|
740 (tex-send-command texinfo-tex-command tex-out-file))
|
|
741 (tex-recenter-output-buffer 0))
|
|
742
|
|
743 (defun texinfo-tex-buffer ()
|
|
744 "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
|
|
745 (interactive)
|
|
746
|
|
747 ;; Make sure TeX shell is running.
|
|
748 (require 'tex-mode)
|
|
749 (if (get-buffer "*tex-shell*")
|
|
750 (quit-process (get-process "tex-shell") t)
|
|
751 (tex-start-shell))
|
|
752
|
|
753 (cond ((null buffer-file-name)
|
|
754 (error "Buffer not visiting any file!"))
|
|
755 ((buffer-modified-p)
|
|
756 (error "Buffer has been modified since last saved!")))
|
|
757
|
|
758 (setq tex-zap-file buffer-file-name)
|
|
759
|
|
760 (tex-send-command tex-shell-cd-command (file-name-directory tex-zap-file))
|
|
761
|
|
762 (tex-send-command texinfo-texi2dvi-command tex-zap-file)
|
|
763
|
|
764 (tex-recenter-output-buffer 0))
|
|
765
|
|
766 (defun texinfo-texindex ()
|
|
767 "Run `texindex' on unsorted index files.
|
|
768 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
|
|
769 This runs the shell command defined by `texinfo-texindex-command'."
|
|
770 (interactive)
|
|
771 (require 'tex-mode)
|
|
772 (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
|
|
773 (tex-recenter-output-buffer nil))
|
|
774
|
|
775 (defun texinfo-tex-print ()
|
|
776 "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
|
|
777 This runs the shell command defined by `tex-dvi-print-command'."
|
|
778 (interactive)
|
|
779 (require 'tex-mode)
|
|
780 (tex-send-command tex-dvi-print-command (concat tex-zap-file ".dvi"))
|
|
781 (tex-recenter-output-buffer nil))
|
|
782
|
|
783 (defun texinfo-quit-job ()
|
|
784 "Quit currently running TeX job, by sending an `x' to it."
|
|
785 (interactive)
|
|
786 (if (not (get-process "tex-shell"))
|
|
787 (error "No TeX shell running"))
|
|
788 (tex-send-command "x"))
|
|
789
|
|
790 (defun texinfo-delete-from-print-queue (job-number)
|
|
791 "Delete job from the line printer spooling queue.
|
|
792 You are prompted for the job number (use a number shown by a previous
|
|
793 \\[texinfo-show-print-queue] command)."
|
|
794 (interactive "nPrinter job number for deletion: ")
|
|
795 (require 'tex-mode)
|
|
796 (if (tex-shell-running)
|
|
797 (tex-kill-job)
|
|
798 (tex-start-shell))
|
|
799 (tex-send-command texinfo-delete-from-print-queue-command job-number)
|
|
800 (tex-recenter-output-buffer nil))
|
|
801
|
|
802 (provide 'texinfo)
|
|
803
|
|
804 ;;; texinfo.el ends here
|