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