--- /dev/null
+;; 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, based on Canna 2.2/3.2. : canna.el,v x.xx 1994/11/7 00:00:00")
+
+(defun canna-version ()
+ (interactive)
+ (message (concat (substring canna-rcs-version 0 72) " ...")) )
+
+(provide 'canna)
+
+;;; \e$B$+$s$J$NJQ?t\e(B
+
+(defvar canna-save-undo-text-predicate nil)
+(defvar canna-undo-hook nil)
+
+(defvar canna-do-keybind-for-functionkeys t)
+(defvar canna-use-functional-numbers nil)
+(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 \e$B$N$H$-$O\e(B, \e$B%_%K%P%C%U%!$rH4$1$k;~F|K\8l>uBV$r=i4|2=$9$k\e(B.")
+
+(defvar canna-inhibit-hankakukana nil
+ "*Non-nil \e$B$N;~!";z<oJQ49$GH>3Q$+$J$KJQ49$7$J$$\e(B")
+
+;;;
+;;; \e$B%b!<%I%i%$%s$N=$@0\e(B
+;;;
+
+(defvar canna:*kanji-mode-string* "[ \e$B$"\e(B ]")
+(defvar canna:*alpha-mode-string* "\e$B$+$s$J\e(B")
+(defvar canna:*saved-mode-string* "[ \e$B$"\e(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 nil) ; same name as TAKANA
+; \e$B$?$+$J$G$O\e(B t \e$B$,%G%U%)%k%H$@$1$I!"\e(Bnil \e$B$r%G%U%)%k%H$K$7$F$*$3$&$+$J!#\e(B
+
+(make-variable-buffer-local 'mode-line-canna-mode)
+
+; select-window-hook \e$B$O\e(B mule \e$B$+$iF~$C$?$s$@$H;W$&$1$I!"\e(B
+; \e$B$3$l$,L5$$$H\e(B preprompt \e$B$,$"$C$F$b$I$&$7$h$&$b$J$$$N$G$J$$$H$-$O\e(B
+; display-minibuffer-mode-in-minibuffer \e$B$r\e(B nil \e$B$K$9$k!#\e(B
+
+(if (not (boundp 'select-window-hook))
+ (setq display-minibuffer-mode-in-minibuffer nil))
+
+(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)))
+ ;; minibuffer\e$B$N%G%U%)%k%H$O%"%k%U%!%Y%C%H%b!<%I\e(B
+ (setq mode-line-canna-mode-in-minibuffer canna:*alpha-mode-string*
+ canna:*japanese-mode-in-minibuffer* nil
+ minibuffer-preprompt nil)))
+ (if (eq new (minibuffer-window))
+ (setq minibuffer-window-selected t)
+ (setq minibuffer-window-selected nil)))
+
+; egg:select-window-hook \e$B$G$b==J,$J$N$G!"\e(Begg:select-window-hook \e$B$,\e(B
+; \e$B@_Dj$5$l$F$$$J$$>l9g$N$_Dj5A$9$k!#\e(B
+
+; \e$BNI$/9M$($F$_$k$H\e(B display-minibuffer-mode-in-minibuffer \e$B$,\e(B t \e$B$N;~$O\e(B
+; \e$B$d$O$j>e5-$N\e(B canna:select-window-hook \e$B$,I,MW$@$J$"!#$I$&$7$h$&!#\e(B
+
+(if (and (boundp 'select-window-hook)
+ (not (eq select-window-hook 'egg:select-window-hook)))
+ (setq select-window-hook 'canna:select-window-hook))
+
+(defun mode-line-canna-mode-update (str)
+ (if (eq (current-buffer) (window-buffer (minibuffer-window)))
+ (if (and display-minibuffer-mode-in-minibuffer
+ (boundp 'minibuffer-preprompt))
+ (setq minibuffer-preprompt str)
+ ;else
+ (setq mode-line-canna-mode-in-minibuffer str))
+ (setq mode-line-canna-mode str) )
+ (set-buffer-modified-p (buffer-modified-p)) )
+
+;; memq \e$B$r6/D4$9$k$J$i!"0J2<$@$,!"\e(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)) ))))
+;; \e$B<!$NDj5A$r;H$*$&\e(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 ()
+ (if (not (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))
+ 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))
+
+;;;
+;;; 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)
+
+(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)
+
+;;;
+;;; global variables
+;;;
+
+(defvar canna-sys:*global-map* (copy-keymap global-map))
+(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:*local-map-backup* nil)
+(defvar canna:*last-kouho* 0)
+(defvar canna:*initialized* nil)
+(defvar canna:*previous-window* nil)
+(defvar canna:*minibuffer-local-map-backup* nil)
+(defvar canna:*cursor-was-in-minibuffer* nil)
+(defvar canna:*menu-buffer* " *menu*")
+(defvar canna:*saved-minibuffer*)
+(defvar canna:*saved-redirection* 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)
+
+;;;
+;;; \e$B?'$N@_Dj\e(B
+;;;
+(defvar canna-use-color nil
+ "*Non-nil \e$B$G%+%i!<%G%#%9%W%l%$$G?'$rIU$1$k\e(B.
+t \e$B$N;~$O%G%U%)%k%H$N?'$r;HMQ$9$k!#\e(B
+\e$B?'$r;XDj$7$?$$;~$O\e(B, \"\e$BFI$_$N?'\e(B\", \"\e$BJQ49BP>]$N?'\e(B\", \"\e$BA*BrBP>]$N?'\e(B\" \e$B$N\e(B
+\e$B%j%9%H$r@_Dj$9$k\e(B")
+(defvar canna:color-p nil "\e$B?'$,;H$($k$+\e(B")
+(defvar canna:attr-mode nil "\e$B8=:_$N%G%#%9%W%l%$%b!<%I\e(B")
+(defvar canna:attr-yomi nil "\e$BFI$_$N?'B0@-\e(B")
+(defvar canna:attr-taishou nil "\e$BJQ49BP>]ItJ,$N?'B0@-\e(B")
+(defvar canna:attr-select nil
+ "\e$B%_%K%P%C%U%!J,N%;~$N%a%K%e!<$NA*BrBP>]HV9f$N?'B0@-\e(B")
+(defvar canna:attribute-alist ;colored by tagu@ae.keio.ac.jp
+ '((yomi (normal . "red")
+ (reverse . "moccasin"))
+ (taishou (normal . "blue/lavender")
+ (reverse . "yellow/cadet blue"))
+ (select (normal . "DarkOliveGreen1/cadet blue")
+ (reverse . "light sea green/burlywood1")))
+ "\e$B$+$s$JJQ49;~$NG[?'$N\e(Balist")
+
+(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))
+
+;;;
+;;; \e$B%-!<%^%C%W%F!<%V%k\e(B
+;;;
+
+;; \e$B%U%'%s%9%b!<%I$G$N%m!<%+%k%^%C%W\e(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))))
+
+(define-key canna-mode-map [up] [?\C-p])
+(define-key canna-mode-map [S-up] [?\C-p])
+(define-key canna-mode-map [C-up] [?\C-p])
+(define-key canna-mode-map [down] [?\C-n])
+(define-key canna-mode-map [S-down] [?\C-n])
+(define-key canna-mode-map [C-down] [?\C-n])
+(define-key canna-mode-map [right] [?\C-f])
+(define-key canna-mode-map [S-right] [?\C-f])
+(define-key canna-mode-map [C-right] [?\C-f])
+(define-key canna-mode-map [left] [?\C-b])
+(define-key canna-mode-map [S-left] [?\C-b])
+(define-key canna-mode-map [C-left] [?\C-b])
+(define-key canna-mode-map [kanji] [? ])
+(define-key canna-mode-map [?\C- ] [?\C-@])
+
+;; \e$B%_%K%P%C%U%!$K2?$+$rI=<($7$F$$$k;~$N%m!<%+%k%^%C%W\e(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))))
+
+(define-key canna-minibuffer-mode-map [up] [?\C-p])
+(define-key canna-minibuffer-mode-map [S-up] [?\C-p])
+(define-key canna-minibuffer-mode-map [C-up] [?\C-p])
+(define-key canna-minibuffer-mode-map [down] [?\C-n])
+(define-key canna-minibuffer-mode-map [S-down] [?\C-n])
+(define-key canna-minibuffer-mode-map [C-down] [?\C-n])
+(define-key canna-minibuffer-mode-map [right] [?\C-f])
+(define-key canna-minibuffer-mode-map [S-right] [?\C-f])
+(define-key canna-minibuffer-mode-map [C-right] [?\C-f])
+(define-key canna-minibuffer-mode-map [left] [?\C-b])
+(define-key canna-minibuffer-mode-map [S-left] [?\C-b])
+(define-key canna-minibuffer-mode-map [C-left] [?\C-b])
+(define-key canna-minibuffer-mode-map [kanji] [? ])
+(define-key canna-minibuffer-mode-map [?\C- ] [?\C-@])
+
+;;;
+;;; \e$B%0%m!<%P%k4X?t$N=q$-BX$(\e(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.
+See also document for canna:saved-exit-minibuffer."
+ (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 (eq (current-buffer) (window-buffer (minibuffer-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\n\
+kana-to-kanji translation."
+ (interactive "*p")
+ (canna:functional-insert-command2 last-command-char arg) )
+
+(defun canna:functional-insert-command2 (ch arg)
+ "This function actualy isert a converted Japanese string."
+ ;; \e$B$3$N4X?t$OM?$($i$l$?J8;z$rF|K\8lF~NO$N$?$a$N%-!<F~NO$H$7$F<h$j07\e(B
+ ;; \e$B$$!"F|K\8lF~NO$NCf4V7k2L$r4^$a$?=hM}$r\e(BEmacs\e$B$N%P%C%U%!$KH?1G$5$;$k\e(B
+ ;; \e$B4X?t$G$"$k!#\e(B
+ (canna:display-candidates (canna-key-proc ch)) )
+
+(defun canna:delete-last-preedit ()
+ (if (not (zerop canna:*last-kouho*))
+ (progn
+ (if canna-underline
+ ; \e$B$^$:!"B0@-$r>C$9!#\e(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*)
+ (setq canna:*last-kouho* 0) )))
+
+(defun canna:insert-fixed (strs)
+ (cond ((> strs 0)
+ (cond ((and canna-kakutei-yomi
+ (or (null canna-save-undo-text-predicate)
+ (funcall canna-save-undo-text-predicate
+ (cons canna-kakutei-yomi
+ canna-kakutei-romaji) )))
+ (setq canna:*undo-text-yomi*
+ (cons canna-kakutei-yomi canna-kakutei-romaji))
+ (set-marker canna:*spos-undo-text* (point))
+;;
+;; update kbnes
+ (let ((list (string-to-char-list canna-kakutei-string))
+ ;; \e$BA^F~$NESCf$G\e(B blink \e$B$,5/$-$k$H$&$C$H$*$7$$$N$G!"\e(B
+ ;; \e$B0l;~E*$K\e(B blink \e$B$rM^;_$9$k!#\e(B
+ (blink-matching-paren nil))
+ (while list
+ (self-insert-internal (car list))
+ (setq list (cdr list))))
+ ;; \e$BL$3NDj$NJ8;z$,$J$/!"3NDjJ8;zNs$N:G8e$,JD$83g8L$N\e(B
+ ;; \e$BN`$@$C$?$H$-$O\e(B blink \e$B$5$;$k!#\e(B
+ (if (and canna-empty-info
+ (eq (char-syntax (char-before (point))) ?\)) )
+ (blink-matching-open))
+
+; (if overwrite-mode
+; (let ((num strs)
+; (kanji-compare 128))
+; (catch 'delete-loop
+; (while (> num 0)
+; (if (eolp)
+; (throw 'delete-loop nil))
+; (if (>= (following-char) kanji-compare)
+; (setq num (1- num)))
+; (delete-char 1)
+; (setq num (1- num))))))
+;; end kbnes
+; (insert canna-kakutei-string)
+ (if self-insert-after-hook
+ (funcall self-insert-after-hook
+ canna:*region-start* canna:*region-end*))
+ (canna:do-auto-fill)
+ (set-marker canna:*epos-undo-text* (point)) )
+ (t
+;;
+;; update kbnes
+ (let ((list (string-to-char-list canna-kakutei-string))
+ ;; \e$BA^F~$NESCf$G\e(B blink \e$B$,5/$-$k$H$&$C$H$*$7$$$N$G!"\e(B
+ ;; \e$B0l;~E*$K\e(B blink \e$B$rM^;_$9$k!#\e(B
+ (blink-matching-paren nil))
+ (while list
+ (self-insert-internal (car list))
+ (setq list (cdr list))))
+ ;; \e$BL$3NDj$NJ8;z$,$J$/!"3NDjJ8;zNs$N:G8e$,JD$83g8L$N\e(B
+ ;; \e$BN`$@$C$?$H$-$O\e(B blink \e$B$5$;$k!#\e(B
+ (if (and canna-empty-info
+ (eq (char-syntax (char-before (point))) ?\)) )
+ (blink-matching-open))
+
+; (if overwrite-mode
+; (let ((num strs)
+; (kanji-compare 128))
+; (catch 'delete-loop
+; (while (> num 0)
+; (if (eolp)
+; (throw 'delete-loop nil))
+; (if (>= (following-char) kanji-compare)
+; (setq num (1- num)))
+; (delete-char 1)
+; (setq num (1- num))))))
+;; end kbnes
+; (insert canna-kakutei-string)
+ (if self-insert-after-hook
+ (funcall self-insert-after-hook
+ canna:*region-start* canna:*region-end*))
+ (canna:do-auto-fill) ))
+ ) ))
+
+(defun canna:insert-preedit ()
+ (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)
+ ))
+
+ ;; \e$B8uJdNN0h$G$O6/D4$7$?$$J8;zNs$,B8:_$9$k$b$N$H9M$($i\e(B
+ ;; \e$B$l$k!#6/D4$7$?$$J8;z$O\e(BEmacs\e$B$G$O%+!<%=%k%]%8%7%g%s$K$FI=<(\e(B
+ ;; \e$B$9$k$3$H$H$9$k!#6/D4$7$?$$J8;z$,$J$$$N$G$"$l$P!"%+!<%=%k\e(B
+ ;; \e$B$O0lHV8e$NItJ,\e(B(\e$BF~NO$,9T$o$l$k%]%$%s%H\e(B)\e$B$KCV$$$F$*$/!#\e(B
+
+ ;; \e$B%+!<%=%k$r0\F0$9$k!#\e(B
+ (if (not canna-underline)
+ (backward-char
+ (- canna:*last-kouho*
+ ;; \e$B%+!<%=%k0LCV$O!"H?E>I=<(ItJ,$,B8:_$7$J$$$N$G$"$l$P!"\e(B
+ ;; \e$B8uJdJ8;zNs$N:G8e$NItJ,$H$7!"H?E>I=<(ItJ,$,B8:_$9$k$N\e(B
+ ;; \e$B$G$"$l$P!"$=$NItJ,$N;O$a$H$9$k!#\e(B
+ (cond ((zerop canna-henkan-revlen)
+ canna:*last-kouho*)
+ (t canna-henkan-revpos) )) )
+ (if (and (> canna-henkan-revlen 0)
+ (> canna-henkan-length 0))
+ ; \e$B8uJd$ND9$5$,\e(B0\e$B$G$J$/!"\e(B
+ ; \e$BH?E>I=<($ND9$5$,\e(B0\e$B$G$J$1$l$P!"\e(B
+ ; \e$B$=$NItJ,$rJQE>I=<($9$k!#\e(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) ; \e$B%(%i!<$,5/$3$C$?>l9g\e(B
+ (beep)
+ (message strs) )
+ (canna-henkan-string
+ ;; \e$B$b$78uJdI=<($,A0$N7k2L$+$iJQ$o$C$F$$$J$/$J$$$H$-$O\e(B......
+
+ ;; \e$B<h$j9g$($::G=i$OA0$K=q$$$F$*$$$?Cf4V7k2L$r>C$9!#\e(B
+ (canna:delete-last-preedit)
+
+ ;; \e$B3NDj$7$?J8;zNs$,$"$l$P$=$l$rA^F~$9$k!#\e(B
+ (canna:insert-fixed strs)
+
+ ;; \e$B<!$O8uJd$K$D$$$F$N:n6H$G$"$k!#\e(B
+
+ ;; \e$B8uJd$rA^F~$9$k!#8uJd$O=DK@FsK\$K$F64$^$l$k!#\e(B
+ (canna:insert-preedit)
+ ))
+
+ ;; \e$B%b!<%I$rI=$9J8;zNs$,B8:_$9$l$P$=$l$r%b!<%I$H$7$F<h$j07$&!#\e(B
+ (if (stringp canna-mode-string)
+ (mode-line-canna-mode-update canna-mode-string))
+
+ ;; \e$B8uJdI=<($,$J$1$l$P%U%'%s%9%b!<%I$+$iH4$1$k!#\e(B
+ (cond (canna-empty-info (canna:quit-canna-mode)))
+
+ ;; \e$B%_%K%P%C%U%!$K=q$/$3$H$,B8:_$9$k$N$G$"$l$P!"$=$l$r%_%K%P%C%U%!\e(B
+ ;; \e$B$KI=<($9$k!#\e(B
+ (cond (canna-ichiran-string
+ (canna:minibuffer-input canna-ichiran-string
+ canna-ichiran-length
+ canna-ichiran-revpos
+ canna-ichiran-revlen
+ strs) )
+ (canna:*cursor-was-in-minibuffer*
+; (select-frame (window-frame (minibuffer-window)))
+ (select-window (minibuffer-window))
+ (set-window-buffer (minibuffer-window)
+ (get-buffer-create canna:*menu-buffer*))
+ (use-local-map canna-minibuffer-mode-map) ))
+ )
+
+(defun canna:minibuffer-input (str len revpos revlen nfixed)
+ "Displaying misc informations for kana-to-kanji input."
+
+ ;; \e$B:n6H$r%_%K%P%C%U%!$K0\$9$N$K:]$7$F!"8=:_$N%&%#%s%I%&$N>pJs$rJ]B8\e(B
+ ;; \e$B$7$F$*$/!#\e(B
+ (setq canna:*previous-window* (selected-window))
+; (select-frame (window-frame (minibuffer-window)))
+
+;; \e$B<+J,$KMh$kA0$,%_%K%P%C%U%!$+$I$&$+$rJQ?t$K$G$b$$$l$F$*$$$?J}$,$$$$$J$"!#\e(B
+
+ (if (not canna:*cursor-was-in-minibuffer*)
+ (progn
+ ;; \e$B%_%K%P%C%U%!$r%/%j%"$9$k!#\e(B
+; (if (eq canna:*previous-window* (selected-window))
+; (progn
+; (canna:henkan-attr-off (point-min) (point-max))
+; (canna:delete-last-preedit) ))
+
+ ;; \e$B%_%K%P%C%U%!%&%#%s%I%&$K8uJd0lMwMQ$N%P%C%U%!$r3d$jEv$F$k!#\e(B
+ (setq canna:*saved-minibuffer* (window-buffer (minibuffer-window)))
+; (set-window-buffer (minibuffer-window)
+; (get-buffer-create canna:*menu-buffer*))
+ (setq canna:*saved-redirection* (frame-focus (selected-frame)))
+ (redirect-frame-focus (selected-frame)
+ (window-frame (minibuffer-window)))
+
+ ;; \e$B%_%K%P%C%U%!$N%-!<%^%C%W$rJ]B8$7$F$*$/!#\e(B
+ (setq canna:*minibuffer-local-map-backup* (current-local-map))
+ ))
+ (select-window (minibuffer-window))
+ (set-window-buffer (minibuffer-window)
+ (get-buffer-create canna:*menu-buffer*))
+
+ (use-local-map canna-minibuffer-mode-map)
+
+; (canna:yomi-attr-off (point-min) (point-max) )
+; (canna:henkan-attr-off (point-min) (point-max) )
+ (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))
+
+ (insert str)
+
+ ;; \e$B%_%K%P%C%U%!$GH?E>I=<($9$k$Y$-J8;z$N$H$3$m$K%+!<%=%k$r0\F0$9$k!#\e(B
+ (cond ((> revlen 0)
+ (backward-char (- len revpos)) ))
+ ;;(message "%s" (selected-frame)) (sit-for 3)
+ (raise-frame (window-frame (minibuffer-window)))
+; (select-frame (window-frame (minibuffer-window)))
+ (and canna:color-p (not (eobp))
+ (canna:select-attr-on (point)
+ (save-excursion (forward-char 1) (point))))
+
+ ;; \e$B%_%K%P%C%U%!$KI=<($9$k$Y$-J8;zNs$,%L%kJ8;zNs$J$N$G$"$l$P!"A0$N%&%#\e(B
+ ;; \e$B%s%I%&$KLa$k!#\e(B
+ (if (or (zerop len) canna-empty-info)
+ (progn
+ (setq canna:*cursor-was-in-minibuffer* nil)
+ (use-local-map canna:*minibuffer-local-map-backup*)
+
+ ;; \e$B%_%K%P%C%U%!%&%#%s%I%&$N%P%C%U%!$r85$KLa$9!#\e(B
+ (set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
+; (setq canna:*saved-minibuffer* nil)
+ (redirect-frame-focus (window-frame canna:*previous-window*)
+ canna:*saved-redirection*)
+ ; \e$B%_%K%P%C%U%!$GF~NO$7$F$$$?$N$J$i0J2<$b$9$k!#\e(B
+; (if (eq canna:*previous-window* (selected-window))
+; (progn
+; (canna:insert-fixed nfixed)
+; (canna:insert-preedit) ))
+
+ (if (and canna-empty-info (> len 0))
+ (progn
+; (delete-region (point-min) (point-max))
+ (message 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")
+ (use-local-map canna:*minibuffer-local-map-backup*)
+ (set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
+ (select-window canna:*previous-window*)
+ (canna:functional-insert-command2 last-command-char arg) )
+
+;;;
+;;; \e$B$+$s$J%b!<%I$N<gLr$O!"<!$N\e(B canna-self-insert-command \e$B$G$"$k!#$3$N\e(B
+;;; \e$B%3%^%s%I$OA4$F$N%0%i%U%#%C%/%-!<$K%P%$%s%I$5$l$k!#\e(B
+;;;
+;;; \e$B$3$N4X?t$G$O!"8=:_$N%b!<%I$,F|K\8lF~NO%b!<%I$+$I$&$+$r%A%'%C%/$7$F!"\e(B
+;;; \e$BF|K\8lF~NO%b!<%I$G$J$$$N$G$"$l$P!"%7%9%F%`$N\e(B self-insert-command
+;;; \e$B$r8F$V!#F|K\8lF~NO%b!<%I$G$"$l$P!"%U%'%s%9%b!<%I$KF~$j!"\e(B
+;;; canna-functional-insert-command \e$B$r8F$V!#\e(B
+;;;
+
+(if (not (boundp 'MULE)) ; for Nemacs
+ (defun cancel-undo-boundary ()))
+
+(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*
+ ;; \e$B%U%'%s%9%b!<%I$@$C$?$i$b$&0lEY%U%'%s%9%b!<%I$KF~$C$?$j$7\e(B
+ ;; \e$B$J$$!#\e(B
+ (not canna:*fence-mode*) )
+ (canna:enter-canna-mode-and-functional-insert)
+ (progn
+ ;; \e$B0J2<$NItJ,$O\e(B egg.el \e$B$N\e(B 3.09 \e$B$N\e(B egg-self-insert-command \e$B$NItJ,$+$i\e(B
+ ;; \e$B%3%T!<$7!"<j$rF~$l$F$$$^$9!#\e(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 (eq last-command 'canna-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 self-insert-after-hook
+ (if (<= 1 arg)
+ (funcall self-insert-after-hook
+ (- (point) arg) (point)))
+ (if (= last-command-char ? ) (canna:do-auto-fill))))))
+
+(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 \e$B$5$l$F$$$?$i2?$b$7$J$$\e(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 \e$B$5$l$F$$$J$+$C$?$i2?$b$7$J$$\e(B
+ (t
+ (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))) ))
+ )
+ (message "\e$B!X$+$s$J!Y$N<-=q$r%;!<%V$7$^$9!#\e(B")
+ )))
+
+(defun canna:enter-canna-mode ()
+ (if (not canna:*initialized*)
+ (progn
+ (message "\e$B!X$+$s$J!Y$N=i4|2=$r9T$C$F$$$^$9\e(B....")
+ (canna:initialize)
+ (message "\e$B!X$+$s$J!Y$N=i4|2=$r9T$C$F$$$^$9\e(B....done")
+ ))
+ (canna-set-width (- (window-width (minibuffer-window))
+ (minibuffer-prompt-width)
+ (if (and display-minibuffer-mode-in-minibuffer
+ (eq (selected-window) (minibuffer-window)))
+ (string-width
+ (let ((new-mode (canna-query-mode)))
+ (if (string-equal new-mode "")
+ canna:*saved-mode-string*
+ new-mode)))
+ 0)))
+ (setq canna:*local-map-backup* (current-local-map))
+ (setq canna:*fence-mode* t)
+ (if (boundp 'disable-undo)
+ (setq disable-undo canna:*fence-mode*))
+ (use-local-map canna-mode-map) )
+
+(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*
+ (use-local-map canna:*local-map-backup*)
+ (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*) )))
+ (if (boundp 'disable-undo)
+ (setq disable-undo canna:*fence-mode*))
+ ))
+ (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 canna:*japanese-mode*
+ (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 canna:*japanese-mode*
+ (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 "\e$B%j!<%8%g%s$,IT@5$G$9!#%L%k%j!<%8%g%s$+!"2~9T$,4^$^$l$F$$$^$9!#\e(B")
+ ))
+
+(defun canna-extend-mode ()
+ "To enter an extend-mode of Canna."
+ (interactive "*")
+; (if (and (not (eq (window-frame (minibuffer-window)) (selected-frame)))
+; (not canna:*fence-mode*))
+ ;; \e$B%_%K%P%C%U%!$rJ,N%$7$F$$$k;~$O0l;~E*$K%U%'%s%9%b!<%I$KF~$k\e(B
+ ;; \e$B$=$&$7$J$$$H%a%K%e!<$rA*$Y$J$$\e(B
+ ;; (focus\e$B$,%_%K%P%C%U%!$K9T$+$J$$$+$i\e(B)
+ (if (not canna:*fence-mode*)
+ (progn
+ (setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+ (canna:enter-canna-mode)
+ (canna:display-candidates
+ (canna-do-function canna-func-extend-mode) ))
+ (beep)))
+
+(defun canna-kigou-mode ()
+ "Enter symbol choosing mode."
+ (interactive "*")
+; (if canna:*japanese-mode*
+ (if (not canna:*fence-mode*)
+ (progn
+ (setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+ (canna:enter-canna-mode)
+ (canna:display-candidates (canna-change-mode canna-mode-kigo-mode)) )
+ (beep)
+ ))
+
+(defun canna-hex-mode ()
+ "Enter hex code entering mode."
+ (interactive "*")
+; (if canna:*japanese-mode*
+ (if (not canna:*fence-mode*)
+ (progn
+ (setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+ (canna:enter-canna-mode)
+ (canna:display-candidates (canna-change-mode canna-mode-hex-mode)) )
+ (beep)
+ ))
+
+(defun canna-bushu-mode ()
+ "Enter special mode to convert by BUSHU name."
+ (interactive "*")
+; (if canna:*japanese-mode*
+ (if (not canna:*fence-mode*)
+ (progn
+ (setq canna:*exit-japanese-mode* (not canna:*japanese-mode*))
+ (canna:enter-canna-mode)
+ (canna:display-candidates (canna-change-mode canna-mode-bushu-mode)) )
+ (beep)
+ ))
+
+(defun canna-reset ()
+ (interactive)
+ (message "\e$B!X$+$s$J!Y$N<-=q$r%;!<%V$7$^$9!#\e(B");
+ (canna:finalize)
+ (message "\e$B!X$+$s$J!Y$N:F=i4|2=$r9T$C$F$$$^$9\e(B....")
+ (canna:initialize)
+ (message "\e$B!X$+$s$J!Y$N:F=i4|2=$r9T$C$F$$$^$9\e(B....done")
+ )
+
+
+(defun canna ()
+ (interactive)
+ (message "\e$B!X$+$s$J!Y$r=i4|2=$7$F$$$^$9\e(B....")
+ (let (init-val)
+ (cond ((and (fboundp 'canna-initialize) (fboundp 'canna-change-mode) )
+
+ ;; canna \e$B$,;H$($k;~$O<!$N=hM}$r$9$k!#\e(B
+
+ ;; \e$BG[?'@_Dj\e(B (by yuuji@ae.keio.ac.jp)
+ (setq canna:color-p (and canna-use-color
+ window-system
+ (x-display-color-p)))
+ ;;\e$B%+%i!<$N;~\e(Bunderline\e$B%b!<%I$HF1$8>uBV$G=i4|2=$9$kI,MW$,$"$k\e(B
+ (setq canna-underline (or canna:color-p canna-underline))
+ (cond
+ (canna:color-p
+ (setq canna:attr-mode
+ (cond
+ ((or (and (boundp 'hilit-background-mode)
+ (eq hilit-background-mode 'dark))
+ (string-match
+ "on\\|t"
+ (or (x-get-resource "ReverseVideo" "reverseVideo")
+ "")))
+ 'reverse) ;\e$BH?E>$7$F$$$k$J$i\e(B 'reverse
+ (t 'normal)))
+ (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))))))
+ ;;\e$B?'$E$1MQ\e(Bface\e$B$N:n@.\e(B
+ (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))
+ ))
+ ;;\e$BG[?'@_Dj=*N;\e(B
+
+ ;; \e$B!X$+$s$J!Y%7%9%F%`$N=i4|2=\e(B
+
+ (setq init-val (canna:initialize))
+
+ ;; \e$B%-!<$N%P%$%s%G%#%s%0\e(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 ; \e$B%G%U%)%k%H$N@_Dj\e(B
+ (global-set-key "\C-o" 'canna-toggle-japanese-mode) ))
+
+ (if (not (keymapp (global-key-binding "\e[")))
+ (global-unset-key "\e[") )
+ (global-set-key "\e[210z" 'canna-toggle-japanese-mode) ; XFER
+ (define-key global-map [kanji] 'canna-toggle-japanese-mode)
+ (if canna-do-keybind-for-functionkeys
+ (progn
+ (global-set-key "\e[28~" 'canna-extend-mode) ; HELP on EWS4800
+ (global-set-key "\e[2~" 'canna-kigou-mode) ; INS on EWS4800
+ (global-set-key "\e[11~" 'canna-kigou-mode)
+ (global-set-key "\e[12~" 'canna-hex-mode)
+ (global-set-key "\e[13~" 'canna-bushu-mode)
+ (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 \e$B$O\e(B C-@ \e$B$H\e(B C-SPC \e$B$r6hJL$9$k$N$G!"$3$l$,I,MW!#\e(B
+ (global-set-key [?\C-\ ] 'canna-set-mark-command)
+ (global-set-key " " 'canna-henkan-region-or-self-insert) ))
+
+ ;; \e$B%b!<%I9T$N:n@.\e(B
+
+ (canna:create-mode-line)
+ (mode-line-canna-mode-update canna:*alpha-mode-string*)
+
+ ;; \e$B%7%9%F%`4X?t$N=q$-BX$(\e(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 "\e$B$3$N\e(B Mule \e$B$G$O\e(B new-canna \e$B$,;H$($^$;$s\e(B")
+ (terpri)
+ (print-help-return-message)) )
+
+ (t ; \e$B!X$+$s$J!Y%7%9%F%`$,;H$($J$+$C$?;~$N=hM}\e(B
+ (beep)
+ (with-output-to-temp-buffer "*canna-warning*"
+ (princ "\e$B$3$N\e(B Mule \e$B$G$O\e(B canna \e$B$,;H$($^$;$s\e(B")
+ (terpri)
+ (print-help-return-message))
+ ))
+ (message "\e$B!X$+$s$J!Y$r=i4|2=$7$F$$$^$9\e(B....done")
+ ) )
+
+;;;
+;;; auto fill controll (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*))
+; (canna-without-newline canna:*spos-undo-text*
+; canna:*epos-undo-text*)
+ )
+ (progn
+ (message "\e$BFI$_$KLa$7$^$9!*\e(B")
+; (switch-to-buffer (marker-buffer canna:*spos-undo-text*))
+ (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) ))
+; (canna-toggle-japanese-mode) ))
+ (if (not canna:*fence-mode*)
+ ;; \e$B%U%'%s%9%b!<%I$@$C$?$i$b$&0lEY%U%'%s%9%b!<%I$KF~$C$?$j$7\e(B
+ ;; \e$B$J$$!#\e(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)
+ )
+ (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")
+ (if (null canna:*japanese-mode*)
+ (progn
+ (setq canna:*exit-japanese-mode* t) ))
+; (canna-toggle-japanese-mode) ))
+ (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) ))
+
+;;;
+;;; \e$B%^!<%/%3%^%s%I!$\e(Bcanna-henkan-region-or-self-insert \e$B$G;H$&$+$b\e(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")
+ (set-mark-command arg)
+ (if canna:*japanese-mode*
+ (progn
+ (setq canna:*use-region-as-henkan-region* t)
+ (message "Mark set(\e$BJQ49NN0h3+;O\e(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*
+; (< (mark) (point))
+; (not (save-excursion (beginning-of-line) (< (mark) (point)))) )
+ (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
+;;
+
+(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 ()
+ (define-key c-mode-map "{" 'canna-electric-c-brace)
+ (define-key c-mode-map "}" 'canna-electric-c-brace)
+ (define-key c-mode-map ";" 'canna-electric-c-semi)
+ (define-key c-mode-map ":" 'canna-electric-c-terminator) )
+
+(defun canna-set-fence-mode-format (fence sep underline)
+ (setq canna-with-fences fence)
+ (canna-set-bunsetsu-kugiri sep)
+ (setq canna-underline underline)
+)
+
+;; \e$B%j!<%8%g%s$K$"$k%m!<%^;z$r!X$+$s$J!Y$K?)$o$9!#\e(B
+;; \e$B7k2L$H$7$F!"!X$+$s$J!Y$NFI$_%b!<%I$K$J$k!#\e(B
+;; \e$B%j!<%8%g%s$KB8:_$7$F$$$k6uGrJ8;z$H@)8fJ8;z$O<N$F$i$l$k!#\e(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) ))
+
+;; \e$B%+!<%=%k$N:8$K$"$k\e(B arg \e$B%o!<%I$N%m!<%^;z$r!X$+$s$J!Y$K?)$o$9!#\e(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 ()
+ (let ((res 0)
+ (kakutei canna-henkan-string))
+ (while (not canna-empty-info)
+; (setq res (canna-key-proc ?\C-m)))
+ (setq res (canna-do-function canna-func-kakutei)))
+ (setq canna-kakutei-string kakutei)
+ (canna:display-candidates (length canna-kakutei-string))
+ (if (not canna:*japanese-mode*)
+ (mode-line-canna-mode-update canna:*alpha-mode-string*))
+ ))
+
+(defun canna-minibuffer-henkan-kakutei-and-self-insert (arg)
+ (interactive "p")
+ (set-window-buffer (minibuffer-window) canna:*saved-minibuffer*)
+ (select-window canna:*previous-window*)
+ (if canna:*japanese-mode*
+ (canna:functional-insert-command2 last-command-event arg)
+ (progn
+ (setq unread-command-events (list last-command-event))
+ (canna-kakutei-to-basic-stat)) ))
+
+(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-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"))
+
+;;
+;; \e$B?'$E$1$N$?$a$N4X?t\e(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* (make-overlay start end nil 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* (make-overlay start end nil 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* (make-overlay start end nil t))
+ 'face
+ 'attr-select))
+ )
+
+(defun canna:select-attr-off (start end)
+ (and (overlayp canna:*select-overlay*)
+ (delete-overlay canna:*select-overlay*)
+ )
+ )