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