Hiroyuki Komatsu
komat****@users*****
2004年 12月 31日 (金) 05:19:04 JST
Index: prime/uim/prime.scm diff -u prime/uim/prime.scm:1.1.2.12 prime/uim/prime.scm:1.1.2.13 --- prime/uim/prime.scm:1.1.2.12 Fri Dec 24 03:27:37 2004 +++ prime/uim/prime.scm Fri Dec 31 05:19:03 2004 @@ -52,9 +52,13 @@ (define prime-always-show-window? #t) (define prime-auto-register-mode? #t) (define prime-pseude-mode-cursor? #f) -(define prime-char-annotation? #t) ;; 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. @@ -100,9 +104,16 @@ (define-key prime-expand-segment-key? '("<Control>o" "<Shift>right")) (define-key prime-shrink-segment-key? '("<Control>i" "<Shift>left")) +(define-key prime-escape-key? '("escape" "<Control>[")) (define-key prime-space-key? '(" ")) (define-key prime-altspace-key? '("<Control> " "<Alt> ")) +(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")))) (define prime-cand-select-key? (lambda (key key-state) @@ -157,21 +168,27 @@ (define prime-keymap-latin-mode '( - (prime-on-key? . prime-command-japanese-mode) - (prime-any-key? . prime-command-latin-input) + (prime-on-key? . prime-command-japanese-mode) + (prime-app-mode-start-key? . prime-command-app-mode-start) + (prime-any-key? . prime-command-latin-input) )) (define prime-keymap-wide-latin-mode '( - (prime-on-key? . prime-command-japanese-mode) - (prime-normal-key? . prime-command-wide-latin-input) - (prime-any-key? . prime-command-commit-raw) + (prime-on-key? . prime-command-japanese-mode) + (prime-app-mode-start-key? . prime-command-app-mode-start) + (prime-normal-key? . prime-command-wide-latin-input) + (prime-any-key? . prime-command-commit-raw) )) +(define prime-keymap-app-mode + '((prime-any-key? . prime-command-app-mode))) + (define prime-keymap-fund-state '( - (prime-wide-latin-key? . prime-command-wide-latin-mode) - (prime-latin-key? . prime-command-latin-mode) + (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) ;; Typing mode key bindings (prime-typing-mode-hiragana-key? . prime-command-mode-hiragana) (prime-typing-mode-katakana-key? . prime-command-mode-katakana) @@ -363,9 +380,10 @@ ;;;; ------------------------------------------------------------ -(define prime-mode-latin 0) -(define prime-mode-hiragana 1) -(define prime-mode-wide-latin 2) +(define prime-mode-latin 0) +(define prime-mode-hiragana 1) +(define prime-mode-wide-latin 2) +(define prime-mode-application 3) (define prime-context-rec-spec (append @@ -384,13 +402,15 @@ (list 'segment-nth 0) (list 'segment-candidates ()) (list 'register-line '(() . ())) - (list 'history ())))) + (list 'history ()) + (list 'previous-mode prime-mode-latin) + (list 'app-mode-key-list ()) + ))) (define-record 'prime-context prime-context-rec-spec) (define prime-context-new-internal prime-context-new) (define prime-context-new (lambda (id im) - (print "prime-context-new") (let ((context (prime-context-new-internal id im)) (session1 (prime-engine-session-start)) (session2 (prime-engine-session-start))) @@ -418,7 +438,6 @@ (define prime-context-history-compare (lambda (context) - (print "prime-context-history-compare") (let* ((prev-data (prime-context-history context)) (state (prime-context-state context)) (selected-index (if (= state 'prime-state-segment) @@ -474,7 +493,6 @@ (define prime-preedit-reset! (lambda (context) - (print "prime-preedit-reset!") (prime-context-set-state! context 'prime-state-no-preedit) (prime-context-reset-preedit-line! context) @@ -483,7 +501,6 @@ (define prime-get-nth-candidate (lambda (context n) - (print "prime-get-nth-candidate") (if (>= n (prime-get-nr-candidates context)) #f (car (nth n (prime-context-candidates context)))))) @@ -494,7 +511,6 @@ (define prime-get-current-candidate (lambda (context) - (print "prime-get-current-candidate") (prime-get-nth-candidate context (prime-context-nth context)))) ;;;; ------------------------------------------------------------ @@ -551,7 +567,12 @@ (string-to-list string)) integer))) -;;;; ------------------------------------------------------------ +;; This returns #t, if the argument command like "<Control>j" reflects +;; a pair of key and key-state. The type of both key and key-stae is integer. +(define prime-util-command-match? + (lambda (command key key-state) + ((make-key-predicate (modify-key-strs-implicitly command)) key key-state))) + ;;;; prime-uim: ;;;; ------------------------------------------------------------ @@ -584,17 +605,14 @@ (define prime-engine-conv-predict (lambda (prime-session) - (print "prime-engine-conv-predict") (cdr (prime-engine-conv-convert-internal prime-session "conv_predict")))) (define prime-engine-conv-convert (lambda (prime-session) - (print "prime-engine-conv-convert") (cdr (prime-engine-conv-convert-internal prime-session "conv_convert")))) (define prime-engine-conv-convert-internal (lambda (prime-session command) - (print "prime-engine-conv-convert-internal") (let* ((result (prime-engine-send-command (list command prime-session))) (index (prime-util-string-to-integer (car result))) @@ -609,7 +627,6 @@ (define prime-engine-conv-select (lambda (prime-session index-no) - (print "prime-engine-conv-select") (prime-engine-send-command (list "conv_select" prime-session (digit->string index-no))))) @@ -731,7 +748,6 @@ (define prime-engine-preedit-convert-input (lambda (string) - (print "prime-engine-preedit-convert-input") (if (string=? string "") '("") (let ((conversion (car (prime-engine-send-command @@ -756,7 +772,6 @@ (define prime-engine-get-env (lambda (env-name) -; (print "prime-engine-get-env") (let* ((result (prime-util-string-split (car (prime-engine-send-command (list "get_env" env-name))) "\t")) @@ -776,7 +791,6 @@ (define prime-engine-get-env-typing-method (lambda () -; (print "prime-engine-get-env-typing-method") (prime-engine-get-env "typing_method") )) @@ -796,7 +810,6 @@ ;; This changes the typing mode specified by mode-string. (define prime-mode-set-mode (lambda (context mode-string) - (print "prime-mode-set-mode") (if (= (prime-context-state context) 'prime-state-converting) (prime-convert-cancel context)) (prime-engine-edit-set-mode (prime-context-session context) mode-string))) @@ -894,21 +907,18 @@ (define prime-command-conv-commit (lambda (context key key-state) - (print "prime-command-conv-commit") (prime-commit-conversion context) ; (prime-commit-candidate context (prime-context-nth context)) )) (define prime-command-register-conv-commit (lambda (context key key-state) - (print "prime-command-register-conv-commit") (prime-commit-to-register-buffer context (prime-get-current-candidate context)) )) (define prime-command-conv-select (lambda (context key key-state) - (print "prime-command-conv-select") (let* ((nth0 (number->candidate-index (numeral-char->number key))) (cand-range (prime-uim-candwin-get-range context)) (nth (min (+ (car cand-range) nth0) (cdr cand-range))) @@ -919,7 +929,6 @@ (define prime-command-register-conv-select (lambda (context key key-state) - (print "prime-command-conv-select") (let* ((nth0 (number->candidate-index (numeral-char->number key))) (cand-range (prime-uim-candwin-get-range context)) (nth (min (+ (car cand-range) nth0) (cdr cand-range))) @@ -932,14 +941,12 @@ (define prime-command-conv-input (lambda (context key key-state) - (print "prime-command-conv-input") (prime-commit-candidate context (prime-context-nth context)) (prime-push-key context key key-state) )) (define prime-command-register-conv-input (lambda (context key key-state) - (print "prime-command-register-conv-input") (prime-commit-to-register-buffer context (prime-get-current-candidate context)) (prime-push-key context key key-state) @@ -951,12 +958,10 @@ (define prime-command-modify-commit (lambda (context key key-state) - (print "prime-command-modify-commit") (prime-commit-conversion context))) (define prime-command-modify-convert (lambda (context key key-state) - (print "prime-command-modify-convert") (prime-context-set-state! context 'prime-state-segment) (let ((conversion (prime-engine-segment-reconvert (prime-context-session context)))) @@ -965,13 +970,11 @@ (define prime-command-modify-convert-reversely (lambda (context key key-state) - (print "prime-command-modify-convert-reversely") (prime-command-modify-convert context key key-state) (prime-command-segment-prev context key key-state))) (define prime-command-modify-cursor-right (lambda (context key key-state) - (print "prime-command-modify-cursor-right") (prime-modify-reset! context) (prime-context-set-modification! context @@ -1047,7 +1050,6 @@ (define prime-segment-selection-move (lambda (context selection-index) - (print "prime-segment-selection-move") (if (or (< selection-index 0) (>= selection-index (prime-segment-get-candidates-length context))) (set! selection-index 0)) @@ -1111,13 +1113,11 @@ (define prime-command-preedit-input (lambda (context key key-state) - (print "prime-command-preedit-input") (prime-engine-edit-insert (prime-context-session context) (charcode->string key)))) (define prime-command-preedit-commit-candidate (lambda (context key key-state) - (print "prime-command-preedit-commit-candidate") (if prime-always-number-selection? (let* ((nth (number->candidate-index (numeral-char->number key))) (cand (prime-get-nth-candidate context nth))) @@ -1130,7 +1130,6 @@ (define prime-command-register-preedit-commit-candidate (lambda (context key key-state) - (print "prime-command-register-preedit-commit-candidate") (if prime-always-number-selection? (let* ((nth (number->candidate-index (numeral-char->number key))) (cand (prime-get-nth-candidate context nth))) @@ -1145,7 +1144,6 @@ (define prime-command-preedit-convert (lambda (context key key-state) - (print "prime-command-preedit-convert") (prime-convert-start context) )) @@ -1159,7 +1157,6 @@ ;;;; ------------------------------------------------------------ (define prime-command-fund-input (lambda (context key key-state) - (print "prime-command-fund-input") (prime-context-set-state! context 'prime-state-preedit) (prime-command-preedit-input context key key-state) )) @@ -1209,7 +1206,6 @@ ;; FIXME: (2004-12-22) <Hiro> (define prime-command-register-fund-commit (lambda (context key key-state) - (print "prime-command-register-fund-commit") (let* ((learning-word (prime-context-learning-word context)) (registered (prime-register-get-string-label context))) (if (not (string=? registered "")) @@ -1238,13 +1234,62 @@ (lambda (context key key-state) (prime-editor-cursor-move (prime-context-get-register-line context) 1))) +;; ------------------------------------------------------------ +;; prime-command-app: commands for specific applications +;; ------------------------------------------------------------ + +(define prime-command-app-mode-start + (lambda (context key key-state) + (prime-context-set-previous-mode! context (prime-context-mode context)) + (prime-context-set-app-mode-key-list! context + prime-app-mode-end-stroke-list) + (prime-mode-set context prime-mode-application))) + +(define prime-command-app-mode-end + (lambda (context key key-state) + (prime-mode-set context (prime-context-previous-mode context)) + (prime-context-set-previous-mode! context prime-mode-latin))) + +(define prime-command-app-mode + (lambda (context key key-state) + (prime-command-app-mode-internal + context key key-state + (prime-context-app-mode-key-list context)))) + +(define prime-command-app-mode-internal + (lambda (context key key-state key-list) + (let ((key-data (car key-list))) + (cond + ;; there's no speficied command then pressed key is passed. + ((= key-list '()) + (prime-context-set-app-mode-key-list! context + prime-app-mode-end-stroke-list) + (prime-commit-raw context)) + + ;; key-data is a string like "i" then this app-mode ends. + ((and (string? key-data) + (prime-util-command-match? key-data key key-state)) + (prime-command-app-mode-end context key key-state) + (prime-commit-raw context)) + + ;; key-data is a stroke of keys like ("c" . ("l" "w" ...)) + ;; then the key-list data goes to a next stage. + ((and (list? key-data) + (prime-util-command-match? (car key-data) key key-state)) + (prime-context-set-app-mode-key-list! context (cdr key-data)) + (prime-commit-raw context)) + + ;; call this command recursively. + (t + (prime-command-app-mode-internal context + key key-state (cdr key-list))))))) + ;;;; ------------------------------------------------------------ ;;;; prime-proc: ;;;; ------------------------------------------------------------ (define prime-proc-call-command (lambda (keymap context key key-state) - (print "prime-proc-call-command") (let ((command (prime-keymap-get-command keymap key key-state))) (if command (begin @@ -1254,7 +1299,6 @@ (define prime-push-key (lambda (context key key-state) - (print "prime-push-key") (let* ((state (prime-context-state context)) (mode (prime-context-mode context)) (learning-word (prime-context-learning-word context)) @@ -1283,11 +1327,13 @@ (if learning-word (set! keymap prime-keymap-register-fund-state) (set! keymap prime-keymap-fund-state)))) + ((= mode prime-mode-application) + (set! keymap prime-keymap-app-mode)) ) - (prime-proc-call-command keymap context key key-state) + (prime-proc-call-command keymap context key key-state) - (prime-update context) - ))) + (prime-update context) + ))) ;;;; ------------------------------------------------------------ ;;;; prime-preedit: @@ -1385,7 +1431,6 @@ (define prime-custom-init (lambda () -; (print "prime-custom-init") (let ((typing-method (prime-engine-get-env-typing-method))) (cond ((string=? typing-method "kana") @@ -1405,7 +1450,6 @@ (define prime-commit-raw (lambda (context) - (print "prime-commit-raw") (im-commit-raw context) (prime-context-set-last-word! context "") (prime-preedit-reset! context) @@ -1419,14 +1463,12 @@ (define prime-commit-string (lambda (context string) - (print "prime-commit-string") (im-commit context string) (prime-preedit-reset! context))) ;; obsolete (define prime-commit-word-data (lambda (context word-data) - (print "prime-commit-word-data") (prime-learn-word context word-data) (prime-commit-string context @@ -1436,27 +1478,23 @@ (define prime-commit-preedition (lambda (context) - (print "prime-commit-preedition") (let ((commited-string (prime-engine-edit-commit (prime-context-session-default context)))) (prime-commit-string context commited-string)))) (define prime-commit-conversion (lambda (context) - (print "prime-commit-conversion") (let ((commited-string (prime-engine-conv-commit (prime-context-session-default context)))) (prime-commit-string context commited-string)))) (define prime-commit-segment (lambda (context) - (print "prime-commit-segment") ; (prime-engine-modify-commit (prime-context-session-default context)) (prime-context-set-state! context 'prime-state-modifying))) (define prime-commit-candidate (lambda (context index-no) - (print "prime-commit-candidate") (prime-engine-conv-select (prime-context-session-default context) index-no) (prime-commit-conversion context))) @@ -1473,7 +1511,6 @@ (define prime-learn-word (lambda (context assoc-list) - (print "prime-learn-word") (let ((key (or (cadr (assoc "basekey" assoc-list)) "")) (value (or (cadr (assoc "base" assoc-list)) "")) (part (or (cadr (assoc "part" assoc-list)) "")) @@ -1503,7 +1540,6 @@ (define prime-convert-start-internal (lambda (context init-idx) - (print "prime-convert-start-internal") (let ((res)) (prime-convert-get-conversion context) (set! res (prime-get-nth-candidate context init-idx)) @@ -1521,7 +1557,6 @@ ;; changed to register-mode. (define prime-convert-selection-move (lambda (context selection-index) - (print "prime-convert-selection-move") (prime-context-set-nth! context selection-index) (if (prime-get-current-candidate context) ;; If the selection-index is a valid number, sends the number @@ -1536,14 +1571,12 @@ ;; This resets the converting mode and goes to the preediting mode. (define prime-convert-cancel (lambda (context) - (print "prime-convert-cancel") (prime-context-set-state! context 'prime-state-preedit) (prime-context-set-nth! context 0))) ;; This executes 'conv_predict' to predict candidate words and stores them. (define prime-convert-get-prediction (lambda (context) - (print "prime-convert-get-prediction") (prime-context-set-candidates! ;; FIXME: candidates -> conversions context (prime-engine-conv-predict (prime-context-session-default context))))) @@ -1551,7 +1584,6 @@ ;; This executes 'conv_convert' to get candidate words and stores them. (define prime-convert-get-conversion (lambda (context) - (print "prime-convert-get-conversion") (prime-context-set-candidates! ;; FIXME: candidates -> conversions context (prime-engine-conv-convert (prime-context-session-default context))))) @@ -1562,7 +1594,6 @@ (define prime-update (lambda (context) - (print "prime-update") (prime-update-state context) (prime-update-prediction context) @@ -1580,12 +1611,10 @@ (define prime-update-history (lambda (context) - (print "prime-update-history") (prime-context-history-update! context))) (define prime-update-prediction (lambda (context) - (print "prime-update-prediction") (let ((diff (prime-context-history-compare context))) (cond ((= diff 'state) @@ -1607,7 +1636,6 @@ (define prime-update-candidate-window (lambda (context) - (print "prime-update-candidate-window") (let ((diff (prime-context-history-compare context))) (cond ((= diff 'state) @@ -1654,7 +1682,6 @@ (define prime-update-preedit (lambda (context) - (print "prime-update-preedit") (if (prime-context-history-compare context) (let ((learning-word (prime-context-learning-word context))) @@ -1670,7 +1697,6 @@ (define prime-register-state-update-preedit (lambda (context) - (print "prime-register-state-update-preedit") (let* ((learning-word (prime-context-learning-word context)) (line (prime-context-get-register-line context)) (register-left (prime-editor-get-left line)) @@ -1687,7 +1713,6 @@ (define prime-preedit-state-update-preedit (lambda (context) - (print "prime-preedit-state-update-preedit") (let* ((state (prime-context-state context))) (cond ((= state 'prime-state-converting) @@ -1757,7 +1782,6 @@ (define prime-register-mode-on (lambda (context) - (print "prime-register-mode-on") (prime-context-set-learning-word! context (prime-preedit-get-string-label context)) (prime-context-set-session! context @@ -1774,7 +1798,6 @@ (define prime-init-handler (lambda (id im arg) - (print "prime-init-handler") (let ((context (prime-context-new id im))) (set! candidate-window-position "left") (im-clear-mode-list context) @@ -1810,7 +1833,6 @@ (define prime-reset-handler (lambda (context) - (print "prime-reset-handler") )) (define prime-mode-set @@ -1825,7 +1847,6 @@ (define prime-mode-handler (lambda (context mode) - (print "prime-mode-handler") (prime-context-set-mode! context mode) (prime-preedit-reset! context) (prime-update context) @@ -1833,7 +1854,6 @@ (define prime-get-candidate-handler (lambda (context index-no accel-enum-hint) - (print "prime-get-candidate-handler") (let ((candidate (if (= (prime-context-state context) 'prime-state-segment) (nth index-no (prime-context-segment-candidates context)) @@ -1844,20 +1864,26 @@ (define prime-candidate-combine-string (lambda (context candidate) - (print "prime-candidate-combine-string") (let ((string (prime-candidate-get-literal candidate)) (usage (prime-candidate-get-data candidate "usage")) - (annotation (prime-candidate-get-data candidate "annotation"))) - (if (and prime-char-annotation? - annotation - (or (= (prime-context-state context) 'prime-state-converting) - (= (prime-context-state context) 'prime-state-segment))) - (set! string (string-append string " (" annotation ")"))) + (comment (prime-candidate-get-data candidate "comment")) + (form (prime-candidate-get-data candidate "form")) + (state (prime-context-state context))) + (if (and prime-custom-display-form? + form + (or (= state 'prime-state-converting) + (= state 'prime-state-segment))) + (set! string (string-append string " (" form ")"))) (if (and prime-custom-display-usage? usage - (or (= (prime-context-state context) 'prime-state-converting) - (= (prime-context-state context) 'prime-state-segment))) + (or (= state 'prime-state-converting) + (= state 'prime-state-segment))) (set! string (string-append string "\t▽" usage))) + (if (and prime-custom-display-comment? + comment + (or (= state 'prime-state-converting) + (= state 'prime-state-segment))) + (set! string (string-append string "\t<" comment ">"))) string))) (define prime-candidate-get-literal @@ -1870,7 +1896,6 @@ (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)) @@ -1879,7 +1904,6 @@ (define prime-prop-handler (lambda (context message) - (print "prime-prop-handler") (let (mode) (mapcar (lambda (data) @@ -1905,7 +1929,9 @@ (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-wide-latin "P" "全角英数" "全角を入力" "prop_prime_mode_wide_latin") + (list prime-mode-application "P!" "特殊" "アプリケーション依存" "prop_prime_mode_application") + )) (define prime-mode-get-label (lambda (mode) Index: prime/uim/ChangeLog diff -u prime/uim/ChangeLog:1.1.2.12 prime/uim/ChangeLog:1.1.2.13 --- prime/uim/ChangeLog:1.1.2.12 Fri Dec 24 03:27:37 2004 +++ prime/uim/ChangeLog Fri Dec 31 05:19:03 2004 @@ -1,3 +1,10 @@ +2004-12-31 Hiroyuki Komatsu <komat****@taiya*****> + + * prime.scm: + - Added an application spesific mode. It's just for vi. + - Added an annotation 'comment'. Almost all comments originate from + a SKK dictionary. + 2004-12-23 Hiroyuki Komatsu <komat****@taiya*****> * prime.scm: