From: tomo Date: Tue, 24 Aug 2004 13:35:43 +0000 (+0000) Subject: (ideo-trans-select-char): New function. X-Git-Tag: chise-base-0_23~29 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=06f0e4d1f827df46d6d767b1a022298cd7c63fa2;p=chise%2Ftomoyo-tools.git (ideo-trans-select-char): New function. (ideo-translate-chinese-string-into-traditional): New function. (ideo-translate-japanese-string-into-traditional): New function. (ideo-translate-string-into-traditional): Deleted. (ideo-translate-japanese-region-into-traditional): Renamed from `ideo-translate-region-into-traditional'; use `ideo-trans-select-char'. (ideo-translate-region-into-traditional): New obsolete alias for `ideo-translate-japanese-region-into-traditional'. --- diff --git a/ideo-trans.el b/ideo-trans.el index d0b84d0..ec8de15 100644 --- a/ideo-trans.el +++ b/ideo-trans.el @@ -51,9 +51,10 @@ ;;;###autoload (defun char-representative-of-ucs (char) "Convert CHAR into representative character of UCS." - (if (setq ret (char-ucs char)) - (decode-char '=ucs ret) - char)) + (let (ret) + (if (setq ret (char-ucs char)) + (decode-char '=ucs ret) + char))) ;;;###autoload (defun char-representative-of-domain (char domain) @@ -113,7 +114,7 @@ ;;;###autoload (defun ideo-translate-string-into-simplified-japanese (string) "Simplify traditional Kanji characters in STRING." - (let (uchr ret) + (let (ret) (mapconcat (lambda (chr) (setq ret (or (char-feature chr '->simplified@JP/Jouyou) @@ -128,24 +129,33 @@ (t chr)))) string ""))) +(defun ideo-trans-select-char (chars &optional prefix) + (let ((i 0) + prompt ret) + (setq prompt + (concat + prefix + (mapconcat (lambda (cell) + (setq i (1+ i)) + (format "%d. %c" i cell)) + chars " ") + " : ")) + (while (and (setq ret (string-to-int (read-string prompt))) + (not (and (< 0 ret) + (<= ret (length chars)))))) + (nth (1- ret) chars))) + ;;;###autoload -(defun ideo-translate-string-into-traditional (string) - "Convert simplified Kanji in STRING into traditional characters." - (let (uchr ret) +(defun ideo-translate-chinese-string-into-traditional (string) + "Convert simplified Chinese characters in STRING to traditional characters." + (let (ret) (mapconcat (lambda (chr) (char-to-string - (cond ((car (char-feature chr '<-simplified))) - ((progn - (setq ret - (cond ((setq ret (char-feature chr '=>ucs@jis)) - (decode-char '=ucs@jis ret)) - ((setq ret (char-ucs chr)) - (decode-char '=ucs@jp ret)) - (t chr))) - (setq ret (or (char-feature ret '<-simplified@JP/Jouyou) - (char-feature ret '<-simplified@JP)))) - (car ret)) + (cond ((car (char-feature chr '<-simplified)) + (if (cdr ret) + (ideo-trans-select-char ret (format "%c => " chr)) + (car ret))) ((progn (setq ret (cond ((setq ret (char-feature chr '=>ucs@gb)) @@ -156,21 +166,47 @@ (if (setq ret (encode-char ret 'chinese-gb2312)) (setq ret (decode-char 'chinese-gb12345 ret)))) ret) + (t chr)))) + string ""))) + +;;;###autoload +(defun ideo-translate-japanese-string-into-traditional (string) + "Convert simplified Kanji in STRING into traditional characters." + (let (ret) + (mapconcat + (lambda (chr) + (char-to-string + (cond ((setq ret (char-feature chr '<-simplified)) + (if (cdr ret) + (ideo-trans-select-char ret (format "%c => " chr)) + (car ret))) + ((progn + (setq ret + (cond ((setq ret (char-feature chr '=>ucs@jis)) + (decode-char '=ucs@jis ret)) + ((setq ret (char-ucs chr)) + (decode-char '=ucs@jp ret)) + (t chr))) + (setq ret (or (char-feature ret '<-simplified@JP/Jouyou) + (char-feature ret '<-simplified@JP)))) + (if (cdr ret) + (ideo-trans-select-char ret (format "%c => " chr)) + (car ret))) ((setq ret (char-feature chr '=>ucs@jis)) (decode-char '=ucs@jis ret)) ((setq ret (char-ucs chr)) (decode-char '=ucs@jp ret)) (t chr)))) string ""))) - + ;;;###autoload -(defun ideo-translate-region-into-traditional (start end) +(defun ideo-translate-japanese-region-into-traditional (start end) (interactive "r") (save-excursion (save-restriction (narrow-to-region start end) (goto-char start) - (let (chr ret rret i prompt) + (let (chr ret rret) (while (and (skip-chars-forward "\x00-\xFF") (not (eobp))) (setq chr (char-after)) @@ -183,26 +219,19 @@ (progn (if (cdr ret) (progn - (setq i 0) - (setq prompt - (concat - (mapconcat (lambda (cell) - (setq i (1+ i)) - (format "%d. %c" i cell)) - ret " ") - " : ")) - (while (and (setq rret - (string-to-int - (read-string prompt))) - (not (and (< 0 rret) - (<= rret (length ret)))))) + (setq rret (ideo-trans-select-char ret)) (delete-char) - (insert (nth (1- rret) ret))) + (insert rret)) (delete-char) (insert (car ret)))) (or (eobp) (forward-char)))))))) +;;;###autoload +(define-obsolete-function-alias + 'ideo-translate-region-into-traditional + 'ideo-translate-japanese-region-into-traditional) + ;;; @ End. ;;;