]> code.delx.au - gnu-emacs/blob - lisp/textmodes/texinfo.el
Removed dired-ls-function.
[gnu-emacs] / lisp / textmodes / texinfo.el
1 ;;;; texinfo.el
2 ;;;; Major mode for editing Texinfo files.
3
4 ;;;; Version 2.00 14 Dec 1990
5
6 ;; Copyright (C) 1985, 1988, 1989, 1990 Free Software Foundation, Inc.
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 1, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 (require 'texnfo-upd)
25 (require 'tex-mode)
26 (provide 'texinfo)
27
28 (defvar texinfo-mode-syntax-table nil)
29
30 (if texinfo-mode-syntax-table
31 nil
32 (setq texinfo-mode-syntax-table (make-syntax-table))
33 (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
34 (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
35 (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
36 (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
37 (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
38 (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
39 (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
40 (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
41 (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
42
43 (defvar texinfo-mode-map nil)
44
45 ;; Mode documentation displays commands in reverse order
46 ;; from how they are listed in the texinfo-mode-map.
47 (if texinfo-mode-map
48 nil
49 (setq texinfo-mode-map (make-sparse-keymap))
50
51 (define-key texinfo-mode-map "\C-c\C-t\C-k" 'tex-kill-job)
52 (define-key texinfo-mode-map "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
53 (define-key texinfo-mode-map "\C-c\C-t\C-q" 'tex-show-print-queue)
54 (define-key texinfo-mode-map "\C-c\C-t\C-p" 'texinfo-tex-print)
55 (define-key texinfo-mode-map "\C-c\C-t\C-i" 'texinfo-texindex)
56 (define-key texinfo-mode-map "\C-c\C-t\C-t" 'texinfo-tex-buffer)
57 (define-key texinfo-mode-map "\C-c\C-t\C-r" 'texinfo-tex-region)
58
59 (define-key texinfo-mode-map "\C-c\C-i\C-r" 'texinfo-format-region)
60 (define-key texinfo-mode-map "\C-c\C-i\C-b" 'texinfo-format-buffer)
61
62 (define-key texinfo-mode-map "\C-c\C-u\C-m" 'texinfo-make-menu)
63 (define-key texinfo-mode-map "\C-c\C-u\C-n" 'texinfo-update-node)
64 (define-key texinfo-mode-map "\C-c\C-u\C-e" 'texinfo-every-node-update)
65 (define-key texinfo-mode-map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
66
67 (define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
68
69 (define-key texinfo-mode-map "\"" 'tex-insert-quote)
70 (define-key texinfo-mode-map "\e}" 'up-list)
71 (define-key texinfo-mode-map "\e{" 'texinfo-insert-braces)
72
73 (define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
74 (define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
75 (define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
76 (define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
77 (define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
78 (define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
79 (define-key texinfo-mode-map "\C-c\C-cx" 'texinfo-insert-@example)
80 (define-key texinfo-mode-map "\C-c\C-ce" 'texinfo-insert-@end-example)
81 (define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
82 (define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
83
84 (defun texinfo-insert-@var ()
85 "Insert the string @var in a texinfo buffer."
86 (interactive)
87 (insert "@var{}")
88 (backward-char))
89
90 (defun texinfo-insert-@samp ()
91 "Insert the string @samp in a texinfo buffer."
92 (interactive)
93 (insert "@samp{}")
94 (backward-char))
95
96 (defun texinfo-insert-@noindent ()
97 "Insert the string @noindent in a texinfo buffer."
98 (interactive)
99 (insert "@noindent\n"))
100
101 (defun texinfo-insert-@node ()
102 "Insert the string @node in a texinfo buffer,
103 along with a comment indicating the arguments to @node."
104 (interactive)
105 (insert "@node \n@comment node-name, next, previous, up")
106 (forward-line -1)
107 (forward-char 6))
108
109 (defun texinfo-insert-@kbd ()
110 "Insert the string @kbd in a texinfo buffer."
111 (interactive)
112 (insert "@kbd{}")
113 (backward-char))
114
115 (defun texinfo-insert-@item ()
116 "Insert the string @item in a texinfo buffer."
117 (interactive)
118 (insert "@item")
119 (newline))
120
121 (defun texinfo-insert-@example ()
122 "Insert the string @example in a texinfo buffer."
123 (interactive)
124 (insert "@example\n"))
125
126 (defun texinfo-insert-@end-example ()
127 "Insert the string @end example in a texinfo buffer."
128 (interactive)
129 (insert "@end example\n"))
130
131 (defun texinfo-insert-@dfn ()
132 "Insert the string @dfn in a texinfo buffer."
133 (interactive)
134 (insert "@dfn{}")
135 (backward-char))
136
137 (defun texinfo-insert-@code ()
138 "Insert the string @code in a texinfo buffer."
139 (interactive)
140 (insert "@code{}")
141 (backward-char))
142
143 (defun texinfo-insert-braces ()
144 "Make a pair of braces and be poised to type inside of them.
145 Use \\[up-list] to move forward out of the braces."
146 (interactive)
147 (insert "{}")
148 (backward-char))
149
150 (defun texinfo-mode ()
151 "Major mode for editing Texinfo files.
152
153 It has these extra commands:
154 \\{texinfo-mode-map}
155
156 These are files that are used as input for TeX to make printed manuals
157 and also to be turned into Info files by \\[texinfo-format-buffer] or
158 `makeinfo'. These files must be written in a very restricted and
159 modified version of TeX input format.
160
161 Editing commands are like text-mode except that the syntax table is
162 set up so expression commands skip Texinfo bracket groups. To see
163 what the Info version of a region of the Texinfo file will look like,
164 use \\[texinfo-format-region]. This command runs Info on the current region
165 of the Texinfo file and formats it properly.
166
167 You can show the structure of a Texinfo file with \\[texinfo-show-structure].
168 This command shows the structure of a Texinfo file by listing the
169 lines with the @-sign commands for @chapter, @section, and the like.
170 These lines are displayed in another window called the *Occur* window.
171 In that window, you can position the cursor over one of the lines and
172 use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
173 in the Texinfo file.
174
175 In addition, Texinfo mode provides commands that insert various
176 frequently used @-sign commands into the buffer. You can use these
177 commands to save keystrokes. And you can insert balanced braces with
178 \\[texinfo-insert-braces] and later use the command \\[up-list] to
179 move forward past the closing brace.
180
181 Also, Texinfo mode provides functions for automatically creating or
182 updating menus and node pointers. These functions
183
184 * insert the `Next', `Previous' and `Up' pointers of a node,
185 * insert or update the menu for a section, and
186 * create a master menu for a Texinfo source file.
187
188 Here are the functions:
189
190 texinfo-update-node \\[texinfo-update-node]
191 texinfo-every-node-update \\[texinfo-every-node-update]
192 texinfo-sequential-node-update
193
194 texinfo-make-menu \\[texinfo-make-menu]
195 texinfo-all-menus-update \\[texinfo-all-menus-update]
196 texinfo-master-menu
197
198 texinfo-indent-menu-description (column &optional region-p)
199
200 The `texinfo-column-for-description' variable specifies the column to
201 which menu descriptions are indented.
202
203 Passed an argument (a prefix argument, if interactive), the
204 `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
205 in the region.
206
207 To use the updating commands, you must structure your Texinfo file
208 hierarchically, such that each `@node' line, with the exception of the
209 Top node, is accompanied by some kind of section line, such as an
210 `@chapter' or `@section' line.
211
212 If the file has a `top' node, it must be called `top' or `Top' and
213 be the first node in the file.
214
215 Entering Texinfo mode calls the value of text-mode-hook, and then the
216 value of texinfo-mode-hook."
217 (interactive)
218 (text-mode)
219 (setq mode-name "texinfo")
220 (setq major-mode 'texinfo-mode)
221 (use-local-map texinfo-mode-map)
222 (set-syntax-table texinfo-mode-syntax-table)
223 (make-local-variable 'require-final-newline)
224 (setq require-final-newline t)
225 (make-local-variable 'paragraph-separate)
226 (setq paragraph-separate (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-separate))
227 (make-local-variable 'paragraph-start)
228 (setq paragraph-start (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-start))
229 (make-local-variable 'fill-column)
230 (setq fill-column 72)
231 (make-local-variable 'comment-start)
232 (setq comment-start "@c ")
233 (make-local-variable 'comment-start-skip)
234 (setq comment-start-skip "@c +")
235 (make-local-variable 'words-include-escapes)
236 (setq words-include-escapes t)
237 (make-local-variable 'tex-start-of-header)
238 (setq tex-start-of-header "%**start of header")
239 (make-local-variable 'tex-end-of-header)
240 (setq tex-end-of-header "%**end of header")
241 (make-local-variable 'tex-trailer)
242 (setq tex-trailer "@bye\n")
243 (run-hooks 'text-mode-hook 'texinfo-mode-hook))
244
245 \f
246 ;;; Texinfo file structure
247
248 ; The following is defined in `texnfo-upd.el'
249 ; (defvar texinfo-section-types-regexp
250 ; "^@\\(chapter \\|sect\\|sub\\|unnum\\|major\\|heading \\|appendix\\)"
251 ; "Regexp matching chapter, section, other headings (but not the top node).")
252
253 (defun texinfo-show-structure (&optional nodes-too)
254 "Show the structure of a Texinfo file.
255 List the lines in the file that begin with the @-sign commands for
256 @chapter, @section, and the like.
257
258 With optional argument (prefix if interactive), list both the lines
259 with @-sign commands for @chapter, @section, and the like, and list
260 @node lines.
261
262 Lines with structuring commands beginning in them are displayed in
263 another window called the *Occur* window. In that window, you can
264 position the cursor over one of the lines and use
265 \\[occur-mode-goto-occurrence],
266 to jump to the corresponding spot in the Texinfo file."
267
268 (interactive "P")
269 (save-excursion
270 (goto-char (point-min))
271 (if nodes-too
272 (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
273 (occur texinfo-section-types-regexp)))
274 (pop-to-buffer "*Occur*")
275 (goto-char (point-min))
276 (flush-lines "-----"))
277
278 \f
279 ;;; texinfo mode tex and hardcopy printing commands.
280
281 ;; These commands are for running tex on a region of a texinfo file in
282 ;; GNU Emacs, or on the whole buffer, and for printing the resulting
283 ;; .dvi file. The three commands are:
284
285 ; texinfo-tex-region to run tex on the current region.
286 ; texinfo-tex-buffer to run tex on the current buffer.
287 ; texinfo-tex-print to print the .dvi file made by tex
288
289 ;;; Other useful functions
290
291 ; These functions are provided by `tex-mode.el' but are bound to keys
292 ; in texinfo mode.
293
294 ; tex-kill-job to kill the currently running tex job
295 ; tex-recenter-output-buffer to redisplay tex job output buffer
296 ; tex-show-print-queue to show the print queue
297
298 ; Various variables are provided by `tex-mode.el'
299
300 ; tex mode variable Default Value
301
302 ; tex-dvi-print-command "lpr -d"
303 ; tex-directory "/tmp/"
304 ; tex-show-queue-command "lpq"
305 ; tex-shell-cd-command "cd"
306 ; tex-zap-file nil (created as needed)
307
308 \f
309 ;;; The tex and print function definitions:
310
311 (defvar texinfo-tex-command "tex"
312 "*Command used by texinfo-tex-region to run tex on a region.")
313
314 (defvar texinfo-texindex-command "texindex"
315 "*Command used by texinfo-texindex to sort unsorted index files.")
316
317 (defun texinfo-tex-region (beg end)
318 "Run tex on the current region. A temporary file (tex-zap-file) is
319 written in directory tex-directory, and tex is run in that directory.
320 The first line of the file is copied to the temporary file; and
321 if the buffer has a header, it is written to the temporary file before
322 the region itself. The buffer's header is all lines between the
323 strings defined by tex-start-of-header and tex-end-of-header
324 inclusive. The header must start in the first 100 lines. The value
325 of tex-trailer is appended to the temporary file after the region."
326 (interactive "r")
327 (if (get-buffer "*tex-shell*")
328 (tex-kill-job)
329 (tex-start-shell))
330 (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
331 (let ((tex-out-file (concat tex-zap-file ".tex"))
332 (temp-buffer (get-buffer-create " tex-Output-Buffer"))
333 (zap-directory
334 (file-name-as-directory (expand-file-name tex-directory))))
335 (save-excursion
336 (save-restriction
337 (widen)
338 (goto-char (point-min))
339 (forward-line 100)
340 (let ((search-end (point))
341 (hbeg (point-min)) (hend (point-min))
342 (default-directory zap-directory))
343 (goto-char (point-min))
344
345 ;; Copy first line, the `\input texinfo' line, to temp file
346 (write-region (point)
347 (save-excursion (end-of-line) (point))
348 tex-out-file nil nil)
349
350 ;; Don't copy first line twice if region includes it.
351 (forward-line 1)
352 (if (< beg (point)) (setq beg (point)))
353
354 ;; Initialize the temp file with either the header or nothing
355 (if (search-forward tex-start-of-header search-end t)
356 (progn
357 (beginning-of-line)
358 (setq hbeg (point)) ; Mark beginning of header.
359 (if (search-forward tex-end-of-header nil t)
360 (progn (beginning-of-line)
361 (setq hend (point))) ; Mark end of header.
362 (setq hbeg (point-min))))) ; Else no header.
363
364 ;; Copy header to temp file.
365 (write-region (min hbeg beg) hend tex-out-file t nil)
366
367 ;; Copy region to temp file.
368 (write-region (max beg hend) end tex-out-file t nil))
369
370 ;; This is a kludge to insert the tex-trailer into the tex-out-file.
371 ;; We have to create a special buffer in which to insert
372 ;; the tex-trailer first because there is no function with
373 ;; which to append a literal string directly to a file.
374 (let ((local-tex-trailer tex-trailer))
375 (set-buffer temp-buffer)
376 (erase-buffer)
377 ;; make sure trailer isn't hidden by a comment
378 (insert-string "\n")
379 (if local-tex-trailer (insert-string local-tex-trailer))
380 (set-buffer-directory temp-buffer zap-directory)
381 (write-region (point-min) (point-max) tex-out-file t nil))))
382
383 (set-buffer-directory "*tex-shell*" zap-directory)
384 (send-string "tex-shell" (concat tex-shell-cd-command " "
385 zap-directory "\n"))
386 (send-string "tex-shell" (concat texinfo-tex-command " "
387 tex-out-file "\n")))
388 (tex-recenter-output-buffer 0))
389
390 (defun texinfo-tex-buffer ()
391 "Run tex on current buffer.
392 See \\[texinfo-tex-region] for more information."
393 (interactive)
394 (texinfo-tex-region (point-min) (point-max)))
395
396 (defun texinfo-texindex ()
397 "Run texindex on unsorted index files.
398 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
399 Runs the shell command defined by texinfo-texindex-command."
400 (interactive)
401 (send-string "tex-shell"
402 (concat texinfo-texindex-command
403 " " tex-zap-file ".??" "\n"))
404 (tex-recenter-output-buffer nil))
405
406 (defun texinfo-tex-print ()
407 "Print .dvi file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
408 Runs the shell command defined by tex-dvi-print-command."
409 (interactive)
410 (send-string "tex-shell"
411 (concat tex-dvi-print-command
412 " " tex-zap-file ".dvi" "\n"))
413 (tex-recenter-output-buffer nil))
414