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