Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexprc.el @ 61:b9f753846b6b
Bug fix release
author | yuuji |
---|---|
date | Mon, 07 Apr 1997 20:07:48 +0000 |
parents | 9e08ed569d80 |
children | 36a48185b95a |
rev | line source |
---|---|
51 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX process handler. | |
3 ;;; yatexprc.el | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
4 ;;; (c )1993-1997 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] |
61 | 5 ;;; Last modified Mon Jan 27 10:22:06 1997 on crx |
51 | 6 ;;; $Id$ |
7 | |
8 (require 'yatex) | |
9 | |
10 (defvar YaTeX-typeset-process nil | |
11 "Process identifier for jlatex" | |
12 ) | |
13 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*" | |
14 "Process buffer for jlatex") | |
15 | |
16 (defvar YaTeX-typeset-buffer-syntax nil | |
17 "*Syntax table for typesetting buffer") | |
18 | |
19 (defvar YaTeX-current-TeX-buffer nil | |
20 "Keeps the buffer on which recently typeset run.") | |
21 | |
22 (defvar YaTeX-shell-command-option | |
23 (or (and (boundp 'shell-command-option) shell-command-option) | |
24 (if YaTeX-dos "/c" "-c")) | |
25 "Shell option for command execution.") | |
26 | |
27 (if YaTeX-typeset-buffer-syntax nil | |
28 (setq YaTeX-typeset-buffer-syntax | |
29 (make-syntax-table (standard-syntax-table))) | |
30 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax) | |
31 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax) | |
32 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax) | |
33 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax) | |
34 ) | |
35 | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
36 (defun YaTeX-typeset (command buffer &optional prcname modename) |
51 | 37 "Execute jlatex (or other) to LaTeX typeset." |
38 (interactive) | |
39 (save-excursion | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
40 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer)) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
41 (map YaTeX-typesetting-mode-map)) |
51 | 42 (if (and YaTeX-typeset-process |
43 (eq (process-status YaTeX-typeset-process) 'run)) | |
44 ;; if tex command is halting. | |
45 (YaTeX-kill-typeset-process YaTeX-typeset-process)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
46 (YaTeX-put-nonstopmode) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
47 (setq prcname (or prcname "LaTeX") |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
48 modename (or modename "typeset")) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
49 (if (eq major-mode 'yatex-mode) (YaTeX-visit-main t)) ;;execution dir |
51 | 50 (setq execdir default-directory) |
51 ;;Select lower-most window if there are more than 2 windows and | |
52 ;;typeset buffer not seen. | |
53 (YaTeX-showup-buffer | |
54 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
55 (set-buffer (get-buffer-create buffer)) | |
56 (setq default-directory execdir) | |
57 (cd execdir) | |
58 (erase-buffer) | |
59 (cond | |
60 (YaTeX-dos ;if MS-DOS | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
61 ;(YaTeX-put-nonstopmode) |
51 | 62 (call-process |
63 shell-file-name nil buffer nil YaTeX-shell-command-option command) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
64 ;(YaTeX-remove-nonstopmode) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
65 ) |
51 | 66 (t ;if UNIX |
67 (set-process-buffer | |
68 (setq YaTeX-typeset-process | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
69 (start-process prcname buffer shell-file-name |
51 | 70 YaTeX-shell-command-option command)) |
71 (get-buffer buffer)) | |
72 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel))) | |
73 (message (format "Calling `%s'..." command)) | |
74 (setq YaTeX-current-TeX-buffer (buffer-name)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
75 (use-local-map map) ;map may be localized |
51 | 76 (set-syntax-table YaTeX-typeset-buffer-syntax) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
77 (setq mode-name modename) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
78 (if YaTeX-typeset-process ;if process is running (maybe on UNIX) |
51 | 79 (cond ((boundp 'MULE) |
80 (set-current-process-coding-system | |
81 YaTeX-latex-message-code YaTeX-coding-system)) | |
82 ((boundp 'NEMACS) | |
83 (set-kanji-process-code YaTeX-latex-message-code)))) | |
84 (if YaTeX-dos (message "Done.") | |
85 (insert " ") | |
86 (set-marker (process-mark YaTeX-typeset-process) (1- (point)))) | |
87 (if (bolp) (forward-line -1)) ;what for? | |
88 (if (and YaTeX-emacs-19 window-system) | |
89 (let ((win (get-buffer-window buffer t)) owin) | |
90 (select-frame (window-frame win)) | |
91 (setq owin (selected-window)) | |
92 (select-window win) | |
93 (goto-char (point-max)) | |
94 (recenter -1) | |
95 (select-window owin)) | |
96 (select-window (get-buffer-window buffer)) | |
97 (goto-char (point-max)) | |
98 (recenter -1)) | |
99 (select-window window) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
100 (switch-to-buffer cb) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
101 (YaTeX-remove-nonstopmode))) |
51 | 102 ) |
103 | |
104 (defun YaTeX-typeset-sentinel (proc mes) | |
105 (cond ((null (buffer-name (process-buffer proc))) | |
106 ;; buffer killed | |
107 (set-process-buffer proc nil)) | |
108 ((memq (process-status proc) '(signal exit)) | |
109 (let* ((obuf (current-buffer)) (pbuf (process-buffer proc)) | |
110 (pwin (get-buffer-window pbuf)) | |
111 (owin (selected-window)) win) | |
112 ;; save-excursion isn't the right thing if | |
113 ;; process-buffer is current-buffer | |
114 (unwind-protect | |
115 (progn | |
116 ;; Write something in *typesetting* and hack its mode line | |
117 (if pwin | |
118 (select-window pwin) | |
119 (set-buffer pbuf)) | |
120 ;;(YaTeX-showup-buffer pbuf nil t) | |
121 (goto-char (point-max)) | |
122 (if pwin (recenter -3)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
123 (insert ?\n mode-name " " mes) |
51 | 124 (forward-char -1) |
125 (insert " at " (substring (current-time-string) 0 -5) "\n") | |
126 (forward-char 1) | |
127 (setq mode-line-process | |
128 (concat ": " | |
129 (symbol-name (process-status proc)))) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
130 (message mode-name " %s." |
51 | 131 (if (eq (process-status proc) 'exit) |
132 "done" "ceased")) | |
133 ;; If buffer and mode line shows that the process | |
134 ;; is dead, we can delete it now. Otherwise it | |
135 ;; will stay around until M-x list-processes. | |
136 (delete-process proc) | |
137 ) | |
138 (setq YaTeX-typeset-process nil) | |
139 ;; Force mode line redisplay soon | |
140 (set-buffer-modified-p (buffer-modified-p)) | |
141 ) | |
142 (select-window owin) | |
143 (set-buffer obuf)))) | |
144 ) | |
145 | |
146 (defvar YaTeX-texput-file "texput.tex" | |
147 "*File name for temporary file of typeset-region." | |
148 ) | |
149 | |
150 (defun YaTeX-typeset-region () | |
52 | 151 "Paste the region to the file `texput.tex' and execute typesetter. |
152 The region is specified by the rule: | |
51 | 153 (1)If keyword `%#BEGIN' is found in the upper direction from (point). |
154 (1-1)if the keyword `%#END' is found after `%#BEGIN', | |
155 ->Assume the text between `%#BEGIN' and `%#END' as region. | |
156 (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN', | |
157 ->Assume the text after `%#BEGIN' as region. | |
158 (2)If no `%#BEGIN' usage is found before the (point), | |
159 ->Assume the text between current (point) and (mark) as region. | |
160 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing | |
161 operation to the region." | |
162 (interactive) | |
163 (save-excursion | |
164 (let* | |
165 ((end "") typeout ;Type out message that tells the method of cutting. | |
166 (texput YaTeX-texput-file) | |
167 (cmd (concat (YaTeX-get-latex-command nil) " " texput)) | |
168 (buffer (current-buffer)) opoint preamble (subpreamble "") main | |
169 (hilit-auto-highlight nil) ;for Emacs19 with hilit19 | |
52 | 170 reg-begin reg-end lineinfo) |
51 | 171 |
172 (save-excursion | |
173 (if (search-backward "%#BEGIN" nil t) | |
174 (progn | |
175 (setq typeout "--- Region from BEGIN to " | |
176 end "the end of the buffer ---" | |
177 reg-begin (match-end 0)) | |
178 (if (search-forward "%#END" nil t) | |
179 (setq reg-end (match-beginning 0) | |
180 end "END ---") | |
181 (setq reg-end (point-max)))) | |
52 | 182 (setq typeout "=== Region from (point) to (mark) ===" |
183 reg-begin (point) reg-end (mark))) | |
184 (goto-char (min reg-begin reg-end)) | |
185 (setq lineinfo (count-lines (point-min) (point-end-of-line))) | |
51 | 186 (goto-char (point-min)) |
187 (while (search-forward "%#REQUIRE" nil t) | |
188 (setq subpreamble | |
189 (concat subpreamble | |
190 (cond | |
191 ((eolp) | |
192 (buffer-substring | |
193 (match-beginning 0) | |
194 (point-beginning-of-line))) | |
195 (t (buffer-substring | |
196 (match-end 0) | |
197 (point-end-of-line)))) | |
198 "\n")) | |
199 (goto-char (match-end 0)))) | |
200 (YaTeX-visit-main t) | |
201 (setq main (current-buffer)) | |
202 (setq opoint (point)) | |
203 (goto-char (point-min)) | |
204 (setq | |
205 preamble | |
206 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t) | |
207 (buffer-substring (point-min) (match-end 0)) | |
208 (concat "\\documentstyle{" YaTeX-default-document-style "}\n" | |
209 "\\begin{document}"))) | |
210 (goto-char opoint) | |
211 ;;(set-buffer buffer) ;for clarity | |
52 | 212 (let ((hilit-auto-highlight nil)) |
213 (set-buffer (find-file-noselect texput))) | |
51 | 214 ;;(find-file YaTeX-texput-file) |
215 (erase-buffer) | |
216 (if YaTeX-need-nonstop | |
217 (insert "\\nonstopmode{}\n")) | |
218 (insert preamble "\n" subpreamble "\n") | |
52 | 219 (setq lineinfo (list (count-lines 1 (point-end-of-line)) lineinfo)) |
51 | 220 (insert-buffer-substring buffer reg-begin reg-end) |
221 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method. | |
222 (insert "\n\\end{document}\n") | |
223 (basic-save-buffer) | |
224 (kill-buffer (current-buffer)) | |
225 (set-buffer main) ;return to parent file or itself. | |
226 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
227 (switch-to-buffer buffer) ;for Emacs-19 | |
52 | 228 (put 'dvi2-command 'region t) |
229 (put 'dvi2-command 'file buffer) | |
230 (put 'dvi2-command 'offset lineinfo) | |
231 )) | |
51 | 232 ) |
233 | |
234 (defun YaTeX-typeset-buffer () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
235 "Typeset whole buffer. |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
236 If %#! usage says other buffer is main text, |
51 | 237 visit main buffer to confirm if its includeonly list contains current |
238 buffer's file. And if it doesn't contain editing text, ask user which | |
239 action wants to be done, A:Add list, R:Replace list, %:comment-out list." | |
240 (interactive) | |
241 (YaTeX-save-buffers) | |
242 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.))) | |
243 (mydir (file-name-directory (buffer-file-name))) | |
244 (cmd (YaTeX-get-latex-command t)) (cb (current-buffer))) | |
245 (if (YaTeX-main-file-p) nil | |
246 (save-excursion | |
247 (YaTeX-visit-main t) ;search into main buffer | |
248 (save-excursion | |
249 (push-mark (point) t) | |
250 (goto-char (point-min)) | |
251 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t) | |
252 (re-search-backward "^[ ]*\\\\includeonly{" nil t)) | |
253 (let* | |
254 ((b (progn (skip-chars-forward "^{") (point))) | |
255 (e (progn (skip-chars-forward "^}") (1+ (point)))) | |
256 (s (buffer-substring b e)) c | |
257 (pardir (file-name-directory (buffer-file-name)))) | |
258 (if (string-match (concat "[{,/]" me "[,}]") s) | |
259 nil ; Nothing to do when it's already in includeonly. | |
260 (ding) | |
261 (switch-to-buffer (current-buffer));Display this buffer. | |
262 (setq | |
263 me ;;Rewrite my name(me) to contain sub directory name. | |
264 (concat | |
265 (if (string-match pardir mydir) ;if mydir is child of main | |
266 (substring mydir (length pardir)) ;cut absolute path | |
267 mydir) ;else concat absolute path name. | |
268 me)) | |
269 (message | |
270 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? " | |
271 me) | |
272 (setq c (read-char)) | |
273 (cond | |
274 ((= c ?a) | |
275 (goto-char (1+ b)) | |
276 (insert me (if (string= s "{}") "" ","))) | |
277 ((= c ?r) | |
278 (delete-region (1+ b) (1- e)) (insert me)) | |
279 ((= c ?%) | |
280 (beginning-of-line) (insert "%")) | |
281 (t nil)) | |
282 (basic-save-buffer)))) | |
283 (exchange-point-and-mark))) | |
284 (switch-to-buffer cb)) ;for 19 | |
285 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
286 (put 'dvi2-command 'region nil)) | |
287 ) | |
288 | |
289 (defvar YaTeX-call-command-history nil | |
290 "Holds history list of YaTeX-call-command-on-file.") | |
291 (put 'YaTeX-call-command-history 'no-default t) | |
292 (defun YaTeX-call-command-on-file (base-cmd buffer) | |
293 (YaTeX-save-buffers) | |
294 (YaTeX-typeset | |
295 (read-string-with-history | |
296 "Call command: " | |
297 (concat base-cmd " " (YaTeX-get-preview-file-name)) | |
298 'YaTeX-call-command-history) | |
299 buffer) | |
300 ) | |
301 | |
302 (defun YaTeX-bibtex-buffer (cmd) | |
303 "Pass the bibliography data of editing file to bibtex." | |
304 (interactive) | |
305 (YaTeX-save-buffers) | |
306 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" ) | |
307 ) | |
308 | |
309 (defun YaTeX-kill-typeset-process (proc) | |
310 "Kill process PROC after sending signal to PROC. | |
311 PROC should be process identifier." | |
312 (cond | |
313 (YaTeX-dos | |
314 (error "MS-DOS can't have concurrent process.")) | |
315 ((or (null proc) (not (eq (process-status proc) 'run))) | |
316 (message "Typesetting process is not running.")) | |
317 (t | |
318 (save-excursion | |
319 (set-buffer (process-buffer proc)) | |
320 (save-excursion | |
321 (goto-char (point-max)) | |
322 (beginning-of-line) | |
323 (if (looking-at "\\? +$") | |
324 (let ((mp (point-max))) | |
325 (process-send-string proc "x\n") | |
326 (while (= mp (point-max)) (sit-for 1)))))) | |
327 (if (eq (process-status proc) 'run) | |
328 (progn | |
329 (interrupt-process proc) | |
330 (delete-process proc))))) | |
331 ) | |
332 | |
333 (defun YaTeX-system (command buffer) | |
334 "Execute some command on buffer. Not a official function." | |
335 (save-excursion | |
336 (YaTeX-showup-buffer | |
337 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
59 | 338 (let ((df default-directory)) ;preserve current buf's pwd |
339 (set-buffer (get-buffer-create buffer)) ;1.61.3 | |
340 (setq default-directory df) | |
341 (cd df)) | |
51 | 342 (erase-buffer) |
343 (if YaTeX-dos | |
344 (call-process | |
345 shell-file-name nil buffer nil YaTeX-shell-command-option command) | |
59 | 346 (if (and (get-buffer-process buffer) |
347 (eq (process-status (get-buffer-process buffer)) 'run) | |
348 (not | |
349 (y-or-n-p (format "Process %s is running. Continue?" buffer)))) | |
350 nil | |
351 (set-process-buffer | |
352 (start-process | |
353 "system" buffer shell-file-name YaTeX-shell-command-option command) | |
354 (get-buffer buffer))))) | |
51 | 355 ) |
356 | |
357 (defvar YaTeX-preview-command-history nil | |
358 "Holds minibuffer history of preview command.") | |
359 (put 'YaTeX-preview-command-history 'no-default t) | |
360 (defvar YaTeX-preview-file-history nil | |
361 "Holds minibuffer history of file to preview.") | |
362 (put 'YaTeX-preview-file-history 'no-default t) | |
363 (defun YaTeX-preview (preview-command preview-file) | |
364 "Execute xdvi (or other) to tex-preview." | |
365 (interactive | |
366 (list | |
367 (read-string-with-history | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
368 "Preview command: " |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
369 (or (YaTeX-get-builtin "PREVIEW") dvi2-command) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
370 'YaTeX-preview-command-history) |
51 | 371 (read-string-with-history |
372 "Preview file[.dvi]: " | |
373 (if (get 'dvi2-command 'region) | |
374 (substring YaTeX-texput-file | |
375 0 (rindex YaTeX-texput-file ?.)) | |
376 (YaTeX-get-preview-file-name)) | |
377 'YaTeX-preview-file-history))) | |
378 (setq dvi2-command preview-command) ;`dvi2command' is buffer local | |
379 (save-excursion | |
380 (YaTeX-visit-main t) | |
381 (let ((pbuffer "*dvi-preview*") (dir default-directory)) | |
382 (YaTeX-showup-buffer | |
383 pbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
384 (set-buffer (get-buffer-create pbuffer)) | |
385 (erase-buffer) | |
386 (setq default-directory dir) ;for 18 | |
387 (cd dir) ;for 19 | |
388 (cond | |
389 (YaTeX-dos ;if MS-DOS | |
390 (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor | |
391 (call-process shell-file-name "con" "*dvi-preview*" nil | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
392 YaTeX-shell-command-option |
61 | 393 (concat preview-command " " preview-file)) |
51 | 394 (send-string-to-terminal "\e[>5l") ;show cursor |
395 (redraw-display)) | |
396 (t ;if UNIX | |
397 (set-process-buffer | |
398 (start-process "preview" "*dvi-preview*" shell-file-name | |
399 YaTeX-shell-command-option | |
400 (concat preview-command " " preview-file)) | |
401 (get-buffer pbuffer)) | |
402 (message | |
403 (concat "Starting " preview-command | |
404 " to preview " preview-file)))))) | |
405 ) | |
406 | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
407 (defvar YaTeX-xdvi-remote-program "xdvi") |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
408 (defun YaTeX-xdvi-remote-search (&optional region-mode) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
409 "Search string at the point on xdvi -remote window. |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
410 Non-nil for optional argument REGION-MODE specifies the search string |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
411 by region." |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
412 (interactive "P") |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
413 (let ((pb " *xdvi*") str proc) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
414 (save-excursion |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
415 (if region-mode |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
416 (setq str (buffer-substring (region-beginning) (region-end))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
417 (setq str (buffer-substring |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
418 (point) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
419 (progn (skip-chars-forward "^\n\\\\}") (point))))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
420 (message "Searching `%s'..." str) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
421 (if (boundp 'MULE) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
422 (define-program-coding-system |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
423 (regexp-quote pb) (regexp-quote YaTeX-xdvi-remote-program) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
424 *euc-japan*)) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
425 (setq proc |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
426 (start-process |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
427 "xdvi" pb YaTeX-xdvi-remote-program |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
428 "-remote" (format "SloppySearch(%s) " str) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
429 (concat (YaTeX-get-preview-file-name) ".dvi"))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
430 (message "Searching `%s'...Done" str))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
431 ) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
432 |
52 | 433 (defun YaTeX-set-virtual-error-position (file-sym line-sym) |
434 "Replace the value of FILE-SYM, LINE-SYM by virtual error position." | |
435 (cond | |
436 ((and (get 'dvi2-command 'region) | |
437 (> (symbol-value line-sym) (car (get 'dvi2-command 'offset)))) | |
438 (set file-sym (get 'dvi2-command 'file)) | |
439 (set line-sym | |
440 (+ (- (apply '- (get 'dvi2-command 'offset))) | |
441 (symbol-value line-sym) | |
442 -1))))) | |
443 | |
51 | 444 (defun YaTeX-prev-error () |
445 "Visit previous typeset error. | |
446 To avoid making confliction of line numbers by editing, jump to | |
447 error or warning lines in reverse order." | |
448 (interactive) | |
449 (let ((cur-buf (buffer-name)) (cur-win (selected-window)) | |
450 error-line typeset-win error-buffer error-win) | |
451 (if (null (get-buffer YaTeX-typeset-buffer)) | |
452 (error "There is no typesetting buffer.")) | |
453 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
454 (setq typeset-win (selected-window)) | |
455 (if (re-search-backward | |
456 (concat "\\(" latex-error-regexp "\\)\\|\\(" | |
457 latex-warning-regexp "\\)") | |
458 nil t) | |
459 nil | |
460 (select-window cur-win) | |
461 (error "No more erros on %s" cur-buf)) | |
462 (goto-char (match-beginning 0)) | |
463 (skip-chars-forward "^0-9" (match-end 0)) | |
464 (setq error-line | |
465 (string-to-int | |
466 (buffer-substring | |
467 (point) | |
468 (progn (skip-chars-forward "0-9" (match-end 0)) (point)))) | |
52 | 469 error-buffer (YaTeX-get-error-file cur-buf)) |
51 | 470 (if (or (null error-line) (equal 0 error-line)) |
471 (error "Can't detect error position.")) | |
52 | 472 (YaTeX-set-virtual-error-position 'error-buffer 'error-line) |
473 (setq error-win (get-buffer-window error-buffer)) | |
51 | 474 (select-window cur-win) |
475 (cond | |
476 (error-win (select-window error-win)) | |
477 ((eq (get-lru-window) typeset-win) | |
478 (YaTeX-switch-to-buffer error-buffer)) | |
479 (t (select-window (get-lru-window)) | |
480 (YaTeX-switch-to-buffer error-buffer))) | |
481 (setq error-win (selected-window)) | |
482 (goto-line error-line) | |
483 (message "LaTeX %s in `%s' on line: %d." | |
484 (if (match-beginning 1) "error" "warning") | |
485 error-buffer error-line) | |
486 (select-window typeset-win) | |
487 (skip-chars-backward "0-9") | |
488 (recenter (/ (window-height) 2)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
489 (sit-for 1) |
51 | 490 (goto-char (match-beginning 0)) |
491 (select-window error-win)) | |
492 ) | |
493 | |
494 (defun YaTeX-jump-error-line () | |
495 "Jump to corresponding line on latex command's error message." | |
496 (interactive) | |
497 (let (error-line error-file error-buf) | |
498 (save-excursion | |
499 (beginning-of-line) | |
500 (setq error-line (re-search-forward "l[ ines]*\\.?\\([1-9][0-9]*\\)" | |
501 (point-end-of-line) t))) | |
502 (if (null error-line) | |
503 (if (eobp) (insert (this-command-keys)) | |
504 (error "No line number expression.")) | |
505 (goto-char (match-beginning 0)) | |
506 (setq error-line (string-to-int | |
507 (buffer-substring (match-beginning 1) (match-end 1))) | |
52 | 508 error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)) |
509 (YaTeX-set-virtual-error-position 'error-file 'error-line) | |
510 (setq error-buf (YaTeX-switch-to-buffer error-file t))) | |
51 | 511 (if (null error-buf) |
512 (error "`%s' is not found in this directory." error-file)) | |
513 (YaTeX-showup-buffer error-buf nil t) | |
52 | 514 (goto-line error-line)) |
51 | 515 ) |
516 | |
517 (defun YaTeX-send-string () | |
518 "Send string to current typeset process." | |
519 (interactive) | |
520 (if (and (eq (process-status YaTeX-typeset-process) 'run) | |
521 (>= (point) (process-mark YaTeX-typeset-process))) | |
522 (let ((b (process-mark YaTeX-typeset-process)) | |
523 (e (point-end-of-line))) | |
524 (goto-char b) | |
525 (skip-chars-forward " \t" e) | |
526 (setq b (point)) | |
527 (process-send-string | |
528 YaTeX-typeset-process (concat (buffer-substring b e) "\n")) | |
529 (goto-char e) | |
530 (insert "\n") | |
531 (set-marker (process-mark YaTeX-typeset-process) (point)) | |
532 (insert " ")) | |
533 (ding)) | |
534 ) | |
535 | |
536 (defun YaTeX-view-error () | |
537 (interactive) | |
538 (if (null (get-buffer YaTeX-typeset-buffer)) | |
539 (message "No typeset buffer found.") | |
540 (let ((win (selected-window))) | |
541 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
542 ;; Next 3 lines are obsolete because YaTeX-typesetting-buffer is | |
543 ;; automatically scrolled up at typesetting. | |
544 ;;(goto-char (point-max)) | |
545 ;;(forward-line -1) | |
546 ;;(recenter -1) | |
547 (select-window win))) | |
548 ) | |
549 | |
550 (defun YaTeX-get-error-file (default) | |
551 "Get current processing file from typesetting log." | |
552 (save-excursion | |
553 (let(s) | |
554 (condition-case () (up-list -1) | |
555 (error | |
556 (let ((list 0) found) | |
557 (while | |
558 (and (<= list 0) (not found) | |
559 (re-search-backward "\\((\\)\\|\\()\\)" nil t)) | |
560 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren. | |
561 (setq list (1- list)) ;open paren | |
562 (setq list (1+ list)) | |
563 (if (= list 1) | |
564 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty") | |
565 (setq found t) | |
566 (setq list (1- list))))))))) | |
567 (setq s | |
568 (buffer-substring | |
569 (progn (forward-char 1) (point)) | |
570 (progn (skip-chars-forward "^ \n" (point-end-of-line)) | |
571 (point)))) | |
572 (if (string= "" s) default s))) | |
573 ) | |
574 | |
575 (defun YaTeX-put-nonstopmode () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
576 (if (and YaTeX-need-nonstop (eq major-mode 'yatex-mode)) |
51 | 577 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t) |
578 nil ;if already written in text then do nothing | |
579 (save-excursion | |
580 (YaTeX-visit-main t) | |
581 (goto-char (point-min)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
582 (insert "\\nonstopmode{}%_YaTeX_%\n") |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
583 (if (buffer-file-name) (basic-save-buffer)))) |
51 | 584 ) |
585 ) | |
586 | |
587 (defun YaTeX-remove-nonstopmode () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
588 (if (and YaTeX-need-nonstop (eq major-mode 'yatex-mode)) ;for speed |
51 | 589 (save-excursion |
590 (YaTeX-visit-main t) | |
591 (goto-char (point-min)) | |
592 (forward-line 1) | |
593 (narrow-to-region (point-min) (point)) | |
594 (goto-char (point-min)) | |
595 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$") | |
596 (widen))) | |
597 ) | |
598 | |
599 (defun YaTeX-get-preview-file-name () | |
600 "Get file name to preview by inquiring YaTeX-get-latex-command" | |
601 (let* ((latex-cmd (YaTeX-get-latex-command t)) | |
602 (rin (rindex latex-cmd ? )) | |
603 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) "")) | |
604 (period)) | |
605 (if (string= fname "") | |
606 (setq fname (substring (file-name-nondirectory | |
607 (buffer-file-name)) | |
608 0 -4)) | |
609 (setq period (rindex fname ?.)) | |
610 (setq fname (substring fname 0 (if (eq -1 period) nil period))) | |
611 )) | |
612 ) | |
613 | |
614 (defun YaTeX-get-latex-command (&optional switch) | |
615 "Specify the latex-command name and its argument. | |
616 If there is a line which begins with string: \"%#!\", the following | |
617 strings are assumed to be the latex-command and arguments. The | |
618 default value of latex-command is: | |
619 tex-command FileName | |
620 and if you write \"%#!jlatex\" in the beginning of certain line. | |
621 \"jlatex \" FileName | |
622 will be the latex-command, | |
623 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH | |
624 is non-nil, then | |
625 \"jlatex main.tex\" | |
626 | |
627 will be given to the shell." | |
628 (let (magic command target) | |
629 (setq parent | |
630 (cond | |
631 (YaTeX-parent-file YaTeX-parent-file) | |
632 (t (save-excursion | |
633 (YaTeX-visit-main t) | |
634 (file-name-nondirectory (buffer-file-name))))) | |
635 magic (YaTeX-get-builtin "!")) | |
636 (cond | |
637 (magic | |
638 (cond | |
639 (switch (if (string-match "\\s " magic) magic | |
640 (concat magic " " parent))) | |
641 (t (concat (substring magic 0 (string-match "\\s " magic)) " ")))) | |
642 (t (concat tex-command " " (if switch parent))))) | |
643 ) | |
644 | |
645 (defvar YaTeX-lpr-command-history nil | |
646 "Holds command line history of YaTeX-lpr.") | |
647 (put 'YaTeX-lpr-command-history 'no-default t) | |
648 (defun YaTeX-lpr (arg) | |
649 "Print out. If prefix arg ARG is non nil, call print driver without | |
650 page range description." | |
651 (interactive "P") | |
652 (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)) | |
52 | 653 from to (lbuffer "*dvi-printing*") dir) |
51 | 654 (setq |
655 cmd | |
656 (YaTeX-replace-format | |
657 cmd "f" | |
658 (if (or arg (not (string-match "%f" cmd))) | |
659 "" | |
660 (YaTeX-replace-format | |
661 dviprint-from-format | |
662 "b" | |
663 (if (string= | |
664 (setq from (read-string "From page(default 1): ")) "") | |
665 "1" from)))) | |
666 ) | |
667 (setq | |
668 cmd | |
669 (YaTeX-replace-format | |
670 cmd "t" | |
671 (if (or arg (not (string-match "%t" cmd)) | |
672 (string= | |
673 (setq to (read-string "To page(default none): ")) "")) | |
674 "" | |
675 (YaTeX-replace-format dviprint-to-format "e" to))) | |
676 ) | |
677 (setq cmd | |
678 (read-string-with-history | |
679 "Edit command line: " | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
680 (format cmd |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
681 (if (get 'dvi2-command 'region) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
682 (substring YaTeX-texput-file |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
683 0 (rindex YaTeX-texput-file ?.)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
684 (YaTeX-get-preview-file-name))) |
51 | 685 'YaTeX-lpr-command-history)) |
686 (save-excursion | |
687 (YaTeX-visit-main t) ;;change execution directory | |
52 | 688 (setq dir default-directory) |
51 | 689 (YaTeX-showup-buffer |
690 lbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
691 (set-buffer (get-buffer-create lbuffer)) | |
692 (erase-buffer) | |
52 | 693 (cd dir) ;for 19 |
51 | 694 (cond |
695 (YaTeX-dos | |
696 (call-process shell-file-name "con" "*dvi-printing*" nil | |
697 YaTeX-shell-command-option cmd)) | |
698 (t | |
699 (set-process-buffer | |
700 (start-process "print" "*dvi-printing*" shell-file-name | |
701 YaTeX-shell-command-option cmd) | |
702 (get-buffer lbuffer)) | |
703 (message "Starting printing command: %s..." cmd))) | |
704 )) | |
705 ) | |
706 | |
707 (defun YaTeX-main-file-p () | |
708 "Return if current buffer is main LaTeX source." | |
709 (cond | |
52 | 710 (YaTeX-parent-file |
711 (eq (get-file-buffer YaTeX-parent-file) (current-buffer))) | |
51 | 712 ((YaTeX-get-builtin "!") |
713 (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name))) | |
714 (t | |
715 (save-excursion | |
57 | 716 (let ((latex-main-id |
717 (concat "^\\s *" YaTeX-ec-regexp "document\\(style\\|class\\)"))) | |
51 | 718 (or (re-search-backward latex-main-id nil t) |
719 (re-search-forward latex-main-id nil t)))))) | |
720 ) | |
721 | |
722 (defun YaTeX-visit-main (&optional setbuf) | |
723 "Switch buffer to main LaTeX source. | |
724 Use set-buffer instead of switch-to-buffer if the optional second argument | |
725 SETBUF is t(Use it only from Emacs-Lisp program)." | |
726 (interactive "P") | |
727 (if (and (interactive-p) setbuf) (setq YaTeX-parent-file nil)) | |
728 (let (b-in main-file) | |
729 (if (setq b-in (YaTeX-get-builtin "!")) | |
730 (setq main-file (YaTeX-guess-parent b-in))) | |
731 (if YaTeX-parent-file | |
732 (setq main-file ;;(get-file-buffer YaTeX-parent-file) | |
733 YaTeX-parent-file)) | |
734 (if (YaTeX-main-file-p) | |
735 (if (interactive-p) (message "I think this is main LaTeX source.") nil) | |
736 (cond | |
737 ((and (interactive-p) main-file (get-file-buffer main-file)) | |
738 (goto-buffer-window main-file)) | |
739 ((and main-file (YaTeX-switch-to-buffer main-file setbuf))) | |
740 ((and main-file | |
741 (file-exists-p (setq main-file (concat "../" main-file))) | |
742 (y-or-n-p (concat (expand-file-name main-file) | |
743 " is main file?:"))) | |
744 (setq YaTeX-parent-file main-file) | |
745 (YaTeX-switch-to-buffer main-file setbuf)) | |
746 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1)) | |
747 (setq YaTeX-parent-file main-file) | |
748 (YaTeX-switch-to-buffer main-file setbuf)) | |
749 ))) | |
750 nil | |
751 ) | |
752 | |
753 | |
754 (defun YaTeX-guess-parent (command-line) | |
755 (setq command-line | |
756 (if (string-match ".*\\s " command-line) | |
757 (substring command-line (match-end 0)) | |
758 (file-name-nondirectory (buffer-file-name))) | |
759 command-line | |
760 (concat (if (string-match "\\(.*\\)\\." command-line) | |
761 (substring command-line (match-beginning 1) (match-end 1)) | |
762 command-line) | |
763 ".tex")) | |
764 ) | |
765 | |
766 (defun YaTeX-visit-main-other-window () | |
767 "Switch to buffer main LaTeX source in other window." | |
768 (interactive) | |
769 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.") | |
770 (YaTeX-switch-to-buffer-other-window | |
771 (concat (YaTeX-get-preview-file-name) ".tex"))) | |
772 ) | |
773 | |
774 (defun YaTeX-get-builtin (key) | |
775 "Read source built-in command of %# usage." | |
776 (save-excursion | |
777 (goto-char (point-min)) | |
778 (if (and (re-search-forward | |
779 (concat "^" (regexp-quote (concat "%#" key))) nil t) | |
780 (not (eolp))) | |
781 (buffer-substring | |
782 (progn (skip-chars-forward " " (point-end-of-line))(point)) | |
783 (point-end-of-line)) | |
784 nil)) | |
785 ) | |
786 | |
787 (defun YaTeX-save-buffers () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
788 "Save buffers whose major-mode is equal to current major-mode." |
51 | 789 (basic-save-buffer) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
790 (let ((cmm major-mode)) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
791 (save-excursion |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
792 (mapcar '(lambda (buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
793 (set-buffer buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
794 (if (and (buffer-file-name buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
795 (eq major-mode cmm) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
796 (buffer-modified-p buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
797 (y-or-n-p (format "Save %s" (buffer-name buf)))) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
798 (save-buffer buf))) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
799 (buffer-list)))) |
51 | 800 ) |
801 | |
802 (provide 'yatexprc) |