Mercurial > hg > xemacs-beta
comparison lisp/packages/texnfo-tex.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 0293115a14e9 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;;; texnfo-tex.el | |
2 | |
3 ;;; Texinfo mode TeX and hardcopy printing commands. | |
4 | |
5 ;; These commands are for running TeX on a region of a Texinfo file in | |
6 ;; GNU Emacs, or on the whole buffer, and for printing the resulting | |
7 ;; DVI file. | |
8 | |
9 ;;; Version 2.07 22 October 1991 | |
10 ;;; Robert J. Chassell | |
11 ;;; Please send bug reports to: bug-texinfo@prep.ai.mit.edu | |
12 | |
13 ;;; Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc. | |
14 | |
15 | |
16 ;; This file is part of XEmacs. | |
17 | |
18 ;; XEmacs is free software; you can redistribute it and/or modify it | |
19 ;; under the terms of the GNU General Public License as published by | |
20 ;; the Free Software Foundation; either version 2, or (at your option) | |
21 ;; any later version. | |
22 | |
23 ;; XEmacs is distributed in the hope that it will be useful, but | |
24 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 ;; General Public License for more details. | |
27 | |
28 ;; You should have received a copy of the GNU General Public License | |
29 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
30 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
31 | |
32 ;;; Synched up with: Not in FSF. | |
33 | |
34 | |
35 ;;; The Texinfo mode TeX related commands are: | |
36 | |
37 ; texinfo-tex-region to run tex on the current region. | |
38 ; texinfo-tex-buffer to run tex on the current buffer. | |
39 ; texinfo-texindex to sort unsorted index files. | |
40 ; texinfo-tex-print to print the .dvi file made by tex. | |
41 ; texinfo-kill-tex-job to kill the currently running tex job. | |
42 ; texinfo-recenter-tex-output-buffer to redisplay tex output buffer. | |
43 ; texinfo-show-tex-print-queue to show the print queue. | |
44 | |
45 | |
46 ;;; Keys common both to Texinfo mode and to TeX shell. | |
47 | |
48 ;; Defined in `texinfo.el' | |
49 ; (defun texinfo-define-common-keys (keymap) | |
50 ; "Define the keys both in Texinfo mode and in the texinfo-tex-shell." | |
51 ; (define-key keymap "\C-c\C-t\C-k" 'texinfo-kill-tex-job) | |
52 ; (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-tex-job) | |
53 ; (define-key keymap "\C-c\C-t\C-l" 'texinfo-recenter-tex-output-buffer) | |
54 ; (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-tex-print-queue) | |
55 ; (define-key keymap "\C-c\C-t\C-q" 'texinfo-show-tex-print-queue) | |
56 ; (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print) | |
57 ; (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex) | |
58 ; (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region) | |
59 ; (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer)) | |
60 | |
61 ;; See also texinfo-tex-start-shell. | |
62 ;; The following is executed in the `texinfo.el' file | |
63 ;(texinfo-define-common-keys texinfo-mode-map) | |
64 | |
65 | |
66 ;;; Variable definitions: | |
67 | |
68 (require 'shell) | |
69 | |
70 (defvar texinfo-tex-shell-cd-command "cd" | |
71 "Command to give to shell running TeX to change directory.") | |
72 | |
73 (defvar texinfo-tex-command "tex" | |
74 "*Command used by texinfo-tex-region to run tex on a region.") | |
75 | |
76 (defvar texinfo-texindex-command "texindex" | |
77 "*Command used by texinfo-texindex to sort unsorted index files.") | |
78 | |
79 (defvar texinfo-tex-dvi-print-command "lpr -d" | |
80 "*Command string used by \\[tex-print] to print a .dvi file.") | |
81 | |
82 (defvar texinfo-show-tex-queue-command "lpq" | |
83 "*Command string used to show the Texinfo TeX print queue. | |
84 Command is used by \\[texinfo-show-tex-print-queue] and it | |
85 should show the queue that \\[texinfo-tex-print] puts jobs on.") | |
86 | |
87 (defvar texinfo-delete-from-print-queue-command "lprm" | |
88 "*Command string used to delete a job from the line printer queue. | |
89 Command is used by \\[texinfo-delete-from-tex-print-queue] based on | |
90 number provided by a previous \\[texinfo-show-tex-print-queue] | |
91 command.") | |
92 | |
93 (defvar texinfo-tex-trailer "@bye" | |
94 "String appended after a region sent to TeX by texinfo-tex-region.") | |
95 | |
96 (defvar texinfo-tex-original-file "" | |
97 "Original name of file on which to run TeX.") | |
98 | |
99 (defvar texinfo-tex-temp-file nil | |
100 "Temporary file name used for text being sent as input to TeX.") | |
101 | |
102 (defvar texinfo-tex-root-temp-file nil | |
103 "Temporary file name used for text being sent as input to TeX.") | |
104 | |
105 | |
106 ;;; Texinfo TeX main functions | |
107 | |
108 (defun texinfo-tex-region (beginning end) | |
109 "Run tex on the current region. | |
110 | |
111 A temporary file is written in the default directory, and tex is run | |
112 in that directory. The first line of the file is copied to the | |
113 temporary file; and if the buffer has a header, it is written to the | |
114 temporary file before the region itself. The buffer's header is all | |
115 lines between the strings defined by texinfo-start-of-header and | |
116 texinfo-end-of-header inclusive. The header must start in the first 100 | |
117 lines. The value of texinfo-tex-trailer is appended to the temporary file | |
118 after the region." | |
119 | |
120 (interactive "r") | |
121 (if (get-buffer "*texinfo-tex-shell*") | |
122 (quit-process (get-process "texinfo-tex-shell") t) | |
123 (texinfo-tex-start-shell)) | |
124 | |
125 (setq texinfo-tex-root-temp-file | |
126 (expand-file-name | |
127 (make-temp-name | |
128 (prin1-to-string (read (buffer-name)))))) | |
129 | |
130 (let ((texinfo-tex-temp-file (concat texinfo-tex-root-temp-file ".tex"))) | |
131 (save-excursion | |
132 (save-restriction | |
133 (widen) | |
134 (goto-char (point-min)) | |
135 (forward-line 100) | |
136 (let ((search-end (point)) | |
137 (header-beginning (point-min)) (header-end (point-min))) | |
138 (goto-char (point-min)) | |
139 ;; Copy first line, the `\input texinfo' line, to temp file | |
140 (write-region (point) | |
141 (save-excursion (forward-line 1) (point)) | |
142 texinfo-tex-temp-file nil nil) | |
143 ;; Don't copy first line twice if region includes it. | |
144 (forward-line 1) | |
145 (if (< beginning (point)) (setq beginning (point))) | |
146 ;; Initialize the temp file with either the header or nothing | |
147 (if (search-forward texinfo-start-of-header search-end t) | |
148 (progn | |
149 (beginning-of-line) | |
150 (setq header-beginning (point)) ; Mark beginning of header. | |
151 (if (search-forward texinfo-end-of-header nil t) | |
152 (progn (beginning-of-line) | |
153 (setq header-end (point))) ; Mark end of header. | |
154 (setq header-beginning (point-min))))) ; Else no header. | |
155 ;; Copy header to temp file. | |
156 (write-region | |
157 (min header-beginning beginning ) | |
158 header-end | |
159 texinfo-tex-temp-file t nil) | |
160 ;; Copy region to temp file. | |
161 (write-region | |
162 (max beginning header-end) | |
163 end | |
164 texinfo-tex-temp-file t nil) | |
165 ;; This is a kludge to insert the texinfo-tex-trailer into the | |
166 ;; texinfo-tex-temp-file. We have to create a special buffer | |
167 ;; in which to insert the texinfo-tex-trailer first because there is | |
168 ;; no function with which to append a literal string directly | |
169 ;; to a file. | |
170 (let ((local-tex-trailer texinfo-tex-trailer) | |
171 (temp-buffer (get-buffer-create " texinfo-trailer-buffer"))) | |
172 (set-buffer temp-buffer) | |
173 (erase-buffer) | |
174 ;; make sure trailer isn't hidden by a comment | |
175 (insert-string "\n") | |
176 (if local-tex-trailer (insert local-tex-trailer)) | |
177 (write-region (point-min) (point-max) | |
178 texinfo-tex-temp-file t nil))) | |
179 (set-process-sentinel (get-process "texinfo-tex-shell") | |
180 'texinfo-tex-shell-sentinel) | |
181 (send-string "texinfo-tex-shell" | |
182 (concat texinfo-tex-shell-cd-command " " | |
183 default-directory "\n")) | |
184 (send-string "texinfo-tex-shell" | |
185 (concat texinfo-tex-command " " | |
186 texinfo-tex-temp-file "\n ")) | |
187 (texinfo-recenter-tex-output-buffer 0))))) | |
188 | |
189 (defun texinfo-tex-buffer (buffer) | |
190 "Run TeX on current buffer. | |
191 After running TeX the first time, you may have to run \\[texinfo-texindex] | |
192 and then \\[texinfo-tex-buffer] again." | |
193 (interactive | |
194 (list | |
195 ;; Sometimes you put point into *texinfo-tex-shell*; this prompts | |
196 ;; you for the correct file regardless. | |
197 (if (and | |
198 (string= (buffer-name (current-buffer)) "*texinfo-tex-shell*") | |
199 texinfo-tex-root-temp-file) | |
200 (read-string (format "Run TeX on: ") | |
201 texinfo-tex-original-file) | |
202 (read-string (format "Run TeX on: ") (buffer-name (current-buffer)))))) | |
203 | |
204 ;; Set to original buffer if in *texinfo-tex-shell*; otherwise, | |
205 ;; record name of current buffer. | |
206 (if (string= (buffer-name (current-buffer)) "*texinfo-tex-shell*") | |
207 (set-buffer buffer) | |
208 (setq texinfo-tex-original-file | |
209 (buffer-name (current-buffer)))) | |
210 | |
211 (if (get-buffer "*texinfo-tex-shell*") | |
212 (quit-process (get-process "texinfo-tex-shell") t) | |
213 (texinfo-tex-start-shell)) | |
214 (cond ((null buffer-file-name) | |
215 (error "Buffer not visiting any file!")) | |
216 ((buffer-modified-p) | |
217 (error "Buffer has been modified since last saved!")) | |
218 (t (set-process-sentinel (get-process "texinfo-tex-shell") | |
219 'texinfo-tex-shell-sentinel) | |
220 (send-string "texinfo-tex-shell" | |
221 (concat texinfo-tex-shell-cd-command | |
222 " " | |
223 (file-name-directory | |
224 (buffer-file-name | |
225 (get-buffer buffer))) | |
226 "\n")) | |
227 (send-string "texinfo-tex-shell" | |
228 (concat texinfo-tex-command " " buffer "\n ")) | |
229 | |
230 ;; so the texinfo-tex-print command works | |
231 (setq texinfo-tex-root-temp-file | |
232 (substring buffer 0 | |
233 (or (string-match "\\.tex" buffer) | |
234 (length buffer)))) | |
235 | |
236 (texinfo-recenter-tex-output-buffer 0)))) | |
237 | |
238 (defun texinfo-texindex () | |
239 "Run texindex on unsorted index files. | |
240 The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer]. | |
241 Runs the shell command defined by texinfo-texindex-command." | |
242 (interactive) | |
243 (send-string "texinfo-tex-shell" | |
244 (concat texinfo-texindex-command | |
245 " " texinfo-tex-root-temp-file ".??" "\n")) | |
246 (texinfo-recenter-tex-output-buffer nil)) | |
247 | |
248 (defun texinfo-tex-print () | |
249 "Print .dvi file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer]. | |
250 Runs the shell command defined by texinfo-tex-dvi-print-command." | |
251 (interactive) | |
252 (send-string "texinfo-tex-shell" | |
253 (concat texinfo-tex-dvi-print-command | |
254 " " texinfo-tex-root-temp-file ".dvi" "\n")) | |
255 (texinfo-recenter-tex-output-buffer nil)) | |
256 | |
257 | |
258 ;;; Texinfo TeX utility functions | |
259 | |
260 (defun texinfo-tex-start-shell () | |
261 (save-excursion | |
262 (require 'texinfo) | |
263 (set-buffer (if (fboundp 'make-shell) | |
264 (make-shell "texinfo-tex-shell" "/bin/sh" nil "-v") | |
265 (make-comint "texinfo-tex-shell" "/bin/sh" nil "-v"))) | |
266 (setq texinfo-tex-shell-map (copy-keymap shell-mode-map)) | |
267 (texinfo-define-common-keys texinfo-tex-shell-map) | |
268 (use-local-map texinfo-tex-shell-map) | |
269 (run-hooks 'texinfo-tex-shell-hook) | |
270 (if (zerop (buffer-size)) | |
271 (sleep-for 1)))) | |
272 | |
273 (defun texinfo-quit-tex-job () | |
274 "Quit currently running TeX job, by sending an `x' to it." | |
275 (interactive) | |
276 (if (not (get-process "texinfo-tex-shell")) | |
277 (error "No TeX shell running.")) | |
278 (save-excursion | |
279 (set-buffer (get-buffer "*texinfo-tex-shell*")) | |
280 (goto-char (point-max)) | |
281 (insert "x") | |
282 (shell-send-input))) | |
283 | |
284 (defun texinfo-kill-tex-job () | |
285 "Kill the currently running TeX job." | |
286 (interactive) | |
287 (if (get-process "texinfo-tex-shell") | |
288 ;; Use `texinfo-tex-shell-sentinel' to restart | |
289 ;; texinfo-tex-shell after it is killed. | |
290 (kill-process (get-process "texinfo-tex-shell")))) | |
291 | |
292 (defun texinfo-tex-shell-sentinel (process event) | |
293 "Restart texinfo-tex-shell after it is killed." | |
294 (if (equal event "killed\n") | |
295 (save-excursion | |
296 (set-buffer "*texinfo-tex-shell*") | |
297 (insert "\n") | |
298 (texinfo-tex-start-shell)))) | |
299 | |
300 (defun texinfo-recenter-tex-output-buffer (linenum) | |
301 "Redisplay buffer of TeX job output so that most recent output can be seen. | |
302 The last line of the buffer is displayed on | |
303 line LINE of the window, or centered if LINE is nil." | |
304 (interactive "P") | |
305 (let ((texinfo-tex-shell (get-buffer "*texinfo-tex-shell*")) | |
306 (old-buffer (current-buffer))) | |
307 (if (null texinfo-tex-shell) | |
308 (message "No TeX output buffer") | |
309 (pop-to-buffer texinfo-tex-shell) | |
310 (bury-buffer texinfo-tex-shell) | |
311 (goto-char (point-max)) | |
312 (recenter (if linenum | |
313 (prefix-numeric-value linenum) | |
314 (/ (window-height) 2))) | |
315 (pop-to-buffer old-buffer) | |
316 ))) | |
317 | |
318 (defun texinfo-show-tex-print-queue () | |
319 "Show the print queue that \\[texinfo-tex-print] put your job on. | |
320 Runs the shell command defined by texinfo-show-tex-queue-command." | |
321 (interactive) | |
322 (if (not (texinfo-tex-shell-running-p)) | |
323 (texinfo-tex-start-shell)) | |
324 (send-string "texinfo-tex-shell" | |
325 (concat texinfo-show-tex-queue-command "\n")) | |
326 (texinfo-recenter-tex-output-buffer nil)) | |
327 | |
328 (defun texinfo-delete-from-tex-print-queue (job-number) | |
329 "Delete job from the line printer spooling queue. | |
330 You are prompted for the job number (shown by a previous | |
331 \\[texinfo-show-tex-print-queue] command." | |
332 (interactive "nPrinter job number for deletion: ") | |
333 (if (texinfo-tex-shell-running-p) | |
334 (texinfo-kill-tex-job) | |
335 (texinfo-tex-start-shell)) | |
336 (send-string "texinfo-tex-shell" | |
337 (concat | |
338 texinfo-delete-from-print-queue-command | |
339 " " | |
340 job-number"\n")) | |
341 (texinfo-recenter-tex-output-buffer nil)) | |
342 | |
343 (defun texinfo-tex-shell-running-p () | |
344 (and (get-process "texinfo-tex-shell") | |
345 (eq (process-status (get-process "texinfo-tex-shell")) 'run))) | |
346 | |
347 | |
348 ;;; Place `provide' at end of file. | |
349 (provide 'texnfo-tex) | |
350 ;;;;;;;;;;;;;;;; end texnfo-tex.el ;;;;;;;;;;;;;;;; |