yatex

changeset 375:afb8cb06b1d4 dev

First trial of on-the-fly image-preview
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 31 Dec 2014 23:00:01 +0900
parents 9b3093c0c181
children 1bbd0c2b340f
files yatex.el yatexprc.el
diffstat 2 files changed, 82 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Tue Dec 30 09:19:04 2014 +0900
     1.2 +++ b/yatex.el	Wed Dec 31 23:00:01 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 28 23:31:32 2014 on firestorm
     1.7 +;;; Last modified Wed Dec 31 18:50:06 2014 on sdr
     1.8  ;;; $Id$
     1.9  ;;; The latest version of this software is always available at;
    1.10  ;;; http://www.yatex.org/
    1.11 @@ -8,7 +8,7 @@
    1.12  ;;; Code:
    1.13  (require 'comment)
    1.14  (require 'yatexlib)
    1.15 -(defconst YaTeX-revision-number "1.78.2"
    1.16 +(defconst YaTeX-revision-number "1.78.3"
    1.17    "Revision number of running yatex.el")
    1.18  
    1.19  ;---------- Local variables ----------
     2.1 --- a/yatexprc.el	Tue Dec 30 09:19:04 2014 +0900
     2.2 +++ b/yatexprc.el	Wed Dec 31 23:00:01 2014 +0900
     2.3 @@ -1,7 +1,7 @@
     2.4  ;;; yatexprc.el --- YaTeX process handler
     2.5  ;;; 
     2.6  ;;; (c)1993-2014 by HIROSE Yuuji.[yuuji@yatex.org]
     2.7 -;;; Last modified Tue Dec 30 09:17:29 2014 on sdr
     2.8 +;;; Last modified Wed Dec 31 22:42:56 2014 on sdr
     2.9  ;;; $Id$
    2.10  
    2.11  ;;; Code:
    2.12 @@ -527,7 +527,11 @@
    2.13  	      (let ((height (cdr (image-size img))))
    2.14  		(enlarge-window
    2.15  		 (- (ceiling (min height (/ (frame-height) 2)))
    2.16 -		    (window-height))))))
    2.17 +		    (window-height)))))
    2.18 +	  ;; Remember elapsed time, which will be threshold in auto-preview
    2.19 +	  (put 'YaTeX-typeset-conv2image-chain 'elapse
    2.20 +	       (YaTeX-elapsed-time
    2.21 +		(get 'YaTeX-typeset-conv2image-chain 'start) (current-time))))
    2.22  	 (t
    2.23  	  ;; Without direct image, display image with image viewer
    2.24  	  (YaTeX-system
    2.25 @@ -537,27 +541,96 @@
    2.26  	  )
    2.27  	 )))))
    2.28  
    2.29 +
    2.30 +(defvar YaTeX-typeset-environment-timer nil)
    2.31 +(defun YaTeX-typeset-environment-timer ()
    2.32 +  "Update preview image in the 
    2.33 +Plist: '(buf begPoint endPoint precedingChar 2precedingChar Substring time)"
    2.34 +  (let*((plist (get 'YaTeX-typeset-environment-timer 'laststate))
    2.35 +	(b (nth 0 plist))
    2.36 +	(s (nth 1 plist))
    2.37 +	(e (nth 2 plist))
    2.38 +	(p (nth 3 plist))
    2.39 +	(q (nth 4 plist))
    2.40 +	(st (nth 5 plist))
    2.41 +	(tm (nth 6 plist))
    2.42 +	(thresh (* 2 (or (get 'YaTeX-typeset-conv2image-chain 'elapse) 1))))
    2.43 +    (cond
    2.44 +     ;; In minibuffer, do nothing
    2.45 +     ((minibuffer-window-active-p (selected-window)) nil)
    2.46 +     ;; If point went out from last environment, cancel timer
    2.47 +     ;;;((and (message "s=%d, e=%d, p=%d" s e (point)) nil))
    2.48 +     ((or (not (eq b (window-buffer (selected-window))))
    2.49 +	  (< (point) s)
    2.50 +	  (> (point) e))
    2.51 +      (YaTeX-typeset-environment-cancel-auto))
    2.52 +     ;;;((and (message "e=%d, p=%d t=%s" e (point) (current-time)) nil))
    2.53 +     ;; If recently called, hold
    2.54 +     ((< (YaTeX-elapsed-time tm (current-time)) thresh)
    2.55 +      nil)
    2.56 +     ;; If condition changed from last call, do it
    2.57 +     ((and (/= p (preceding-char))
    2.58 +	   (/= q (char-after (- (point) 1)))
    2.59 +	   (not (string= st (YaTeX-buffer-substring s e))))
    2.60 +      (YaTeX-typeset-environment)))))
    2.61 +
    2.62  (defun YaTeX-typeset-environment ()
    2.63    "Typeset current environment or paragraph.
    2.64  If region activated, use it."
    2.65    (interactive)
    2.66    (save-excursion
    2.67 -    (let ((math (YaTeX-in-math-mode-p)))
    2.68 +    (let ((math (YaTeX-in-math-mode-p)) usetimer)
    2.69        (cond
    2.70         ((and (fboundp 'region-active-p) (region-active-p))
    2.71  	nil)				;if region is active, use it
    2.72 -       (math (YaTeX-mark-environment))
    2.73 +       (math (setq usetimer t) (YaTeX-mark-environment))
    2.74         ((equal (or (YaTeX-inner-environment t) "document") "document")
    2.75  	(mark-paragraph))
    2.76 -       (t (YaTeX-mark-environment)))
    2.77 +       (t (setq usetimer t) (YaTeX-mark-environment)))
    2.78        (if YaTeX-use-image-preview
    2.79 -	  (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer)))
    2.80 +	  (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer))
    2.81 +		(b (region-beginning)) (e (region-end)))
    2.82  	    (put 'YaTeX-typeset-conv2image-chain 'math math)
    2.83  	    (put 'YaTeX-typeset-conv2image-chain 'srctype nil)
    2.84  	    (put 'YaTeX-typeset-conv2image-chain 'win (selected-window))
    2.85 -	    (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain))
    2.86 +	    (put 'YaTeX-typeset-conv2image-chain 'start (current-time))
    2.87 +	    (put 'YaTeX-typeset-environment-timer 'laststate
    2.88 +		 (list (current-buffer) b e (preceding-char)
    2.89 +		       (char-after (- (point) 2))
    2.90 +		       (YaTeX-buffer-substring b e)
    2.91 +		       (current-time)))
    2.92 +	    (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain)
    2.93 +	    (if usetimer (YaTeX-typeset-environment-auto)))
    2.94  	(YaTeX-typeset-region)))))
    2.95  
    2.96 +(defvar YaTeX-on-the-fly-preview-image (string-to-number "0.1")
    2.97 +  "*Control the on-the-fly update of preview environment by an image.
    2.98 +Nil disables on-the-fly update.  Otherwise on-the-fly update is enabled
    2.99 +with update interval specified by this value.")
   2.100 +
   2.101 +(defun YaTeX-typeset-environment-auto ()
   2.102 +  "Turn on on-the-fly preview-image"
   2.103 +  (if YaTeX-typeset-environment-timer
   2.104 +      nil
   2.105 +    (setq YaTeX-typeset-environment-timer
   2.106 +	  (run-with-idle-timer
   2.107 +	   (max (string-to-number "0.1")
   2.108 +		(cond
   2.109 +		 ((numberp YaTeX-on-the-fly-preview-image) 
   2.110 +		  YaTeX-on-the-fly-preview-image)
   2.111 +		 ((stringp YaTeX-on-the-fly-preview-image)
   2.112 +		  (string-to-number YaTeX-on-the-fly-preview-image))
   2.113 +		 (t 1)))
   2.114 +	   t 'YaTeX-typeset-environment-timer))))
   2.115 +
   2.116 +(defun YaTeX-typeset-environment-cancel-auto ()
   2.117 +  "Cancel typeset-environment timer."
   2.118 +  (interactive)
   2.119 +  (cancel-timer YaTeX-typeset-environment-timer)
   2.120 +  (setq YaTeX-typeset-environment-timer nil)
   2.121 +  (message "Auto-preview canceled"))
   2.122 +
   2.123 +
   2.124  (defun YaTeX-typeset-buffer (&optional pp)
   2.125    "Typeset whole buffer.
   2.126  If %#! usage says other buffer is main text,