Revision: 7338
Author: deton.kih
Date: Fri Oct 28 04:12:43 2011
Log: * Add function to undo last commit of postfix conversion.
* scm/tutcode-key-custom.scm
- (tutcode-undo-sequence): New key custom.
* scm/tutcode.scm
- (tutcode-context-rec-spec): Add undo variable.
- (tutcode-commit-raw, tutcode-commit): Reset undo variable.
- (tutcode-commit-with-auto-help,
tutcode-commit-editor-context,
tutcode-begin-postfix-bushu-conversion,
tutcode-proc-state-converting): Prepare for undo.
- (tutcode-stroke-help-update-alist-with-rule):
Add label for undo key sequence.
- (tutcode-proc-state-on): Add check of undo key sequence.
- (tutcode-undo, tutcode-undo-prepare): New function.
- (tutcode-custom-set-mazegaki/bushu-start-sequence!):
Add undo key sequence.
http://code.google.com/p/uim/source/detail?r=7338
Modified:
/trunk/scm/tutcode-key-custom.scm
/trunk/scm/tutcode.scm
=======================================
--- /trunk/scm/tutcode-key-custom.scm Wed Apr 6 04:54:23 2011
+++ /trunk/scm/tutcode-key-custom.scm Fri Oct 28 04:12:43 2011
@@ -239,6 +239,12 @@
(N_ "[TUT-Code] display last auto help")
(N_ "long description will be here"))
+(define-custom 'tutcode-undo-sequence ""
+ '(tutcode-keys1)
+ '(string ".*")
+ (N_ "[TUT-Code] undo last commit")
+ (N_ "long description will be here"))
+
(define-custom 'tutcode-katakana-commit-key '()
'(tutcode-keys1)
'(key)
=======================================
--- /trunk/scm/tutcode.scm Thu Oct 27 04:11:16 2011
+++ /trunk/scm/tutcode.scm Fri Oct 28 04:12:43 2011
@@ -750,6 +750,8 @@
(list 'commit-strs-used-len 0)
;;; commit¤·¤¿Ê¸»úÎó¤ÎÍúÎò(¥Ò¥¹¥È¥êÆþÎÏÍÑ)
(list 'history ())
+ ;;; ¸åÃÖ·¿ÊÑ´¹¤Î³ÎÄê¤òundo¤¹¤ë¤¿¤á¤Î¥Ç¡¼¥¿
+ (list 'undo ())
;;; Êä´°/ͽ¬ÆþÎϤθõÊäÁªÂòÃæ¤«¤É¤¦¤«
;;; 'tutcode-predicting-off Êä´°/ͽ¬ÆþÎϤθõÊäÁªÂòÃæ¤Ç¤Ê¤¤
;;; 'tutcode-predicting-completion Êä´°¸õÊäÁªÂòÃæ
@@ -1256,6 +1258,7 @@
;;; im-commit-raw¤ò¸Æ¤Ó½Ð¤¹¡£
;;; ¤¿¤À¤·¡¢»Ò¥³¥ó¥Æ¥¥¹¥È¤Î¾ì¹ç¤Ï¡¢editor¤«dialog¤ËÆþÎÏ¥¡¼¤òÅϤ¹¡£
(define (tutcode-commit-raw pc key key-state)
+ (tutcode-context-set-undo! pc ())
(if (or tutcode-use-completion?
tutcode-enable-fallback-surrounding-text?)
(tutcode-append-commit-string pc (im-get-raw-key-str key key-state)))
(let ((ppc (tutcode-context-parent-context pc)))
@@ -1274,6 +1277,7 @@
;;; opt-skip-append-history? history¤Ø¤ÎÄɲäò
;;; ¥¹¥¥Ã¥×¤¹¤ë¤«¤É¤¦¤«¡£Ì¤»ØÄê»þ¤Ï#f¡£
(define (tutcode-commit pc str . opts)
+ (tutcode-context-set-undo! pc ())
(let-optionals* opts ((opt-skip-append-commit-strs? #f)
(opt-skip-append-history? #f))
(if (and
@@ -1294,11 +1298,16 @@
(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)))
(suffix (tutcode-context-mazegaki-suffix pc))
(res (tutcode-prepare-commit-string pc))) ;
flush¤Ë¤è¤êheadÅù¤¬¥¯¥ê¥¢
(if (> yomi-len 0)
- (tutcode-postfix-delete-text pc yomi-len))
- (tutcode-commit pc res)
+ (begin
+ (tutcode-postfix-delete-text pc yomi-len)
+ (tutcode-commit pc res)
+ (tutcode-undo-prepare pc res yomi))
+ (tutcode-commit pc res))
(tutcode-check-auto-help-window-begin pc
(drop (string-to-list res) (length suffix))
(append suffix head))))
@@ -1858,6 +1867,7 @@
((tutcode-postfix-mazegaki-inflection-8-start) "¡½8")
((tutcode-postfix-mazegaki-inflection-9-start) "¡½9")
((tutcode-auto-help-redisplay) "¢ã")
+ ((tutcode-undo) "¢Î")
(else cand)))
(cand-hint
(or
@@ -2308,17 +2318,22 @@
;;; tutcode-editor¦¤Ç¤ÎÊÔ½¸´°Î»»þ¤Ë¸Æ¤Ð¤ì¤ë¡£
;;; @param str ¥¨¥Ç¥£¥¿Â¦¤Ç³ÎÄꤵ¤ì¤¿Ê¸»úÎó
(define (tutcode-commit-editor-context pc str)
- (let ((yomi-len (tutcode-context-postfix-yomi-len pc))
- (suffix (tutcode-context-mazegaki-suffix pc)))
- (if (> yomi-len 0)
- (tutcode-postfix-delete-text pc yomi-len))
- (tutcode-flush pc)
+ (let* ((yomi-len (tutcode-context-postfix-yomi-len pc))
+ (suffix (tutcode-context-mazegaki-suffix pc))
+ (commit-str (if (null? suffix)
+ str
+ (string-append str (string-list-concat suffix)))))
(tutcode-context-set-child-context! pc ())
(tutcode-context-set-child-type! pc ())
- (tutcode-commit pc
- (if (null? suffix)
- str
- (string-append str (string-list-concat suffix))))
+ (if (> yomi-len 0)
+ (let ((yomi (take (tutcode-context-mazegaki-yomi-all pc) yomi-len)))
+ (tutcode-postfix-delete-text pc yomi-len)
+ (tutcode-flush pc)
+ (tutcode-commit pc commit-str)
+ (tutcode-undo-prepare pc commit-str yomi))
+ (begin
+ (tutcode-flush pc)
+ (tutcode-commit pc commit-str)))
(tutcode-update-preedit pc)))
;;; Êä´°¸õÊä¤ò¸¡º÷¤·¤Æ¸õÊ䥦¥£¥ó¥É¥¦¤Ëɽ¼¨¤¹¤ë
@@ -2807,6 +2822,8 @@
(tutcode-begin-postfix-mazegaki-inflection-conversion pc
9))
((eq? res 'tutcode-history-start)
(tutcode-begin-history pc))
+ ((eq? res 'tutcode-undo)
+ (tutcode-undo pc))
((eq? res 'tutcode-auto-help-redisplay)
(tutcode-auto-help-redisplay pc))))))))))
@@ -2818,8 +2835,25 @@
(tutcode-bushu-convert (cadr former-seq) (car
former-seq)))))
(tutcode-postfix-delete-text pc 2)
(tutcode-commit pc res)
+ (tutcode-undo-prepare pc res former-seq)
(tutcode-check-auto-help-window-begin pc (list res) ())))
+;;; ¸åÃÖ·¿ÊÑ´¹¤Î³ÎÄê¤òundo¤¹¤ë
+(define (tutcode-undo pc)
+ (and-let*
+ ((undo (tutcode-context-undo pc))
+ (len (and (pair? undo) (car undo)))
+ (strs (cdr undo)))
+ (tutcode-postfix-delete-text pc len)
+ (tutcode-commit pc (string-list-concat strs) #t #t)))
+
+;;; ¸åÃÖ·¿ÊÑ´¹¤Î³ÎÄê¤òundo¤¹¤ë¤¿¤á¤Î½àÈ÷
+;;; @param commit-str ³ÎÄêʸ»úÎó
+;;; @param yomi-str ÊÑ´¹¸µ¤Îʸ»úÎó(ÆÉ¤ß/Éô¼ó)¤Î¥ê¥¹¥È(µÕ½ç)
+(define (tutcode-undo-prepare pc commit-str yomi-list)
+ (let ((commit-len (length (string-to-list commit-str))))
+ (tutcode-context-set-undo! pc (cons commit-len yomi-list))))
+
;;; ¸åÃÖ·¿¸ò¤¼½ñ¤ÊÑ´¹¤ò³«»Ï¤¹¤ë
;;; @param yomi-len »ØÄꤵ¤ì¤¿ÆÉ¤ß¤Îʸ»ú¿ô¡£»ØÄꤵ¤ì¤Æ¤Ê¤¤¾ì¹ç¤Ï#f¡£
;;; @param autocommit? ¸õÊ䤬1¸Ä¤Î¾ì¹ç¤Ë¼«Æ°Åª¤Ë³ÎÄꤹ¤ë¤«¤É¤¦¤«
@@ -3926,10 +3960,17 @@
(tutcode-heading-label-char? key))
(tutcode-commit-by-label-key pc (charcode->string key)))
(else
- (let ((postfix-yomi-len (tutcode-context-postfix-yomi-len pc)))
+ (let* ((postfix-yomi-len (tutcode-context-postfix-yomi-len pc))
+ (yomi (and (> postfix-yomi-len 0)
+ (take (tutcode-context-mazegaki-yomi-all pc)
+ postfix-yomi-len)))
+ (commit-str (tutcode-prepare-commit-string pc)))
(if (> postfix-yomi-len 0)
- (tutcode-postfix-delete-text pc postfix-yomi-len)))
- (tutcode-commit pc (tutcode-prepare-commit-string pc))
+ (begin
+ (tutcode-postfix-delete-text pc postfix-yomi-len)
+ (tutcode-commit pc commit-str)
+ (tutcode-undo-prepare pc commit-str yomi))
+ (tutcode-commit pc commit-str)))
(tutcode-proc-state-on pc key key-state)))))
;;; Éô¼ó¹çÀ®ÊÑ´¹¤ò¹Ô¤¦¡£
@@ -5214,7 +5255,9 @@
(make-subrule
tutcode-postfix-mazegaki-inflection-9-start-sequence
'(tutcode-postfix-mazegaki-inflection-9-start))
(make-subrule tutcode-auto-help-redisplay-sequence
- '(tutcode-auto-help-redisplay)))))))
+ '(tutcode-auto-help-redisplay))
+ (make-subrule tutcode-undo-sequence
+ '(tutcode-undo)))))))
;;; ¥³¡¼¥Éɽ¤Î°ìÉô¤ÎÄêµÁ¤ò¾å½ñ¤Êѹ¹/Äɲ乤롣~/.uim¤«¤é¤Î»ÈÍѤòÁÛÄê¡£
;;; ¸Æ¤Ó½Ð¤·»þ¤Ë¤Ïtutcode-rule-userconfig¤ËÅÐÏ¿¤·¤Æ¤ª¤¯¤À¤±¤Ç¡¢