Revision: 6991
Author:   deton.kih
Date:     Wed Apr  6 04:54:23 2011
Log:      * Add history input mode for tutcode.
* scm/tutcode-custom.scm
  - (tutcode-history-size,
    tutcode-nr-candidate-max-for-history): New custom.
* scm/tutcode-key-custom.scm
  - (tutcode-history-start-sequence): New custom.
* scm/tutcode.scm
  - Add comment about history input mode.
  - (tutcode-heading-label-char-list-for-history): New variable.
  - (tutcode-context-rec-spec): Add history.
  - (tutcode-context-new):
    Add initialization of tutcode-heading-label-char-list-for-history.
  - (tutcode-get-nth-candidate-for-history,
    tutcode-get-current-candidate-for-history,
    tutcode-prepare-commit-string-for-history): New.
  - (tutcode-commit): Change to update commit history list.
  - (tutcode-commit-by-label-key):
    Change to use tutcode-get-idx-by-label-key.
  - (tutcode-commit-by-label-key-for-prediction): Ditto.
  - (tutcode-get-idx-by-label-key):
    New function extracted and merged from tutcode-commit-by-label-key
    and tutcode-commit-by-label-key-for-prediction.
  - (tutcode-commit-by-label-key-for-history): New.
  - (tutcode-append-history): New.
  - (tutcode-begin-history): New.
  - (tutcode-check-candidate-window-begin): Change for history mode.
  - (tutcode-stroke-help-update-alist-with-rule):
    Add label for history start sequence.
  - (tutcode-do-update-preedit): Add update for history mode.
  - (tutcode-proc-state-on):
Add parameter to tutcode-commit not to append to history on normal input.
    Add check of history start sequence.
  - (tutcode-postfix-delete-text):
    Add parameter to tutcode-commit not to append to history
    of fallback-backspace-string.
  - (tutcode-proc-state-history): New.
  - (tutcode-change-candidate-index): Fix error except in converting mode.
  - (tutcode-heading-label-char-for-history?): New.
  - (tutcode-proc-state-converting):
    Fix not to use key with modifier as label key.
  - (tutcode-state-has-preedit?): Add tutcode-state-history.
  - (tutcode-key-press-handler): Add history mode.
  - (tutcode-get-candidate-handler): Change for history mode.
  - (tutcode-set-candidate-index-handler): Change for history mode.
  - (tutcode-custom-set-mazegaki/bushu-start-sequence!):
    Add history start sequence.

http://code.google.com/p/uim/source/detail?r=6991

Modified:
 /trunk/scm/tutcode-custom.scm
 /trunk/scm/tutcode-key-custom.scm
 /trunk/scm/tutcode.scm

=======================================
--- /trunk/scm/tutcode-custom.scm       Thu Feb 24 03:17:36 2011
+++ /trunk/scm/tutcode-custom.scm       Wed Apr  6 04:54:23 2011
@@ -116,6 +116,12 @@
   (N_ "Enable fallback of surrounding text API")
   (N_ "long description will be here."))

+(define-custom 'tutcode-history-size 0
+  '(tutcode)
+  '(integer 0 65535)
+  (N_ "History size")
+  (N_ "long description will be here."))
+
 (define-custom 'tutcode-mazegaki-yomi-max 10
   '(tutcode tutcode-mazegaki)
   '(integer 1 99)
@@ -215,6 +221,12 @@
(N_ "Number of candidates in candidate window at a time for kanji combination guide")
   (N_ "long description will be here."))

+(define-custom 'tutcode-nr-candidate-max-for-history 10
+  '(tutcode candwin)
+  '(integer 1 99)
+  (N_ "Number of candidates in candidate window at a time for history")
+  (N_ "long description will be here."))
+
 (define-custom 'tutcode-use-stroke-help-window? #f
   '(tutcode candwin)
   '(boolean)
=======================================
--- /trunk/scm/tutcode-key-custom.scm   Wed Apr  6 04:21:34 2011
+++ /trunk/scm/tutcode-key-custom.scm   Wed Apr  6 04:54:23 2011
@@ -227,6 +227,12 @@
               (N_ "[TUT-Code] kanji code input mode")
               (N_ "long description will be here"))

+(define-custom 'tutcode-history-start-sequence ""
+               '(tutcode-keys1 mode-transition)
+              '(string ".*")
+              (N_ "[TUT-Code] history")
+              (N_ "long description will be here"))
+
 (define-custom 'tutcode-auto-help-redisplay-sequence ""
                '(tutcode-keys1)
               '(string ".*")
=======================================
--- /trunk/scm/tutcode.scm      Wed Apr  6 04:44:06 2011
+++ /trunk/scm/tutcode.scm      Wed Apr  6 04:54:23 2011
@@ -220,6 +220,11 @@
;;; 1Ì̤ξì¹ç¡¢ÌÌ-¤Ï¾Êά²Äǽ¡£(Îã:1-48-13¤Þ¤¿¤Ï48-13)
 ;;; + JIS¥³¡¼¥É(ISO-2022-JP): 4·å¤Î16¿Ê¿ô¡£(Îã:502d)
 ;;;
+;;; ¡Ú¥Ò¥¹¥È¥êÆþÎϥ⡼¥É¡Û
+;;;   ºÇ¶á¤ÎÉô¼ó¹çÀ®ÊÑ´¹¤ä¸ò¤¼½ñ¤­ÊÑ´¹¡¢Êä´°/ͽ¬ÆþÎÏ¡¢µ­¹æÆþÎÏ¡¢
+;;;   ´Á»ú¥³¡¼¥ÉÆþÎϤdzÎÄꤷ¤¿Ê¸»úÎó¤òºÆÆþÎϤ¹¤ë¥â¡¼¥É¡£
+;;;   tutcode-history-size¤ò1°Ê¾å¤ËÀßÄꤹ¤ë¤ÈÍ­¸ú¤Ë¤Ê¤ê¤Þ¤¹¡£
+;;;
 ;;; ¡ÚÀßÄêÎã¡Û
;;; * ¥³¡¼¥Éɽ¤Î°ìÉô¤òÊѹ¹¤·¤¿¤¤¾ì¹ç¤Ï¡¢Î㤨¤Ð~/.uim¤Ç°Ê²¼¤Î¤è¤¦¤Ëµ­½Ò¤¹¤ë¡£
 ;;;   (require "tutcode.scm")
@@ -429,6 +434,9 @@
 ;;; (Á´³Ñ±Ñ¿ô¥â¡¼¥É¤È¤·¤Æ»È¤¦¤Ë¤Ï¡¢tutcode-kigoudic¤È¹ç¤ï¤»¤ëɬÍפ¢¤ê)
 (define tutcode-heading-label-char-list-for-kigou-mode ())

+;;; ¥Ò¥¹¥È¥êÆþÎÏ»þ¤Î¸õÊäÁªÂòÍÑ¥é¥Ù¥ëʸ»ú¤Î¥ê¥¹¥È
+(define tutcode-heading-label-char-list-for-history ())
+
 ;;; Êä´°/ͽ¬ÆþÎÏ»þ¤Î¸õÊäÁªÂòÍÑ¥é¥Ù¥ëʸ»ú¤Î¥ê¥¹¥È¡£
 ;;; (Ä̾ï¤Îʸ»úÆþÎϤ˱ƶÁ¤·¤Ê¤¤¤è¤¦¤Ë¡¢1ÂǸ°ÌܤȤ«¤Ö¤é¤Ê¤¤Ê¸»ú¤ò»ÈÍÑ¡£
 ;;; µ­¹æ(¤ä¿ô»ú)¤ÏľÀÜÆþÎϤǤ­¤ë¤è¤¦¤Ë¡¢¤³¤³¤Ç¤Ï´Þ¤á¤Ê¤¤)
@@ -634,6 +642,7 @@
      ;;; 'tutcode-state-bushu Éô¼óÆþÎÏ¡¦ÊÑ´¹Ãæ
      ;;; 'tutcode-state-interactive-bushu ÂÐÏÃŪÉô¼ó¹çÀ®ÊÑ´¹Ãæ
      ;;; 'tutcode-state-kigou µ­¹æÆþÎϥ⡼¥É
+     ;;; 'tutcode-state-history ¥Ò¥¹¥È¥êÆþÎϥ⡼¥É
      (list 'state 'tutcode-state-off)
      ;;; ¥«¥¿¥«¥Ê¥â¡¼¥É¤«¤É¤¦¤«
      ;;; #t: ¥«¥¿¥«¥Ê¥â¡¼¥É¡£#f: ¤Ò¤é¤¬¤Ê¥â¡¼¥É¡£
@@ -665,6 +674,7 @@
      ;;; 'tutcode-candidate-window-auto-help ¼«Æ°¥Ø¥ë¥×ɽ¼¨Ãæ
      ;;; 'tutcode-candidate-window-predicting Êä´°/ͽ¬ÆþÎϸõÊäɽ¼¨Ãæ
;;; 'tutcode-candidate-window-interactive-bushu ÂÐÏÃŪÉô¼ó¹çÀ®ÊÑ´¹¸õÊäɽ¼¨
+     ;;; 'tutcode-candidate-window-history ¥Ò¥¹¥È¥êÆþÎϸõÊäɽ¼¨Ãæ
      (list 'candidate-window 'tutcode-candidate-window-off)
      ;;; ¥¹¥È¥í¡¼¥¯É½
;;; ¼¡¤ËÆþÎϤ¹¤ë¥­¡¼¤Èʸ»ú¤ÎÂбþ¤Î¡¢get-candidate-handlerÍÑ·Á¼°¤Ç¤Î¥ê¥¹¥È
@@ -689,6 +699,8 @@
      (list 'commit-strs ())
      ;;; commit-strs¤Î¤¦¤Á¤ÇÊä´°¤Ë»ÈÍѤ·¤Æ¤¤¤ëʸ»ú¿ô
      (list 'commit-strs-used-len 0)
+     ;;; commit¤·¤¿Ê¸»úÎó¤ÎÍúÎò(¥Ò¥¹¥È¥êÆþÎÏÍÑ)
+     (list 'history ())
      ;;; Êä´°/ͽ¬ÆþÎϤθõÊäÁªÂòÃæ¤«¤É¤¦¤«
      ;;; 'tutcode-predicting-off Êä´°/ͽ¬ÆþÎϤθõÊäÁªÂòÃæ¤Ç¤Ê¤¤
      ;;; 'tutcode-predicting-completion Êä´°¸õÊäÁªÂòÃæ
@@ -781,6 +793,9 @@
             (else tutcode-table-heading-label-char-list)))
         (set! tutcode-heading-label-char-list
           tutcode-uim-heading-label-char-list)))
+    (if (null? tutcode-heading-label-char-list-for-history)
+      (set! tutcode-heading-label-char-list-for-history
+        tutcode-heading-label-char-list))
     (if (null? tutcode-heading-label-char-list-for-kigou-mode)
       (if tutcode-use-table-style-candidate-window?
         (begin
@@ -1140,6 +1155,11 @@
 (define (tutcode-get-nth-candidate-for-kigou-mode pc n)
  (car (nth n tutcode-kigoudic)))

+;;; ¥Ò¥¹¥È¥êÆþÎϥ⡼¥É»þ¤ÎnÈÖÌܤθõÊä¤òÊÖ¤¹¡£
+;;; @param n ÂоݤθõÊäÈÖ¹æ
+(define (tutcode-get-nth-candidate-for-history pc n)
+  (list-ref (tutcode-context-history pc) n))
+
 ;;; ¸ò¤¼½ñ¤­ÊÑ´¹Ãæ¤Î¸½ºßÁªÂòÃæ¤Î¸õÊä¤òÊÖ¤¹¡£
 ;;; @param pc ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È
 (define (tutcode-get-current-candidate pc)
@@ -1149,6 +1169,10 @@
 (define (tutcode-get-current-candidate-for-kigou-mode pc)
   (tutcode-get-nth-candidate-for-kigou-mode pc (tutcode-context-nth pc)))

+;;; ¥Ò¥¹¥È¥êÆþÎϥ⡼¥É»þ¤Î¸½ºßÁªÂòÃæ¤Î¸õÊä¤òÊÖ¤¹¡£
+(define (tutcode-get-current-candidate-for-history pc)
+  (tutcode-get-nth-candidate-for-history pc (tutcode-context-nth pc)))
+
 ;;; ¸ò¤¼½ñ¤­ÊÑ´¹¤Ç³ÎÄꤷ¤¿Ê¸»úÎó¤òÊÖ¤¹¡£
 ;;; @param pc ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È
 ;;; @return ³ÎÄꤷ¤¿Ê¸»úÎó
@@ -1179,6 +1203,10 @@
 (define (tutcode-prepare-commit-string-for-kigou-mode pc)
   (tutcode-get-current-candidate-for-kigou-mode pc))

+;;; ¥Ò¥¹¥È¥êÆþÎϥ⡼¥É»þ¤Ë³ÎÄꤷ¤¿Ê¸»úÎó¤òÊÖ¤¹¡£
+(define (tutcode-prepare-commit-string-for-history pc)
+  (tutcode-get-current-candidate-for-history pc))
+
 ;;; im-commit-raw¤ò¸Æ¤Ó½Ð¤¹¡£
 ;;; ¤¿¤À¤·¡¢»Ò¥³¥ó¥Æ¥­¥¹¥È¤Î¾ì¹ç¤Ï¡¢editor¤«dialog¤ËÆþÎÏ¥­¡¼¤òÅϤ¹¡£
 (define (tutcode-commit-raw pc key key-state)
@@ -1194,13 +1222,21 @@
 ;;; im-commit¤ò¸Æ¤Ó½Ð¤¹¡£
 ;;; ¤¿¤À¤·¡¢»Ò¥³¥ó¥Æ¥­¥¹¥È¤Î¾ì¹ç¤Ï¡¢editor¤«dialog¤ËÆþÎÏ¥­¡¼¤òÅϤ¹¡£
 ;;; @param str ¥³¥ß¥Ã¥È¤¹¤ëʸ»úÎó
-;;; @param opt-skip-append-commit-strs? commit-strs¤Ø¤ÎÄɲäò
-;;;  ¥¹¥­¥Ã¥×¤¹¤ë¤«¤É¤¦¤«¡£Ì¤»ØÄê»þ¤Ï#f
-(define (tutcode-commit pc str . opt-skip-append-commit-strs?)
-  (if
- (and (or tutcode-use-completion? tutcode-enable-fallback-surrounding-text?)
-         (not (:optional opt-skip-append-commit-strs? #f)))
-    (tutcode-append-commit-string pc str))
+;;; @param opts ¥ª¥×¥·¥ç¥ó°ú¿ô¡£
+;;;  opt-skip-append-commit-strs? commit-strs¤Ø¤ÎÄɲäò
+;;;  ¥¹¥­¥Ã¥×¤¹¤ë¤«¤É¤¦¤«¡£Ì¤»ØÄê»þ¤Ï#f¡£
+;;;  opt-skip-append-history? history¤Ø¤ÎÄɲäò
+;;;  ¥¹¥­¥Ã¥×¤¹¤ë¤«¤É¤¦¤«¡£Ì¤»ØÄê»þ¤Ï#f¡£
+(define (tutcode-commit pc str . opts)
+  (let-optionals* opts ((opt-skip-append-commit-strs? #f)
+                        (opt-skip-append-history? #f))
+    (if (and
+ (or tutcode-use-completion? tutcode-enable-fallback-surrounding-text?)
+          (not opt-skip-append-commit-strs?))
+      (tutcode-append-commit-string pc str))
+    (if (and (> tutcode-history-size 0)
+             (not opt-skip-append-history?))
+      (tutcode-append-history pc str)))
   (let ((ppc (tutcode-context-parent-context pc)))
     (if (not (null? ppc))
       (if (eq? (tutcode-context-child-type ppc) 'tutcode-child-type-editor)
@@ -1231,30 +1267,45 @@
   ;; ¤Ê¤ë¤Ù¤¯¾¯¤Ê¤¤¥­¡¼¤ÇÌÜŪ¤Î¸õÊä¤òÁª¤Ù¤ë¤è¤¦¤Ë¤¹¤ë¤¿¤á)
   (let* ((nr (tutcode-context-nr-candidates pc))
          (nth (tutcode-context-nth pc))
-         (cur-page (cond
-                     ((= tutcode-nr-candidate-max 0) 0)
-                     (else
-                       (quotient nth tutcode-nr-candidate-max))))
-         ;; ¸½ºß¸õÊ䥦¥£¥ó¥É¥¦¤Ëɽ¼¨Ãæ¤Î¸õÊä¥ê¥¹¥È¤ÎÀèÆ¬¤Î¸õÊäÈÖ¹æ
-         (cur-offset (* cur-page tutcode-nr-candidate-max))
-         (cur-labels (list-tail
-                       tutcode-heading-label-char-list
-                       (remainder cur-offset
- (length tutcode-heading-label-char-list))))
-         (target-labels (member ch cur-labels))
-         (offset (if target-labels
-                   (- (length cur-labels) (length target-labels))
-                   (+ (length cur-labels)
-                      (- (length tutcode-heading-label-char-list)
-                         (length
-                           (member ch tutcode-heading-label-char-list))))))
-         (idx (+ cur-offset offset)))
+         (idx
+          (tutcode-get-idx-by-label-key ch nth tutcode-nr-candidate-max
+            tutcode-nr-candidate-max tutcode-heading-label-char-list)))
     (if (and (>= idx 0)
              (< idx nr))
       (begin
         (tutcode-context-set-nth! pc idx)
         (tutcode-commit-with-auto-help pc)))))

+;;; ¸õÊäÁªÂò»þ¤Ë¡¢»ØÄꤵ¤ì¤¿¥é¥Ù¥ëʸ»ú¤ËÂбþ¤¹¤ë¸õÊäÈÖ¹æ¤ò·×»»¤¹¤ë
+;;; @param ch ÆþÎϤµ¤ì¤¿¥é¥Ù¥ëʸ»ú
+;;; @param nth ¸½ºßÁªÂò¤µ¤ì¤Æ¤¤¤ë¸õÊä¤ÎÈÖ¹æ
+;;; @param page-limit ¸õÊäÁªÂò¥¦¥£¥ó¥É¥¦¤Ç¤Î³Æ¥Ú¡¼¥¸Æâ¤Î¸õÊä¿ô¾å¸Â
+;;;                   (Êä´°¤Î¾ì¹ç:Êä´°¸õÊä+½Ï¸ì¥¬¥¤¥É)
+;;; @param nr-in-page ¸õÊäÁªÂò¥¦¥£¥ó¥É¥¦¤Ç¤Î³Æ¥Ú¡¼¥¸Æâ¤Î¸õÊä¿ô
+;;;                   (Êä´°¤Î¾ì¹ç:Êä´°¸õÊä¤Î¤ß)
+;;; @param heading-label-char-list ¥é¥Ù¥ëʸ»ú¤ÎÇÛÎó
+;;; @return ¸õÊäÈÖ¹æ
+(define (tutcode-get-idx-by-label-key ch nth page-limit nr-in-page
+        heading-label-char-list)
+  (let*
+    ((cur-page (if (= page-limit 0)
+                  0
+                  (quotient nth page-limit)))
+     ;; ¸½ºß¸õÊ䥦¥£¥ó¥É¥¦¤Ëɽ¼¨Ãæ¤Î¸õÊä¥ê¥¹¥È¤ÎÀèÆ¬¤Î¸õÊäÈÖ¹æ
+     (cur-offset (* cur-page nr-in-page))
+     (labellen (length heading-label-char-list))
+     (cur-labels
+       (list-tail heading-label-char-list (remainder cur-offset labellen)))
+     (target-labels (member ch cur-labels))
+     (offset (if target-labels
+               (- (length cur-labels) (length target-labels))
+               (+ (length cur-labels)
+                  (- labellen
+                     (length
+                       (member ch heading-label-char-list))))))
+     (idx (+ cur-offset offset)))
+    idx))
+
 ;;; µ­¹æÆþÎϥ⡼¥É»þ¤Ë¡¢»ØÄꤵ¤ì¤¿¥é¥Ù¥ëʸ»ú¤ËÂбþ¤¹¤ë¸õÊä¤ò³ÎÄꤹ¤ë
 (define (tutcode-commit-by-label-key-for-kigou-mode pc ch)
   ;; ¸ò¤¼½ñ¤­ÊÑ´¹»þ¤È°Û¤Ê¤ê¡¢¸½ºß¤è¤êÁ°¤Î¸õÊä¤ò³ÎÄꤹ¤ë¾ì¹ç¤¢¤ê
@@ -1281,6 +1332,25 @@
         (tutcode-commit pc
           (tutcode-prepare-commit-string-for-kigou-mode pc))))))

+;;; ¥Ò¥¹¥È¥êÆþÎϤθõÊäÁªÂò»þ¤Ë¡¢»ØÄꤵ¤ì¤¿¥é¥Ù¥ëʸ»ú¤ËÂбþ¤¹¤ë¸õÊä¤ò³ÎÄꤹ¤ë
+;;; @param ch ÆþÎϤµ¤ì¤¿¥é¥Ù¥ëʸ»ú
+(define (tutcode-commit-by-label-key-for-history pc ch)
+  (let* ((nr (tutcode-context-nr-candidates pc))
+         (nth (tutcode-context-nth pc))
+         (idx
+          (tutcode-get-idx-by-label-key ch nth
+            tutcode-nr-candidate-max-for-history
+            tutcode-nr-candidate-max-for-history
+            tutcode-heading-label-char-list-for-history)))
+    (if (and (>= idx 0)
+             (< idx nr))
+      (begin
+        (tutcode-context-set-nth! pc idx)
+        (let ((str (tutcode-prepare-commit-string-for-history pc)))
+          (tutcode-commit pc str)
+          (tutcode-flush pc)
+ (tutcode-check-auto-help-window-begin pc (string-to-list str) ()))))))
+
 ;;; Êä´°/ͽ¬ÆþÎϸõÊäɽ¼¨»þ¤Ë¡¢»ØÄꤵ¤ì¤¿¥é¥Ù¥ëʸ»ú¤ËÂбþ¤¹¤ë¸õÊä¤ò³ÎÄꤹ¤ë
 ;;; @param ch ÆþÎϤµ¤ì¤¿¥é¥Ù¥ëʸ»ú
 ;;; @param mode tutcode-context-predicting¤ÎÃÍ
@@ -1288,24 +1358,11 @@
   (let*
     ((nth (tutcode-context-prediction-index pc))
      (page-limit (tutcode-context-prediction-page-limit pc))
-     (cur-page (quotient nth page-limit))
      (nr-in-page (tutcode-context-prediction-nr-in-page pc))
-     ;; ¸½ºß¸õÊ䥦¥£¥ó¥É¥¦¤Ëɽ¼¨Ãæ¤Î¸õÊä¥ê¥¹¥È¤ÎÀèÆ¬¤Î¸õÊäÈÖ¹æ
-     (cur-offset (* cur-page nr-in-page))
-     (labellen (length tutcode-heading-label-char-list-for-prediction))
-     (cur-labels
-       (list-tail
-         tutcode-heading-label-char-list-for-prediction
-         (remainder cur-offset labellen)))
-     (target-labels (member ch cur-labels))
-     (offset (if target-labels
-               (- (length cur-labels) (length target-labels))
-               (+ (length cur-labels)
-                  (- labellen
-                     (length
- (member ch tutcode-heading-label-char-list-for-prediction))))))
+     (idx
+      (tutcode-get-idx-by-label-key ch nth page-limit nr-in-page
+        tutcode-heading-label-char-list-for-prediction))
      (nr (tutcode-lib-get-nr-predictions pc))
-     (idx (+ cur-offset offset))
      (i (remainder idx nr)))
     (if (>= i 0)
       (begin
@@ -1390,6 +1447,16 @@
           (take new-strs tutcode-completion-chars-max)
           new-strs)))))

+;;; commitʸ»úÎóÍúÎò¥ê¥¹¥Èhistory¤Ëʸ»úÎó¤òÄɲ乤롣
+;;; @param str Äɲ乤ëʸ»úÎó
+(define (tutcode-append-history pc str)
+  (let* ((history (tutcode-context-history pc))
+         (new-history (cons str (delete str history))))
+    (tutcode-context-set-history! pc
+      (if (> (length new-history) tutcode-history-size)
+        (take new-history tutcode-history-size)
+        new-history))))
+
 ;;; ¸ò¤¼½ñ¤­ÊÑ´¹¤ò³«»Ï¤¹¤ë
 ;;; @param yomi ÊÑ´¹ÂÐ¾Ý¤ÎÆÉ¤ß(ʸ»úÎó¤ÎµÕ½ç¥ê¥¹¥È)
 ;;; @param suffix ³èÍѤ¹¤ë¸ì¤ÎÊÑ´¹¤ò¹Ô¤¦¾ì¹ç¤Î³èÍѸìÈø(ʸ»úÎó¤ÎµÕ½ç¥ê¥¹¥È)
@@ -1589,6 +1656,20 @@
            'tutcode-candidate-window-kigou)
     (im-select-candidate pc 0)))

+;;; ¥Ò¥¹¥È¥êÆþÎϤθõÊäɽ¼¨¤ò³«»Ï¤¹¤ë
+(define (tutcode-begin-history pc)
+  (if (and (> tutcode-history-size 0)
+           (pair? (tutcode-context-history pc)))
+    (begin
+      (tutcode-context-set-nth! pc 0)
+      (tutcode-context-set-nr-candidates! pc
+        (length (tutcode-context-history pc)))
+      (tutcode-context-set-state! pc 'tutcode-state-history)
+      (tutcode-check-candidate-window-begin pc)
+      (if (eq? (tutcode-context-candidate-window pc)
+               'tutcode-candidate-window-hisory)
+        (im-select-candidate pc 0)))))
+
;;; 2¥¹¥È¥í¡¼¥¯µ­¹æÆþÎϥ⡼¥É(tutcode-kigou-rule)¤Ètutcode-rule¤ÎÀÚ¤êÂØ¤¨¤ò¹Ô¤¦
 ;;; @param pc ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È
 (define (tutcode-toggle-kigou2-mode pc)
@@ -1609,17 +1690,19 @@
                 'tutcode-candidate-window-off)
            tutcode-use-candidate-window?
            (>= (tutcode-context-nth pc) (- tutcode-candidate-op-count 1)))
-    (begin
+    (let ((state (tutcode-context-state pc)))
       (tutcode-context-set-candidate-window! pc
-        (if (eq? (tutcode-context-state pc) 'tutcode-state-kigou)
-          'tutcode-candidate-window-kigou
-          'tutcode-candidate-window-converting))
+        (case state
+          ((tutcode-state-kigou) 'tutcode-candidate-window-kigou)
+          ((tutcode-state-history) 'tutcode-candidate-window-history)
+          (else 'tutcode-candidate-window-converting)))
       (im-activate-candidate-selector
         pc
         (tutcode-context-nr-candidates pc)
-        (if (eq? (tutcode-context-state pc) 'tutcode-state-kigou)
-          tutcode-nr-candidate-max-for-kigou-mode
-          tutcode-nr-candidate-max)))))
+        (case state
+          ((tutcode-state-kigou) tutcode-nr-candidate-max-for-kigou-mode)
+          ((tutcode-state-history) tutcode-nr-candidate-max-for-history)
+          (else tutcode-nr-candidate-max))))))

 ;;; ²¾ÁÛ¸°ÈפÎɽ¼¨¤ò³«»Ï¤¹¤ë
 (define (tutcode-check-stroke-help-window-begin pc)
@@ -1739,6 +1822,7 @@
             ((tutcode-mazegaki-start) "¡þ")
             ((tutcode-latin-conv-start) "/")
             ((tutcode-kanji-code-input-start) "¢¢")
+            ((tutcode-history-start) "¡ý")
             ((tutcode-bushu-start) "¢¡")
             ((tutcode-interactive-bushu-start) "¢§")
             ((tutcode-postfix-bushu-start) "¢¥")
@@ -2106,7 +2190,11 @@
       ((tutcode-state-kigou)
         ;; ¸õÊ䥦¥£¥ó¥É¥¦Èóɽ¼¨»þ¤Ç¤â¸õÊäÁªÂò¤Ç¤­¤ë¤è¤¦¤Ëpreeditɽ¼¨
         (im-pushback-preedit pc preedit-reverse
-          (tutcode-get-current-candidate-for-kigou-mode pc))))
+          (tutcode-get-current-candidate-for-kigou-mode pc)))
+      ((tutcode-state-history)
+        (im-pushback-preedit pc preedit-none "¡ý")
+        (im-pushback-preedit pc preedit-none
+          (tutcode-get-current-candidate-for-history pc))))
     (if (not cursor-shown?)
       (im-pushback-preedit pc preedit-cursor ""))))

@@ -2438,7 +2526,7 @@
            (let ((res (tutcode-push-key! pc (charcode->string key))))
             (cond
               ((string? res)
-                (tutcode-commit pc res)
+                (tutcode-commit pc res #f (not (tutcode-kigou2-mode? pc)))
                 (if (and tutcode-use-completion?
                          (> tutcode-completion-chars-min 0))
                   (tutcode-check-completion pc #f 0)))
@@ -2510,6 +2598,8 @@
(tutcode-begin-postfix-mazegaki-inflection-conversion pc 8))
               ((eq? res 'tutcode-postfix-mazegaki-inflection-9-start)
(tutcode-begin-postfix-mazegaki-inflection-conversion pc 9))
+              ((eq? res 'tutcode-history-start)
+                (tutcode-begin-history pc))
               ((eq? res 'tutcode-auto-help-redisplay)
                 (tutcode-auto-help-redisplay pc))))))))))

@@ -2869,7 +2959,7 @@
               (tutcode-commit pc
                 (tutcode-make-string
                   (make-list len tutcode-fallback-backspace-string))
-                #t))))))))
+                #t #t))))))))

 ;;; ľÀÜÆþÎϾõÂ֤ΤȤ­¤Î¥­¡¼ÆþÎϤò½èÍý¤¹¤ë¡£
 ;;; @param c ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È
@@ -2938,6 +3028,39 @@
       (else
         (tutcode-commit-raw pc key key-state)))))

+;;; ¥Ò¥¹¥È¥êÆþÎϥ⡼¥É»þ¤Î¥­¡¼ÆþÎϤò½èÍý¤¹¤ë¡£
+;;; @param key ÆþÎϤµ¤ì¤¿¥­¡¼
+;;; @param key-state ¥³¥ó¥È¥í¡¼¥ë¥­¡¼Åù¤Î¾õÂÖ
+(define (tutcode-proc-state-history c key key-state)
+  (let ((pc (tutcode-find-descendant-context c)))
+    (cond
+      ((tutcode-next-candidate-key? key key-state)
+        (tutcode-change-candidate-index pc 1))
+      ((tutcode-prev-candidate-key? key key-state)
+        (tutcode-change-candidate-index pc -1))
+      ((tutcode-next-page-key? key key-state)
+        (tutcode-change-candidate-index pc
+          tutcode-nr-candidate-max-for-history))
+      ((tutcode-prev-page-key? key key-state)
+        (tutcode-change-candidate-index pc
+          (- tutcode-nr-candidate-max-for-history)))
+      ((tutcode-cancel-key? key key-state)
+        (tutcode-flush pc))
+      ((and (not (and (modifier-key-mask key-state)
+                      (not (shift-key-mask key-state))))
+            (tutcode-heading-label-char-for-history? key))
+ (tutcode-commit-by-label-key-for-history pc (charcode->string key)))
+      ((or (tutcode-commit-key? key key-state)
+           (tutcode-return-key? key key-state))
+        (let ((str (tutcode-prepare-commit-string-for-history pc)))
+          (tutcode-commit pc str)
+          (tutcode-flush pc)
+ (tutcode-check-auto-help-window-begin pc (string-to-list str) ())))
+      (else
+        (tutcode-commit pc (tutcode-prepare-commit-string-for-history pc))
+        (tutcode-flush pc)
+        (tutcode-proc-state-on pc key key-state)))))
+
 ;;; ¸ò¤¼½ñ¤­ÊÑ´¹¤ÎÆÉ¤ßÆþÎϾõÂ֤ΤȤ­¤Î¥­¡¼ÆþÎϤò½èÍý¤¹¤ë¡£
 ;;; @param c ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È
 ;;; @param key ÆþÎϤµ¤ì¤¿¥­¡¼
@@ -3435,7 +3558,10 @@
     (cond
       ((< new-nth 0)
        (set! new-nth 0))
- ((and tutcode-use-recursive-learning? (= nth (- nr 1)) (>= new-nth nr))
+      ((and tutcode-use-recursive-learning?
+            (eq? (tutcode-context-state pc) 'tutcode-state-converting)
+            (= nth (- nr 1))
+            (>= new-nth nr))
        (tutcode-reset-candidate-window pc)
        (tutcode-setup-child-context pc 'tutcode-child-type-editor))
       ((>= new-nth nr)
@@ -3518,6 +3644,11 @@
 (define (tutcode-heading-label-char-for-kigou-mode? key)
(member (charcode->string key) tutcode-heading-label-char-list-for-kigou-mode))

+;;; ÆþÎϤµ¤ì¤¿¥­¡¼¤¬¥Ò¥¹¥È¥êÆþÎϥ⡼¥É»þ¤Î¸õÊä¥é¥Ù¥ëʸ»ú¤«¤É¤¦¤«¤òÄ´¤Ù¤ë
+;;; @param key ÆþÎϤµ¤ì¤¿¥­¡¼
+(define (tutcode-heading-label-char-for-history? key)
+ (member (charcode->string key) tutcode-heading-label-char-list-for-history))
+
 ;;; ÆþÎϤµ¤ì¤¿¥­¡¼¤¬Êä´°/ͽ¬ÆþÎÏ»þ¤Î¸õÊä¥é¥Ù¥ëʸ»ú¤«¤É¤¦¤«¤òÄ´¤Ù¤ë
 ;;; @param key ÆþÎϤµ¤ì¤¿¥­¡¼
 (define (tutcode-heading-label-char-for-prediction? key)
@@ -3555,6 +3686,8 @@
       ((tutcode-mazegaki-relimit-left-key? key key-state)
         (tutcode-mazegaki-proc-relimit-left pc))
       ((and tutcode-commit-candidate-by-label-key?
+            (not (and (modifier-key-mask key-state)
+                      (not (shift-key-mask key-state))))
             (> (tutcode-context-nr-candidates pc) 1)
             (tutcode-heading-label-char? key))
         (tutcode-commit-by-label-key pc (charcode->string key)))
@@ -3957,7 +4090,7 @@
     (memq (tutcode-context-state pc)
       '(tutcode-state-yomi tutcode-state-bushu tutcode-state-converting
         tutcode-state-interactive-bushu tutcode-state-kigou
-        tutcode-state-code))))
+        tutcode-state-code tutcode-state-history))))

 ;;; ¥­¡¼¤¬²¡¤µ¤ì¤¿¤È¤­¤Î½èÍý¤Î¿¶¤êʬ¤±¤ò¹Ô¤¦¡£
 ;;; @param c ¥³¥ó¥Æ¥­¥¹¥È¥ê¥¹¥È
@@ -3994,6 +4127,9 @@
           ((tutcode-state-code)
            (tutcode-proc-state-code pc key key-state)
            (tutcode-update-preedit pc))
+          ((tutcode-state-history)
+           (tutcode-proc-state-history pc key key-state)
+           (tutcode-update-preedit pc))
           (else
            (tutcode-proc-state-off pc key key-state)
            (if (tutcode-state-has-preedit? c) ; ºÆµ¢³Ø½¬»þ
@@ -4054,6 +4190,8 @@
(set! tutcode-nr-candidate-max (length tutcode-heading-label-char-list))
         (set! tutcode-nr-candidate-max-for-kigou-mode
           (length tutcode-heading-label-char-list-for-kigou-mode))
+        (set! tutcode-nr-candidate-max-for-history
+          (length tutcode-heading-label-char-list-for-history))
         (set! tutcode-nr-candidate-max-for-prediction
           (length tutcode-heading-label-char-list-for-prediction))
         (set! tutcode-nr-candidate-max-for-guide
@@ -4065,6 +4203,8 @@
               (cond
                 ((eq? (tutcode-context-state tc) 'tutcode-state-kigou)
                   tutcode-nr-candidate-max-for-kigou-mode)
+                ((eq? (tutcode-context-state tc) 'tutcode-state-history)
+                  tutcode-nr-candidate-max-for-history)
                 ((eq? (tutcode-context-state tc)
                       'tutcode-state-interactive-bushu)
                   (tutcode-context-prediction-page-limit tc))
@@ -4081,6 +4221,13 @@
(label (nth n tutcode-heading-label-char-list-for-kigou-mode))) ;; XXX:annotationɽ¼¨¤Ï¸½¾õ̵¸ú²½¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢¾ï¤Ë""¤òÊÖ¤·¤Æ¤ª¤¯
           (list cand label "")))
+      ;; ¥Ò¥¹¥È¥êÆþÎÏ
+      ((eq? (tutcode-context-state tc) 'tutcode-state-history)
+        (let* ((cand (tutcode-get-nth-candidate-for-history tc idx))
+               (n (remainder idx
+                    (length tutcode-heading-label-char-list-for-history)))
+               (label (nth n tutcode-heading-label-char-list-for-history)))
+          (list cand label "")))
       ;; Êä´°/ͽ¬ÆþÎϸõÊä
       ((not (eq? (tutcode-context-predicting tc) 'tutcode-predicting-off))
         (let*
@@ -4161,14 +4308,22 @@
   (let* ((pc (tutcode-find-descendant-context c))
          (candwin (tutcode-context-candidate-window pc)))
     (cond
-      ((and (or (eq? candwin 'tutcode-candidate-window-converting)
-                (eq? candwin 'tutcode-candidate-window-kigou))
+      ((and (memq candwin '(tutcode-candidate-window-converting
+                            tutcode-candidate-window-kigou
+                            tutcode-candidate-window-history))
           (>= idx 0)
           (< idx (tutcode-context-nr-candidates pc)))
         (tutcode-context-set-nth! pc idx)
-        (if (eq? (tutcode-context-state pc) 'tutcode-state-kigou)
- (tutcode-commit pc (tutcode-prepare-commit-string-for-kigou-mode pc))
-          (tutcode-commit-with-auto-help pc))
+        (case (tutcode-context-state pc)
+          ((tutcode-state-kigou)
+ (tutcode-commit pc (tutcode-prepare-commit-string-for-kigou-mode pc)))
+          ((tutcode-state-history)
+            (let ((str (tutcode-prepare-commit-string-for-history pc)))
+              (tutcode-commit pc str)
+              (tutcode-flush pc)
+ (tutcode-check-auto-help-window-begin pc (string-to-list str) ())))
+          (else
+            (tutcode-commit-with-auto-help pc)))
         (tutcode-update-preedit pc))
       ((and (or (eq? candwin 'tutcode-candidate-window-predicting)
                 (eq? candwin 'tutcode-candidate-window-interactive-bushu))
@@ -4461,6 +4616,8 @@
             '(tutcode-latin-conv-start))
           (make-subrule tutcode-kanji-code-input-start-sequence
             '(tutcode-kanji-code-input-start))
+          (make-subrule tutcode-history-start-sequence
+            '(tutcode-history-start))
           (make-subrule tutcode-bushu-start-sequence
             '(tutcode-bushu-start))
           (and

Reply via email to