Mercurial > emacs
annotate lisp/textmodes/makeinfo.el @ 16646:6aeaedabbb62
(Fend_of_line, Fbeginning_of_line): Declared.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 09 Dec 1996 00:51:15 +0000 |
| parents | 83f275dcd93a |
| children | f0ff96a35eb8 |
| 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 | |
| 50 (defvar makeinfo-run-command "makeinfo" | |
| 51 "*Command used to run `makeinfo' subjob. | |
| 52 The name of the file is appended to this string, separated by a space.") | |
| 53 | |
| 4117 | 54 (defvar makeinfo-options "--fill-column=70" |
| 3856 | 55 "*String containing options for running `makeinfo'. |
| 56 Do not include `--footnote-style' or `--paragraph-indent'; | |
| 57 the proper way to specify those is with the Texinfo commands | |
| 58 `@footnotestyle` and `@paragraphindent'.") | |
| 59 | |
| 60 (require 'texinfo) | |
| 61 | |
| 62 (defvar makeinfo-compilation-process nil | |
| 63 "Process that runs `makeinfo'. Should start out nil.") | |
| 64 | |
| 65 (defvar makeinfo-temp-file nil | |
| 66 "Temporary file name used for text being sent as input to `makeinfo'.") | |
| 67 | |
| 68 (defvar makeinfo-output-file-name nil | |
| 69 "Info file name used for text output by `makeinfo'.") | |
| 70 | |
| 71 | |
| 72 ;;; The `makeinfo' function definitions | |
| 73 | |
| 74 (defun makeinfo-region (region-beginning region-end) | |
| 75 "Make Info file from region of current Texinfo file, and switch to it. | |
| 76 | |
| 77 This command does not offer the `next-error' feature since it would | |
| 78 apply to a temporary file, not the original; use the `makeinfo-buffer' | |
| 79 command to gain use of `next-error'." | |
| 80 | |
| 81 (interactive "r") | |
| 82 (let (filename-or-header | |
| 83 filename-or-header-beginning | |
| 84 filename-or-header-end) | |
| 85 ;; Cannot use `let' for makeinfo-temp-file or | |
| 86 ;; makeinfo-output-file-name since `makeinfo-compilation-sentinel' | |
| 87 ;; needs them. | |
| 88 | |
| 89 (setq makeinfo-temp-file | |
| 90 (concat | |
| 91 (make-temp-name | |
| 92 (substring (buffer-file-name) | |
| 93 0 | |
| 94 (or (string-match "\\.tex" (buffer-file-name)) | |
| 95 (length (buffer-file-name))))) | |
| 96 ".texinfo")) | |
| 97 | |
| 98 (save-excursion | |
| 99 (save-restriction | |
| 100 (widen) | |
| 101 (goto-char (point-min)) | |
| 102 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
| 103 ;; Find and record the Info filename, | |
| 104 ;; or else explain that a filename is needed. | |
| 105 (if (re-search-forward | |
| 106 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
| 107 search-end t) | |
| 108 (setq makeinfo-output-file-name | |
| 109 (buffer-substring (match-beginning 1) (match-end 1))) | |
| 110 (error | |
| 111 "The texinfo file needs a line saying: @setfilename <name>")) | |
| 112 | |
| 113 ;; Find header and specify its beginning and end. | |
| 114 (goto-char (point-min)) | |
| 115 (if (and | |
| 116 (prog1 | |
|
6828
cccf812ed4f2
(makeinfo-region): Fix name of tex-start/end-of-header.
Richard M. Stallman <rms@gnu.org>
parents:
4149
diff
changeset
|
117 (search-forward tex-start-of-header search-end t) |
| 3856 | 118 (beginning-of-line) |
| 119 ;; Mark beginning of header. | |
| 120 (setq filename-or-header-beginning (point))) | |
| 121 (prog1 | |
|
6828
cccf812ed4f2
(makeinfo-region): Fix name of tex-start/end-of-header.
Richard M. Stallman <rms@gnu.org>
parents:
4149
diff
changeset
|
122 (search-forward tex-end-of-header nil t) |
| 3856 | 123 (beginning-of-line) |
| 124 ;; Mark end of header | |
| 125 (setq filename-or-header-end (point)))) | |
| 126 | |
| 127 ;; Insert the header into the temporary file. | |
| 128 (write-region | |
| 129 (min filename-or-header-beginning region-beginning) | |
| 130 filename-or-header-end | |
| 131 makeinfo-temp-file nil nil) | |
| 132 | |
| 133 ;; Else no header; insert @filename line into temporary file. | |
| 134 (goto-char (point-min)) | |
| 135 (search-forward "@setfilename" search-end t) | |
| 136 (beginning-of-line) | |
| 137 (setq filename-or-header-beginning (point)) | |
| 138 (forward-line 1) | |
| 139 (setq filename-or-header-end (point)) | |
| 140 (write-region | |
| 141 (min filename-or-header-beginning region-beginning) | |
| 142 filename-or-header-end | |
| 143 makeinfo-temp-file nil nil)) | |
| 144 | |
| 145 ;; Insert the region into the file. | |
| 146 (write-region | |
| 147 (max region-beginning filename-or-header-end) | |
| 148 region-end | |
| 149 makeinfo-temp-file t nil) | |
| 150 | |
| 151 ;; Run the `makeinfo-compile' command in the *compilation* buffer | |
| 152 (save-excursion | |
| 153 (makeinfo-compile | |
| 154 (concat makeinfo-run-command | |
| 155 " " | |
| 156 makeinfo-options | |
| 157 " " | |
| 158 makeinfo-temp-file) | |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
159 "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
|
160 nil))))))) |
| 3856 | 161 |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
162 ;;; Actually run makeinfo. COMMAND is the command to run. |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
163 ;;; 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
|
164 ;;; 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
|
165 (defun makeinfo-compile (command error-message parse-errors) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
166 (let ((buffer |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
167 (compile-internal command error-message nil |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
168 (and (not parse-errors) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
169 ;; If we do want to parse errors, pass nil. |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
170 ;; Otherwise, use this function, which won't |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
171 ;; ever find any errors. |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
172 '(lambda (&rest ignore) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
173 (setq compilation-error-list nil)))))) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
174 (set-process-sentinel (get-buffer-process buffer) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
175 'makeinfo-compilation-sentinel))) |
| 3856 | 176 |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
177 ;; Delete makeinfo-temp-file after processing is finished, |
| 3856 | 178 ;; and visit Info file. |
| 179 ;; This function is called when the compilation process changes state. | |
| 180 ;; Based on `compilation-sentinel' in compile.el | |
| 181 (defun makeinfo-compilation-sentinel (proc msg) | |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
182 (compilation-sentinel proc msg) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
183 (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
|
184 (delete-file makeinfo-temp-file)) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
185 ;; Always use the version on disk. |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
186 (if (get-file-buffer makeinfo-output-file-name) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
187 (progn (set-buffer makeinfo-output-file-name) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
188 (revert-buffer t t)) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
189 (find-file makeinfo-output-file-name)) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
190 (goto-char (point-min))) |
| 3856 | 191 |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
192 (defun makeinfo-buffer () |
| 3856 | 193 "Make Info file from current buffer. |
| 194 | |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
195 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
|
196 \(if there are errors\)." |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
197 |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
198 (interactive) |
| 3856 | 199 (cond ((null buffer-file-name) |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
200 (error "Buffer not visiting any file")) |
| 3856 | 201 ((buffer-modified-p) |
| 202 (if (y-or-n-p "Buffer modified; do you want to save it? ") | |
| 203 (save-buffer)))) | |
| 204 | |
| 205 ;; Find and record the Info filename, | |
| 206 ;; or else explain that a filename is needed. | |
| 207 (save-excursion | |
| 208 (goto-char (point-min)) | |
| 209 (let ((search-end (save-excursion (forward-line 100) (point)))) | |
| 210 (if (re-search-forward | |
| 211 "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | |
| 212 search-end t) | |
| 213 (setq makeinfo-output-file-name | |
| 214 (buffer-substring (match-beginning 1) (match-end 1))) | |
| 215 (error | |
| 216 "The texinfo file needs a line saying: @setfilename <name>")))) | |
| 217 | |
| 218 (save-excursion | |
| 219 (makeinfo-compile | |
|
3857
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
220 (concat makeinfo-run-command " " makeinfo-options |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
221 " " buffer-file-name) |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
222 "No more errors." |
|
ef8b4ed0de91
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
3856
diff
changeset
|
223 t))) |
| 3856 | 224 |
| 225 (defun makeinfo-recenter-compilation-buffer (linenum) | |
| 226 "Redisplay `*compilation*' buffer so most recent output can be seen. | |
| 227 The last line of the buffer is displayed on | |
| 228 line LINE of the window, or centered if LINE is nil." | |
| 229 (interactive "P") | |
| 230 (let ((makeinfo-buffer (get-buffer "*compilation*")) | |
| 231 (old-buffer (current-buffer))) | |
| 232 (if (null makeinfo-buffer) | |
| 233 (message "No *compilation* buffer") | |
| 234 (pop-to-buffer makeinfo-buffer) | |
| 235 (bury-buffer makeinfo-buffer) | |
| 236 (goto-char (point-max)) | |
| 237 (recenter (if linenum | |
| 238 (prefix-numeric-value linenum) | |
| 239 (/ (window-height) 2))) | |
| 240 (pop-to-buffer old-buffer) | |
| 241 ))) | |
| 242 | |
| 243 ;;; Place `provide' at end of file. | |
| 244 (provide 'makeinfo) | |
| 245 | |
| 246 ;;; makeinfo.el ends here | |
| 247 |
