yatex

view yatexprc.el @ 352:ecf7b5543e65

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