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 wrap: on
line diff
--- a/yatex.el	Wed Nov 30 14:22:46 2011 +0900
+++ b/yatex.el	Thu Dec 01 23:02:36 2011 +0900
@@ -2,7 +2,7 @@
 ;;; Yet Another tex-mode for emacs - //–ì’¹//
 ;;; yatex.el rev. 1.74.5
 ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Wed Nov 30 14:22:06 2011 on duke
+;;; Last modified Thu Dec  1 23:00:13 2011 on firestorm
 ;;; $Id$
 ;;; The latest version of this software is always available at;
 ;;; http://www.yatex.org/
@@ -1257,7 +1257,7 @@
 (defun YaTeX-jmode ()
   (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
       (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
-      (and (boundp 'skk-mode) skk-mode)
+      (and (boundp 'skk-mode) skk-mode (not skk-latin-mode))
       (and (boundp 'default-input-method) default-input-method
 	   current-input-method)))
 
@@ -1269,7 +1269,17 @@
 	(egg:toggle-egg-mode-on-off) t)
        ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
 	(cond
-	 ((fboundp 'skk-latin-mode)	(skk-latin-mode t))
+	 ((fboundp 'skk-latin-mode)
+	  (or (and (boundp 'skk-henkan-mode) skk-henkan-mode)
+	      (and (boundp 'skk-henkan-on)
+		   (or skk-henkan-mode skk-henkan-active))
+	      (and (boundp 'j-henkan-on)
+		   (or j-henkan-on j-henkan-active))
+	      ;; Deactivate jmode if henkan-mode is not running.
+	      ;; Suggested by tt.tetsuo.tsukamoto.
+	      (progn
+		(put 'YaTeX-jmode-on 'skkkata skk-katakana)
+		(skk-latin-mode t))))
 	 ((fboundp 'skk-mode-off)	(skk-mode-off))
 	 (t (j-mode-off)))
 	t)
@@ -1286,7 +1296,10 @@
     (and (not egg:*mode-on*) (not egg:*input-mode*)
 	 (egg:toggle-egg-mode-on-off)))
    ((and (fboundp 'skk-mode) (boundp 'skk-mode))
-    (if (not skk-mode) (skk-mode 1)))
+    (if (get 'YaTeX-jmode-on 'skkkata)
+	(skk-j-mode-on t)
+      (skk-mode 1))
+    (put 'YaTeX-jmode-on 'skkkata nil))
    ((fboundp 'toggle-input-method)
     (if (not current-input-method) (toggle-input-method)))
    ((and (fboundp 'fep-force-on) (fep-force-on)))))
@@ -1442,40 +1455,46 @@
 
 (defun YaTeX-jmode-hook (old new)
   "A hook controling jmode on/off."
+  ;; This function is called via point-entered/leave hook, so that
+  ;; codes in it is evaluated on such emacsen as having text-properties.
   (let ((inhibit-point-motion-hooks t)
 	(oldp (plist-get (text-properties-at old) 'point-left))
 	(newp (plist-get (text-properties-at new) 'point-left))
 	(lnew (plist-get (text-properties-at new) 'last-new))
-	(bmp (buffer-modified-p)) ;(endc ?x)
+	(mjmode (plist-get (text-properties-at new) 'mjmode))
+	(bmp (buffer-modified-p))
 	(jm (YaTeX-jmode)) b e)
-    ;;(if (eq 'YaTeX-jmode-hook newp)
-    ;;	(setq endc (char-after (next-single-property-change new 'point-left))))
-    ;;(message "n[%c]=%s o[%c]=%s end=[%c] jm=%s"
-    ;;	     (char-after new) newp (char-after old) oldp endc jm)
     (unwind-protect
 	(cond
 	 ((eq lnew new) nil)		;Do nothing if continuous entry
 	 ((and (not (eq newp 'YaTeX-jmode-hook))
-	       (eq oldp 'YaTeX-jmode-hook))
+	       (eq oldp 'YaTeX-jmode-hook)
+	       (plist-get (text-properties-at old) 'entered))
 	  ;; leave
 	  (remove-text-properties
-	   (1+ (or (previous-single-property-change old 'point-left)
-		   (1- (point))))
-	   (1- (or (next-single-property-change old 'point-left)
-		   (1+ (point))))
-	   (list 'last-new nil))
+	   (setq b (1+ (or (previous-single-property-change old 'point-left)
+			   (1- (point)))))
+	   (setq e (1- (or (next-single-property-change old 'point-left)
+			   (1+ (point)))))
+	   (list 'last-new nil 'entered nil))
+	  (add-text-properties b e (list 'mjmode jm))
+	  (if (boundp 'skk-katakana)
+	      (put 'YaTeX-jmode-on 'skkkata skk-katakana))
 	  (if (plist-get (text-properties-at old) 'jmode)
 	      (YaTeX-jmode-on)))
 	 ((and (not (eq oldp 'YaTeX-jmode-hook))
-	       (eq newp 'YaTeX-jmode-hook))
+	       (eq newp 'YaTeX-jmode-hook)
+	       (not (plist-get (text-properties-at new) 'entered)))
 	  ;; enter
 	  (add-text-properties
 	   (1+ (or (previous-single-property-change new 'point-left)
 		   (1- (point))))
 	   (1- (or (next-single-property-change new 'point-left)
 		   (1+ (point))))
-	   (list 'jmode jm 'last-new new))
-	  (YaTeX-jmode-off)))
+	   (list 'jmode jm 'last-new new 'entered t))
+	  (if (boundp 'skk-katakana)	;care for skk katakana mode
+	      (put 'YaTeX-jmode-on 'skkkata skk-katakana))
+	  (if mjmode (YaTeX-jmode-on) (YaTeX-jmode-off))))
       ;;unwind job
       (set-buffer-modified-p bmp))))
 
@@ -1495,6 +1514,7 @@
 	       'point-entered 'YaTeX-jmode-hook
 	       'front-sticky t
 	       'rear-nonsticky t
+	       'mjmode nil
 	       'jmode (YaTeX-jmode))))
     (YaTeX-jmode-off)
     (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))

yatex.org