comparison lisp/textmodes/makeinfo.el @ 48934:48b3aae63381

(makeinfo-buffer): Display result using Info-mode. (makeinfo-compilation-sentinel-buffer, makeinfo-current-node): New functions. (makeinfo-compile): Add a sentinel parameter. (makeinfo-compilation-sentinel-region): Renamed from makeinfo-compilation-sentinel, and makeinfo-temp-file now never nil. (makeinfo-region): Use this.
author Richard M. Stallman <rms@gnu.org>
date Sun, 22 Dec 2002 22:05:16 +0000
parents 3bdd11464124
children 5ade352e8d1c
comparison
equal deleted inserted replaced
48933:06dd01f3b917 48934:48b3aae63381
1 ;;; makeinfo.el --- run makeinfo conveniently 1 ;;; makeinfo.el --- run makeinfo conveniently
2 2
3 ;; Copyright (C) 1991, 1993 Free Software Foundation, Inc. 3 ;; Copyright (C) 1991, 1993, 2002 Free Software Foundation, Inc.
4 4
5 ;; Author: Robert J. Chassell 5 ;; Author: Robert J. Chassell
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: docs convenience 7 ;; Keywords: docs convenience
8 8
45 ;;; Code: 45 ;;; Code:
46 46
47 ;;; Variables used by `makeinfo' 47 ;;; Variables used by `makeinfo'
48 48
49 (require 'compile) 49 (require 'compile)
50 (require 'info)
50 51
51 (defgroup makeinfo nil 52 (defgroup makeinfo nil
52 "Run makeinfo conveniently" 53 "Run makeinfo conveniently"
53 :group 'docs) 54 :group 'docs)
54 55
75 (defvar makeinfo-temp-file nil 76 (defvar makeinfo-temp-file nil
76 "Temporary file name used for text being sent as input to `makeinfo'.") 77 "Temporary file name used for text being sent as input to `makeinfo'.")
77 78
78 (defvar makeinfo-output-file-name nil 79 (defvar makeinfo-output-file-name nil
79 "Info file name used for text output by `makeinfo'.") 80 "Info file name used for text output by `makeinfo'.")
81
82 (defvar makeinfo-output-node-name nil
83 "Node name to visit in output file, for `makeinfo-buffer'.")
80 84
81 85
82 ;;; The `makeinfo' function definitions 86 ;;; The `makeinfo' function definitions
83 87
84 (defun makeinfo-region (region-beginning region-end) 88 (defun makeinfo-region (region-beginning region-end)
165 " " 169 " "
166 makeinfo-options 170 makeinfo-options
167 " " 171 " "
168 makeinfo-temp-file) 172 makeinfo-temp-file)
169 "Use `makeinfo-buffer' to gain use of the `next-error' command" 173 "Use `makeinfo-buffer' to gain use of the `next-error' command"
170 nil))))))) 174 nil
175 'makeinfo-compilation-sentinel-region)))))))
171 176
172 ;;; Actually run makeinfo. COMMAND is the command to run. 177 ;;; Actually run makeinfo. COMMAND is the command to run.
173 ;;; ERROR-MESSAGE is what to say when next-error can't find another error. 178 ;;; ERROR-MESSAGE is what to say when next-error can't find another error.
174 ;;; If PARSE-ERRORS is non-nil, do try to parse error messages. 179 ;;; If PARSE-ERRORS is non-nil, do try to parse error messages.
175 (defun makeinfo-compile (command error-message parse-errors) 180 (defun makeinfo-compile (command error-message parse-errors sentinel)
176 (let ((buffer 181 (let ((buffer
177 (compile-internal command error-message nil 182 (compile-internal command error-message nil
178 (and (not parse-errors) 183 (and (not parse-errors)
179 ;; If we do want to parse errors, pass nil. 184 ;; If we do want to parse errors, pass nil.
180 ;; Otherwise, use this function, which won't 185 ;; Otherwise, use this function, which won't
181 ;; ever find any errors. 186 ;; ever find any errors.
182 (lambda (&rest ignore) 187 (lambda (&rest ignore)
183 (setq compilation-error-list nil)))))) 188 (setq compilation-error-list nil))))))
184 (set-process-sentinel (get-buffer-process buffer) 189 (set-process-sentinel (get-buffer-process buffer) sentinel)))
185 'makeinfo-compilation-sentinel)))
186 190
187 ;; Delete makeinfo-temp-file after processing is finished, 191 ;; Delete makeinfo-temp-file after processing is finished,
188 ;; and visit Info file. 192 ;; and visit Info file.
189 ;; This function is called when the compilation process changes state. 193 ;; This function is called when the compilation process changes state.
190 ;; Based on `compilation-sentinel' in compile.el 194 ;; Based on `compilation-sentinel' in compile.el
191 (defun makeinfo-compilation-sentinel (proc msg) 195 (defun makeinfo-compilation-sentinel-region (proc msg)
196 "Sentinel for `makeinfo-compile' run from `makeinfo-region'."
192 (compilation-sentinel proc msg) 197 (compilation-sentinel proc msg)
193 (if (and makeinfo-temp-file (file-exists-p makeinfo-temp-file)) 198 (when (memq (process-status proc) '(signal exit))
194 (delete-file makeinfo-temp-file)) 199 (if (file-exists-p makeinfo-temp-file)
195 ;; Always use the version on disk. 200 (delete-file makeinfo-temp-file))
196 (let ((buffer (get-file-buffer makeinfo-output-file-name))) 201 ;; Always use the version on disk.
197 (if buffer 202 (let ((buffer (get-file-buffer makeinfo-output-file-name)))
198 (with-current-buffer buffer 203 (if buffer
199 (revert-buffer t t)) 204 (with-current-buffer buffer
200 (setq buffer (find-file-noselect makeinfo-output-file-name))) 205 (revert-buffer t t))
201 (if (window-dedicated-p (selected-window)) 206 (setq buffer (find-file-noselect makeinfo-output-file-name)))
202 (switch-to-buffer-other-window buffer) 207 (if (window-dedicated-p (selected-window))
203 (switch-to-buffer buffer))) 208 (switch-to-buffer-other-window buffer)
204 (goto-char (point-min))) 209 (switch-to-buffer buffer)))
210 (goto-char (point-min))))
211
212 (defun makeinfo-current-node ()
213 "Return the name of the node containing point, in a texinfo file."
214 (save-excursion
215 (end-of-line) ; in case point is at the start of an @node line
216 (if (re-search-backward "^@node\\s-+\\([^,\n]+\\)" (point-min) t)
217 (match-string 1)
218 "Top")))
205 219
206 (defun makeinfo-buffer () 220 (defun makeinfo-buffer ()
207 "Make Info file from current buffer. 221 "Make Info file from current buffer.
208 222
209 Use the \\[next-error] command to move to the next error 223 Use the \\[next-error] command to move to the next error
223 (let ((search-end (save-excursion (forward-line 100) (point)))) 237 (let ((search-end (save-excursion (forward-line 100) (point))))
224 (if (re-search-forward 238 (if (re-search-forward
225 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" 239 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*"
226 search-end t) 240 search-end t)
227 (setq makeinfo-output-file-name 241 (setq makeinfo-output-file-name
228 (buffer-substring (match-beginning 1) (match-end 1))) 242 (expand-file-name
243 (buffer-substring (match-beginning 1) (match-end 1))))
229 (error 244 (error
230 "The texinfo file needs a line saying: @setfilename <name>")))) 245 "The texinfo file needs a line saying: @setfilename <name>"))))
246 (setq makeinfo-output-node-name (makeinfo-current-node))
231 247
232 (save-excursion 248 (save-excursion
233 (makeinfo-compile 249 (makeinfo-compile
234 (concat makeinfo-run-command " " makeinfo-options 250 (concat makeinfo-run-command " " makeinfo-options
235 " " buffer-file-name) 251 " " buffer-file-name)
236 "No more errors." 252 "No more errors."
237 t))) 253 t
254 'makeinfo-compilation-sentinel-buffer)))
255
256 (defun makeinfo-compilation-sentinel-buffer (proc msg)
257 "Sentinel for `makeinfo-compile' run from `makeinfo-buffer'."
258 (compilation-sentinel proc msg)
259 (when (memq (process-status proc) '(signal exit))
260 (when (file-exists-p makeinfo-output-file-name)
261 (Info-revert-find-node
262 makeinfo-output-file-name makeinfo-output-node-name))))
238 263
239 (defun makeinfo-recenter-compilation-buffer (linenum) 264 (defun makeinfo-recenter-compilation-buffer (linenum)
240 "Redisplay `*compilation*' buffer so most recent output can be seen. 265 "Redisplay `*compilation*' buffer so most recent output can be seen.
241 The last line of the buffer is displayed on 266 The last line of the buffer is displayed on
242 line LINE of the window, or centered if LINE is nil." 267 line LINE of the window, or centered if LINE is nil."