1 ;;; makeinfo.el --- run makeinfo conveniently
3 ;; Copyright (C) 1991, 1993 Free Software Foundation, Inc.
5 ;; Author: Robert J. Chassell
8 ;; This file is part of GNU Emacs.
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)
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.
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.
26 ;;; The Texinfo mode `makeinfo' related commands are:
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
34 ;;; Keybindings (defined in `texinfo.el')
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)
45 ;;; Variables used by `makeinfo'
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.")
53 (defvar makeinfo-options
"--fill-column=70"
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'.")
61 (defvar makeinfo-compilation-process nil
62 "Process that runs `makeinfo'. Should start out nil.")
64 (defvar makeinfo-temp-file nil
65 "Temporary file name used for text being sent as input to `makeinfo'.")
67 (defvar makeinfo-output-file-name nil
68 "Info file name used for text output by `makeinfo'.")
71 ;;; The `makeinfo' function definitions
73 (defun makeinfo-region (region-beginning region-end
)
74 "Make Info file from region of current Texinfo file, and switch to it.
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'."
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'
88 (setq makeinfo-temp-file
91 (substring (buffer-file-name)
93 (or (string-match "\\.tex" (buffer-file-name))
94 (length (buffer-file-name)))))
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]*"
107 (setq makeinfo-output-file-name
108 (buffer-substring (match-beginning 1) (match-end 1)))
110 "The texinfo file needs a line saying: @setfilename <name>"))
112 ;; Find header and specify its beginning and end.
113 (goto-char (point-min))
116 (search-forward tex-start-of-header search-end t
)
118 ;; Mark beginning of header.
119 (setq filename-or-header-beginning
(point)))
121 (search-forward tex-end-of-header nil t
)
123 ;; Mark end of header
124 (setq filename-or-header-end
(point))))
126 ;; Insert the header into the temporary file.
128 (min filename-or-header-beginning region-beginning
)
129 filename-or-header-end
130 makeinfo-temp-file nil nil
)
132 ;; Else no header; insert @filename line into temporary file.
133 (goto-char (point-min))
134 (search-forward "@setfilename" search-end t
)
136 (setq filename-or-header-beginning
(point))
138 (setq filename-or-header-end
(point))
140 (min filename-or-header-beginning region-beginning
)
141 filename-or-header-end
142 makeinfo-temp-file nil nil
))
144 ;; Insert the region into the file.
146 (max region-beginning filename-or-header-end
)
148 makeinfo-temp-file t nil
)
150 ;; Run the `makeinfo-compile' command in the *compilation* buffer
153 (concat makeinfo-run-command
158 "Use `makeinfo-buffer' to gain use of the `next-error' command"
161 ;;; Actually run makeinfo. COMMAND is the command to run.
162 ;;; ERROR-MESSAGE is what to say when next-error can't find another error.
163 ;;; If PARSE-ERRORS is non-nil, do try to parse error messages.
164 (defun makeinfo-compile (command error-message parse-errors
)
166 (compile-internal command error-message nil
167 (and (not parse-errors
)
168 ;; If we do want to parse errors, pass nil.
169 ;; Otherwise, use this function, which won't
170 ;; ever find any errors.
171 '(lambda (&rest ignore
)
172 (setq compilation-error-list nil
))))))
173 (set-process-sentinel (get-buffer-process buffer
)
174 'makeinfo-compilation-sentinel
)))
176 ;; Delete makeinfo-temp-file after processing is finished,
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
)
181 (compilation-sentinel proc msg
)
182 (if (and makeinfo-temp-file
(file-exists-p makeinfo-temp-file
))
183 (delete-file makeinfo-temp-file
))
184 ;; Always use the version on disk.
185 (if (get-file-buffer makeinfo-output-file-name
)
186 (progn (set-buffer makeinfo-output-file-name
)
188 (find-file makeinfo-output-file-name
))
189 (goto-char (point-min)))
191 (defun makeinfo-buffer ()
192 "Make Info file from current buffer.
194 Use the \\[next-error] command to move to the next error
195 \(if there are errors\)."
198 (cond ((null buffer-file-name
)
199 (error "Buffer not visiting any file"))
201 (if (y-or-n-p "Buffer modified; do you want to save it? ")
204 ;; Find and record the Info filename,
205 ;; or else explain that a filename is needed.
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]*"
212 (setq makeinfo-output-file-name
213 (buffer-substring (match-beginning 1) (match-end 1)))
215 "The texinfo file needs a line saying: @setfilename <name>"))))
219 (concat makeinfo-run-command
" " makeinfo-options
220 " " buffer-file-name
)
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."
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
)
242 ;;; Place `provide' at end of file.
245 ;;; makeinfo.el ends here