yatex

view yatexprc.el @ 16:cb9afa9c1213

Auto-indentation at begin-type completion works correctly. Hack for gmhist&gmhist-mh. Fix the bug on \ref-completion. YaTeX-help is now available.
author yuuji
date Fri, 06 May 1994 21:14:11 +0000
parents cd762e854337
children adc2f1472409
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX process handler.
3 ;;; yatexprc.el
4 ;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Thu May 5 17:33:04 1994 on 98fa
6 ;;; $Id$
8 (require 'yatex)
10 (defvar YaTeX-typeset-process nil
11 "Process identifier for jlatex"
12 )
13 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
14 "Process buffer for jlatex")
16 (defvar YaTeX-typeset-buffer-syntax nil
17 "*Syntax table for typesetting buffer")
19 (defvar YaTeX-current-TeX-buffer nil
20 "Keeps the buffer on which recently typeset run.")
22 (if YaTeX-typeset-buffer-syntax nil
23 (setq YaTeX-typeset-buffer-syntax
24 (make-syntax-table (standard-syntax-table)))
25 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax)
26 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax)
27 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax)
28 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)
29 )
31 (defun YaTeX-typeset (command buffer)
32 "Execute jlatex (or other) to LaTeX typeset."
33 (interactive)
34 (let ((window (selected-window)))
35 (if (and YaTeX-typeset-process
36 (eq (process-status YaTeX-typeset-process) 'run))
37 ;; if tex command is halting.
38 (YaTeX-kill-typeset-process YaTeX-typeset-process))
39 (YaTeX-visit-main t);;execution directory
40 ;;Select lower-most window if there are more than 2 windows and
41 ;;typeset buffer not seen.
42 (YaTeX-showup-buffer
43 buffer (function (lambda (x) (nth 3 (window-edges x)))))
44 (with-output-to-temp-buffer buffer
45 (if YaTeX-dos ;if MS-DOS
46 (progn
47 (message (concat "Typesetting " (buffer-name) "..."))
48 (YaTeX-put-nonstopmode)
49 (call-process shell-file-name
50 nil buffer nil "/c" command)
51 (YaTeX-remove-nonstopmode))
52 (setq YaTeX-typeset-process ;if UNIX
53 (start-process "LaTeX" buffer shell-file-name "-c"
54 command))
55 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
56 (setq YaTeX-current-TeX-buffer (buffer-name))
57 (select-window (get-buffer-window buffer))
58 (use-local-map YaTeX-typesetting-mode-map)
59 (set-syntax-table YaTeX-typeset-buffer-syntax)
60 (setq mode-name "typeset")
61 (if YaTeX-typeset-process ; if process is running (maybe on UNIX)
62 (cond ((boundp 'MULE)
63 (set-current-process-coding-system
64 YaTeX-latex-message-code YaTeX-coding-system))
65 ((boundp 'NEMACS)
66 (set-kanji-process-code YaTeX-latex-message-code))))
67 (message "Type SPC to continue.")
68 (goto-char (point-max))
69 (if YaTeX-dos (message "Done.")
70 (insert (message " "))
71 (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
72 (if (bolp) (forward-line -1))
73 (recenter -1)
74 (select-window window))
75 )
77 (defun YaTeX-typeset-sentinel (proc mes)
78 (cond ((null (buffer-name (process-buffer proc)))
79 ;; buffer killed
80 (set-process-buffer proc nil))
81 ((memq (process-status proc) '(signal exit))
82 (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
83 (owin (selected-window)) win)
84 ;; save-excursion isn't the right thing if
85 ;; process-buffer is current-buffer
86 (unwind-protect
87 (progn
88 ;; Write something in *typesetting* and hack its mode line
89 (YaTeX-pop-to-buffer pbuf)
90 (set-buffer (process-buffer proc))
91 (goto-char (point-max))
92 (recenter -3)
93 (insert ?\n "latex typesetting " mes)
94 (forward-char -1)
95 (insert " at " (substring (current-time-string) 0 -5) "\n")
96 (forward-char 1)
97 (setq mode-line-process
98 (concat ": "
99 (symbol-name (process-status proc))))
100 (message "latex typesetting done.")
101 ;; If buffer and mode line shows that the process
102 ;; is dead, we can delete it now. Otherwise it
103 ;; will stay around until M-x list-processes.
104 (delete-process proc)
105 )
106 (setq YaTeX-typesetting-process nil)
107 ;; Force mode line redisplay soon
108 (set-buffer-modified-p (buffer-modified-p))
109 )
110 (select-window owin)
111 (set-buffer obuf))))
112 )
114 (defvar YaTeX-texput-file "texput.tex"
115 "*File name for temporary file of typeset-region."
116 )
118 (defun YaTeX-typeset-region ()
119 "Paste the region to the file `texput.tex' and execute jlatex (or other)
120 to LaTeX typeset. The region is specified by the rule:
121 (1)If keyword `%#BEGIN' is found in the upper direction from (point).
122 (1-1)if the keyword `%#END' is found after `%#BEGIN',
123 ->Assume the text between `%#BEGIN' and `%#END' as region.
124 (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN',
125 ->Assume the text after `%#BEGIN' as region.
126 (2)If no `%#BEGIN' usage is found before the (point),
127 ->Assume the text between current (point) and (mark) as region.
128 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
129 operation to the region."
130 (interactive)
131 (save-excursion
132 (let*
133 ((end "") typeout ;Type out message that tells the method of cutting.
134 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
135 (buffer (current-buffer)) opoint preamble main
136 reg-begin reg-end)
138 (if (re-search-backward "%#BEGIN" nil t)
139 (progn
140 (setq typeout "--- Region from BEGIN to " end "END ---"
141 reg-begin (match-end 0))
142 (if (re-search-forward "%#END" nil t)
143 (setq reg-end (match-beginning 0)
144 end "end of buffer ---")
145 (setq reg-end (point-max))))
146 (setq typeout "=== Region from (point) to (mark) ===")
147 (setq reg-begin (point) reg-end (mark)))
148 (YaTeX-visit-main t)
149 (setq main (current-buffer))
150 (setq opoint (point))
151 (goto-char (point-min))
152 (setq
153 preamble
154 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t)
155 (buffer-substring (point-min) (match-end 0))
156 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
157 "\\begin{document}")))
158 (goto-char opoint)
159 ;;(set-buffer buffer) ;for clarity
160 (set-buffer (find-file-noselect YaTeX-texput-file))
161 ;;(find-file YaTeX-texput-file)
162 (erase-buffer)
163 (if YaTeX-need-nonstop
164 (insert "\\nonstopmode{}\n"))
165 (insert preamble "\n")
166 (insert-buffer-substring buffer reg-begin reg-end)
167 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
168 (insert "\n\\end{document}\n")
169 (basic-save-buffer)
170 (kill-buffer (current-buffer))
171 (set-buffer main) ;return to parent file or itself.
172 (YaTeX-typeset cmd YaTeX-typeset-buffer)
173 (put 'dvi2-command 'region t)))
174 )
176 (defun YaTeX-typeset-buffer ()
177 "Typeset whole buffer. If %#! usage says other buffer is main text,
178 visit main buffer to confirm if its includeonly list contains current
179 buffer's file. And if it doesn't contain editing text, ask user which
180 action wants to be done, A:Add list, R:Replace list, %:comment-out list."
181 (interactive)
182 (YaTeX-save-buffers)
183 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
184 (mydir (file-name-directory (buffer-file-name)))
185 (cmd (YaTeX-get-latex-command t)))
186 (if (YaTeX-main-file-p) nil
187 (save-excursion
188 (YaTeX-visit-main t) ;search into main buffer
189 (save-excursion
190 (push-mark (point) t)
191 (goto-char (point-min))
192 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t)
193 (re-search-backward "^[ ]*\\\\includeonly{" nil t))
194 (let*
195 ((b (progn (skip-chars-forward "^{") (point)))
196 (e (progn (skip-chars-forward "^}") (1+ (point))))
197 (s (buffer-substring b e)) c
198 (pardir (file-name-directory (buffer-file-name))))
199 (if (string-match (concat "[{,/]" me "[,}]") s)
200 nil ; Nothing to do when it's already in includeonly.
201 (ding)
202 (switch-to-buffer (current-buffer));Display this buffer.
203 (setq
204 me ;;Rewrite my name(me) to contain sub directory name.
205 (concat
206 (if (string-match pardir mydir) ;if mydir is child of main
207 (substring mydir (length pardir)) ;cut absolute path
208 mydir) ;else concat absolute path name.
209 me))
210 (message
211 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? "
212 me)
213 (setq c (read-char))
214 (cond
215 ((= c ?a)
216 (goto-char (1+ b))
217 (insert me (if (string= s "{}") "" ",")))
218 ((= c ?r)
219 (delete-region (1+ b) (1- e)) (insert me))
220 ((= c ?%)
221 (beginning-of-line) (insert "%"))
222 (t nil))
223 (basic-save-buffer))))
224 (exchange-point-and-mark))
225 ))
226 (YaTeX-typeset cmd YaTeX-typeset-buffer)
227 (put 'dvi2-command 'region nil))
228 )
230 (defvar YaTeX-call-command-history nil
231 "Holds history list of YaTeX-call-command-on-file.")
232 (put 'YaTeX-call-command-history 'no-default t)
233 (defun YaTeX-call-command-on-file (base-cmd buffer)
234 (YaTeX-save-buffers)
235 (YaTeX-typeset
236 (let ((minibufer-history-symbol 'YaTeX-call-command-history))
237 (read-string "Call command: "
238 (concat base-cmd " " (YaTeX-get-preview-file-name))))
239 buffer)
240 )
242 (defun YaTeX-bibtex-buffer (cmd)
243 "Pass the bibliography data of editing file to bibtex."
244 (interactive)
245 (YaTeX-save-buffers)
246 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" )
247 )
249 (defun YaTeX-kill-typeset-process (proc)
250 "Kill process PROC after sending signal to PROC.
251 PROC should be process identifier."
252 (cond
253 (YaTeX-dos
254 (error "MS-DOS can't have concurrent process."))
255 ((or (null proc) (not (eq (process-status proc) 'run)))
256 (error "No typesetting process."))
257 (t (interrupt-process proc)
258 (delete-process proc)))
259 )
261 (defun YaTeX-system (command buffer)
262 "Execute some command on buffer. Not a official function."
263 (save-excursion
264 (with-output-to-temp-buffer buffer
265 (if YaTeX-dos
266 (call-process shell-file-name nil buffer nil "/c " command)
267 (start-process "system" buffer shell-file-name "-c" command))))
268 )
270 (defvar YaTeX-preview-command-history nil
271 "Holds minibuffer history of preview command.")
272 (put 'YaTeX-preview-command-history 'no-default t)
273 (defvar YaTeX-preview-file-history nil
274 "Holds minibuffer history of file to preview.")
275 (put 'YaTeX-preview-file-history 'no-default t)
276 (defun YaTeX-preview (preview-command preview-file)
277 "Execute xdvi (or other) to tex-preview."
278 (interactive
279 (list
280 (let ((minibuffer-history-symbol 'YaTeX-preview-command-history))
281 (read-string "Preview command: " dvi2-command))
282 (let ((minibuffer-history-symbol 'YaTeX-preview-file-history))
283 (read-string "Preview file[.dvi]: "
284 (if (get 'dvi2-command 'region)
285 (substring YaTeX-texput-file
286 0 (rindex YaTeX-texput-file ?.))
287 (YaTeX-get-preview-file-name))
288 ))))
289 (setq dvi2-command preview-command)
290 (save-excursion
291 (YaTeX-visit-main t)
292 (with-output-to-temp-buffer "*dvi-preview*"
293 (if YaTeX-dos ;if MS-DOS
294 (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
295 (call-process shell-file-name "con" "*dvi-preview*" nil
296 "/c " dvi2-command preview-file)
297 (send-string-to-terminal "\e[>5l") ;show cursor
298 (redraw-display))
299 (start-process "preview" "*dvi-preview*" shell-file-name "-c"
300 (concat dvi2-command " " preview-file)) ;if UNIX
301 (message
302 (concat "Starting " dvi2-command " to preview " preview-file)))))
303 )
305 (defun YaTeX-prev-error ()
306 "Visit previous typeset error.
307 To avoid making confliction of line numbers by editing, jump to
308 error or warning lines in reverse order."
309 (interactive)
310 (let ((cur-buf (buffer-name)) (cur-win (selected-window))
311 error-line typeset-win error-buffer error-win)
312 (if (null (get-buffer YaTeX-typeset-buffer))
313 (error "There is no typesetting buffer."))
314 (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
315 (setq typeset-win (selected-window))
316 (if (re-search-backward
317 (concat "\\(" latex-error-regexp "\\)\\|\\("
318 latex-warning-regexp "\\)")
319 nil t)
320 nil
321 (select-window cur-win)
322 (error "No more erros on %s" cur-buf))
323 (goto-char (match-beginning 0))
324 (skip-chars-forward "^0-9" (match-end 0))
325 (setq error-line
326 (string-to-int
327 (buffer-substring
328 (point)
329 (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
330 error-buffer (YaTeX-get-error-file cur-buf)
331 error-win (get-buffer-window error-buffer))
332 (if (or (null error-line) (equal 0 error-line))
333 (error "Can't detect error position."))
334 (select-window cur-win)
335 (cond
336 (error-win (select-window error-win))
337 ((eq (get-lru-window) typeset-win)
338 (YaTeX-switch-to-buffer error-buffer))
339 (t (select-window (get-lru-window))
340 (YaTeX-switch-to-buffer error-buffer)))
341 (setq error-win (selected-window))
342 (goto-line error-line)
343 (message "LaTeX %s in `%s' on line: %d."
344 (if (match-beginning 1) "error" "warning")
345 error-buffer error-line)
346 (select-window typeset-win)
347 (skip-chars-backward "0-9")
348 (recenter (/ (window-height) 2))
349 (sit-for 3)
350 (goto-char (match-beginning 0))
351 (select-window error-win))
352 )
354 (defun YaTeX-jump-error-line ()
355 "Jump to corresponding line on latex command's error message."
356 (interactive)
357 (let (error-line error-file error-buf)
358 (save-excursion
359 (beginning-of-line)
360 (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
361 (point-end-of-line) t)))
362 (if (null error-line)
363 (if (eobp) (insert (this-command-keys))
364 (error "No line number expression."))
365 (goto-char (match-beginning 0))
366 (setq error-line (string-to-int
367 (buffer-substring (match-beginning 1) (match-end 1)))
368 error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
369 error-buf (YaTeX-switch-to-buffer error-file t))
370 (if (null error-buf)
371 (error "`%s' is not found in this directory." error-file))
372 (YaTeX-showup-buffer error-buf nil t)
373 (goto-line error-line)))
374 )
376 (defun YaTeX-send-string ()
377 "Send string to current typeset process."
378 (interactive)
379 (if (and (eq (process-status YaTeX-typeset-process) 'run)
380 (>= (point) (process-mark YaTeX-typeset-process)))
381 (let ((b (process-mark YaTeX-typeset-process))
382 (e (point-end-of-line)))
383 (goto-char b)
384 (skip-chars-forward " \t" e)
385 (setq b (point))
386 (process-send-string
387 YaTeX-typeset-process (concat (buffer-substring b e) "\n"))
388 (goto-char e)
389 (insert "\n")
390 (set-marker (process-mark YaTeX-typeset-process) (point))
391 (insert " "))
392 (ding))
393 )
395 (defun YaTeX-view-error ()
396 (interactive)
397 (if (null (get-buffer YaTeX-typeset-buffer))
398 (message "No typeset buffer found.")
399 (let ((win (selected-window)))
400 (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
401 (goto-char (point-max))
402 (recenter -1)
403 (select-window win)))
404 )
406 (defun YaTeX-get-error-file (default)
407 "Get current processing file from typesetting log."
408 (save-excursion
409 (let(s)
410 (condition-case () (up-list -1)
411 (error
412 (let ((list 0) found)
413 (while
414 (and (<= list 0) (not found)
415 (re-search-backward "\\((\\)\\|\\()\\)" nil t))
416 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren.
417 (setq list (1- list)) ;open paren
418 (setq list (1+ list))
419 (if (= list 1)
420 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty")
421 (setq found t)
422 (setq list (1- list)))))))))
423 (setq s
424 (buffer-substring
425 (progn (forward-char 1) (point))
426 (progn (skip-chars-forward "-A-Za-z0-9_/\.\\" (point-end-of-line))
427 (point))))
428 (if (string= "" s) default s)))
429 )
431 (defun YaTeX-put-nonstopmode ()
432 (if YaTeX-need-nonstop
433 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
434 nil ;if already written in text then do nothing
435 (save-excursion
436 (YaTeX-visit-main t)
437 (goto-char (point-min))
438 (insert "\\nonstopmode{}%_YaTeX_%\n")))
439 )
440 )
442 (defun YaTeX-remove-nonstopmode ()
443 (if YaTeX-need-nonstop ;for speed
444 (save-excursion
445 (YaTeX-visit-main t)
446 (goto-char (point-min))
447 (forward-line 1)
448 (narrow-to-region (point-min) (point))
449 (goto-char (point-min))
450 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
451 (widen)))
452 )
454 (defun YaTeX-get-preview-file-name ()
455 "Get file name to preview by inquiring YaTeX-get-latex-command"
456 (let* ((latex-cmd (YaTeX-get-latex-command t))
457 (rin (rindex latex-cmd ? ))
458 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
459 (period))
460 (if (string= fname "")
461 (setq fname (substring (file-name-nondirectory
462 (buffer-file-name))
463 0 -4))
464 (setq period (rindex fname ?.))
465 (setq fname (substring fname 0 (if (eq -1 period) nil period)))
466 ))
467 )
469 (defun YaTeX-get-latex-command (&optional switch)
470 "Specify the latex-command name and its argument.
471 If there is a line which begins with string: \"%#!\", the following
472 strings are assumed to be the latex-command and arguments. The
473 default value of latex-command is:
474 tex-command FileName
475 and if you write \"%#!jlatex\" in the beginning of certain line.
476 \"jlatex \" FileName
477 will be the latex-command,
478 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
479 is non-nil, then
480 \"jlatex main.tex\"
482 will be given to the shell."
483 (let (magic command target)
484 (setq parent
485 (cond
486 (YaTeX-parent-file YaTeX-parent-file)
487 (t (save-excursion
488 (YaTeX-visit-main t)
489 (file-name-nondirectory (buffer-file-name)))))
490 magic (YaTeX-get-builtin "!"))
491 (cond
492 (magic
493 (cond
494 (switch (if (string-match "\\s " magic) magic
495 (concat magic " " parent)))
496 (t (concat (substring magic 0 (string-match "\\s " magic)) " "))))
497 (t (concat tex-command " " (if switch parent)))))
498 )
500 (defvar YaTeX-lpr-command-history nil
501 "Holds command line history of YaTeX-lpr.")
502 (put 'YaTeX-lpr-command-history 'no-default t)
503 (defun YaTeX-lpr (arg)
504 "Print out. If prefix arg ARG is non nil, call print driver without
505 page range description."
506 (interactive "P")
507 (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
508 (setq
509 cmd
510 (YaTeX-replace-format
511 cmd "f"
512 (if (or arg (not (string-match "%f" cmd)))
513 ""
514 (YaTeX-replace-format
515 dviprint-from-format
516 "b"
517 (if (string=
518 (setq from (read-string "From page(default 1): ")) "")
519 "1" from))))
520 )
521 (setq
522 cmd
523 (YaTeX-replace-format
524 cmd "t"
525 (if (or arg (not (string-match "%t" cmd))
526 (string=
527 (setq to (read-string "To page(default none): ")) ""))
528 ""
529 (YaTeX-replace-format dviprint-to-format "e" to)))
530 )
531 (setq cmd
532 (let ((minibuffer-history-symbol 'YaTeX-lpr-command-history))
533 (read-string "Edit command line: "
534 (format cmd (YaTeX-get-preview-file-name)))))
535 (save-excursion
536 (YaTeX-visit-main t) ;;change execution directory
537 (with-output-to-temp-buffer "*dvi-printing*"
538 (if YaTeX-dos
539 (call-process shell-file-name "con" "*dvi-printing*" nil
540 "/c " cmd)
541 (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
542 (message (concat "Starting " cmd " to printing "
543 (YaTeX-get-preview-file-name))))
544 )))
545 )
547 (defun YaTeX-main-file-p ()
548 "Return if current buffer is main LaTeX source."
549 (cond
550 ((YaTeX-get-builtin "!")
551 (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name)))
552 (t
553 (save-excursion
554 (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
555 (or (re-search-backward latex-main-id nil t)
556 (re-search-forward latex-main-id nil t))))))
557 )
559 (defun YaTeX-visit-main (&optional setbuf)
560 "Switch buffer to main LaTeX source.
561 Use set-buffer instead of switch-to-buffer if the optional second argument
562 SETBUF is t(Use it only from Emacs-Lisp program)."
563 (interactive)
564 (let (b-in main-file)
565 (if (setq b-in (YaTeX-get-builtin "!"))
566 (setq main-file (YaTeX-guess-parent b-in)))
567 (if YaTeX-parent-file
568 (setq main-file YaTeX-parent-file))
569 (if (YaTeX-main-file-p)
570 (if (interactive-p) (message "I think this is main LaTeX source.") nil)
571 (cond
572 ((and (interactive-p) main-file (get-buffer-window main-file))
573 (select-window (get-buffer-window main-file)))
574 ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
575 ((and main-file
576 (file-exists-p (setq main-file (concat "../" main-file)))
577 (y-or-n-p (concat (expand-file-name main-file)
578 " is main file?:")))
579 (YaTeX-switch-to-buffer main-file setbuf))
580 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
581 (setq YaTeX-parent-file main-file)
582 (find-file main-file))
583 )))
584 nil
585 )
588 (defun YaTeX-guess-parent (command-line)
589 (setq command-line
590 (if (string-match ".*\\s " command-line)
591 (substring command-line (match-end 0))
592 (file-name-nondirectory (buffer-file-name)))
593 command-line
594 (concat (if (string-match "\\(.*\\)\\." command-line)
595 (substring command-line (match-beginning 1) (match-end 1))
596 command-line)
597 ".tex"))
598 )
600 (defun YaTeX-visit-main-other-window ()
601 "Switch to buffer main LaTeX source in other window."
602 (interactive)
603 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
604 (YaTeX-switch-to-buffer-other-window
605 (concat (YaTeX-get-preview-file-name) ".tex")))
606 )
608 (defun YaTeX-get-builtin (key)
609 "Read source built-in command of %# usage."
610 (save-excursion
611 (goto-char (point-min))
612 (if (and (re-search-forward
613 (concat "^" (regexp-quote (concat "%#" key))) nil t)
614 (not (eolp)))
615 (buffer-substring
616 (progn (skip-chars-forward " " (point-end-of-line))(point))
617 (point-end-of-line))
618 nil))
619 )
621 (defun YaTeX-save-buffers ()
622 "Save buffers which is in yatex-mode."
623 (basic-save-buffer)
624 (save-excursion
625 (mapcar '(lambda (buf)
626 (set-buffer buf)
627 (if (and (buffer-file-name buf)
628 (eq major-mode 'yatex-mode)
629 (buffer-modified-p buf)
630 (y-or-n-p (format "Save %s" (buffer-name buf))))
631 (save-buffer buf)))
632 (buffer-list)))
633 )
635 (defun YaTeX-pop-to-buffer (buffer &optional win)
636 (if (setq win (get-buffer-window buffer))
637 (select-window win)
638 (pop-to-buffer buffer))
639 )
641 (defun YaTeX-showup-buffer (buffer &optional func select)
642 "Make BUFFER show up in certain window (but current window)
643 that gives the maximum value by the FUNC. FUNC should take an argument
644 of its window object. Non-nil for optional third argument SELECT selects
645 that window."
646 (or (and (get-buffer-window buffer)
647 (progn (if select (select-window (get-buffer-window buffer)))
648 t))
649 (cond
650 ((> (length (YaTeX-window-list)) 2)
651 (let ((window (selected-window))
652 (list (YaTeX-window-list)) win w (x 0))
653 (if func
654 (while list
655 (setq w (car list))
656 (if (and (not (eq window w))
657 (> (funcall func w) x))
658 (setq win w x (funcall func w)))
659 (setq list (cdr list)))
660 (setq win (get-lru-window)))
661 (select-window win)
662 (switch-to-buffer buffer)
663 (or select (select-window window))))
664 ((= (length (YaTeX-window-list)) 2)
665 (let ((window (selected-window)))
666 (other-window 1)
667 (switch-to-buffer buffer)
668 (or select (select-window window))))
669 (t nil)))
670 )
672 (defun YaTeX-window-list ()
673 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
674 (while (not (eq curw (setq win (next-window win))))
675 (setq wlist (cons win wlist)))
676 wlist)
677 )
678 (provide 'yatexprc)