Add arch taglines
[bpt/emacs.git] / lisp / language / japan-util.el
index 8b75055..e9a80fc 100644 (file)
@@ -1,7 +1,8 @@
-;;; japan-util.el ---  utilities for Japanese
+;;; japan-util.el --- utilities for Japanese -*- coding: iso-2022-7bit; -*-
 
-;; Copyright (C) 1995 Free Software Foundation, Inc.
 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+;; Licensed to the Free Software Foundation.
+;; Copyright (C) 2001 Free SOftware Foundation, Inc.
 
 ;; Keywords: mule, multilingual, Japanese
 
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
 ;;; Code:
 
 ;;;###autoload
-(defun setup-japanese-environment ()
-  "Setup multilingual environment (MULE) for Japanese."
-  (interactive)
-  (setup-english-environment)
-  (setq coding-category-iso-8-2 'japanese-iso-8bit)
-
-  (set-coding-priority
-   '(coding-category-iso-7
-     coding-category-iso-8-2
-     coding-category-sjis
-     coding-category-iso-8-1
-     coding-category-iso-else
-     coding-category-emacs-mule))
-
-  (if (eq system-type 'ms-dos)
-      (progn
-       (setq-default buffer-file-coding-system 'japanese-shift-jis)
-       (set-terminal-coding-system-internal 'japanese-shift-jis)
-       (set-keyboard-coding-system-internal 'japanese-shift-jis)
-       (setq default-process-coding-system
-             '(japanese-shift-jis-dos . japanese-shift-jis-dos)))
-    (setq-default buffer-file-coding-system 'iso-2022-7bit)
-    (set-terminal-coding-system-internal 'iso-2022-7bit)
-    (set-keyboard-coding-system-internal 'iso-2022-7bit))
-
-  (setq default-input-method '("Japanese" . "quail-ja"))
-
-  (setq sendmail-coding-system 'iso-2022-jp
-       rmail-file-coding-system 'iso-2022-jp)
-  )
+(defun setup-japanese-environment-internal ()
+  ;; By default, we use 'japanese-iso-8bit for file names.  But, the
+  ;; following prefer-coding-system will override it.
+  (if (memq system-type '(windows-nt ms-dos cygwin))
+      (prefer-coding-system 'japanese-shift-jis)
+    (prefer-coding-system 'japanese-iso-8bit)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%,\e(B "\e(I6^\e(B") (?\e$B$.\e(B ?\e$B%.\e(B "\e(I7^\e(B") (?\e$B$0\e(B ?\e$B%0\e(B "\e(I8^\e(B") (?\e$B$2\e(B ?\e$B%2\e(B "\e(I9^\e(B") (?\e$B$4\e(B ?\e$B%4\e(B "\e(I:^\e(B")
     (?\e$B$6\e(B ?\e$B%6\e(B "\e(I;^\e(B") (?\e$B$8\e(B ?\e$B%8\e(B "\e(I<^\e(B") (?\e$B$:\e(B ?\e$B%:\e(B "\e(I=^\e(B") (?\e$B$<\e(B ?\e$B%<\e(B "\e(I>^\e(B") (?\e$B$>\e(B ?\e$B%>\e(B "\e(I?^\e(B")
@@ -76,8 +55,8 @@
     (?\e$B$!\e(B ?\e$B%!\e(B ?\e(I'\e(B) (?\e$B$#\e(B ?\e$B%#\e(B ?\e(I(\e(B) (?\e$B$%\e(B ?\e$B%%\e(B ?\e(I)\e(B) (?\e$B$'\e(B ?\e$B%'\e(B ?\e(I*\e(B) (?\e$B$)\e(B ?\e$B%)\e(B ?\e(I+\e(B)
     (?\e$B$C\e(B ?\e$B%C\e(B ?\e(I/\e(B)
     (?\e$B$c\e(B ?\e$B%c\e(B ?\e(I,\e(B) (?\e$B$e\e(B ?\e$B%e\e(B ?\e(I-\e(B) (?\e$B$g\e(B ?\e$B%g\e(B ?\e(I.\e(B)
-    (?\e$B$n\e(B ?\e$B%n\e(B nil)
-    (nil ?\e$B%t\e(B "\e(I3^\e(B") (nil ?\e$B%u\e(B nil) (nil ?\e$B%v\e(B nil))
+    (?\e$B$n\e(B ?\e$B%n\e(B "\e(I\\e(B")
+    ("\e$B$&!+\e(B" ?\e$B%t\e(B "\e(I3^\e(B") (nil ?\e$B%u\e(B "\e(I6\e(B") (nil ?\e$B%v\e(B "\e(I9\e(B"))
   "Japanese JISX0208 Kana character table.
 Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where
 HIRAGANA and KATAKANA belong to `japanese-jisx0208',
@@ -92,27 +71,38 @@ HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.")
          hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot)
          l (cdr l))
     (if hiragana
-       (progn
+       (if (stringp hiragana)
+           (if (> (length hiragana) 1)
+               (let ((hira (aref hiragana 0)))
+                 (put-char-code-property
+                  hira 'kana-composition
+                  (cons (cons (aref hiragana 1) katakana)
+                        (get-char-code-property hira 'kana-composition)))))
          (put-char-code-property hiragana 'katakana katakana)
-         (put-char-code-property katakana 'hiragana hiragana)
-         (if jisx0201
-             (progn
-               (put-char-code-property hiragana 'jisx0201 jisx0201)
-               (if (integerp jisx0201)
-                   (put-char-code-property jisx0201 'hiragana hiragana))))))
+         (put-char-code-property hiragana 'jisx0201 jisx0201)))
+    (when (integerp katakana)
+      (put-char-code-property katakana 'hiragana hiragana)
+      (put-char-code-property katakana 'jisx0201 jisx0201))
     (if jisx0201
-       (progn
-         (put-char-code-property katakana 'jisx0201 jisx0201)
-         (if (integerp jisx0201)
-             (put-char-code-property jisx0201 'katakana katakana))))))
+       (if (stringp jisx0201)
+           (if (> (length jisx0201) 1)
+               (let ((kana (aref jisx0201 0)))
+                 (put-char-code-property
+                  kana 'kana-composition
+                  (cons (cons (aref jisx0201 1) katakana)
+                        (get-char-code-property kana 'kana-composition)))))
+         (put-char-code-property jisx0201 'hiragana hiragana)
+         (put-char-code-property jisx0201 'katakana katakana)
+         (put-char-code-property jisx0201 'jisx0208 katakana)))))
 
 (defconst japanese-symbol-table
-  '((?\\e$B!!\e(B ?\ ) (?\e$B!"\e(B ?, ?\e(I$\e(B) (?\e$B!#\e(B ?. ?\e(I!\e(B) (?\e$B!$\e(B ?, ?\e(I$\e(B) (?\e$B!%\e(B ?. ?\e(I!\e(B) (?\e$B!&\e(B nil ?\e(I%\e(B)
+  '((?\\e$B!!\e(B ?\ ) (?\e$B!$\e(B ?, ?\e(I$\e(B) (?\e$B!%\e(B ?. ?\e(I!\e(B) (?\e$B!"\e(B ?, ?\e(I$\e(B)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!t\e(B ?#) (?\e$B!u\e(B ?&) (?\e$B!v\e(B ?*)
     (?\e$B!w\e(B ?@))
   "Japanese JISX0208 symbol character table.
@@ -140,7 +130,7 @@ belongs to `japanese-jisx0201-kana'.")
 (defconst japanese-alpha-numeric-table
   '((?\e$B#0\e(B . ?0) (?\e$B#1\e(B . ?1) (?\e$B#2\e(B . ?2) (?\e$B#3\e(B . ?3) (?\e$B#4\e(B . ?4)
     (?\e$B#5\e(B . ?5) (?\e$B#6\e(B . ?6) (?\e$B#7\e(B . ?7) (?\e$B#8\e(B . ?8) (?\e$B#9\e(B . ?9)
-    (?\e$B#A\e(B . ?A) (?\e$B#B\e(B . ?B) (?\e$B#C\e(B . ?C) (?\e$B#D\e(B . ?D) (?\e$B#E\e(B . ?E) 
+    (?\e$B#A\e(B . ?A) (?\e$B#B\e(B . ?B) (?\e$B#C\e(B . ?C) (?\e$B#D\e(B . ?D) (?\e$B#E\e(B . ?E)
     (?\e$B#F\e(B . ?F) (?\e$B#G\e(B . ?G) (?\e$B#H\e(B . ?H) (?\e$B#I\e(B . ?I) (?\e$B#J\e(B . ?J)
     (?\e$B#K\e(B . ?K) (?\e$B#L\e(B . ?L) (?\e$B#M\e(B . ?M) (?\e$B#N\e(B . ?N) (?\e$B#O\e(B . ?O)
     (?\e$B#P\e(B . ?P) (?\e$B#Q\e(B . ?Q) (?\e$B#R\e(B . ?R) (?\e$B#S\e(B . ?S) (?\e$B#T\e(B . ?T)
@@ -207,9 +197,9 @@ The argument object is not altered--the value is a copy.
 Optional argument ASCII-ONLY non-nil means to return only ASCII character."
   (if (stringp obj)
       (japanese-string-conversion obj 'japanese-hankaku-region ascii-only)
-    (or (get-char-code-property obj 'ascii)
-       (and (not ascii-only)
+    (or (and (not ascii-only)
             (get-char-code-property obj 'jisx0201))
+       (get-char-code-property obj 'ascii)
        obj)))
 
 ;;;###autoload
@@ -222,6 +212,12 @@ The argument object is not altered--the value is a copy."
     (or (get-char-code-property obj 'jisx0208)
        obj)))
 
+(defun japanese-replace-region (from to string)
+  "Replace the region specified by FROM and TO to STRING."
+  (goto-char from)
+  (insert string)
+  (delete-char (- to from)))
+
 ;;;###autoload
 (defun japanese-katakana-region (from to &optional hankaku)
   "Convert Japanese `hiragana' chars in the region to `katakana' chars.
@@ -230,29 +226,44 @@ of which charset is `japanese-jisx0201-kana'."
   (interactive "r\nP")
   (save-restriction
     (narrow-to-region from to)
-    (goto-char (point-min))
-    (while (re-search-forward "\\cH\\|\\cK" nil t)
-      (let* ((hira (preceding-char))
-            (kata (japanese-katakana hira hankaku)))
-       (if kata
-           (progn
-             (delete-region (match-beginning 0) (match-end 0))
-             (insert kata)))))))
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "\\cH\\|\\cK" nil t)
+       (let* ((kana (preceding-char))
+              (composition
+               (and (not hankaku)
+                    (get-char-code-property kana 'kana-composition)))
+              next slot)
+         (if (and composition (setq slot (assq (following-char) composition)))
+             (japanese-replace-region (match-beginning 0) (1+ (point))
+                                      (cdr slot))
+           (let ((kata (get-char-code-property
+                        kana (if hankaku 'jisx0201 'katakana))))
+             (if kata
+                 (japanese-replace-region (match-beginning 0) (point)
+                                          kata)))))))))
+
 
 ;;;###autoload
 (defun japanese-hiragana-region (from to)
-  "Convert Japanese `katakana' chars in the region to `hiragana'  chars."
+  "Convert Japanese `katakana' chars in the region to `hiragana' chars."
   (interactive "r")
   (save-restriction
     (narrow-to-region from to)
-    (goto-char (point-min))
-    (while (re-search-forward "\\cK\\|\\ck" nil t)
-      (let* ((kata (preceding-char))
-            (hira (japanese-hiragana kata)))
-       (if hira
-           (progn
-             (delete-region (match-beginning 0) (match-end 0))
-             (insert hira)))))))
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "\\cK\\|\\ck" nil t)
+       (let* ((kata (preceding-char))
+              (composition (get-char-code-property kata 'kana-composition))
+              next slot)
+         (if (and composition (setq slot (assq (following-char) composition)))
+             (japanese-replace-region (match-beginning 0) (1+ (point))
+                                      (get-char-code-property
+                                       (cdr slot) 'hiragana))
+           (let ((hira (get-char-code-property kata 'hiragana)))
+             (if hira
+                 (japanese-replace-region (match-beginning 0) (point)
+                                          hira)))))))))
 
 ;;;###autoload
 (defun japanese-hankaku-region (from to &optional ascii-only)
@@ -263,43 +274,51 @@ Optional argument ASCII-ONLY non-nil means to convert only to ASCII char."
   (interactive "r\nP")
   (save-restriction
     (narrow-to-region from to)
-    (goto-char (point-min))
-    (while (re-search-forward "\\cj" nil t)
-      (let* ((zenkaku (preceding-char))
-            (hankaku (japanese-hankaku zenkaku ascii-only)))
-       (if hankaku
-           (progn
-             (delete-region (match-beginning 0) (match-end 0))
-             (insert hankaku)))))))
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "\\cj" nil t)
+       (let* ((zenkaku (preceding-char))
+              (hankaku (or (and (not ascii-only)
+                                (get-char-code-property zenkaku 'jisx0201))
+                           (get-char-code-property zenkaku 'ascii))))
+         (if hankaku
+             (japanese-replace-region (match-beginning 0) (match-end 0)
+                                      hankaku)))))))
 
 ;;;###autoload
-(defun japanese-zenkaku-region (from to)
+(defun japanese-zenkaku-region (from to &optional katakana-only)
   "Convert hankaku' chars in the region to Japanese `zenkaku' chars.
 `Zenkaku' chars belong to `japanese-jisx0208'
-`Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'."
-  (interactive "r")
+`Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'.
+Optional argument KATAKANA-ONLY non-nil means to convert only KATAKANA char."
+  (interactive "r\nP")
   (save-restriction
     (narrow-to-region from to)
-    (goto-char (point-min))
-    (while (re-search-forward "\\ca\\|\\ck" nil t)
-      (let* ((hankaku (preceding-char))
-            (zenkaku (japanese-zenkaku hankaku)))
-       (if zenkaku
-           (progn
-             (delete-region (match-beginning 0) (match-end 0))
-             (insert zenkaku)))))))
+    (save-excursion
+      (goto-char (point-min))
+      (while (or (and katakana-only
+                     (re-search-forward "\\ck" nil t))
+                (and (not katakana-only)
+                     (re-search-forward "\\ca\\|\\ck" nil t)))
+       (let* ((hankaku (preceding-char))
+              (composition (get-char-code-property hankaku 'kana-composition))
+              next slot)
+         (if (and composition (setq slot (assq (following-char) composition)))
+             (japanese-replace-region (match-beginning 0) (1+ (point))
+                                      (cdr slot))
+           (let ((zenkaku (japanese-zenkaku hankaku)))
+             (if zenkaku
+                 (japanese-replace-region (match-beginning 0) (match-end 0)
+                                          zenkaku)))))))))
 
 ;;;###autoload
 (defun read-hiragana-string (prompt &optional initial-input)
   "Read a Hiragana string from the minibuffer, prompting with string PROMPT.
 If non-nil, second arg INITIAL-INPUT is a string to insert before reading."
-  (read-multilingual-string prompt initial-input
-                           "Japanese" "quail-ja-hiragana"))
+  (read-multilingual-string prompt initial-input "japanese-hiragana"))
 
 ;;
-(provide 'language/japan-util)
+(provide 'japan-util)
 
-;;; Local Variables:
-;;; generated-autoload-file: "../loaddefs.el"
-;;; End:
+;;; arch-tag: b579595c-c9ad-4b57-9314-98cd8b214f89
 ;;; japan-util.el ends here