Revision: 7372
Author: deton.kih
Date: Tue Nov 22 02:42:43 2011
Log: * Add conversions on selection.
* scm/tutcode-key-custom.scm
- (tutcode-selection-mazegaki-start-sequence,
tutcode-selection-mazegaki-inflection-start-sequence,
tutcode-selection-katakana-start-sequence,
tutcode-selection-kanji2seq-start-sequence,
tutcode-selection-seq2kanji-start-sequence): New custom.
* scm/tutcode.scm
- (tutcode-commit-with-auto-help):
Change for conversion on selection.
- (tutcode-stroke-help-update-alist-with-rule):
Add labels for conversion on selection.
- (tutcode-commit-editor-context):
Change for conversion on selection.
- (tutcode-proc-state-on):
Add check of conversion on selection start keys.
- (tutcode-begin-selection-mazegaki-conversion,
tutcode-begin-selection-mazegaki-inflection-conversion,
tutcode-begin-selection-katakana-conversion,
tutcode-begin-selection-kanji2seq-conversion,
tutcode-begin-selection-seq2kanji-conversion,
tutcode-selection-commit,
tutcode-selection-acquire-text-wo-nl,
tutcode-selection-acquire-text): New function.
- (tutcode-back-to-yomi-state):
Change for conversion on selection.
- (tutcode-proc-state-converting):
Change for conversion on selection.
- (tutcode-custom-set-mazegaki/bushu-start-sequence!):
Add conversion on selection start sequences.
http://code.google.com/p/uim/source/detail?r=7372
Modified:
/trunk/scm/tutcode-key-custom.scm
/trunk/scm/tutcode.scm
=======================================
--- /trunk/scm/tutcode-key-custom.scm Mon Nov 21 14:10:12 2011
+++ /trunk/scm/tutcode-key-custom.scm Tue Nov 22 02:42:43 2011
@@ -95,6 +95,36 @@
(N_ "[TUT-Code] postfix bushu conversion")
(N_ "long description will be here"))
+(define-custom 'tutcode-selection-mazegaki-start-sequence ""
+ '(tutcode-keys1)
+ '(string ".*")
+ (N_ "[TUT-Code] mazegaki conversion on selection")
+ (N_ "long description will be here"))
+
+(define-custom 'tutcode-selection-mazegaki-inflection-start-sequence ""
+ '(tutcode-keys1)
+ '(string ".*")
+ (N_ "[TUT-Code] mazegaki conversion with inflection on
selection")
+ (N_ "long description will be here"))
+
+(define-custom 'tutcode-selection-katakana-start-sequence ""
+ '(tutcode-keys1)
+ '(string ".*")
+ (N_ "[TUT-Code] katakana conversion on selection")
+ (N_ "long description will be here"))
+
+(define-custom 'tutcode-selection-kanji2seq-start-sequence ""
+ '(tutcode-keys1)
+ '(string ".*")
+ (N_ "[TUT-Code] kanji to sequence conversion on selection")
+ (N_ "long description will be here"))
+
+(define-custom 'tutcode-selection-seq2kanji-start-sequence ""
+ '(tutcode-keys1)
+ '(string ".*")
+ (N_ "[TUT-Code] sequence to kanji conversion on selection")
+ (N_ "long description will be here"))
+
(define-custom 'tutcode-postfix-mazegaki-start-sequence ""
'(tutcode-keys1)
'(string ".*")
=======================================
--- /trunk/scm/tutcode.scm Mon Nov 21 14:10:12 2011
+++ /trunk/scm/tutcode.scm Tue Nov 22 02:42:43 2011
@@ -167,6 +167,16 @@
;;; Îã:"aljekri"¤òÊÑ´¹¢ª""¡£"ekri"¤À¤±ÊÑ´¹¢ª"¤«¤¤"¡£
;;; "aljekri \n"¤Î¤è¤¦¤Ë³ÎÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¢ª"²¼°Ì"
;;;
+;;; ¡Úselection¤ËÂФ¹¤ëÊÑ´¹¡Û
+;;; uim¤Îsurrounding text´Ø·¸¤ÎAPI(text acquisition API)¤ò»È¤Ã¤Æ¡¢
+;;; selectionʸ»úÎó¤Î¼èÆÀ¡¦ºï½ü¤ò¹Ô¤¤¤Þ¤¹¡£
+;;; * ¸ò¤¼½ñ¤ÊÑ´¹
+;;; ³èÍѤ·¤Ê¤¤¸ì tutcode-selection-mazegaki-start-sequence
+;;; ³èÍѤ¹¤ë¸ì tutcode-selection-mazegaki-inflection-start-sequence
+;;; * ¥«¥¿¥«¥ÊÊÑ´¹ tutcode-selection-katakana-start-sequence
+;;; * ´Á»ú¢ªÆþÎÏ¥·¡¼¥±¥ó¥¹ÊÑ´¹ tutcode-selection-kanji2seq-start-sequence
+;;; * ÆþÎÏ¥·¡¼¥±¥ó¥¹¢ª´Á»úÊÑ´¹ tutcode-selection-seq2kanji-start-sequence
+;;;
;;; ¡Ú¥Ø¥ë¥×µ¡Ç½¡Û
;;; * ²¾ÁÛ¸°È×ɽ¼¨(ɽ·Á¼°¤Î¸õÊ䥦¥£¥ó¥É¥¦¤òήÍÑ)
;;; ³Æ°ÌÃ֤Υ¡¼¤ÎÂǸ°¤Ë¤è¤êÆþÎϤµ¤ì¤ëʸ»ú¤òɽ¼¨¤·¤Þ¤¹¡£
@@ -775,7 +785,7 @@
(list 'nr-candidates 0)
;;; ¸åÃÖ·¿¸ò¤¼½ñ¤ÊÑ´¹»þ¤Ë¡¢ÊÑ´¹¤Ë»ÈÍѤ¹¤ëÆÉ¤ß¤ÎŤµ¡£
;;; (³ÎÄê»þ¤Ëim-delete-text¤¹¤ë¤¿¤á¤Ë»ÈÍÑ)
- ;;; ¸åÃÖ·¿¤«Á°ÃÖ·¿¤«¤ÎȽÄê¤Ë¤â»ÈÍÑ¡£(Á°ÃÖ·¿¤Î¾ì¹ç¤Ï0)
+ ;;; ¸åÃÖ·¿(Àµ)¤«Á°ÃÖ·¿(0)¤«selection·¿(Éé)¤«¤ÎȽÄê¤Ë¤â»ÈÍÑ¡£
(list 'postfix-yomi-len 0)
;;; ¸ò¤¼½ñ¤ÊÑ´¹³«»Ï»þ¤Ë»ØÄꤵ¤ì¤¿ÆÉ¤ß¤Îʸ»ú¿ô¡£
;;; Á°ÃÖ·¿¤Î¾ì¹ç¤ÏÆþÎÏºÑ¤ß¤ÎÆÉ¤ß¤Îʸ»ú¿ô¡£
@@ -1381,8 +1391,9 @@
(define (tutcode-commit-with-auto-help pc)
(let* ((head (tutcode-context-head pc))
(yomi-len (tutcode-context-postfix-yomi-len pc))
- (yomi (and (> yomi-len 0)
- (take (tutcode-context-mazegaki-yomi-all pc)
yomi-len)))
+ (yomi (and (not (zero? yomi-len))
+ (take (tutcode-context-mazegaki-yomi-all pc)
+ (abs yomi-len))))
(suffix (tutcode-context-mazegaki-suffix pc))
(state (tutcode-context-state pc))
;;
¸õÊä1¸Ä¤Ç¼«Æ°³ÎÄꤵ¤ì¤¿´Á»ú¤¬°Õ¿Þ¤·¤¿¤â¤Î¤Ç¤Ê¤«¤Ã¤¿¾ì¹ç¤Îundo¤òÁÛÄê
@@ -1390,12 +1401,15 @@
(undo-data (and (eq? state 'tutcode-state-converting)
(list head (tutcode-context-latin-conv pc))))
(res (tutcode-prepare-commit-string pc))) ;
flush¤Ë¤è¤êheadÅù¤¬¥¯¥ê¥¢
- (if (> yomi-len 0)
- (tutcode-postfix-commit pc res yomi)
- (begin
+ (cond
+ ((= yomi-len 0)
(tutcode-commit pc res)
(if undo-data
- (tutcode-undo-prepare pc state res undo-data))))
+ (tutcode-undo-prepare pc state res undo-data)))
+ ((> yomi-len 0)
+ (tutcode-postfix-commit pc res yomi))
+ (else
+ (tutcode-selection-commit pc res yomi)))
(tutcode-check-auto-help-window-begin pc
(drop (string-to-list res) (length suffix))
(append suffix head))))
@@ -1936,6 +1950,8 @@
((tutcode-bushu-start) "¢¡")
((tutcode-interactive-bushu-start) "¢§")
((tutcode-postfix-bushu-start) "¢¥")
+ ((tutcode-selection-mazegaki-start) "¢¤s")
+ ((tutcode-selection-mazegaki-inflection-start) "¡½s")
((tutcode-postfix-mazegaki-start) "¢¤")
((tutcode-postfix-mazegaki-1-start) "¢¤1")
((tutcode-postfix-mazegaki-2-start) "¢¤2")
@@ -1956,6 +1972,7 @@
((tutcode-postfix-mazegaki-inflection-7-start) "¡½7")
((tutcode-postfix-mazegaki-inflection-8-start) "¡½8")
((tutcode-postfix-mazegaki-inflection-9-start) "¡½9")
+ ((tutcode-selection-katakana-start) "¥«s")
((tutcode-postfix-katakana-start) "¥«")
((tutcode-postfix-katakana-1-start) "¥«1")
((tutcode-postfix-katakana-2-start) "¥«2")
@@ -1966,6 +1983,7 @@
((tutcode-postfix-katakana-7-start) "¥«7")
((tutcode-postfix-katakana-8-start) "¥«8")
((tutcode-postfix-katakana-9-start) "¥«9")
+ ((tutcode-selection-kanji2seq-start) "/s")
((tutcode-postfix-kanji2seq-start) "/@")
((tutcode-postfix-kanji2seq-1-start) "/1")
((tutcode-postfix-kanji2seq-2-start) "/2")
@@ -1976,6 +1994,7 @@
((tutcode-postfix-kanji2seq-7-start) "/7")
((tutcode-postfix-kanji2seq-8-start) "/8")
((tutcode-postfix-kanji2seq-9-start) "/9")
+ ((tutcode-selection-seq2kanji-start) "´Ás")
((tutcode-postfix-seq2kanji-start) "´Á@")
((tutcode-postfix-seq2kanji-1-start) "´Á1")
((tutcode-postfix-seq2kanji-2-start) "´Á2")
@@ -2494,13 +2513,18 @@
(string-append str (string-list-concat suffix)))))
(tutcode-context-set-child-context! pc ())
(tutcode-context-set-child-type! pc ())
- (if (> yomi-len 0)
- (let ((yomi (take (tutcode-context-mazegaki-yomi-all pc) yomi-len)))
- (tutcode-postfix-commit pc commit-str yomi)
- (tutcode-flush pc))
- (begin
+ (cond
+ ((= yomi-len 0)
(tutcode-flush pc)
- (tutcode-commit pc commit-str)))
+ (tutcode-commit pc commit-str))
+ ((> yomi-len 0)
+ (let ((yomi (take (tutcode-context-mazegaki-yomi-all pc)
yomi-len)))
+ (tutcode-postfix-commit pc commit-str yomi)
+ (tutcode-flush pc)))
+ (else
+ (tutcode-selection-commit pc commit-str
+ (tutcode-context-mazegaki-yomi-all pc))
+ (tutcode-flush pc)))
(tutcode-update-preedit pc)))
;;; Êä´°¸õÊä¤ò¸¡º÷¤·¤Æ¸õÊ䥦¥£¥ó¥É¥¦¤Ëɽ¼¨¤¹¤ë
@@ -3064,6 +3088,16 @@
(tutcode-begin-postfix-seq2kanji-conversion pc 8))
((eq? res 'tutcode-postfix-seq2kanji-9-start)
(tutcode-begin-postfix-seq2kanji-conversion pc 9))
+ ((eq? res 'tutcode-selection-mazegaki-start)
+ (tutcode-begin-selection-mazegaki-conversion pc))
+ ((eq? res 'tutcode-selection-mazegaki-inflection-start)
+ (tutcode-begin-selection-mazegaki-inflection-conversion
pc))
+ ((eq? res 'tutcode-selection-katakana-start)
+ (tutcode-begin-selection-katakana-conversion pc))
+ ((eq? res 'tutcode-selection-kanji2seq-start)
+ (tutcode-begin-selection-kanji2seq-conversion pc))
+ ((eq? res 'tutcode-selection-seq2kanji-start)
+ (tutcode-begin-selection-seq2kanji-conversion pc))
((eq? res 'tutcode-history-start)
(tutcode-begin-history pc))
((eq? res 'tutcode-undo)
@@ -3491,6 +3525,82 @@
(make-list len tutcode-fallback-backspace-string))
#t #t))))))))
+;;; selection¤ËÂФ·¤Æ¸ò¤¼½ñ¤ÊÑ´¹¤ò³«»Ï¤¹¤ë
+(define (tutcode-begin-selection-mazegaki-conversion pc)
+ (let ((sel (tutcode-selection-acquire-text-wo-nl pc)))
+ (if (pair? sel)
+ (let ((sel-len (length sel)))
+ (tutcode-context-set-mazegaki-yomi-len-specified! pc sel-len)
+ (tutcode-context-set-postfix-yomi-len! pc (- sel-len)) ;
Éé:selection
+ (tutcode-context-set-mazegaki-yomi-all! pc sel)
+ (tutcode-begin-conversion pc sel () #t
+ tutcode-use-recursive-learning?)))))
+
+;;; selection¤ËÂФ·¤Æ³èÍѤ¹¤ë¸ì¤È¤·¤Æ¸ò¤¼½ñ¤ÊÑ´¹¤ò³«»Ï¤¹¤ë
+(define (tutcode-begin-selection-mazegaki-inflection-conversion pc)
+ (let ((sel (tutcode-selection-acquire-text-wo-nl pc)))
+ (if (pair? sel)
+ (let ((sel-len (length sel)))
+ (tutcode-context-set-mazegaki-yomi-len-specified! pc sel-len)
+ (tutcode-context-set-postfix-yomi-len! pc (- sel-len)) ;
Éé:selection
+ (tutcode-context-set-mazegaki-yomi-all! pc sel)
+ (if (tutcode-mazegaki-inflection? sel)
+ (tutcode-begin-conversion pc sel () #t
+ tutcode-use-recursive-learning?)
+ (tutcode-mazegaki-inflection-relimit-right pc
+ sel-len sel-len #f))))))
+
+;;; selection¤ËÂФ·¤Æ¥«¥¿¥«¥ÊÊÑ´¹¤ò³«»Ï¤¹¤ë
+(define (tutcode-begin-selection-katakana-conversion pc)
+ (let ((sel (tutcode-selection-acquire-text pc)))
+ (if (pair? sel)
+ (let* ((katakana (tutcode-katakana-convert sel
+ (not (tutcode-context-katakana-mode? pc))))
+ (str (string-list-concat katakana)))
+ (tutcode-selection-commit pc str sel)
+ (if (= (length katakana) 1) ;
1ʸ»ú¤Î¾ì¹ç¡¢¼«Æ°¥Ø¥ë¥×ɽ¼¨(tc2¤ÈƱÍÍ)
+ (tutcode-check-auto-help-window-begin pc katakana ()))))))
+
+;;; selection¤ËÂФ·¤Æ´Á»ú¢ªÆþÎÏ¥·¡¼¥±¥ó¥¹ÊÑ´¹¤ò³«»Ï¤¹¤ë
+(define (tutcode-begin-selection-kanji2seq-conversion pc)
+ (let ((sel (tutcode-selection-acquire-text pc)))
+ (if (pair? sel)
+ (tutcode-selection-commit pc
+ (string-list-concat (tutcode-kanji-list->sequence pc sel)) sel))))
+
+;;; selection¤ËÂФ·¤ÆÆþÎÏ¥·¡¼¥±¥ó¥¹¢ª´Á»úÊÑ´¹¤ò³«»Ï¤¹¤ë
+(define (tutcode-begin-selection-seq2kanji-conversion pc)
+ (let ((sel (tutcode-selection-acquire-text pc)))
+ (if (pair? sel)
+ (tutcode-selection-commit pc
+ (string-list-concat (tutcode-sequence->kanji-list pc sel)) sel))))
+
+;;; selection¤ËÂФ¹¤ëÊÑ´¹¤ò³ÎÄꤹ¤ë
+;;; @param str ³ÎÄꤹ¤ëʸ»úÎó
+;;; @param yomi-list ÊÑ´¹¸µ¤Îʸ»úÎó(ÆÉ¤ß/Éô¼ó)¤Î¥ê¥¹¥È(µÕ½ç)
+(define (tutcode-selection-commit pc str yomi-list)
+ ;; commit¤¹¤ë¤Èselection¤¬¾å½ñ¤¤µ¤ì¤ë¤Î¤Çdelete-text¤ÏÉÔÍ×
+ ;(im-delete-text pc 'selection 'beginning 0 'full)
+ (tutcode-commit pc str)
+ (tutcode-undo-prepare pc 'tutcode-state-off str yomi-list))
+
+;;; selectionʸ»úÎó¤ò²þ¹Ô¤ò½ü¤¤¤Æ¼èÆÀ¤¹¤ë
+;;; @return ¼èÆÀ¤·¤¿Ê¸»úÎó¤Î¥ê¥¹¥È(µÕ½ç)
+(define (tutcode-selection-acquire-text-wo-nl pc)
+ (let ((latter-seq (tutcode-selection-acquire-text pc)))
+ (and (pair? latter-seq)
+ (delete "\n" latter-seq))))
+
+;;; selectionʸ»úÎó¤ò¼èÆÀ¤¹¤ë
+;;; @return ¼èÆÀ¤·¤¿Ê¸»úÎó¤Î¥ê¥¹¥È(µÕ½ç)
+(define (tutcode-selection-acquire-text pc)
+ (and-let*
+ ((ustr (im-acquire-text pc 'selection 'beginning 0 'full))
+ (latter (ustr-latter-seq ustr))
+ (latter-seq (and (pair? latter) (string-to-list (car latter)))))
+ (and (not (null? latter-seq))
+ latter-seq)))
+
;;; ¸åÃÖ·¿¥«¥¿¥«¥ÊÊÑ´¹¤ò³ÎÄꤹ¤ë
;;; @param yomi ÆÉ¤ß
;;; @param katakana ÆÉ¤ß¤ò¥«¥¿¥«¥Ê¤ËÊÑ´¹¤·¤¿Ê¸»úÎó¥ê¥¹¥È
@@ -4591,14 +4701,27 @@
;;; ¸ò¤¼½ñ¤ÊÑ´¹¤Î¸õÊäÁªÂò¾õÂÖ¤«¤é¡¢ÆÉ¤ßÆþÎϾõÂÖ¤ËÌ᤹¡£
;;; @param pc ¥³¥ó¥Æ¥¥¹¥È¥ê¥¹¥È
(define (tutcode-back-to-yomi-state pc)
- (if (> (tutcode-context-postfix-yomi-len pc) 0) ; ¸åÃÖ·¿?
- (tutcode-flush pc)
- (begin
- (tutcode-reset-candidate-window pc)
- (tutcode-context-set-state! pc 'tutcode-state-yomi)
- (tutcode-context-set-head! pc (tutcode-context-mazegaki-yomi-all pc))
- (tutcode-context-set-mazegaki-suffix! pc ())
- (tutcode-context-set-nr-candidates! pc 0))))
+ (let ((postfix-yomi-len (tutcode-context-postfix-yomi-len pc)))
+ (cond
+ ((= postfix-yomi-len 0)
+ (tutcode-reset-candidate-window pc)
+ (tutcode-context-set-state! pc 'tutcode-state-yomi)
+ (tutcode-context-set-head! pc (tutcode-context-mazegaki-yomi-all
pc))
+ (tutcode-context-set-mazegaki-suffix! pc ())
+ (tutcode-context-set-nr-candidates! pc 0))
+ ((> postfix-yomi-len 0)
+ (tutcode-flush pc))
+ (else ; selection
+ (im-clear-preedit pc)
+ (im-update-preedit pc)
+ ;;
Firefox¤äqt4¤Î¾ì¹ç¡¢preeditɽ¼¨»þ¤Ëselection¤¬¾å½ñ¤¤µ¤ì¤ë¤è¤¦¤Ç¡¢
+ ;;
cancel¤·¤Æ¤â¾Ã¤¨¤¿¤Þ¤Þ¤Ë¤Ê¤ë¤Î¤Ç¡¢¼èÆÀºÑ¤ÎselectionÆâÍÆ¤ò½ñ¤Ì᤹¡£
+ ;;
(selection¾õÂÖ¤¬²ò½ü¤µ¤ì¤ë¤¿¤áFirefox¤äqt4°Ê³°(leafpadÅù)¤Ç¤Ï¤¦¤ì¤·
+ ;;
¤¯¤Ê¤¤¤¬¡¢¾Ã¤¨¤ë¥Ç¥á¥ê¥Ã¥È¤ÎÊý¤¬selection²ò½ü¤Î¥Ç¥á¥ê¥Ã¥È¤è¤êÂ礤¤)
+ ;;
(ºÆÅÙacquire-text¤·¤Æ¤ÎȽÄê¤ÏFirefox¤Î¾ì¹çpair¤¬Ê֤뤿¤áȽÄêÉÔǽ)
+ (tutcode-commit pc
+ (string-list-concat (tutcode-context-mazegaki-yomi-all pc)) #t
#t)
+ (tutcode-flush pc)))))
;;; ¸ò¤¼½ñ¤ÊÑ´¹¤Î¼½ñÅÐÏ¿¾õÂÖ¤«¤é¡¢¸õÊäÁªÂò¾õÂÖ¤ËÌ᤹¡£
;;; @param pc ¥³¥ó¥Æ¥¥¹¥È¥ê¥¹¥È
@@ -4669,13 +4792,17 @@
(tutcode-commit-by-label-key pc (charcode->string key)))
(else
(let* ((postfix-yomi-len (tutcode-context-postfix-yomi-len pc))
- (yomi (and (> postfix-yomi-len 0)
+ (yomi (and (not (zero? postfix-yomi-len))
(take (tutcode-context-mazegaki-yomi-all pc)
- postfix-yomi-len)))
+ (abs postfix-yomi-len))))
(commit-str (tutcode-prepare-commit-string pc)))
- (if (> postfix-yomi-len 0)
- (tutcode-postfix-commit pc commit-str yomi)
- (tutcode-commit pc commit-str)))
+ (cond
+ ((= postfix-yomi-len 0)
+ (tutcode-commit pc commit-str))
+ ((> postfix-yomi-len 0)
+ (tutcode-postfix-commit pc commit-str yomi))
+ (else
+ (tutcode-selection-commit pc commit-str yomi))))
(tutcode-proc-state-on pc key key-state)))))
;;; Éô¼ó¹çÀ®ÊÑ´¹¤ò¹Ô¤¦¡£
@@ -5965,6 +6092,16 @@
'(tutcode-interactive-bushu-start)))
(make-subrule tutcode-postfix-bushu-start-sequence
'(tutcode-postfix-bushu-start))
+ (make-subrule tutcode-selection-mazegaki-start-sequence
+ '(tutcode-selection-mazegaki-start))
+ (make-subrule
tutcode-selection-mazegaki-inflection-start-sequence
+ '(tutcode-selection-mazegaki-inflection-start))
+ (make-subrule tutcode-selection-katakana-start-sequence
+ '(tutcode-selection-katakana-start))
+ (make-subrule tutcode-selection-kanji2seq-start-sequence
+ '(tutcode-selection-kanji2seq-start))
+ (make-subrule tutcode-selection-seq2kanji-start-sequence
+ '(tutcode-selection-seq2kanji-start))
(make-subrule tutcode-postfix-mazegaki-start-sequence
'(tutcode-postfix-mazegaki-start))
(make-subrule tutcode-postfix-mazegaki-1-start-sequence