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