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