[Anthy-dev 419] uim-anthyのプリエディット編集機能追加

アーカイブの一覧に戻る

YamaKen yamak****@bp*****
2004年 1月 15日 (木) 01:19:34 JST


ヤマケンです。
#Scheme猿モード

uim-anthyのプリエディット編集機能を追加してみました。

C-k        kill
C-u        kill-backward
C-a, Home  beginning-of-preedit
C-e, End   end-of-preedit
C-d, Del   delete

deleteは元々ありましたが、deleteキーしか効かないのでC-dのキーバ
インドを追加しました。

もう一つ、プリエディットにかなを入力した状態でqを押すと現在のひ
らがな/カタカナモードと逆のモードでcommitされますが、通常時のか
なモード切換と同じキーバインドでこのような挙動をされると驚きが大
きいので(バグかと思いました)、以下のように変更してみました。どう
でしょうか?

Q  現在のひらがな/カタカナモードと逆のモードでcommit
q  現在のひらがな/カタカナモードでcommitし、その後モード切換

現在のAnthyはカタカナ混じり文を正しく処理しないようなので一旦
commitするようにしていますが、将来的にはモード切換だけにしたいで
すね。

-------------------------------
ヤマケン yamak****@bp*****
-------------- next part --------------
Index: scm/generic-key.scm
===================================================================
--- scm/generic-key.scm	(revision 356)
+++ scm/generic-key.scm	(working copy)
@@ -40,20 +40,40 @@
 	     (= (to-lower-char key) 104)))))
 (define generic-delete-key
   (lambda (key key-state)
-    (= key 'delete)))
+    (or (= key 'delete)
+	(and (control-key-mask key-state)
+	     (= (to-lower-char key) 100)))))
+(define generic-kill-key
+  (lambda (key key-state)
+    (and (control-key-mask key-state)
+	 (= (to-lower-char key) 107))))
+(define generic-kill-backward-key
+  (lambda (key key-state)
+    (and (control-key-mask key-state)
+	 (= (to-lower-char key) 117))))
+
 (define generic-go-left-key
   (lambda (key key-state)
     (or
      (left-key key key-state)
      (and (= (to-lower-char key) 98)
 	  (control-key-mask key-state)))))
-
 (define generic-go-right-key
   (lambda (key key-state)
     (or
      (right-key key key-state)
      (and (= (to-lower-char key) 102)
 	  (control-key-mask key-state)))))
+(define generic-beginning-of-preedit-key
+  (lambda (key key-state)
+    (or (= key 'home)
+	(and (control-key-mask key-state)
+	     (= (to-lower-char key) 97)))))
+(define generic-end-of-preedit-key
+  (lambda (key key-state)
+    (or (= key 'end)
+	(and (control-key-mask key-state)
+	     (= (to-lower-char key) 101)))))
 ;;
 (define generic-on-key
   (lambda (key key-state)
Index: scm/anthy.scm
===================================================================
--- scm/anthy.scm	(revision 356)
+++ scm/anthy.scm	(working copy)
@@ -30,6 +30,11 @@
     (and
      (= (to-lower-char key) 113)
      (not (modifier-key-mask key-state)))))
+(define anthy-commit-as-opposite-kana-key
+  (lambda (key key-state)
+    (and
+     (= (to-lower-char key) 113)
+     (shift-key-mask key-state))))
 (define anthy-begin-conv-key
   (lambda (key key-state)
     (= (to-lower-char key) 32)))
@@ -69,12 +74,24 @@
 (define anthy-delete-key
   (lambda (key key-state)
     (generic-delete-key key key-state)))
+(define anthy-kill-key
+  (lambda (key key-state)
+    (generic-kill-key key key-state)))
+(define anthy-kill-backward-key
+  (lambda (key key-state)
+    (generic-kill-backward-key key key-state)))
 (define anthy-go-left-key
   (lambda (key key-state)
     (generic-go-left-key key key-state)))
 (define anthy-go-right-key
   (lambda (key key-state)
     (generic-go-right-key key key-state)))
+(define anthy-beginning-of-preedit-key
+  (lambda (key key-state)
+    (generic-beginning-of-preedit-key key key-state)))
+(define anthy-end-of-preedit-key
+  (lambda (key key-state)
+    (generic-end-of-preedit-key key key-state)))
 (define anthy-next-segment-key
   (lambda (key key-state)
     (generic-go-right-key key key-state)))
@@ -472,15 +489,46 @@
 		      (cdr (anthy-context-right-string ac)))))
 	     #f)
 	   #t)
+       ;; kill
+       (if (anthy-kill-key key key-state)
+	   (begin
+	     (anthy-context-set-right-string! ac ())
+	     #f)
+	   #t)
+       ;; kill-backward
+       (if (anthy-kill-backward-key key key-state)
+	   (begin
+	     (rk-flush rkc)
+	     (anthy-context-set-left-string! ac ())
+	     #f)
+	   #t)
        ;; ひらがなモードでカタカナを確定する
+       (if (anthy-commit-as-opposite-kana-key key key-state)
+	   (begin
+	     (im-commit
+	      id
+	      (string-append
+	       (anthy-make-left-string (anthy-context-left-string ac)
+				       (not kana))
+	       (anthy-make-right-string (anthy-context-right-string ac)
+					(not kana))))
+	     (anthy-flush ac)
+	     #f)
+	   #t)
+       ;; 現在のかなを確定後、ひらがな/カタカナモードを切り換える
        (if (anthy-kana-toggle-key key key-state)
 	   (begin
 	     (im-commit
 	      id
 	      (string-append
-		(anthy-make-left-string (anthy-context-left-string ac) (not kana))
-		(anthy-make-right-string (anthy-context-right-string ac) (not kana))))
+	       (anthy-make-left-string (anthy-context-left-string ac)
+				       kana)
+	       (anthy-make-right-string (anthy-context-right-string ac)
+					kana)))
 	     (anthy-flush ac)
+	     (anthy-context-kana-toggle ac)
+	     (anthy-update-mode ac id)
+	     (anthy-update-prop-label ac id)
 	     #f)
 	   #t)
        ;; cancel
@@ -524,6 +572,32 @@
 		   (anthy-append-string ac c)))
 	     #f)
 	   #t)
+       ;; beginning-of-preedit
+       (if (anthy-beginning-of-preedit-key key key-state)
+	   (begin
+	     (if (anthy-context-left-string ac)
+		 (begin
+		   (anthy-context-set-right-string!
+		    ac
+		    (append
+		     (reverse (anthy-context-left-string ac))
+		     (anthy-context-right-string ac)))
+		   (anthy-context-set-left-string! ac ())))
+	     #f)
+	   #t)
+       ;; end-of-preedit
+       (if (anthy-end-of-preedit-key key key-state)
+	   (begin
+	     (if (anthy-context-right-string ac)
+		 (begin
+		   (anthy-context-set-left-string!
+		    ac
+		    (append
+		     (reverse (anthy-context-right-string ac))
+		     (anthy-context-left-string ac)))
+		   (anthy-context-set-right-string! ac ())))
+	     #f)
+	   #t)
        ;; modifiers (except shift) => ignore
        (if (and (modifier-key-mask key-state)
 		(not (shift-key-mask key-state)))


Anthy-dev メーリングリストの案内
アーカイブの一覧に戻る