+1998-03-04 NIIBE Yutaka <gniibe@mri.co.jp>
+
+ * its.el (its-define-select-keys of its-mode-map): Comment it out.
+ * its-keydef.el (its-make-select-func): Add eval-when to compile this.
+
+ * egg-cnv.el (egg-decide-bunsetsu): Deleted.
+ * its.el (its-restart): Call its-setup-fence-mode with no argument.
+
+ * its.el (its-keyseq-acceptable-p): Bug fix.
+
+1998-03-03 KATAYAMA Yoshio <kate@pfu.co.jp>
+
+ *its.el (its-get-keyseq-syl): Compensate when DSYL has back.
+ (its-DSYL-with-back-p): New function. Return t when DSYL has back.
+ (its-concrete-DSYL-p): New function. Return t when DSYL is cons
+ form which means input is not continued after DSYL was created.
+ (its-make-concrete-DSYL): New function.
+ (its-self-insert-char): Make DSYL to ``concrete-DSYL'' if cursor
+ is t which means input is not continued.
+ (its-input): Test input key is whether acceptable or not when
+ its-barf-on-invalid-keyseq is non-nil.
+ (its-input-to-vsyl): Set cursor status, not just returning it.
+ (its-state-machine its-state-machine-keyseq): Make sure to issue
+ ``DSYL-with-back'' when syllable is decided by the rule with back.
+ ``test mode'' is added.
+ (its-keyseq-acceptable-p): New function.
+ (its-forward-SYL): The args order of put-text-property was wrong.
+ (its-delete-backward-SYL-by-keystroke): New function.
+ (its-delete-backward-within-SYL): ``delete-by-keystroke'' mode
+ did not work when syllable is decided by the rule with back.
+ Deletion limit is extended to outside of SYL (meaning of
+ ``within-SYL'' is changed to ``deletion starts within SYL).
+ (its-transpose-chars): Fixed up.
+ (its-in-fence-p): Confuse at openning fence.
+
+1998-02-25 KATAYAMA Yoshio <kate@pfu.co.jp>
+
+ * its.el (its-put-cursor): Enable its-map change in fence mode.
+
+ * its-keydef.el (its-make-select-func): Same as above.
+
+1998-02-25 KATAYAMA Yoshio <kate@pfu.co.jp>
+
+ * its.el (its-set-cursor-status): New function.
+ (its-setup-fence-mode): New function.
+ (its-insert-fence-open its-insert-fence-close): Deleted.
+ (its-start, its-restart, its-self-insert-char): Avoid fence
+ destruction on its-barf.
+ (its-input-to-vsyl, its-state-machine, its-state-machine-keyseq,
+ its-buffer-ins/del-SYL, its-ins/del-SYL-batch): Update cursor
+ status on updating syllables.
+ (its-input-error): New function to realize doc-string of
+ its-barf-on-invalid-keyseq.
+
+ * egg.el (egg-mode): Don't use egg-mode-line-title which cause
+ wrong-type-argument at isearch. Bind its-select-XXX to key only
+ when modefull is select.
+
+ * egg-mlh.el (mlh-hangul, mlh-zhongwen, mlh-zhongwen-tw): Same
+ as above.
+
+ * its-keydef.el (its-make-select-func): Same as above.
+
+ * leim-list-egg.el: Same as above.
+
+1998-02-24 KATAYAMA Yoshio <kate@pfu.co.jp>
+
+ * its.el (its-state-machine-keyseq): Remove binding
+ its-barf-on-invalid-keyseq to nil.
+ (its-ins/del-SYL-batch): Avoide altering its-XXX-map.
+ (its-translate-region-internal): its-translation-result's data
+ type is changed to string.
+
+ * egg-cnv.el (egg-convert-region): Gather contiguous same
+ language part.
+
+1998-02-21 KATAYAMA Yoshio <kate@pfu.co.jp>
+
+ * its.el (its-ins/del-SYL-batch): Set its-lang property.
+ (its-translate-region): Remove its-lang property from translated
+ text.
+ (its-translate-region-internal): New function. Retain its-lang
+ property on translated text.
+
+ * egg-mlh.el (mlh-space-bar-backward-henkan): Force base language
+ to Japanese.
+
+ (mlh-hangul mlh-zhongwen-tw mlh-zhongwen): New functions for
+ conversion functions.
+
1998-02-20 KATAYAMA Yoshio <kate@pfu.co.jp>
* its.el (its-restart): New function.
(defvar its-zhuyin nil)
(make-variable-buffer-local 'its-zhuyin)
-(defmacro its-make-slect-func (key name file map &optional lang zhuyin)
+(eval-when (eval compile)
+(defun its-make-select-func (key1 key2 name file map &optional lang zhuyin)
(setq name (intern (concat "its-select-" (symbol-name name)))
file (intern (concat "its/" (symbol-name file)))
map (intern (concat "its-" (symbol-name map) "-map"))
lang (symbol-name lang))
- `(progn
- (defun ,name ()
- (interactive)
- (cond
- ((its-in-fence-p)
- (its-input-end)
- (its-put-cursor t))
- ((egg-get-bunsetsu-info (point))
- (egg-exit-conversion)))
- ,(if lang `(egg-check-language ,lang))
- (require ',file)
- (setq its-current-map ,map)
- ,(if lang `(setq its-current-language ,lang))
- ,(if zhuyin `(setq its-zhuyin ,(eq zhuyin 'T)))
- (egg-set-mode-line-title (its-get-indicator its-current-map)))
- (define-key mule-keymap ,key ',name)))
+ (cons
+ `(defun ,name (&optional mode-line-unchange)
+ (interactive)
+ (cond
+ ((its-in-fence-p)
+ (its-input-end)
+ (its-put-cursor t))
+ ((egg-get-bunsetsu-info (point))
+ (egg-exit-conversion)))
+ ,(if lang `(egg-check-language ,lang))
+ (require ',file)
+ (setq its-current-map ,map)
+ ,(if lang `(setq its-current-language ,lang))
+ ,(if zhuyin `(setq its-zhuyin ,(eq zhuyin 'T)))
+ (if (null mode-line-unchange)
+ (egg-set-mode-line-title)))
+ `(define-key map
+ (if fence
+ ,(concat "\e" (vector key2))
+ ,(concat "\C-x\C-m" (vector key1)))
+ ',name)))
+)
-(defmacro its-do-list-make-slect-func (list)
+(defmacro its-do-list-make-select-func (list)
(eval-when (eval compile)
- (let (e l)
+ (let (funcs keydefs pair)
(while list
- (setq e (car list))
- (setq l (cons `(its-make-slect-func ,@(car list)) l))
+ (setq pair (apply 'its-make-select-func (car list)))
+ (setq funcs (cons (car pair) funcs)
+ keydefs (cons (cdr pair) keydefs))
(setq list (cdr list)))
- (cons 'progn l))))
+ `(progn
+ ,@funcs
+ (defun its-define-select-keys (map &optional fence)
+ ,@keydefs)))))
-(its-do-list-make-slect-func
- (("Q" upcase ascii up)
- ("q" downcase ascii down)
- ("h" hiragana hira hira Japanese)
- ("K" katakana kata kata Japanese)
- ("x" hankaku-katakana hankata han-kata Japanese)
- ("Z" zenkaku-upcase zenkaku zenkaku-up Japanese)
- ("z" zenkaku-downcase zenkaku zenkaku-down Japanese)
- ("\C-e" erpin-cn erpin erpin-cn Chinese-GB NIL)
- ("\C-p" pinyin-cn pinyin pinyin-cn Chinese-GB NIL)
- ("\C-z" zhuyin-cn zhuyin zhuyin-cn Chinese-GB T)
- ("\C-u" quanjiao-upcase-cn quanjiao quanjiao-up-cn Chinese-GB)
- ("\C-d" quanjiao-downcase-cn quanjiao quanjiao-down-cn Chinese-GB)
- ("E" erpin-tw erpin erpin-tw Chinese-CNS NIL)
- ("P" pinyin-tw pinyin pinyin-tw Chinese-CNS NIL)
- ("Z" zhuyin-tw zhuyin zhuyin-tw Chinese-CNS T)
- ("U" quanjiao-upcase-tw quanjiao quanjiao-up-tw Chinese-CNS)
- ("D" quanjiao-downcase-tw quanjiao quanjiao-down-tw Chinese-CNS)
- ("H" hangul hangul hangul Korean)
- ("J" jeonkak-upcase jeonkak jeonkak-up Korean)
- ("j" jeonkak-downcase jeonkak jeonkak-down Korean)))
+(its-do-list-make-select-func
+ ((?Q ?Q upcase ascii up)
+ (?q ?q downcase ascii down)
+ (?h ?\C-h hiragana hira hira Japanese)
+ (?k ?\C-k katakana kata kata Japanese)
+ (?x ?\C-x hankaku-katakana hankata han-kata Japanese)
+ (?Z ?Z zenkaku-upcase zenkaku zenkaku-up Japanese)
+ (?z ?z zenkaku-downcase zenkaku zenkaku-down Japanese)
+ (?\C-e ?\C-e erpin-cn erpin erpin-cn Chinese-GB NIL)
+ (?\C-p ?\C-p pinyin-cn pinyin pinyin-cn Chinese-GB NIL)
+ (?\C-z ?\C-z zhuyin-cn zhuyin zhuyin-cn Chinese-GB T)
+ (?\C-u ?\C-u quanjiao-upcase-cn quanjiao quanjiao-up-cn Chinese-GB)
+ (?\C-d ?\C-d quanjiao-downcase-cn quanjiao quanjiao-down-cn Chinese-GB)
+ (?E ?E erpin-tw erpin erpin-tw Chinese-CNS NIL)
+ (?P ?P pinyin-tw pinyin pinyin-tw Chinese-CNS NIL)
+ (?Z ?Z zhuyin-tw zhuyin zhuyin-tw Chinese-CNS T)
+ (?U ?U quanjiao-upcase-tw quanjiao quanjiao-up-tw Chinese-CNS)
+ (?C ?C quanjiao-downcase-tw quanjiao quanjiao-down-tw Chinese-CNS)
+ (?H ?H hangul hangul hangul Korean)
+ (?J ?J jeonkak-upcase jeonkak jeonkak-up Korean)
+ (?j ?j jeonkak-downcase jeonkak jeonkak-down Korean)))
(provide 'its-keydef)
l)
((numberp l) ; VSYL
(car syl))
+ ((numberp (cdr l))
+ (substring (car l) 0 (cdr l)))
(t
- (car (cdr syl))))))
+ (car l)))))
(defsubst its-eob-keyexpr (eob)
(car (cdr eob)))
(cons class back))
(defsubst its-make-otherwise (output class+back)
(cons output class+back))
+
+(defsubst its-DSYL-with-back-p (syl)
+ (and (consp (cdr syl))
+ (numberp (its-get-kst/t syl))))
+
+(defsubst its-concrete-DSYL-p (syl)
+ (stringp (cdr syl)))
+
+(defsubst its-make-concrete-DSYL (syl)
+ (if (consp (cdr syl))
+ (cons (its-get-output syl) (its-get-keyseq-syl syl))
+ syl))
+
;;
;;
+(require 'its-keydef)
+
(defvar its-mode-map
(let ((map (make-sparse-keymap))
(i 33))
(define-key map "\C-m" 'its-exit-mode) ; RET
(define-key map [return] 'its-exit-mode)
(define-key map "\C-t" 'its-transpose-chars)
+ (define-key map [backspace] 'its-delete-backward-SYL)
(define-key map [delete] 'its-delete-backward-SYL)
+ (define-key map [M-backspace] 'its-delete-backward-SYL-by-keystroke)
+ (define-key map [M-delete] 'its-delete-backward-SYL-by-keystroke)
(define-key map [right] 'its-forward-SYL)
(define-key map [left] 'its-backward-SYL)
(define-key map "\C-\\" 'its-exit-mode-off-input-method)
(define-key map " " 'its-kick-convert-region)
(define-key map "\177" 'its-delete-backward-SYL)
;;
- (define-key map "\C-p" 'its-previous-map)
- (define-key map "\C-n" 'its-next-map)
-; (define-key map "\M-h" 'its-hiragana) ; hiragana-region for input-buffer
-; (define-key map "\M-k" 'its-katakana)
-; (define-key map "\M-<" 'its-hankaku)
-; (define-key map "\M->" 'its-zenkaku)
-; (define-key map "\M-\C-h" 'its-select-hiragana)
-; (define-key map "\M-\C-k" 'its-select-katakana)
-;;; (define-key map "\M-q" 'its-select-downcase) ;
-; (define-key map "\M-Q" 'its-select-upcase)
-; (define-key map "\M-z" 'its-select-zenkaku-downcase)
-; (define-key map "\M-Z" 'its-select-zenkaku-upcase)
+ (define-key map "\M-p" 'its-previous-map)
+ (define-key map "\M-n" 'its-next-map)
+ (define-key map "\M-h" 'its-hiragana) ; hiragana-region for input-buffer
+ (define-key map "\M-k" 'its-katakana)
+ (define-key map "\M-<" 'its-hankaku)
+ (define-key map "\M->" 'its-zenkaku)
+; (its-define-select-keys map t)
map)
"Keymap for ITS mode.")
(defvar its-fence-close "|" "*\e$B%U%'%s%9$N=*E@$r<($9J8;zNs\e(B (1 \e$BJ8;z\e(B)")
(defvar its-fence-face nil "*\e$B%U%'%s%9I=<($KMQ$$$k\e(B face \e$B$^$?$O\e(B nil")
+(defconst its-setup-fence-before-insert-SYL nil)
+
(defun its-put-cursor (cursor)
- (let ((p (point)))
+ (let ((p (point))
+ (map (copy-keymap its-mode-map)))
+ (its-define-select-keys map)
(insert "!")
- (add-text-properties p (point) (list 'local-map its-mode-map
+ (add-text-properties p (point) (list 'local-map map
'invisible t
'intangible 'its-part-2
'its-cursor cursor))
(goto-char p)))
+
+(defsubst its-set-cursor-status (cursor)
+ (put-text-property (point) (1+ (point)) 'its-cursor cursor)
+ cursor)
+
;;
;; +-- START property
;; | --- CURSOR Property
;; intangible intangible
;; 1 2
;;
-(defun its-insert-fence-open ()
- (let ((p (point)))
+(defun its-setup-fence-mode ()
+ (let ((open-props '(its-start t intangible its-part-1))
+ (close-props '(its-end t intangible its-part-2))
+ (p (point)) p1)
(insert its-fence-open)
- (add-text-properties p (point)
- (if its-fence-face
- '(invisible t its-start t intangible its-part-1)
- '(its-start t intangible its-part-1)))))
-
-(defun its-insert-fence-close ()
- (let ((p (point)))
+ (setq p1 (point))
+ (add-text-properties p p1 open-props)
(insert its-fence-close)
- (add-text-properties p (point)
- (if its-fence-face
- '(invisible t its-end t intangible its-part-2)
- '(its-end t intangible its-part-2)))
- (goto-char p)))
+ (add-text-properties p1 (point) close-props)
+ (if its-fence-face
+ (put-text-property 'invisible t p (point)))
+ (goto-char p1)
+ (its-put-cursor t)))
(defun its-start (key)
- (its-insert-fence-open)
- (its-insert-fence-close)
- (its-put-cursor (its-input nil key))
- (force-mode-line-update))
+ (let ((its-setup-fence-before-insert-SYL t))
+ (its-input nil key)
+ (force-mode-line-update)))
(defun its-restart (str)
(let (p)
- (its-insert-fence-open)
- (its-insert-fence-close)
+ (its-setup-fence-mode)
(setq p (point))
(insert str)
- (put-text-property p (point) 'intangible 'its-part-2)
- (goto-char p)
- (its-put-cursor t)))
+ (its-beginning-of-input-buffer)))
(defun its-self-insert-char ()
(interactive)
(let ((key last-command-char)
(cursor (get-text-property (point) 'its-cursor))
- (syl nil))
- (if (null cursor)
- (setq syl (get-text-property (1- (point)) 'its-syl)))
- ;; delete cursor
- (delete-region (point) (1+ (point)))
- (setq cursor (its-input syl key))
- (its-put-cursor cursor)))
+ (syl (get-text-property (1- (point)) 'its-syl)))
+ (cond
+ ((or (eq cursor t)
+ (not (eq (get-text-property (1- (point)) 'its-map) its-current-map)))
+ (put-text-property (- (point) (length (its-get-output syl))) (point)
+ 'its-syl (its-make-concrete-DSYL syl))
+ (setq syl nil))
+ (cursor
+ (setq syl nil)))
+ (its-input syl key)))
(defvar its-current-map nil)
(make-variable-buffer-local 'its-current-map)
(defun its-make-VSYL (keyseq)
(cons keyseq (length keyseq)))
+(defvar its-barf-on-invalid-keyseq nil
+ "T means don't allow invalid key sequence in input buffer.")
+
+(defun its-input-error ()
+ (error "Invalid Romaji Sequence"))
+
;; Return CURSOR
(defun its-input (syl key)
(if (null syl)
(setq syl (its-initial-ISYL)))
(let ((output (car syl))
(k/kk/s (cdr syl)))
- (if (numberp k/kk/s)
+ (cond
+ ((numberp k/kk/s)
;; k/kk/s is "point in keyseq"
- (its-input-to-vsyl syl key k/kk/s output)
+ (its-input-to-vsyl syl key k/kk/s output))
+ ((and its-barf-on-invalid-keyseq
+ (null (its-keyseq-acceptable-p (vector key) syl)))
+ ;; signal before altering
+ (its-input-error))
+ (t
;; It's ISYL
- (its-state-machine syl key 'its-buffer-ins/del-SYL))))
+ (its-state-machine syl key 'its-buffer-ins/del-SYL)))))
(defun its-input-to-vsyl (syl key point output)
(if (< key 0)
- t
+ (its-set-cursor-status t)
(let ((len (length output)))
(if (= len point)
;; point is at end of VSYL. Don't need to call state machine.
- (progn
- (its-buffer-ins/del-SYL
- (its-make-VSYL (concat output (vector key))) syl)
- nil)
+ (its-buffer-ins/del-SYL
+ (its-make-VSYL (concat output (vector key))) syl nil)
;; point is at middle of VSYL.
(let ((new-keyseq (concat (substring output 0 point)
(vector key)
(substring output point))))
(its-state-machine-keyseq new-keyseq 'its-buffer-ins/del-SYL))))))
-
-(defvar its-barf-on-invalid-keyseq nil
- "T means don't allow invalid key sequence in input buffer.")
\f
;;;
;;; ITS State Machine
;; Return CURSOR
(defun its-state-machine (state key emit)
(let ((next-state (its-get-next-state state key))
- expr-output-back)
- (if next-state
- (let ((kst/t (its-get-kst/t next-state)))
- (funcall emit next-state state)
- (if (not (its-kst-p kst/t))
- ;; Here we arrive to a terminal state.
- ;; Emit a DSYL, and go ahead.
- (let ((output (its-get-output next-state))
- (keyseq (its-get-keyseq next-state))
- (back kst/t))
- (if back
- ;; It's negative integer which specifies how many
- ;; characters we go backwards
- (its-state-machine-keyseq (substring keyseq back)
- emit (< key 0))
- 'its-cursor))
- ;; Still, it's a intermediate state.
- nil))
- (if (and (>= key 0)
- (setq expr-output-back (its-get-otherwise state key)))
- (let ((keyseq (concat (its-get-keyseq state) (char-to-string key))))
- (funcall emit expr-output-back state)
- (its-state-machine-keyseq
- (substring keyseq (its-eob-back expr-output-back)) emit))
- ;; No next state for KEY. It's invalid sequence.
- (if (< key 0) ; no next state for END of keystroke
- ;; ISYL --> DSYL XXX
- (if its-barf-on-invalid-keyseq
- (error its-barf-on-invalid-keyseq)
- (funcall emit (cons (car state)
- (list (its-get-keyseq state))) state)
- t)
- (if its-barf-on-invalid-keyseq
- (error its-barf-on-invalid-keyseq)
- ;; XXX Should make DSYL (instead of VSYL)?
- (let ((keyseq (concat (its-get-keyseq state) (vector key))))
- (funcall emit (its-make-VSYL keyseq) state)
- nil)))))))
+ expr-output-back kst/t output keyseq back)
+ (cond
+ ;; proceed to next status
+ (next-state
+ (setq kst/t (its-get-kst/t next-state)
+ output (its-get-output next-state)
+ keyseq (its-get-keyseq next-state))
+ (cond
+ ;; Still, it's a intermediate state.
+ ((its-kst-p kst/t)
+ (funcall emit next-state state nil))
+
+ ;; It's negative integer which specifies how many
+ ;; characters we go backwards
+ (kst/t
+ (funcall emit next-state state 'its-cursor)
+ (its-state-machine-keyseq (substring keyseq kst/t) emit (< key 0)))
+
+ ;; Here we arrive to a terminal state.
+ ;; Emit a DSYL, and go ahead.
+ (t
+ (funcall emit next-state state 'its-cursor))))
+
+ ;; push back by otherwise status
+ ((and (>= key 0)
+ (setq expr-output-back (its-get-otherwise state key)))
+ (setq keyseq (concat (its-get-keyseq state) (vector key)))
+ (funcall emit
+ (cons (its-get-output expr-output-back)
+ (cons keyseq (its-eob-back expr-output-back)))
+ state t)
+ (its-state-machine-keyseq
+ (substring keyseq (its-eob-back expr-output-back)) emit))
+
+ ((eq its-barf-on-invalid-keyseq 'its-keyseq-test)
+ 'its-keyseq-test-failed)
+
+ ;; No next state for KEY. It's invalid sequence.
+ (its-barf-on-invalid-keyseq
+ (its-input-error))
+
+ (t
+ ;; XXX Should make DSYL (instead of VSYL)?
+ (setq keyseq (concat (its-get-keyseq state) (if (> key 0) (vector key))))
+ (funcall emit (its-make-VSYL keyseq) state nil)))))
(defvar its-latest-SYL nil
"The latest SYL inserted.")
(defun its-state-machine-keyseq (keyseq emit &optional eol)
(let ((i 0)
(len (length keyseq))
- (its-barf-on-invalid-keyseq nil) ; temporally disable DING
(syl (its-initial-ISYL))
cursor)
(while (< i len)
- (let ((key (aref keyseq i)))
- (setq cursor
- (if (numberp (cdr syl)) ; VSYL
- (progn
- (funcall emit
- (its-make-VSYL (concat (car syl) (vector key)))
- syl)
- nil)
- (its-state-machine syl key emit)))
- (setq i (1+ i))
- (if cursor
- (setq syl (its-initial-ISYL))
- (setq syl its-latest-SYL))))
- (if eol
+ (cond
+ ((numberp (cdr syl))
+ ;; VSYL - no need looping
+ (funcall emit
+ (its-make-VSYL (concat (car syl) (substring keyseq i)))
+ syl nil)
+ (setq cursor nil
+ i len))
+ (t
+ (setq cursor (its-state-machine syl (aref keyseq i) emit))))
+ (if (eq cursor 'its-keyseq-test-failed)
+ (setq i len)
+ (setq syl (if cursor (its-initial-ISYL) its-latest-SYL)
+ i (1+ i))))
+ (if (and eol (not (eq cursor 'its-keyseq-test-failed)))
(its-state-machine syl -1 emit)
cursor)))
-(defun its-buffer-ins/del-SYL (newsyl oldsyl)
+(defun its-buffer-ins/del-SYL (newsyl oldsyl cursor)
+ (if its-setup-fence-before-insert-SYL
+ (progn
+ (setq its-setup-fence-before-insert-SYL nil)
+ (its-setup-fence-mode)))
(its-buffer-delete-SYL oldsyl)
(its-update-latest-SYL newsyl)
(let ((p (point)))
'its-lang its-current-language
'intangible 'its-part-1))
(if its-fence-face
- (put-text-property p (point) 'face its-fence-face))))
+ (put-text-property p (point) 'face its-fence-face))
+ (its-set-cursor-status cursor)))
(defun its-buffer-delete-SYL (syl)
(let ((len (length (its-get-output syl))))
(setq ebl nil)
(setq ebl (cdr ebl)))))
expr-output-back))
+
+(defun its-keyseq-acceptable-p (keyseq &optional syl eol)
+ (let ((i 0)
+ (len (length keyseq))
+ (its-barf-on-invalid-keyseq 'its-keyseq-test)
+ (its-latest-SYL nil)
+ (emit (lambda (nsyl osyl cursor)
+ (its-update-latest-SYL nsyl)
+ cursor))
+ cursor)
+ (if (null syl)
+ (setq syl (its-initial-ISYL)))
+ (while (and syl (< i len))
+ (setq cursor (its-state-machine syl (aref keyseq i) emit))
+ (cond
+ ((eq cursor 'its-keyseq-test-failed)
+ (setq syl nil))
+ (cursor
+ (setq syl (its-initial-ISYL)))
+ (t
+ its-latest-SYL))
+ (setq i (1+ i)))
+ (if eol
+ (setq cursor (its-state-machine syl -1 emit)))
+ (not (eq cursor 'its-keyseq-test-failed))))
\f
;;;
;;; Name --> map
(setq syl (get-text-property p 'its-syl))
(setq n (1- n)))
;; Make SYLs have property of "part 1"
- (put-text-property p old-point 'intangible 'its-part-1)
+ (put-text-property old-point p 'intangible 'its-part-1)
(goto-char p)
(its-put-cursor t)
(if (> n 0)
(defvar its-delete-by-keystroke nil)
+(defun its-delete-backward-SYL-by-keystroke (n killflag)
+ (interactive "p\nP")
+ (let ((its-delete-by-keystroke t))
+ (its-delete-backward-SYL n killflag)))
+
;; TODO: killflag
(defun its-delete-backward-within-SYL (syl n killflag)
(let* ((keyseq (its-get-keyseq-syl syl))
(len (length keyseq))
- (p (point))
- (its-current-map (get-text-property (1- (point)) 'its-map)))
+ (p (- (point) (length (its-get-output syl))))
+ (its-current-map (get-text-property (1- (point)) 'its-map))
+ back pp)
+ (if (< n 0)
+ (signal 'args-out-of-range (list (- (point) n) (point))))
+ (if its-delete-by-keystroke
+ (while (null (or (eq p pp) (its-concrete-DSYL-p syl)))
+ (setq pp p)
+ (while (and (setq syl (get-text-property (1- p) 'its-syl))
+ (its-DSYL-with-back-p syl)
+ (<= (setq back (- (its-get-kst/t syl))) len)
+ (> back (- len n))
+ (equal (substring (its-get-keyseq syl) (- back))
+ (substring keyseq 0 back)))
+ (setq keyseq (concat (its-get-keyseq-syl syl) keyseq)
+ len (length keyseq)
+ p (- p (length (its-get-output syl)))))
+ (if (and (eq p pp) syl (> n len))
+ (setq n (- n len)
+ keyseq (its-get-keyseq-syl syl)
+ len (length keyseq)
+ p (- p (length (its-get-output syl))))))
+ (if (and (> n len) (its-concrete-DSYL-p syl))
+ (setq len 1)))
(if (> n len)
- (signal 'args-out-of-range (list p n)))
- ;; Delete CURSOR
- (delete-region p (1+ p))
- (its-buffer-delete-SYL syl)
- (if (= n len)
- ;; Check if empty
- (let ((s (get-text-property (1- (point)) 'its-start))
- (e (get-text-property (point) 'its-end)))
- (if (and s e)
- (its-exit-mode-internal)
- (its-put-cursor (not its-delete-by-keystroke))))
- (setq keyseq (substring keyseq 0 (- len n)))
- (let ((r (its-state-machine-keyseq keyseq 'its-buffer-ins/del-SYL)))
- (its-put-cursor r)))))
-
-;; XXX: NIY
+ (setq n (- n len)
+ len 0))
+ (while (and (> n len) (setq syl (get-text-property (1- p) 'its-syl)))
+ (setq n (1- n)
+ p (- p (length (its-get-output syl)))))
+ (if (> n len)
+ (signal 'beginning-of-buffer nil))
+ (delete-region p (point))
+ (cond
+ ((> len n)
+ (its-state-machine-keyseq (substring keyseq 0 (- len n))
+ 'its-buffer-ins/del-SYL))
+ ;; Check if empty
+ ((and (get-text-property (1- (point)) 'its-start)
+ (get-text-property (1+ (point)) 'its-end))
+ ;; Delete CURSOR
+ (delete-region (point) (1+ (point)))
+ (its-exit-mode-internal))
+ ((and its-delete-by-keystroke
+ (null (its-concrete-DSYL-p (get-text-property (1- p) 'its-syl))))
+ (its-set-cursor-status 'its-cursor))
+ (t
+ (its-set-cursor-status t)))))
+
(defun its-transpose-chars (n)
- (interactive)
+ (interactive "p")
(let ((syl (get-text-property (1- (point)) 'its-syl))
- (cursor (get-text-property (point) 'its-cursor)))
- (if (null syl)
- (signal 'beginning-of-buffer nil)
- (if (eq cursor t)
- (its-delete-backward-SYL-internal n nil)
- (its-delete-backward-within-SYL syl 2 nil)))))
+ (cursor (get-text-property (point) 'its-cursor))
+ keyseq len)
+ (cond
+ ((null syl)
+ (signal 'beginning-of-buffer nil))
+ ((eq cursor t)
+ (if (and (= n 1) (get-text-property (1+ (point)) 'its-end))
+ (progn
+ (its-backward-SYL 1)
+ (setq syl (get-text-property (1- (point)) 'its-syl))
+ (if (null syl)
+ (signal 'beginning-of-buffer nil))))
+ (its-buffer-delete-SYL syl)
+ (while (> n 0)
+ (if (get-text-property (1+ (point)) 'its-end)
+ (progn
+ (its-buffer-ins/del-SYL syl nil t)
+ (signal 'end-of-buffer nil)))
+ (its-forward-SYL 1)
+ (setq n (1- n)))
+ (while (< n 0)
+ (if (get-text-property (1- (point)) 'its-start)
+ (progn
+ (its-buffer-ins/del-SYL syl nil t)
+ (signal 'beginning-of-buffer nil)))
+ (its-backward-SYL 1)
+ (setq n (1+ n)))
+ (its-buffer-ins/del-SYL syl nil t))
+ (t
+ (setq keyseq (its-get-keyseq-syl syl)
+ len (length keyseq))
+ (cond
+ ((or (> n 1) (<= len 1))
+ (signal 'end-of-buffer nil))
+ ((>= (- n) len)
+ (signal 'beginning-of-buffer nil))
+ (t
+ (setq n (if (> n 0) (- -1 n) (1- n)))
+ (setq keyseq (concat (substring keyseq 0 n)
+ (substring keyseq -1)
+ (substring keyseq n -1)))
+ (if (and its-barf-on-invalid-keyseq
+ (null (its-keyseq-acceptable-p keyseq)))
+ (its-input-error))
+ (delete-region (- (point) (length (its-get-output syl))) (point))
+ (its-state-machine-keyseq keyseq 'its-buffer-ins/del-SYL)))))))
;; Return VOID
(defun its-input-end ()
(its-exit-mode-internal t))
(defun its-in-fence-p ()
- (let ((prop (get-text-property (point) 'intangible)))
- (or (eq prop 'its-part-1) (eq prop 'its-part-2))))
+ (eq (get-text-property (point) 'intangible) 'its-part-2))
\f
-(defvar its-translation-result nil "")
+(defvar its-translation-result "" "")
-(defun its-ins/del-SYL-batch (newsyl oldsyl)
+(defun its-ins/del-SYL-batch (newsyl oldsyl cursor)
(its-update-latest-SYL newsyl)
(if (and newsyl
(consp (cdr newsyl))
(not (its-kst-p (its-get-kst/t newsyl))))
;; DSYL
- (setq its-translation-result
- (cons (its-get-output newsyl) its-translation-result))))
-
-(defun its-translate-region (start end &optional map)
+ (let ((output (its-get-output newsyl))
+ (oldlen (length its-translation-result)))
+ (setq its-translation-result (concat its-translation-result output))
+ (put-text-property oldlen (length its-translation-result)
+ 'its-lang its-current-language
+ its-translation-result)))
+ cursor)
+
+(defun its-translate-region (start end)
+ (its-translate-region-internal start end)
+ (remove-text-properties start (point) '(its-lang nil)))
+
+(defun its-translate-region-internal (start end)
(interactive "r")
- (setq its-translation-result nil)
+ (setq its-translation-result "")
(goto-char start)
(let ((i 0)
(syl (its-initial-ISYL))
;; temporally enable DING
- (its-barf-on-invalid-keyseq "Invalid Romaji Sequence")
+ (its-barf-on-invalid-keyseq t)
cursor)
(while (< (point) end)
(let ((key (following-char)))
(if (eq syl its-latest-SYL)
(its-state-machine syl -1 'its-ins/del-SYL-batch))
(delete-region start end)
- (apply 'insert (reverse its-translation-result))))
+ (insert its-translation-result)))
\f
-(require 'its-keydef)
-
(provide 'its)
;;; its.el ends here.