comparison yatexprc.el @ 86:f14ec50103d0

as of 2009/9/28
author yuuji@gentei.org
date Mon, 28 Sep 2009 07:56:08 +0900
parents 9b4354af748c
children ce2deaceb818
comparison
equal deleted inserted replaced
85:42c373ac73af 86:f14ec50103d0
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX process handler. 2 ;;; YaTeX process handler.
3 ;;; yatexprc.el 3 ;;; yatexprc.el
4 ;;; (c)1993-2006 by HIROSE Yuuji.[yuuji@yatex.org] 4 ;;; (c)1993-2007 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Sun Dec 24 15:12:50 2006 on firestorm 5 ;;; Last modified Thu May 7 13:47:28 2009 on firestorm
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 ;(require 'yatex) 8 ;(require 'yatex)
9 (require 'yatexlib) 9 (require 'yatexlib)
10 10
311 (put 'dvi2-command 'region nil))) 311 (put 'dvi2-command 'region nil)))
312 312
313 (defvar YaTeX-call-command-history nil 313 (defvar YaTeX-call-command-history nil
314 "Holds history list of YaTeX-call-command-on-file.") 314 "Holds history list of YaTeX-call-command-on-file.")
315 (put 'YaTeX-call-command-history 'no-default t) 315 (put 'YaTeX-call-command-history 'no-default t)
316 (defun YaTeX-call-command-on-file (base-cmd buffer) 316 (defun YaTeX-call-command-on-file (base-cmd buffer &optional file)
317 "Call external command BASE-CMD int the BUFFER.
318 By default, pass the basename of current file. Optional 3rd argument
319 FILE changes the default file name."
317 (YaTeX-save-buffers) 320 (YaTeX-save-buffers)
318 (YaTeX-typeset 321 (YaTeX-typeset
319 (read-string-with-history 322 (read-string-with-history
320 "Call command: " 323 "Call command: "
321 (concat base-cmd " " 324 (concat base-cmd " "
322 (let ((me (file-name-nondirectory buffer-file-name))) 325 (let ((me (file-name-nondirectory (or file buffer-file-name))))
323 (if (string-match "\\.tex" me) 326 (if (string-match "\\.tex" me)
324 (substring me 0 (match-beginning 0)) 327 (substring me 0 (match-beginning 0))
325 me))) 328 me)))
326 'YaTeX-call-command-history) 329 'YaTeX-call-command-history)
327 buffer)) 330 buffer))
328 331
329 (defun YaTeX-bibtex-buffer (cmd) 332 (defun YaTeX-bibtex-buffer (cmd)
330 "Pass the bibliography data of editing file to bibtex." 333 "Pass the bibliography data of editing file to bibtex."
331 (interactive) 334 (interactive)
332 (YaTeX-save-buffers) 335 (YaTeX-save-buffers)
333 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" )) 336 (let ((main (or YaTeX-parent-file
337 (progn (YaTeX-visit-main t) buffer-file-name))))
338 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" main)))
334 339
335 (defun YaTeX-kill-typeset-process (proc) 340 (defun YaTeX-kill-typeset-process (proc)
336 "Kill process PROC after sending signal to PROC. 341 "Kill process PROC after sending signal to PROC.
337 PROC should be process identifier." 342 PROC should be process identifier."
338 (cond 343 (cond
421 "Holds minibuffer history of file to preview.") 426 "Holds minibuffer history of file to preview.")
422 (put 'YaTeX-preview-file-history 'no-default t) 427 (put 'YaTeX-preview-file-history 'no-default t)
423 (defun YaTeX-preview (preview-command preview-file) 428 (defun YaTeX-preview (preview-command preview-file)
424 "Execute xdvi (or other) to tex-preview." 429 "Execute xdvi (or other) to tex-preview."
425 (interactive 430 (interactive
426 (list 431 (let* ((command (read-string-with-history
427 (read-string-with-history 432 "Preview command: "
428 "Preview command: " 433 (YaTeX-replace-format
429 (YaTeX-replace-format 434 (or (YaTeX-get-builtin "PREVIEW") dvi2-command)
430 (or (YaTeX-get-builtin "PREVIEW") dvi2-command) 435 "p" (format (cond
431 "p" (format (cond 436 (YaTeX-dos "-y:%s")
432 (YaTeX-dos "-y:%s") 437 (t "-paper %s"))
433 (t "-paper %s")) 438 (YaTeX-get-paper-type)))
434 (YaTeX-get-paper-type))) 439 'YaTeX-preview-command-history))
435 'YaTeX-preview-command-history) 440 (file (read-string-with-history
436 (read-string-with-history 441 "Preview file: "
437 "Preview file: " 442 (if (get 'dvi2-command 'region)
438 (if (get 'dvi2-command 'region) 443 (substring YaTeX-texput-file
439 (substring YaTeX-texput-file 444 0 (rindex YaTeX-texput-file ?.))
440 0 (rindex YaTeX-texput-file ?.)) 445 (YaTeX-get-preview-file-name command))
441 (YaTeX-get-preview-file-name)) 446 'YaTeX-preview-file-history)))
442 'YaTeX-preview-file-history))) 447 (list command file)))
443 (if YaTeX-dos (setq preview-file (expand-file-name preview-file)))
444 (setq dvi2-command preview-command) ;`dvi2command' is buffer local 448 (setq dvi2-command preview-command) ;`dvi2command' is buffer local
445 (save-excursion 449 (save-excursion
446 (YaTeX-visit-main t) 450 (YaTeX-visit-main t)
451 (if YaTeX-dos (setq preview-file (expand-file-name preview-file)))
447 (let ((pbuffer "*dvi-preview*") (dir default-directory)) 452 (let ((pbuffer "*dvi-preview*") (dir default-directory))
448 (YaTeX-showup-buffer 453 (YaTeX-showup-buffer
449 pbuffer (function (lambda (x) (nth 3 (window-edges x))))) 454 pbuffer (function (lambda (x) (nth 3 (window-edges x)))))
450 (set-buffer (get-buffer-create pbuffer)) 455 (set-buffer (get-buffer-create pbuffer))
451 (erase-buffer) 456 (erase-buffer)
465 (call-process shell-file-name "con" "*dvi-preview*" nil 470 (call-process shell-file-name "con" "*dvi-preview*" nil
466 YaTeX-shell-command-option 471 YaTeX-shell-command-option
467 (concat preview-command " " preview-file))) 472 (concat preview-command " " preview-file)))
468 (t ;if UNIX 473 (t ;if UNIX
469 (set-process-buffer 474 (set-process-buffer
470 (start-process "preview" "*dvi-preview*" shell-file-name 475 (let ((process-connection-type nil))
471 YaTeX-shell-command-option 476 (start-process "preview" "*dvi-preview*" shell-file-name
472 (concat preview-command " " preview-file)) 477 YaTeX-shell-command-option
478 (concat preview-command " " preview-file)))
473 (get-buffer pbuffer)) 479 (get-buffer pbuffer))
474 (message 480 (message
475 (concat "Starting " preview-command 481 (concat "Starting " preview-command
476 " to preview " preview-file))))))) 482 " to preview " preview-file)))))))
477 483
660 (widen)))) 666 (widen))))
661 667
662 (defvar YaTeX-dvi2-command-ext-alist 668 (defvar YaTeX-dvi2-command-ext-alist
663 '(("[agx]dvi\\|dviout" . ".dvi") 669 '(("[agx]dvi\\|dviout" . ".dvi")
664 ("ghostview\\|gv" . ".ps") 670 ("ghostview\\|gv" . ".ps")
665 ("acroread\\|pdf\\|Preview\\|TeXShop" . ".pdf"))) 671 ("acroread\\|pdf\\|Preview\\|TeXShop\\|Skim" . ".pdf")))
666 672
667 (defun YaTeX-get-preview-file-name () 673 (defun YaTeX-get-preview-file-name (&optional preview-command)
668 "Get file name to preview by inquiring YaTeX-get-latex-command" 674 "Get file name to preview by inquiring YaTeX-get-latex-command"
675 (if (null preview-command) (setq preview-command dvi2-command))
669 (let* ((latex-cmd (YaTeX-get-latex-command t)) 676 (let* ((latex-cmd (YaTeX-get-latex-command t))
670 (rin (rindex latex-cmd ? )) 677 (rin (rindex latex-cmd ? ))
671 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) "")) 678 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
672 (r (YaTeX-assoc-regexp dvi2-command YaTeX-dvi2-command-ext-alist)) 679 (r (YaTeX-assoc-regexp preview-command YaTeX-dvi2-command-ext-alist))
673 (ext (if r (cdr r) "")) 680 (ext (if r (cdr r) ""))
674 (period)) 681 (period))
675 (concat 682 (concat
676 (if (string= fname "") 683 (if (string= fname "")
677 (setq fname (substring (file-name-nondirectory 684 (setq fname (substring (file-name-nondirectory
778 ((not (fboundp 'start-process)) 785 ((not (fboundp 'start-process))
779 (call-process shell-file-name "con" "*dvi-printing*" nil 786 (call-process shell-file-name "con" "*dvi-printing*" nil
780 YaTeX-shell-command-option cmd)) 787 YaTeX-shell-command-option cmd))
781 (t 788 (t
782 (set-process-buffer 789 (set-process-buffer
783 (start-process "print" "*dvi-printing*" shell-file-name 790 (let ((process-connection-type nil))
784 YaTeX-shell-command-option cmd) 791 (start-process "print" "*dvi-printing*" shell-file-name
792 YaTeX-shell-command-option cmd))
785 (get-buffer lbuffer)) 793 (get-buffer lbuffer))
786 (message "Starting printing command: %s..." cmd)))))) 794 (message "Starting printing command: %s..." cmd))))))
787 795
788 (defun YaTeX-main-file-p () 796 (defun YaTeX-main-file-p ()
789 "Return if current buffer is main LaTeX source." 797 "Return if current buffer is main LaTeX source."

yatex.org