diff -r 08c8dbbb056a configure
--- a/configure	Thu Jun 14 18:19:18 2012 +0900
+++ b/configure	Thu Jun 14 21:59:32 2012 +0900
@@ -1111,6 +1111,10 @@
 canonical
 configuration
 version
+CANNA_OBJ
+LIBS_MULE
+LD_SWITCH_CANNA
+C_SWITCH_CANNA
 KRB4LIB
 DESLIB
 KRB5LIB
@@ -1302,6 +1306,9 @@
 with_mail_unlink
 with_mailhost
 with_sound
+with_canna
+with_canna_includes
+with_canna_libraries
 with_sync_input
 with_x_toolkit
 with_wide_int
@@ -2017,6 +2024,9 @@
   --with-mailhost=HOSTNAME
                           string giving default POP mail host
   --without-sound         don't compile with sound support
+  --with-canna            support CANNA
+  --with-canna-includes=DIR search for CANNA header files in DIR
+  --with-canna-libraries=DIR search for CANNA libraries in DIR
   --without-sync-input    process async input synchronously
   --with-x-toolkit=KIT    use an X toolkit (KIT one of: yes or gtk, gtk3,
                           lucid or athena, motif, no)
@@ -3864,6 +3874,25 @@
 
 
 
+# Check whether --with-canna was given.
+if test "${with_canna+set}" = set; then :
+  withval=$with_canna;
+fi
+
+
+# Check whether --with-canna-includes was given.
+if test "${with_canna_includes+set}" = set; then :
+  withval=$with_canna_includes;
+fi
+
+
+# Check whether --with-canna-libraries was given.
+if test "${with_canna_libraries+set}" = set; then :
+  withval=$with_canna_libraries;
+fi
+
+
+
 # Check whether --with-sync-input was given.
 if test "${with_sync_input+set}" = set; then :
   withval=$with_sync_input;
@@ -15732,6 +15761,30 @@
 fi
 
 
+case "${with_canna}" in
+  y | yes )
+    $as_echo "#define CANNA 1" >>confdefs.h
+
+    test -n "${with_canna_includes}" && C_SWITCH_CANNA="-I${with_canna_includes}"
+    if test -n "${with_canna_libraries}" ; then
+      if test -d ${with_canna_libraries} ; then
+        LD_SWITCH_CANNA="-L${with_canna_libraries}"
+        LD_SWITCH_CANNA_AUX="-R${with_canna_libraries}"
+        LIBS_MULE="${LIBS_MULE} -lcanna"
+	CANNA_OBJ=canna.o
+      else
+        LIBS_MULE="${LIBS_MULE} ${with_canna_libraries}"
+      fi
+    else
+      LIBS_MULE="${LIBS_MULE} -lcanna"
+    fi
+    ;;
+esac
+
+
+
+
+
 # Set up the CFLAGS for real compilation, so we can substitute it.
 CFLAGS="$REAL_CFLAGS"
 CPPFLAGS="$REAL_CPPFLAGS"
@@ -15818,6 +15871,32 @@
 _ACEOF
 
 
+cat >>confdefs.h <<_ACEOF
+#define LIBS_MULE ${LIBS_MULE}
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define C_SWITCH_CANNA ${C_SWITCH_CANNA}
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define LD_SWITCH_CANNA ${LD_SWITCH_CANNA}
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define LD_SWITCH_CANNA_AUX ${LD_SWITCH_CANNA_AUX}
+_ACEOF
+
+
+
+
+
+
+
+
+
+
+
 XMENU_OBJ=
 XOBJ=
 FONT_OBJ=
diff -r 08c8dbbb056a configure.in
--- a/configure.in	Thu Jun 14 18:19:18 2012 +0900
+++ b/configure.in	Thu Jun 14 21:59:32 2012 +0900
@@ -117,6 +117,13 @@
 
 OPTION_DEFAULT_ON([sound],[don't compile with sound support])
 
+AC_ARG_WITH(canna,
+[  --with-canna            support CANNA])
+AC_ARG_WITH(canna-includes,
+[  --with-canna-includes=DIR search for CANNA header files in DIR])
+AC_ARG_WITH(canna-libraries,
+[  --with-canna-libraries=DIR search for CANNA libraries in DIR])
+
 OPTION_DEFAULT_ON([sync-input],[process async input synchronously])
 if test "$with_sync_input" = yes; then
    AC_DEFINE(SYNC_INPUT, 1, [Process async input synchronously.])
@@ -3180,6 +3187,29 @@
 dnl    AC_DEFINE(HAVE_TCATTR, 1, [Define to 1 if you have tcgetattr and tcsetattr.])
 dnl fi
 
+case "${with_canna}" in
+  y | yes )
+    AC_DEFINE(CANNA)
+    test -n "${with_canna_includes}" && C_SWITCH_CANNA="-I${with_canna_includes}"
+    if test -n "${with_canna_libraries}" ; then
+      if test -d ${with_canna_libraries} ; then
+        LD_SWITCH_CANNA="-L${with_canna_libraries}"
+        LD_SWITCH_CANNA_AUX="-R${with_canna_libraries}"
+        LIBS_MULE="${LIBS_MULE} -lcanna"
+	CANNA_OBJ=canna.o
+      else
+        LIBS_MULE="${LIBS_MULE} ${with_canna_libraries}"
+      fi
+    else
+      LIBS_MULE="${LIBS_MULE} -lcanna"
+    fi
+    ;;
+esac
+AC_SUBST(C_SWITCH_CANNA)
+AC_SUBST(LD_SWITCH_CANNA)
+AC_SUBST(LIBS_MULE)
+AC_SUBST(CANNA_OBJ)
+
 # Set up the CFLAGS for real compilation, so we can substitute it.
 CFLAGS="$REAL_CFLAGS"
 CPPFLAGS="$REAL_CPPFLAGS"
@@ -3254,6 +3284,21 @@
 AC_DEFINE_UNQUOTED(config_opsysfile, "${opsysfile}",
 		   [Define to the used os dependent file.])
 
+AC_DEFINE_UNQUOTED(LIBS_MULE, ${LIBS_MULE})
+AC_DEFINE_UNQUOTED(C_SWITCH_CANNA, ${C_SWITCH_CANNA})
+AC_DEFINE_UNQUOTED(LD_SWITCH_CANNA, ${LD_SWITCH_CANNA})
+AC_DEFINE_UNQUOTED(LD_SWITCH_CANNA_AUX, ${LD_SWITCH_CANNA_AUX})
+
+AH_TEMPLATE(LIBS_MULE, [special library for Mule])
+
+AH_TEMPLATE(CANNA, [flag whether to use Canna])
+AH_TEMPLATE(CANNA_EMACS_23, [flag whether to use Canna on Mule])
+AH_TEMPLATE(CANNA2, [flag whether to use Canna2])
+AH_TEMPLATE(C_SWITCH_CANNA, [compile switch for Canna])
+AH_TEMPLATE(LD_SWITCH_CANNA, [link switch for Canna])
+AH_TEMPLATE(LD_SWITCH_CANNA_AUX,
+	    [link switch for Canna if -R option is needed])
+
 XMENU_OBJ=
 XOBJ=
 FONT_OBJ=
@@ -3704,6 +3749,14 @@
 #  endif
 #endif
 
+#ifdef CANNA
+#  define CANNA2
+#  define CANNA_EMACS_23
+#  define CANNA_PURESIZE 18000
+#else  /* not CANNA */
+#  define CANNA_PURESIZE 0
+#endif /* not CANNA */
+
 #endif /* EMACS_CONFIG_H */
 
 /*
diff -r 08c8dbbb056a lisp/canna.el
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/canna.el	Thu Jun 14 21:59:32 2012 +0900
@@ -0,0 +1,1526 @@
+;; This file is a part of Canna on Nemacs/Mule.
+
+;; Canna on Nemacs/Mule is distributed in the forms of
+;; patches to Nemacs under the terms of the GNU EMACS
+;; GENERAL PUBLIC LICENSE which is distributed along with
+;; GNU Emacs by the Free Software Foundation.
+
+;; Canna on Nemacs/Mule is distributed in the hope that it will
+;; be useful, but WITHOUT ANY WARRANTY; without even the
+;; implied warranty of MERCHANTABILITY or FITNESS FOR A
+;; PARTICULAR PURPOSE.  See the GNU EMACS GENERAL PUBLIC
+;; LICENSE for more details.
+
+;; You should have received a copy of the GNU EMACS GENERAL
+;; PUBLIC LICENSE along with Nemacs/Mule; see the file
+;; COPYING.  If not, write to the Free Software Foundation,
+;; 675 Mass Ave, Cambridge, MA 02139, USA.
+
+;; Egg offered some influences to the implementation of
+;; Canna on Nemacs/Mule, and this file contains a few part
+;; of Egg which is written by S.Tomura, Electrotechnical
+;; Lab.  (tomura@etl.go.jp)
+
+;; Written by Akira Kon, NEC Corporation.
+;; E-Mail:  kon@d1.bs2.mt.nec.co.jp.
+
+;; -*-mode: emacs-lisp-*-
+
+(defconst canna-rcs-version "Canna/mule 2.x-5.x, based on Canna 2.2/3.2/3.5. : canna.el,v x.xx 1998/9/28 00:00:00")
+
+(if (featurep 'xemacs) (require 'poem))
+
+(eval-when-compile
+  (if (featurep 'xemacs)
+      nil
+    (defalias 'event-key 'ignore)
+    (defalias 'get-frame-background-mode 'ignore)
+    (defalias 'char-or-char-int-p 'ignore)))
+
+(cond
+ ((fboundp 'dynamic-link)
+  (defvar canna-dl-module
+    (expand-file-name "canna.so" exec-directory))
+
+  (defvar canna-dl-handle
+    (or (boundp 'CANNA)
+	(eval '(dynamic-link canna-dl-module))))
+
+  (and canna-dl-handle
+       (eval '(dynamic-call "emacs_canna_init" canna-dl-handle)))))
+
+(defvar self-insert-after-hook nil)
+(defvar minibuffer-window-selected nil)
+
+
+(defun canna-version ()
+  (interactive)
+  (message (concat (substring canna-rcs-version 0 72) " ...")))
+
+;;; $B$+$s$J$NJQ?t(B
+
+(defvar canna-save-undo-text-predicate nil)
+(defvar canna-undo-hook nil)
+
+(defvar canna-do-keybind-for-functionkeys t)
+(defvar canna-use-space-key-as-henkan-region t)
+
+(defvar canna-server nil)
+(defvar canna-file   nil)
+
+(defvar canna-underline nil)
+(defvar canna-with-fences (not canna-underline))
+
+(defvar canna-initialize-minibuffer-state-when-exit nil
+  "*Non-nil $B$N$H$-$O(B, $B%_%K%P%C%U%!$rH4$1$k;~F|K\8l>uBV$r=i4|2=$9$k(B.")
+
+(defvar canna-inhibit-hankakukana nil
+  "*Non-nil $B$N;~!";z<oJQ49$GH>3Q$+$J$KJQ49$7$J$$(B")
+
+;;;
+;;; Canna local variables
+;;;
+
+(defvar canna:*japanese-mode* nil "T if canna mode is ``japanese''.")
+(make-variable-buffer-local 'canna:*japanese-mode*)
+(set-default 'canna:*japanese-mode* nil)
+(put 'canna:*japanese-mode* 'permanent-local t)
+
+(defvar canna:*japanese-mode-in-minibuffer* nil
+  "T if canna mode is ``japanese'' in minibuffer.")
+
+(defvar canna:*exit-japanese-mode* nil)
+(defvar canna:*fence-mode* nil)
+(make-variable-buffer-local 'canna:*fence-mode*)
+(setq-default canna:*fence-mode* nil)
+(put 'canna:*fence-mode* 'permanent-local t)
+(defvar canna:*select-mode* nil)
+
+(defvar canna:*use-region-as-henkan-region* nil)
+(make-variable-buffer-local 'canna:*use-region-as-henkan-region*)
+(setq-default canna:*use-region-as-henkan-region* nil)
+(put 'canna:*use-region-as-henkan-region* 'permanent-local t)
+
+;;;
+;;; global variables
+;;;
+
+(defvar canna:*region-start* (make-marker))
+(defvar canna:*region-end*   (make-marker))
+(defvar canna:*spos-undo-text* (make-marker))
+(defvar canna:*epos-undo-text* (make-marker))
+(defvar canna:*undo-text-yomi* nil)
+(defvar canna:*last-kouho* 0)
+(defvar canna:*initialized* nil)
+(defvar canna:*previous-window* nil)
+(defvar canna:*cursor-was-in-minibuffer* nil)
+(defvar canna:*menu-buffer* " *menu*")
+(defvar canna:*saved-minibuffer*)
+
+;;;
+;;; $B%b!<%I%i%$%s$N=$@0(B
+;;;
+
+(defvar canna:*kanji-mode-string* "[ $B$"(B ]")
+(defvar canna:*alpha-mode-string* "$B$+$s$J(B")
+(defvar canna:*saved-mode-string* "[ $B$"(B ]")
+
+(defvar mode-line-canna-mode canna:*alpha-mode-string*)
+(defvar mode-line-canna-mode-in-minibuffer canna:*alpha-mode-string*)
+
+(defvar display-minibuffer-mode-in-minibuffer t)
+
+(make-variable-buffer-local 'mode-line-canna-mode)
+(put 'mode-line-canna-mode 'permanent-local t)
+
+(defvar canna:minibuffer-preprompt-overlay nil
+  "Internal variable used to keep an overlay to show a preprompt string
+in the minibuffer.")
+
+(defun canna:select-window-hook (old new)
+  (if (and (eq old (minibuffer-window))
+	   (not (eq new (minibuffer-window))))
+      (save-excursion
+	(set-buffer (window-buffer (minibuffer-window)))
+	(if canna:minibuffer-preprompt-overlay
+	    (delete-overlay canna:minibuffer-preprompt-overlay))
+	(setq canna:minibuffer-preprompt-overlay nil
+	      ;; minibuffer$B$N%G%U%)%k%H$O%"%k%U%!%Y%C%H%b!<%I(B
+	      mode-line-canna-mode-in-minibuffer canna:*alpha-mode-string*
+	      canna:*japanese-mode-in-minibuffer* nil)))
+  (if (eq new (minibuffer-window))
+      (setq minibuffer-window-selected t)
+    (setq minibuffer-window-selected nil)))
+
+(defun canna:minibuffer-setup-hook ()
+  (canna:select-window-hook nil (minibuffer-window)))
+
+(add-hook 'minibuffer-setup-hook 'canna:minibuffer-setup-hook)
+
+(defun canna:minibuffer-exit-hook ()
+  (canna:select-window-hook (minibuffer-window) nil))
+
+(add-hook 'minibuffer-exit-hook 'canna:minibuffer-exit-hook)
+
+(defun mode-line-canna-mode-update (str)
+  (if (window-minibuffer-p (selected-window))
+      (if display-minibuffer-mode-in-minibuffer
+	  (progn
+	    (or canna:minibuffer-preprompt-overlay
+		(setq canna:minibuffer-preprompt-overlay
+		      (make-overlay (point-min) (point-min))))
+	    (overlay-put canna:minibuffer-preprompt-overlay
+			 'before-string str))
+	;else
+	(setq mode-line-canna-mode-in-minibuffer str))
+    (setq mode-line-canna-mode str) )
+  (set-buffer-modified-p (buffer-modified-p)) )
+
+;; memq $B$r6/D4$9$k$J$i!"0J2<$@$,!"(B
+;(defun canna:memq-recursive (a l)
+;  (or (eq a l)
+;      (and (consp l)
+;	   (or (canna:memq-recursive a (car l))
+;	       (canna:memq-recursive a (cdr l)) ))))
+;; $B<!$NDj5A$r;H$*$&(B...
+(defun canna:memq-recursive (a l)
+  (if (atom l) (eq a l)
+    (or (canna:memq-recursive a (car l))
+	(canna:memq-recursive a (cdr l)) )))
+
+(defun canna:create-mode-line ()
+  "Add Canna status string into mode-line."
+  (cond ((featurep 'xemacs)
+	 (or (canna:memq-recursive 'mode-line-canna-mode
+				   (default-value 'default-modeline-format))
+	     (set-default 'default-modeline-format
+			  (append '("" mode-line-canna-mode)
+				  (symbol-value 'default-modeline-format))))
+	 (mapcar (function
+		  (lambda (buffer)
+		    (save-excursion
+		      (set-buffer buffer)
+		      (or (canna:memq-recursive 'mode-line-canna-mode
+						(symbol-value
+						 'modeline-format))
+			  (set 'modeline-format
+			       (append '("" mode-line-canna-mode)
+				       (symbol-value 'modeline-format)))))))
+		 (buffer-list)))
+	(t
+	 (or (canna:memq-recursive 'mode-line-canna-mode mode-line-format)
+	     (setq-default
+	      mode-line-format
+	      (append (list (list 'minibuffer-window-selected
+				  (list 'display-minibuffer-mode-in-minibuffer
+					"-" "m") "-")
+			    (list 'minibuffer-window-selected
+				  (list 'display-minibuffer-mode-in-minibuffer
+					'mode-line-canna-mode
+					'mode-line-canna-mode-in-minibuffer)
+				  'mode-line-canna-mode))
+		      ;; Remove an element that egg.el added.
+		      (let ((forms mode-line-format)
+			    elem)
+			(while forms
+			  (setq elem (pop forms))
+			  (when (canna:memq-recursive 'mode-line-egg-mode elem)
+			    (setq mode-line-format (delq elem mode-line-format)
+				  forms nil)))
+			mode-line-format))))))
+  (mode-line-canna-mode-update mode-line-canna-mode))
+
+(defun canna:mode-line-display ()
+  (mode-line-canna-mode-update mode-line-canna-mode))
+
+;;;
+;;; $B?'$N@_Dj(B
+;;;
+(defvar canna-use-color nil
+  "*Non-nil $B$G%+%i!<%G%#%9%W%l%$$G?'$rIU$1$k(B.
+t $B$N;~$O%G%U%)%k%H$N?'$r;HMQ$9$k!#(B
+$B?'$r;XDj$7$?$$;~$O(B, \"$BFI$_$N?'(B\", \"$BJQ49BP>]$N?'(B\", \"$BA*BrBP>]$N?'(B\" $B$N(B
+$B%j%9%H$r@_Dj$9$k(B")
+(defvar canna:color-p nil "$B?'$,;H$($k$+(B")
+(defvar canna:attr-mode nil "$B8=:_$N%G%#%9%W%l%$%b!<%I(B")
+(defvar canna:attr-yomi nil "$BFI$_$N?'B0@-(B")
+(defvar canna:attr-taishou nil "$BJQ49BP>]ItJ,$N?'B0@-(B")
+(defvar canna:attr-select nil
+  "$B%_%K%P%C%U%!J,N%;~$N%a%K%e!<$NA*BrBP>]HV9f$N?'B0@-(B")
+(defvar canna-background-mode nil
+  "$B$+$s$JJQ49;~$NG[?'%;%C%H$r9uCOGX7JMQ$K$9$k>l9g$O(B 'dark $B$K$9$k(B")
+(defvar canna:attribute-alist		;colored by tagu@ae.keio.ac.jp
+  '((yomi (normal . "red")
+	  (reverse . "moccasin")
+	  (nw . "blue/white")
+	  (nw-rv . "yellow/black"))
+    (taishou (normal . "blue/lavender")
+	     (reverse . "yellow/cadet blue")
+	     (nw . "black/yellow")
+	     (nw-rv . "yellow/blue"))
+    (select (normal . "DarkOliveGreen1/cadet blue")
+	    (reverse . "light sea green/burlywood1")
+	    (nw . "black/cyan")
+	    (nw-rv . "black/cyan")))
+  "$B$+$s$JJQ49;~$NG[?'$N(Balist
+$B6/@)E*$K0E$$GX7J$NG[?'$rA*$S$?$$>l9g$OJQ?t(B canna-background-mode $B$K(B
+$B%7%s%\%k(B 'dark $B$r%;%C%H$7$F$*$/!#(B")
+
+(make-variable-buffer-local (defvar canna:*yomi-overlay* nil))
+(make-variable-buffer-local (defvar canna:*henkan-overlay* nil))
+(make-variable-buffer-local (defvar canna:*select-overlay* nil))
+
+;;;
+;;; $B%-!<%^%C%W%F!<%V%k(B
+;;;
+
+;; $B%U%'%s%9%b!<%I$G$N%m!<%+%k%^%C%W(B
+(defvar canna-mode-map (make-sparse-keymap))
+
+(let ((ch 0))
+  (while (<= ch 127)
+    (define-key canna-mode-map (make-string 1 ch) 'canna-functional-insert-command)
+    (setq ch (1+ ch))))
+
+(cond ((featurep 'xemacs)
+       (define-key canna-mode-map [up]		    "\C-p")
+       (define-key canna-mode-map [(shift up)]	    "\C-p")
+       (define-key canna-mode-map [(control up)]    "\C-p")
+       (define-key canna-mode-map [down]	    "\C-n")
+       (define-key canna-mode-map [(shift down)]    "\C-n")
+       (define-key canna-mode-map [(control down)]  "\C-n")
+       (define-key canna-mode-map [right]	    "\C-f")
+       (define-key canna-mode-map [(shift right)]   "\C-f")
+       (define-key canna-mode-map [(control right)] "\C-f")
+       (define-key canna-mode-map [left]	    "\C-b")
+       (define-key canna-mode-map [(shift left)]    "\C-b")
+       (define-key canna-mode-map [(control left)]  "\C-b")
+       (define-key canna-mode-map [kanji]	    " ")
+       (define-key canna-mode-map [(control space)] [(control @)])
+       (define-key canna-mode-map [backspace]	    "\C-h")
+       (define-key canna-mode-map [delete]	    "\C-h")
+       )
+      (t
+       (define-key canna-mode-map [?\C- ]   [?\C-@])
+       (define-key canna-mode-map [backspace] [?\C-h])
+; delete $B$O(B function-key-map $B$G(B \C-? $B$K(B map $B$5$l$k!#(B
+; \C-? $B$r(B \C-h $B$HF1$8$K07$&$+$I$&$+$O!"(B.canna $B$G;XDj$9$k$Y$-!#(B
+; $B!J;2>H(B: [Canna 1885]$B!K(B 2001,4/27 ikumi
+;        (define-key canna-mode-map [delete]  [?\C-h])
+;  $B"*(B $B$,!"(B[Canna 5570] $B$G$O(B
+;; $B$_$J$5$s$,JXMx$J$h$&$K@_Dj$7$F$$$?$@$1$l$PNI$$$H;W$$$^$9!#(B
+
+;; $B$J$*!"<+J,$O(B DEL $B$G(B backspace $BF0:n$,$5$l$k$h$&$K$O$7$F$$$J$+$C(B
+;; $B$?$N$H!"(BTTY $B$G$O(B DEL $B$,JL$N0UL#$H$J$C$F$$$k$?$aFC$KF0:n$r5,(B
+;; $BDj$7$F$$$J$+$C$?$b$N$H;W$$$^$9!#(B
+
+;; Emacs $B>e$G$O(B Emacs $B$KJXMx$J$h$&$K$7$F$$$?$@$1$l$P$H;W$$$^$9!#(B
+;     $B$H$$$&$3$H$K$J$C$F$$$k$J$"!D!#(B
+       ))
+
+(or (assq 'canna:*fence-mode* minor-mode-map-alist)
+    (setq minor-mode-map-alist
+	  (cons (cons 'canna:*fence-mode* canna-mode-map)
+		minor-mode-map-alist)))
+
+;; $B%_%K%P%C%U%!$K2?$+$rI=<($7$F$$$k;~$N%m!<%+%k%^%C%W(B
+(defvar canna-minibuffer-mode-map (make-sparse-keymap))
+
+(let ((ch 0))
+  (while (<= ch 127)
+    (define-key canna-minibuffer-mode-map (make-string 1 ch) 'canna-minibuffer-insert-command)
+    (setq ch (1+ ch))))
+
+(cond ((featurep 'xemacs)
+       (define-key canna-minibuffer-mode-map [up]	       "\C-p")
+       (define-key canna-minibuffer-mode-map [(shift up)]      "\C-p")
+       (define-key canna-minibuffer-mode-map [(control up)]    "\C-p")
+       (define-key canna-minibuffer-mode-map [down]	       "\C-n")
+       (define-key canna-minibuffer-mode-map [(shift down)]    "\C-n")
+       (define-key canna-minibuffer-mode-map [(control down)]  "\C-n")
+       (define-key canna-minibuffer-mode-map [right]	       "\C-f")
+       (define-key canna-minibuffer-mode-map [(shift right)]   "\C-f")
+       (define-key canna-minibuffer-mode-map [(control right)] "\C-f")
+       (define-key canna-minibuffer-mode-map [left]	       "\C-b")
+       (define-key canna-minibuffer-mode-map [(shift left)]    "\C-b")
+       (define-key canna-minibuffer-mode-map [(control left)]  "\C-b")
+       (define-key canna-minibuffer-mode-map [kanji]	       " ")
+       (define-key canna-minibuffer-mode-map [(control space)] [(control @)])
+       (define-key canna-minibuffer-mode-map [backspace]       "\C-h")
+       (define-key canna-minibuffer-mode-map [delete]          "\C-h")
+       )
+      (t
+       (define-key canna-minibuffer-mode-map [?\C- ]   [?\C-@])
+       (define-key canna-minibuffer-mode-map [backspace] [?\C-h])
+; delete $B$O(B function-key-map $B$G(B \C-? $B$K(B map $B$5$l$k!#(B
+; \C-? $B$r(B \C-h $B$HF1$8$K07$&$+$I$&$+$O!"(B.canna $B$G;XDj$9$k$Y$-!#(B
+; $B!J;2>H(B: [Canna 1885]$B!K(B 2001,4/27 ikumi
+;       (define-key canna-minibuffer-mode-map [delete]  [?\C-h])
+;  $B"*(B $B$,!"(B[Canna 5570] $B$G$O(B
+;; $B$_$J$5$s$,JXMx$J$h$&$K@_Dj$7$F$$$?$@$1$l$PNI$$$H;W$$$^$9!#(B
+
+;; $B$J$*!"<+J,$O(B DEL $B$G(B backspace $BF0:n$,$5$l$k$h$&$K$O$7$F$$$J$+$C(B
+;; $B$?$N$H!"(BTTY $B$G$O(B DEL $B$,JL$N0UL#$H$J$C$F$$$k$?$aFC$KF0:n$r5,(B
+;; $BDj$7$F$$$J$+$C$?$b$N$H;W$$$^$9!#(B
+
+;; Emacs $B>e$G$O(B Emacs $B$KJXMx$J$h$&$K$7$F$$$?$@$1$l$P$H;W$$$^$9!#(B
+;     $B$H$$$&$3$H$K$J$C$F$$$k$J$"!D!#(B
+       ))
+
+(or (assq 'canna:*select-mode* minor-mode-map-alist)
+    (setq minor-mode-map-alist
+	  (cons (cons 'canna:*select-mode* canna-minibuffer-mode-map)
+		minor-mode-map-alist)))
+
+;;;
+;;; $B$+$s$J$N%U%!%s%/%7%g%s%-!<$rM-8z$K$9$k(B
+;;;
+(if (featurep 'xemacs) nil
+  ;;; xemacs $B$G$O(B S-up $B$H$+(B C-up $B$H$+$N07$$$,0c$C$FLLE]!#(B
+  ;;; $B$H$j$"$($:J]N1!#(B
+  (let ((alist
+	 ;;; elisp $B$G$N%U%!%s%/%7%g%s%-!<$N(B symbol $B$H!"(B
+	 ;;; $B$+$s$J$NFC<l%-!<%3!<%I$NBP1~!#(B
+	 '((muhenkan . canna-key-nfer) (henkan . canna-key-xfer)
+	   (kanji . canna-key-xfer)
+	   (up . canna-key-up) (left . canna-key-left)
+	   (right . canna-key-right) (down . canna-key-down)
+	   (insert . canna-key-insert) (next . canna-key-rollup)
+	   (prior . canna-key-rolldown) (home . canna-key-home)
+	   (help . canna-key-help) (end . canna-key-end)
+	   (S-muhenkan . canna-key-shift-nfer)
+	   (S-henkan . canna-key-shift-xfer)
+	   (S-kanji . canna-key-shift-xfer)
+	   (S-up . canna-key-shift-up)
+	   (S-left . canna-key-shift-left)
+	   (S-right . canna-key-shift-right)
+	   (S-down . canna-key-shift-down)
+	   (C-muhenkan . canna-key-control-nfer)
+	   (C-henkan . canna-key-control-xfer)
+	   (C-kanji . canna-key-control-xfer)
+	   (C-up . canna-key-control-up)
+	   (C-left . canna-key-control-left)
+	   (C-right . canna-key-control-right)
+	   (C-down . canna-key-control-down)
+	   (f1 . canna-key-f1) (f2 . canna-key-f2)
+	   (f3 . canna-key-f3) (f4 . canna-key-f4)
+	   (f5 . canna-key-f5) (f6 . canna-key-f6)
+	   (f7 . canna-key-f7) (f8 . canna-key-f8)
+	   (f9 . canna-key-f9) (f10 . canna-key-f10)
+	   (hiragana . canna-key-hiragana) (katakana . canna-key-katakana)
+	   (zenkaku-hankaku . canna-key-hankakuzenkaku)
+	   (eisu-toggle . canna-key-eisu)))
+	pair)
+    (while alist
+      ;;; $B3F(B symbol $B$K!"BP1~$9$k(B canna-key-* $B$,Dj5A$5$l$F$$$l$P!"(B
+      ;;; symbol $B$N(B canna-fuction-key-code $B%W%m%Q%F%#$K(B canna-key-* $B$r(B
+      ;;; $B%;%C%H$7$F!"$=$N(B symbol $B$N%-!<$,2!$5$l$?$i$+$s$J$K=hM}$5$;$k(B
+      ;;; $B%3%^%s%I$r(B canna-mode-map $B$H(B canna-minibuffer-mode-map $B$GDj5A!#(B
+      (setq pair (car alist))
+      (if (boundp (cdr pair))
+	  (progn
+	    (put (car pair) 'canna-function-key-code (symbol-value (cdr pair)))
+	    (define-key canna-mode-map
+	      (vector (car pair)) 'canna-send-function-key-to-canna)
+	    (define-key canna-minibuffer-mode-map
+	      (vector (car pair)) 'canna-minibuffer-send-function-key-to-canna)))
+      (setq alist (cdr alist)))))
+
+(defun canna-send-function-key-to-canna (arg)
+  "Convert function key events into canna special key code and send to canna lib."
+  (interactive "p")
+  (let ((code (get last-command-event 'canna-function-key-code)))
+    (if code
+	(canna:functional-insert-command2 code arg)
+      (ding))))
+
+(defun canna-minibuffer-send-function-key-to-canna (arg)
+  "Convert function key events into canna special key code and send to canna lib while in minibuffer."
+  (interactive "p")
+  (let ((code (get last-command-event 'canna-function-key-code)))
+    (if code
+	(progn
+	  (setq canna:*select-mode* nil)
+	  (set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
+	  (select-window canna:*previous-window*)
+	  (canna:functional-insert-command2 code arg))
+      (ding))))
+
+;;;
+;;; $B%0%m!<%P%k4X?t$N=q$-BX$((B
+;;;
+
+
+;; Keyboard quit
+
+;(if (not (fboundp 'canna-sys:keyboard-quit))
+;    (fset 'canna-sys:keyboard-quit (symbol-function 'keyboard-quit)) )
+
+;(defun canna:keyboard-quit ()
+;  "See documents for canna-sys:keyboard-quit"
+;  (interactive)
+;  (if canna:*japanese-mode*
+;      (progn
+;;	(setq canna:*japanese-mode* nil)
+;	(setq canna:*fence-mode* nil)
+;	(if (boundp 'disable-undo)
+;	    (setq disable-undo canna:*fence-mode*))
+;	(canna:mode-line-display) ))
+;  (canna-sys:keyboard-quit) )
+
+;; Abort recursive edit
+
+;(if (not (fboundp 'canna-sys:abort-recursive-edit))
+;    (fset 'canna-sys:abort-recursive-edit
+;	  (symbol-function 'abort-recursive-edit)) )
+
+;(defun canna:abort-recursive-edit ()
+;  "see documents for canna-sys:abort-recursive-edit"
+;  (interactive)
+;  (if canna:*japanese-mode*
+;      (progn
+;	(setq canna:*japanese-mode* nil)
+;	(setq canna:*fence-mode* nil)
+;	(if (boundp 'disable-undo)
+;	    (setq disable-undo canna:*fence-mode*))
+;	(canna:mode-line-display) ))
+;  (canna-sys:abort-recursive-edit) )
+
+;; Exit-minibuffer
+
+(defun canna:exit-minibuffer ()
+  "Exit minibuffer turning off canna Japanese mode."
+  (interactive)
+  (if canna-initialize-minibuffer-state-when-exit
+      (setq canna:*japanese-mode-in-minibuffer* nil
+	    mode-line-canna-mode-in-minibuffer canna:*alpha-mode-string*))
+  )
+
+(add-hook 'minibuffer-exit-hook 'canna:exit-minibuffer)
+
+;; kill-emacs
+
+(add-hook 'kill-emacs-hook 'canna:finalize)
+
+;;;
+;;; function for mini-buffer
+;;;
+
+(defun adjust-minibuffer-mode ()
+  (if (window-minibuffer-p (selected-window))
+      (progn
+	(setq canna:*japanese-mode* canna:*japanese-mode-in-minibuffer*)
+	t)
+    nil))
+
+;;;
+;;; keyboard input for japanese language
+;;;
+
+(defun canna-functional-insert-command (arg)
+  "Use input character as a key of complex translation input such as
+kana-to-kanji translation."
+  (interactive "*p")
+  (let ((ch))
+    (cond ((integerp last-command-char)
+	   (setq ch last-command-char))
+	  ((and (fboundp 'char-or-char-int-p)
+		(char-or-char-int-p arg)
+		(not (null last-command-char)))
+	   (setq ch last-command-char))
+	  ((eq (event-key last-command-event) 'backspace)
+	   (setq ch ?\010))
+	  ((eq (event-key last-command-event) 'delete)
+	   (setq ch ?\177))
+	  ;; XEmacs:
+	  ;;(t
+	  ;; (setq ch (event-to-character last-command-event)))
+	  )
+    (canna:functional-insert-command2 ch arg)))
+
+(defun canna:functional-insert-command2 (ch arg)
+  "This function actually inserts a converted Japanese string."
+  ;; $B$3$N4X?t$OM?$($i$l$?J8;z$rF|K\8lF~NO$N$?$a$N%-!<F~NO$H$7$F<h$j07(B
+  ;; $B$$!"F|K\8lF~NO$NCf4V7k2L$r4^$a$?=hM}$r(BEmacs$B$N%P%C%U%!$KH?1G$5$;$k(B
+  ;; $B4X?t$G$"$k!#(B
+  (canna:display-candidates (canna-key-proc ch)) )
+
+(defun canna:delete-last-preedit ()
+  (let ((buffer-undo-list t))
+  (if (and (not (zerop canna:*last-kouho*))
+	   (if (fboundp 'buffer-live-p)
+	       (buffer-live-p (marker-buffer canna:*region-start*))
+	     t))
+      (progn
+	(if canna-underline
+	    ; $B$^$:!"B0@-$r>C$9!#(B
+	    (progn
+	      (canna:henkan-attr-off canna:*region-start* canna:*region-end*)
+	      (canna:yomi-attr-off canna:*region-start* canna:*region-end*)))
+	(delete-region canna:*region-start* canna:*region-end*)
+	(set-marker canna:*region-start* nil)
+	(set-marker canna:*region-end* nil)
+	(setq canna:*last-kouho* 0) ))))
+
+(defun canna:insert-fixed (strs)
+  (cond ((> strs 0)
+	 (let ((p (and canna-kakutei-yomi
+		       (or (null canna-save-undo-text-predicate)
+			   (funcall canna-save-undo-text-predicate
+				    (cons canna-kakutei-yomi
+					  canna-kakutei-romaji))))))
+	   (if p (progn
+		   (setq canna:*undo-text-yomi*
+			 (cons canna-kakutei-yomi canna-kakutei-romaji))
+		   (set-marker canna:*spos-undo-text* (point))))
+
+	   (if overwrite-mode
+	       (delete-region
+		(point) (save-excursion
+			  (move-to-column
+			   (+ (current-column)
+			      (string-width canna-kakutei-string)) t)
+			  (point))))
+
+	   (insert-and-inherit canna-kakutei-string)
+
+	   ;; Workaround to remove position to which `undo' goes.
+	   (if (listp buffer-undo-list)
+	       (if (car buffer-undo-list)
+		   (if (numberp (cadr buffer-undo-list))
+		       (setcdr buffer-undo-list (nthcdr 2 buffer-undo-list)))
+		 (if (numberp (nth 2 buffer-undo-list))
+		     (setcdr (cdr buffer-undo-list) (nthcdr 3 buffer-undo-list)))))
+
+	   (if (and (boundp 'self-insert-after-hook)
+		    self-insert-after-hook)
+	       ;; funcall $B$8$c$J$/$F(B run-hook-with-args $B$+!)(B
+	       (funcall self-insert-after-hook
+			(- (point) (length canna-kakutei-string)) (point)))
+	   (canna:do-auto-fill)
+	   ;; $BL$3NDj$NJ8;z$,$J$/!"3NDjJ8;zNs$N:G8e$,JD$83g8L$N(B
+	   ;; $BN`$@$C$?$H$-$O(B blink $B$5$;$k!#(B
+	   (if (and canna-empty-info
+		    blink-paren-function
+		    (eq (char-syntax (char-before)) ?\)) )
+	       (funcall blink-paren-function))
+	   (if p (set-marker canna:*epos-undo-text* (point)))))))
+
+(defun canna:insert-preedit ()
+  (let ((buffer-undo-list t))
+  (cond ((> canna-henkan-length 0)
+	 (set-marker canna:*region-start* (point))
+	 (if canna-with-fences
+	     (progn
+	       (insert "||")
+	       (set-marker canna:*region-end* (point))
+	       (backward-char 1)
+	       ))
+	 (insert canna-henkan-string)
+	 (if (not canna-with-fences)
+	     (set-marker canna:*region-end* (point)) )
+	 (if canna-underline
+	     (canna:yomi-attr-on canna:*region-start* canna:*region-end*))
+	 (setq canna:*last-kouho* canna-henkan-length)
+	 ))
+
+	 ;; $B8uJdNN0h$G$O6/D4$7$?$$J8;zNs$,B8:_$9$k$b$N$H9M$($i(B
+	 ;; $B$l$k!#6/D4$7$?$$J8;z$O(BEmacs$B$G$O%+!<%=%k%]%8%7%g%s$K$FI=<((B
+	 ;; $B$9$k$3$H$H$9$k!#6/D4$7$?$$J8;z$,$J$$$N$G$"$l$P!"%+!<%=%k(B
+	 ;; $B$O0lHV8e$NItJ,(B($BF~NO$,9T$o$l$k%]%$%s%H(B)$B$KCV$$$F$*$/!#(B
+
+	 ;; $B%+!<%=%k$r0\F0$9$k!#(B
+	 (if (not canna-underline)
+	     (backward-char
+	      (- canna:*last-kouho*
+		 ;; $B%+!<%=%k0LCV$O!"H?E>I=<(ItJ,$,B8:_$7$J$$$N$G$"$l$P!"(B
+		 ;; $B8uJdJ8;zNs$N:G8e$NItJ,$H$7!"H?E>I=<(ItJ,$,B8:_$9$k$N(B
+		 ;; $B$G$"$l$P!"$=$NItJ,$N;O$a$H$9$k!#(B
+		 (cond ((zerop canna-henkan-revlen)
+			canna:*last-kouho*)
+		       (t canna-henkan-revpos) )) )
+	   (if (and (> canna-henkan-revlen 0)
+		    (> canna-henkan-length 0))
+		    ; $B8uJd$ND9$5$,(B0$B$G$J$/!"(B
+		    ; $BH?E>I=<($ND9$5$,(B0$B$G$J$1$l$P!"(B
+		    ; $B$=$NItJ,$rJQE>I=<($9$k!#(B
+	       (let ((start (+ canna:*region-start*
+			       (if canna-with-fences 1 0)
+			       canna-henkan-revpos)))
+		 (if canna-underline
+		     (canna:henkan-attr-on start
+					   (+ start canna-henkan-revlen))))))))
+
+(defun canna:display-candidates (strs)
+  (cond ((stringp strs) ; $B%(%i!<$,5/$3$C$?>l9g(B
+	 (beep)
+	 (message "%s" strs) )
+	(canna-henkan-string
+	 ;; $B$b$78uJdI=<($,A0$N7k2L$+$iJQ$o$C$F$$$J$/$J$$$H$-$O(B......
+
+	 ;; $B<h$j4:$($::G=i$OA0$K=q$$$F$*$$$?Cf4V7k2L$r>C$9!#(B
+	 (canna:delete-last-preedit)
+
+	 ;; $B3NDj$7$?J8;zNs$,$"$l$P$=$l$rA^F~$9$k!#(B
+	 (canna:insert-fixed strs)
+	 ;; $B<!$O8uJd$K$D$$$F$N:n6H$G$"$k!#(B
+
+	 ;; $B8uJd$rA^F~$9$k!#8uJd$O=DK@FsK\$K$F64$^$l$k!#(B
+	 (canna:insert-preedit)
+	 ))
+
+  ;; $B%b!<%I$rI=$9J8;zNs$,B8:_$9$l$P$=$l$r%b!<%I$H$7$F<h$j07$&!#(B
+  (if (stringp canna-mode-string)
+      (mode-line-canna-mode-update canna-mode-string))
+
+  ;; $B8uJdI=<($,$J$1$l$P%U%'%s%9%b!<%I$+$iH4$1$k!#(B
+  (cond (canna-empty-info (canna:quit-canna-mode)))
+
+  ;; $B%_%K%P%C%U%!$K=q$/$3$H$,B8:_$9$k$N$G$"$l$P!"$=$l$r%_%K%P%C%U%!(B
+  ;; $B$KI=<($9$k!#(B
+  (cond (canna-ichiran-string
+	 (canna:minibuffer-input canna-ichiran-string
+				 canna-ichiran-length
+				 canna-ichiran-revpos
+				 canna-ichiran-revlen))
+	(canna:*cursor-was-in-minibuffer*
+	 (select-window (minibuffer-window))
+	 (set-window-buffer (minibuffer-window)
+			    (get-buffer-create canna:*menu-buffer*))
+	 (setq canna:*select-mode* t)))
+  )
+
+(defun canna:minibuffer-input (str len revpos revlen)
+  "Displaying misc informations for kana-to-kanji input."
+
+  ;; $B:n6H$r%_%K%P%C%U%!$K0\$9$N$K:]$7$F!"8=:_$N%&%#%s%I%&$N>pJs$rJ]B8(B
+  ;; $B$7$F$*$/!#(B
+  (setq canna:*previous-window* (selected-window))
+
+;; $B<+J,$KMh$kA0$,%_%K%P%C%U%!$+$I$&$+$rJQ?t$K$G$b$$$l$F$*$$$?J}$,$$$$$J$"!#(B
+
+  (if (not canna:*cursor-was-in-minibuffer*)
+      (progn
+	;; $B%_%K%P%C%U%!%&%#%s%I%&$K8uJd0lMwMQ$N%P%C%U%!$r3d$jEv$F$k!#(B
+	(setq canna:*saved-minibuffer* (window-buffer (minibuffer-window)))
+	))
+  (set-minibuffer-window (minibuffer-window))
+  (select-window (minibuffer-window))
+  (set-window-buffer (minibuffer-window)
+		       (get-buffer-create canna:*menu-buffer*))
+  (if (string< "23" emacs-version)
+      ;; Emacs-23$B$G$O$5$i$K(B swith-to-buffer $B$7$J$$$H%$%s%?%i%/%7%g%s$K(B
+      ;; $BLa$C$?$H$-$K85$N%P%C%U%!$KLa$5$l$F$7$^$&$h$&$@!#(B
+      ;; $B$b$C$H0BA4$JJ}K!$,$"$k$O$:!#(B
+      ;; 2009/9/12 yuuji
+      (switch-to-buffer canna:*menu-buffer*))
+
+  (setq canna:*select-mode* t)
+
+  (canna:select-attr-off (point-min) (point-max) )
+  (setq canna:*cursor-was-in-minibuffer* t)
+  (delete-region (point-min) (point-max))
+  (if (not (eq canna:*previous-window* (selected-window)))
+      (setq minibuffer-window-selected nil))
+
+  ;; emacs 21 $B$G$O!"$b$H$b$H$N%_%K%P%C%U%!$KI=<($5$l$F$$$?%b!<%IJ8;zNs$O(B
+  ;; $B0lMw$K$h$C$F1#$5$l$k$N$G!"2~$a$F%b!<%IJ8;zNs$rI=<($7$J$*$9!#(B
+  (if (and display-minibuffer-mode-in-minibuffer
+	   (> emacs-major-version 20)
+	   (eq canna:*previous-window* (selected-window)))
+      (insert (canna-query-mode)))
+
+  (insert str)
+
+  ;; $B%_%K%P%C%U%!$GH?E>I=<($9$k$Y$-J8;z$N$H$3$m$K%+!<%=%k$r0\F0$9$k!#(B
+  (cond ((> revlen 0)
+	 (backward-char (- len revpos)) ))
+  (raise-frame (window-frame (minibuffer-window)))
+  (and canna:color-p (not (eobp))
+       (canna:select-attr-on (point)
+			     (save-excursion (forward-char 1) (point))))
+
+  ;; $B%_%K%P%C%U%!$KI=<($9$k$Y$-J8;zNs$,%L%kJ8;zNs$J$N$G$"$l$P!"A0$N%&%#(B
+  ;; $B%s%I%&$KLa$k!#(B
+  (if (or (zerop len) canna-empty-info)
+      (progn
+	(setq canna:*cursor-was-in-minibuffer* nil)
+	(setq canna:*select-mode* nil)
+
+	;; $B%_%K%P%C%U%!%&%#%s%I%&$N%P%C%U%!$r85$KLa$9!#(B
+	(set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
+	(if (eq (minibuffer-window) (selected-window))
+	    (set-buffer canna:*saved-minibuffer*))
+;	(setq canna:*saved-minibuffer* nil)
+
+	(if (and canna-empty-info (> len 0))
+	    (progn
+	      (message "%s" str) ))
+	(select-window canna:*previous-window*) ))
+  )
+
+(defun canna-minibuffer-insert-command (arg)
+  "Use input character as a key of complex translation input such as\n\
+kana-to-kanji translation, even if you are in the minibuffer."
+  (interactive "p")
+  (setq canna:*select-mode* nil)
+  (set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
+  (if (eq (minibuffer-window) (selected-window))
+      (set-buffer canna:*saved-minibuffer*))
+  (select-window canna:*previous-window*)
+  (canna-functional-insert-command arg))
+
+;;;
+;;; $B$+$s$J%b!<%I$N<gLr$O!"<!$N(B canna-self-insert-command $B$G$"$k!#$3$N(B
+;;; $B%3%^%s%I$OA4$F$N%0%i%U%#%C%/%-!<$K%P%$%s%I$5$l$k!#(B
+;;;
+;;; $B$3$N4X?t$G$O!"8=:_$N%b!<%I$,F|K\8lF~NO%b!<%I$+$I$&$+$r%A%'%C%/$7$F!"(B
+;;; $BF|K\8lF~NO%b!<%I$G$J$$$N$G$"$l$P!"%7%9%F%`$N(B self-insert-command
+;;; $B$r8F$V!#F|K\8lF~NO%b!<%I$G$"$l$P!"%U%'%s%9%b!<%I$KF~$j!"(B
+;;; canna-functional-insert-command $B$r8F$V!#(B
+;;;
+
+(eval-and-compile
+  (and (not (fboundp 'cancel-undo-boundary))
+       (boundp 'buffer-undo-list)
+       ;; cancel-undo-boundary from mule2/mule-util.el
+       (fset 'cancel-undo-boundary
+	     (function
+	      (lambda ()
+		"Cancel undo boundary."
+		(if (and (consp buffer-undo-list)
+			 ;; if car is nil.
+			 (null (car buffer-undo-list)) )
+		    (setq buffer-undo-list (cdr buffer-undo-list))))))))
+
+(defun canna-self-insert-command (arg)
+  "Self insert pressed key and use it to assemble Romaji character."
+  (interactive "*p")
+  (adjust-minibuffer-mode)
+  (if (and canna:*japanese-mode*
+	   ;; $B%U%'%s%9%b!<%I$@$C$?$i$b$&0lEY%U%'%s%9%b!<%I$KF~$C$?$j$7(B
+	   ;; $B$J$$!#(B
+	   (not canna:*fence-mode*) )
+      (canna:enter-canna-mode-and-functional-insert)
+    (progn
+      ;; $B0J2<$NItJ,$O(B egg.el $B$N(B 3.09 $B$N(B egg-self-insert-command $B$NItJ,$+$i(B
+      ;; $B%3%T!<$7!"<j$rF~$l$F$$$^$9!#(B93.11.5 kon
+      ;; treat continuous 20 self insert as a single undo chunk.
+      ;; `20' is a magic number copied from keyboard.c
+;      (if (or				;92.12.20 by T.Enami
+;	   (not (eq last-command 'canna-self-insert-command))
+;	   (>= canna:*self-insert-non-undo-count* 20))
+;	  (setq canna:*self-insert-non-undo-count* 1)
+;	(cancel-undo-boundary)
+;	(setq canna:*self-insert-non-undo-count*
+;	      (1+ canna:*self-insert-non-undo-count*)))
+      (if (and (memq last-command
+		     '(canna-self-insert-command
+		       egg-self-insert-command
+		       can-n-egg-self-insert-command))
+	       (> last-command-char ? ))
+	  (cancel-undo-boundary))
+      (self-insert-command arg)
+;      (if canna-insert-after-hook
+;	  (run-hooks 'canna-insert-after-hook))
+      (if (and (boundp 'self-insert-after-hook) ; append by knak 97.10.21
+	       self-insert-after-hook)
+	  (if (<= 1 arg)
+	      (funcall self-insert-after-hook
+		       (- (point) arg) (point)))
+	(if (= last-command-char ? ) (canna:do-auto-fill))))))
+
+;; wire us into pending-delete
+(put 'canna-self-insert-command
+     (if (featurep 'xemacs) 'pending-delete 'delete-selection) t)
+
+(defun canna-toggle-japanese-mode ()
+  "Toggle canna japanese mode."
+  (interactive)
+  (let ((in-minibuffer (adjust-minibuffer-mode)))
+    (cond (canna:*japanese-mode*
+	   (setq canna:*japanese-mode* nil)
+	   (canna-abandon-undo-info)
+	   (setq canna:*use-region-as-henkan-region* nil)
+	   (setq canna:*saved-mode-string* mode-line-canna-mode)
+	   (mode-line-canna-mode-update canna:*alpha-mode-string*) )
+	  (t
+	   (setq canna:*japanese-mode* t)
+	   (if (fboundp 'canna-query-mode)
+	       (let ((new-mode (canna-query-mode)))
+		 (if (string-equal new-mode "")
+		     (setq canna:*kanji-mode-string* canna:*saved-mode-string*)
+		   (setq canna:*kanji-mode-string* new-mode)
+		   )) )
+	   (mode-line-canna-mode-update canna:*kanji-mode-string*) ) )
+    (if in-minibuffer
+	(setq canna:*japanese-mode-in-minibuffer* canna:*japanese-mode*)) ))
+
+(defun canna:initialize ()
+  (let ((init-val nil))
+    (cond (canna:*initialized*) ; initialize $B$5$l$F$$$?$i2?$b$7$J$$(B
+	  (t
+	   (setq canna:*initialized* t)
+	   (setq init-val (canna-initialize
+			   (if canna-underline 0 1)
+			   canna-server canna-file))
+	   (cond ((car (cdr (cdr init-val)))
+		  (canna:output-warnings (car (cdr (cdr init-val)))) ))
+	   (cond ((car (cdr init-val))
+		  (error (car (cdr init-val))) ))
+	   ) )
+
+    (if (fboundp 'canna-query-mode)
+	(progn
+	  (canna-change-mode canna-mode-alpha-mode)
+	  (setq canna:*alpha-mode-string* (canna-query-mode)) ))
+
+    (canna-do-function canna-func-japanese-mode)
+
+    (if (fboundp 'canna-query-mode)
+	(setq canna:*kanji-mode-string* (canna-query-mode)))
+
+    init-val))
+
+(defun canna:finalize ()
+  (cond ((null canna:*initialized*)) ; initialize $B$5$l$F$$$J$+$C$?$i2?$b$7$J$$(B
+	(t
+	 (message "$B!X$+$s$J!Y$N<-=q$r%;!<%V$7$^$9!#(B")
+	 (setq canna:*initialized* nil)
+	 (let ((init-val (canna-finalize)))
+	   (cond ((car (cdr (cdr init-val)))
+		  (canna:output-warnings (car (cdr (cdr init-val)))) ))
+	   (cond ((car (cdr init-val))
+		  (error (car (cdr init-val))) ))
+	   )
+	 )))
+
+(defun canna:enter-canna-mode ()
+  (if (not canna:*initialized*)
+      (progn
+	(message "$B!X$+$s$J!Y$N=i4|2=$r9T$C$F$$$^$9(B....")
+	(canna:initialize)
+	(message "$B!X$+$s$J!Y$N=i4|2=$r9T$C$F$$$^$9(B....done")
+	))
+  (canna-set-width (- (window-width (minibuffer-window))
+;; emacs 21 $B$G$O!"0lMwI=<($N$H$-(B minibuffer prompt $B$O1#$l$k$h$&$K$J$C$?$N$G!"(B
+;; window $BI}$N7W;;$+$i=|$$$F$$$$!#(B
+		      (if (> emacs-major-version 20)
+			  0
+			(minibuffer-prompt-width))
+		      (if (and display-minibuffer-mode-in-minibuffer
+			       (window-minibuffer-p (selected-window)))
+			  (string-width
+			   (let ((new-mode (canna-query-mode)))
+			     (if (string-equal new-mode "")
+				 canna:*saved-mode-string*
+			       new-mode)))
+			0)))
+  (setq canna:*fence-mode* t))
+
+(defun canna:enter-canna-mode-and-functional-insert ()
+  (canna:enter-canna-mode)
+  (setq canna:*use-region-as-henkan-region* nil)
+  (setq unread-command-events (list last-command-event)))
+
+(defun canna:quit-canna-mode ()
+  (cond (canna:*fence-mode*
+	 (setq canna:*fence-mode* nil)
+	 (if canna:*exit-japanese-mode*
+	     (progn
+	       (setq canna:*exit-japanese-mode* nil)
+	       (setq canna-mode-string canna:*alpha-mode-string*)
+	       (if canna:*japanese-mode*
+		   (canna-toggle-japanese-mode)
+		 (mode-line-canna-mode-update canna:*alpha-mode-string*) )))
+	))
+  (set-marker canna:*region-start* nil)
+  (set-marker canna:*region-end* nil)
+  )
+
+(defun canna-touroku ()
+  "Register a word into a kana-to-kanji dictionary."
+  (interactive)
+  (if (not canna:*fence-mode*)
+      (progn
+	(setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+	(canna:enter-canna-mode)
+	(canna:display-candidates (canna-touroku-string "")) )
+    (beep)
+  ))
+
+(defun canna-without-newline (start end)
+  (and (not (eq start end))
+       (or
+	(and (<= end (point))
+	     (save-excursion
+	       (beginning-of-line)
+	       (<= (point) start) ))
+	(and (<= (point) start)
+	     (save-excursion
+	       (end-of-line)
+	       (<= end (point)) ))
+	)))
+
+(defun canna-touroku-region (start end)
+  "Register a word which is indicated by region into a kana-to-kanji\n\
+dictionary."
+  (interactive "r")
+  (if (canna-without-newline start end)
+      (if (not canna:*fence-mode*)
+	  (progn
+	    (setq canna:*use-region-as-henkan-region* nil)
+	    (setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+	    (canna:enter-canna-mode)
+	    (canna:display-candidates
+	     (canna-touroku-string (buffer-substring start end))) ))
+    (message "$B%j!<%8%g%s$,IT@5$G$9!#%L%k%j!<%8%g%s$+!"2~9T$,4^$^$l$F$$$^$9!#(B")
+    ))
+
+(defun canna-extend-mode ()
+  "To enter an extend-mode of Canna."
+  (interactive "*")
+  (if (or canna:*fence-mode* canna:*select-mode*)
+      (beep)
+      (progn
+	(setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+	(canna:enter-canna-mode)
+	(canna:display-candidates
+	 (canna-do-function canna-func-extend-mode) ))))
+
+(defun canna-kigou-mode ()
+  "Enter symbol choosing mode."
+  (interactive "*")
+  (if (or canna:*fence-mode* canna:*select-mode*)
+      (beep)
+      (progn
+	(setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+	(canna:enter-canna-mode)
+	(canna:display-candidates (canna-change-mode canna-mode-kigo-mode)) )
+    ))
+
+(defun canna-hex-mode ()
+  "Enter hex code entering mode."
+  (interactive "*")
+  (if (or canna:*fence-mode* canna:*select-mode*)
+      (beep)
+      (progn
+	(setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+	(canna:enter-canna-mode)
+	(canna:display-candidates (canna-change-mode canna-mode-hex-mode)) )
+    ))
+
+(defun canna-bushu-mode ()
+  "Enter special mode to convert by BUSHU name."
+  (interactive "*")
+  (if (or canna:*fence-mode* canna:*select-mode*)
+      (beep)
+      (progn
+	(setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+	(canna:enter-canna-mode)
+	(canna:display-candidates (canna-change-mode canna-mode-bushu-mode)) )
+    ))
+
+(defun canna-reset ()
+  (interactive)
+  (canna:finalize)
+  (message "$B!X$+$s$J!Y$N:F=i4|2=$r9T$C$F$$$^$9(B....")
+  (canna:initialize)
+  (message "$B!X$+$s$J!Y$N:F=i4|2=$r9T$C$F$$$^$9(B....done")
+  )
+
+
+(defun canna ()
+  (interactive)
+  (message "$B!X$+$s$J!Y$r=i4|2=$7$F$$$^$9(B....")
+  (let (init-val)
+    (cond ((and (fboundp 'canna-initialize) (fboundp 'canna-change-mode) )
+
+	   ;; canna $B$,;H$($k;~$O<!$N=hM}$r$9$k!#(B
+
+	   ;; $BG[?'@_Dj(B (by yuuji@ae.keio.ac.jp)
+	   (setq canna:color-p (and canna-use-color
+				    (if window-system
+					(x-display-color-p)
+				      (or (featurep 'xemacs)
+					  (and (string< "21" emacs-version)
+					       (tty-display-color-p))))))
+; $B0J2<$N#29T$O!"?'?t$,B-$j$J$/$F%(%i!<$K$J$C$?$H$-$N$3$H$r9M$($F(B
+; $B2<$N(B condition-error $B$N8e$K0\$9!#(B 2001,9/5 ikumi
+;	   ;;$B%+%i!<$N;~(Bunderline$B%b!<%I$HF1$8>uBV$G=i4|2=$9$kI,MW$,$"$k(B
+;	   (setq canna-underline (or canna:color-p canna-underline))
+	   (cond
+	    (canna:color-p
+	     (setq canna:attr-mode
+		   (cond
+		    (canna-background-mode
+		     (if window-system
+			 (if (eq canna-background-mode 'dark)
+			     'reverse 'normal)
+		       (if (eq canna-background-mode 'dark)
+			   'nw-rv 'nw)))
+		    ((eq 'dark
+			     (cond
+			      ((boundp 'hilit-background-mode)
+			       (symbol-value 'hilit-background-mode))
+			      ((boundp 'frame-background-mode)
+			       frame-background-mode)
+			      ((fboundp 'get-frame-background-mode)
+			       (get-frame-background-mode nil))))
+		     (if window-system 'reverse 'nw-rv))
+		    (window-system
+		     (if (string-match
+			  "on\\|t\\|yes"
+			  (or (if (featurep 'xemacs)
+				  (x-get-resource "ReverseVideo"
+						  "reverseVideo" 'string)
+				(x-get-resource "ReverseVideo" "reverseVideo"))
+			      ""))
+			 'reverse
+		       'normal))
+		    (t 'nw)))
+	     (setq canna:attr-yomi
+		   (if (listp canna-use-color)
+		       (car canna-use-color)
+		     (cdr (assq canna:attr-mode
+				(assq 'yomi canna:attribute-alist)))))
+	     (setq canna:attr-taishou
+		   (if (listp canna-use-color)
+		       (car (cdr canna-use-color))
+		     (setq canna:attr-taishou
+			   (cdr (assq
+				 canna:attr-mode
+				 (assq 'taishou canna:attribute-alist))))))
+	     (setq canna:attr-select
+		   (if (listp canna-use-color)
+		       (car (cdr (cdr canna-use-color)))
+		     (setq canna:attr-select
+			   (cdr (assq canna:attr-mode
+				      (assq 'select canna:attribute-alist))))))
+	     ;;$B?'$E$1MQ(Bface$B$N:n@.(B
+	     (condition-case err
+		 (mapcar
+		  (function
+		   (lambda (face)
+		     (let* ((color (symbol-value
+				    (intern (concat "canna:" (symbol-name face)))))
+			    backp)
+		       (make-face face)
+		       (if (stringp color)
+			   (progn
+			     (setq backp (string-match "/" color))
+			     (set-face-foreground
+			      face (substring color 0 backp))
+			     (if backp
+				 (set-face-background
+				  face (substring color (1+ backp)))))
+			 (copy-face color face)))))
+		  '(attr-yomi attr-taishou attr-select))
+	       (error
+		(message "$BI,MW$J?'?t$,3NJ]$G$-$^$;$s$G$7$?(B")
+		(sit-for 1)
+		(setq canna:color-p nil
+		      canna:attr-mode nil
+		      canna:attr-yomi nil
+		      canna:attr-taishou nil
+		      canna:attr-select nil)))
+	     ))
+	   ;;$B%+%i!<$N;~(Bunderline$B%b!<%I$HF1$8>uBV$G=i4|2=$9$kI,MW$,$"$k(B
+	   (setq canna-underline (or canna:color-p canna-underline))
+	   ;;$BG[?'@_Dj=*N;(B
+
+	   ;; $B!X$+$s$J!Y%7%9%F%`$N=i4|2=(B
+
+	   (setq init-val (canna:initialize))
+
+	   ;; $B%-!<$N%P%$%s%G%#%s%0(B
+
+	   (let ((ch 32))
+	     (while (< ch 127)
+	       (define-key global-map (make-string 1 ch) 'canna-self-insert-command)
+	       (setq ch (1+ ch)) ))
+
+	   (cond ((let ((keys (car init-val)) (ok nil))
+		    (while keys
+		      (cond ((< (car keys) 128)
+			     (global-set-key
+			      (make-string 1 (car keys))
+			      'canna-toggle-japanese-mode)
+			     (setq ok t) ))
+		      (setq keys (cdr keys))
+		      ) ok))
+		 (t ; $B%G%U%)%k%H$N@_Dj(B
+		  (global-set-key "\C-o" 'canna-toggle-japanese-mode) ))
+
+	   (define-key global-map [kanji] 'canna-toggle-japanese-mode)
+	   (define-key global-map [henkan] 'canna-toggle-japanese-mode)
+	   (if canna-do-keybind-for-functionkeys
+	       (progn
+		 (define-key global-map [help] 'canna-extend-mode)
+		 (define-key global-map [insert] 'canna-kigou-mode)
+		 (define-key global-map [f1] 'canna-kigou-mode)
+		 (define-key global-map [f2] 'canna-hex-mode)
+		 (define-key global-map [f3] 'canna-bushu-mode)
+		 ))
+
+	   (if canna-use-space-key-as-henkan-region
+	       (progn
+		 (global-set-key "\C-@" 'canna-set-mark-command)
+		 ;; X Window $B$O(B C-@ $B$H(B C-SPC $B$r6hJL$9$k$N$G!"$3$l$,I,MW!#(B
+		 (global-set-key [?\C-\ ] 'canna-set-mark-command)
+		 (global-set-key " " 'canna-henkan-region-or-self-insert) ))
+
+	 ;; $B%b!<%I9T$N:n@.(B
+
+	   (canna:create-mode-line)
+	   (mode-line-canna-mode-update canna:*alpha-mode-string*)
+
+	 ;; $B%7%9%F%`4X?t$N=q$-BX$((B
+
+;	   (fset 'abort-recursive-edit
+;		 (symbol-function 'canna:abort-recursive-edit))
+;	   (fset 'keyboard-quit
+;		 (symbol-function 'canna:keyboard-quit))
+
+	   )
+
+	  ((fboundp 'canna-initialize)
+	   (beep)
+	   (with-output-to-temp-buffer "*canna-warning*"
+	     (princ "$B$3$N(B Mule $B$G$O(B new-canna $B$,;H$($^$;$s(B")
+	     (terpri)
+	     (print-help-return-message)) )
+
+	  (t ; $B!X$+$s$J!Y%7%9%F%`$,;H$($J$+$C$?;~$N=hM}(B
+	   (beep)
+	   (with-output-to-temp-buffer "*canna-warning*"
+	     (princ "$B$3$N(B Mule $B$G$O(B canna $B$,;H$($^$;$s(B")
+	     (terpri)
+	     (print-help-return-message))
+	   ))
+    (message "$B!X$+$s$J!Y$r=i4|2=$7$F$$$^$9(B....done")
+    ) )
+
+;;;
+;;; auto fill control (from egg)
+;;;
+
+(defun canna:do-auto-fill ()
+  (if (and auto-fill-function (not buffer-read-only)
+	   (> (current-column) fill-column))
+      (let ((ocolumn (current-column)))
+	(funcall auto-fill-function)
+	(while (and (< fill-column (current-column))
+		    (< (current-column) ocolumn))
+	  (setq ocolumn (current-column))
+	  (funcall auto-fill-function)))))
+
+(defun canna:output-warnings (mesg)
+  (with-output-to-temp-buffer "*canna-warning*"
+    (while mesg
+      (princ (car mesg))
+      (terpri)
+      (setq mesg (cdr mesg)) )
+    (print-help-return-message)))
+
+(defun canna-undo (&optional arg)
+  (interactive "*P")
+  (if (and canna:*undo-text-yomi*
+	   (eq (current-buffer) (marker-buffer canna:*spos-undo-text*))
+	   )
+      (progn
+	(message "$BFI$_$KLa$7$^$9!*(B")
+	(goto-char canna:*spos-undo-text*)
+	(delete-region canna:*spos-undo-text*
+		       canna:*epos-undo-text*)
+
+	(if (null canna:*japanese-mode*)
+	    (progn
+	      (setq canna:*exit-japanese-mode* t) ))
+	(if (not canna:*fence-mode*)
+	    ;; $B%U%'%s%9%b!<%I$@$C$?$i$b$&0lEY%U%'%s%9%b!<%I$KF~$C$?$j$7(B
+	    ;; $B$J$$!#(B
+	    (canna:enter-canna-mode) )
+	(canna:display-candidates
+	 (let ((texts (canna-store-yomi (car canna:*undo-text-yomi*)
+					(cdr canna:*undo-text-yomi*) )) )
+	   (cond (canna-undo-hook
+		  (funcall canna-undo-hook))
+		 (t texts) )))
+	(canna-abandon-undo-info))
+    (undo arg)))
+
+(defun canna-abandon-undo-info ()
+  (interactive)
+  (setq canna:*undo-text-yomi* nil)
+  (set-marker canna:*spos-undo-text* nil)
+  (set-marker canna:*epos-undo-text* nil) )
+
+(defun canna-henkan-region (start end)
+  "Convert a text which is indicated by region into a kanji text."
+  (interactive "*r")
+  ;; [Canna 4302] $B$h$j!"J8;z?t$,B?$9$.$k$H$-$OJQ49BP>]$K$J$i$J$$$h$&$K!#(B
+  (if (> (- end start) 320) (error "$BJQ49BP>]J8;z?t$,B?$9$.$^$9(B"))
+  (if (null canna:*japanese-mode*)
+      (progn
+	(setq canna:*exit-japanese-mode* t) ))
+  (let ((res nil))
+    (setq res (canna-store-yomi (buffer-substring start end)))
+    (delete-region start end)
+    (canna:enter-canna-mode)
+    (if (fboundp 'canna-do-function)
+	(setq res (canna-do-function canna-func-henkan)))
+    (canna:display-candidates res) ))
+
+;;;
+;;; $B%^!<%/%3%^%s%I!$(Bcanna-henkan-region-or-self-insert $B$G;H$&$+$b(B
+;;;
+
+(defun canna-set-mark-command (arg)
+  "Besides setting mark, set mark as a HENKAN region if it is in\n\
+the japanese mode."
+  (interactive "P")
+  (setq this-command 'set-mark-command) ;hack for set-mark-command itself.
+  (set-mark-command arg)
+  (if canna:*japanese-mode*
+      (progn
+	(setq canna:*use-region-as-henkan-region* (mark t))
+	(message "Mark set($BJQ49NN0h3+;O(B)") )))
+
+
+(defun canna-henkan-region-or-self-insert (arg)
+  "Do kana-to-kanji convert region if HENKAN region is defined,\n\
+self insert otherwise."
+  (interactive "*p")
+  (if (and canna:*use-region-as-henkan-region*
+	   (eq canna:*use-region-as-henkan-region* (mark t))
+	   (canna-without-newline (region-beginning) (region-end)))
+      (progn
+	(setq canna:*use-region-as-henkan-region* nil)
+	(canna-henkan-region (region-beginning) (region-end)))
+    (canna-self-insert-command arg) ))
+
+;;
+;; for C-mode
+;;
+
+(eval-when-compile
+  (autoload 'electric-c-terminator "c-mode" nil t)
+  (autoload 'electric-c-semi "c-mode" nil t)
+  (autoload 'electric-c-brace "c-mode" nil t))
+
+(defun canna-electric-c-terminator (arg)
+  (interactive "P")
+  (if canna:*japanese-mode*
+      (canna-self-insert-command arg)
+    (electric-c-terminator arg) ))
+
+(defun canna-electric-c-semi (arg)
+  (interactive "P")
+  (if canna:*japanese-mode*
+      (canna-self-insert-command arg)
+    (electric-c-semi arg) ))
+
+(defun canna-electric-c-brace (arg)
+  (interactive "P")
+  (if canna:*japanese-mode*
+      (canna-self-insert-command arg)
+    (electric-c-brace arg) ))
+
+(defun canna-c-mode-hook ()
+  (let ((map (symbol-value 'c-mode-map)))
+    (define-key map "{" 'canna-electric-c-brace)
+    (define-key map "}" 'canna-electric-c-brace)
+    (define-key map ";" 'canna-electric-c-semi)
+    (define-key map ":" 'canna-electric-c-terminator)))
+
+;;
+;; for CC-mode
+;;
+
+(eval-when-compile
+  (autoload 'c-electric-colon "cc-cmds" nil t)
+  (autoload 'c-electric-semi&comma "cc-cmds" nil t)
+  (autoload 'c-electric-brace "cc-cmds" nil t))
+
+(defun canna-c-electric-colon (arg)
+  (interactive "P")
+  (if canna:*japanese-mode*
+      (canna-self-insert-command arg)
+    (c-electric-colon arg)))
+
+(defun canna-c-electric-semi&comma (arg)
+  (interactive "P")
+  (if canna:*japanese-mode*
+      (canna-self-insert-command arg)
+    (c-electric-semi&comma arg)))
+
+(defun canna-c-electric-brace (arg)
+  (interactive "P")
+  (if canna:*japanese-mode*
+      (canna-self-insert-command arg)
+    (c-electric-brace arg)))
+
+(defun canna-cc-mode-hook ()
+  (let ((map (symbol-value 'c-mode-base-map)))
+    (define-key map "{" 'canna-c-electric-brace)
+    (define-key map "}" 'canna-c-electric-brace)
+    (define-key map ";" 'canna-c-electric-semi&comma)
+    (define-key map ":" 'canna-c-electric-colon)))
+
+(defun canna-set-fence-mode-format (fence sep underline)
+  (setq canna-with-fences fence)
+  (canna-set-bunsetsu-kugiri sep)
+  (setq canna-underline underline)
+)
+
+;; $B%j!<%8%g%s$K$"$k%m!<%^;z$r!X$+$s$J!Y$K?)$o$9!#(B
+;; $B7k2L$H$7$F!"!X$+$s$J!Y$NFI$_%b!<%I$K$J$k!#(B
+;; $B%j!<%8%g%s$KB8:_$7$F$$$k6uGrJ8;z$H@)8fJ8;z$O<N$F$i$l$k!#(B
+
+(defun canna-rk-region (start end)
+  "Convert region into kana."
+;  (interactive "*r")
+  (let ((str nil) (len 0) (i 0) (res 0))
+    (setq str (buffer-substring start end))
+    (setq len (length str))
+    (while (< i len)
+      (let ((ch (elt str i)))
+	(if (> ch ? )
+	    (setq res (canna-do-function canna-func-functional-insert ch)) ))
+      (setq i (1+ i)) )
+    res))
+
+(defun canna-rk-trans-region (start end)
+  "Insert alpha-numeric string as it is sent from keyboard."
+  (interactive "*r")
+  (let ((res))
+    (setq res (canna-rk-region start end))
+    (delete-region start end)
+    (if (null canna:*japanese-mode*)
+	(progn
+	  (setq canna:*exit-japanese-mode* t) ))
+    (setq res (canna-do-function canna-func-henkan))
+    (canna:enter-canna-mode)
+    (canna:display-candidates res) ))
+
+;; $B%+!<%=%k$N:8$K$"$k(B arg $B%o!<%I$N%m!<%^;z$r!X$+$s$J!Y$K?)$o$9!#(B
+
+(defun canna-rk-trans (arg)
+  (interactive "*p")
+  (let ((po (point)))
+    (skip-chars-backward "-a-zA-Z.,?!~")
+    (if (not (eq (point) po))
+	(canna-rk-trans-region (point) po) )))
+
+(defun canna-henkan-kakutei-and-self-insert (arg)
+  (interactive "*p")
+  (if canna:*japanese-mode*
+      (canna-functional-insert-command arg)
+    (progn
+      (setq unread-command-events (list last-command-event))
+      (canna-kakutei-to-basic-stat)) ))
+
+(defun canna-kakutei-to-basic-stat ()
+  ;; $B<!$N9T$O!"!V$+$s$J!W$,(B 2003,7/3 $B0J9_$NHG$G$J$1$l$P@5$7$/F0$+$J$$!#(B
+  (canna:display-candidates (canna-do-function canna-func-kakutei))
+  (if (not canna:*japanese-mode*)
+      (mode-line-canna-mode-update canna:*alpha-mode-string*)))
+
+(defun canna-minibuffer-maybe-henkan-kakutei-and-self-insert (arg)
+  (interactive "p")
+  (canna-minibuffer-insert-command arg)
+  ;; $BDL>o$N%-!<F~NO$H;W$C$F=hM}$7$?7k2L!"%a%K%e!<I=<($rI,MW$H$7$J$/$J$C(B
+  ;; $B$?>uBV$K$J$j!"L$3NDjJ8;zNs$,;D$C$F$*$j!"#1J8;z0J>e$N3NDjJ8;zNs$,(B
+  ;; $B$"$k$J$i!"$H$j$d$a=hM}$r9T$C$F%U%'%s%9%b!<%I$rH4$1!":FEYF1$8%-!<(B
+  ;; $BF~NO$r=hM}$9$k!#(B
+  ;;   $B"*(B $B$3$l$@$H!"(B.canna $B$G(B renbun-continue $B$H(B chikuji-continue $B$r(B nil
+  ;;      $B$K$7$F$*$+$J$$$H!"!V<!$N#1;z$rF~NO$7$?;~E@$G$O3NDj$7$J$$$1$I!"(B
+  ;;      $BB3$1$F#1;zF~NO$9$k$H$=$3$G3NDj$7$A$c$&!W$H$$$&JQ$JF0:n$K$J$C$F(B
+  ;;      $B$7$^$&$J$"!#(B
+  ;;      $B$=$l$+$i!"(B.canna $B$G(B allow-next-input $B$r(B nil $B$K$7$F$k$H!"$=$b$=$b(B
+  ;;      $B3NDj$7$F$/$l$J$$!#(B
+  ;;   $B$d$C$Q$j!"$f$G$?$^$4E*F0:n$K$D$$$F$O!"K\?&$N(B yc.el $B$KG$$;$k$N$,$$$$(B
+  ;;   $B$N$+$J$"!#(B
+  (or canna:*japanese-mode*
+      canna:*cursor-was-in-minibuffer* canna-empty-info
+      (zerop (length canna-kakutei-string))
+      (progn
+	(canna:display-candidates (canna-do-function canna-func-quit))
+	(mode-line-canna-mode-update canna:*alpha-mode-string*)
+	(setq unread-command-events (list last-command-event)))))
+
+(defun canna-setup-for-being-boiled ()
+  (let ((ch (1+ ? )))
+    (while (< ch 127)
+      (define-key canna-mode-map (make-string 1 ch) 'canna-henkan-kakutei-and-self-insert)
+      (define-key canna-minibuffer-mode-map (make-string 1 ch) 'canna-minibuffer-maybe-henkan-kakutei-and-self-insert)
+      (setq ch (1+ ch)))))
+
+(defvar rK-trans-key "\C-j" "for `boil' only")
+(make-variable-buffer-local 'rK-trans-key)
+
+(defun canna-boil ()
+  "`canna-boil' cooks `canna' as if `boil' does for `egg'."
+  (interactive)
+  (canna-setup-for-being-boiled)
+  (local-set-key rK-trans-key 'canna-rk-trans)
+  (message "boiled"))
+
+;;
+;; $B?'$E$1$N$?$a$N4X?t(B
+;;
+(defun canna:yomi-attr-on (start end)
+  (if (overlayp canna:*yomi-overlay*)
+      (move-overlay canna:*yomi-overlay* start end)
+    (overlay-put (setq canna:*yomi-overlay*
+		       (apply
+			'make-overlay start end nil nil
+			(if (string< "20.2" emacs-version) (list t))))
+		 'face
+		 (if canna:color-p 'attr-yomi 'underline))))
+
+(defun canna:yomi-attr-off (start end)
+  (and (overlayp canna:*yomi-overlay*)
+       (delete-overlay canna:*yomi-overlay*)))
+
+(defun canna:henkan-attr-on (start end)
+  (if (overlayp canna:*henkan-overlay*)
+      (move-overlay canna:*henkan-overlay* start end)
+    (overlay-put (setq canna:*henkan-overlay*
+		       (apply
+			'make-overlay start end nil nil
+			(if (string< "20.2" emacs-version) (list t))))
+		 'face
+		 (if canna:color-p 'attr-taishou 'region))))
+
+(defun canna:henkan-attr-off (start end)
+  (and (overlayp canna:*henkan-overlay*)
+       (delete-overlay canna:*henkan-overlay*)))
+
+(defun canna:select-attr-on (start end)
+  (if (overlayp canna:*select-overlay*)
+      (move-overlay canna:*select-overlay* start end)
+    (overlay-put (setq canna:*select-overlay*
+		       (apply
+			'make-overlay start end nil nil
+			(if (string< "20.2" emacs-version) (list t))))
+		 'face
+		 'attr-select)))
+
+(defun canna:select-attr-off (start end)
+  (and (overlayp canna:*select-overlay*)
+       (delete-overlay canna:*select-overlay*)))
+
+(eval-when-compile
+  (autoload 'picture-substitute "picture"))
+(if (featurep 'picture)
+    (progn
+      (picture-substitute 'self-insert-command 'canna-self-insert-command)
+      (picture-substitute 'completion-separator-self-insert-command
+			  'canna-self-insert-command)
+      (picture-substitute 'completion-separator-self-insert-autofilling
+			  'canna-self-insert-command)))
+
+(provide 'canna)
+;;; canna.el ends here
diff -r 08c8dbbb056a lisp/isearch-ext.el
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/isearch-ext.el	Thu Jun 14 21:59:32 2012 +0900
@@ -0,0 +1,305 @@
+;;; isearch-ext.el --- incremental search with front-end inputting method
+
+;; Author: SAKAI Kiyotaka <ksakai@mtl.t.u-tokyo.ac.jp>
+;; Keywords: search
+
+;; $Id: isearch-ext.el,v 1.41 1994/12/16 15:33:34 ksakai Exp $
+
+;; This file is part of Mule.
+
+;; Mule is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; Mule is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+;;; Commentary:
+
+;; This program is extension of isearch.el to support multi-lingal
+;; incremental search with front-end input method.
+;;
+;; If you want to use this program, simply put C-\ or C-o or C-[ when
+;; doing incremental search, and you can input search words with
+;; inputting method.
+;;
+;; For backward compatibility with mule-1.x, you can also use C-k, but
+;; isearch-edit-string may be more suitable for this use.  If you
+;; think so, put the following code in your .emacs.
+;;
+;;   (define-key isearch-mode-map "\C-k" 'isearch-edit-string)
+;;
+
+;; Following people contributed modifications to isearch-ext.el:
+;;   Kenichi Handa <handa@etlken.etl.go.jp>
+;;   YAMAMOTO Mitsuharu <mituharu@is.s.u-tokyo.ac.jp>
+;;   A. Sasaki <beckun@cis.canon.co.jp>
+;;   Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp>
+
+;;; Code:
+
+;;(eval-when-compile (require 'quail))
+
+
+;;;###autoload
+(defvar search-string-char-prompt "*Enter string... ")
+
+(defvar isearch-fep-prompt "" "Prompt for isearch-fep mode.")
+(defvar isearch-fep-mode nil "If t, isearch-fep-mode is invoked.")
+
+(defconst isearch-fep-table
+  '((isearch-fep-string isearch-fep-prompt-string isearch-fep-read-string)
+    (isearch-fep-egg    isearch-fep-prompt-egg    isearch-fep-read-egg)
+    (isearch-fep-canna  isearch-fep-prompt-canna  isearch-fep-read-canna)
+    (isearch-fep-quail  isearch-fep-prompt-quail  isearch-fep-read-quail)))
+
+(define-key isearch-mode-map "\C-k"  'isearch-fep-string)
+(define-key isearch-mode-map "\C-\\" 'isearch-fep-egg)
+(define-key isearch-mode-map "\M-k"  'isearch-fep-egg)
+(define-key isearch-mode-map "\C-o"  'isearch-fep-canna)
+(define-key isearch-mode-map "\C-\]" 'isearch-fep-quail)
+
+(defun isearch-fep-mode ()
+  (let ((command this-command)
+	(isearch-fep-mode t)
+	table str)
+    (while isearch-fep-mode
+      (setq table (assq command isearch-fep-table))
+      (setq isearch-fep-prompt (funcall (car (cdr table))))
+      (message "%s%s" isearch-fep-prompt (isearch-message))
+      (if (eq command 'isearch-fep-string)    ;; \C-k
+	  (progn
+	    (setq str (funcall (nth 2 table)))
+	    (setq isearch-fep-mode nil)
+	    (isearch-process-search-string str str))
+	(let* ((keys (read-key-sequence nil))
+	       (current-command (key-binding keys t)))
+	  (setq isearch-fep-mode (not (eq command current-command)))
+	  (if isearch-fep-mode
+	      (if (assq current-command isearch-fep-table)
+		  (setq command current-command)
+		(cond ((eq current-command 'isearch-printing-char)
+		       (setq str (funcall (nth 2 table) keys))
+		       (isearch-process-search-string str str))
+		      ((or (eq current-command 'isearch-other-control-char)
+			   (eq current-command 'isearch-other-meta-char))
+		       (call-interactively current-command)
+		       (setq isearch-fep-mode nil))
+		      ((eq current-command 'isearch-exit)
+		       (setq isearch-fep-mode nil)
+		       (message "%s%s"
+				(isearch-message-prefix) isearch-message))
+		      (t
+		       (call-interactively current-command))))
+	    (setq isearch-fep-prompt nil)
+	    (message "%s%s" (isearch-message-prefix) isearch-message)))))))
+
+;;
+;;  Read string from minibuffer for incremental search.
+;;
+
+;;;###autoload
+(defun isearch-fep-string ()
+  "Read string from minibuffer for incremental search."
+  (interactive)
+  (isearch-fep-mode))
+
+(defun isearch-fep-prompt-string ()
+  search-string-char-prompt)
+
+(defun exit-minibuffer-and-isearch-backward ()
+  (interactive)
+  (setq unread-command-events '(?\C-r ?\C-r))
+  (exit-minibuffer))
+
+(defun isearch-fep-read-string ()
+  (let ((minibuffer-local-map (cons 'keymap minibuffer-local-map)))
+    ;; Some program overwrites "\C-m"'s default binding.
+    (define-key minibuffer-local-map "\C-m" 'exit-minibuffer)
+    (define-key minibuffer-local-map "\C-s" 'exit-minibuffer)
+    (define-key minibuffer-local-map "\C-r"
+      'exit-minibuffer-and-isearch-backward)
+    (condition-case condition
+	;; isearch.el of GNU Emacs 19.28 used overriding-local-map.
+	;; isearch.el of GNU Emacs 19.29, 19.30 (which is latest at
+	;; this point) uses overriding-terminal-local-map.  Disable
+	;; isearch keymap with binding it to nil.  We bind the map
+	;; here so that isearch-abort (actually, by isearch-done)
+	;; can set it to nil.
+	(let ((overriding-terminal-local-map nil))
+	  (read-from-minibuffer (concat isearch-fep-prompt (isearch-message))))
+      (quit
+       ;; Also, this isearch-abort should be called in original
+       ;; buffer, because the variable which always has buffer-local
+       ;; binding (at least isearch-mode is such variable) should be
+       ;; bound in right environment.
+       (isearch-abort)))))
+
+
+;;
+;;  For EGG
+;;
+
+;;;###autoload
+(defun isearch-fep-egg ()
+  "Read string for incremental search by using egg."
+  (interactive)
+  (isearch-fep-mode))
+
+(defun isearch-fep-prompt-egg ()
+  (if (featurep 'egg)
+      (format "[%s]" (map-indicator its:*current-map*))
+    (setq isearch-fep-mode nil)
+    (message "No EGG!! ")
+    (sit-for 1)
+    ""))
+
+(defun isearch-exit-minibuffer-egg (from to)
+  (exit-minibuffer))
+
+;; these variables are used to pass current-buffer's value of some
+;; buffer-local variable to minibuffer
+(defvar isearch-fep-egg-its-map nil)
+(defvar isearch-fep-egg-server-type nil)
+
+(defun isearch-minibuffer-setup-egg ()
+  ;; setup buffer-local variables for minibuffer
+  (setq its:*current-map* isearch-fep-egg-its-map)
+  (setq wnn-server-type isearch-fep-egg-server-type)
+  (setq egg:*input-mode* t)
+  (setq egg:*mode-on* t))
+
+(defun isearch-minibuffer-exit-egg ()
+  (setq egg:henkan-mode-in-use nil)
+  ;; Mule:
+  ;;(set 'disable-undo nil)
+  )
+
+(defun isearch-fep-read-egg (first-str)
+  (if (and (featurep 'egg) (= (minibuffer-depth) 0))
+      (let ((display-minibuffer-mode-in-minibuffer t)
+	    (isearch-fep-egg-its-map its:*current-map*)
+	    (isearch-fep-egg-server-type wnn-server-type)
+	    ;; In GNU Emacs 19.29 or later, isearch.el doesn't
+	    ;; make overriding-terminal-local-map buffer local.
+	    ;; So we must bind explicitly it to nil to disable it
+	    ;; while reading from minibuffer.
+	    (overriding-terminal-local-map nil)
+	    (self-insert-after-hook 'isearch-exit-minibuffer-egg))
+	(setq unread-command-events (listify-key-sequence first-str))
+	(unwind-protect
+	    (progn
+	      (add-hook 'minibuffer-setup-hook 'isearch-minibuffer-setup-egg)
+	      (add-hook 'minibuffer-exit-hook 'isearch-minibuffer-exit-egg)
+	      (read-from-minibuffer (isearch-message)))
+	  (remove-hook 'minibuffer-setup-hook 'isearch-minibuffer-setup-egg)
+	  (remove-hook 'minibuffer-exit-hook 'isearch-minibuffer-exit-egg)))
+    ""))
+
+
+;;
+;;  For Canna
+;;
+
+(eval-when-compile
+  (autoload 'canna:quit-canna-mode "canna"))
+
+;;;###autoload
+(defun isearch-fep-canna ()
+  "Read string for incremental search by using canna."
+  (interactive)
+  (unwind-protect
+      (isearch-fep-mode)
+    (canna:quit-canna-mode)))
+
+(eval-when-compile
+  (defvar canna:*initialized*)
+  (defvar canna:*kanji-mode-string*))
+
+(defun isearch-fep-prompt-canna ()
+  (if (and (featurep 'canna) canna:*initialized*)
+      (format "%s" canna:*kanji-mode-string*)
+    (setq isearch-fep-mode nil)
+    (message "No Canna!! ")
+    (sit-for 1)
+    ""))
+
+(defun isearch-exit-minibuffer-canna (from to)
+  (exit-minibuffer))
+
+(eval-when-compile
+  (defvar canna:*japanese-mode*)
+  (defvar canna:*japanese-mode-in-minibuffer*)
+  (defvar canna:*fence-mode*))
+
+(defun isearch-minibuffer-setup-canna ()
+  ;; setup buffer-local variables for minibuffer.
+  (setq canna:*japanese-mode* t
+	canna:*japanese-mode-in-minibuffer* t
+	canna:*fence-mode* nil))
+
+(defun isearch-minibuffer-exit-canna ()
+  ;; Mule:
+  ;;(set 'disable-undo nil)
+  )
+
+(defun isearch-fep-read-canna (first-str)
+  (if (and (featurep 'canna) (= (minibuffer-depth) 0))
+      (let ((display-minibuffer-mode-in-minibuffer t)
+	    ;; See comment in isearch-fep-read-egg.
+	    (overriding-terminal-local-map nil)
+	    (self-insert-after-hook 'isearch-exit-minibuffer-canna))
+	(setq unread-command-events (listify-key-sequence first-str))
+	(unwind-protect
+	    (progn
+	      (add-hook 'minibuffer-setup-hook 'isearch-minibuffer-setup-canna)
+	      (add-hook 'minibuffer-exit-hook 'isearch-minibuffer-exit-canna)
+	      (read-from-minibuffer (isearch-message)))
+	  (remove-hook 'minibuffer-setup-hook 'isearch-minibuffer-setup-canna)
+	  (remove-hook 'minibuffer-exit-hook 'isearch-minibuffer-exit-canna)))
+    ""))
+
+
+;;
+;;  For QUAIL
+;;
+
+;;;###autoload
+(defun isearch-fep-quail ()
+  "Read string for incremental search by using quail."
+  (interactive)
+  (require 'quail)
+  (isearch-fep-mode))
+
+(defun isearch-fep-prompt-quail ()
+  "[QUAIL]")
+
+(defun isearch-exit-minibuffer-quail ()
+  (if (or (symbol-value 'quail-current-key)
+	  (symbol-value 'quail-current-str))
+      nil
+    (exit-minibuffer)))
+
+(defun isearch-fep-read-quail (first-str)
+  (let ((quail-self-insert-after-hook 'isearch-exit-minibuffer-quail)
+	;; See comment in isearch-fep-read-egg.
+	(overriding-terminal-local-map nil))
+    (setq unread-command-events (cons ?\C-\] (listify-key-sequence first-str)))
+    (unwind-protect
+	(read-from-minibuffer
+	 (concat isearch-fep-prompt (isearch-message)))
+      ;; Mule:
+      ;;(set 'disable-undo nil)
+      )))
+
+
+(provide 'isearch-ext)
+;;; isearch-ext.el ends here
+
diff -r 08c8dbbb056a lisp/loadup.el
--- a/lisp/loadup.el	Thu Jun 14 18:19:18 2012 +0900
+++ b/lisp/loadup.el	Thu Jun 14 21:59:32 2012 +0900
@@ -175,6 +175,7 @@
       (load "select")))
 (load "emacs-lisp/timer")
 (load "isearch")
+(load "isearch-ext")
 (load "rfn-eshadow")
 
 (load "menu-bar")
@@ -241,6 +242,11 @@
 (load "vc/ediff-hook")
 (if (fboundp 'x-show-tip) (load "tooltip"))
 
+(if (boundp 'CANNA)
+    (progn
+      (autoload 'canna "canna" nil t nil)
+      (garbage-collect)))
+
 ;If you want additional libraries to be preloaded and their
 ;doc strings kept in the DOC file rather than in core,
 ;you may load them with a "site-load.el" file.
diff -r 08c8dbbb056a lisp/subr.el
--- a/lisp/subr.el	Thu Jun 14 18:19:18 2012 +0900
+++ b/lisp/subr.el	Thu Jun 14 21:59:32 2012 +0900
@@ -515,6 +515,9 @@
 Normally, as an exception, digits and minus-sign are set to make prefix args,
 but optional second arg NODIGITS non-nil treats them like other chars."
   (define-key map [remap self-insert-command] 'undefined)
+  (when (boundp 'CANNA)
+    (define-key map [remap canna-self-insert-command] 'undefined)
+    (define-key map [remap can-n-egg-self-insert-command] 'undefined))
   (or nodigits
       (let (loop)
 	(define-key map "-" 'negative-argument)
diff -r 08c8dbbb056a lisp/textmodes/picture.el
--- a/lisp/textmodes/picture.el	Thu Jun 14 18:19:18 2012 +0900
+++ b/lisp/textmodes/picture.el	Thu Jun 14 21:59:32 2012 +0900
@@ -163,6 +163,28 @@
   (interactive)
   (picture-set-motion 1 0))
 
+;;; 89.9.7  patch by K.Handa
+(defun picture-movement-wnw ()
+  "Move up and left and left after self-inserting character in Picture mode."
+  (interactive)
+  (picture-set-motion -1 -2))
+
+(defun picture-movement-ene ()
+  "Move up and right and right after self-inserting character in Picture mode."
+  (interactive)
+  (picture-set-motion -1 2))
+
+(defun picture-movement-wsw ()
+  "Move down and left and left after self-inserting character in Picture mode."
+  (interactive)
+  (picture-set-motion 1 -2))
+
+(defun picture-movement-ese ()
+  "Move down and right and right after self-inserting character in Picture mode."
+  (interactive)
+  (picture-set-motion 1 2))
+;;; end of patch
+
 (defun picture-movement-nw (&optional arg)
   "Move up and left after self-inserting character in Picture mode.
 With prefix argument, move up and two-column left."
@@ -285,6 +307,70 @@
   (picture-update-desired-column (not (eq this-command last-command)))
   (picture-insert last-command-event arg)) ; Always a character in this case.
 
+;;; 89.9.7  by K.Handa
+(defun picture-insert-after-hook (begin end)
+  "Called as a hook after a string is inserted into the current buffer.
+Two arguments BEGIN and END point the head and tail of just inserted string."
+  (let ((str (buffer-substring begin end)))
+    (delete-region begin end)
+    (picture-insert-string str)))
+
+(defun picture-delete-text-in-column (from to)
+  "Delete the text between column FROM and TO (exclusive) of the current line.
+Nil of FORM or TO means the current column.
+If there's a charcter across the borders, the character is replaced with
+the same width of spaces before deleting."
+  (save-excursion
+    (let (p1 p2)
+      (if from
+         (progn
+           (setq p1 (move-to-column from))
+           (if (> p1 from)
+               (progn
+                 (delete-char -1)
+                 (insert-char ?  (- p1 (current-column)))
+                 (forward-char (- from p1))))))
+      (setq p1 (point))
+      (if to
+         (progn
+           (setq p2 (move-to-column to))
+           (if (> p2 to)
+               (progn
+                 (delete-char -1)
+                 (insert-char ?  (- p2 (current-column)))
+                 (forward-char (- to p2))))))
+      (setq p2 (point))
+      (delete-region p1 p2))))
+
+(defun picture-insert-string (str)	; 91.11.25, 92.7.10 by K.Handa
+  "Insert characters in STR one by one in place of character previously
+at the cursor while moving cursor in the direction you previously specified
+with the commands picture-movement-right, picture-movement-up, etc.
+Do \\[command-apropos]  picture-movement  to see those commands."
+  (interactive "sInsert string: ")
+  (let  ((len (length str)))
+    (if (> len 0)
+	(let* ((idx 0)
+	       (c (aref str idx))
+	       (width (char-width c))
+	       clm)
+	  (while idx				; Set to nil at the end of loop
+	    (setq clm (current-column))
+	    (picture-delete-text-in-column clm (+ clm width))
+	    (insert c)
+	    (forward-char -1)
+	    (setq idx (1+ idx))
+	    (if (< idx len)
+		(setq c (aref str idx) width (char-width c))
+	      (setq idx nil))
+	    (if (/= picture-vertical-step 0)
+		(picture-move)
+	      (if (> picture-horizontal-step 0)
+		  (forward-char 1)
+		(move-to-column-force (- clm width))))
+	    )))))
+;;; end of patch
+
 (defun picture-clear-column (arg)
   "Clear out ARG columns after point without moving."
   (interactive "p")
@@ -614,11 +700,17 @@
 (if (not picture-mode-map)
     (progn
       (setq picture-mode-map (make-keymap))
-      (picture-substitute 'self-insert-command 'picture-self-insert)
-      (picture-substitute 'completion-separator-self-insert-command
-			  'picture-self-insert)
-      (picture-substitute 'completion-separator-self-insert-autofilling
-			  'picture-self-insert)
+      (let ((picture-self-insert (cond ((featurep 'canna)
+					'canna-self-insert-command)
+				       ((boundp 'EGG) ; 89.9.7 by K.Handa
+					'egg-self-insert-command)
+				       (t
+					'picture-self-insert))))
+	(picture-substitute 'self-insert-command picture-self-insert)
+	(picture-substitute 'completion-separator-self-insert-command
+			    picture-self-insert)
+	(picture-substitute 'completion-separator-self-insert-autofilling
+			    picture-self-insert))
       (picture-substitute 'forward-char 'picture-forward-column)
       (picture-substitute 'backward-char 'picture-backward-column)
       (picture-substitute 'delete-char 'picture-clear-column)
@@ -652,6 +744,13 @@
       (define-key picture-mode-map "\C-c>" 'picture-movement-right)
       (define-key picture-mode-map "\C-c^" 'picture-movement-up)
       (define-key picture-mode-map "\C-c." 'picture-movement-down)
+      ;;; 89.9.7 by K.Handa
+      (define-key picture-mode-map "\C-ck" 'picture-insert-string)
+      (define-key picture-mode-map "\C-c~" 'picture-movement-wnw)
+      (define-key picture-mode-map "\C-c\"" 'picture-movement-ene)
+      (define-key picture-mode-map "\C-c?" 'picture-movement-wsw)
+      (define-key picture-mode-map "\C-c|" 'picture-movement-ese)
+      ;;; end of patch
       (define-key picture-mode-map "\C-c`" 'picture-movement-nw)
       (define-key picture-mode-map "\C-c'" 'picture-movement-ne)
       (define-key picture-mode-map "\C-c/" 'picture-movement-sw)
@@ -675,6 +774,8 @@
 (defvar picture-mode-old-mode-name)
 (defvar picture-mode-old-major-mode)
 (defvar picture-mode-old-truncate-lines)
+(defvar picture-mode-old-self-insert-after-hook)
+(defvar self-insert-after-hook)
 
 ;;;###autoload
 (defun picture-mode ()
@@ -761,6 +862,13 @@
 	 (default-value 'picture-tab-chars))
     (make-local-variable 'picture-vertical-step)
     (make-local-variable 'picture-horizontal-step)
+    ;;; 89.9.17  patch by K.Handa
+    (set (make-local-variable 'picture-mode-old-self-insert-after-hook)
+	 (if (boundp 'self-insert-after-hook)
+	     self-insert-after-hook))
+    (set (make-local-variable 'self-insert-after-hook)
+	 'picture-insert-after-hook)
+    ;;; end of patch
     (set (make-local-variable 'picture-mode-old-truncate-lines) truncate-lines)
     (setq truncate-lines t)
     (picture-set-motion 0 1)
@@ -786,6 +894,9 @@
     (setq mode-name picture-mode-old-mode-name)
     (use-local-map picture-mode-old-local-map)
     (setq major-mode picture-mode-old-major-mode)
+    ;;; 89.9.17  patch by K.Handa
+    (setq self-insert-after-hook picture-mode-old-self-insert-after-hook)
+    ;;; end of patch
     (kill-local-variable 'tab-stop-list)
     (setq truncate-lines picture-mode-old-truncate-lines)
     (force-mode-line-update)
diff -r 08c8dbbb056a src/Makefile.in
--- a/src/Makefile.in	Thu Jun 14 18:19:18 2012 +0900
+++ b/src/Makefile.in	Thu Jun 14 21:59:32 2012 +0900
@@ -109,9 +109,10 @@
 ## contains options that have to do with using Emacs's crt0,
 ## which are only good with temacs.
 LD_SWITCH_SYSTEM_TEMACS=@LD_SWITCH_SYSTEM_TEMACS@
+LD_SWITCH_CANNA = @LD_SWITCH_CANNA@
 
 ## Flags to pass to ld only for temacs.
-TEMACS_LDFLAGS = $(LD_SWITCH_SYSTEM) $(LD_SWITCH_SYSTEM_TEMACS)
+TEMACS_LDFLAGS = $(LD_SWITCH_SYSTEM) $(LD_SWITCH_SYSTEM_TEMACS) $(LD_SWITCH_CANNA)
 
 ## $LDFLAGS or empty if NS_IMPL_GNUSTEP (for some reason).
 TEMACS_LDFLAGS2 = @TEMACS_LDFLAGS2@
@@ -272,6 +273,10 @@
 LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
 LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@
 
+LIBS_MULE = @LIBS_MULE@
+C_SWITCH_CANNA = @C_SWITCH_CANNA@
+CANNA_OBJ = @CANNA_OBJ@
+
 LIB_PTHREAD_SIGMASK = @LIB_PTHREAD_SIGMASK@
 
 INTERVALS_H = dispextern.h intervals.h composite.h
@@ -313,6 +318,7 @@
   $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
   $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) $(PROFILING_CFLAGS) \
   $(LIBGNUTLS_CFLAGS) \
+  $(C_SWITCH_CANNA) \
   $(C_WARNINGS_SWITCH) $(CFLAGS)
 ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS)
 
@@ -324,6 +330,26 @@
 	@$(MKDEPDIR)
 	$(CC) -c $(CPPFLAGS) $(ALL_OBJC_CFLAGS) $<
 
+#ifdef CANNA
+#  define CANNA_OBJ canna.o
+#else /* not CANNA */
+#  define CANNA_OBJ
+#endif /* not CANNA */
+
+#ifdef CANNA
+#define CANNA_SUPPORT ${lispsource}canna.elc
+#define CANNA_ELC  ${dotdot}/lisp/canna.elc
+#else
+#define CANNA_SUPPORT
+#define CANNA_ELC
+#endif
+
+#define MULE_SUPPORT_EXTRA \
+       CANNA_SUPPORT
+
+#define MULE_SOME_MACHINE_LISP \
+       CANNA_ELC
+
 
 ## lastfile must follow all files whose initialized data areas should
 ## be dumped as pure by dump-emacs.
@@ -339,6 +365,7 @@
 	syntax.o $(UNEXEC_OBJ) bytecode.o \
 	process.o gnutls.o callproc.o \
 	region-cache.o sound.o atimer.o \
+	$(CANNA_OBJ) \
 	doprnt.o intervals.o textprop.o composite.o xml.o \
 	$(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ)
 obj = $(base_obj) $(NS_OBJC_OBJ)
@@ -389,6 +416,7 @@
    $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
    $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
    $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \
+   $(LIBS_MULE) \
    $(LIB_GCC) $(LIB_MATH) $(LIB_STANDARD) $(LIB_GCC)
 
 all: emacs$(EXEEXT) $(OTHER_FILES)
diff -r 08c8dbbb056a src/canna.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/canna.c	Thu Jun 14 21:59:32 2012 +0900
@@ -0,0 +1,1598 @@
+/* CANNA interface for GNU Emacs 24 or later(?)
+
+   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1996,1997,1999 MORIOKA Tomohiko
+
+   This file is not part of GNU Emacs.
+   
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Emacs; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+
+  Authors: Akira Kon (kon@d1.bs2.mt.nec.co.jp)
+           Ichiro Hirakura (hirakura@uxp.bs2.mt.nec.co.jp)
+	   modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
+
+  Functions defined in this file are
+
+  (canna-key-proc key)
+ 		key: single STRING
+ 		RETURNS:
+			 Length of converted string if no error occurs.
+			 Error string if error occurs.
+ 		DESCRIPTION:
+			 Convert a key input to a set of strings.  The
+			 strings contain both well-formed string and a
+			 intermediate result to show the translation
+			 information to a user.  converted strings are
+			 stored in specific variables.
+
+  (canna-initialize)
+  		RETURNS:
+			List of the following things:
+			- list of keys to toggle Japanese-mode
+			- error message
+			- list of warning messages
+		DESCRIPTION:
+			Initialize ``canna'', which is a kana-to-kanji
+			converter for GNU Emacs.  The first arg
+			specifies if inserting space character between
+			BUNSETSU when candidates are displayed.  The
+			second arg specifies server.  The third arg
+			specifies a file which will be used as a
+			customization description.  If nil is
+			specified for each arg, the default value will
+			be used.
+
+  (canna-finalize)
+		RETURNS:
+			list of warning messages
+		DESCRIPTION:
+			finalize ``canna'', which is a kana-to-kanji
+			converter for GNU Emacs.  This cause to write
+			miscellaneous informations to kana-to-kanji
+			dictionary.
+
+  (canna-touroku-string string)
+		string:
+			String to register to a dictionary.
+		RETURNS:
+			The same thing returns as canna-key-proc does.
+		DESCRIPTION:
+			Register Kanji words into kana-to-kanji
+			conversion dictionary.
+
+  (canna-set-width width)
+		width:
+			Column width of the place where the candidates
+			of kana-to-kanji conversion will be shown.
+		RETURNS:
+			nil
+		DESCRIPTION:
+			Set status-line width information, which is
+			used to display kanji candidates.
+
+  (canna-change-mode num)
+		num:
+			The mode number of Canna.
+		RETURNS:
+			The same thing returns as canna-key-proc does.
+		DESCRIPTION:
+			Change Japanese pre-edit mode.
+
+  (canna-store-yomi yomi roma)
+		yomi:
+			``Yomi'' to be stored.
+		roma:
+			``Romaji'' which corresponds to the ``Yomi''.
+		RETURNS:
+			The same thing returns as canna-key-proc does.
+		DESCRIPTION:
+			Store yomi characters as a YOMI of
+			kana-to-kanji conversion.
+
+  (canna-do-function num ch)
+		num:
+			A function number to be called.
+		ch:
+			A character will be specified in order to feed
+			the character to the function if the function
+			needs a input character.
+		RETURNS:
+			The same thing returns as canna-key-proc does.
+		DESCRIPTION:
+			Do specified function at current mode.
+
+  (canna-parse string)
+		string:
+			To be parsed.
+		RETURNS:
+			List of warning messages.
+		DESCRIPTION:
+			Parse customize string.
+
+  (canna-query-mode)
+		RETURNS:
+			A string which indicate the current mode.
+		DESCRIPTION:
+			Get current mode string.
+
+  Functions below are used for KKCP compatible library.  These
+  functions provides a base kana-to-kanji conversion system for EGG.
+  These functions may be used when users want to change the engine
+  from Wnn to Canna without changing user interface of Japanese input.
+
+  (canna-henkan-begin)
+  (canna-henkan-next)
+  (canna-bunsetu-henkou)
+  (canna-henkan-kakutei)
+  (canna-henkan-end)
+  (canna-henkan-quit)
+
+ */
+
+#ifndef lint
+static char rcs_id[] = "$Id: canna.c,v 1.36 1999/03/02 18:52:41 morioka Exp $";
+#endif
+
+#include <stdio.h>
+#include <setjmp.h>
+
+#ifdef CANNA_EMACS_DL
+#define HAVE_DYNAMIC_LOADER
+#endif
+
+#include "config.h"
+#include "lisp.h"
+#include "buffer.h"
+#include "charset.h"
+
+#define ISO_CODE_SS2 0x8E	/* defined in  coding.c */
+#define ISO_CODE_SS3 0x8F	/* defined in  coding.c */
+
+#define CANNA3_7
+#ifdef CANNA3_7
+# define CANNA_NEW_WCHAR_AWARE
+#endif
+
+#define IROHA_BC
+#include "canna/jrkanji.h"
+#include "canna/RK.h"
+
+#ifndef CANNA3_7
+extern char *jrKanjiError;
+#endif
+
+#define KEYTOSTRSIZE 2048
+static unsigned char buf[KEYTOSTRSIZE];
+static char **warning;
+
+static int IRCP_context;
+
+#if __STDC__
+static Lisp_Object storeResults(unsigned char *, int, jrKanjiStatus *);
+static Lisp_Object kanjiYomiList(int, int);
+#else
+static Lisp_Object storeResults();
+static Lisp_Object kanjiYomiList();
+#endif
+
+#if __STDC__
+static Lisp_Object mule_make_string(unsigned char *, int);
+static mule_strlen(unsigned char *, int);
+static count_char(unsigned char *,int, int, int, int *, int *, int *);
+#else /* __STDC__ */
+static Lisp_Object mule_make_string();
+static mule_strlen();
+static count_char();
+#endif /* __STDC__ */
+
+/* Lisp functions definition */
+
+DEFUN ("canna-key-proc", Fcanna_key_proc, Scanna_key_proc,
+       1, 1, 0,
+       doc: /* Translate a key input CH to a set of strings.
+The strings contain both well-formed string and intermediate result
+to show the translation information to a user.  Converted strings are
+stored in specific variables.
+
+Return the length of converted string if no error occurs, while
+the error string if error occurs.  */)
+	(ch)
+Lisp_Object ch;
+{
+  jrKanjiStatus ks;
+  int len;
+
+  CHECK_NUMBER (ch);
+  len = jrKanjiString(0, XINT (ch), buf, KEYTOSTRSIZE, &ks);
+  return storeResults(buf, len, &ks);
+}
+
+static
+Lisp_Object
+storeResults(buf, len, ks)
+unsigned char *buf;
+int len;
+jrKanjiStatus *ks;
+{
+  Lisp_Object val = Qnil;
+
+  if (len < 0) { /* Error detected */
+    val = mule_make_string((unsigned char*)jrKanjiError, strlen(jrKanjiError));
+  }
+  else {
+    /* 確定した文字列 */
+    Vcanna_kakutei_string = mule_make_string(buf, len);
+    val = make_number(len);
+    /* 確定した文字列の読みの情報... */
+    Vcanna_kakutei_yomi = Vcanna_kakutei_romaji = Qnil;
+    if (ks->info & KanjiYomiInfo) {
+      unsigned char *p = buf + len + 1;
+      int yomilen = strlen(p);
+
+      if (len + yomilen + 1 < KEYTOSTRSIZE) {
+	int yomilen2;
+
+	Vcanna_kakutei_yomi = mule_make_string(p, yomilen); /* 読み */
+	p += yomilen + 1;
+	yomilen2 = strlen(p);
+	if (len + yomilen + yomilen2 + 2 < KEYTOSTRSIZE) {
+	  Vcanna_kakutei_romaji = mule_make_string(p, yomilen2); /* ローマ字 */
+	}
+      }
+    }
+
+
+    /* 候補表示の文字列です。*/
+    Vcanna_henkan_string = Qnil;
+    if (ks->length >= 0) {
+      Vcanna_henkan_string = mule_make_string(ks->echoStr, ks->length);
+      if (canna_underline) {
+	canna_henkan_length = mule_strlen(ks->echoStr,ks->length);
+	canna_henkan_revPos = mule_strlen(ks->echoStr,ks->revPos);
+	canna_henkan_revLen = mule_strlen(ks->echoStr+ks->revPos,ks->revLen);
+      }
+      else {
+	count_char(ks->echoStr, ks->length, ks->revPos, ks->revLen,
+		   &canna_henkan_length, &canna_henkan_revPos,
+		   &canna_henkan_revLen);
+      }
+    }
+
+    /* 一覧の情報 */
+    Vcanna_ichiran_string = Qnil;
+    if (ks->info & KanjiGLineInfo && ks->gline.length >= 0) {
+      Vcanna_ichiran_string = mule_make_string(ks->gline.line, ks->gline.length);
+      count_char(ks->gline.line, ks->gline.length,
+		 ks->gline.revPos, ks->gline.revLen, &canna_ichiran_length,
+		 &canna_ichiran_revPos, &canna_ichiran_revLen);
+    }
+
+    /* モードの情報 */
+    Vcanna_mode_string = Qnil;
+    if (ks->info & KanjiModeInfo) {
+      Vcanna_mode_string = mule_make_string(ks->mode, strlen(ks->mode));
+    }
+
+    /* その他の情報 */
+    canna_empty_info = (ks->info & KanjiEmptyInfo) ? 1 : 0;
+    canna_through_info = (ks->info & KanjiThroughInfo) ? 1 : 0;
+  }
+
+  return val;
+}
+
+DEFUN ("canna-set-bunsetsu-kugiri", Fcanna_set_bunsetsu, Scanna_set_bunsetsu,
+       0, 1, 0,
+       doc: /* Set the clause separator.
+
+Optional arg NUM non-nil means the white space separator will be used.
+No separator will be used otherwise.  */)
+     (num)
+     Lisp_Object num;
+{
+  int kugiri; /* 文節区切りをするか？ */
+
+  kugiri = NILP(num) ? 0 : 1;
+
+  jrKanjiControl(0, KC_SETBUNSETSUKUGIRI, (char *)kugiri);
+
+  return Qnil;
+}
+
+/*
+ * Mule-canna.c of XEmacs-21.4.14 reads
+ * "For whatever reason, calling Fding directly from libCanna loses".
+ * In any case following glue is needed for new jrBeepFunc prototype.
+ */
+static int
+call_Fding (void)
+{
+  Fding (Qnil);
+  return 0;
+}
+
+DEFUN ("canna-initialize", Fcanna_initialize, Scanna_initialize, 0, 3, 0,
+       doc: /* Initialize ``canna'', which is a kana-to-kanji converter for GNU Emacs.
+
+Optional first arg NUM non-nil means space character is inserted
+between clause when candidates are displayed.
+
+Optional second arg SERVER specifies canna server.
+
+Optional third arg RCFILE specifies a file of personal
+customization of canna.
+
+If nil is specified for each arg, the default value will be used.
+
+Return a list consisting of the following elements.
+- list of keys to toggle Japanese-mode
+- error message
+- list of warning messages
+*/)
+(num, server, rcfile)
+Lisp_Object num, server, rcfile;
+{
+  Lisp_Object val;
+  int res;
+  unsigned char **p, **q;
+
+  int kugiri; /* 文節区切りをするか？ */
+
+  IRCP_context = -1;
+
+  if (NILP(num)) {
+    kugiri = 1;
+  }
+  else {
+    CHECK_NUMBER(num);
+    kugiri = XINT(num);
+    kugiri = (kugiri == 1) ? 1 : 0;
+  }
+
+  if (NILP(server)) {
+    jrKanjiControl(0, KC_SETSERVERNAME, (char *)0);
+  }
+  else {
+    char servername[256];
+
+    CHECK_STRING(server);
+    strncpy(servername, XSTRING(server)->data, XSTRING(server)->size);
+    servername[XSTRING(server)->size] = '\0';
+    jrKanjiControl(0, KC_SETSERVERNAME, servername);
+  }
+
+  if (NILP(rcfile)) {
+    jrKanjiControl(0, KC_SETINITFILENAME, (char *)0);
+  }
+  else {
+    char rcname[256];
+
+    CHECK_STRING(rcfile);
+    strncpy(rcname, XSTRING(rcfile)->data, XSTRING(rcfile)->size);
+    rcname[XSTRING(rcfile)->size] = '\0';
+    jrKanjiControl(0, KC_SETINITFILENAME, rcname);
+  }
+
+  warning = (char **)0;
+#ifdef nec_ews_svr4				/* hir, 1994.2.24 */
+  stop_polling ();
+#endif /* nec_ews_svr4 */
+  res = jrKanjiControl(0, KC_INITIALIZE, (char *)&warning);
+#ifdef nec_ews_svr4				/* hir, 1994.2.24 */
+  start_polling ();
+#endif /* nec_ews_svr4 */
+  val = Qnil;
+  if (warning) {
+    for (p = q = (unsigned char **)warning ; *q ; q++)
+      ;
+    while (p < q) {
+      q--;
+      val = Fcons(mule_make_string(*q, strlen(*q)), val);
+    }
+  }
+  val = Fcons(val, Qnil);
+
+  if (res == -1) {
+    val = Fcons(mule_make_string((unsigned char*)jrKanjiError, 
+			    strlen(jrKanjiError)), val);
+    /* イニシャライズで失敗した場合。 */
+    return Fcons(Qnil, val);
+  }
+  else {
+#ifndef CANNA_JR_BEEP_FUNC_DECLARED
+    extern int (*jrBeepFunc) (void);
+#endif
+    Lisp_Object Fding(), CANNA_mode_keys();
+
+    jrBeepFunc = call_Fding;
+
+#ifdef KC_SETAPPNAME
+    wcKanjiControl(0, KC_SETAPPNAME, "Emacs24");
+#endif /* KC_SETAPPNAME */
+
+    jrKanjiControl(0, KC_SETBUNSETSUKUGIRI, (char *)kugiri);
+    jrKanjiControl(0, KC_SETWIDTH, (char *)78);
+    /* mule だったら半角カタカナも使える */
+    if (canna_inhibit_hankakukana)
+      jrKanjiControl(0, KC_INHIBITHANKAKUKANA, (char *)1);
+    jrKanjiControl(0, KC_YOMIINFO, (char *)2); /* ※２: ローマ字まで返す */
+    val = Fcons(Qnil, val);
+    return Fcons(CANNA_mode_keys(), val);
+  }
+}
+
+DEFUN ("canna-finalize", Fcanna_finalize, Scanna_finalize, 0, 0, 0,
+       doc: /* Finalize ``canna'', which is a kana-to-kanji converter for GNU Emacs.
+Write miscellaneous informations to kana-to-kanji dictionary.
+
+Return nil or a list of warning messages if exists.  */)
+(void)
+{
+  Lisp_Object val;
+  unsigned char **p;
+
+  jrKanjiControl(0, KC_FINALIZE, (char *)&warning);
+
+  val = Qnil;
+  if (warning) {
+    for (p = (unsigned char**)warning ; *p ; p++) {
+      val = Fcons(mule_make_string(*p, strlen(*p)), val);
+    }
+  }
+  val = Fcons(val, Qnil);
+  IRCP_context = -1;
+  return val;
+}
+
+DEFUN ("canna-touroku-string", Fcanna_touroku_string, 
+       Scanna_touroku_string, 1, 1, 0,
+       doc: /* Register Kanji words STR into kana-to-kanji conversion dictionary.
+
+Return the same thing as `canna-key-proc'.  */)
+	(str)
+Lisp_Object str;
+{
+  jrKanjiStatusWithValue ksv;
+  jrKanjiStatus ks;
+  int len;
+  Lisp_Object val;
+  unsigned char cbuf[4096];
+
+  CHECK_STRING(str);
+  ksv.buffer = (unsigned char *)buf;
+  ksv.bytes_buffer = KEYTOSTRSIZE;
+  str = code_convert_string(str, Vcanna_coding_system, Qnil, 1, 1, 1);
+  bcopy(XSTRING(str)->data, cbuf, SBYTES (str));
+  cbuf[SBYTES (str)] = 0;
+  ks.echoStr = cbuf;
+  ks.length = strlen(cbuf);
+  ksv.ks = &ks;
+  len = jrKanjiControl(0, KC_DEFINEKANJI, (char *)&ksv);
+  val = storeResults(buf, ksv.val, ksv.ks);
+  return val;
+}
+
+DEFUN ("canna-set-width", Fcanna_set_width,
+       Scanna_set_width, 1, 1, 0,
+       doc: /* Set status-line width to NUM to display kanji candidates.  */)
+	(num)
+Lisp_Object num;
+{
+  CHECK_NUMBER(num);
+
+  jrKanjiControl(0, KC_SETWIDTH,  (char *)XINT (num));
+  return Qnil;
+}
+
+DEFUN ("canna-change-mode", Fcanna_change_mode,
+       Scanna_change_mode, 1, 1, 0,
+       doc: /* Change Japanese pre-edit mode to NUM-th mode.
+
+Return the same thing as `canna-key-proc'.  */)
+	(num)
+Lisp_Object num;
+{
+  jrKanjiStatusWithValue ksv;
+  jrKanjiStatus ks;
+  Lisp_Object val;
+
+  CHECK_NUMBER(num);
+
+  ksv.buffer = (unsigned char *)buf;
+  ksv.bytes_buffer = KEYTOSTRSIZE;
+  ksv.ks = &ks;
+  ksv.val = XINT (num);
+  jrKanjiControl(0, KC_CHANGEMODE,  (char *)&ksv);
+  val = storeResults(buf, ksv.val, ksv.ks);
+  return val;
+}
+
+Lisp_Object
+CANNA_mode_keys()
+{
+#define CANNAWORKBUFSIZE 32
+  char xxx[CANNAWORKBUFSIZE];
+  Lisp_Object val;
+  int i, n;
+
+  n = jrKanjiControl(0, KC_MODEKEYS, xxx);
+  val = Qnil;
+  for (i = n ; i > 0 ;) {
+    --i;
+    val = Fcons(make_number((int)(0xFF & (unsigned char)xxx[i])), val);
+  }
+  return val;
+}
+
+DEFUN ("canna-store-yomi", Fcanna_store_yomi, Scanna_store_yomi, 
+       1, 2, 0,
+       doc: /* Store the yomi characters YOMI on canna.
+Optional arg ROMA is the roman spell of YOMI.
+
+Return the same thing as `canna-key-proc'.  */)
+	(yomi, roma)
+Lisp_Object yomi, roma;
+{
+  jrKanjiStatusWithValue ksv;
+  jrKanjiStatus ks;
+
+  CHECK_STRING(yomi);
+  yomi = code_convert_string(yomi, Vcanna_coding_system, Qnil, 1, 1, 1);
+  bcopy(XSTRING(yomi)->data, buf, SBYTES (yomi));
+  buf[SBYTES (yomi)] = 0;
+  ks.length = strlen(buf);
+
+  if (NILP(roma)) {
+    ks.mode = 0;
+  }
+  else {
+    CHECK_STRING(roma);
+
+    ks.mode = (unsigned char *)(buf + ks.length + 1);
+    roma = code_convert_string(roma, Vcanna_coding_system, Qnil, 1, 1, 1);
+    bcopy(XSTRING(roma)->data, ks.mode, SBYTES (roma));
+    ks.mode[SBYTES (roma)] = 0;
+  }
+
+  ks.echoStr = (unsigned char *)buf;
+  ksv.buffer = (unsigned char *)buf; /* 返値用 */
+  ksv.bytes_buffer = KEYTOSTRSIZE;
+  ksv.ks = &ks;
+
+  jrKanjiControl(0, KC_STOREYOMI, (char *)&ksv);
+
+  return storeResults(buf, ksv.val, ksv.ks);
+}
+
+DEFUN ("canna-do-function", Fcanna_do_function, Scanna_do_function, 
+       1, 2, 0,
+       doc: /* Do NUM-th canna function at the current mode.
+Key input is feeded as optional arg CH, for the function which
+needs input character.
+
+Return the same thing as `canna-key-proc'.  */)
+	(num, ch)
+Lisp_Object num, ch;
+{
+  jrKanjiStatusWithValue ksv;
+  jrKanjiStatus ks;
+  Lisp_Object val;
+
+  CHECK_NUMBER(num);
+
+  if (NILP(ch)) {
+    *buf = '@';
+  }
+  else {
+    CHECK_NUMBER(ch);
+    *buf = XINT (ch);
+  }
+
+  ksv.buffer = (unsigned char *)buf;
+  ksv.bytes_buffer = KEYTOSTRSIZE;
+  ksv.ks = &ks;
+  ksv.val = XINT (num);
+  jrKanjiControl(0, KC_DO,  (char *)&ksv);
+  val = storeResults(buf, ksv.val, ksv.ks);
+  return val;
+}
+
+DEFUN ("canna-parse", Fcanna_parse, Scanna_parse, 
+       1, 1, 0,
+       doc: /* Parse string STR as canlisp to customize canna setting.
+
+Return nil or list of warning messages if exists.  */)
+	(str)
+Lisp_Object str;
+{
+  jrKanjiStatusWithValue ksv;
+  jrKanjiStatus ks;
+  Lisp_Object val;
+  unsigned char **p;
+  int n;
+
+  CHECK_STRING(str);
+
+  str = code_convert_string(str, Vcanna_coding_system, Qnil, 1, 1, 1);
+  bcopy(XSTRING(str)->data, buf, SBYTES (str));
+  buf[SBYTES (str)] = 0;
+  p = (unsigned char**)buf;
+  n = jrKanjiControl(0, KC_PARSE,  (char *)&p);
+  val = Qnil;
+  while (n > 0) {
+    n--;
+    val = Fcons(mule_make_string(p[n], strlen(p[n])), val);
+  }
+  return val;
+}
+
+DEFUN ("canna-query-mode", Fcanna_query_mode, Scanna_query_mode, 
+       0, 0, 0,
+       doc: /* Get the current mode string.  */)
+	(void)
+{
+  unsigned char buf[256];
+
+  jrKanjiControl(0, KC_QUERYMODE, buf);
+  return mule_make_string(buf, strlen(buf));
+}
+
+/*
+ * Functions following this line are for KKCP interface compatible
+ * library.  These functions may be used by MILK system.
+ */
+
+#define RKBUFSIZE 1024
+
+static unsigned char yomibuf[RKBUFSIZE];
+static short kugiri[RKBUFSIZE / 2];
+
+static confirmContext()
+{
+  if (IRCP_context < 0) {
+    int context;
+
+    if ((context = jrKanjiControl(0, KC_GETCONTEXT, (char *)0)) == -1) {
+      return 0;
+    }
+    IRCP_context = context;
+  }
+  return 1;
+}
+
+static byteLen(bun, len)
+int bun, len;
+{
+  int i = 0, offset = 0, ch;
+
+  if (0 <= bun && bun < RKBUFSIZE) {
+    offset = kugiri[bun];
+  }
+
+  while (len-- > 0 && (ch = (int)yomibuf[offset + i])) {
+    i++;
+    if (ch & 0x80) {
+      i++;
+    }
+  }
+  return i;
+}
+
+DEFUN ("canna-henkan-begin", Fcanna_henkan_begin, Scanna_henkan_begin,
+       1, 1, 0,
+       doc: /**/)
+/* "かな漢字変換した結果を返還する。文節切りがしてある。" */
+	(yomi)
+    Lisp_Object yomi;
+{
+  int nbun;
+  Lisp_Object res;
+
+  CHECK_STRING(yomi);
+  if (confirmContext() == 0) {
+    return Qnil;
+  }
+  yomi = code_convert_string(yomi, Vcanna_coding_system, Qnil, 1, 1, 1);
+  bcopy(XSTRING(yomi)->data, yomibuf, SBYTES (yomi));
+  yomibuf[SBYTES (yomi)] = 0;
+  nbun = RkBgnBun(IRCP_context, (char *)yomibuf, strlen(yomibuf),
+		  (RK_XFER << RK_XFERBITS) | RK_KFER);
+
+  return kanjiYomiList(IRCP_context, nbun);
+}
+
+static Lisp_Object kanjiYomiList(context, nbun)
+int context, nbun;
+{
+  Lisp_Object val, res = Qnil;
+  unsigned char RkBuf[RKBUFSIZE];
+  int len, i, total;
+
+  for (i = nbun ; i > 0 ; ) {
+    i--;
+    RkGoTo(context, i);
+    len = RkGetKanji(context, RkBuf, RKBUFSIZE);
+    val = mule_make_string(RkBuf, len);
+    len = RkGetYomi(context, RkBuf, RKBUFSIZE);
+    res = Fcons(Fcons(val, mule_make_string(RkBuf, len)), res);
+    if (i < RKBUFSIZE / 2) {
+      kugiri[i] = len;
+    }
+  }
+  for (i = 0, total = 0 ; i < nbun ; i++) {
+    int temp = kugiri[i];
+    kugiri[i] = total;
+    total += temp;
+  }
+  return res;
+}
+
+DEFUN ("canna-henkan-next", Fcanna_henkan_next, Scanna_henkan_next,
+       1, 1, 0,
+       doc: /**/)
+/* "候補一覧を求める。" */
+	(bunsetsu)
+    Lisp_Object bunsetsu;
+{
+  int i, nbun, slen, len;
+  unsigned char *p, RkBuf[RKBUFSIZE];
+  Lisp_Object res = Qnil, endp;
+
+  CHECK_NUMBER(bunsetsu);
+  if (confirmContext() == 0) {
+    return Qnil;
+  }
+  RkGoTo(IRCP_context, XINT (bunsetsu));
+  len = RkGetKanjiList(IRCP_context, RkBuf, RKBUFSIZE);
+  p = RkBuf;
+  for (i = 0 ; i < len ; i++) {
+    slen = strlen(p);
+    if (res == Qnil) {
+      endp = res = Fcons(mule_make_string(p, slen), Qnil);
+    }
+    else {
+      endp = XCONS (endp)->u.cdr = Fcons(mule_make_string(p, slen), Qnil);
+    }
+    p += slen + 1;
+  }
+  return res;
+}
+
+DEFUN ("canna-bunsetu-henkou", Fcanna_bunsetu_henkou, Scanna_bunsetu_henkou,
+       2, 2, 0,
+       doc: /**/)
+/* "文節の長さを指定する。" */
+	(bunsetsu, bunlen)
+    Lisp_Object bunsetsu, bunlen;
+{
+  int nbun, len;
+
+  CHECK_NUMBER(bunsetsu);
+  CHECK_NUMBER(bunlen);
+  
+  nbun = XINT (bunsetsu);
+  if (confirmContext() == 0) {
+    return Qnil;
+  }
+  RkGoTo(IRCP_context, nbun);
+  len = byteLen(nbun, XINT(bunlen));
+  return kanjiYomiList(IRCP_context, RkResize(IRCP_context, len));
+}
+
+DEFUN ("canna-henkan-kakutei", Fcanna_henkan_kakutei, Scanna_henkan_kakutei,
+       2, 2, 0,
+       doc: /**/)
+/* "候補選択。" */
+	(bun, kouho)
+register Lisp_Object bun, kouho;
+{
+  int nbun, nkouho;
+
+  if (confirmContext() == 0) {
+    return Qnil;
+  }
+  CHECK_NUMBER(bun);
+  CHECK_NUMBER(kouho);
+  nbun = XINT (bun);
+  nkouho = XINT (kouho);
+  RkGoTo(IRCP_context, nbun);
+  RkXfer(IRCP_context, nkouho);
+  return Qt;
+}
+
+DEFUN ("canna-henkan-end", Fcanna_henkan_end, Scanna_henkan_end,
+       0, 0, 0,
+       doc: /**/)
+/* "変換終了。" */
+	(void)
+{
+  if (confirmContext() == 0) {
+    return Qnil;
+  }
+  RkEndBun(IRCP_context, 1); /* 学習はいつでも行って良いものなのか？ */
+  return Qt;
+}
+
+DEFUN ("canna-henkan-quit", Fcanna_henkan_quit, Scanna_henkan_quit,
+       0, 0, 0,
+       doc: /**/)
+/* "変換終了。" */
+	(void)
+{
+  if (confirmContext() == 0) {
+    return Qnil;
+  }
+  RkEndBun(IRCP_context, 0);
+  return Qt;
+}
+
+syms_of_canna ()
+{
+  DEFVAR_LISP ("CANNA", VCANNA, "");		/* hir@nec, 1992.5.21 */
+  VCANNA = Qt; 					/* hir@nec, 1992.5.21 */
+
+  defsubr (&Scanna_key_proc);
+  defsubr (&Scanna_initialize);
+  defsubr (&Scanna_finalize);
+  defsubr (&Scanna_touroku_string);
+  defsubr (&Scanna_set_width);
+  defsubr (&Scanna_change_mode);
+  defsubr (&Scanna_store_yomi);
+  defsubr (&Scanna_do_function);
+  defsubr (&Scanna_parse);
+  defsubr (&Scanna_query_mode);
+  defsubr (&Scanna_set_bunsetsu);
+
+  DEFVAR_LISP ("canna-kakutei-string", Vcanna_kakutei_string, "");
+  DEFVAR_LISP ("canna-kakutei-yomi",   Vcanna_kakutei_yomi,   "");
+  DEFVAR_LISP ("canna-kakutei-romaji", Vcanna_kakutei_romaji, "");
+  DEFVAR_LISP ("canna-henkan-string",  Vcanna_henkan_string,  "");
+  DEFVAR_INT ("canna-henkan-length",  canna_henkan_length,  "");
+  DEFVAR_INT ("canna-henkan-revpos",  canna_henkan_revPos,  "");
+  DEFVAR_INT ("canna-henkan-revlen",  canna_henkan_revLen,  "");
+  DEFVAR_LISP ("canna-ichiran-string", Vcanna_ichiran_string, "");
+  DEFVAR_INT ("canna-ichiran-length", canna_ichiran_length, "");
+  DEFVAR_INT ("canna-ichiran-revpos", canna_ichiran_revPos, "");
+  DEFVAR_INT ("canna-ichiran-revlen", canna_ichiran_revLen, "");
+  DEFVAR_LISP ("canna-mode-string",    Vcanna_mode_string,    "");
+  DEFVAR_BOOL ("canna-empty-info", canna_empty_info, "For canna");
+  DEFVAR_BOOL ("canna-through-info", canna_through_info, "For canna");
+  DEFVAR_BOOL ("canna-underline", canna_underline, "For canna");
+  DEFVAR_BOOL ("canna-inhibit-hankakukana", canna_inhibit_hankakukana, 
+	       "For canna");			/* hir, 1994.12.5 */
+
+  defsubr (&Scanna_henkan_begin);
+  defsubr (&Scanna_henkan_next);
+  defsubr (&Scanna_bunsetu_henkou);
+  defsubr (&Scanna_henkan_kakutei);
+  defsubr (&Scanna_henkan_end);
+  defsubr (&Scanna_henkan_quit);
+
+  DEFVAR_LISP ("canna-coding-system",  Vcanna_coding_system,  "");
+  Vcanna_coding_system = intern("euc-jp");
+
+  /* variables below this line is constants of Canna */
+  DEFVAR_INT ("canna-mode-alpha-mode", canna_mode_AlphaMode, "");
+  canna_mode_AlphaMode = IROHA_MODE_AlphaMode;
+
+  DEFVAR_INT ("canna-mode-empty-mode", canna_mode_EmptyMode, "");
+  canna_mode_EmptyMode = IROHA_MODE_EmptyMode;
+
+  DEFVAR_INT ("canna-mode-kigo-mode",  canna_mode_KigoMode,  "");
+  canna_mode_KigoMode = IROHA_MODE_KigoMode;
+
+  DEFVAR_INT ("canna-mode-yomi-mode",  canna_mode_YomiMode,  "");
+  canna_mode_YomiMode = IROHA_MODE_YomiMode;
+
+  DEFVAR_INT ("canna-mode-jishu-mode", canna_mode_JishuMode, "");
+  canna_mode_JishuMode = IROHA_MODE_JishuMode;
+
+  DEFVAR_INT ("canna-mode-tankouho-mode", canna_mode_TankouhoMode, "");
+  canna_mode_TankouhoMode = IROHA_MODE_TankouhoMode;
+
+  DEFVAR_INT ("canna-mode-ichiran-mode",  canna_mode_IchiranMode,  "");
+  canna_mode_IchiranMode = IROHA_MODE_IchiranMode;
+
+  DEFVAR_INT ("canna-mode-yes-no-mode", canna_mode_YesNoMode, "");
+  canna_mode_YesNoMode = IROHA_MODE_YesNoMode;
+
+  DEFVAR_INT ("canna-mode-on-off-mode", canna_mode_OnOffMode, "");
+  canna_mode_OnOffMode = IROHA_MODE_OnOffMode;
+
+#ifdef CANNA_MODE_AdjustBunsetsuMode
+  DEFVAR_INT ("canna-mode-adjust-bunsetsu-mode",
+	      canna_mode_AdjustBunsetsuMode, "");
+  canna_mode_AdjustBunsetsuMode = CANNA_MODE_AdjustBunsetsuMode;
+#endif
+#ifdef CANNA_MODE_ChikujiYomiMode
+  DEFVAR_INT ("canna-mode-chikuji-yomi-mode", canna_mode_ChikujiYomiMode,"");
+  canna_mode_ChikujiYomiMode = CANNA_MODE_ChikujiYomiMode;
+
+  DEFVAR_INT ("canna-mode-chikuji-bunsetsu-mode",
+	      canna_mode_ChikujiTanMode, "");
+  canna_mode_ChikujiTanMode = CANNA_MODE_ChikujiTanMode;
+#endif
+
+  DEFVAR_INT ("canna-mode-henkan-mode", canna_mode_HenkanMode, "");
+  canna_mode_HenkanMode = IROHA_MODE_HenkanMode;
+#ifdef CANNA_MODE_HenkanNyuryokuMode
+  DEFVAR_INT ("canna-mode-henkan-nyuuryoku-mode",
+	      canna_mode_HenkanNyuryokuMode, "");
+  canna_mode_HenkanNyuryokuMode = CANNA_MODE_HenkanNyuryokuMode;
+#endif
+#ifdef CANNA_MODE_ZenHiraHenkanMode
+  DEFVAR_INT ("canna-mode-zen-hira-henkan-mode",
+	      canna_mode_ZenHiraHenkanMode, "");
+  canna_mode_ZenHiraHenkanMode = CANNA_MODE_ZenHiraHenkanMode;
+
+#ifdef CANNA_MODE_HanHiraHenkanMode
+  DEFVAR_INT ("canna-mode-han-hira-henkan-mode",
+	      canna_mode_HanHiraHenkanMode, "");
+  canna_mode_HanHiraHenkanMode = CANNA_MODE_HanHiraHenkanMode;
+#endif
+  DEFVAR_INT ("canna-mode-zen-kata-henkan-mode",
+	      canna_mode_ZenKataHenkanMode, "");
+  canna_mode_ZenKataHenkanMode = CANNA_MODE_ZenKataHenkanMode;
+
+  DEFVAR_INT ("canna-mode-han-kata-henkan-mode",
+	      canna_mode_HanKataHenkanMode, "");
+  canna_mode_HanKataHenkanMode = CANNA_MODE_HanKataHenkanMode;
+
+  DEFVAR_INT ("canna-mode-zen-alpha-henkan-mode",
+	      canna_mode_ZenAlphaHenkanMode, "");
+  canna_mode_ZenAlphaHenkanMode = CANNA_MODE_ZenAlphaHenkanMode;
+
+  DEFVAR_INT ("canna-mode-han-alpha-henkan-mode",
+	      canna_mode_HanAlphaHenkanMode, "");
+  canna_mode_HanAlphaHenkanMode = CANNA_MODE_HanAlphaHenkanMode;
+#endif
+  DEFVAR_INT ("canna-mode-zen-hira-kakutei-mode",
+	      canna_mode_ZenHiraKakuteiMode, "");
+  canna_mode_ZenHiraKakuteiMode = IROHA_MODE_ZenHiraKakuteiMode;
+
+#ifdef CANNA_MODE_HanHiraKakuteiMode
+  DEFVAR_INT ("canna-mode-han-hira-kakutei-mode",
+	      canna_mode_HanHiraKakuteiMode, "");
+  canna_mode_HanHiraKakuteiMode = CANNA_MODE_HanHiraKakuteiMode;
+#endif
+  DEFVAR_INT ("canna-mode-zen-kata-kakutei-mode",
+	      canna_mode_ZenKataKakuteiMode, "");
+  canna_mode_ZenKataKakuteiMode = IROHA_MODE_ZenKataKakuteiMode;
+
+  DEFVAR_INT ("canna-mode-han-kata-kakutei-mode",
+	      canna_mode_HanKataKakuteiMode, "");
+  canna_mode_HanKataKakuteiMode = IROHA_MODE_HanKataKakuteiMode;
+
+  DEFVAR_INT ("canna-mode-zen-alpha-kakutei-mode",
+	      canna_mode_ZenAlphaKakuteiMode, "");
+  canna_mode_ZenAlphaKakuteiMode = IROHA_MODE_ZenAlphaKakuteiMode;
+
+  DEFVAR_INT ("canna-mode-han-alpha-kakutei-mode",
+	      canna_mode_HanAlphaKakuteiMode, "");
+  canna_mode_HanAlphaKakuteiMode = IROHA_MODE_HanAlphaKakuteiMode;
+
+  DEFVAR_INT ("canna-mode-hex-mode", canna_mode_HexMode, "");
+  canna_mode_HexMode = IROHA_MODE_HexMode;
+
+  DEFVAR_INT ("canna-mode-bushu-mode", canna_mode_BushuMode, "");
+  canna_mode_BushuMode = IROHA_MODE_BushuMode;
+
+  DEFVAR_INT ("canna-mode-extend-mode", canna_mode_ExtendMode, "");
+  canna_mode_ExtendMode = IROHA_MODE_ExtendMode;
+
+  DEFVAR_INT ("canna-mode-russian-mode", canna_mode_RussianMode, "");
+  canna_mode_RussianMode = IROHA_MODE_RussianMode;
+
+  DEFVAR_INT ("canna-mode-greek-mode", canna_mode_GreekMode, "");
+  canna_mode_GreekMode = IROHA_MODE_GreekMode;
+
+  DEFVAR_INT ("canna-mode-line-mode", canna_mode_LineMode, "");
+  canna_mode_LineMode = IROHA_MODE_LineMode;
+
+  DEFVAR_INT ("canna-mode-changing-server-mode",
+	      canna_mode_ChangingServerMode, "");
+  canna_mode_ChangingServerMode = IROHA_MODE_ChangingServerMode;
+
+  DEFVAR_INT ("canna-mode-henkan-method-mode",
+	      canna_mode_HenkanMethodMode, "");
+  canna_mode_HenkanMethodMode = IROHA_MODE_HenkanMethodMode;
+
+  DEFVAR_INT ("canna-mode-delete-dic-mode", canna_mode_DeleteDicMode, "");
+  canna_mode_DeleteDicMode = IROHA_MODE_DeleteDicMode;
+
+  DEFVAR_INT ("canna-mode-touroku-mode", canna_mode_TourokuMode, "");
+  canna_mode_TourokuMode = IROHA_MODE_TourokuMode;
+
+  DEFVAR_INT ("canna-mode-touroku-empty-mode",
+	      canna_mode_TourokuEmptyMode, "");
+  canna_mode_TourokuEmptyMode = IROHA_MODE_TourokuEmptyMode;
+
+  DEFVAR_INT ("canna-mode-touroku-hinshi-mode",
+	      canna_mode_TourokuHinshiMode, "");
+  canna_mode_TourokuHinshiMode = IROHA_MODE_TourokuHinshiMode;
+
+  DEFVAR_INT ("canna-mode-touroku-dic-mode", canna_mode_TourokuDicMode, "");
+  canna_mode_TourokuDicMode = IROHA_MODE_TourokuDicMode;
+
+  DEFVAR_INT ("canna-mode-quoted-insert-mode",
+	      canna_mode_QuotedInsertMode, "");
+  canna_mode_QuotedInsertMode = IROHA_MODE_QuotedInsertMode;
+
+  DEFVAR_INT ("canna-mode-bubun-muhenkan-mode",
+	      canna_mode_BubunMuhenkanMode, "");
+  canna_mode_BubunMuhenkanMode = IROHA_MODE_BubunMuhenkanMode;
+
+  DEFVAR_INT ("canna-mode-mount-dic-mode", canna_mode_MountDicMode, "");
+  canna_mode_MountDicMode = IROHA_MODE_MountDicMode;
+
+  DEFVAR_INT ("canna-func-self-insert", canna_fn_SelfInsert ,"");
+  canna_fn_SelfInsert = IROHA_FN_SelfInsert;
+
+  DEFVAR_INT ("canna-func-functional-insert", canna_fn_FunctionalInsert ,"");
+  canna_fn_FunctionalInsert = IROHA_FN_FunctionalInsert;
+
+  DEFVAR_INT ("canna-func-quoted-insert", canna_fn_QuotedInsert ,"");
+  canna_fn_QuotedInsert = IROHA_FN_QuotedInsert;
+
+  DEFVAR_INT ("canna-func-japanese-mode", canna_fn_JapaneseMode ,"");
+  canna_fn_JapaneseMode = IROHA_FN_JapaneseMode;
+
+  DEFVAR_INT ("canna-func-alpha-mode", canna_fn_AlphaMode ,"");
+  canna_fn_AlphaMode = IROHA_FN_AlphaMode;
+
+  DEFVAR_INT ("canna-func-henkan-nyuryoku-mode",
+	      canna_fn_HenkanNyuryokuMode ,"");
+  canna_fn_HenkanNyuryokuMode = IROHA_FN_HenkanNyuryokuMode;
+
+  DEFVAR_INT ("canna-func-forward", canna_fn_Forward ,"");
+  canna_fn_Forward = IROHA_FN_Forward;
+
+  DEFVAR_INT ("canna-func-backward", canna_fn_Backward ,"");
+  canna_fn_Backward = IROHA_FN_Backward;
+
+  DEFVAR_INT ("canna-func-next", canna_fn_Next ,"");
+  canna_fn_Next = IROHA_FN_Next;
+
+  DEFVAR_INT ("canna-func-previous", canna_fn_Prev ,"");
+  canna_fn_Prev = IROHA_FN_Prev;
+
+  DEFVAR_INT ("canna-func-beginning-of-line", canna_fn_BeginningOfLine ,"");
+  canna_fn_BeginningOfLine = IROHA_FN_BeginningOfLine;
+ 
+  DEFVAR_INT ("canna-func-end-of-line", canna_fn_EndOfLine ,"");
+  canna_fn_EndOfLine = IROHA_FN_EndOfLine;
+
+  DEFVAR_INT ("canna-func-delete-next", canna_fn_DeleteNext ,"");
+  canna_fn_DeleteNext = IROHA_FN_DeleteNext;
+
+  DEFVAR_INT ("canna-func-delete_previous", canna_fn_DeletePrevious ,"");
+  canna_fn_DeletePrevious = IROHA_FN_DeletePrevious;
+
+  DEFVAR_INT ("canna-func-kill-to-end-of-line", canna_fn_KillToEndOfLine,"");
+  canna_fn_KillToEndOfLine = IROHA_FN_KillToEndOfLine;
+
+  DEFVAR_INT ("canna-func-henkan", canna_fn_Henkan ,"");
+  canna_fn_Henkan = IROHA_FN_Henkan;
+
+  DEFVAR_INT ("canna-func-kakutei", canna_fn_Kakutei ,"");
+  canna_fn_Kakutei = IROHA_FN_Kakutei;
+
+  DEFVAR_INT ("canna-func-extend", canna_fn_Extend ,"");
+  canna_fn_Extend = IROHA_FN_Extend;
+
+  DEFVAR_INT ("canna-func-shrink", canna_fn_Shrink ,"");
+  canna_fn_Shrink = IROHA_FN_Shrink;
+
+#ifdef CANNA_FN_AdjustBunsetsu
+  DEFVAR_INT ("canna-func-adjust-bunsetsu", canna_fn_AdjustBunsetsu ,"");
+  canna_fn_AdjustBunsetsu = CANNA_FN_AdjustBunsetsu;
+#endif
+  DEFVAR_INT ("canna-func-quit", canna_fn_Quit ,"");
+  canna_fn_Quit = IROHA_FN_Quit;
+
+  DEFVAR_INT ("canna-func-convert-as-hex", canna_fn_ConvertAsHex ,"");
+  canna_fn_ConvertAsHex = IROHA_FN_ConvertAsHex;
+
+  DEFVAR_INT ("canna-func-convert-as-bushu", canna_fn_ConvertAsBushu ,"");
+  canna_fn_ConvertAsBushu = IROHA_FN_ConvertAsBushu;
+
+  DEFVAR_INT ("canna-func-kouho-ichiran", canna_fn_KouhoIchiran ,"");
+  canna_fn_KouhoIchiran = IROHA_FN_KouhoIchiran;
+
+  DEFVAR_INT ("canna-func-bubun-muhenkan", canna_fn_BubunMuhenkan ,"");
+  canna_fn_BubunMuhenkan = IROHA_FN_BubunMuhenkan;
+
+  DEFVAR_INT ("canna-func-zenkaku", canna_fn_Zenkaku ,"");
+  canna_fn_Zenkaku = IROHA_FN_Zenkaku;
+
+  DEFVAR_INT ("canna-func-hankaku", canna_fn_Hankaku ,"");
+  canna_fn_Hankaku = IROHA_FN_Hankaku;
+
+  DEFVAR_INT ("canna-func-to-upper", canna_fn_ToUpper ,"");
+  canna_fn_ToUpper = IROHA_FN_ToUpper;
+
+  DEFVAR_INT ("canna-func-capitalize", canna_fn_Capitalize ,"");
+  canna_fn_Capitalize = IROHA_FN_Capitalize;
+
+  DEFVAR_INT ("canna-func-to-lower", canna_fn_ToLower ,"");
+  canna_fn_ToLower = IROHA_FN_ToLower;
+
+  DEFVAR_INT ("canna-func-hiragana", canna_fn_Hiragana ,"");
+  canna_fn_Hiragana = IROHA_FN_Hiragana;
+
+  DEFVAR_INT ("canna-func-katakana", canna_fn_Katakana ,"");
+  canna_fn_Katakana = IROHA_FN_Katakana;
+
+  DEFVAR_INT ("canna-func-romaji", canna_fn_Romaji ,"");
+  canna_fn_Romaji = IROHA_FN_Romaji;
+
+#ifdef CANNA_FN_BaseHiragana
+  DEFVAR_INT ("canna-func-base-hiragana", canna_fn_BaseHiragana ,"");
+  canna_fn_BaseHiragana = CANNA_FN_BaseHiragana;
+
+  DEFVAR_INT ("canna-func-base-katakana", canna_fn_BaseKatakana ,"");
+  canna_fn_BaseKatakana = CANNA_FN_BaseKatakana;
+
+  DEFVAR_INT ("canna-func-base-eisu", canna_fn_BaseEisu ,"");
+  canna_fn_BaseEisu = CANNA_FN_BaseEisu;
+
+  DEFVAR_INT ("canna-func-base-zenkaku", canna_fn_BaseZenkaku ,"");
+  canna_fn_BaseZenkaku = CANNA_FN_BaseZenkaku;
+
+  DEFVAR_INT ("canna-func-base-hankaku", canna_fn_BaseHankaku ,"");
+  canna_fn_BaseHankaku = CANNA_FN_BaseHankaku;
+
+  DEFVAR_INT ("canna-func-base-kana", canna_fn_BaseKana ,"");
+  canna_fn_BaseKana = CANNA_FN_BaseKana;
+
+  DEFVAR_INT ("canna-func-base-kakutei", canna_fn_BaseKakutei ,"");
+  canna_fn_BaseKakutei = CANNA_FN_BaseKakutei;
+
+  DEFVAR_INT ("canna-func-base-henkan", canna_fn_BaseHenkan ,"");
+  canna_fn_BaseHenkan = CANNA_FN_BaseHenkan;
+
+  DEFVAR_INT ("canna-func-base-hiragana-katakana-toggle",
+	      canna_fn_BaseHiraKataToggle ,"");
+  canna_fn_BaseHiraKataToggle = CANNA_FN_BaseHiraKataToggle;
+
+  DEFVAR_INT ("canna-func-base-zenkaku-hankaku-toggle",
+	      canna_fn_BaseZenHanToggle ,"");
+  canna_fn_BaseZenHanToggle = CANNA_FN_BaseZenHanToggle;
+
+  DEFVAR_INT ("canna-func-base-kana-eisu-toggle",
+	      canna_fn_BaseKanaEisuToggle ,"");
+  canna_fn_BaseKanaEisuToggle = CANNA_FN_BaseKanaEisuToggle;
+
+  DEFVAR_INT ("canna-func-base-kakutei-henkan-toggle",
+	      canna_fn_BaseKakuteiHenkanToggle ,"");
+  canna_fn_BaseKakuteiHenkanToggle = CANNA_FN_BaseKakuteiHenkanToggle;
+
+  DEFVAR_INT ("canna-func-base-rotate-forward",
+	      canna_fn_BaseRotateForward ,"");
+  canna_fn_BaseRotateForward = CANNA_FN_BaseRotateForward;
+
+  DEFVAR_INT ("canna-func-base-rotate-backward",
+	      canna_fn_BaseRotateBackward ,"");
+  canna_fn_BaseRotateBackward = CANNA_FN_BaseRotateBackward;
+#endif
+  DEFVAR_INT ("canna-func-extend-mode", canna_fn_ExtendMode ,"");
+  canna_fn_ExtendMode = IROHA_FN_ExtendMode;
+
+  DEFVAR_INT ("canna-func-touroku", canna_fn_Touroku ,"");
+  canna_fn_Touroku = IROHA_FN_Touroku;
+
+  DEFVAR_INT ("canna-func-hex-mode", canna_fn_HexMode ,"");
+  canna_fn_HexMode = IROHA_FN_HexMode;
+
+  DEFVAR_INT ("canna-func-bushu-mode", canna_fn_BushuMode ,"");
+  canna_fn_BushuMode = IROHA_FN_BushuMode;
+
+  DEFVAR_INT ("canna-func-kigo-mode", canna_fn_KigouMode ,"");
+  canna_fn_KigouMode = IROHA_FN_KigouMode;
+
+#ifdef CANNA_FN_Mark
+  DEFVAR_INT ("canna-func-mark", canna_fn_Mark ,"");
+  canna_fn_Mark = CANNA_FN_Mark;
+#endif
+#ifdef CANNA_FN_TemporalMode
+  DEFVAR_INT ("canna-func-temporal-mode", canna_fn_TemporalMode ,"");
+  canna_fn_TemporalMode = CANNA_FN_TemporalMode;
+#endif
+
+  DEFVAR_INT ("canna-key-nfer", canna_key_Nfer, "");
+  canna_key_Nfer = IROHA_KEY_Nfer;
+
+  DEFVAR_INT ("canna-key-xfer", canna_key_Xfer, "");
+  canna_key_Xfer = IROHA_KEY_Xfer;
+
+  DEFVAR_INT ("canna-key-up", canna_key_Up, "");
+  canna_key_Up = IROHA_KEY_Up;
+
+  DEFVAR_INT ("canna-key-left", canna_key_Left, "");
+  canna_key_Left = IROHA_KEY_Left;
+
+  DEFVAR_INT ("canna-key-right", canna_key_Right, "");
+  canna_key_Right = IROHA_KEY_Right;
+
+  DEFVAR_INT ("canna-key-down", canna_key_Down, "");
+  canna_key_Down = IROHA_KEY_Down;
+
+  DEFVAR_INT ("canna-key-insert", canna_key_Insert, "");
+  canna_key_Insert = IROHA_KEY_Insert;
+
+  DEFVAR_INT ("canna-key-rollup", canna_key_Rollup, "");
+  canna_key_Rollup = IROHA_KEY_Rollup;
+
+  DEFVAR_INT ("canna-key-rolldown", canna_key_Rolldown, "");
+  canna_key_Rolldown = IROHA_KEY_Rolldown;
+
+  DEFVAR_INT ("canna-key-home", canna_key_Home, "");
+  canna_key_Home = IROHA_KEY_Home;
+
+  DEFVAR_INT ("canna-key-help", canna_key_Help, "");
+  canna_key_Help = IROHA_KEY_Help;
+
+  DEFVAR_INT ("canna-key-kp-key", canna_key_KP_Key, "");
+  canna_key_KP_Key = IROHA_KEY_KP_Key;
+
+  DEFVAR_INT ("canna-key-shift-nfer", canna_key_Shift_Nfer, "");
+  canna_key_Shift_Nfer = IROHA_KEY_Shift_Nfer;
+
+  DEFVAR_INT ("canna-key-shift-xfer", canna_key_Shift_Xfer, "");
+  canna_key_Shift_Xfer = IROHA_KEY_Shift_Xfer;
+
+  DEFVAR_INT ("canna-key-shift-up", canna_key_Shift_Up, "");
+  canna_key_Shift_Up = IROHA_KEY_Shift_Up;
+
+  DEFVAR_INT ("canna-key-shift-left", canna_key_Shift_Left, "");
+  canna_key_Shift_Left = IROHA_KEY_Shift_Left;
+
+  DEFVAR_INT ("canna-key-shift-right", canna_key_Shift_Right, "");
+  canna_key_Shift_Right = IROHA_KEY_Shift_Right;
+
+  DEFVAR_INT ("canna-key-shift-down", canna_key_Shift_Down, "");
+  canna_key_Shift_Down = IROHA_KEY_Shift_Down;
+
+  DEFVAR_INT ("canna-key-control-nfer", canna_key_Cntrl_Nfer, "");
+  canna_key_Cntrl_Nfer = IROHA_KEY_Cntrl_Nfer;
+
+  DEFVAR_INT ("canna-key-control-xfer", canna_key_Cntrl_Xfer, "");
+  canna_key_Cntrl_Xfer = IROHA_KEY_Cntrl_Xfer;
+
+  DEFVAR_INT ("canna-key-control-up", canna_key_Cntrl_Up, "");
+  canna_key_Cntrl_Up = IROHA_KEY_Cntrl_Up;
+
+  DEFVAR_INT ("canna-key-control-left", canna_key_Cntrl_Left, "");
+  canna_key_Cntrl_Left = IROHA_KEY_Cntrl_Left;
+
+  DEFVAR_INT ("canna-key-control-right", canna_key_Cntrl_Right, "");
+  canna_key_Cntrl_Right = IROHA_KEY_Cntrl_Right;
+
+  DEFVAR_INT ("canna-key-control-down", canna_key_Cntrl_Down, "");
+  canna_key_Cntrl_Down = IROHA_KEY_Cntrl_Down;
+}
+
+#ifdef CANNA_EMACS_DL
+#define HAVE_DYNAMIC_LOADER
+
+static int initialized = 0;
+
+void
+emacs_canna_init ()
+{
+  if (initialized) return;
+  initialized = 1;
+
+  syms_of_canna ();
+}
+
+void
+emacs_canna_fini ()
+{
+  if (!initialized) return;
+  initialized = 0;
+
+  UNDEFVAR_LISP ("CANNA", VCANNA, "");		/* hir@nec, 1992.5.21 */
+
+  undefsubr (&Scanna_key_proc);
+  undefsubr (&Scanna_initialize);
+  undefsubr (&Scanna_finalize);
+  undefsubr (&Scanna_touroku_string);
+  undefsubr (&Scanna_set_width);
+  undefsubr (&Scanna_change_mode);
+  undefsubr (&Scanna_store_yomi);
+  undefsubr (&Scanna_do_function);
+  undefsubr (&Scanna_parse);
+  undefsubr (&Scanna_query_mode);
+  undefsubr (&Scanna_set_bunsetsu);
+
+  UNDEFVAR_LISP ("canna-kakutei-string", Vcanna_kakutei_string, "");
+  UNDEFVAR_LISP ("canna-kakutei-yomi",   Vcanna_kakutei_yomi,   "");
+  UNDEFVAR_LISP ("canna-kakutei-romaji", Vcanna_kakutei_romaji, "");
+  UNDEFVAR_LISP ("canna-henkan-string",  Vcanna_henkan_string,  "");
+  UNDEFVAR_INT ("canna-henkan-length",  canna_henkan_length,  "");
+  UNDEFVAR_INT ("canna-henkan-revpos",  canna_henkan_revPos,  "");
+  UNDEFVAR_INT ("canna-henkan-revlen",  canna_henkan_revLen,  "");
+  UNDEFVAR_LISP ("canna-ichiran-string", Vcanna_ichiran_string, "");
+  UNDEFVAR_INT ("canna-ichiran-length", canna_ichiran_length, "");
+  UNDEFVAR_INT ("canna-ichiran-revpos", canna_ichiran_revPos, "");
+  UNDEFVAR_INT ("canna-ichiran-revlen", canna_ichiran_revLen, "");
+  UNDEFVAR_LISP ("canna-mode-string",    Vcanna_mode_string,    "");
+  UNDEFVAR_BOOL ("canna-empty-info", canna_empty_info, "For canna");
+  UNDEFVAR_BOOL ("canna-through-info", canna_through_info, "For canna");
+  UNDEFVAR_BOOL ("canna-underline", canna_underline, "For canna");
+  UNDEFVAR_BOOL ("canna-inhibit-hankakukana", canna_inhibit_hankakukana, 
+	       "For canna");			/* hir, 1994.12.5 */
+
+  undefsubr (&Scanna_henkan_begin);
+  undefsubr (&Scanna_henkan_next);
+  undefsubr (&Scanna_bunsetu_henkou);
+  undefsubr (&Scanna_henkan_kakutei);
+  undefsubr (&Scanna_henkan_end);
+  undefsubr (&Scanna_henkan_quit);
+
+  UNDEFVAR_LISP ("canna-coding-system",  Vcanna_coding_system,  "");
+  /* variables below this line is constants of Canna */
+  UNDEFVAR_INT ("canna-mode-alpha-mode", canna_mode_AlphaMode, "");
+  UNDEFVAR_INT ("canna-mode-empty-mode", canna_mode_EmptyMode, "");
+  UNDEFVAR_INT ("canna-mode-kigo-mode",  canna_mode_KigoMode,  "");
+  UNDEFVAR_INT ("canna-mode-yomi-mode",  canna_mode_YomiMode,  "");
+  UNDEFVAR_INT ("canna-mode-jishu-mode", canna_mode_JishuMode, "");
+  UNDEFVAR_INT ("canna-mode-tankouho-mode", canna_mode_TankouhoMode, "");
+  UNDEFVAR_INT ("canna-mode-ichiran-mode",  canna_mode_IchiranMode,  "");
+  UNDEFVAR_INT ("canna-mode-yes-no-mode", canna_mode_YesNoMode, "");
+  UNDEFVAR_INT ("canna-mode-on-off-mode", canna_mode_OnOffMode, "");
+#ifdef CANNA_MODE_AdjustBunsetsuMode
+  UNDEFVAR_INT ("canna-mode-adjust-bunsetsu-mode",
+	      canna_mode_AdjustBunsetsuMode, "");
+#endif
+#ifdef CANNA_MODE_ChikujiYomiMode
+  UNDEFVAR_INT ("canna-mode-chikuji-yomi-mode", canna_mode_ChikujiYomiMode,"");
+  UNDEFVAR_INT ("canna-mode-chikuji-bunsetsu-mode",
+	      canna_mode_ChikujiTanMode, "");
+#endif
+  UNDEFVAR_INT ("canna-mode-henkan-mode", canna_mode_HenkanMode, "");
+#ifdef CANNA_MODE_HenkanNyuryokuMode
+  UNDEFVAR_INT ("canna-mode-henkan-nyuuryoku-mode",
+	      canna_mode_HenkanNyuryokuMode, "");
+#endif
+#ifdef CANNA_MODE_ZenHiraHenkanMode
+  UNDEFVAR_INT ("canna-mode-zen-hira-henkan-mode",
+	      canna_mode_ZenHiraHenkanMode, "");
+#ifdef CANNA_MODE_HanHiraHenkanMode
+  UNDEFVAR_INT ("canna-mode-han-hira-henkan-mode",
+	      canna_mode_HanHiraHenkanMode, "");
+#endif
+  UNDEFVAR_INT ("canna-mode-zen-kata-henkan-mode",
+	      canna_mode_ZenKataHenkanMode, "");
+  UNDEFVAR_INT ("canna-mode-han-kata-henkan-mode",
+	      canna_mode_HanKataHenkanMode, "");
+  UNDEFVAR_INT ("canna-mode-zen-alpha-henkan-mode",
+	      canna_mode_ZenAlphaHenkanMode, "");
+  UNDEFVAR_INT ("canna-mode-han-alpha-henkan-mode",
+	      canna_mode_HanAlphaHenkanMode, "");
+#endif
+  UNDEFVAR_INT ("canna-mode-zen-hira-kakutei-mode",
+	      canna_mode_ZenHiraKakuteiMode, "");
+#ifdef CANNA_MODE_HanHiraKakuteiMode
+  UNDEFVAR_INT ("canna-mode-han-hira-kakutei-mode",
+	      canna_mode_HanHiraKakuteiMode, "");
+#endif
+  UNDEFVAR_INT ("canna-mode-zen-kata-kakutei-mode",
+	      canna_mode_ZenKataKakuteiMode, "");
+  UNDEFVAR_INT ("canna-mode-han-kata-kakutei-mode",
+	      canna_mode_HanKataKakuteiMode, "");
+  UNDEFVAR_INT ("canna-mode-zen-alpha-kakutei-mode",
+	      canna_mode_ZenAlphaKakuteiMode, "");
+  UNDEFVAR_INT ("canna-mode-han-alpha-kakutei-mode",
+	      canna_mode_HanAlphaKakuteiMode, "");
+  UNDEFVAR_INT ("canna-mode-hex-mode", canna_mode_HexMode, "");
+  UNDEFVAR_INT ("canna-mode-bushu-mode", canna_mode_BushuMode, "");
+  UNDEFVAR_INT ("canna-mode-extend-mode", canna_mode_ExtendMode, "");
+  UNDEFVAR_INT ("canna-mode-russian-mode", canna_mode_RussianMode, "");
+  UNDEFVAR_INT ("canna-mode-greek-mode", canna_mode_GreekMode, "");
+  UNDEFVAR_INT ("canna-mode-line-mode", canna_mode_LineMode, "");
+  UNDEFVAR_INT ("canna-mode-changing-server-mode",
+	      canna_mode_ChangingServerMode, "");
+  UNDEFVAR_INT ("canna-mode-henkan-method-mode",
+	      canna_mode_HenkanMethodMode, "");
+  UNDEFVAR_INT ("canna-mode-delete-dic-mode", canna_mode_DeleteDicMode, "");
+  UNDEFVAR_INT ("canna-mode-touroku-mode", canna_mode_TourokuMode, "");
+  UNDEFVAR_INT ("canna-mode-touroku-empty-mode",
+	      canna_mode_TourokuEmptyMode, "");
+  UNDEFVAR_INT ("canna-mode-touroku-hinshi-mode",
+	      canna_mode_TourokuHinshiMode, "");
+  UNDEFVAR_INT ("canna-mode-touroku-dic-mode", canna_mode_TourokuDicMode, "");
+  UNDEFVAR_INT ("canna-mode-quoted-insert-mode",
+	      canna_mode_QuotedInsertMode, "");
+  UNDEFVAR_INT ("canna-mode-bubun-muhenkan-mode",
+	      canna_mode_BubunMuhenkanMode, "");
+  UNDEFVAR_INT ("canna-mode-mount-dic-mode", canna_mode_MountDicMode, "");
+  UNDEFVAR_INT ("canna-func-self-insert", canna_fn_SelfInsert ,"");
+  UNDEFVAR_INT ("canna-func-functional-insert", canna_fn_FunctionalInsert ,"");
+  UNDEFVAR_INT ("canna-func-quoted-insert", canna_fn_QuotedInsert ,"");
+  UNDEFVAR_INT ("canna-func-japanese-mode", canna_fn_JapaneseMode ,"");
+  UNDEFVAR_INT ("canna-func-alpha-mode", canna_fn_AlphaMode ,"");
+  UNDEFVAR_INT ("canna-func-henkan-nyuryoku-mode",
+	      canna_fn_HenkanNyuryokuMode ,"");
+  UNDEFVAR_INT ("canna-func-forward", canna_fn_Forward ,"");
+  UNDEFVAR_INT ("canna-func-backward", canna_fn_Backward ,"");
+  UNDEFVAR_INT ("canna-func-next", canna_fn_Next ,"");
+  UNDEFVAR_INT ("canna-func-previous", canna_fn_Prev ,"");
+  UNDEFVAR_INT ("canna-func-beginning-of-line", canna_fn_BeginningOfLine ,"");
+  UNDEFVAR_INT ("canna-func-end-of-line", canna_fn_EndOfLine ,"");
+  UNDEFVAR_INT ("canna-func-delete-next", canna_fn_DeleteNext ,"");
+  UNDEFVAR_INT ("canna-func-delete_previous", canna_fn_DeletePrevious ,"");
+  UNDEFVAR_INT ("canna-func-kill-to-end-of-line", canna_fn_KillToEndOfLine,"");
+  UNDEFVAR_INT ("canna-func-henkan", canna_fn_Henkan ,"");
+  UNDEFVAR_INT ("canna-func-kakutei", canna_fn_Kakutei ,"");
+  UNDEFVAR_INT ("canna-func-extend", canna_fn_Extend ,"");
+  UNDEFVAR_INT ("canna-func-shrink", canna_fn_Shrink ,"");
+#ifdef CANNA_FN_AdjustBunsetsu
+  UNDEFVAR_INT ("canna-func-adjust-bunsetsu", canna_fn_AdjustBunsetsu ,"");
+#endif
+  UNDEFVAR_INT ("canna-func-quit", canna_fn_Quit ,"");
+  UNDEFVAR_INT ("canna-func-convert-as-hex", canna_fn_ConvertAsHex ,"");
+  UNDEFVAR_INT ("canna-func-convert-as-bushu", canna_fn_ConvertAsBushu ,"");
+  UNDEFVAR_INT ("canna-func-kouho-ichiran", canna_fn_KouhoIchiran ,"");
+  UNDEFVAR_INT ("canna-func-bubun-muhenkan", canna_fn_BubunMuhenkan ,"");
+  UNDEFVAR_INT ("canna-func-zenkaku", canna_fn_Zenkaku ,"");
+  UNDEFVAR_INT ("canna-func-hankaku", canna_fn_Hankaku ,"");
+  UNDEFVAR_INT ("canna-func-to-upper", canna_fn_ToUpper ,"");
+  UNDEFVAR_INT ("canna-func-capitalize", canna_fn_Capitalize ,"");
+  UNDEFVAR_INT ("canna-func-to-lower", canna_fn_ToLower ,"");
+  UNDEFVAR_INT ("canna-func-hiragana", canna_fn_Hiragana ,"");
+  UNDEFVAR_INT ("canna-func-katakana", canna_fn_Katakana ,"");
+  UNDEFVAR_INT ("canna-func-romaji", canna_fn_Romaji ,"");
+#ifdef CANNA_FN_BaseHiragana
+  UNDEFVAR_INT ("canna-func-base-hiragana", canna_fn_BaseHiragana ,"");
+  UNDEFVAR_INT ("canna-func-base-katakana", canna_fn_BaseKatakana ,"");
+  UNDEFVAR_INT ("canna-func-base-eisu", canna_fn_BaseEisu ,"");
+  UNDEFVAR_INT ("canna-func-base-zenkaku", canna_fn_BaseZenkaku ,"");
+  UNDEFVAR_INT ("canna-func-base-hankaku", canna_fn_BaseHankaku ,"");
+  UNDEFVAR_INT ("canna-func-base-kana", canna_fn_BaseKana ,"");
+  UNDEFVAR_INT ("canna-func-base-kakutei", canna_fn_BaseKakutei ,"");
+  UNDEFVAR_INT ("canna-func-base-henkan", canna_fn_BaseHenkan ,"");
+  UNDEFVAR_INT ("canna-func-base-hiragana-katakana-toggle",
+	      canna_fn_BaseHiraKataToggle ,"");
+  UNDEFVAR_INT ("canna-func-base-zenkaku-hankaku-toggle",
+	      canna_fn_BaseZenHanToggle ,"");
+  UNDEFVAR_INT ("canna-func-base-kana-eisu-toggle",
+	      canna_fn_BaseKanaEisuToggle ,"");
+  UNDEFVAR_INT ("canna-func-base-kakutei-henkan-toggle",
+	      canna_fn_BaseKakuteiHenkanToggle ,"");
+  UNDEFVAR_INT ("canna-func-base-rotate-forward",
+	      canna_fn_BaseRotateForward ,"");
+  UNDEFVAR_INT ("canna-func-base-rotate-backward",
+	      canna_fn_BaseRotateBackward ,"");
+#endif
+  UNDEFVAR_INT ("canna-func-extend-mode", canna_fn_ExtendMode ,"");
+  UNDEFVAR_INT ("canna-func-touroku", canna_fn_Touroku ,"");
+  UNDEFVAR_INT ("canna-func-hex-mode", canna_fn_HexMode ,"");
+  UNDEFVAR_INT ("canna-func-bushu-mode", canna_fn_BushuMode ,"");
+  UNDEFVAR_INT ("canna-func-kigo-mode", canna_fn_KigouMode ,"");
+#ifdef CANNA_FN_Mark
+  UNDEFVAR_INT ("canna-func-mark", canna_fn_Mark ,"");
+#endif
+#ifdef CANNA_FN_TemporalMode
+  UNDEFVAR_INT ("canna-func-temporal-mode", canna_fn_TemporalMode ,"");
+#endif
+  UNDEFVAR_INT ("canna-key-nfer", canna_key_Nfer, "");
+  UNDEFVAR_INT ("canna-key-xfer", canna_key_Xfer, "");
+  UNDEFVAR_INT ("canna-key-up", canna_key_Up, "");
+  UNDEFVAR_INT ("canna-key-left", canna_key_Left, "");
+  UNDEFVAR_INT ("canna-key-right", canna_key_Right, "");
+  UNDEFVAR_INT ("canna-key-down", canna_key_Down, "");
+  UNDEFVAR_INT ("canna-key-insert", canna_key_Insert, "");
+  UNDEFVAR_INT ("canna-key-rollup", canna_key_Rollup, "");
+  UNDEFVAR_INT ("canna-key-rolldown", canna_key_Rolldown, "");
+  UNDEFVAR_INT ("canna-key-home", canna_key_Home, "");
+  UNDEFVAR_INT ("canna-key-help", canna_key_Help, "");
+  UNDEFVAR_INT ("canna-key-kp-key", canna_key_KP_Key, "");
+  UNDEFVAR_INT ("canna-key-shift-nfer", canna_key_Shift_Nfer, "");
+  UNDEFVAR_INT ("canna-key-shift-xfer", canna_key_Shift_Xfer, "");
+  UNDEFVAR_INT ("canna-key-shift-up", canna_key_Shift_Up, "");
+  UNDEFVAR_INT ("canna-key-shift-left", canna_key_Shift_Left, "");
+  UNDEFVAR_INT ("canna-key-shift-right", canna_key_Shift_Right, "");
+  UNDEFVAR_INT ("canna-key-shift-down", canna_key_Shift_Down, "");
+  UNDEFVAR_INT ("canna-key-control-nfer", canna_key_Cntrl_Nfer, "");
+  UNDEFVAR_INT ("canna-key-control-xfer", canna_key_Cntrl_Xfer, "");
+  UNDEFVAR_INT ("canna-key-control-up", canna_key_Cntrl_Up, "");
+  UNDEFVAR_INT ("canna-key-control-left", canna_key_Cntrl_Left, "");
+  UNDEFVAR_INT ("canna-key-control-right", canna_key_Cntrl_Right, "");
+  UNDEFVAR_INT ("canna-key-control-down", canna_key_Cntrl_Down, "");
+}
+#endif
+
+/* To handle MULE internal code and EUC.
+   I assume CANNA can handle only Japanese EUC. */
+
+/* EUC multibyte string to MULE internal string */
+
+/* make_string after converting EUC string to MULE internal string */
+static
+Lisp_Object
+mule_make_string(p,l)
+unsigned char *p;
+int l;
+{
+  return (code_convert_string(make_unibyte_string(p,l), Vcanna_coding_system, Qnil, 0, 1, 1));
+}	
+
+#ifdef STRING_BYTES
+#define MULE_STR_SS2 1
+#define MULE_STR_SS3 1
+#define MULE_STR_KNJ 1
+#else
+#define MULE_STR_SS2 2
+#define MULE_STR_SS3 3
+#define MULE_STR_KNJ 3
+#endif
+/* return the MULE internal string length of EUC string */
+static
+mule_strlen(p,l)
+unsigned char *p;
+int l;
+{
+  unsigned char ch, *cp = p;
+  int len = 0;
+  
+  while((cp < p + l) && (ch = *cp)) {
+    if ((unsigned char)ch == ISO_CODE_SS2) {
+      len += MULE_STR_SS2;
+      cp += 2;
+    }
+    else if ((unsigned char)ch == ISO_CODE_SS3) {
+      len += MULE_STR_SS3;
+      cp += 3;
+    }
+    else if(ch & 0x80) {
+      len += MULE_STR_KNJ;
+      cp += 2;
+    }
+    else {
+      len++;
+      cp++;	
+    }
+  }
+  return(len);
+}
+
+/* count number of characters */
+static
+count_char(p,len,pos,rev,clen,cpos,crev)
+unsigned char *p;	
+int len,pos,rev,*clen,*cpos,*crev;
+{
+  unsigned char *q = p;
+  
+  *clen = *cpos = *crev = 0;
+  if (len == 0) return;
+  while (q < p + pos) {
+    (*clen)++;
+    (*cpos)++;
+    if (*q++ & 0x80) q++;
+  }
+  while (q < p + pos + rev) {
+    (*clen)++;
+    (*crev)++;
+    if (*q++ & 0x80) q++;
+  }		
+  while (q < p + len) {
+    (*clen)++;
+    if (*q++ & 0x80) q++;
+  }
+}
diff -r 08c8dbbb056a src/config.in
--- a/src/config.in	Thu Jun 14 18:19:18 2012 +0900
+++ b/src/config.in	Thu Jun 14 21:59:32 2012 +0900
@@ -46,6 +46,15 @@
 /* Define to the number of bits in type 'wint_t'. */
 #undef BITSIZEOF_WINT_T
 
+/* flag whether to use Canna */
+#undef CANNA
+
+/* flag whether to use Canna2 */
+#undef CANNA2
+
+/* flag whether to use Canna on Mule */
+#undef CANNA_EMACS_23
+
 /* Define if Emacs cannot be dumped on your system. */
 #undef CANNOT_DUMP
 
@@ -57,6 +66,9 @@
 /* Define to 1 if using `alloca.c'. */
 #undef C_ALLOCA
 
+/* compile switch for Canna */
+#undef C_SWITCH_CANNA
+
 /* Define to 1 for DGUX with <sys/dg_sys_info.h>. */
 #undef DGUX
 
@@ -948,6 +960,15 @@
 /* Define to use Kerberos 5 instead of Kerberos 4. */
 #undef KERBEROS5
 
+/* link switch for Canna */
+#undef LD_SWITCH_CANNA
+
+/* link switch for Canna if -R option is needed */
+#undef LD_SWITCH_CANNA_AUX
+
+/* special library for Mule */
+#undef LIBS_MULE
+
 /* Define to 1 if localtime caches TZ. */
 #undef LOCALTIME_CACHE
 
@@ -1475,6 +1496,14 @@
 #  endif
 #endif
 
+#ifdef CANNA
+#  define CANNA2
+#  define CANNA_EMACS_23
+#  define CANNA_PURESIZE 18000
+#else  /* not CANNA */
+#  define CANNA_PURESIZE 0
+#endif /* not CANNA */
+
 #endif /* EMACS_CONFIG_H */
 
 /*
diff -r 08c8dbbb056a src/emacs.c
--- a/src/emacs.c	Thu Jun 14 18:19:18 2012 +0900
+++ b/src/emacs.c	Thu Jun 14 21:59:32 2012 +0900
@@ -202,6 +202,7 @@
 
 static void sort_args (int argc, char **argv);
 static void syms_of_emacs (void);
+static void syms_of_mule (void);
 
 /* MSVC needs each string be shorter than 2048 bytes, so the usage
    strings below are split to not overflow this limit.  */
@@ -1583,6 +1584,13 @@
       syms_of_dbusbind ();
 #endif /* HAVE_DBUS */
 
+      syms_of_mule ();		/* 94.7.15 by K.Handa */
+
+#ifdef CANNA
+      syms_of_canna ();
+#endif /* CANNA */
+/* end of patch */
+
 #ifdef WINDOWSNT
       syms_of_ntterm ();
 #endif /* WINDOWSNT */
@@ -2546,3 +2554,18 @@
   /* Make sure IS_DAEMON starts up as false.  */
   daemon_pipe[1] = 0;
 }
+
+void
+syms_of_mule (void)
+{
+#if 0
+  defsubr (&Sdefine_word_pattern);
+
+  DEFVAR_BOOL ("re-short-flag", re_short_flag,
+    "*T means regexp search success when the shortest match is found.");
+  re_short_flag = 0;
+
+  DEFVAR_LISP ("MULE", VMULE, "");
+  VMULE = Qt;
+#endif
+}
diff -r 08c8dbbb056a src/puresize.h
--- a/src/puresize.h	Thu Jun 14 18:19:18 2012 +0900
+++ b/src/puresize.h	Thu Jun 14 21:59:32 2012 +0900
@@ -63,7 +63,7 @@
 
 /* This is the actual size in bytes to allocate.  */
 #ifndef PURESIZE
-#define PURESIZE  (BASE_PURESIZE * PURESIZE_RATIO * PURESIZE_CHECKING_RATIO)
+#define PURESIZE  ((BASE_PURESIZE + CANNA_PURESIZE) * PURESIZE_RATIO * PURESIZE_CHECKING_RATIO)
 #endif
 
 /* Signal an error if OBJ is pure.  */
