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