Mercurial > emacs
annotate lisp/textmodes/makeinfo.el @ 42675:640c0fcaebf1
Fix typos.
author | Pavel Janík <Pavel@Janik.cz> |
---|---|
date | Sat, 12 Jan 2002 16:01:51 +0000 |
parents | 3bdd11464124 |
children | 48b3aae63381 |
rev | line source |
---|---|
13337 | 1 ;;; makeinfo.el --- run makeinfo conveniently |
2 | |
3 ;; Copyright (C) 1991, 1993 Free Software Foundation, Inc. | |
3856 | 4 |
13337 | 5 ;; Author: Robert J. Chassell |
6 ;; Maintainer: FSF | |
38697
a19197c6442f
Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents:
38412
diff
changeset
|
7 ;; Keywords: docs convenience |
3856 | 8 |
13337 | 9 ;; This file is part of GNU Emacs. |
3856 | 10 |
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) | |
14 ;; any later version. | |
15 | |
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. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
3856 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;;; The Texinfo mode `makeinfo' related commands are: | |
29 | |
30 ;; makeinfo-region to run makeinfo on the current region. | |
31 ;; makeinfo-buffer to run makeinfo on the current buffer, or | |
32 ;; with optional prefix arg, on current region | |
33 ;; kill-compilation to kill currently running makeinfo job | |
34 ;; makeinfo-recenter-makeinfo-buffer to redisplay *compilation* buffer | |
35 | |
36 ;;; Keybindings (defined in `texinfo.el') | |
37 | |
38 ;; makeinfo bindings | |
39 ; (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region) | |
40 ; (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer) | |
41 ; (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation) | |
42 ; (define-key texinfo-mode-map "\C-c\C-m\C-l" | |
43 ; 'makeinfo-recenter-compilation-buffer) | |
44 | |
45 ;;; Code: | |
46 | |
47 ;;; Variables used by `makeinfo' | |
48 | |
49 (require 'compile) | |
50 | |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
51 (defgroup makeinfo nil |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
52 "Run makeinfo conveniently" |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
53 :group 'docs) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
54 |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
55 |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
56 (defcustom makeinfo-run-command "makeinfo" |
3856 | 57 "*Command used to run `makeinfo' subjob. |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
58 The name of the file is appended to this string, separated by a space." |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
59 :type 'string |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
60 :group 'makeinfo) |
3856 | 61 |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
62 (defcustom makeinfo-options "--fill-column=70" |
3856 | 63 "*String containing options for running `makeinfo'. |
64 Do not include `--footnote-style' or `--paragraph-indent'; | |
65 the proper way to specify those is with the Texinfo commands | |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
66 `@footnotestyle` and `@paragraphindent'." |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
67 :type 'string |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
68 :group 'makeinfo) |
3856 | 69 |
70 (require 'texinfo) | |
71 | |
72 (defvar makeinfo-compilation-process nil | |
73 "Process that runs `makeinfo'. Should start out nil.") | |
74 | |
75 (defvar makeinfo-temp-file nil | |
76 "Temporary file name used for text being sent as input to `makeinfo'.") | |
77 | |
78 (defvar makeinfo-output-file-name nil | |
79 "Info file name used for text output by `makeinfo'.") | |
80 | |
81 | |
82 ;;; The `makeinfo' function definitions | |
83 | |
84 (defun makeinfo-region (region-beginning region-end) | |
85 "Make Info file from region of current Texinfo file, and switch to it. | |
86 | |
87 This command does not offer the `next-error' feature since it would | |
88 apply to a temporary file, not the original; use the `makeinfo-buffer' | |
89 command to gain use of `next-error'." | |
90 | |
91 (interactive "r") | |
92 (let (filename-or-header | |
93 filename-or-header-beginning | |
94 filename-or-header-end) | |
95 ;; Cannot use `let' for makeinfo-temp-file or | |
96 ;; makeinfo-output-file-name since `makeinfo-compilation-sentinel' | |
97 ;; needs them. | |
98 | |
99 (setq makeinfo-temp-file | |
100 (concat | |
26039
fb6b9c37cdc4
Use make-temp-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
17411
diff
changeset
|
101 (make-temp-file |
3856 | 102 (substring (buffer-file-name) |
103 0 | |
104 (or (string-match "\\.tex" (buffer-file-name)) | |
105 (length (buffer-file-name))))) | |
106 ".texinfo")) | |
107 | |
108 (save-excursion | |
109 (save-restriction | |
110 (widen) | |
111 (goto-char (point-min)) | |
112 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
113 ;; Find and record the Info filename, | |
114 ;; or else explain that a filename is needed. | |
115 (if (re-search-forward | |
116 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
117 search-end t) | |
118 (setq makeinfo-output-file-name | |
119 (buffer-substring (match-beginning 1) (match-end 1))) | |
120 (error | |
121 "The texinfo file needs a line saying: @setfilename <name>")) | |
122 | |
123 ;; Find header and specify its beginning and end. | |
124 (goto-char (point-min)) | |
125 (if (and | |
126 (prog1 | |
6828
cccf812ed4f2
(makeinfo-region): Fix name of tex-start/end-of-header.
Richard M. Stallman <rms@gnu.org>
parents:
4149
diff
changeset
|
127 (search-forward tex-start-of-header search-end t) |
3856 | 128 (beginning-of-line) |
129 ;; Mark beginning of header. | |
130 (setq filename-or-header-beginning (point))) | |
131 (prog1 | |
6828
cccf812ed4f2
(makeinfo-region): Fix name of tex-start/end-of-header.
Richard M. Stallman <rms@gnu.org>
parents:
4149
diff
changeset
|
132 (search-forward tex-end-of-header nil t) |
3856 | 133 (beginning-of-line) |
134 ;; Mark end of header | |
135 (setq filename-or-header-end (point)))) | |
136 | |
137 ;; Insert the header into the temporary file. | |
138 (write-region | |
139 (min filename-or-header-beginning region-beginning) | |
140 filename-or-header-end | |
141 makeinfo-temp-file nil nil) | |
142 | |
143 ;; Else no header; insert @filename line into temporary file. | |
144 (goto-char (point-min)) | |
145 (search-forward "@setfilename" search-end t) | |
146 (beginning-of-line) | |
147 (setq filename-or-header-beginning (point)) | |
148 (forward-line 1) | |
149 (setq filename-or-header-end (point)) | |
150 (write-region | |
151 (min filename-or-header-beginning region-beginning) | |
152 filename-or-header-end | |
153 makeinfo-temp-file nil nil)) | |
154 | |
155 ;; Insert the region into the file. | |
156 (write-region | |
157 (max region-beginning filename-or-header-end) | |
158 region-end | |
159 makeinfo-temp-file t nil) | |
160 | |
161 ;; Run the `makeinfo-compile' command in the *compilation* buffer | |
162 (save-excursion | |
163 (makeinfo-compile | |
164 (concat makeinfo-run-command | |
165 " " | |
166 makeinfo-options | |
167 " " | |
168 makeinfo-temp-file) | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
169 "Use `makeinfo-buffer' to gain use of the `next-error' command" |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
170 nil))))))) |
3856 | 171 |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
172 ;;; Actually run makeinfo. COMMAND is the command to run. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
173 ;;; ERROR-MESSAGE is what to say when next-error can't find another error. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
174 ;;; If PARSE-ERRORS is non-nil, do try to parse error messages. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
175 (defun makeinfo-compile (command error-message parse-errors) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
176 (let ((buffer |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
177 (compile-internal command error-message nil |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
178 (and (not parse-errors) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
179 ;; If we do want to parse errors, pass nil. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
180 ;; Otherwise, use this function, which won't |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
181 ;; ever find any errors. |
29591
b70f4500968f
(makeinfo-compile): Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26039
diff
changeset
|
182 (lambda (&rest ignore) |
b70f4500968f
(makeinfo-compile): Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26039
diff
changeset
|
183 (setq compilation-error-list nil)))))) |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
184 (set-process-sentinel (get-buffer-process buffer) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
185 'makeinfo-compilation-sentinel))) |
3856 | 186 |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
187 ;; Delete makeinfo-temp-file after processing is finished, |
3856 | 188 ;; and visit Info file. |
189 ;; This function is called when the compilation process changes state. | |
190 ;; Based on `compilation-sentinel' in compile.el | |
191 (defun makeinfo-compilation-sentinel (proc msg) | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
192 (compilation-sentinel proc msg) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
193 (if (and makeinfo-temp-file (file-exists-p makeinfo-temp-file)) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
194 (delete-file makeinfo-temp-file)) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
195 ;; Always use the version on disk. |
42429
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
196 (let ((buffer (get-file-buffer makeinfo-output-file-name))) |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
197 (if buffer |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
198 (with-current-buffer buffer |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
199 (revert-buffer t t)) |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
200 (setq buffer (find-file-noselect makeinfo-output-file-name))) |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
201 (if (window-dedicated-p (selected-window)) |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
202 (switch-to-buffer-other-window buffer) |
3bdd11464124
(makeinfo-compilation-sentinel):
Richard M. Stallman <rms@gnu.org>
parents:
38697
diff
changeset
|
203 (switch-to-buffer buffer))) |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
204 (goto-char (point-min))) |
3856 | 205 |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
206 (defun makeinfo-buffer () |
3856 | 207 "Make Info file from current buffer. |
208 | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
209 Use the \\[next-error] command to move to the next error |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
210 \(if there are errors\)." |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
211 |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
212 (interactive) |
3856 | 213 (cond ((null buffer-file-name) |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
214 (error "Buffer not visiting any file")) |
3856 | 215 ((buffer-modified-p) |
216 (if (y-or-n-p "Buffer modified; do you want to save it? ") | |
217 (save-buffer)))) | |
218 | |
219 ;; Find and record the Info filename, | |
220 ;; or else explain that a filename is needed. | |
221 (save-excursion | |
222 (goto-char (point-min)) | |
223 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
224 (if (re-search-forward | |
225 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
226 search-end t) | |
227 (setq makeinfo-output-file-name | |
228 (buffer-substring (match-beginning 1) (match-end 1))) | |
229 (error | |
230 "The texinfo file needs a line saying: @setfilename <name>")))) | |
231 | |
232 (save-excursion | |
233 (makeinfo-compile | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
234 (concat makeinfo-run-command " " makeinfo-options |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
235 " " buffer-file-name) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
236 "No more errors." |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
237 t))) |
3856 | 238 |
239 (defun makeinfo-recenter-compilation-buffer (linenum) | |
240 "Redisplay `*compilation*' buffer so most recent output can be seen. | |
241 The last line of the buffer is displayed on | |
242 line LINE of the window, or centered if LINE is nil." | |
243 (interactive "P") | |
244 (let ((makeinfo-buffer (get-buffer "*compilation*")) | |
245 (old-buffer (current-buffer))) | |
246 (if (null makeinfo-buffer) | |
247 (message "No *compilation* buffer") | |
248 (pop-to-buffer makeinfo-buffer) | |
249 (bury-buffer makeinfo-buffer) | |
250 (goto-char (point-max)) | |
251 (recenter (if linenum | |
252 (prefix-numeric-value linenum) | |
253 (/ (window-height) 2))) | |
254 (pop-to-buffer old-buffer) | |
255 ))) | |
256 | |
257 ;;; Place `provide' at end of file. | |
258 (provide 'makeinfo) | |
259 | |
260 ;;; makeinfo.el ends here |