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