yatex

changeset 186:61996cd55816 dev

Ensure point-entered/point-left hook should not run continuously.
author yuuji@gentei.org
date Thu, 01 Dec 2011 23:02:36 +0900
parents 85e57c4b27a2
children 2f91947a43a1
files yatex.el
diffstat 1 files changed, 38 insertions(+), 18 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Wed Nov 30 14:22:46 2011 +0900
     1.2 +++ b/yatex.el	Thu Dec 01 23:02:36 2011 +0900
     1.3 @@ -2,7 +2,7 @@
     1.4  ;;; Yet Another tex-mode for emacs - //–ì’¹//
     1.5  ;;; yatex.el rev. 1.74.5
     1.6  ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org]
     1.7 -;;; Last modified Wed Nov 30 14:22:06 2011 on duke
     1.8 +;;; Last modified Thu Dec  1 23:00:13 2011 on firestorm
     1.9  ;;; $Id$
    1.10  ;;; The latest version of this software is always available at;
    1.11  ;;; http://www.yatex.org/
    1.12 @@ -1257,7 +1257,7 @@
    1.13  (defun YaTeX-jmode ()
    1.14    (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
    1.15        (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
    1.16 -      (and (boundp 'skk-mode) skk-mode)
    1.17 +      (and (boundp 'skk-mode) skk-mode (not skk-latin-mode))
    1.18        (and (boundp 'default-input-method) default-input-method
    1.19  	   current-input-method)))
    1.20  
    1.21 @@ -1269,7 +1269,17 @@
    1.22  	(egg:toggle-egg-mode-on-off) t)
    1.23         ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
    1.24  	(cond
    1.25 -	 ((fboundp 'skk-latin-mode)	(skk-latin-mode t))
    1.26 +	 ((fboundp 'skk-latin-mode)
    1.27 +	  (or (and (boundp 'skk-henkan-mode) skk-henkan-mode)
    1.28 +	      (and (boundp 'skk-henkan-on)
    1.29 +		   (or skk-henkan-mode skk-henkan-active))
    1.30 +	      (and (boundp 'j-henkan-on)
    1.31 +		   (or j-henkan-on j-henkan-active))
    1.32 +	      ;; Deactivate jmode if henkan-mode is not running.
    1.33 +	      ;; Suggested by tt.tetsuo.tsukamoto.
    1.34 +	      (progn
    1.35 +		(put 'YaTeX-jmode-on 'skkkata skk-katakana)
    1.36 +		(skk-latin-mode t))))
    1.37  	 ((fboundp 'skk-mode-off)	(skk-mode-off))
    1.38  	 (t (j-mode-off)))
    1.39  	t)
    1.40 @@ -1286,7 +1296,10 @@
    1.41      (and (not egg:*mode-on*) (not egg:*input-mode*)
    1.42  	 (egg:toggle-egg-mode-on-off)))
    1.43     ((and (fboundp 'skk-mode) (boundp 'skk-mode))
    1.44 -    (if (not skk-mode) (skk-mode 1)))
    1.45 +    (if (get 'YaTeX-jmode-on 'skkkata)
    1.46 +	(skk-j-mode-on t)
    1.47 +      (skk-mode 1))
    1.48 +    (put 'YaTeX-jmode-on 'skkkata nil))
    1.49     ((fboundp 'toggle-input-method)
    1.50      (if (not current-input-method) (toggle-input-method)))
    1.51     ((and (fboundp 'fep-force-on) (fep-force-on)))))
    1.52 @@ -1442,40 +1455,46 @@
    1.53  
    1.54  (defun YaTeX-jmode-hook (old new)
    1.55    "A hook controling jmode on/off."
    1.56 +  ;; This function is called via point-entered/leave hook, so that
    1.57 +  ;; codes in it is evaluated on such emacsen as having text-properties.
    1.58    (let ((inhibit-point-motion-hooks t)
    1.59  	(oldp (plist-get (text-properties-at old) 'point-left))
    1.60  	(newp (plist-get (text-properties-at new) 'point-left))
    1.61  	(lnew (plist-get (text-properties-at new) 'last-new))
    1.62 -	(bmp (buffer-modified-p)) ;(endc ?x)
    1.63 +	(mjmode (plist-get (text-properties-at new) 'mjmode))
    1.64 +	(bmp (buffer-modified-p))
    1.65  	(jm (YaTeX-jmode)) b e)
    1.66 -    ;;(if (eq 'YaTeX-jmode-hook newp)
    1.67 -    ;;	(setq endc (char-after (next-single-property-change new 'point-left))))
    1.68 -    ;;(message "n[%c]=%s o[%c]=%s end=[%c] jm=%s"
    1.69 -    ;;	     (char-after new) newp (char-after old) oldp endc jm)
    1.70      (unwind-protect
    1.71  	(cond
    1.72  	 ((eq lnew new) nil)		;Do nothing if continuous entry
    1.73  	 ((and (not (eq newp 'YaTeX-jmode-hook))
    1.74 -	       (eq oldp 'YaTeX-jmode-hook))
    1.75 +	       (eq oldp 'YaTeX-jmode-hook)
    1.76 +	       (plist-get (text-properties-at old) 'entered))
    1.77  	  ;; leave
    1.78  	  (remove-text-properties
    1.79 -	   (1+ (or (previous-single-property-change old 'point-left)
    1.80 -		   (1- (point))))
    1.81 -	   (1- (or (next-single-property-change old 'point-left)
    1.82 -		   (1+ (point))))
    1.83 -	   (list 'last-new nil))
    1.84 +	   (setq b (1+ (or (previous-single-property-change old 'point-left)
    1.85 +			   (1- (point)))))
    1.86 +	   (setq e (1- (or (next-single-property-change old 'point-left)
    1.87 +			   (1+ (point)))))
    1.88 +	   (list 'last-new nil 'entered nil))
    1.89 +	  (add-text-properties b e (list 'mjmode jm))
    1.90 +	  (if (boundp 'skk-katakana)
    1.91 +	      (put 'YaTeX-jmode-on 'skkkata skk-katakana))
    1.92  	  (if (plist-get (text-properties-at old) 'jmode)
    1.93  	      (YaTeX-jmode-on)))
    1.94  	 ((and (not (eq oldp 'YaTeX-jmode-hook))
    1.95 -	       (eq newp 'YaTeX-jmode-hook))
    1.96 +	       (eq newp 'YaTeX-jmode-hook)
    1.97 +	       (not (plist-get (text-properties-at new) 'entered)))
    1.98  	  ;; enter
    1.99  	  (add-text-properties
   1.100  	   (1+ (or (previous-single-property-change new 'point-left)
   1.101  		   (1- (point))))
   1.102  	   (1- (or (next-single-property-change new 'point-left)
   1.103  		   (1+ (point))))
   1.104 -	   (list 'jmode jm 'last-new new))
   1.105 -	  (YaTeX-jmode-off)))
   1.106 +	   (list 'jmode jm 'last-new new 'entered t))
   1.107 +	  (if (boundp 'skk-katakana)	;care for skk katakana mode
   1.108 +	      (put 'YaTeX-jmode-on 'skkkata skk-katakana))
   1.109 +	  (if mjmode (YaTeX-jmode-on) (YaTeX-jmode-off))))
   1.110        ;;unwind job
   1.111        (set-buffer-modified-p bmp))))
   1.112  
   1.113 @@ -1495,6 +1514,7 @@
   1.114  	       'point-entered 'YaTeX-jmode-hook
   1.115  	       'front-sticky t
   1.116  	       'rear-nonsticky t
   1.117 +	       'mjmode nil
   1.118  	       'jmode (YaTeX-jmode))))
   1.119      (YaTeX-jmode-off)
   1.120      (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))