Hiroyuki Komatsu
komat****@users*****
2005年 3月 2日 (水) 04:59:34 JST
Index: prime/uim/ChangeLog diff -u prime/uim/ChangeLog:1.1.2.17 prime/uim/ChangeLog:1.1.2.18 --- prime/uim/ChangeLog:1.1.2.17 Tue Feb 1 08:38:11 2005 +++ prime/uim/ChangeLog Wed Mar 2 04:59:34 2005 @@ -1,3 +1,8 @@ +2005-03-02 Hiroyuki Komatsu <komat****@taiya*****> + + * prime.scm: + Modified a lot for uim-0.4.6. + 2005-02-01 Hiroyuki Komatsu <komat****@taiya*****> * prime.scm: Index: prime/uim/prime.scm diff -u prime/uim/prime.scm:1.1.2.20 prime/uim/prime.scm:1.1.2.21 --- prime/uim/prime.scm:1.1.2.20 Tue Feb 1 08:42:40 2005 +++ prime/uim/prime.scm Wed Mar 2 04:59:34 2005 @@ -28,9 +28,6 @@ ;;; SUCH DAMAGE. ;;;; -;;TODO -;; ::単語登録 -;; ;;モード一覧 ;; 日本語入力モード(カタカナ日本語入力モードも必要?) ;; 英数モード @@ -43,28 +40,23 @@ ;; 読み入力状態,単語入力状態 ;; -(require "japanese.scm") -(require "generic-key.scm") (require "util.scm") +(require "japanese.scm") +(require-custom "generic-key-custom.scm") +(require-custom "prime-custom.scm") +(require-custom "prime-key-custom.scm") ;; configs -(define prime-nr-candidate-max 10) -(define prime-always-show-window? #t) -(define prime-auto-register-mode? #t) -(define prime-pseude-mode-cursor? #f) -;; If #t a candidate window displays usage examples of candidate words. -(define prime-custom-display-usage? #t) ;; If #t a candidate window displays comments of candidate words. (define prime-custom-display-comment? #t) ;; If #t a candidate window displays forms of candidate words such as ;; 'l (small L)', 'I (large i)'. (define prime-custom-display-form? #t) -(define prime-mask-pending-preedit? #f) -;; If #t, users can select candidates with pressing a number key. (define prime-always-number-selection? #f) ;; config function +;; should be replaced with boolean custom variable -- YamaKen 2005-01-15 (define prime-dont-use-numeral-key-to-select-cand (lambda () (set! prime-cand-select-key? @@ -73,28 +65,6 @@ (control-key-mask key-state)))))) ;; key -(define-key prime-latin-key? '("<Control>l" generic-off-key?)) -(define-key prime-wide-latin-key? "<Control>L") -(define-key prime-begin-conv-key? 'generic-begin-conv-key?) -(define-key prime-on-key? '("<Control>j" "<Control>J" generic-on-key?)) -(define-key prime-commit-key? 'generic-commit-key?) -(define-key prime-next-candidate-key? 'generic-next-candidate-key?) -(define-key prime-prev-candidate-key? 'generic-prev-candidate-key?) -(define-key prime-next-page-key? 'generic-next-page-key?) -(define-key prime-prev-page-key? 'generic-prev-page-key?) -(define-key prime-cancel-key? 'generic-cancel-key?) -(define-key prime-backspace-key? 'generic-backspace-key?) -(define-key prime-delete-key? 'generic-delete-key?) -(define-key prime-go-left-key? 'generic-go-left-key?) -(define-key prime-go-right-key? 'generic-go-right-key?) -(define-key prime-go-left-edge-key? '("<Control>a" "<Control>left")) -(define-key prime-go-right-edge-key? '("<Control>e" "<Control>right")) -(define-key prime-register-key? '("<Control>w")) -(define-key prime-typing-mode-hiragana-key? "F6") -(define-key prime-typing-mode-katakana-key? "F7") -(define-key prime-typing-mode-hankana-key? "F8") -(define-key prime-typing-mode-wideascii-key? "F9") -(define-key prime-typing-mode-ascii-key? "F10") (define-key prime-language-toggle-key? "F11") (define-key prime-expand-segment-key? '("<Control>o" "<Shift>right")) (define-key prime-shrink-segment-key? '("<Control>i" "<Shift>left")) @@ -108,12 +78,14 @@ (define-key prime-english-direct-key? '("." "," ":" ";" "(" ")" "\"" "'" "!" "?")) +;;;; If you're a Vi user, modify the lines below. +;; Default (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. -; (define-key prime-app-mode-start-key? prime-escape-key?) -; (define prime-app-mode-end-stroke-list -; '("i" "I" "a" "A" "o" "O" "C" "s" "S" ("c" . ("l" "w" "e" "c" "G")))) +;; For Vi users +;(define-key prime-app-mode-start-key? prime-escape-key?) +;(define prime-app-mode-end-stroke-list +; '("i" "I" "a" "A" "o" "O" "C" "s" "S" ("c" . ("l" "w" "e" "c" "G")))) (define prime-cand-select-key? (lambda (key key-state) @@ -155,6 +127,50 @@ ;;;; prime-keymap: Keymaps binding a key stroke to a command. ;;;; ------------------------------------------------------------ +(define prime-keymap-get-keymap + (lambda (context key key-state) + (let ((mode (prime-context-mode context)) + (keymap)) + (cond + ((= mode prime-mode-latin) + (set! keymap prime-keymap-latin-mode)) + ((= mode prime-mode-hiragana) + (set! keymap (prime-keymap-get-keymap-hiragana context key key-state))) + ((= mode prime-mode-wide-latin) + (set! keymap prime-keymap-wide-latin-mode)) + ((= mode prime-mode-application) + (set! keymap prime-keymap-app-mode))) + keymap))) + +(define prime-keymap-get-keymap-hiragana + (lambda (context key key-state) + (let ((state (prime-context-state context)) + (language (prime-context-language context)) + (keymap)) + (cond + ((= state 'prime-state-segment) + (set! keymap prime-keymap-segment-state)) + + ((= state 'prime-state-modifying) + (set! keymap prime-keymap-modify-state)) + + ((= state 'prime-state-converting) + (if (string=? language "Japanese") + (set! keymap prime-keymap-conv-state) + (set! keymap prime-keymap-english-conv-state))) + + ((= state 'prime-state-preedit) + (if (string=? language "Japanese") + (set! keymap prime-keymap-preedit-state) + (set! keymap prime-keymap-english-preedit-state))) + + ((= state 'prime-state-fund) + (if (string=? language "Japanese") + (if (prime-context-parent-context context) + (set! keymap prime-keymap-child-fund-state) + (set! keymap prime-keymap-fund-state))))) + keymap))) + (define prime-keymap-get-command (lambda (keymap key key-state) (let ((command-key? (car (car keymap))) @@ -170,7 +186,7 @@ '( (prime-on-key? . prime-command-japanese-mode) (prime-app-mode-start-key? . prime-command-app-mode-start) - (prime-any-key? . prime-command-latin-input) + (prime-any-key? . prime-command-commit-raw) )) (define prime-subkeymap-child-context @@ -406,11 +422,72 @@ ;;;; ------------------------------------------------------------ +;;; Implementations + (define prime-mode-latin 0) (define prime-mode-hiragana 1) (define prime-mode-wide-latin 2) (define prime-mode-application 3) +(register-action 'action_prime_mode_latin + (lambda (context) + '(figure_prime_mode_latin + "p[--]" + "通常入力" + "PRIMEをオフ")) + (lambda (context) + (= (prime-context-mode context) + prime-mode-latin)) + (lambda (context) + (prime-mode-set context prime-mode-latin))) + +(register-action 'action_prime_mode_hiragana + (lambda (context) + '(figure_prime_mode_hiragana + "P[あ]" + "日本語" + "PRIMEをオン")) + (lambda (context) + (= (prime-context-mode context) + prime-mode-hiragana)) + (lambda (context) + (prime-mode-set context prime-mode-hiragana))) + +(register-action 'action_prime_mode_wide_latin + (lambda (context) + '(figure_prime_mode_wide_latin + "P[A]" + "全角英数" + "全角を入力")) + (lambda (context) + (= (prime-context-mode context) + prime-mode-wide-latin)) + (lambda (context) + (prime-mode-set context prime-mode-wide-latin))) + +(register-action 'action_prime_mode_application + (lambda (context) + '(figure_prime_mode_application + "P[!]" + "特殊" + "アプリケーション依存")) + (lambda (context) + (= (prime-context-mode context) + prime-mode-application)) + (lambda (context) + (prime-mode-set context prime-mode-application))) + +;; Update widget definitions based on action configurations. The +;; procedure is needed for on-the-fly reconfiguration involving the +;; custom API +(define prime-configure-widgets + (lambda () + (register-widget 'widget_prime_input_mode + (activity-indicator-new prime-input-mode-actions) + (actions-new prime-input-mode-actions)) + (context-list-replace-widgets! 'prime prime-widgets))) + + (define prime-context-rec-spec (append context-rec-spec @@ -426,7 +503,7 @@ (list 'candidates ()) (list 'mode prime-mode-latin) (list 'last-word "") ;; PRIMEやPOBoxの用語でいうContext - (list 'session "") ; the actual value is -default or -register. + (list 'session #f) ; 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 '("" "" "")) @@ -441,23 +518,43 @@ (define prime-context-new (lambda (id im) - (let ((context (prime-context-new-internal id im)) - (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) + (let ((context (prime-context-new-internal id im))) + (prime-context-set-widgets! context prime-widgets) + context))) + +(define prime-context-new2 + (lambda (id im) + (let ((context (prime-context-new-internal id im))) + (prime-context-initialize! context) context))) +;; This initializes an empty context, and also initializes the prime server. +;; This returns context. +(define prime-context-initialize! + (lambda (context) + (print "prime-context-initialize!") + (if (null? (prime-context-session context)) + (begin + ;; The prime server is initialized here. + (prime-lib-init prime-use-unixdomain?) + (let ((session (prime-engine-session-start))) + (prime-custom-init) + (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)) + ;; This function pushs the current context-data to the stack of ;; uim-contexts and create a new context-data. (define prime-context-push (lambda (context) + (print "prime-context-push") (let* ((im (prime-context-im context)) (id (prime-context-id context)) - (new-context (prime-context-new (prime-context-id context) im))) + (new-context (prime-context-new2 (prime-context-id context) im))) (prime-context-set-history! new-context (prime-context-history context)) (set-cdr! (assoc 'state (prime-context-history new-context)) @@ -556,7 +653,6 @@ (define prime-preedit-reset! (lambda (context) - (prime-context-set-state! context 'prime-state-fund) (prime-context-reset-preedit-line! context) (prime-context-set-nth! context 0) @@ -660,12 +756,15 @@ (loop (prime-lib-send-command "")) buffer))))) +;; Don't append "\n" to arg-list in this function. That will cause a +;; problem with unix domain socket. (define prime-engine-send-command (lambda (arg-list) - (cdr (string-split - (prime-send-command - (string-append (prime-util-string-concat arg-list "\t") "\n")) - "\n")))) + (cdr + (string-split + (prime-send-command + (prime-util-string-concat arg-list "\t")) + "\n")))) (define prime-engine-conv-predict (lambda (prime-session) @@ -924,6 +1023,7 @@ (define prime-command-japanese-mode (lambda (context key key-state) + (prime-context-initialize! context) (prime-mode-set context prime-mode-hiragana))) (define prime-command-wide-latin-mode @@ -937,17 +1037,11 @@ (define prime-command-register-mode (lambda (context key key-state) + (print "prime-command-register-mode") (prime-register-mode-on context))) ;;;; ------------------------------------------------------------ -;;;; prime-command-latin: User commands in a latin-mode -;;;; ------------------------------------------------------------ -(define prime-command-latin-input - (lambda (context key key-state) - (prime-command-commit-raw context key key-state))) - -;;;; ------------------------------------------------------------ ;;;; prime-command-wide-latin: User commands in a wide-latin-mode ;;;; ------------------------------------------------------------ (define prime-command-wide-latin-input @@ -1281,6 +1375,7 @@ (define prime-command-app-mode-start (lambda (context key key-state) + (print "prime-command-app-mode-start") (prime-context-set-previous-mode! context (prime-context-mode context)) (prime-context-set-app-mode-key-list! context prime-app-mode-end-stroke-list) @@ -1327,7 +1422,7 @@ key key-state (cdr key-list))))))) ;;;; ------------------------------------------------------------ -;;;; prime-proc: +;;;; prime-proc: procedure ;;;; ------------------------------------------------------------ (define prime-proc-call-command @@ -1339,49 +1434,6 @@ #t) #f)))) -(define prime-push-key - (lambda (context key key-state) - (let* ((state (prime-context-state context)) - (language (prime-context-language context)) - (mode (prime-context-mode context)) - (keymap)) - (cond - ((= state 'prime-state-segment) - (set! keymap prime-keymap-segment-state)) - - ((= state 'prime-state-modifying) - (set! keymap prime-keymap-modify-state)) - - ((= state 'prime-state-converting) - (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)) - - ((= mode prime-mode-wide-latin) - (set! keymap prime-keymap-wide-latin-mode)) - - ((= mode prime-mode-hiragana) - (if (prime-preedit-exist? context) - (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)) - ) - (prime-proc-call-command keymap context key key-state) - - (prime-update context) - ))) - ;;;; ------------------------------------------------------------ ;;;; prime-preedit: ;;;; ------------------------------------------------------------ @@ -1501,13 +1553,16 @@ (define prime-commit-raw (lambda (context) - ;; Reset the current prime-context - (prime-engine-context-reset (prime-context-session context)) + (if (= (prime-context-mode context) prime-mode-latin) + (im-commit-raw context) + (begin + ;; Reset the current prime-context + (prime-engine-context-reset (prime-context-session context)) - (im-commit-raw context) - (prime-context-set-last-word! context "") - (prime-preedit-reset! context) - )) + (im-commit-raw context) + (prime-context-set-last-word! context "") + (prime-preedit-reset! context) + )))) (define prime-commit-without-learning (lambda (context string) @@ -1653,19 +1708,38 @@ (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-key-press context) + (prime-update-key-release context))) - (prime-update-state context) - (prime-update-prediction context) - - (prime-update-candidate-window context) - (prime-update-preedit context) +(define prime-update-key-press + (lambda (context) + (let ((session (prime-context-session context))) + (cond + ((null? session) + #f) ;; Do nothing. - (prime-update-history context) - )) + (#t + ;; Store the current preedition into the context + (prime-context-set-preedit-line! + context + (prime-engine-edit-get-preedition session)) + + (prime-update-state context) + (prime-update-preedit context) + ))))) + +(define prime-update-key-release + (lambda (context) + (let ((session (prime-context-session context))) + (cond + ((null? session) + #f) ;; Do nothing. + + (#t + (prime-update-prediction context) + (prime-update-candidate-window context) + (prime-update-history context) + ))))) (define prime-update-state (lambda (context) @@ -1795,7 +1869,7 @@ (define prime-display-preedit-format (list (cons 'committed preedit-none) (cons 'cursor preedit-cursor) - (cons 'pseude-cursor preedit-reverse) + (cons 'pseudo-cursor preedit-reverse) (cons 'preedit preedit-underline) (cons 'converting preedit-underline) (cons 'segment preedit-underline) @@ -1823,11 +1897,11 @@ (lambda (context) (im-pushback-preedit context (cdr (assoc 'cursor prime-display-preedit-format)) "") - (if (and prime-pseude-mode-cursor? + (if (and prime-pseudo-mode-cursor? (= (prime-context-mode context) prime-mode-hiragana) (eq? (prime-context-state context) 'prime-state-fund)) (im-pushback-preedit context - (cdr (assoc 'pseude-cursor + (cdr (assoc 'pseudo-cursor prime-display-preedit-format)) " ")) )) @@ -1836,6 +1910,7 @@ (define prime-register-mode-on (lambda (context) + (print "prime-register-mode-on") (let* ((reading (prime-preedit-get-string-label context)) ;; Header and footer strings for a preedition line. (current-display-head (prime-context-display-head context)) @@ -1845,7 +1920,6 @@ (current-line-left (prime-editor-get-left-string current-line)) (current-line-right (prime-editor-get-right-string current-line)) (new-context (prime-context-push context))) - (prime-context-set-display-head! new-context (append current-display-head @@ -1865,52 +1939,59 @@ (prime-mode-set context prime-mode-hiragana) ))) +;; This just returns the empty context between this client and a prime +;; server. However the prime server may not be initialized yet. The +;; server will be initialized in prime-context-initialize! after a +;; user turn on the prime mode. (define prime-init-handler (lambda (id im arg) - (let ((context (prime-context-new id im))) - (set! candidate-window-position "left") - (im-clear-mode-list context) - (mapcar - (lambda (data) - (im-pushback-mode-list context (nth 2 data))) ; = mode name - prime-mode) - (im-update-mode-list context) - (im-update-mode context prime-mode-latin) - - (prime-update-prop-list context) - (prime-custom-init) - context))) + (prime-context-new id im))) (define prime-release-handler (lambda (context) - (prime-engine-session-end (prime-context-session context)) + (print "prime-release-handler") + (let ((session (prime-context-session context))) + (if session + (prime-engine-session-end session))) )) (define prime-press-key-handler - (lambda (context key state) + (lambda (context key key-state) (if (control-char? key) (im-commit-raw context) - (prime-push-key context key state)))) + (let ((keymap (prime-keymap-get-keymap context key key-state))) + (prime-proc-call-command keymap context key key-state) + (prime-update-key-press context) + )))) (define prime-release-key-handler - (lambda (context key state) + (lambda (context key key-state) + (print "prime-release-key-handler") (if (or (control-char? key) (= (prime-context-mode context) prime-mode-latin)) - (im-commit-raw context)))) + (im-commit-raw context) + ;; else + ;; FIXME: update candidate words. + (prime-update-key-release context) + ))) (define prime-reset-handler (lambda (context) + (print "prime-reset-handler") )) (define prime-mode-set (lambda (context mode) (prime-context-set-mode! context mode) - (im-update-mode context mode) - (prime-update-prop-label context) - (prime-update-prop-list context) - (prime-preedit-reset! context) - (prime-update context) + ;; FIXME: I don't wanna use prime-context-session here. + ;; FIXME: (2005-02-25) <Hiroyuki Komatsu> + ;; If the session is #f, the PRIME mode has never been turned on. + (if (prime-context-session context) + (begin + (prime-preedit-reset! context) + (prime-update context) + )) )) (define prime-mode-language-set @@ -1926,13 +2007,6 @@ (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) - (prime-preedit-reset! context) - (prime-update context) - ())) - (define prime-get-candidate-handler (lambda (context index-no accel-enum-hint) (let ((candidate @@ -1977,73 +2051,29 @@ (define prime-set-candidate-index-handler (lambda (context selection-index) + (print "prime-set-candidate-index-handler") (if (= (prime-context-state context) 'prime-state-segment) (prime-segment-selection-move context selection-index) (prime-convert-selection-move context)) (prime-update context) )) -(define prime-prop-handler - (lambda (context message) - (let (mode) - (mapcar - (lambda (data) - (if (string=? message (nth 4 data)) ; = message - (set! mode (nth 0 data)))) ; = mode number - prime-mode) - (prime-mode-set context mode)))) - -(define prime-update-prop-label - (lambda (context) - (let* ((mode (prime-context-mode context)) - (str (prime-mode-get-label mode))) - (im-update-prop-label context str)))) - -(define prime-update-prop-list - (lambda (context) - (let* ((mode (prime-context-mode context)) - (str (prime-mode-get-list mode))) - (im-update-prop-list context str) - ))) - -(define prime-mode - (list - (list prime-mode-latin "P" "直接入力" "PRIME オフ" "prop_prime_mode_latin") - (list prime-mode-hiragana "ぷ" "日本語" "PRIME オン" "prop_prime_mode_hiragana") - (list prime-mode-wide-latin "P" "全角英数" "全角を入力" "prop_prime_mode_wide_latin") - (list prime-mode-application "P!" "特殊" "アプリケーション依存" "prop_prime_mode_application") - )) - -(define prime-mode-get-label - (lambda (mode) - (let ((data (assoc mode prime-mode))) - (string-append (nth 1 data) "\t" (nth 2 data) "\n")))) - -(define prime-mode-get-list - (lambda (mode) - (string-append - "branch\t" (prime-mode-get-label mode) - - (prime-util-string-concat - (mapcar (lambda (data) - (prime-util-string-concat (cons "leaf" (cdr data)) "\t")) - prime-mode) - "\n") - - "\n"))) +(prime-configure-widgets) (register-im - 'prime - "ja" - "EUC-JP" - (N_ "Japanese predictable input method") - #f - prime-init-handler - prime-release-handler - prime-mode-handler - prime-press-key-handler - prime-release-key-handler - prime-reset-handler - prime-get-candidate-handler - prime-set-candidate-index-handler - prime-prop-handler) + 'prime ;; name + "ja" ;; lang + "EUC-JP" ;; encoding + prime-im-name-label ;; name-label + prime-im-short-desc ;; short-dest + #f ;; init-arg + prime-init-handler ;; init + prime-release-handler ;; release + context-mode-handler ;; mode + prime-press-key-handler ;; key-press + prime-release-key-handler ;; key-release + prime-reset-handler ;; reset + prime-get-candidate-handler ;; get-candidate + prime-set-candidate-index-handler ;; set-candidate-index + context-prop-activate-handler ;; prop +)