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