yatex

changeset 354:5465428f5a68 dev

`[prefix] t e' displays typesetting image in the next window, if possible.
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 22 Dec 2014 00:01:30 +0900
parents 2a72779d9c50
children 6c67a826f266
files yatex.el yatexhlp.el yatexlib.el yatexprc.el
diffstat 4 files changed, 131 insertions(+), 61 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Sun Dec 21 14:20:01 2014 +0900
     1.2 +++ b/yatex.el	Mon Dec 22 00:01:30 2014 +0900
     1.3 @@ -1,6 +1,6 @@
     1.4  ;;; yatex.el --- Yet Another tex-mode for emacs //–ì’¹// -*- coding: sjis -*-
     1.5  ;;; (c)1991-2014 by HIROSE Yuuji.[yuuji@yatex.org]
     1.6 -;;; Last modified Sun Dec 21 14:02:49 2014 on firestorm
     1.7 +;;; Last modified Sun Dec 21 23:13:59 2014 on firestorm
     1.8  ;;; $Id$
     1.9  ;;; The latest version of this software is always available at;
    1.10  ;;; http://www.yatex.org/
    1.11 @@ -676,22 +676,7 @@
    1.12  	    YaTeX-math-mode indent-line-function comment-line-break-function
    1.13  	    comment-start comment-start-skip
    1.14  	    ))
    1.15 -  (cond ((null YaTeX-kanji-code)
    1.16 -	 nil)
    1.17 -	((boundp 'MULE)
    1.18 -	 (set-file-coding-system  YaTeX-coding-system))
    1.19 -	((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
    1.20 -	 (setq buffer-file-coding-system
    1.21 -	       (or (and (fboundp 'set-auto-coding) buffer-file-name
    1.22 -			(save-excursion
    1.23 -			  (goto-char (point-min))
    1.24 -			  (set-auto-coding buffer-file-name (buffer-size))))
    1.25 -		   YaTeX-coding-system)))
    1.26 -	((featurep 'mule)
    1.27 -	 (set-file-coding-system YaTeX-coding-system))
    1.28 -	((boundp 'NEMACS)
    1.29 -	 (make-local-variable 'kanji-fileio-code)
    1.30 -	 (setq kanji-fileio-code YaTeX-kanji-code)))
    1.31 +  (YaTeX-set-file-coding-system YaTeX-kanji-code YaTeX-coding-system)
    1.32    (setq fill-column YaTeX-fill-column
    1.33  	fill-prefix YaTeX-fill-prefix
    1.34  	paragraph-start    YaTeX-paragraph-start
     2.1 --- a/yatexhlp.el	Sun Dec 21 14:20:01 2014 +0900
     2.2 +++ b/yatexhlp.el	Mon Dec 22 00:01:30 2014 +0900
     2.3 @@ -1,7 +1,7 @@
     2.4  ;;; yatexhlp.el --- YaTeX helper with LaTeX commands and macros
     2.5  ;;; 
     2.6  ;;; (c)1994,1998,2004,2014 by HIROSE Yuuji.[yuuji@yatex.org]
     2.7 -;;; Last modified Sun Dec 21 14:14:34 2014 on firestorm
     2.8 +;;; Last modified Sun Dec 21 22:55:07 2014 on firestorm
     2.9  ;;; $Id$
    2.10  
    2.11  ;;; Code:
    2.12 @@ -159,7 +159,7 @@
    2.13  		  (concat "^" (regexp-quote YaTeX-help-delimiter)) nil 1)
    2.14  		 (- (point) (length YaTeX-help-delimiter))))
    2.15        (YaTeX-showup-buffer
    2.16 -       hbuf (function (lambda (x) (nth 3 (window-edges x)))) t)
    2.17 +       hbuf 'YaTeX-showup-buffer-bottom-most t)
    2.18        (set-buffer hbuf)
    2.19        (setq buffer-read-only nil)
    2.20        (if append (goto-char (point-max)) (erase-buffer))
    2.21 @@ -226,7 +226,7 @@
    2.22    (let ((buf (get-buffer-create "**Description**"))
    2.23  	(conf (current-window-configuration)))
    2.24      (YaTeX-showup-buffer
    2.25 -     buf (function (lambda (x) (nth 3 (window-edges x)))) t)
    2.26 +     buf 'YaTeX-showup-buffer-bottom-most t)
    2.27      (make-local-variable 'YaTeX-help-file-current)
    2.28      (make-local-variable 'YaTeX-help-command-current)
    2.29      (make-local-variable 'YaTeX-help-saved-config)
    2.30 @@ -266,8 +266,7 @@
    2.31  	(sw (selected-window))
    2.32  	(head (concat "^" (regexp-quote YaTeX-help-delimiter)))
    2.33  	pt command)
    2.34 -    (YaTeX-showup-buffer
    2.35 -     ab (function (lambda (x) (nth 3 (window-edges x)))))
    2.36 +    (YaTeX-showup-buffer ab 'YaTeX-showup-buffer-bottom-most)
    2.37      (select-window (get-buffer-window ab))
    2.38      (set-buffer ab)			;assertion
    2.39      (setq buffer-read-only nil)
     3.1 --- a/yatexlib.el	Sun Dec 21 14:20:01 2014 +0900
     3.2 +++ b/yatexlib.el	Mon Dec 22 00:01:30 2014 +0900
     3.3 @@ -1,7 +1,7 @@
     3.4  ;;; yatexlib.el --- YaTeX and yahtml common libraries
     3.5  ;;; 
     3.6  ;;; (c)1994-2013 by HIROSE Yuuji.[yuuji@yatex.org]
     3.7 -;;; Last modified Sun Dec 21 14:15:24 2014 on firestorm
     3.8 +;;; Last modified Sun Dec 21 23:55:30 2014 on firestorm
     3.9  ;;; $Id$
    3.10  
    3.11  ;;; Code:
    3.12 @@ -481,7 +481,7 @@
    3.13  (defun point-end-of-line ()
    3.14    (save-excursion (end-of-line)(point)))
    3.15  
    3.16 -
    3.17 +(defun YaTeX-showup-buffer-bottom-most (x) (nth 3 (window-edges x)))
    3.18  ;;;###autoload
    3.19  (defun YaTeX-showup-buffer (buffer &optional func select)
    3.20    "Make BUFFER show up in certain window (but current window)
    3.21 @@ -514,6 +514,9 @@
    3.22  	  ;(other-window 1);This does not work properly on Emacs-19
    3.23  	  (select-window (get-lru-window))
    3.24  	  (switch-to-buffer buffer)
    3.25 +	  (if (< (window-height) (/ YaTeX-default-pop-window-height 2))
    3.26 +	      (enlarge-window (- YaTeX-default-pop-window-height
    3.27 +				 (window-height))))
    3.28  	  (or select (select-window window)))
    3.29  	 (t				;if one-window
    3.30  	  (cond
    3.31 @@ -780,6 +783,25 @@
    3.32  		     (throw 'found (car l)))
    3.33  		 (setq l (cdr l)))))))))
    3.34  
    3.35 +(defun YaTeX-set-file-coding-system (code coding)
    3.36 +  "Set current buffer's coding system according to symbol."
    3.37 +  (cond ((null code)
    3.38 +	 nil)
    3.39 +	((boundp 'MULE)
    3.40 +	 (set-file-coding-system  coding))
    3.41 +	((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
    3.42 +	 (setq buffer-file-coding-system
    3.43 +	       (or (and (fboundp 'set-auto-coding) buffer-file-name
    3.44 +			(save-excursion
    3.45 +			  (goto-char (point-min))
    3.46 +			  (set-auto-coding buffer-file-name (buffer-size))))
    3.47 +		   coding)))
    3.48 +	((featurep 'mule)
    3.49 +	 (set-file-coding-system coding))
    3.50 +	((boundp 'NEMACS)
    3.51 +	 (make-local-variable 'kanji-fileio-code)
    3.52 +	 (setq kanji-fileio-code code))))
    3.53 +
    3.54  (defun YaTeX-insert-file-contents (file visit &optional beg end)
    3.55    (cond
    3.56     ((and (string< "19" emacs-version) (not (featurep 'xemacs)))
     4.1 --- a/yatexprc.el	Sun Dec 21 14:20:01 2014 +0900
     4.2 +++ b/yatexprc.el	Mon Dec 22 00:01:30 2014 +0900
     4.3 @@ -1,7 +1,7 @@
     4.4  ;;; yatexprc.el --- YaTeX process handler
     4.5  ;;; 
     4.6  ;;; (c)1993-2013 by HIROSE Yuuji.[yuuji@yatex.org]
     4.7 -;;; Last modified Sun Dec 21 13:56:03 2014 on firestorm
     4.8 +;;; Last modified Mon Dec 22 00:00:27 2014 on firestorm
     4.9  ;;; $Id$
    4.10  
    4.11  ;;; Code:
    4.12 @@ -64,6 +64,7 @@
    4.13    (save-excursion
    4.14      (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer))
    4.15  	  (map YaTeX-typesetting-mode-map)
    4.16 +	  (background (string-match "\\*bg:" buffer))
    4.17  	  (outcode
    4.18  	   (cond ((eq major-mode 'yatex-mode) YaTeX-coding-system)
    4.19  		 ((eq major-mode 'yahtml-mode) yahtml-kanji-code))))
    4.20 @@ -78,8 +79,10 @@
    4.21        (setq execdir default-directory)
    4.22        ;;Select lower-most window if there are more than 2 windows and
    4.23        ;;typeset buffer not seen.
    4.24 -      (YaTeX-showup-buffer
    4.25 -       buffer (function (lambda (x) (nth 3 (window-edges x)))))
    4.26 +      (if background
    4.27 +	  nil				;do not showup
    4.28 +	(YaTeX-showup-buffer
    4.29 +	 buffer 'YaTeX-showup-buffer-bottom-most))
    4.30        (set-buffer (get-buffer-create buffer))
    4.31        (setq default-directory execdir)
    4.32        (cd execdir)
    4.33 @@ -137,17 +140,19 @@
    4.34  	(insert " ")
    4.35  	(set-marker (process-mark YaTeX-typeset-process) (1- (point))))
    4.36        (if (bolp) (forward-line -1))	;what for?
    4.37 -      (if (and YaTeX-emacs-19 window-system)
    4.38 -	  (let ((win (get-buffer-window buffer t)) owin)
    4.39 -	    (select-frame (window-frame win))
    4.40 -	    (setq owin (selected-window))
    4.41 -	    (select-window win)
    4.42 -	    (goto-char (point-max))
    4.43 -	    (recenter -1)
    4.44 -	    (select-window owin))
    4.45 -	(select-window (get-buffer-window buffer))
    4.46 -	(goto-char (point-max))
    4.47 -	(recenter -1))
    4.48 +      (cond
    4.49 +       (background nil)
    4.50 +       ((and YaTeX-emacs-19 window-system)
    4.51 +	(let ((win (get-buffer-window buffer t)) owin)
    4.52 +	  (select-frame (window-frame win))
    4.53 +	  (setq owin (selected-window))
    4.54 +	  (select-window win)
    4.55 +	  (goto-char (point-max))
    4.56 +	  (recenter -1)
    4.57 +	    (select-window owin)))
    4.58 +       (t (select-window (get-buffer-window buffer))
    4.59 +	  (goto-char (point-max))
    4.60 +	  (recenter -1)))
    4.61        (select-window window)
    4.62        (switch-to-buffer cb)
    4.63        (YaTeX-remove-nonstopmode))))
    4.64 @@ -250,7 +255,7 @@
    4.65  		       (setq tobecalled thiscmd shortname "+typeset"))
    4.66  		      (t
    4.67  		       nil))			  ;no need to call any process
    4.68 -		     (progn
    4.69 +		     (progn ;;Something occurs to call next command
    4.70  		       (insert
    4.71  			(format
    4.72  			 "===!!! %s !!!===\n"
    4.73 @@ -274,18 +279,20 @@
    4.74  		   (cond
    4.75  		    ((and ppcmd (string-match "finish" mes))
    4.76  		     (insert (format "=======> Success! Calling %s\n" ppcmd))
    4.77 -		     (setq mode-name	; set process name
    4.78 -			   (concat
    4.79 -			    mode-name "+"
    4.80 -			    (substring ppcmd 0 (string-match " " ppcmd))))
    4.81 +		     (if (symbolp ppcmd)
    4.82 +			 (funcall ppcmd)
    4.83 +		       (setq mode-name	; set process name
    4.84 +			     (concat
    4.85 +			      mode-name "+"
    4.86 +			      (substring ppcmd 0 (string-match " " ppcmd))))
    4.87  					; to reach here, 'start-process exists on this emacsen
    4.88 -		     (set-process-sentinel
    4.89 -		      (start-process
    4.90 -		       mode-name
    4.91 -		       pbuf		; Use this buffer twice.
    4.92 -		       shell-file-name YaTeX-shell-command-option
    4.93 -		       ppcmd)
    4.94 -		      'YaTeX-typeset-sentinel))
    4.95 +		       (set-process-sentinel
    4.96 +			(start-process
    4.97 +			 mode-name
    4.98 +			 pbuf		; Use this buffer twice.
    4.99 +			 shell-file-name YaTeX-shell-command-option
   4.100 +			 ppcmd)
   4.101 +			'YaTeX-typeset-sentinel)))
   4.102  		    (t ;pull back original mode-name
   4.103  		     (setq mode-name "typeset"))))
   4.104  		 (forward-char 1))
   4.105 @@ -299,7 +306,7 @@
   4.106  (defvar YaTeX-texput-file "texput.tex"
   4.107    "*File name for temporary file of typeset-region.")
   4.108  
   4.109 -(defun YaTeX-typeset-region ()
   4.110 +(defun YaTeX-typeset-region (&optional pp)
   4.111    "Paste the region to the file `texput.tex' and execute typesetter.
   4.112  The region is specified by the rule:
   4.113  	(1)If keyword `%#BEGIN' is found in the upper direction from (point).
   4.114 @@ -310,17 +317,21 @@
   4.115  	(2)If no `%#BEGIN' usage is found before the (point),
   4.116  		->Assume the text between current (point) and (mark) as region.
   4.117  DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
   4.118 -operation to the region."
   4.119 +operation to the region.
   4.120 +Optional second argument PP specifies post-processor command which will be
   4.121 +called with one argument of current file name whitout extension."
   4.122    (interactive)
   4.123    (save-excursion
   4.124      (let*
   4.125  	((end "") typeout ;Type out message that tells the method of cutting.
   4.126  	 (texput YaTeX-texput-file)
   4.127 +	 (texputroot (substring texput 0 (string-match "\\.tex$" texput)))
   4.128  	 (cmd (concat (YaTeX-get-latex-command nil) " " texput))
   4.129  	 (buffer (current-buffer)) opoint preamble (subpreamble "") main
   4.130  	 (hilit-auto-highlight nil)	;for Emacs19 with hilit19
   4.131 +	 ppcmd
   4.132  	 reg-begin reg-end lineinfo)
   4.133 -
   4.134 +      (setq ppcmd (if (stringp pp) (concat pp " " texputroot) pp))
   4.135        (save-excursion
   4.136  	(if (search-backward "%#BEGIN" nil t)
   4.137  	    (progn
   4.138 @@ -368,9 +379,11 @@
   4.139  	(set-buffer (find-file-noselect texput)))
   4.140        ;;(find-file YaTeX-texput-file)
   4.141        (erase-buffer)
   4.142 +      (YaTeX-set-file-coding-system YaTeX-kanji-code YaTeX-coding-system)
   4.143        (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop)
   4.144  	  (insert "\\nonstopmode{}\n"))
   4.145 -      (insert preamble "\n" subpreamble "\n")
   4.146 +      (insert preamble "\n" subpreamble "\n"
   4.147 +	      "\\pagestyle{empty}\n\\thispagestyle{empty}\n")
   4.148        (setq lineinfo (list (count-lines 1 (point-end-of-line)) lineinfo))
   4.149        (insert-buffer-substring buffer reg-begin reg-end)
   4.150        (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   4.151 @@ -378,18 +391,70 @@
   4.152        (basic-save-buffer)
   4.153        (kill-buffer (current-buffer))
   4.154        (set-buffer main)		;return to parent file or itself.
   4.155 -      (YaTeX-typeset cmd YaTeX-typeset-buffer)
   4.156 +      (YaTeX-typeset cmd YaTeX-typeset-buffer nil nil ppcmd)
   4.157        (switch-to-buffer buffer)		;for Emacs-19
   4.158        (put 'dvi2-command 'region t)
   4.159        (put 'dvi2-command 'file buffer)
   4.160        (put 'dvi2-command 'offset lineinfo))))
   4.161  
   4.162 +(defvar YaTeX-typeset-conv2image-process nil "Process of conv2image chain")
   4.163 +(defun YaTeX-typeset-conv2image-chain ()
   4.164 +  (let*((proc (or YaTeX-typeset-process YaTeX-typeset-conv2image-process))
   4.165 +	(prevname (process-name proc))
   4.166 +	(target "texput.jpg")
   4.167 +	(math (get 'YaTeX-typeset-conv2image-chain 'math))
   4.168 +	(conv (format "convert -density %d - %s" (if math 250 100) target))
   4.169 +	(chain (list (format "dvips -E -o - texput|%s" conv)))
   4.170 +	(curproc (member prevname chain))
   4.171 +	img)
   4.172 +    (if (not (= (process-exit-status proc) 0))
   4.173 +	(progn
   4.174 +	  (YaTeX-showup-buffer		;nevers comes here(?)
   4.175 +	   (current-buffer) 'YaTeX-showup-buffer-bottom-most)
   4.176 +	  (message "Region typesetting FAILED"))
   4.177 +      (setq command
   4.178 +	    (if curproc (car (cdr-safe curproc)) (car chain)))
   4.179 +      (if command
   4.180 +	  (progn
   4.181 +	    (insert (format "Calling `%s'...\n" command))
   4.182 +	    (set-process-sentinel
   4.183 +	     (setq YaTeX-typeset-conv2image-process
   4.184 +		   (start-process
   4.185 +		    command
   4.186 +		    (current-buffer)
   4.187 +		    shell-file-name YaTeX-shell-command-option command))
   4.188 +	     'YaTeX-typeset-sentinel)
   4.189 +	    (put 'YaTeX-typeset-process 'ppcmd
   4.190 +		 (cons (cons (get-buffer-process (current-buffer))
   4.191 +			     'YaTeX-typeset-conv2image-chain)
   4.192 +		       (get 'YaTeX-typeset-process 'ppcmd))))
   4.193 +	;; After all chain executed, display image in current window
   4.194 +	(YaTeX-showup-buffer
   4.195 +	 (get-buffer-create " *YaTeX-region-image*")
   4.196 +	 'YaTeX-showup-buffer-bottom-most t)
   4.197 +	(remove-images (point-min) (point-max))
   4.198 +	(erase-buffer)
   4.199 +	;(put-image (create-image (expand-file-name target)) (point))
   4.200 +	(insert-image-file target)
   4.201 +	(goto-char (point-min))
   4.202 +	(setq img (plist-get (text-properties-at (point)) 'intangible))
   4.203 +	(if img
   4.204 +	    (let ((height (cdr (image-size img))))
   4.205 +	      (enlarge-window
   4.206 +	       (- (ceiling (min height (/ (frame-height) 2)))
   4.207 +		  (window-height)))))))))
   4.208 +
   4.209  (defun YaTeX-typeset-environment ()
   4.210    "Typeset current math environment"
   4.211    (interactive)
   4.212    (save-excursion
   4.213 -    (YaTeX-mark-environment)
   4.214 -    (YaTeX-typeset-region)))
   4.215 +    (let ((math (YaTeX-in-math-mode-p)))
   4.216 +      (YaTeX-mark-environment)
   4.217 +      (if (and (featurep 'image) window-system)
   4.218 +	  (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer)))
   4.219 +	    (put 'YaTeX-typeset-conv2image-chain 'math math)
   4.220 +	    (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain))
   4.221 +	(YaTeX-typeset-region)))))
   4.222  
   4.223  (defun YaTeX-typeset-buffer (&optional pp)
   4.224    "Typeset whole buffer.
   4.225 @@ -549,8 +614,7 @@
   4.226        (setq default-directory (cd (or basedir df)))
   4.227        (erase-buffer)
   4.228        (insert (format "Calling `%s'..." command))
   4.229 -      (YaTeX-showup-buffer
   4.230 -       buffer (function (lambda (x) (nth 3 (window-edges x)))))
   4.231 +      (YaTeX-showup-buffer buffer 'YaTeX-showup-buffer-bottom-most)
   4.232        (if (not (fboundp 'start-process))
   4.233  	  (call-process
   4.234  	   shell-file-name nil buffer nil YaTeX-shell-command-option command)
   4.235 @@ -652,7 +716,7 @@
   4.236      (if YaTeX-dos (setq preview-file (expand-file-name preview-file)))
   4.237      (let ((pbuffer "*dvi-preview*") (dir default-directory))
   4.238        (YaTeX-showup-buffer
   4.239 -       pbuffer (function (lambda (x) (nth 3 (window-edges x)))))
   4.240 +       pbuffer 'YaTeX-showup-buffer-bottom-most)
   4.241        (set-buffer (get-buffer-create pbuffer))
   4.242        (erase-buffer)
   4.243        (setq default-directory dir)	;for 18
   4.244 @@ -1032,7 +1096,7 @@
   4.245        (YaTeX-visit-main t) ;;change execution directory
   4.246        (setq dir default-directory)
   4.247        (YaTeX-showup-buffer
   4.248 -       lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
   4.249 +       lbuffer 'YaTeX-showup-buffer-bottom-most)
   4.250        (set-buffer (get-buffer-create lbuffer))
   4.251        (erase-buffer)
   4.252        (cd dir)				;for 19