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