Mercurial > emacs
annotate lisp/textmodes/makeinfo.el @ 13620:e5b36a1526dd
(Info-directory-list): Use source-directory.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 21 Nov 1995 21:11:16 +0000 |
parents | 84acc3adcd63 |
children | 83f275dcd93a |
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 | |
3856 | 7 |
13337 | 8 ;; This file is part of GNU Emacs. |
3856 | 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 2, 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 ;;; Commentary: | |
25 | |
26 ;;; The Texinfo mode `makeinfo' related commands are: | |
27 | |
28 ;; makeinfo-region to run makeinfo on the current region. | |
29 ;; makeinfo-buffer to run makeinfo on the current buffer, or | |
30 ;; with optional prefix arg, on current region | |
31 ;; kill-compilation to kill currently running makeinfo job | |
32 ;; makeinfo-recenter-makeinfo-buffer to redisplay *compilation* buffer | |
33 | |
34 ;;; Keybindings (defined in `texinfo.el') | |
35 | |
36 ;; makeinfo bindings | |
37 ; (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region) | |
38 ; (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer) | |
39 ; (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation) | |
40 ; (define-key texinfo-mode-map "\C-c\C-m\C-l" | |
41 ; 'makeinfo-recenter-compilation-buffer) | |
42 | |
43 ;;; Code: | |
44 | |
45 ;;; Variables used by `makeinfo' | |
46 | |
47 (require 'compile) | |
48 | |
49 (defvar makeinfo-run-command "makeinfo" | |
50 "*Command used to run `makeinfo' subjob. | |
51 The name of the file is appended to this string, separated by a space.") | |
52 | |
4117 | 53 (defvar makeinfo-options "--fill-column=70" |
3856 | 54 "*String containing options for running `makeinfo'. |
55 Do not include `--footnote-style' or `--paragraph-indent'; | |
56 the proper way to specify those is with the Texinfo commands | |
57 `@footnotestyle` and `@paragraphindent'.") | |
58 | |
59 (require 'texinfo) | |
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 | |
6828
cccf812ed4f2
(makeinfo-region): Fix name of tex-start/end-of-header.
Richard M. Stallman <rms@gnu.org>
parents:
4149
diff
changeset
|
116 (search-forward tex-start-of-header search-end t) |
3856 | 117 (beginning-of-line) |
118 ;; Mark beginning of header. | |
119 (setq filename-or-header-beginning (point))) | |
120 (prog1 | |
6828
cccf812ed4f2
(makeinfo-region): Fix name of tex-start/end-of-header.
Richard M. Stallman <rms@gnu.org>
parents:
4149
diff
changeset
|
121 (search-forward tex-end-of-header nil t) |
3856 | 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) | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
158 "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
|
159 nil))))))) |
3856 | 160 |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
161 ;;; Actually run makeinfo. COMMAND is the command to run. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
162 ;;; 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
|
163 ;;; 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
|
164 (defun makeinfo-compile (command error-message parse-errors) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
165 (let ((buffer |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
166 (compile-internal command error-message nil |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
167 (and (not parse-errors) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
168 ;; If we do want to parse errors, pass nil. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
169 ;; Otherwise, use this function, which won't |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
170 ;; ever find any errors. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
171 '(lambda (&rest ignore) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
172 (setq compilation-error-list nil)))))) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
173 (set-process-sentinel (get-buffer-process buffer) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
174 'makeinfo-compilation-sentinel))) |
3856 | 175 |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
176 ;; Delete makeinfo-temp-file after processing is finished, |
3856 | 177 ;; and visit Info file. |
178 ;; This function is called when the compilation process changes state. | |
179 ;; Based on `compilation-sentinel' in compile.el | |
180 (defun makeinfo-compilation-sentinel (proc msg) | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
181 (compilation-sentinel proc msg) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
182 (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
|
183 (delete-file makeinfo-temp-file)) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
184 ;; Always use the version on disk. |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
185 (if (get-file-buffer makeinfo-output-file-name) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
186 (progn (set-buffer makeinfo-output-file-name) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
187 (revert-buffer t t)) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
188 (find-file makeinfo-output-file-name)) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
189 (goto-char (point-min))) |
3856 | 190 |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
191 (defun makeinfo-buffer () |
3856 | 192 "Make Info file from current buffer. |
193 | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
194 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
|
195 \(if there are errors\)." |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
196 |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
197 (interactive) |
3856 | 198 (cond ((null buffer-file-name) |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
199 (error "Buffer not visiting any file")) |
3856 | 200 ((buffer-modified-p) |
201 (if (y-or-n-p "Buffer modified; do you want to save it? ") | |
202 (save-buffer)))) | |
203 | |
204 ;; Find and record the Info filename, | |
205 ;; or else explain that a filename is needed. | |
206 (save-excursion | |
207 (goto-char (point-min)) | |
208 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
209 (if (re-search-forward | |
210 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
211 search-end t) | |
212 (setq makeinfo-output-file-name | |
213 (buffer-substring (match-beginning 1) (match-end 1))) | |
214 (error | |
215 "The texinfo file needs a line saying: @setfilename <name>")))) | |
216 | |
217 (save-excursion | |
218 (makeinfo-compile | |
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
219 (concat makeinfo-run-command " " makeinfo-options |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
220 " " buffer-file-name) |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
221 "No more errors." |
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
222 t))) |
3856 | 223 |
224 (defun makeinfo-recenter-compilation-buffer (linenum) | |
225 "Redisplay `*compilation*' buffer so most recent output can be seen. | |
226 The last line of the buffer is displayed on | |
227 line LINE of the window, or centered if LINE is nil." | |
228 (interactive "P") | |
229 (let ((makeinfo-buffer (get-buffer "*compilation*")) | |
230 (old-buffer (current-buffer))) | |
231 (if (null makeinfo-buffer) | |
232 (message "No *compilation* buffer") | |
233 (pop-to-buffer makeinfo-buffer) | |
234 (bury-buffer makeinfo-buffer) | |
235 (goto-char (point-max)) | |
236 (recenter (if linenum | |
237 (prefix-numeric-value linenum) | |
238 (/ (window-height) 2))) | |
239 (pop-to-buffer old-buffer) | |
240 ))) | |
241 | |
242 ;;; Place `provide' at end of file. | |
243 (provide 'makeinfo) | |
244 | |
245 ;;; makeinfo.el ends here | |
246 |