Hiroyuki Komatsu
komat****@users*****
2005年 2月 1日 (火) 08:38:12 JST
Index: prime/uim/prime.scm diff -u prime/uim/prime.scm:1.1.2.18 prime/uim/prime.scm:1.1.2.19 --- prime/uim/prime.scm:1.1.2.18 Sat Jan 29 04:04:12 2005 +++ prime/uim/prime.scm Tue Feb 1 08:38:11 2005 @@ -103,6 +103,11 @@ (define-key prime-space-key? '(" ")) (define-key prime-altspace-key? '("<Control> " "<Alt> ")) +(define-key prime-english-next-candidate-key? '("<Control>i" + generic-next-candidate-key?)) +(define-key prime-english-direct-key? '("." "," ":" ";" "(" ")" "\"" "'" + "!" "?")) + (define-key prime-app-mode-start-key? #f) (define prime-app-mode-end-stroke-list #f) ;; If you're a vi user, comment out the lines below. @@ -346,6 +351,59 @@ (prime-any-key? . prime-command-pass) )) +;; Keymaps for English + +(define prime-keymap-english-fund-state + '( + (prime-space-key? . prime-command-commit-raw) + (prime-english-direct-key? . prime-command-commit-raw) + (prime-wide-latin-key? . prime-command-wide-latin-mode) + (prime-latin-key? . prime-command-latin-mode) + (prime-app-mode-start-key? . prime-command-app-mode-start) + (prime-language-toggle-key? . prime-command-language-toggle) + + (prime-with-control-key? . prime-command-commit-raw) + (prime-symbol-key? . prime-command-commit-raw) + (prime-any-key? . prime-command-fund-input) + )) + +(define prime-keymap-english-preedit-state + '( + (prime-space-key? . prime-command-preedit-commit-and-space) + (prime-english-direct-key? . prime-command-preedit-commit-and-commit-raw) + (prime-begin-conv-key? . prime-command-preedit-convert) + (prime-english-next-candidate-key? . prime-command-preedit-convert) + (prime-prev-candidate-key? . prime-command-preedit-convert-reversely) + (prime-delete-key? . prime-command-preedit-delete) + (prime-cancel-key? . prime-command-preedit-cancel) + (prime-backspace-key? . prime-command-preedit-backspace) + (prime-commit-key? . prime-command-preedit-commit) + (prime-go-left-edge-key? . prime-command-preedit-cursor-left-edge) + (prime-go-right-edge-key? . prime-command-preedit-cursor-right-edge) + (prime-go-left-key? . prime-command-preedit-cursor-left) + (prime-go-right-key? . prime-command-preedit-cursor-right) + (prime-cand-select-key? . prime-command-preedit-commit-candidate) + + (prime-command-key? . prime-command-pass) + (prime-symbol-key? . prime-command-pass) + (prime-any-key? . prime-command-preedit-input) + )) + +(define prime-keymap-english-conv-state + '( + (prime-space-key? . prime-command-conv-commit-and-space) + (prime-english-direct-key? . prime-command-conv-commit-and-commit-raw) + (prime-english-next-candidate-key? . prime-command-conv-next) + (prime-prev-candidate-key? . prime-command-conv-prev) + (prime-cancel-key? . prime-command-conv-cancel) + (prime-backspace-key? . prime-command-conv-cancel) + (prime-commit-key? . prime-command-conv-commit) + (prime-cand-select-key? . prime-command-conv-select) + (prime-symbol-key? . prime-command-pass) + (prime-with-control-key? . prime-command-pass) + (prime-any-key? . prime-command-conv-input) + )) + ;;;; ------------------------------------------------------------ (define prime-mode-latin 0) @@ -362,12 +420,15 @@ (list 'display-head '()) (list 'display-tail '()) (list 'fund-line '(() . ())) + (list 'preedit-line '("" "" "")) (list 'state 'prime-state-fund) (list 'nth 0) (list 'candidates ()) (list 'mode prime-mode-latin) (list 'last-word "") ;; PRIMEやPOBoxの用語でいうContext (list 'session "") ; the actual value is -default or -register. + (list 'language "Japanese") ; language of the current session. + (list 'lang-session-list ()) ; session data of each language (list 'modification '("" "" "")) (list 'segment-nth 0) (list 'segment-candidates ()) @@ -384,6 +445,9 @@ (session (prime-engine-session-start))) (prime-context-set-fund-line! context (cons (list) (list))) (prime-context-set-session! context session) + (prime-context-set-lang-session-list! + context + (list (cons (prime-engine-session-language-get session) session))) (prime-context-history-update! context) context))) @@ -407,6 +471,10 @@ (define prime-context-pop (lambda (context) (let ((parent-context (prime-context-parent-context context))) + (mapcar + (lambda (lang-pair) + (prime-engine-session-end (cdr lang-pair))) + (prime-context-lang-session-list context)) (if parent-context (begin (prime-context-set-history! context @@ -484,7 +552,7 @@ ;; The structure of the list is [left, cursor, right]. ex. ["ab", "c", "de"]. (define prime-context-get-preedit-line (lambda (context) - (prime-engine-edit-get-preedition (prime-context-session context)))) + (prime-context-preedit-line context))) (define prime-preedit-reset! (lambda (context) @@ -688,14 +756,14 @@ (prime-engine-send-command (list "session_end" prime-session)))) (define prime-engine-session-language-set - (lambda (prime-session language) - (prime-engine-send-command - (list "session_language_set" prime-session language)))) + (lambda (language) + (car (prime-engine-send-command (list "session_start" language))))) (define prime-engine-session-language-get (lambda (prime-session) - (car (prime-engine-send-command - (list "session_language_get" prime-session))))) - + (nth 1 (prime-util-string-split + (car (prime-engine-send-command + (list "session_get_env" prime-session "language"))) + "\t")))) ;; composing operations (define prime-engine-edit-insert @@ -849,12 +917,10 @@ (define prime-command-language-toggle (lambda (context key key-state) - (let* ((current-language (prime-engine-session-language-get - (prime-context-session context))) - (next-language (if (string=? current-language "English") - "Japanese" "English"))) - (prime-engine-session-language-set (prime-context-session context) - next-language)))) + (let ((next-language (if (string=? (prime-context-language context) + "English") + "Japanese" "English"))) + (prime-mode-language-set context next-language)))) (define prime-command-japanese-mode (lambda (context key key-state) @@ -916,6 +982,16 @@ (lambda (context key key-state) (prime-commit-conversion context))) +(define prime-command-conv-commit-and-commit-raw + (lambda (context key key-state) + (prime-commit-conversion context) + (prime-command-commit-raw context key key-state))) + +(define prime-command-conv-commit-and-space + (lambda (context key key-state) + (prime-commit-conversion context) + (prime-commit-string context " "))) + (define prime-command-conv-select (lambda (context key key-state) (let* ((nth0 (number->candidate-index (numeral-char->number key))) @@ -929,7 +1005,7 @@ (define prime-command-conv-input (lambda (context key key-state) (prime-commit-candidate context (prime-context-nth context)) - (prime-push-key context key key-state) + (prime-command-fund-input context key key-state) )) ;;;; ------------------------------------------------------------ @@ -1065,6 +1141,16 @@ (lambda (context key key-state) (prime-commit-preedition context))) +(define prime-command-preedit-commit-and-commit-raw + (lambda (context key key-state) + (prime-commit-preedition context) + (prime-command-commit-raw context key key-state))) + +(define prime-command-preedit-commit-and-space + (lambda (context key key-state) + (prime-commit-preedition context) + (prime-commit-string context " "))) + (define prime-command-preedit-cursor-left-edge (lambda (context key key-state) (prime-engine-edit-cursor-left-edge (prime-context-session context)))) @@ -1119,15 +1205,21 @@ (define prime-command-fund-space (lambda (context key key-state) - (let ((space (ja-direct " "))) - (prime-commit-without-learning context space) - ))) + (cond + ((string=? (prime-context-language context) "Japanese") + (let ((space (ja-direct " "))) + (prime-commit-without-learning context space))) + (t + (prime-commit-without-learning context " "))))) (define prime-command-fund-altspace (lambda (context key key-state) - (let ((space (if (string=? (ja-direct " ") " ") " " " "))) - (prime-commit-without-learning context space) - ))) + (cond + ((string=? (prime-context-language context) "Japanese") + (let ((space (if (string=? (ja-direct " ") " ") " " " "))) + (prime-commit-without-learning context space))) + (t + (prime-commit-without-learning context " "))))) (define prime-command-fund-commit-ja-direct (lambda (context key key-state) @@ -1150,7 +1242,6 @@ (define prime-command-fund-cancel (lambda (context key key-state) - (prime-engine-session-end (prime-context-session context)) (prime-context-pop context) )) @@ -1163,7 +1254,6 @@ (word-data (list (list "basekey" reading) (list "base" literal)))) (prime-commit-word-data parent-context word-data) - (prime-engine-session-end (prime-context-session context)) (prime-context-pop context))) ))) @@ -1251,8 +1341,9 @@ (define prime-push-key (lambda (context key key-state) - (let* ((state (prime-context-state context)) - (mode (prime-context-mode context)) + (let* ((state (prime-context-state context)) + (language (prime-context-language context)) + (mode (prime-context-mode context)) (keymap)) (cond ((= state 'prime-state-segment) @@ -1262,7 +1353,9 @@ (set! keymap prime-keymap-modify-state)) ((= state 'prime-state-converting) - (set! keymap prime-keymap-conv-state)) + (if (string=? language "Japanese") + (set! keymap prime-keymap-conv-state) + (set! keymap prime-keymap-english-conv-state))) ((= mode prime-mode-latin) (set! keymap prime-keymap-latin-mode)) @@ -1272,10 +1365,14 @@ ((= mode prime-mode-hiragana) (if (prime-preedit-exist? context) - (set! keymap prime-keymap-preedit-state) - (if (prime-context-parent-context context) - (set! keymap prime-keymap-child-fund-state) - (set! keymap prime-keymap-fund-state)))) + (if (string=? language "Japanese") + (set! keymap prime-keymap-preedit-state) + (set! keymap prime-keymap-english-preedit-state)) + (if (string=? language "Japanese") + (if (prime-context-parent-context context) + (set! keymap prime-keymap-child-fund-state) + (set! keymap prime-keymap-fund-state)) + (set! keymap prime-keymap-english-fund-state)))) ((= mode prime-mode-application) (set! keymap prime-keymap-app-mode)) @@ -1363,8 +1460,7 @@ ;; This returns a preediting string. (define prime-preedit-get-string-label (lambda (context) - (apply string-append (prime-engine-edit-get-preedition - (prime-context-session context))))) + (apply string-append (prime-context-preedit-line context)))) ;; This returns #t if the preediting string is not empty. Or #f. (define prime-preedit-exist? @@ -1557,6 +1653,10 @@ (define prime-update (lambda (context) + ;; Store the current preedition into the context + (prime-context-set-preedit-line! context + (prime-engine-edit-get-preedition + (prime-context-session context))) (prime-update-state context) (prime-update-prediction context) @@ -1813,6 +1913,19 @@ (prime-update context) )) +(define prime-mode-language-set + (lambda (context language) + (let* ((lang-session-list (prime-context-lang-session-list context)) + (session (cdr (assoc language lang-session-list)))) + (if (not session) + (begin + (set! session (prime-engine-session-language-set language)) + (prime-context-set-lang-session-list! + context + (cons (cons language session) lang-session-list)))) + (prime-context-set-language! context language) + (prime-context-set-session! context session)))) + (define prime-mode-handler (lambda (context mode) (prime-context-set-mode! context mode) Index: prime/uim/ChangeLog diff -u prime/uim/ChangeLog:1.1.2.16 prime/uim/ChangeLog:1.1.2.17 --- prime/uim/ChangeLog:1.1.2.16 Tue Jan 18 02:04:52 2005 +++ prime/uim/ChangeLog Tue Feb 1 08:38:11 2005 @@ -1,3 +1,8 @@ +2005-02-01 Hiroyuki Komatsu <komat****@taiya*****> + + * prime.scm: + Added English prediction. + 2005-01-18 Hiroyuki Komatsu <komat****@taiya*****> * prime.scm: