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