Mercurial > emacs
comparison lisp/textmodes/makeinfo.el @ 3856:7f0b238b15a1
Initial revision
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 21 Jun 1993 06:45:33 +0000 |
parents | |
children | ef8b4ed0de91 |
comparison
equal
deleted
inserted
replaced
3855:7e33c0f86cb6 | 3856:7f0b238b15a1 |
---|---|
1 ;;;; makeinfo.el -- run makeinfo conveniently. | |
2 ;;; Copyright (C) 1991, 1993 Free Software Foundation, Inc. | |
3 | |
4 ;;; Author: Robert J. Chassell | |
5 ;;; Maintainer: FSF | |
6 | |
7 ;;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;;; The Texinfo mode `makeinfo' related commands are: | |
26 | |
27 ;; makeinfo-region to run makeinfo on the current region. | |
28 ;; makeinfo-buffer to run makeinfo on the current buffer, or | |
29 ;; with optional prefix arg, on current region | |
30 ;; kill-compilation to kill currently running makeinfo job | |
31 ;; makeinfo-recenter-makeinfo-buffer to redisplay *compilation* buffer | |
32 | |
33 ;;; Keybindings (defined in `texinfo.el') | |
34 | |
35 ;; makeinfo bindings | |
36 ; (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region) | |
37 ; (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer) | |
38 ; (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation) | |
39 ; (define-key texinfo-mode-map "\C-c\C-m\C-l" | |
40 ; 'makeinfo-recenter-compilation-buffer) | |
41 | |
42 ;;; Code: | |
43 | |
44 ;;; Variables used by `makeinfo' | |
45 | |
46 (require 'compile) | |
47 | |
48 (defvar makeinfo-run-command "makeinfo" | |
49 "*Command used to run `makeinfo' subjob. | |
50 The name of the file is appended to this string, separated by a space.") | |
51 | |
52 (defvar makeinfo-options "+fill-column=70" | |
53 "*String containing options for running `makeinfo'. | |
54 Do not include `--footnote-style' or `--paragraph-indent'; | |
55 the proper way to specify those is with the Texinfo commands | |
56 `@footnotestyle` and `@paragraphindent'.") | |
57 | |
58 (require 'texinfo) | |
59 (require 'texinfmt) | |
60 | |
61 (defvar makeinfo-compilation-process nil | |
62 "Process that runs `makeinfo'. Should start out nil.") | |
63 | |
64 (defvar makeinfo-temp-file nil | |
65 "Temporary file name used for text being sent as input to `makeinfo'.") | |
66 | |
67 (defvar makeinfo-output-file-name nil | |
68 "Info file name used for text output by `makeinfo'.") | |
69 | |
70 | |
71 ;;; The `makeinfo' function definitions | |
72 | |
73 (defun makeinfo-region (region-beginning region-end) | |
74 "Make Info file from region of current Texinfo file, and switch to it. | |
75 | |
76 This command does not offer the `next-error' feature since it would | |
77 apply to a temporary file, not the original; use the `makeinfo-buffer' | |
78 command to gain use of `next-error'." | |
79 | |
80 (interactive "r") | |
81 (let (filename-or-header | |
82 filename-or-header-beginning | |
83 filename-or-header-end) | |
84 ;; Cannot use `let' for makeinfo-temp-file or | |
85 ;; makeinfo-output-file-name since `makeinfo-compilation-sentinel' | |
86 ;; needs them. | |
87 | |
88 (setq makeinfo-temp-file | |
89 (concat | |
90 (make-temp-name | |
91 (substring (buffer-file-name) | |
92 0 | |
93 (or (string-match "\\.tex" (buffer-file-name)) | |
94 (length (buffer-file-name))))) | |
95 ".texinfo")) | |
96 | |
97 (save-excursion | |
98 (save-restriction | |
99 (widen) | |
100 (goto-char (point-min)) | |
101 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
102 ;; Find and record the Info filename, | |
103 ;; or else explain that a filename is needed. | |
104 (if (re-search-forward | |
105 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
106 search-end t) | |
107 (setq makeinfo-output-file-name | |
108 (buffer-substring (match-beginning 1) (match-end 1))) | |
109 (error | |
110 "The texinfo file needs a line saying: @setfilename <name>")) | |
111 | |
112 ;; Find header and specify its beginning and end. | |
113 (goto-char (point-min)) | |
114 (if (and | |
115 (prog1 | |
116 (search-forward texinfo-start-of-header search-end t) | |
117 (beginning-of-line) | |
118 ;; Mark beginning of header. | |
119 (setq filename-or-header-beginning (point))) | |
120 (prog1 | |
121 (search-forward texinfo-end-of-header nil t) | |
122 (beginning-of-line) | |
123 ;; Mark end of header | |
124 (setq filename-or-header-end (point)))) | |
125 | |
126 ;; Insert the header into the temporary file. | |
127 (write-region | |
128 (min filename-or-header-beginning region-beginning) | |
129 filename-or-header-end | |
130 makeinfo-temp-file nil nil) | |
131 | |
132 ;; Else no header; insert @filename line into temporary file. | |
133 (goto-char (point-min)) | |
134 (search-forward "@setfilename" search-end t) | |
135 (beginning-of-line) | |
136 (setq filename-or-header-beginning (point)) | |
137 (forward-line 1) | |
138 (setq filename-or-header-end (point)) | |
139 (write-region | |
140 (min filename-or-header-beginning region-beginning) | |
141 filename-or-header-end | |
142 makeinfo-temp-file nil nil)) | |
143 | |
144 ;; Insert the region into the file. | |
145 (write-region | |
146 (max region-beginning filename-or-header-end) | |
147 region-end | |
148 makeinfo-temp-file t nil) | |
149 | |
150 ;; Run the `makeinfo-compile' command in the *compilation* buffer | |
151 (save-excursion | |
152 (makeinfo-compile | |
153 (concat makeinfo-run-command | |
154 " " | |
155 makeinfo-options | |
156 " " | |
157 makeinfo-temp-file) | |
158 "Use `makeinfo-buffer' to gain use of the `next-error' command."))))))) | |
159 | |
160 ;; Based on `compile1' in compile.el; changed so to make it possible | |
161 ;; to delete temporary file. | |
162 (defun makeinfo-compile (command error-message &optional name-of-mode) | |
163 ;(save-some-buffers) ; Don't need to save other buffers. | |
164 (if makeinfo-compilation-process | |
165 (if (or (not (eq (process-status makeinfo-compilation-process) 'run)) | |
166 (yes-or-no-p | |
167 "A `makeinfo' compilation process is running; kill it? ")) | |
168 (condition-case () | |
169 (let ((comp-proc makeinfo-compilation-process)) | |
170 (interrupt-process comp-proc) | |
171 (sit-for 1) | |
172 (delete-process comp-proc)) | |
173 (error nil)) | |
174 (error "Cannot have two makeinfo processes"))) | |
175 (setq makeinfo-compilation-process nil) | |
176 (compilation-forget-errors) | |
177 (setq compilation-error-list t) | |
178 (setq compilation-error-message error-message) | |
179 (setq makeinfo-compilation-process | |
180 (start-process "makeinfo" "*compilation*" | |
181 shell-file-name | |
182 "-c" (concat "exec " command))) | |
183 (with-output-to-temp-buffer "*compilation*" | |
184 (princ "cd ") | |
185 (princ default-directory) | |
186 (terpri) | |
187 (princ command) | |
188 (terpri)) | |
189 (let ((regexp compilation-error-regexp)) | |
190 (save-excursion | |
191 (set-buffer "*compilation*") | |
192 (make-local-variable 'compilation-error-regexp) | |
193 (setq compilation-error-regexp regexp))) | |
194 (set-process-sentinel | |
195 makeinfo-compilation-process 'makeinfo-compilation-sentinel) | |
196 (let* ((thisdir default-directory) | |
197 (outbuf (process-buffer makeinfo-compilation-process)) | |
198 (outwin (get-buffer-window outbuf))) | |
199 (if (eq outbuf (current-buffer)) | |
200 (goto-char (point-max))) | |
201 (save-excursion | |
202 (set-buffer outbuf) | |
203 (buffer-flush-undo outbuf) | |
204 (let ((start (save-excursion (set-buffer outbuf) (point-min)))) | |
205 (set-window-start outwin start) | |
206 (or (eq outwin (selected-window)) | |
207 (set-window-point outwin start))) | |
208 (setq default-directory thisdir) | |
209 (fundamental-mode) | |
210 (setq mode-name (or name-of-mode "compilation")) | |
211 ;; Make log buffer's mode line show process state | |
212 (setq mode-line-process '(": %s"))))) | |
213 | |
214 ;; Delete makeinfo-temp-file after proccessing is finished, | |
215 ;; and visit Info file. | |
216 ;; This function is called when the compilation process changes state. | |
217 ;; Based on `compilation-sentinel' in compile.el | |
218 (defun makeinfo-compilation-sentinel (proc msg) | |
219 (cond ((null (buffer-name (process-buffer proc))) | |
220 ;; buffer killed | |
221 (set-process-buffer proc nil)) | |
222 ((memq (process-status proc) '(signal exit)) | |
223 (let* ((obuf (current-buffer)) | |
224 omax opoint) | |
225 ;; save-excursion isn't the right thing if | |
226 ;; process-buffer is current-buffer | |
227 (unwind-protect | |
228 (progn | |
229 ;; Write something in *compilation* and hack | |
230 ;; its mode line, | |
231 (set-buffer (process-buffer proc)) | |
232 (setq omax (point-max) opoint (point)) | |
233 (goto-char (point-max)) | |
234 (insert ?\n mode-name " " msg) | |
235 (forward-char -1) | |
236 (insert " at " | |
237 (substring (current-time-string) 0 -5)) | |
238 (forward-char 1) | |
239 (setq mode-line-process | |
240 (concat ": " | |
241 (symbol-name (process-status proc)))) | |
242 ;; If buffer and mode line will show that the process | |
243 ;; is dead, we can delete it now. Otherwise it | |
244 ;; will stay around until M-x list-processes. | |
245 (delete-process proc)) | |
246 (setq makeinfo-compilation-process nil) | |
247 ;; Force mode line redisplay soon | |
248 (set-buffer-modified-p (buffer-modified-p))) | |
249 (if (and opoint (< opoint omax)) | |
250 (goto-char opoint)) | |
251 (set-buffer obuf)) | |
252 (if (and makeinfo-temp-file (file-exists-p makeinfo-temp-file)) | |
253 (delete-file makeinfo-temp-file)) | |
254 ;; Always use the version on disk. | |
255 (if (get-file-buffer makeinfo-output-file-name) | |
256 (progn (set-buffer makeinfo-output-file-name) | |
257 (revert-buffer t t))) | |
258 (find-file makeinfo-output-file-name) | |
259 (goto-char (point-min))))) | |
260 | |
261 (defun makeinfo-buffer (buffer) | |
262 "Make Info file from current buffer. | |
263 | |
264 The \\[next-error] command can be used to move to the next error | |
265 \(if any are found\)." | |
266 | |
267 (interactive "bRun `makeinfo' on: ") | |
268 (cond ((null buffer-file-name) | |
269 (error "Buffer not visiting any file!")) | |
270 ((buffer-modified-p) | |
271 (if (y-or-n-p "Buffer modified; do you want to save it? ") | |
272 (save-buffer)))) | |
273 | |
274 ;; Find and record the Info filename, | |
275 ;; or else explain that a filename is needed. | |
276 (save-excursion | |
277 (goto-char (point-min)) | |
278 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
279 (if (re-search-forward | |
280 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
281 search-end t) | |
282 (setq makeinfo-output-file-name | |
283 (buffer-substring (match-beginning 1) (match-end 1))) | |
284 (error | |
285 "The texinfo file needs a line saying: @setfilename <name>")))) | |
286 | |
287 (save-excursion | |
288 (makeinfo-compile | |
289 (concat makeinfo-run-command | |
290 " " | |
291 makeinfo-options | |
292 " " | |
293 "+footnote-style=" | |
294 texinfo-footnote-style | |
295 " " | |
296 (buffer-file-name | |
297 (get-buffer buffer))) | |
298 "No more errors."))) | |
299 | |
300 (defun makeinfo-recenter-compilation-buffer (linenum) | |
301 "Redisplay `*compilation*' buffer so most recent output can be seen. | |
302 The last line of the buffer is displayed on | |
303 line LINE of the window, or centered if LINE is nil." | |
304 (interactive "P") | |
305 (let ((makeinfo-buffer (get-buffer "*compilation*")) | |
306 (old-buffer (current-buffer))) | |
307 (if (null makeinfo-buffer) | |
308 (message "No *compilation* buffer") | |
309 (pop-to-buffer makeinfo-buffer) | |
310 (bury-buffer makeinfo-buffer) | |
311 (goto-char (point-max)) | |
312 (recenter (if linenum | |
313 (prefix-numeric-value linenum) | |
314 (/ (window-height) 2))) | |
315 (pop-to-buffer old-buffer) | |
316 ))) | |
317 | |
318 | |
319 ;;; Place `provide' at end of file. | |
320 (provide 'makeinfo) | |
321 | |
322 ;;; makeinfo.el ends here | |
323 |