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