[prime-dev: 420] Re: uim-prime の backspace

Back to archive index

Masaki Yatsu yatsu****@yatsu*****
2004年 8月 6日 (金) 18:17:33 JST


谷津です。

なんか、やるべきじゃないことをやってる気はしますが……。

本来であれば、
* uim-primeにsuikyoをもたせる
or
* primeコマンドに文字削除機能をもたせる
のが正しいのでしょうか?

とりあえず、前回のは「っ」が正しく処理されないので、改良しました。
今回は入力時点で「ん」と「っ」のキー入力を変更してしまっています。

(define prime-command-preedit-input
  (lambda (context key key-state)
    (let* ((sc (context-data context))
           (id (context-id context))
           (keystr (charcode->string key))
           (last-left-string (prime-context-left-string sc))
           (char-list))
      (prime-context-set-left-string!
       sc (cons keystr last-left-string))
      (set! char-list (string-to-list (prime-preedit-get-string-label sc)))
      (if (and (equal? (car char-list) keystr)
               (>= (length char-list) 2))
          (cond
           ((and (equal? (cadr char-list) "ん")
                 (not (equal? keystr "n")))
            (prime-context-set-left-string!
             sc (cons keystr (cons "n" (cons "n" (cdr last-left-string))))))
           ((and (equal? (cadr char-list) "っ")
                 (not (equal? (car last-left-string) "u")))
            (prime-context-set-left-string!
             sc (cons keystr
                      (cons "u" (cons "t" (cons "x"
                                              (cdr last-left-string)))))))))
      (prime-context-set-candidate-window! sc #f) ;FIXME:very dirty hack
      (if (and
           prime-preedit-immediate-commit?
           (prime-context-immediate-commit sc))
          (begin
            (im-commit id (string-list-concat
                           (prime-context-left-string sc)))
            (prime-flush sc))))))

(define prime-command-preedit-backspace
  (lambda (context key key-state)
    (let* ((sc (context-data context))
           (preedit-char-list (string-to-list
                               (prime-preedit-get-string-label sc))))
      (letrec ((delete-backward
                (lambda (char-list goal-char-list)
                  (cond
                   ((= (length goal-char-list) 0)
                      (prime-context-set-left-string! sc '()))
                   ((= (length char-list) (length goal-char-list))
                    (if (equal? (car char-list) (car goal-char-list)) ()
                        (delete-backward char-list (cdr goal-char-list))))
                   (else
                    (begin
                      (prime-context-set-left-string!
                       sc (cdr (prime-context-left-string sc)))
                      (delete-backward
                       (string-to-list (prime-preedit-get-string-label sc))
                       goal-char-list)))))))
        (delete-backward preedit-char-list (cdr preedit-char-list)))
      (prime-context-set-candidate-window! sc #f) ;FIXME:very dirty hack
      )))

---
谷津真樹 (Masaki Yatsu)
mailto:yatsu****@yatsu*****





Prime-dev メーリングリストの案内
Back to archive index