- (let (bunsetsu-info-list lang contin p s e)
- (save-restriction
- (narrow-to-region start end)
- (goto-char start)
- (insert egg-conversion-open)
- (add-text-properties start (point)
- (list
- 'egg-start t
- 'egg-source (buffer-substring (point)
- (point-max))))
- (if egg-conversion-face
- (put-text-property start (point) 'invisible t))
- (setq start (point))
- (egg-separate-languages start (point-max))
- (goto-char start)
- (while (< (point) (point-max))
- (setq lang (get-text-property (point) 'egg-lang)
- s (point)
- e (point))
- (while (and (< e (point-max))
- (equal lang (get-text-property e 'egg-lang)))
- (setq e (next-single-property-change e 'egg-lang nil (point-max))))
- (setq bunsetsu-info-list
- (egg-start-conversion (buffer-substring s e) lang))
- (setq contin (< e (point-max)))
- (delete-region s e)
- (egg-insert-bunsetsu-list bunsetsu-info-list
- (if (< (point) (point-max)) 'contine t))))
- (setq p (point))
- (insert egg-conversion-close)
- (put-text-property p (point) 'egg-end t)
- (if egg-conversion-face
- (put-text-property p (point) 'invisible t))
- (goto-char start)))
-
-(defun egg-separate-languages (start end)
- (let (lang last-lang last-chinese p l c cset)
+ (let ((source (buffer-substring start end))
+ (no-prop-source (buffer-substring-no-properties start end))
+ bunsetsu-info-list len result i j s)
+ (if (>= start end)
+ ;; nothing to do
+ nil
+ (delete-region start end)
+ (let ((inhibit-read-only t))
+ (its-define-select-keys egg-conversion-map)
+ (goto-char start)
+ ;; XXX: Why make OPEN&CLOSE string every time when
+ ;; this function is invoked? Any Reason?
+ ;; For me it's matter of user costomization
+ ;; of setting egg-conversion-open/egg-conversion-close
+ ;; it can be string of properties at the beginning, isn't it?
+ (setq s (copy-sequence egg-conversion-open)
+ len (length s))
+ (set-text-properties 0 len
+ (list
+ 'read-only t
+ 'egg-start t
+ 'egg-source source)
+ s)
+ (if egg-conversion-invisible
+ (put-text-property 0 len 'invisible t s))
+ (insert s)
+ (setq start (point)
+ s (copy-sequence egg-conversion-close)
+ len (length s))
+ (set-text-properties 0 len
+ '(read-only t rear-nonsticky t egg-end t)
+ s)
+ (if egg-conversion-invisible
+ (put-text-property 0 len 'invisible t s))
+ (insert s)
+ (goto-char start)
+ (egg-separate-languages (copy-sequence source))
+ (setq i 0
+ len (length source))
+ (while (< i len)
+ (setq egg-current-language (get-text-property i 'egg-lang source)
+ j (egg-next-single-property-change i 'egg-lang source len))
+ (condition-case result
+ (setq bunsetsu-info-list (egg-start-conversion
+ (substring no-prop-source i j)
+ egg-current-language))
+ (error ; XXX: catching all error is BADBADBAD
+ (setq bunsetsu-info-list (egg-start-conversion-other-languages
+ (substring no-prop-source i j)
+ egg-current-language))
+ (message "egg %s backend: %s"
+ egg-current-language (nth 1 result))))
+ (egg-insert-bunsetsu-list bunsetsu-info-list
+ (if (< j len) 'contine t))
+ (setq i j))
+ (goto-char start)))))
+
+(defconst egg-chinese-sisheng-regexp
+ (concat "[" (list (make-char 'chinese-sisheng 32))
+ "-" (list (make-char 'chinese-sisheng 127))
+ "]+"))
+
+(defun egg-separate-languages (str &optional last-lang)
+ (let (lang last-chinese
+ (len (length str)) i j l)