2
|
1 ;;; makeinfo.el --- run makeinfo conveniently
|
|
2
|
|
3 ;; Copyright (C) 1991, 1993 Free Software Foundation, Inc.
|
0
|
4
|
2
|
5 ;; Author: Robert J. Chassell
|
|
6 ;; Maintainer: FSF
|
0
|
7
|
2
|
8 ;; This file is part of XEmacs.
|
0
|
9
|
2
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
0
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
2
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
0
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
2
|
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.
|
0
|
24
|
2
|
25 ;;; Synched up with: FSF 19.34.
|
0
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;;; The Texinfo mode `makeinfo' related commands are:
|
|
30
|
|
31 ;; makeinfo-region to run makeinfo on the current region.
|
|
32 ;; makeinfo-buffer to run makeinfo on the current buffer, or
|
|
33 ;; with optional prefix arg, on current region
|
|
34 ;; kill-compilation to kill currently running makeinfo job
|
|
35 ;; makeinfo-recenter-makeinfo-buffer to redisplay *compilation* buffer
|
|
36
|
|
37 ;;; Keybindings (defined in `texinfo.el')
|
|
38
|
|
39 ;; makeinfo bindings
|
|
40 ; (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
|
|
41 ; (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
|
|
42 ; (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
|
|
43 ; (define-key texinfo-mode-map "\C-c\C-m\C-l"
|
|
44 ; 'makeinfo-recenter-compilation-buffer)
|
|
45
|
|
46 ;;; Code:
|
|
47
|
|
48 ;;; Variables used by `makeinfo'
|
|
49
|
|
50 (require 'compile)
|
|
51
|
|
52 (defvar makeinfo-run-command "makeinfo"
|
|
53 "*Command used to run `makeinfo' subjob.
|
|
54 The name of the file is appended to this string, separated by a space.")
|
|
55
|
|
56 (defvar makeinfo-options "--fill-column=70"
|
|
57 "*String containing options for running `makeinfo'.
|
|
58 Do not include `--footnote-style' or `--paragraph-indent';
|
|
59 the proper way to specify those is with the Texinfo commands
|
|
60 `@footnotestyle` and `@paragraphindent'.")
|
|
61
|
|
62 (require 'texinfo)
|
|
63
|
|
64 (defvar makeinfo-compilation-process nil
|
|
65 "Process that runs `makeinfo'. Should start out nil.")
|
|
66
|
|
67 (defvar makeinfo-temp-file nil
|
|
68 "Temporary file name used for text being sent as input to `makeinfo'.")
|
|
69
|
|
70 (defvar makeinfo-output-file-name nil
|
|
71 "Info file name used for text output by `makeinfo'.")
|
|
72
|
|
73
|
|
74 ;;; The `makeinfo' function definitions
|
|
75
|
|
76 (defun makeinfo-region (region-beginning region-end)
|
|
77 "Make Info file from region of current Texinfo file, and switch to it.
|
|
78
|
|
79 This command does not offer the `next-error' feature since it would
|
|
80 apply to a temporary file, not the original; use the `makeinfo-buffer'
|
|
81 command to gain use of `next-error'."
|
|
82
|
|
83 (interactive "r")
|
|
84 (let (filename-or-header
|
|
85 filename-or-header-beginning
|
|
86 filename-or-header-end)
|
|
87 ;; Cannot use `let' for makeinfo-temp-file or
|
|
88 ;; makeinfo-output-file-name since `makeinfo-compilation-sentinel'
|
|
89 ;; needs them.
|
|
90
|
|
91 (setq makeinfo-temp-file
|
|
92 (concat
|
|
93 (make-temp-name
|
|
94 (substring (buffer-file-name)
|
|
95 0
|
|
96 (or (string-match "\\.tex" (buffer-file-name))
|
|
97 (length (buffer-file-name)))))
|
|
98 ".texinfo"))
|
|
99
|
|
100 (save-excursion
|
|
101 (save-restriction
|
|
102 (widen)
|
|
103 (goto-char (point-min))
|
|
104 (let ((search-end (save-excursion (forward-line 100) (point))))
|
|
105 ;; Find and record the Info filename,
|
|
106 ;; or else explain that a filename is needed.
|
|
107 (if (re-search-forward
|
|
108 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*"
|
|
109 search-end t)
|
|
110 (setq makeinfo-output-file-name
|
|
111 (buffer-substring (match-beginning 1) (match-end 1)))
|
|
112 (error
|
|
113 "The texinfo file needs a line saying: @setfilename <name>"))
|
|
114
|
|
115 ;; Find header and specify its beginning and end.
|
|
116 (goto-char (point-min))
|
|
117 (if (and
|
|
118 (prog1
|
|
119 (search-forward tex-start-of-header search-end t)
|
|
120 (beginning-of-line)
|
|
121 ;; Mark beginning of header.
|
|
122 (setq filename-or-header-beginning (point)))
|
|
123 (prog1
|
|
124 (search-forward tex-end-of-header nil t)
|
|
125 (beginning-of-line)
|
|
126 ;; Mark end of header
|
|
127 (setq filename-or-header-end (point))))
|
|
128
|
|
129 ;; Insert the header into the temporary file.
|
|
130 (write-region
|
|
131 (min filename-or-header-beginning region-beginning)
|
|
132 filename-or-header-end
|
|
133 makeinfo-temp-file nil nil)
|
|
134
|
|
135 ;; Else no header; insert @filename line into temporary file.
|
|
136 (goto-char (point-min))
|
|
137 (search-forward "@setfilename" search-end t)
|
|
138 (beginning-of-line)
|
|
139 (setq filename-or-header-beginning (point))
|
|
140 (forward-line 1)
|
|
141 (setq filename-or-header-end (point))
|
|
142 (write-region
|
|
143 (min filename-or-header-beginning region-beginning)
|
|
144 filename-or-header-end
|
|
145 makeinfo-temp-file nil nil))
|
|
146
|
|
147 ;; Insert the region into the file.
|
|
148 (write-region
|
|
149 (max region-beginning filename-or-header-end)
|
|
150 region-end
|
|
151 makeinfo-temp-file t nil)
|
|
152
|
|
153 ;; Run the `makeinfo-compile' command in the *compilation* buffer
|
|
154 (save-excursion
|
|
155 (makeinfo-compile
|
|
156 (concat makeinfo-run-command
|
|
157 " "
|
|
158 makeinfo-options
|
|
159 " "
|
|
160 makeinfo-temp-file)
|
|
161 "Use `makeinfo-buffer' to gain use of the `next-error' command"
|
|
162 nil)))))))
|
|
163
|
|
164 ;;; Actually run makeinfo. COMMAND is the command to run.
|
|
165 ;;; ERROR-MESSAGE is what to say when next-error can't find another error.
|
|
166 ;;; If PARSE-ERRORS is non-nil, do try to parse error messages.
|
|
167 (defun makeinfo-compile (command error-message parse-errors)
|
|
168 (let ((buffer
|
|
169 (compile-internal command error-message nil
|
|
170 (and (not parse-errors)
|
|
171 ;; If we do want to parse errors, pass nil.
|
|
172 ;; Otherwise, use this function, which won't
|
|
173 ;; ever find any errors.
|
|
174 '(lambda (&rest ignore)
|
|
175 (setq compilation-error-list nil))))))
|
|
176 (set-process-sentinel (get-buffer-process buffer)
|
|
177 'makeinfo-compilation-sentinel)))
|
|
178
|
|
179 ;; Delete makeinfo-temp-file after processing is finished,
|
|
180 ;; and visit Info file.
|
|
181 ;; This function is called when the compilation process changes state.
|
|
182 ;; Based on `compilation-sentinel' in compile.el
|
|
183 (defun makeinfo-compilation-sentinel (proc msg)
|
|
184 (compilation-sentinel proc msg)
|
|
185 (if (and makeinfo-temp-file (file-exists-p makeinfo-temp-file))
|
|
186 (delete-file makeinfo-temp-file))
|
|
187 ;; Always use the version on disk.
|
|
188 (if (get-file-buffer makeinfo-output-file-name)
|
|
189 (progn (set-buffer makeinfo-output-file-name)
|
|
190 (revert-buffer t t))
|
|
191 (find-file makeinfo-output-file-name))
|
|
192 (goto-char (point-min)))
|
|
193
|
|
194 (defun makeinfo-buffer ()
|
|
195 "Make Info file from current buffer.
|
|
196
|
|
197 Use the \\[next-error] command to move to the next error
|
|
198 \(if there are errors\)."
|
|
199
|
|
200 (interactive)
|
|
201 (cond ((null buffer-file-name)
|
|
202 (error "Buffer not visiting any file"))
|
|
203 ((buffer-modified-p)
|
|
204 (if (y-or-n-p "Buffer modified; do you want to save it? ")
|
|
205 (save-buffer))))
|
|
206
|
|
207 ;; Find and record the Info filename,
|
|
208 ;; or else explain that a filename is needed.
|
|
209 (save-excursion
|
|
210 (goto-char (point-min))
|
|
211 (let ((search-end (save-excursion (forward-line 100) (point))))
|
|
212 (if (re-search-forward
|
|
213 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*"
|
|
214 search-end t)
|
|
215 (setq makeinfo-output-file-name
|
|
216 (buffer-substring (match-beginning 1) (match-end 1)))
|
|
217 (error
|
|
218 "The texinfo file needs a line saying: @setfilename <name>"))))
|
|
219
|
|
220 (save-excursion
|
|
221 (makeinfo-compile
|
|
222 (concat makeinfo-run-command " " makeinfo-options
|
|
223 " " buffer-file-name)
|
|
224 "No more errors."
|
|
225 t)))
|
|
226
|
|
227 (defun makeinfo-recenter-compilation-buffer (linenum)
|
|
228 "Redisplay `*compilation*' buffer so most recent output can be seen.
|
|
229 The last line of the buffer is displayed on
|
|
230 line LINE of the window, or centered if LINE is nil."
|
|
231 (interactive "P")
|
|
232 (let ((makeinfo-buffer (get-buffer "*compilation*"))
|
|
233 (old-buffer (current-buffer)))
|
|
234 (if (null makeinfo-buffer)
|
|
235 (message "No *compilation* buffer")
|
|
236 (pop-to-buffer makeinfo-buffer)
|
|
237 (bury-buffer makeinfo-buffer)
|
|
238 (goto-char (point-max))
|
|
239 (recenter (if linenum
|
|
240 (prefix-numeric-value linenum)
|
|
241 (/ (window-height) 2)))
|
|
242 (pop-to-buffer old-buffer)
|
|
243 )))
|
|
244
|
|
245 ;;; Place `provide' at end of file.
|
|
246 (provide 'makeinfo)
|
|
247
|
|
248 ;;; makeinfo.el ends here
|
|
249
|