(show-paren-mode): Use define-minor-mode.
[bpt/emacs.git] / leim / quail / japanese.el
index 13115b7..4b04035 100644 (file)
 (require 'quail)
 (require 'kkc)
 
+(defvar quail-japanese-use-double-n nil
+  "If non-nil, use type \"nn\" to insert \e$B$s\e(B.")
+
 ;; Update Quail translation region while considering Japanese bizarre
 ;; translation rules.
 (defun quail-japanese-update-translation (control-flag)
-  (cond ((eq control-flag t)
-        (insert quail-current-str)
-        (quail-terminate-translation))
-       ((null control-flag)
-        (if (/= (aref quail-current-key 0) ?q)
-            (insert (or quail-current-str quail-current-key))))
-       (t                              ; i.e. (numberp control-flag)
-        (cond ((= (aref quail-current-key 0) ?n)
-               (insert ?\e$B$s\e(B))
-              ((= (aref quail-current-key 0) (aref quail-current-key 1))
-               (insert ?\e$B$C\e(B))
-              (t
-               (insert (aref quail-current-key 0))))
-        (setq unread-command-events
-              (list (aref quail-current-key control-flag)))
-        (quail-terminate-translation))))
+  (if (null control-flag)
+      (setq quail-current-str
+           (if (/= (aref quail-current-key 0) ?q)
+               (or quail-current-str quail-current-key)
+             ""))
+    (if (integerp control-flag)
+       (if (= control-flag 0)
+           (setq quail-current-str (aref quail-current-key 0))
+         (cond ((= (aref quail-current-key 0) ?n)
+                (setq quail-current-str ?\e$B$s\e(B)
+                (if (and quail-japanese-use-double-n
+                         (= (aref quail-current-key 1) ?n))
+                    (setq control-flag t)))
+               ((= (aref quail-current-key 0) (aref quail-current-key 1))
+                (setq quail-current-str ?\e$B$C\e(B))
+               (t
+                (setq quail-current-str (aref quail-current-key 0))))
+         (if (integerp control-flag)
+             (setq unread-command-events
+                   (list (aref quail-current-key control-flag)))))))
+  control-flag)
         
 ;; Flag to control the behavior of `quail-japanese-toggle-kana'.
 (defvar quail-japanese-kana-state nil)
@@ -54,6 +62,7 @@
 ;; Convert Hiragana <-> Katakana in the current translation region.
 (defun quail-japanese-toggle-kana ()
   (interactive)
+  (setq quail-translating nil)
   (let ((start (overlay-start quail-conv-overlay))
        (end (overlay-end quail-conv-overlay)))
     (setq quail-japanese-kana-state
     (if quail-japanese-kana-state
        (japanese-hiragana-region start end)
       (japanese-katakana-region start end))
-    (goto-char (overlay-end quail-conv-overlay))))
+    (setq quail-conversion-str
+         (buffer-substring (overlay-start quail-conv-overlay)
+                           (overlay-end quail-conv-overlay)))))
 
 ;; Convert Hiragana in the current translation region to Kanji by KKC
 ;; (Kana Kanji Converter) utility.
 (defun quail-japanese-kanji-kkc ()
   (interactive)
   (let ((from (overlay-start quail-conv-overlay))
-       (to (overlay-end quail-conv-overlay))
-       newfrom)
+       (to (overlay-end quail-conv-overlay)))
     (quail-delete-overlays)
-    (setq overriding-terminal-local-map nil)
-    (kkc-region from to 'quail-japanese-kkc-mode-exit)))
-
-;; Function to call on exiting KKC mode.  ARG is nil if KKC mode is
-;; exited normally, else ARG is a cons (FROM . TO) where FROM and TO
-;; specify a region not yet processed.
-(defun quail-japanese-kkc-mode-exit (arg)
-  (if arg
-      (progn
-       (setq overriding-terminal-local-map (quail-conversion-keymap))
-       (move-overlay quail-conv-overlay (car arg) (cdr arg)))
-    (run-hooks 'input-method-after-insert-chunk-hook)))
+    (setq quail-current-str nil)
+    (when (= (char-before to) ?n)
+      ;; The last char is `n'.  We had better convert it to `\e$B$s\e(B'
+      ;; before kana-kanji conversion.
+      (goto-char to)
+      (delete-char -1)
+      (insert ?\e$B$s\e(B))
+    (let ((result (kkc-region from to)))
+      (move-overlay quail-conv-overlay from (point))
+      (setq quail-conversion-str (buffer-substring from (point)))
+      (if (= (+ from result) (point))
+         (setq quail-converting nil))
+      (setq quail-translating nil))))
 
 (defun quail-japanese-self-insert-and-switch-to-alpha (key idx)
   (quail-delete-region)
 (put 'quail-japanese-package-saved 'permanent-local t)
 
 (defun quail-japanese-switch-package (key idx)
+  (quail-delete-region)
+  (setq quail-current-str nil
+       quail-converting nil
+       quail-conversion-str "")
   (let ((pkg (cdr (assq (aref key (1- idx)) quail-japanese-switch-table))))
     (if (null pkg)
-       (error "No package to be switched")
-      (setq overriding-terminal-local-map nil)
-      (quail-delete-region)
+       (quail-error "No package to be switched")
       (if (stringp pkg)
          (activate-input-method pkg)
        (if (string= (car pkg) current-input-method)
          (activate-input-method (car pkg))))))
   (throw 'quail-tag nil))
 
+;; \e$B%m!<%^;zF~NO5Z$S2>L>4A;zJQ49$K$h$kF|K\8lF~NO%a%=%C%I\e(B
+;;
+;; \e$B$3$NF~NO%a%=%C%I$G$NF|K\8l$NF~NO$OFs$D$N%9%F!<%8!V%m!<%^;z2>L>JQ49!W\e(B
+;; \e$B$H!V2>L>4A;zJQ49!W$+$i$J$k!#:G=i$O%m!<%^;z2>L>JQ49$N%9%F!<%8$G!"%9\e(B
+;; \e$B%Z!<%9%-!<$r2!$9$3$H$K$h$j!"<!$N%9%F!<%8!V2>L>4A;zJQ49!W$X?J$`!#\e(B
+;;
+;; \e$B!V%m!<%^;z2>L>JQ49!W\e(B
+;;
+;; \e$BJ?2>L>$O>.J8;z%-!<!JNs!K$rBG$D$3$H$K$h$jF~NO!#6gFIE@!"3g8LN`$OBP1~\e(B
+;; \e$B$9$k1Q;z%-!<$rBG$D$3$H$K$h$jF~NO!#$=$NB>$N%7%s%\%k$O\e(B `z' \e$B$KB3$1$F2?\e(B
+;; \e$B$l$+$N%-!<$rBG$D$3$H$K$h$jF~NO!#2<$KA4$F$N2DG=$J%-!<%7!<%1%s%9%j%9\e(B
+;; \e$B%H%"%C%W$5$l$F$$$k!#F~NO$5$l$?J8;z$O2<@~$G<($5$l$k!#\e(B
+;;
+;; \e$B$5$i$K0J2<$N%-!<$GFCJL$J=hM}$r9T$&!#\e(B
+;;
+;; K   \e$BJ?2>L>$rJR2>L>$K!"$"$k$$$OJR2>L>$rJ?2>L>$KJQ49\e(B
+;; qq  \e$B$3$NF~NO%a%=%C%I$H\e(B `japanese-ascii' \e$BF~NO%a%=%C%I$r%H%0%k@ZBX\e(B
+;; qz  `japanese-zenkaku' \e$BF~NO%a%=%C%I$K%7%U%H\e(B
+;;     qh \e$B$HBG$F$P85$KLa$k\e(B
+;; RET \e$B8=:_$NF~NOJ8;zNs$r3NDj\e(B
+;; SPC \e$B2>L>4A;zJQ49$K?J$`\e(B
+;;
+;; `japanese-ascii' \e$BF~NO%a%=%C%I$O\e(B ASCII \e$BJ8;z$rF~NO$9$k$N$K;H$&!#$3$l\e(B
+;; \e$B$OF~NO%a%=%C%I$r%*%U$K$9$k$N$H$[$H$s$IF1$8$G$"$k!#0[$J$k$N$O\e(B qq \e$B$H\e(B
+;; \e$BBG$D$3$H$K$h$j!"\e(B`japanese' \e$BF~NO%a%=%C%I$KLa$l$kE@$G$"$k!#\e(B
+;;
+;; `japanese-zenkaku' \e$BF~NO%a%=%C%I$OA43Q1Q?t;z$rF~NO$9$k$N$K;H$&!#\e(B
+;;
+;; \e$B!V%m!<%^;z2>L>JQ49!W%9%F!<%8$G$N%-!<%7!<%1%s%9$N%j%9%H$O:G8e$KIU$1\e(B
+;; \e$B$F$"$k!#\e(B
+;;
+;; \e$B!V2>L>4A;zJQ49!W\e(B
+;;
+;; \e$B$3$N%9%F!<%8$G$O!"A0%9%F!<%8$GF~NO$5$l$?J8;zNs$r2>L>4A;zJQ49$9$k!#\e(B
+;; \e$BJQ49$5$l$?J8;zNs$O!"CmL\J8@a!JH?E>I=<(!K$H;D$j$NF~NO!J2<@~I=<(!K$K\e(B
+;; \e$BJ,$1$i$l$k!#CmL\J8@a$KBP$7$F$O0J2<$N%3%^%s%I$,;H$($k!#\e(B
+;;
+;; SPC, C-n    kkc-next
+;;     \e$B<!$NJQ498uJd$rI=<(\e(B
+;;     kkc-show-conversion-list-count \e$B0J>eB3$1$FBG$F$P!"JQ498uJd%j%9\e(B
+;;     \e$B%H$r%(%3!<%(%j%"$KI=<(\e(B
+;; C-p         kkc-prev
+;;     \e$BA0$NJQ498uJd$rI=<(\e(B
+;;     kkc-show-conversion-list-count \e$B0J>eB3$1$FBG$F$P!"JQ498uJd%j%9\e(B
+;;     \e$B%H$r%(%3!<%(%j%"$KI=<(\e(B
+;; l           kkc-show-conversion-list-or-next-group
+;;     \e$B:G9b#1#08D$^$G$NJQ498uJd$r%(%3!<%(%j%"$KI=<(!#\e(B
+;;     \e$BB3$1$FBG$?$l$l$P!"<!$N#1#08uJd$rI=<(!#\e(B
+;; L           kkc-show-conversion-list-or-prev-group
+;;     \e$B:G9b#1#08D$^$G$NJQ498uJd$r%(%3!<%(%j%"$KI=<(!#\e(B
+;;     \e$BB3$1$FBG$?$l$l$P!"A0$N#1#08uJd$rI=<(!#\e(B
+;; 0..9                kkc-select-from-list
+;;     \e$BBG$?$l$??t;z$NJQ498uJd$rA*Br\e(B
+;; H           kkc-hiragana
+;;     \e$BCmL\J8@a$rJ?2>L>$KJQ49\e(B
+;; K           kkc-katakana
+;;     \e$BCmL\J8@a$rJR2>L>$KJQ49\e(B
+;; C-o         kkc-longer
+;;     \e$BCmL\J8@a$r8e$m$K0lJ8;z?-$P$9\e(B
+;; C-i         kkc-shorter
+;;     \e$BCmL\J8@a$r8e$m$+$i0lJ8;z=L$a$k\e(B
+;; C-f         kkc-next-phrase
+;;     \e$BCmL\J8@a$r3NDj$5$;$k!#$b$7;D$j$NF~NO$,$^$@$"$l$P!":G=i$NJ8@a$r\e(B
+;;     \e$BA*Br$7!"$=$l$rCmL\J8@a$H$7!"$=$N:G=i$NJQ498uJd$rI=<($9$k!#\e(B
+;; DEL, C-c    kkc-cancel
+;;     \e$B2>L>4A;zJQ49$r%-%c%s%;%k$7!"%m!<%^;z2>L>JQ49$N%9%F!<%8$KLa$k!#\e(B
+;; return              kkc-terminate
+;;     \e$BA4J8@a$r3NDj$5$;$k!#\e(B
+;; C-SPC, C-@  kkc-first-char-only
+;;     \e$B:G=i$NJ8;z$r3NDj$5$;!";D$j$O:o=|$9$k!#\e(B
+;; C-h         kkc-help
+;;     \e$B$3$l$i$N%-!<%P%$%s%I$N%j%9%H$rI=<($9$k!#$"\e(B
+
 (quail-define-package
  "japanese" "Japanese" "A\e$B$"\e(B"
  nil
- "Romaji -> Hiragana -> Kanji&Kana
----- Special key bindings ----
-qq:    toggle between input methods `japanese' and `japanese-ascii'
-qz:    use `japanese-zenkaku' package, \"qh\" puts you back to `japanese'
-K:     toggle converting region between Katakana and Hiragana
-SPC:   convert to Kanji&Kana
-z:     insert one Japanese symbol according to a key which follows
+ "Japanese input method by Roman transliteration and Kana-Kanji conversion.
+
+When you use this input method, text entry proceeds in two stages:
+Roman-Kana transliteration and Kana-Kanji conversion.  When you start
+to enter text, you are in the first stage, Roman-Kana transliteration.
+Type SPC to proceed to the next stage, Kana-Kanji conversion.
+
+:: Roman-Kana transliteration ::
+
+You can input any Hiragana character as a sequence of lower-case
+letters, Japanese punctuation characters by typing punctuation keys,
+Japanese symbols by typing `z' followed by another key.  See below for
+a list of all available sequences.  The characters you input are
+underlined.
+
+In addition, the following keys provide special effects:
+
+K      Change Hiragana to Katakana or Katakana to Hiragana.
+qq     Toggle between this input method and the input method `japanese-ascii'.
+qz     Shift to the input method `japanese-zenkaku'.
+       Typing \"qh\" will put you back to this input method.
+RET    Accept the current character sequence.
+SPC    Proceed to the next stage, Kana-Kanji conversion.
+
+The input method `japanese-ascii' is used to enter ASCII characters.
+This is almost the same as turning off the input method.  The only
+difference is that typing `qq' will put you back into the Japanese
+input method.
+
+The input method `japanese-zenkaku' is used to enter full width
+JISX0208 characters corresponding to typed ASCII characters.
+
+List of the all key sequences for Roman-Kana transliteration is shown
+at the tail.
+
+:: Kana-Kanji conversion ::
+
+You can convert the current Japanese characters (underlined) to
+Kana-Kanji mixed text.  In this stage, the converted text is divided
+into two parts, the current phrase (highlighted) and the remaining
+input (underlined).  The following commands can be used on the
+current phrase.
+
+SPC, C-n       kkc-next
+       Show the next candidate for the current phrase.
+       If successively typed `kkc-show-conversion-list-count' times,
+       conversion candidates are shown in the echo area.
+C-p            kkc-prev
+       Show the previous candidate for the current phrase.
+       If successively typed `kkc-show-conversion-list-count' times,
+       conversion candidates are shown in the echo area.
+l              kkc-show-conversion-list-or-next-group
+       Show at most 10 candidates for the current phrase in echo area.
+       If typed repeatedly, show the next 10 candidates.
+L              kkc-show-conversion-list-or-prev-group
+       Show at most 10 candidates for the current phrase in echo area.
+       If typed repeatedly, show the previous 10 candidates.
+0..9           kkc-select-from-list
+       Select a candidate corresponding to the typed number.
+H              kkc-hiragana
+       Convert the current phrase to Hiragana
+K              kkc-katakana
+       Convert the current phrase to Katakana
+C-o            kkc-longer
+       Extend the current phrase; pull in the first character of
+       the remaining input.
+C-i            kkc-shorter
+       Contract the current phrase; drop its last character
+       back into the remaining input.
+C-f            kkc-next-phrase
+       Accept the current phrase.  If there remains input, select
+       the first phrase as the current one, and show the first
+       candidate for the conversion.
+DEL, C-c       kkc-cancel
+       Cancel the conversion, shift back to the Roman-Kana
+       transliteration.
+return         kkc-terminate
+       Accept the whole conversion.
+C-SPC, C-@     kkc-first-char-only
+       Accept the first character of the current conversion,
+       delete the remaining input.
+C-h            kkc-help
+       List these key bindings.
 "
  nil t t nil nil nil nil nil
  'quail-japanese-update-translation
@@ -234,7 +396,7 @@ z:  insert one Japanese symbol according to a key which follows
 ("z;" "\e$B!+\e(B") ("z:" "\e$B!,\e(B")
 ("z\'" "\e$B!F\e(B") ("z\"" "\e$B!H\e(B")
 
-("zx" ":-") ("zX" ":-)")
+("zx" [":-"]) ("zX" [":-)"])
 ("zc" "\e$B!;\e(B") ("zC" "\e$B!n\e(B")
 ("zv" "\e$B"(\e(B") ("zV" "\e$B!`\e(B")
 ("zb" "\e$B!k\e(B") ("zB" "\e$B"+\e(B")
@@ -256,8 +418,8 @@ z:  insert one Japanese symbol according to a key which follows
 (quail-define-package
  "japanese-ascii" "Japanese" "Aa"
  nil
- "Temporary ASCII input mode while using Quail package `japanese'
-Type \"qq\" to go back to previous package."
+ "Temporary ASCII input mode used within the input method `japanese'.
+Type \"qq\" to go back to previous input method."
  nil t t)
 
 (quail-define-rules ("qq" quail-japanese-switch-package))
@@ -265,10 +427,11 @@ Type \"qq\" to go back to previous package."
 (quail-define-package
  "japanese-zenkaku" "Japanese" "\e$B#A\e(B"
  nil
- "Japanese zenkaku alpha numeric character input method
+ "Japanese zenkaku alpha numeric character input method.
 ---- Special key bindings ----
-qq:    toggle between `japanese-zenkaku' and `japanese-ascii'
-qh:    use `japanese' package, \"qz\" puts you back to `japanese-zenkaku'
+qq:    toggle between this input method and the input method `japanese-ascii'.
+qh:    shift to the input method `japanese',
+       typing \"qz\" puts you back to this input method.
 "
  nil t t)
 
@@ -304,32 +467,21 @@ qh:       use `japanese' package, \"qz\" puts you back to `japanese-zenkaku'
 )
 
 (defun quail-japanese-hankaku-update-translation (control-flag)
-  (cond ((eq control-flag t)
-        (insert (japanese-hankaku quail-current-str))
-        (quail-terminate-translation))
-       ((null control-flag)
-        (insert (if quail-current-str
-                    (japanese-hankaku quail-current-str)
-                  quail-current-key)))
-       (t                              ; i.e. (numberp control-flag)
-        (cond ((= (aref quail-current-key 0) ?n)
-               (insert ?\e(I]\e(B))
-              ((= (aref quail-current-key 0) (aref quail-current-key 1))
-               (insert ?\e(I/\e(B))
-              (t
-               (insert (aref quail-current-key 0))))
-        (setq unread-command-events
-              (list (aref quail-current-key control-flag)))
-        (quail-terminate-translation))))
-
+  (setq control-flag
+       (quail-japanese-update-translation control-flag))
+  (if (or (and (stringp quail-current-str)
+              (> (length quail-current-str) 0))
+         (integerp quail-current-str))
+      (setq quail-current-str (japanese-hankaku quail-current-str)))
+  control-flag)
 
 (quail-define-package
  "japanese-hankaku-kana"
  "Japanese" "\e(I1\e(B"
  nil
- "Japanese hankaku katakana input method by Roman transliteration
+ "Japanese hankaku katakana input method by Roman transliteration.
 ---- Special key bindings ----
-qq:    toggle between `japanese-hankaku-kana' and `japanese-ascii'
+qq:    toggle between this input method and the input method `japanese-ascii'.
 "
  nil t t nil nil nil nil nil
  'quail-japanese-hankaku-update-translation)
@@ -341,7 +493,7 @@ qq: toggle between `japanese-hankaku-kana' and `japanese-ascii'
 (quail-define-package
  "japanese-hiragana" "Japanese" "\e$B$"\e(B"
  nil
- "Japanese hiragana input method by Roman transliteration"
+ "Japanese hiragana input method by Roman transliteration."
  nil t t nil nil nil nil nil
  'quail-japanese-update-translation)
 
@@ -351,28 +503,18 @@ qq:       toggle between `japanese-hankaku-kana' and `japanese-ascii'
 
 ;; Update Quail translation region while converting Hiragana to Katakana.
 (defun quail-japanese-katakana-update-translation (control-flag)
-  (cond ((eq control-flag t)
-        (insert (japanese-katakana quail-current-str))
-        (quail-terminate-translation))
-       ((null control-flag)
-        (insert (if quail-current-str
-                    (japanese-katakana quail-current-str)
-                  quail-current-key)))
-       (t                              ; i.e. (numberp control-flag)
-        (cond ((= (aref quail-current-key 0) ?n)
-               (insert ?\e$B%s\e(B))
-              ((= (aref quail-current-key 0) (aref quail-current-key 1))
-               (insert ?\e$B%C\e(B))
-              (t
-               (insert (aref quail-current-key 0))))
-        (setq unread-command-events
-              (list (aref quail-current-key control-flag)))
-        (quail-terminate-translation))))
+  (setq control-flag
+       (quail-japanese-update-translation control-flag))
+  (if (or (and (stringp quail-current-str)
+              (> (length quail-current-str) 0))
+         (integerp quail-current-str))
+      (setq quail-current-str (japanese-katakana quail-current-str)))
+  control-flag)
 
 (quail-define-package 
  "japanese-katakana" "Japanese" "\e$B%"\e(B"
  nil
- "Japanese katakana input method by Roman transliteration"
+ "Japanese katakana input method by Roman transliteration."
  nil t t nil nil nil nil nil
  'quail-japanese-katakana-update-translation)