[uim-commit] r2258 - in trunk: . emacs

ekato at freedesktop.org ekato at freedesktop.org
Sat Nov 26 21:59:57 PST 2005


Author: ekato
Date: 2005-11-26 21:59:54 -0800 (Sat, 26 Nov 2005)
New Revision: 2258

Added:
   trunk/emacs/
   trunk/emacs/COPYING
   trunk/emacs/INSTALL
   trunk/emacs/Makefile.am
   trunk/emacs/README
   trunk/emacs/README.jp
   trunk/emacs/callback.c
   trunk/emacs/callback.h
   trunk/emacs/candidate.c
   trunk/emacs/candidate.h
   trunk/emacs/commit.c
   trunk/emacs/commit.h
   trunk/emacs/context.c
   trunk/emacs/context.h
   trunk/emacs/debug.c
   trunk/emacs/debug.h
   trunk/emacs/encoding.c
   trunk/emacs/encoding.h
   trunk/emacs/helper-server.c
   trunk/emacs/helper-server.h
   trunk/emacs/helper.c
   trunk/emacs/helper.h
   trunk/emacs/im.c
   trunk/emacs/im.h
   trunk/emacs/key.c
   trunk/emacs/key.h
   trunk/emacs/output.c
   trunk/emacs/output.h
   trunk/emacs/preedit.c
   trunk/emacs/preedit.h
   trunk/emacs/prop.c
   trunk/emacs/prop.h
   trunk/emacs/uim-candidate.el
   trunk/emacs/uim-debug.el
   trunk/emacs/uim-el-agent.c
   trunk/emacs/uim-el-agent.h
   trunk/emacs/uim-key.el
   trunk/emacs/uim-keymap.el
   trunk/emacs/uim-leim.el
   trunk/emacs/uim-preedit.el
   trunk/emacs/uim-util.el
   trunk/emacs/uim-var.el
   trunk/emacs/uim.el
Modified:
   trunk/Makefile.am
   trunk/configure.ac
Log:
* Merge Konosuke Watanabe's uim-el
(http://garakuta.homelinux.org/~nosuke/tsubo/uim-el.html).

* configure.ac : Support --enable-emacs.
* Makefile.am : Ditto.
* emacs/
* emacs/COPYING
* emacs/INSTALL
* emacs/Makefile.am
* emacs/README
* emacs/README.jp
* emacs/callback.c
* emacs/callback.h
* emacs/candidate.c
* emacs/candidate.h
* emacs/commit.c
* emacs/commit.h
* emacs/context.c
* emacs/context.h
* emacs/debug.c
* emacs/debug.h
* emacs/encoding.c
* emacs/encoding.h
* emacs/helper-server.c
* emacs/helper-server.h
* emacs/helper.c
* emacs/helper.h
* emacs/im.c
* emacs/im.h
* emacs/key.c
* emacs/key.h
* emacs/output.c
* emacs/output.h
* emacs/preedit.c
* emacs/preedit.h
* emacs/prop.c
* emacs/prop.h
* emacs/uim-candidate.el
* emacs/uim-debug.el
* emacs/uim-el-agent.c
* emacs/uim-el-agent.h
* emacs/uim-key.el
* emacs/uim-keymap.el
* emacs/uim-leim.el
* emacs/uim-preedit.el
* emacs/uim-util.el
* emacs/uim-var.el
* emacs/uim.el
  - New file.


Modified: trunk/Makefile.am
===================================================================
--- trunk/Makefile.am	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/Makefile.am	2005-11-27 05:59:54 UTC (rev 2258)
@@ -1,5 +1,6 @@
 AUTOMAKE_OPTIONS = foreign
-SUBDIRS = m4 doc replace uim scm gtk qt xim helper po test fep examples pixmaps
+SUBDIRS = m4 doc replace uim scm gtk qt xim helper po test fep emacs \
+	examples pixmaps
 EXTRA_DIST = README.ja INSTALL.ja test.sh.in uim.spec.in \
 	intltool-extract.in intltool-merge.in intltool-update.in \
 	uim.pc.in ChangeLog.old uim.desktop autogen.sh RELEASING
@@ -45,14 +46,15 @@
 .PHONY: ChangeLog releasetest-all-flag-enabled releasetest-all-flag-disabled each-releasetest releasetest
 
 releasetest-all-flag-enabled: RELEASETEST_CONFIGURE_FLAGS= --enable-debug \
-	 --enable-fep --enable-dict --with-m17nlib --with-canna \
-	 --with-gtk2 --with-gnome2 --with-qt --with-qt-immodule --with-libedit
+	--enable-fep --enable-emacs --enable-dict \
+	--with-m17nlib --with-canna --with-gtk2 --with-gnome2 --with-qt \
+	--with-qt-immodule --with-libedit
 releasetest-all-flag-enabled: each-releasetest
 
 releasetest-all-flag-disabled: RELEASETEST_CONFIGURE_FLAGS= --disable-debug \
-	--disable-fep --disable-sumika	--disable-dict --without-m17nlib \
-	--without-canna --without-gtk2  --without-gnome2 --without-qt \
-	--without-qt-immodule --without-libedit
+	--disable-fep --disable-sumika --disable-emacs --disable-dict \
+	--without-m17nlib --without-canna --without-gtk2  --without-gnome2 \
+	--without-qt --without-qt-immodule --without-libedit
 releasetest-all-flag-disabled: each-releasetest
 
 each-releasetest:

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/configure.ac	2005-11-27 05:59:54 UTC (rev 2258)
@@ -420,6 +420,26 @@
     AC_SUBST(FEP_LIBADD)
   ])
 
+AC_ARG_ENABLE(emacs,
+  AC_HELP_STRING([--disable-emacs],
+                 [disable uim-el]),
+  [
+    case $enable_emacs in
+      no)
+        use_uim_el="no"
+      ;;
+      yes|*)
+        use_uim_el="yes"
+        AM_PATH_LISPDIR
+        AC_SUBST(UIMEL_LISP_DIR, $lispdir/uim-el)
+      ;;
+    esac
+  ],
+  [ use_uim_el="yes"
+    AM_PATH_LISPDIR
+    AC_SUBST(UIMEL_LISP_DIR, $lispdir/uim-el)
+  ])
+
 AC_ARG_ENABLE(dict,
   AC_HELP_STRING([--enable-dict],
                  [enable uim-dict (a dictionary utility for uim, broken)]),
@@ -526,6 +546,7 @@
 AM_CONDITIONAL(GNOME2, test x$use_gnome2 = xyes)
 AM_CONDITIONAL(APPLET, test x$use_applet = xyes)
 AM_CONDITIONAL(UIM_FEP, test x$use_uim_fep = xyes)
+AM_CONDITIONAL(UIM_EL, test x$use_uim_el = xyes)
 AM_CONDITIONAL(XIM, test x$use_xim = xyes)
 AM_CONDITIONAL(DICT, test x$use_dict = xyes)
 AM_CONDITIONAL(EB, test x$use_eb = xyes)
@@ -754,17 +775,18 @@
 
 
 AC_CONFIG_FILES([test.sh
-                 Makefile
-                 po/Makefile.in
+		 Makefile
+		 po/Makefile.in
 		 m4/Makefile
-                 helper/Makefile
-                 doc/Makefile
-                 uim/Makefile
-                 scm/Makefile
-                 gtk/Makefile
-                 qt/Makefile
-                 xim/Makefile
+		 helper/Makefile
+		 doc/Makefile
+		 uim/Makefile
+		 scm/Makefile
+		 gtk/Makefile
+		 qt/Makefile
+		 xim/Makefile
 		 fep/Makefile
+		 emacs/Makefile
 		 test/Makefile
 		 examples/Makefile
 		 examples/uim-custom/Makefile
@@ -772,7 +794,7 @@
 		 replace/Makefile
 		 uim.pc
 		 uim.desktop
-                 ])
+		 ])
 
 AC_OUTPUT
 
@@ -790,6 +812,7 @@
    Qt              : ${use_qt}
    Qt immodule     : ${use_qtimmodule}
    FEP             : ${use_uim_fep}
+   Emacs           : ${use_uim_el}
    XIM             : ${use_xim}
    DICT            : ${use_dict}
    EB              : ${use_eb}

Added: trunk/emacs/COPYING
===================================================================
--- trunk/emacs/COPYING	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/COPYING	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,34 @@
+uim.el - Emacs Uim bridge
+
+Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Added: trunk/emacs/INSTALL
===================================================================
--- trunk/emacs/INSTALL	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/INSTALL	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,229 @@
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
+Foundation, Inc.
+
+   This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+   These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+   You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory.  After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+   By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+   Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+   There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on.  Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the `--target=TYPE' option to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+   Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+will cause the specified gcc to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+`configure' Invocation
+======================
+
+   `configure' recognizes the following options to control how it
+operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+

Added: trunk/emacs/Makefile.am
===================================================================
--- trunk/emacs/Makefile.am	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/Makefile.am	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,20 @@
+EXTRA_DIST = README.jp
+
+if UIM_EL
+
+uimel_target = uim.el uim-var.el uim-keymap.el uim-key.el uim-util.el uim-candidate.el uim-preedit.el uim-debug.el uim-leim.el
+uimeldir = $(UIMEL_LISP_DIR)
+uimel_DATA = $(uimel_target)
+
+bin_PROGRAMS = uim-el-agent
+
+uim_el_agent_SOURCES = uim-el-agent.c debug.c output.c context.c preedit.c \
+ key.c candidate.c encoding.c im.c callback.c commit.c helper-server.c \
+ helper.c prop.c callback.h candidate.h commit.h context.h debug.h \
+ encoding.h helper-server.h helper.h im.h key.h output.h preedit.h \
+ prop.h uim-el-agent.h
+
+uim_el_agent_CPPFLAGS = -I$(top_srcdir)
+uim_el_agent_LDADD = $(top_builddir)/uim/libuim.la
+
+endif
\ No newline at end of file

Added: trunk/emacs/README
===================================================================
--- trunk/emacs/README	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/README	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,318 @@
+uim.el - Emacs Uim bridge
+
+Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+All rights reserved.
+
+This software is released under the BSD license.
+
+
+ABOUT uim.el
+============
+
+uim.el is a bridge software between Emacs and Uim.
+
+uim.el makes you able to use Uim supported IMs from Emacs
+directly.
+
+
+FEATURES
+========
+
+- Inline Candidates Displaying Mode
+
+While most of IMs supported by Emacs display the candidates
+in the echo area, uim.el can display candidates as follows;
+  - display them just below the preedit string
+  - align them in vertical direction
+
+This is a mode called ``inline candidates displaying mode.''
+
+This mode releases users from an affliction that should move
+their eyes from current cursor position to bottom of the
+buffer every selection time.
+
+Also, by aligning candidates vertically, users can select a
+candidate naturally, like using other Uim bridges.
+
+
+- Preedit Displaying on the Emacs Buffer
+
+Unlike uim-xim or uim-fep, uim.el displays preedit string on
+the Emacs buffer.  So, the existing characters after the
+cursor are never hidden behind the preedit string.
+
+
+- IM Managing on Each Buffer
+
+uim.el manages the IM on each buffer independently.
+
+Users can use different IM (such as Anthy, Skk, Canna and so
+on) on each buffer and also can do conversion in
+concurrently.
+
+
+REQUIREMENTS
+============
+
+As you guessed, uim.el requires Emacs and Uim.
+
+- Emacs: following versions are supported
+
+  - FSF Emacs 20.7
+  - FSF Emacs 21.3.1
+  - FSF Emacs 22.0.50 (CVS version)
+  - XEmacs 21.4.17 (with sumo and mule-sumo)
+
+  * note: Ancient Emacs such as Emacs-19.x or Mule-2.3 are
+          not supported
+
+- Uim: 0.4.6 or later
+          (highly recommended to use the latest version)
+
+  Also, you should install some IMs which can be used with
+  Uim if required.
+
+
+INSTALLATION
+============
+
+You can install uim.el in usual way
+
+ % ./configure
+ % make
+ % su
+ # make install
+
+  * note: It is recommended to remove older version of uim.el
+          before upgrading.
+
+USAGE
+=====
+
+uim.el is implemented as a minor-mode of Emacs.
+
+You can call uim.el from Emacs in two ways; 
+directly or with the LEIM framework.
+
+Though settings of them are different, basic functions are
+same.
+
+If you want to switch between uim.el and other Emacs IMs
+frequently, you should use LEIM framework.
+
+
+[Settings for the minor-mode]
+
+Write the following settings into your .emacs or some other
+file for Emacs customizing.
+
+  ;; read uim.el
+  (require 'uim)
+  ;; uncomment next and comment out previous to load uim.el on-demand
+  ;; (autoload 'uim-mode "uim" nil t)
+
+  ;; set default IM (ex. use Anthy)
+  ;; (setq uim-default-im-engine "anthy")
+
+  ;; key-binding for activate Uim (ex. C-o)
+  (global-set-key "\C-o" 'uim-mode)
+
+
+[Settings for the LEIM]
+
+Write the following settings into your .emacs or some other
+file for Emacs customizing.
+
+  ;; read uim.el with LEIM initializing
+  (require 'uim-leim)
+
+  ;; set default IM (ex. use Anthy)
+  (setq default-input-method "japanese-anthy-uim")
+
+  * note: The naming rule of the IMs of LEIM are as follows.
+
+     <lang. of Emacs>-<each IM name of Uim>-uim
+
+     for example...
+       - chinese-big5-pinyin-big5-uim
+       - japanese-skk-uim
+       - vietnamese-viqr-uim
+
+     Correspondence between Emacs Language name and Uim
+     Language name are described in uim-el/uim.el.
+
+     Also, available names can be listed in the following way;
+
+       M-x set-input-method RET TAB
+
+
+[Path Settings]
+
+You can install uim.el into any directory of your computer
+if you have a permit. 
+
+If you have installed uim.el and its back-end software 
+(i.e., uim-el-agent) into nonstandard directory, you should 
+describe paths to them before uim.el loading as follows.
+
+  ;; path to uim.el and other lisp files
+  (setq load-path (append '("/home/nosuke/uim-el/uim-el") load-path))
+
+  ;; path to uim-el-agent 
+  ;; (path of executable binary file, not a directory)
+  (setq uim-el-agent "/home/nosuke/uim-el/uim-el-agent/uim-el-agent")
+
+
+
+
+CUSTOMIZATION
+=============
+
+* Change treatment of Escape-key on terminal-mode
+
+To support function keys, such as F10 and Delete, 
+when Emacs has been executed on terminal 
+window (i.e., with -nw option), uim.el 
+doesn't pass  single Escape-key to Uim by default.
+
+If you want to invoke Uim function bound to a Escape-key,
+press Escape-key in two times.
+
+
+Following is a configuration to invalidate this 
+setting while preedits are displayed.
+
+  ;; enable single Escape-key pressing on terminal
+  (setq uim-use-single-escape-on-terminal t)
+
+  * note: This configuration is unrecommended.
+
+
+
+* Change candidate style
+
+If you want to enable inline candidates displaying mode by
+default, write as follows.
+
+   ;; set inline candidates displaying mode as default
+   (setq uim-candidate-display-inline t)
+
+
+Also, to switch candidates displaying mode immediately,
+write as follows.
+
+    ;; switch candidate displaying mode immediately
+    ;; (ex. binding to M-;)
+    (global-set-key "\M-;" 'uim-switch-candidate-display-mode)
+
+
+
+* Change appearances of preedits and candidates
+
+You can change appearances of preedit and candidates in the
+following way.
+
+  ;; text color and background color of preedit
+  (set-face-foreground 'uim-preedit-highlight-face "white")
+  (set-face-background 'uim-preedit-highlight-face "blue")
+
+  ;; separator color
+  (set-face-foreground 'uim-separator-face "white")
+
+  ;; text color and background color of odd number candidates
+  (set-face-foreground 'uim-candidate-odd-face "blue")
+  (set-face-background 'uim-candidate-odd-face "white")
+
+  ;; text color and background color of even number candidates
+  (set-face-foreground 'uim-candidate-odd-face "blue")
+  (set-face-background 'uim-candidate-odd-face "white")
+
+  ;; text color and background color of a selected candidate
+  (set-face-foreground 'uim-candidate-selected-face "blue")
+  (set-face-background 'uim-candidate-selected-face "white")
+
+  ;; text color and background color of page number of candidates
+  (set-face-foreground 'uim-candidate-nth-face "red")
+  (set-face-background 'uim-candidate-nth-face "white")
+
+
+* Display fences / frame (for poor Emacs environment)
+
+You also can use ASCII character as border of preedit and
+candidates.  It's maybe useful when using Emacs-20.x with
+terminal mode.
+
+  ;; display fences both sides of preedit
+  (setq-default uim-preedit-display-fences t)
+
+  ;; display frame of candidates
+  (setq-default uim-candidate-display-frame t)
+
+
+* Change IMs settings
+
+To overwrite default properties of each IM, write as
+follows.  
+
+  ;; set initial mode of anthy and skk to Hiragana mode
+  (setq uim-default-im-prop 
+          '("action_anthy_hiragana" "action_skk_hiragana"))
+
+
+
+* Activate uim.el 
+
+To enable Uim from the beginning in particular major-mode, 
+write as follows.
+
+  ;; enable Uim automatically on html-mode
+  ;;  for minor-mode
+  (add-hook 'html-mode-hook
+             (lambda () (uim-mode 1)))
+
+  ;;  for LEIM
+  (add-hook 'html-mode-hook
+             (lambda () (toggle-input-method)))
+
+
+
+MISC COMMANDS
+=============
+
+If you want to switch IM on minor-mode, just type following
+keys.
+
+  M-x uim-im-switch
+
+  * note: Use set-input-method instead of this if you are
+         using LEIM framework.
+
+
+
+KNOWN PROBLEMS
+==============
+
+See official web page.
+
+
+
+FUTURE WORKS
+============
+
+- Integrate into Uim distribution (?)
+
+
+GET THE LATEST VERSION
+======================
+
+You can get the latest version of uim.el from the following URL.
+
+http://garakuta.homelinux.org/~nosuke/tsubo/uim-el.html
+
+
+
+CONTACT
+=======
+
+Konosuke Watanabe <nosuke at csc.ne.jp>
+

Added: trunk/emacs/README.jp
===================================================================
--- trunk/emacs/README.jp	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/README.jp	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,560 @@
+uim.el - Emacs Uim bridge
+
+Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+All rights reserved.
+
+¤³¤Î¥½¥Õ¥È¥¦¥§¥¢¤ÏBSD¥é¥¤¥»¥ó¥¹¤Ë´ð¤Å¤­ÇÛÉÛ¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥
+
+
+uim.el¤È¤Ï
+==========
+
+uim.el¤Ï¡¤Uim¤ÈEmacs¤Î´Ö¤ò·ë¤Ö¥Ö¥ê¥Ã¥¸¤Ç¤¹¡¥
+
+uim.el¤òƳÆþ¤¹¤ë¤³¤È¤Ç¡¤Emacs¾å¤«¤é¡¤Uim¤Î¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¥¤
+¥ó¥×¥Ã¥È¥á¥½¥Ã¥É¤òľÀÜÍøÍѤǤ­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥
+
+
+ÆÃħ
+====
+
+- ¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨
+
+   Emacs¾å¤ÇÆ°ºî¤¹¤ëÂçÄñ¤ÎIM¤¬¥¨¥³¡¼Îΰè¤ËÊÑ´¹¸õÊä¤òɽ¼¨¤¹¤ë
+   ¤Î¤ËÂФ·¡¤uim.el¤ÏÊÑ´¹¸õÊä¤ò
+
+    - ÆþÎÏ°ÌÃ֤Τ¹¤°²¼¤Ë
+    - ½ÄÊý¸þ¤Ëʤ٤Æ
+
+   ɽ¼¨¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡¥¤³¤ì¤ò¡Ö¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨¡×¤È
+   ¸Æ¤ó¤Ç¤¤¤Þ¤¹¡¥
+
+   ¤³¤Î¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨µ¡Ç½¤Ë¤è¤ê¡¤ÆþÎÏÃ桤ÊÑ´¹¤ò¹Ô¤¦
+   Å٤˻ëÀþ¤ò¥Õ¥ì¡¼¥à¤ÎºÇ²¼Éô¤Þ¤Ç°Ü¤¹É¬Íפ¬¤Ê¤¯¤Ê¤ê¤Þ¤¹¡¥
+
+   ¤Þ¤¿¡¤½ÄÊý¸þ¤ËÊÑ´¹¸õÊä¤òʤ٤뤳¤È¤Ç¡¤ÊÑ´¹¸õÊä¤ÎÇÛÃÖ¤¬Â¾
+   ¤ÎUim¤Î¥Ö¥ê¥Ã¥¸¤ÈƱÍͤˤʤ뤿¤á¡¤²£Êý¸þ¤Ëʤ٤¿¾ì¹ç¤ËÈæ
+   ¤Ù¤Æ°ãÏ´¶Ìµ¤¯Áàºî¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥
+
+
+- ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Î¥Ð¥Ã¥Õ¥¡¤Ø¤ÎÁÞÆþ
+
+   uim.el¤ÏÊÑ´¹Ãæ¤Îʸ»úÎó(¥×¥ê¥¨¥Ç¥£¥Ã¥È)¤ò¡¤¥Ð¥Ã¥Õ¥¡¾å¤Ëľ
+   ÀÜÁÞÆþ¤·¤Æɽ¼¨¤·¤Þ¤¹¡¥
+
+   ¤½¤Î¤¿¤á¡¤uim-xim¤äuim-fepÅù¤ÇEmacs¤ËÆþÎϤ¹¤ë¾ì¹ç¤ËȯÀ¸
+   ¤¹¤ë¡¤Ê¸»úÆþÎÏÃæ¤Ë´û¸¤Îʸ»ú¤¬°ì»þŪ¤Ë¾å½ñ¤­¤µ¤ì¤Æ¸«¤¨¤Ê
+   ¤¯¤Ê¤Ã¤Æ¤·¤Þ¤¦ÌäÂ꤬ȯÀ¸¤·¤Þ¤»¤ó¡¥
+
+
+- ¥Ð¥Ã¥Õ¥¡¤´¤È¤ËÆÈΩ¤·¤¿IM¤Î´ÉÍý
+
+   uim.el¤Ï¡¤ÆþÎÏ¥¨¥ó¥¸¥óÅù¤Ë´Ø¤¹¤ë¾ðÊó¤ò¥Ð¥Ã¥Õ¥¡Ëè¤Ë´°Á´¤Ë
+   ÆÈΩ¤·¤Æ´ÉÍý¤·¤Þ¤¹¡¥
+
+   ¤½¤Î¤¿¤á¡¤¥Ð¥Ã¥Õ¥¡Ëè¤Ë°Û¤Ê¤ëÊÑ´¹¥¨¥ó¥¸¥ó(Anthy¡¤SKK¡¤
+   CannaÅù)¤òÍøÍѤ·¤¿¤ê¡¤Ê£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤ÇʹԤ·¤ÆÊÑ´¹½èÍý¤ò
+   ¿Ê¤á¤¿¤ê¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡¥
+
+
+
+Æ°¤«¤¹¤Î¤ËɬÍפʤâ¤Î
+====================
+
+- GNU Emacs ¤â¤·¤¯¤Ï XEmacs
+
+ - GNU Emacs¤Ï¡¤20.7.1¡¤21.3.1¡¤22.0.50(CVSÈÇ) ¤ÇÆ°ºî³Îǧ
+
+ - XEmacs ¤Ï 21.4.17 (sumo + mule-sumo) ¤ÇÆ°ºî³Îǧ
+
+ ¢¨ Mule-2.3 ¤Ç¤ÏÆ°ºî¤·¤Þ¤»¤ó
+    ¤ª¤½¤é¤¯ GNU Emacs-21.x ¤¬ºÇ¤â°ÂÄꤷ¤ÆÆ°ºî¤¹¤ë¤È»×¤¤¤Þ¤¹
+
+- Uim
+
+ - ¤ª¤½¤é¤¯ 0.4.6 °Ê¾å (ºÇ¿·Èǿ侩)
+
+
+- Anthy Åù¤Î¡¤Uim¤«¤éÍøÍѲÄǽ¤Ê³Æ¼ï¥¤¥ó¥×¥Ã¥È¥á¥½¥Ã¥É
+
+
+
+¥¤¥ó¥¹¥È¡¼¥ë¼ê½ç
+================
+
+uim.el¤Ï¡¤Emacs LISP¤Ç½ñ¤«¤ì¤¿¥Õ¥í¥ó¥È¥¨¥ó¥É¤È¡¤Uim¤Î¥é¥¤¥Ö
+¥é¥ê¤È¥ê¥ó¥¯¤·¤ÆÊÑ´¹½èÍýÅù¤ò¹Ô¤¦¥Í¥¤¥Æ¥£¥Ö¥Ð¥¤¥Ê¥ê¤Î¥Ð¥Ã¥¯¥¨
+¥ó¥É(uim-el-agent)¤È¤Ç¹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥
+
+¤½¤Î¤¿¤á¡¤uim.el¤ò¥½¡¼¥¹¤«¤é¥¤¥ó¥¹¥È¡¼¥ë¤Ë¤Ï¡¤C¤Î¥½¡¼¥¹¤ò¥³
+¥ó¥Ñ¥¤¥ë¤Ç¤­¤ë´Ä¶­¤¬É¬Íפˤʤê¤Þ¤¹¡¥
+
+Ä̾ï¤Ï¡¤°Ê²¼¤Î¼ê½ç¤Ç¥¤¥ó¥¹¥È¡¼¥ë²Äǽ¤Ç¤¹¡¥
+
+ % ./configure
+ % make
+ % su
+ # make install
+
+
+¢¨ ¥Õ¥¡¥¤¥ë¹½À®¤Ë¼ã´³Êѹ¹¤¬¤¢¤ê¤Þ¤·¤¿¤Î¤Ç¡¤°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó
+   ¤«¤é¥¢¥Ã¥×¥Ç¡¼¥È¤¹¤ë¤Ë¤Ï¡¤¾å½ñ¤­¥¤¥ó¥¹¥È¡¼¥ë¤»¤º¤Ë¡¤°ìö
+   ¸Å¤¤¤â¤Î¤òºï½ü¤·¤Æ¤«¤é¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤¯¤À¤µ¤¤
+
+
+
+»È¤¤Êý
+======
+
+
+uim.el¤Ï¡¤Ä¾ÀÜ¥Þ¥¤¥Ê¡¼¥â¡¼¥É¤òµ¯Æ°¤·¤ÆÍøÍѤ¹¤ëÊýË¡¤È¡¤LEIM¤Î
+ºîË¡¤Ë¤·¤¿¤¬¤Ã¤Æµ¯Æ°¤¹¤ëÊýË¡¤Î2¼ïÎब¤¢¤ê¤Þ¤¹¡¥
+
+¤É¤Á¤é¤òÁª¤ó¤Ç¤â¡¤´ðËÜŪ¤ÊÉôʬ¤ÏÊѤï¤ê¤¢¤ê¤Þ¤»¤ó¡¥
+
+¢¨ °ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤ÈÈæ¤Ù¡¤ÀßÄêÊýË¡¤¬¼ã´³Êѹ¹¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥
+   ¸æÃí°Õ²¼¤µ¤¤¡¥
+
+
+[¥Þ¥¤¥Ê¡¼¥â¡¼¥É¤ÇľÀÜuim.el¤òÍøÍѤ¹¤ë¾ì¹ç¤Î´ðËÜÀßÄê]
+
+.emacs¤Ë°Ê²¼¤Îµ­½Ò¤ò²Ã¤¨¤Æ¤¯¤À¤µ¤¤
+
+  ;; uim.el¤òÆɤ߹þ¤à
+  (require 'uim)
+  ;; Emacsµ¯Æ°»þ¤ËÆɤ߹þ¤ó¤Ç¤Û¤·¤¯¤Ê¤¤¾ì¹ç¤ÏÂå¤ï¤ê¤Ë²¼µ­¤òµ­ºÜ
+  ;; (autoload 'uim-mode "uim" nil t)
+
+  ;; ¥Ç¥Õ¥©¥ë¥È¤ÎIM¤Î»ØÄê (°Ê²¼¤ÏAnthy¤ÎÎã)
+  ;;   »ØÄꤷ¤Ê¤¤¾ì¹ç¤ÏUim¤Î¥Ç¥Õ¥©¥ë¥È¤ÈƱ¤¸¤Ë¤Ê¤ê¤Þ¤¹
+  ;; (setq uim-default-im-engine "anthy")
+
+  ;; Uim¤òµ¯Æ°¤¹¤ë¤¿¤á¤Î¥­¡¼¤ÎÀßÄê(C-o¤ò»È¤¦¾ì¹ç¤ÎÎã)
+  (global-set-key "\C-o" 'uim-mode)
+
+
+[LEIM¤ÎºîË¡¤Ë¤·¤¿¤¬¤Ã¤Æuim.el¤òÍøÍѤ¹¤ë¾ì¹ç¤Î´ðËÜÀßÄê]
+
+.emacs¤Ë°Ê²¼¤Îµ­½Ò¤ò²Ã¤¨¤Æ¤¯¤À¤µ¤¤
+
+  ;; LEIM¤Î¥»¥Ã¥È¥¢¥Ã¥×¤ò¤·¤Ä¤Äuim.el¤òÆɤ߹þ¤à
+  (require 'uim-leim)
+
+  ;; ¥Ç¥Õ¥©¥ë¥È¤ÎIM¤ÎÀßÄê (°Ê²¼¤ÏAnthy¤ÎÎã)
+  ;;   »ØÄꤷ¤Ê¤¤¾ì¹ç¡¤LEIM¤Î¥Ç¥Õ¥©¥ë¥È¤ÎIM¤¬µ¯Æ°¤·¤Þ¤¹
+  (setq default-input-method "japanese-anthy-uim")
+
+
+  ¢¨LEIM¤Ç¤Î IM ̾¤Ï
+
+     <EmacsŪ¸À¸ì̾>-<Uim¤ÎÊÖ¤·¤Æ¤¯¤ëIM̾>-uim
+
+   ¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥UimŪ¸À¸ì̾¤ÈEmacsŪ¸À¸ì̾¤ÎÂбþ¤Ë¤Ä¤¤¤Æ¤Ï
+   uim-el/uim-var.el¤Î uim-lang-code ¤Ç³Îǧ¤Ç¤­¤Þ¤¹¡¥
+
+    ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ëIM°ìÍ÷¤Ï¡¤°Ê²¼¤Î¥³¥Þ¥ó¥É¤Ç¸«¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹
+
+     M-x set-input-method RET TAB
+
+
+
+[¥Ñ¥¹¤Ë´Ø¤¹¤ëÀßÄê]
+
+´ÉÍý¼Ô¸¢¸Â¤¬Ìµ¤¤¾ì¹ç¤ä¡¤uim.el¤ò¾¤Î¥×¥í¥°¥é¥à¤È¤ÏÊ̤ξì½ê¤Ë
+¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¤¤¾ì¹çÅù¤Ï¡¤°Ê²¼¤Î¤è¤¦¤Ë¤·¤Æ¥Ñ¥¹¤òÄ̤¹É¬Íפ¬
+¤¢¤ê¤Þ¤¹¡¥É¬Íפ˱þ¤¸¤Æuim.el¤òÆɤ߹þ¤àÉôʬ¤è¤ê¤â Á° ¤Ëµ­½Ò¤·
+¤Æ¤¯¤À¤µ¤¤
+
+  ;; uim.el¤Îlisp¥Õ¥¡¥¤¥ë¤ò¡¤Emasc¤¬¥Ç¥Õ¥©¥ë¥È¤Ç¥Ñ¥¹¤òÄ̤·¤Æ
+  ;; ¤¯¤ì¤Ê¤¤¤È¤³¤í¤ËÀßÃÖ¤·¤¿¾ì¹ç¡¤¥Ñ¥¹¤òÄ̤¹
+  (setq load-path (append '("/home/nosuke/uim-el/uim-el") load-path))
+
+  ;; uim-el-agent¤¬¡¤Emacs¾å¤Ç¥Ñ¥¹¤ÎÄ̤äƤ¤¤Ê¤¤¾ì½ê¤Ë¤¢¤ë¾ì¹ç
+  ;; ľÀܾì½ê¤ò»ØÄê
+  (setq uim-el-agent "/home/nosuke/uim-el/uim-el-agent/uim-el-agent")
+
+
+
+
+[¥«¥¹¥¿¥Þ¥¤¥ºÍѤÎÀßÄê]
+
+* ¥¿¡¼¥ß¥Ê¥ë¥â¡¼¥É¤Ç¤ÎEscape¥­¡¼¤ÎµóÆ°¤òÊѹ¹¤¹¤ë
+
+Emacs¤ò -nw ¥ª¥×¥·¥ç¥ó¤ò¤Ä¤±¤Æ¥¿¡¼¥ß¥Ê¥ë¾å¤Çµ¯Æ°¤·¤¿¾ì¹ç¡¤
+uim.el¤Ï F10¤äDeleteÅù¤Î¥Õ¥¡¥ó¥¯¥·¥ç¥ó¥­¡¼¤òǧ¼±¤¹¤ë¤¿¤á¤Ë¡¤
+¥Ç¥Õ¥©¥ë¥È¤Ç¤ÏñÆȤDz¡²¼¤µ¤ì¤¿ Escape¤òUim¦¤ËÅϤµ¤Ê¤¤¤è¤¦¤Ë
+¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥
+
+Uim¦¤ÇñÆȤÎEscape¤Ë¥Ð¥¤¥ó¥É¤µ¤ì¤¿½èÍý¤ò¸Æ¤Ó½Ð¤¹¤Ë¤Ï¡¤
+Escape¤ò2²ó³¤±¤ÆÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡¥
+
+
+¤Ê¤ª¡¤.emacs¤Ë°Ê²¼¤Î¤è¤¦¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¤¥×¥ê¥¨¥Ç¥£¥Ã¥Èɽ¼¨
+»þ¤Î¤ß¡¤Ã±ÆȤÎEscape¤òÍ­¸ú¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥
+
+  ;; ñÆȤÎEsc¤Î²¡²¼¤ò¥¿¡¼¥ß¥Ê¥ë¾å¤ÇÍ­¸ú¤Ë¤¹¤ë
+  (setq uim-use-single-escape-on-terminal t)
+
+¤¿¤À¤·¡¤¤³¤ÎÀßÄê¤ò¤·¤¿¾ì¹ç¡¤¥¿¡¼¥ß¥Ê¥ë¾å¤Ç¤ÏFn¥­¡¼¤äDelete¥­¡¼
+¤Î¾¡¤Alt¥­¡¼¤òÁȤ߹ç¤ï¤»¤¿¥­¡¼¥Ð¥¤¥ó¥ÉÅù¤âÀµ¤·¤¯Æ°ºî¤·¤Ê¤¯
+¤Ê¤ê¤Þ¤¹¤Î¤Ç¡¤¤ªÁ¦¤á¤·¤Þ¤»¤ó¡¥
+
+
+* ¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨¤ò¥Ç¥Õ¥©¥ë¥È¤ÇÍ­¸ú¤Ë¤¹¤ë
+  
+¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨¤ÏEmacs¤Ç»ÈÍѤ·¤Æ¤¤¤ë¥Õ¥©¥ó¥È¤¬¥×¥í¥Ý¡¼
+¥·¥ç¥Ê¥ë¥Õ¥©¥ó¥È¤Ç̵¤¤¾ì¹çÅù¤ËÀµ¾ï¤ËÆ°ºî¤·¤Ê¤¤¤¿¤á¡¤¥Ç¥Õ¥©¥ë
+¥È¤Ç¤Ï̵¸ú²½¤·¤Æ¤¢¤ê¤Þ¤¹¡¥
+
+ÊÑ´¹¸õÊä¤Î¥¤¥ó¥é¥¤¥óɽ¼¨¤Ë´Ø¤¹¤ë¥Ç¥Õ¥©¥ë¥È¤Î¿¶Éñ¤òÊѹ¹¤·¤¿¤¤
+¾ì¹ç¤Ï¡¤°Ê²¼¤ò .emacs ¤Ëµ­½Ò¤·¤Æ¤¯¤À¤µ¤¤¡¥
+
+  ;; ÊÑ´¹¸õÊä¤ò¥Ç¥Õ¥©¥ë¥È¤Ç¥¤¥ó¥é¥¤¥óɽ¼¨¤Ë¤¹¤ë
+  (setq uim-candidate-display-inline t)
+
+
+ÊÑ´¹¸õÊä¤Î¥¤¥ó¥é¥¤¥óɽ¼¨¤Î¥ª¥ó¥ª¥Õ¤ò¥­¡¼¥Ü¡¼¥É¤«¤éÀÚÂؤ¨¤¿¤¤
+¾ì¹ç¤Ï¡¤°Ê²¼¤ò .emacs ¤Ëµ­½Ò¤·¤Æ¤¯¤À¤µ¤¤¡¥
+
+  ;; Æ°ºîÃæ¤ËÊÑ´¹¸õÊä¤Îɽ¼¨Êý¼°¤òÀÚÂؤ¨¤ë
+  ;; (M-;¤ò»È¤¦¾ì¹ç¤ÎÎã)
+  (global-set-key "\M-;" 'uim-switch-candidate-display-mode)
+
+
+
+* ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤äÊÑ´¹¸õÊä¤Î¿§¤òÊѹ¹¤¹¤ë
+
+ÊÑ´¹¸õÊäÅù¤Î¿§¤¬µ¤¤ËÆþ¤é¤Ê¤¤¾ì¹ç¤Ï¡¤°Ê²¼¤Î¤è¤¦¤Ëµ­½Ò¤¹¤ë¤³¤È
+¤ÇÊѹ¹²Äǽ¤Ç¤¹¡¥
+
+ÍøÍѲÄǽ¤Ê¿§¤Ï M-x list-colors-display ¤Ç³Îǧ¤Ç¤­¤Þ¤¹¡¥
+
+  ;; ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Îʸ»ú¿§¡¦ÇØ·Ê¿§
+  (set-face-foreground 'uim-preedit-highlight-face "white")
+  (set-face-background 'uim-preedit-highlight-face "blue")
+
+  ;; ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Î¥»¥Ñ¥ì¡¼¥¿¤Îʸ»ú¿§
+  (set-face-foreground 'uim-separator-face "white")
+
+  ;; ÊÑ´¹¸õÊä¤Î´ñ¿ôÈÖÌܤÎʸ»ú¿§¡¦ÇØ·Ê¿§
+  (set-face-foreground 'uim-candidate-odd-face "blue")
+  (set-face-background 'uim-candidate-odd-face "white")
+
+  ;; ÊÑ´¹¸õÊä¤Î¶ö¿ôÈÖÌܤÎʸ»ú¿§¡¦ÇØ·Ê¿§
+  (set-face-foreground 'uim-candidate-even-face "blue")
+  (set-face-background 'uim-candidate-even-face "yellow")
+
+  ;; ÊÑ´¹¸õÊä¤ÎÁªÂòÃæ¤ÎÉôʬ¤Îʸ»ú¿§¡¦ÇØ·Ê¿§
+  (set-face-foreground 'uim-candidate-selected-face "blue")
+  (set-face-background 'uim-candidate-selected-face "white")
+
+  ;; ÊÑ´¹¸õÊä¤Î¸½ºß¤Î¥Ú¡¼¥¸ÈÖ¹æ¤Îɽ¼¨Ê¬¤Îʸ»ú¿§¡¦ÇØ·Ê¿§
+  (set-face-foreground 'uim-candidate-nth-face "red")
+  (set-face-background 'uim-candidate-nth-face "white")
+
+
+
+* ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤äÊÑ´¹¸õÊä¤ËÏȤòÉÕ¤±¤ë (Éϼå¤ÊEmacs¸þ¤±)
+
+Emacs¤¬ÂÀÀþ¤ä²¼Àþ¤Îɽ¼¨¤ËÂбþ¤·¤Æ¤¤¤Ê¤¤¾ì¹ç(Emacs-20.x¤ò-nw 
+¥ª¥×¥·¥ç¥ó¤ò¤Ä¤±¤Æ¥¿¡¼¥ß¥Ê¥ë¤Çµ¯Æ°¤·¤¿¾ì¹çÅù)¤Ë¡¤¥×¥ê¥¨¥Ç¥£¥Ã
+¥È¤äÊÑ´¹¸õÊä¤Î¶­³¦¤ò¥Æ¥­¥¹¥È¤ÇÉÁ²è¤¹¤ë¤Ë¤Ï°Ê²¼¤òÀßÄꤷ¤Þ¤¹¡¥
+
+  ;; ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤ÎξÏƤˡÖ|¡×¤òɽ¼¨¤¹¤ë
+  (setq-default uim-preedit-display-fences t)
+
+  ;; ÊÑ´¹¸õÊä¤Îº¸±¦¤È²¼¤ò¡Ö|¡×¤ä¡Ö-¡×¤Ç°Ï¤¦
+  (setq-default uim-candidate-display-frame t)
+
+
+
+* ³ÆIM¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÀßÄê¤ò»ØÄꤹ¤ë
+
+³ÆIM¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÀßÄê¤ò¡¤UimÁ´ÂÎÀßÄê¤È¤Ï°Û¤Ê¤ëÆâÍƤËÊѹ¹¤·
+¤¿¤¤¾ì¹ç¤Ï¡¤ÀßÄê¤òÎóµó¤·¤¿¥ê¥¹¥È¤òµ­½Ò¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡¥
+
+  ;; Anthy¤Èskk¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÆþÎϥ⡼¥É¤ò¤Ò¤é¤¬¤Ê¤Ë¤¹¤ë
+  (setq uim-default-im-prop 
+          '("action_anthy_hiragana" "action_skk_hiragana"))
+
+
+
+* ¥Ç¥Õ¥©¥ë¥È¤ÇUim¤¬µ¯Æ°¤·¤Æ¤¤¤ë¤è¤¦¤Ë¤¹¤ë
+
+ÆÃÄê¤Î¥á¥¸¥ã¡¼¥â¡¼¥É¤ÇºÇ½é¤«¤éUim¤¬µ¯Æ°¤¹¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç
+¤Ï¡¤°Ê²¼¤Î¤è¤¦¤Ë.emacs ¤Ê¤É¤Ë½ñ¤¤¤Æ¤ª¤­¤Þ¤¹¡¥
+
+  ;; html-mode¤ÇºÇ½é¤«¤éUim¤òµ¯Æ°¤·¤Æ¤ª¤­¤¿¤¤¾ì¹ç
+  ;; (html-mode¤Îµ¯Æ°¤Ë¤¢¤ï¤»¤ÆUim¤òµ¯Æ°¤¹¤ë¾ì¹ç¤ÎÎã)
+  (add-hook 'html-mode-hook
+             (lambda ()
+              (uim-mode 1)
+               ))
+
+ ¢¨ LEIM¤Ç»ÈÍѤ¹¤ë¾ì¹ç¤Ï¡¤¡Ö(uim-mode 1)¡×¤ÎÂå¤ï¤ê¤Ë
+  ¡Ö(toggle-input-method)¡×Åù¤È½ñ¤±¤Ð¤¦¤Þ¤¯¤¤¤¯¤«¤â¤·¤ì¤Þ¤»¤ó
+
+
+¤¿¤¯¤µ¤ó¤¢¤ë¾ì¹ç¤Ï¡¤°Ê²¼¤Î¤è¤¦¤Ë¤Þ¤È¤á¤Æ½ñ¤¤¤Æ¤·¤Þ¤¤¤Þ¤·¤ç¤¦
+
+  (mapcar (lambda (x)
+    (add-hook x (lambda () (uim-mode 1))))
+     '(mew-draft-mode-hook
+       html-mode-hook
+       lisp-interaction-mode-hook
+       php-mode-hook
+       text-mode-hook))
+
+
+¤Þ¤¿¡¤Æ±Íͤˡ¤ÆÃÄê¤Î¥â¡¼¥É¤Ç¤ÎÊÑ´¹¸õÊä¤Î¥Ç¥Õ¥©¥ë¥È¤Îɽ¼¨Êý¼°
+¤òÀßÄꤹ¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡¥
+
+  ;; navi2ch¤Ç½ñ¤­¹þ¤ß»þ¤Ë¡¤¥Ç¥Õ¥©¥ë¥È¤Ç Uim ¤¬µ¯Æ°¤¹¤ë¤è¤¦¤Ë¤·¡¤
+  ;; ÊÑ´¹¸õÊä¤Ï¥¤¥ó¥é¥¤¥óɽ¼¨¤µ¤»¤Ê¤¤¤è¤¦¤Ë¤¹¤ëÎã
+  (add-hook 'navi2ch-message-mode-hook 
+            (lambda () (uim-mode 1)
+              (setq uim-candidate-display-inline-buffer nil)
+              ))
+
+
+
+[¤½¤Î¾ÆÃÊ̤ÊÁàºî]
+
+¥Þ¥¤¥Ê¡¼¥â¡¼¥É¤ÇIM¤òÀÚÂؤ¨¤¿¤¤¾ì¹ç¤Ï
+
+  M-x uim-im-switch
+
+¤Ç uim.el ¤ÇÍøÍѲÄǽ¤ÊIM°ìÍ÷¤«¤éÁªÂò¤¹¤ë¤È¤¬¤Ç¤­¤Þ¤¹¡¥
+
+
+¢¨ LEIM¤ÇUim¤òÍøÍѤ·¤Æ¤¤¤ë¾ì¹ç¤Ï¡¤IM¤ÎÀÚÂؤ¨¤Ë¤ÏLEIM¤ÎÊý¼°¤Ë
+  ½¾¤¤ set-input-method ¥³¥Þ¥ó¥É¤òÍøÍѤ·¤Æ¤¯¤À¤µ¤¤¡¥
+
+
+
+ºÇ¿·ÈǤÎÊѹ¹ÅÀ
+==============
+
+[¥æ¡¼¥¶¤Ë´Ø·¸¤Î¿¼¤¤ÅÀ]
+
+0.0.6b1 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- ÊÑ´¹¸õÊä¤Îɽ¼¨¥ì¥¤¥¢¥¦¥È¤ò¼ã´³Êѹ¹
+
+
+0.0.5.3 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- ¥¿¡¼¥ß¥Ê¥ë¾å¤Ç¤â Ctrl-~¡¤Ctrl-]¡¤Ctrl-\ ¤òUim¦¤ËÅϤ»¤ë¤è
+  ¤¦¤Ë½¤Àµ
+
+- viper-mode¤ädiff-mode¤Ç¤â¤­¤Á¤ó¤ÈÆ°¤¯¤è¤¦¤Ë¡¤¥×¥ê¥¨¥Ç¥£¥Ã
+  ¥Èɽ¼¨Ãæ¤Ï¡¤Â¾¤Î¥â¡¼¥É¤Î¥­¡¼¥Ð¥¤¥ó¥É¤òÁ´¤Æ̵¸ú²½¤¹¤ë¤è¤¦¤Ë
+  Êѹ¹
+
+- ¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨»þ¤Ë¡¤ÅÓÃæ¤Ë¥¿¥Ö¤¬¤¢¤ë¾ì¹ç¤Ë¸õÊäɽ¼¨
+  °ÌÃÖ¤¬¥×¥ê¥¨¥Ç¥£¥Ã¥È¤«¤é¤º¤ì¤Æ¤·¤Þ¤¦ÌäÂê¤ò½¤Àµ
+
+- XEmacs¤Ç¥×¥ê¥¨¥Ç¥£¥Ã¥Èɽ¼¨»þ¤Ë¥Ð¥Ã¥Õ¥¡´Ö¤ò°ÜÆ°¤Ç¤­¤Ê¤¤¥Ð¥°
+  ¤ò½¤Àµ
+
+
+0.0.5.2 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- Undo¥ê¥¹¥È¤¬¶õ¤Î¾õÂÖ¤ÇUim¤òÄ̤·¤ÆÆþÎϤ¹¤ë¤È¡¤¤½¤Î¸åUndo¤¬
+  ¤Ç¤­¤Ê¤¯¤Ê¤ë¥Ð¥°¤ò½¤Àµ
+
+- ÊÑ´¹¸õÊä¤Î¥é¥Ù¥ë¤Îɽ¼¨¤Î»ÅÊý¤ò¡¤Â¾¤ÎIM¤ÈƱ¤¸¤Ë¤Ê¤ë¤è¤¦¤ËÊѹ¹
+
+- C-xÅù¤Ç»Ï¤Þ¤ë¥­¡¼¥Ð¥¤¥ó¥É¤¬¥×¥ê¥¨¥Ç¥£¥Ã¥Èɽ¼¨Ãæ¤Ë¤â»È¤¨¤Æ
+  ¤·¤Þ¤¦¥Ð¥°¤ò½¤Àµ
+
+- C-SPC C-SPC Åù¤ÎEmacs-22¤ÎÆüì¤Ê¥­¡¼Áàºî¤ËÂбþ
+
+- GNU Emacs¤Î transient-mark-mode ¤ËÂбþ
+
+- ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤¬Ìµ¤¤¾õÂÖ¤Çshift+space¤äshift+backspace¤¬²¡¤µ¤ì¤¿
+  ºÝ¤Î½èÍý¤ò¡¤uim.el¤òÍøÍѤ·¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÈƱÍͤˤʤë¤è¤¦¤ËÊѹ¹
+
+- ¥×¥ê¥¨¥Ç¥£¥Ã¥ÈÆâ¤Ç¥«¡¼¥½¥ë¤ò°ÜÆ°¤µ¤»¤Æ¡¤¥«¡¼¥½¥ë¤¬¥×¥ê¥¨
+  ¥Ç¥£¥Ã¥È¤ÎÀèƬ¤ËÍ褿ºÝ¤Ë¡¤¥«¡¼¥½¥ë°ÌÃÖ¤¬¥×¥ê¥¨¥Ç¥£¥Ã¥È¤ÎËö
+  Èø¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤Ã¤Æ¤¤¤¿¥Ð¥°¤ò½¤Àµ
+
+- C-9 (digit-argument) ¤È¤« M-- (negative-argument) ¤È¤«¤ËÂбþ
+
+- XEmacs¤ÇC-[¤òuim.el¤¬²£¼è¤ê¤Ç¤­¤Æ¤¤¤Ê¤«¤Ã¤¿¤Î¤ò½¤Àµ
+
+- Emacs¦¤ËÊ£¿ô¤Î¥Ð¥Ã¥Õ¥¡¤¬¤¢¤ê¡¤¤¢¤ë¥Ð¥Ã¥Õ¥¡¤Ç¥×¥ê¥¨¥Ç¥£¥Ã
+  ¥È¤òɽ¼¨¤·¤¿¾õÂ֤ǡ¤Emacs°Ê³°¤Î¥¦¥£¥ó¥É¥¦¤ò¥Þ¥¦¥¹¥¯¥ê¥Ã¥¯
+  ¤·¤Æ¥Õ¥©¡¼¥«¥¹¤ò°Ü¤·¡¤¤½¤Î¸å¡¤Emacs¾å¤Î¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Î̵
+  ¤¤¥Ð¥Ã¥Õ¥¡¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¥Õ¥©¡¼¥«¥¹¤òÌᤷ¤¿ºÝ¤Ë¡¤Àè¤Î¥Ð¥Ã¥Õ¥¡
+  ¤Ç¤Î¥×¥ê¥¨¥Ç¥£¥Ã¥È¤¬¾Ã¤¨¤Æ¤·¤Þ¤¦¥Ð¥°¤ò½¤Àµ
+
+
+0.0.5.1 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- pyÅù¤Î¡¤¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Ë¥«¡¼¥½¥ë¾ðÊ󤬴ޤޤì¤Ê¤¤¤³¤È¤¬¤¢¤ë
+  IM¤Ç¡¤¥×¥ê¥¨¥Ç¥£¥Ã¥ÈÁÞÆþ¸å¤Ë¥¨¥é¡¼¤¬½Ð¤ë¥Ð¥°¤ò½¤Àµ
+
+- buffer-undo-list¤¬ 't ¤Î¤È¤­¤Ë°ìʸ»úÆþÎϤ¹¤ëÅ٤˥¨¥é¡¼¤¬½Ð
+  ¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤¿¥Ð¥°¤ò½¤Àµ
+
+- ¥¿¡¼¥ß¥Ê¥ë¥â¡¼¥É¤Çµ¯Æ°¤·¤¿ºÝ¤Ë¡¤¥×¥ê¥¨¥Ç¥£¥Ã¥ÈÆþÎÏÃæ¤ËÌð°õ
+  ¤È¤«F9¤È¤«¸ú¤«¤Ê¤¯¤Ê¤Ã¤Æ¤¤¤¿¥Ð¥°¤ò½¤Àµ
+  (¤¢¤¤¤«¤ï¤é¤º¥­¡¼²ó¤ê¤Ïº®Æ٤Ȥ·¤¹¤®¡¦¡¦¡¦ orz)
+
+0.0.5 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- Emacs-22·Ï¤Ç¥â¡¼¥É¥é¥¤¥ó¤Îɽµ­¤¬Áý¿£¤·¤Æ¤·¤Þ¤¦¥Ð¥°¤ò²ò¾Ã
+
+- Backspace¥­¡¼¤òC-h¤Ë³ä¤êÅö¤Æ¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¡¤Emacs¤Ç¥Ð¥Ã¥¯
+  ¥¹¥Ú¡¼¥¹¤¬¸ú¤«¤Ê¤¯¤Ê¤ë¥Ð¥°¤ò²ò¾Ã
+
+- ¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨»þ¤Ë¥¦¥£¥ó¥É¥¦¤ÎÉý¤è¤êŤ¤ÊÑ´¹¸õÊ䤬
+  ɽ¼¨¤µ¤ì¤Ê¤¤¥Ð¥°¤ò²ò¾Ã
+
+- ¥¿¡¼¥ß¥Ê¥ë¤ÇÆ°¤«¤·¤¿¤È¤­¤ä¡¤Emacs20¤ÇÆ°¤«¤·¤¿¤È¤­¤Ê¤É¤Ë¡¤
+  Ť¤¹Ô¤¬¥¦¥£¥ó¥É¥¦±¦Ã¼¤ÇÀÞ¤êÊÖ¤·¤Æ¤¤¤ë¤È¤³¤í¤ËÊÑ´¹¸õÊä¤ò½Å
+  ¤Í¤Æ½Ð¤¹¤È¸õÊä¤Î°ìÉô¤¬·ç¤±¤ë¥Ð¥°¤ò²ò¾Ã
+
+- skkÅù¤ÇƱ»þ¤ËÊ£¿ô¤Î¥³¥ß¥Ã¥È¤¬È¯À¸¤·¤¿ºÝ¤Ë¡¤ºÇ¸å¤ËȯÀ¸¤·¤¿
+  ¥³¥ß¥Ã¥È¤·¤«½èÍý¤µ¤ì¤Ê¤¤¥Ð¥°¤ò²ò¾Ã
+
+- ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤¬É½¼¨¤µ¤ì¤Æ¤¤¤ë´Ö¤Î¥á¥Ë¥å¡¼¤ä¥Ä¡¼¥ë¥Ð¡¼¤Î¥Ü
+  ¥¿¥ó¤ËÂФ¹¤ëÁàºî¤ò̵¸ú²½
+
+- ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤¬É½¼¨¤µ¤ì¤Æ¤¤¤ë´Ö¡¤¥Ð¥Ã¥Õ¥¡¤ò¥ê¡¼¥É¥ª¥ó¥ê¡¼
+  ¤Ë¤¹¤ë¤³¤È¤ÇÉÔÀµ¤ÊÊѹ¹¤òËÉ»ß
+
+- ¥¿¡¼¥ß¥Ê¥ëµ¯Æ°»þ¤ÎEscape¤Î°·¤¤¤ÈÀßÄêÊýË¡¤òÊѹ¹(¥Ç¥Õ¥©¥ë¥È
+  ¤Ç¤ÏñÆÈEscape¤Ï̵¸ú¤Ë)
+
+- ¥¿¡¼¥ß¥Ê¥ëµ¯Æ°»þ¤Ë¡¤F11¤äDeleteÅù¤Î¥­¡¼¤¬Ç§¼±¤Ç¤­¤Ê¤¤ÌäÂê
+  ¤ËÂбþ
+
+- ¥Ð¥Ã¥Õ¥¡¤¬¥ê¡¼¥É¥ª¥ó¥ê¡¼¤À¤Ã¤¿¤ê¾¤Î¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æ¥í¥Ã¥¯
+  ¤µ¤ì¤Æ¤¤¤¿¤ê¤·¤¿¾ì¹ç¤Ë¡¤uim.el¤ò¾¡¼ê¤Ë̵¸ú²½¤·¤Ê¤¤¤è¤¦¤ËÊѹ¹
+
+- C-u x ¤Î¤è¤¦¤ÊÆþÎϤËÂбþ
+
+- Í­¸ú/̵¸ú¤Î¤¿¤á¤Î´Ø¿ô¤ò uim-mode-switch ¤«¤é uim-mode¤ËÊÑ
+  ¹¹ (by °æ¾å¤µ¤ó)
+
+- ¥¦¥£¥ó¥É¥¦Æâ¤Î°ÌÃ֤ˤè¤Ã¤Æ¤Ï¡¤ÊÑ´¹¸õÊ䤬¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Î¾å
+  ¤Ëɽ¼¨¤µ¤ì¤ë¤è¤¦¤ËÊѹ¹
+
+- XEmacs¤äEmacs20¤Ç¤Î¡¤¥¨¥³¡¼Îΰè¤Ø¤ÎÊÑ´¹¸õÊä¤Îɽ¼¨ÊýË¡¤Î²þÁ±
+
+- ¥¤¥ó¥é¥¤¥óɽ¼¨¤·¤¿ÊÑ´¹¸õÊ䤬¥¦¥£¥ó¥É¥¦¤«¤é¤Ï¤ß¤À¤¹¾ì¹ç¡¤¼«
+  Æ°¤Ç¥¹¥¯¥í¡¼¥ë¤¹¤ë¤è¤¦¤ËÊѹ¹
+
+- ÊÑ´¹¸õÊä¤ò¤Ê¤ë¤Ù¤¯¥×¥ê¥¨¥Ç¥£¥Ã¥È¤Îľ²¼¤Ë½Ð¤ë¤è¤¦¤ËÊѹ¹
+
+- prime¤Ç¤ÎÊÑ´¹¸õÊä¤Îɽ¼¨°ÌÃÖ¤ò²þÁ±
+
+- ¥Ð¥Ã¥Õ¥¡´û¸¤Î¥ª¡¼¥Ð¥ì¥¤¤ËÊÑ´¹¸õÊ䤬½Å¤Ê¤ê¤½¤¦¤Ë¤Ê¤Ã¤¿¤é¡¤
+  ¥¤¥ó¥é¥¤¥óÊÑ´¹¸õÊäɽ¼¨¥â¡¼¥É¤Ç¤â¶¯À©Åª¤Ë¥¨¥³¡¼Îΰè¤ËÊÑ´¹¸õ
+  Êä¤òɽ¼¨¤¹¤ë¤è¤¦¤ËÊѹ¹
+
+- ¤½¤Î¾ºÙ¤«¤¤ÌäÂê¤Î½¤ÀµÂ¿¿ô
+
+
+[ÆâÉôŪ¤ÊÅÀ]
+
+0.0.6b1 ¤Ç¤ÎÊѹ¹
+
+- uim-agent¤òuim-el-agent¤Ë̾¾ÎÊѹ¹
+
+0.0.5.1 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- Uim¤¬ÊÖ¤·¤Æ¤­¤¿¡Ö\¡×¤ò¥¨¥¹¥±¡¼¥×¤·¤Ê¤¤¤è¤¦¤ËÊѹ¹ 
+  (pinyin-big5¤ÏSJIS¤ß¤¿¤¤¤Ê´¶¤¸¡©)
+  (¸µ¡¹¥¨¥¹¥±¡¼¥×¤·¤Æ¤¯¤ì¤Æ¤¿¤Î¤Íorz)
+
+
+0.0.5 ¤Ç¤ÎÊѹ¹ÅÀ
+
+- ¥­¡¼¥Þ¥Ã¥×¤òÂçÉý¤Ë½Ì¾®²½
+
+- uim¤¬Ìµ»ë¤·¤¿¥­¡¼¤Î½èÍý¤ËÂбþ
+
+- ¥Þ¥¦¥¹¥¤¥Ù¥ó¥È¤Î¥Ï¥ó¥É¥ê¥ó¥°¤ËÂбþ
+
+- uim-agentµ¯Æ°»þ¤Î¥¿¥¤¥à¥¢¥¦¥È½èÍý¤Î²þÁ± (by °æ¾å¤µ¤ó)
+
+- uim-interactive.el¤Îuim.el¤Ø¤ÎºÆÅý¹ç
+
+- ¤½¤Î¾ºÙ¤«¤¤ÌäÂê¤Î½¤ÀµÂ¿¿ô
+
+
+
+´ûÃΤÎÌäÂêÅÀ
+============
+
+- ¥­¡¼¥Ü¡¼¥É¥Þ¥¯¥í¤Ë¤è¤ëÁÞÆþ¤òÁ°ÃÖ°ú¿ô¤òÉÕ¤±¤Æ¹Ô¤Ã¤¿ºÝ¤Ë¡¤°ì
+  ³ç¤·¤Æundo¥ê¥¹¥È¤ËÅÐÏ¿¤µ¤ì¤Ê¤¤
+
+ -- Îã)  C-x ( abc C-x ) C-u 1 0 C-x e C-_
+
+- Emacs-22¤Ç¡¤C-[ ¤ò²£¼è¤ê¤Ç¤­¤Ê¤¤
+
+- ¥×¥ê¥¨¥Ç¥£¥Ã¥Èɽ¼¨Ãæ¤Ë¥Þ¥¦¥¹¤Ç¥Ð¥Ã¥Õ¥¡Æâ¤ò¥É¥é¥Ã¥°¤¹¤ë¤È¥Ð¥Ã
+  ¥Õ¥¡¤¬¥¹¥¯¥í¡¼¥ë¤Ç¤­¤Æ¤·¤Þ¤¦
+
+- Æ°ºî¤¬¤«¤Ê¤êÆߤ¤
+
+¢¨ºÇ¿·¤Î¾õ¶·¤ÏÇÛÉÛ¥Ú¡¼¥¸¤ò¸æÍ÷²¼¤µ¤¤¡¥
+
+
+
+º£¸å¤ÎͽÄê
+==========
+
+- Æ°ºî®Å٤βþÁ±
+
+- Uim ËÜÂΤËÅý¹ç¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤
+
+
+
+ºÇ¿·ÈǤÎÆþ¼ê
+============
+
+- ²¼µ­¤ÎWiki¤«¤é¤É¤¦¤¾
+
+http://garakuta.homelinux.org/~nosuke/tsubo/uim-el.html
+
+
+
+¥Ð¥°¤äÍ×˾¤ÎÁ÷¤êÀè
+==================
+
+- ¥á¡¼¥ë¤ÇÊó¹ð¤¹¤ë¾ì¹ç¤Ï ¤Î¤¹¤±<nosuke at csc.ne.jp> °¸¤Ë¤ª´ê¤¤¤·¤Þ¤¹
+
+- Wiki¤ÎÊý¤Ë½ñ¤­¹þ¤ó¤Ç¤¯¤À¤µ¤Ã¤Æ¤â·ë¹½¤Ç¤¹
+
+
+
+¤ª´ê¤¤
+======
+
+nosuke¤Ï̤¤À Emacs LISP½é¿´¼Ô¤Ê¤¿¤á¡¤¤È¤ó¤Ç¤â¤Ê¤¤½ñ¤­Êý¤ò¤·
+¤Æ¤¤¤ëÉôʬ¤¬Â¿¡¹¸«¼õ¤±¤é¤ì¤ë¤«¤È»×¤¤¤Þ¤¹¡¥
+
+¤Þ¤¿¡¤Emacs¤ò¤¢¤ó¤Þ¤ê»È¤¤¹þ¤ó¤Ç¤¤¤Ê¤¤¤Î¤Ç¡¤ÃΤé¤Ê¤¤¥â¡¼¥É¡¤
+»È¤Ã¤¿¤³¤È¤Î̵¤¤¥â¡¼¥É¤¬¤¿¤¯¤µ¤ó¤¢¤ê¤Þ¤¹¡¥
+
+¤³¤Î¥â¡¼¥É¤À¤ÈÆ°¤«¤Ê¤¤¤è¡¤¤³¤³¤Ï¤³¤¦¤·¤¿Êý¤¬Îɤ¤¤èÅù¤¬¤¢¤ì¤Ð¡¤
+À§È󶵤¨¤Æ¤¯¤À¤µ¤¤¡¥
+
+
+
+¤´Ãí°Õ
+======
+
+- ¥é¥¤¥»¥ó¥¹Ê¸¤È¤«¤Ö¤ê¤Þ¤¹¤¬¡¤¤³¤Î¥½¥Õ¥È¥¦¥§¥¢¤Ï¤Þ¤Ã¤¿¤¯¤Î̵
+  ÊݾڤǤ¹¡¥»ÈÍѼԼ«¿È¤ÎÀÕǤ¤Ç¤ª»È¤¤²¼¤µ¤¤¡¥
+
+- ·è¤Þ¤êʸ¶ç¤È¤·¤Æ¸À¤Ã¤Æ¤¤¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¤ËÜÅö¤Ë½ñ¤­¤«¤±¤Îʸ¾Ï
+  ¤¬Èô¤ó¤À¤ê¡¤Emacs¤¬ÁàºîÉÔǽ¤Ë¤Ê¤Ã¤¿¤ê¤¹¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡¥
+
+- ¤¯¤ì¤°¤ì¤â¸æÃí°Õ²¼¤µ¤¤¡¥
+

Added: trunk/emacs/callback.c
===================================================================
--- trunk/emacs/callback.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/callback.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,166 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "callback.h"
+
+void
+commit_cb(void *ptr, const char *str)
+{
+  debug_printf(DEBUG_NOTE, "commit_cb\n");
+
+  do_commit(str);
+}
+
+
+void
+preedit_clear_cb(void *ptr)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "preedit_clear_cb\n");
+
+  clear_preedit(ua->pe);
+}
+
+
+void
+preedit_pushback_cb(void *ptr, int attr, const char * str)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE,
+			   "preedit_pushback_cb \"%s\" (attr: %d)\n", str, attr); 
+
+  add_preedit(ua->pe, attr, str);
+}
+
+
+void
+preedit_update_cb(void *ptr)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "preedit_update_cb (ua = %p)\n", ua);
+
+  /* do nothing */
+}
+
+
+void
+candidate_activate_cb(void *ptr, int num, int limit)
+{
+  /* 
+	 num:   total number of candidates
+	 limit: candidates per page
+  */
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, 
+			   "candidate_activate_cb (num=%d,limit=%d)\n", num, limit);
+
+  new_candidate(ua->context, ua->pe->cand, num, limit);
+}
+
+
+
+void
+candidate_select_cb(void *ptr, int index)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "candidate_select_cb (index: %d)\n", index);
+
+  ua->pe->cand->index = index;
+}
+
+
+void
+candidate_shift_page_cb(void *ptr, int direction)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "candidate_shift_page_cb\n");
+
+  shift_candidate_page(ua->context, ua->pe->cand, direction);
+}
+
+
+void
+candidate_deactivate_cb(void *ptr)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "candidate_deactivate_cb\n");
+
+  clear_candidate(ua->pe->cand);
+}
+
+
+/*
+ *
+ *  This function is called after key event... maybe...
+ *     If it's true, "ptr" is equal to "current" and 
+ *    S-expression with new prop_label should be outputted at end
+ *    of key processing.
+ *
+ *  This function is called when IM mode has changed... maybe...
+ * 
+ *  To notify current IM status to other processes which are 
+ *  displaying IM's status (such as uim-toolbar-gtk), 
+ *  uim_helper_send_message should be called... maybe...
+ *
+ */
+
+void
+prop_list_update_cb(void *ptr, const char *str)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "prop_list_update_cb\n");
+
+  update_prop_list(ua->prop, str);
+}
+
+
+void
+prop_label_update_cb(void *ptr , const char *str)
+{
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  debug_printf(DEBUG_NOTE, "prop_label_update_cb\n");
+
+  update_prop_label(ua->prop, str);
+}
+

Added: trunk/emacs/callback.h
===================================================================
--- trunk/emacs/callback.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/callback.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,70 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_cb_h_included_
+#define _uim_agent_cb_h_included_
+
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+#include <uim/uim.h>
+#include <uim/uim-helper.h>
+
+#include "debug.h"
+#include "output.h"
+#include "candidate.h"
+#include "preedit.h"
+#include "im.h"
+#include "context.h"
+#include "commit.h"
+#include "helper-server.h"
+#include "prop.h"
+
+void commit_cb(void *ptr, const char *str);
+
+void preedit_clear_cb(void *ptr);
+void preedit_pushback_cb(void *ptr, int attr, const char * str);
+void preedit_update_cb(void *ptr);
+
+void candidate_activate_cb(void *ptr, int num, int limit);
+void candidate_select_cb(void *ptr, int index);
+void candidate_shift_page_cb(void *ptr, int direction);
+void candidate_deactivate_cb(void *ptr);
+
+void prop_list_update_cb(void *ptr , const char *str);
+void prop_label_update_cb(void *ptr , const char *str);
+
+#endif

Added: trunk/emacs/candidate.c
===================================================================
--- trunk/emacs/candidate.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/candidate.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,170 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "candidate.h"
+
+int
+new_candidate(uim_context context, candidate_info *cand, int num, int limit)
+{
+  int i;
+  uim_candidate u_cand;
+
+  if (cand->valid) clear_candidate(cand);
+
+
+  cand->valid = 1;
+
+  cand->index = 0; 
+  cand->disp_limit = limit;
+  cand->num = num;
+
+  cand->cand_array = (candidate *)malloc(sizeof(candidate) * num);
+
+  /* get candidates from context */
+  for (i = 0; i < num; i ++) {
+	u_cand = uim_get_candidate(context, i, limit ? i % limit : i);
+	cand->cand_array[i].str = strdup(uim_candidate_get_cand_str(u_cand));
+	cand->cand_array[i].label = strdup(uim_candidate_get_heading_label(u_cand));
+	uim_candidate_free(u_cand);
+  }
+
+  return 1;
+}
+
+
+void
+show_candidate(candidate_info *cand)
+{
+  int i;
+  int page;
+  int index;
+
+  if (!cand->valid || cand->num == 0) return;
+
+  index = cand->index;
+  page = index / cand->disp_limit;
+
+  a_printf("( c ");
+
+  a_printf(" ( %d . %d ) ",  cand->index + 1,  cand->num);
+
+  for (i = cand->disp_limit * page;
+	   i < cand->disp_limit * (page + 1);
+	   i ++) {
+
+	if (i >= cand->num) break;
+
+	if (i == index)
+	  a_printf("( t ");
+	else
+	  a_printf("( nil ");
+
+	output_with_escape(cand->cand_array[i].label);
+
+	a_putchar(' ');
+
+	output_with_escape(cand->cand_array[i].str);
+
+	a_printf(" ) ");
+  }
+
+  a_printf(") ");
+}
+
+
+
+void
+clear_candidate(candidate_info *cand)
+{
+  int i;
+
+  if (cand->valid) {
+
+	cand->valid = 0;
+
+	for (i = 0; i < cand->num; i ++) {
+	  free(cand->cand_array[i].str);
+	  free(cand->cand_array[i].label);
+	}
+
+	free(cand->cand_array);
+  }
+}
+
+
+
+void
+shift_candidate_page(uim_context context, candidate_info *cand, int direction)
+{
+  int index;
+  int is_first = 0, is_last = 0;
+
+  debug_printf(DEBUG_NOTE, 
+			   "candidate_shift_page_cb (direction: %d)\n", direction);
+
+  index = cand->index;
+  
+  is_first = (index < cand->disp_limit);
+
+  /*
+   * ((cand.num - 1) / cand.disp_limit) + 1   : total pages
+   * (index / cand.disp_limit) + 1            : current page number
+   */
+  is_last = ((((cand->num - 1) / cand->disp_limit) + 1) 
+			 == ((index / cand->disp_limit) + 1));
+  
+  if (direction) { /* forward */
+
+	if (is_last)
+	  index = index % cand->disp_limit;
+	else
+	  index += cand->disp_limit;
+
+  } else { /* backward */
+
+	if (is_first)
+	  index = (cand->num / cand->disp_limit) * cand->disp_limit + index;
+    else
+	  index -= cand->disp_limit;
+  }
+
+  if (index < 0) index = 0;
+  
+  if (index >= cand->num) index = cand->num - 1;
+
+  cand->index = index;
+
+  uim_set_candidate_index(context, index);
+}

Added: trunk/emacs/candidate.h
===================================================================
--- trunk/emacs/candidate.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/candidate.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,69 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_candidate_h_included_
+#define _uim_agent_candidate_h_included_
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <uim/uim.h>
+
+#include "debug.h"
+#include "output.h"
+
+typedef struct candidate {
+  char *str;
+  char *label;
+} candidate;
+
+typedef struct candidate_info {
+  int valid;
+  int num;
+  int disp_limit;
+  int index;
+  candidate *cand_array;
+} candidate_info;
+
+
+int new_candidate(uim_context context, candidate_info *cand,
+				  int num, int limit);
+void clear_candidate(candidate_info *cand);
+
+void show_candidate(candidate_info *cand);
+
+void shift_candidate_page(uim_context context, candidate_info *cand, int direction);
+
+#endif

Added: trunk/emacs/commit.c
===================================================================
--- trunk/emacs/commit.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/commit.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,44 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "commit.h"
+
+void
+do_commit(const char *str)
+{
+  a_printf("( s ");
+  output_with_escape(str);
+  a_printf(" ) ");
+}

Added: trunk/emacs/commit.h
===================================================================
--- trunk/emacs/commit.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/commit.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,43 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_commit_h_included_
+#define _uim_agent_commit_h_included_
+
+#include "output.h"
+
+void do_commit(const char *str);
+
+#endif

Added: trunk/emacs/context.c
===================================================================
--- trunk/emacs/context.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/context.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,299 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "context.h"
+
+/* current focused context */
+uim_agent_context *current;
+
+uim_agent_context_list *agent_context_list_head = NULL;
+uim_agent_context_list *agent_context_list_tail = NULL;
+
+/* search context */
+uim_agent_context *
+get_uim_agent_context(int id)
+{
+  uim_agent_context_list *ptr;
+
+  debug_printf(DEBUG_NOTE, "get_uim_agent_context (%d)\n", id);
+  
+  for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
+	if (ptr->agent_context->context_id == id)
+	  return ptr->agent_context;
+  }
+
+  return NULL;
+}
+
+
+uim_agent_context *
+switch_context_im(uim_agent_context *ua, const char *im, const char *encoding)
+{
+  debug_printf(DEBUG_NOTE, "switch_context_im\n");
+
+  if (encoding == NULL) {
+	/* unspported engine or not ready for use from Emacs  */
+	debug_printf(DEBUG_WARNING,
+				 "switch_context_im: encoding of %s is NULL\n", im);
+	return ua;
+  }
+
+  if (strcmp(ua->encoding, encoding) == 0) {
+	/* encodings are same */
+
+	debug_printf(DEBUG_NOTE,
+				 "same encoding %s %s\n", ua->im, im);
+
+	if (ua->im) free(ua->im);
+
+	if (im)
+	  ua->im = strdup(im);
+	else
+	  ua->im = NULL;
+
+	uim_switch_im(ua->context, im);  
+
+	uim_prop_label_update(ua->context);
+	uim_prop_list_update(ua->context);
+
+	return ua;
+
+  } else {
+	/* encodings are different */
+
+	debug_printf(DEBUG_NOTE, 
+				 "different encoding %s %s\n", ua->encoding, encoding);
+
+	/* discard current context */
+	clear_candidate(ua->pe->cand);
+	clear_preedit(ua->pe);
+	uim_release_context(ua->context);
+
+	ua->context = create_context(encoding, ua);
+
+	uim_switch_im(ua->context, im);
+
+	if (ua->im) free(ua->im);
+
+	ua->im = strdup(uim_get_current_im_name(ua->context));
+
+	if (ua->encoding) free(ua->encoding);
+
+	ua->encoding = strdup(encoding);
+
+	uim_prop_label_update(ua->context);
+	uim_prop_list_update(ua->context);
+
+	return ua;
+  }
+}
+
+
+uim_context
+create_context(const char *encoding, uim_agent_context *ptr)
+{
+  uim_context context;
+
+  context = uim_create_context(ptr,
+							   encoding,
+							   NULL,
+							   NULL,  /*default_engine_name,*/
+							   uim_iconv,
+							   commit_cb);
+
+  uim_set_preedit_cb(context,
+					 preedit_clear_cb,
+					 preedit_pushback_cb,
+					 preedit_update_cb);
+
+  uim_set_candidate_selector_cb(context,
+								candidate_activate_cb,
+								candidate_select_cb,
+								candidate_shift_page_cb,
+								candidate_deactivate_cb);
+
+  uim_set_prop_list_update_cb(context,
+							  prop_list_update_cb);
+
+  uim_set_prop_label_update_cb(context,
+							   prop_label_update_cb);
+  
+  return context;
+
+}
+
+
+uim_agent_context *
+create_uim_agent_context(const char *encoding)
+{
+
+  uim_agent_context *ret;
+  const char *im;
+
+  debug_printf(DEBUG_NOTE, "create_uim_agent_context\n");
+
+  ret = (uim_agent_context *)malloc(sizeof(uim_agent_context));
+
+  if (encoding) {
+	ret->encoding = strdup(encoding);
+  } else {
+	if (debug_level > 0)
+	  ret->encoding = strdup("EUC-JP");
+	else
+	  ret->encoding = strdup("UTF-8");
+  }
+
+  ret->context = create_context(ret->encoding, ret);
+
+  /* 
+	 uim_get_current_im_name doesn't return IM name.
+	 It just returns copy of argument.
+	 Hmm... I just want to know IM name which is in use.
+  */
+  /*
+  if( (im = uim_get_current_im_name(ret->context)) ){
+	ret->im = strdup(im);
+  }else{
+	ret->im = NULL;
+  }
+  */
+
+  if ((im = uim_get_default_im_name(setlocale(LC_ALL, NULL))))
+	ret->im = strdup(im);
+  else
+	ret->im = NULL;
+
+  ret->pe = (preedit *)malloc(sizeof(preedit));
+
+  ret->pe->head = ret->pe->tail = NULL;
+
+  ret->pe->cand = (candidate_info *)malloc(sizeof(candidate_info));
+  ret->pe->cand->valid = 0;
+
+  ret->prop = (property *)malloc(sizeof(property));
+  ret->prop->list = NULL;
+  ret->prop->label = NULL;
+  ret->prop->list_update = 0;
+  ret->prop->label_update = 0;
+
+  uim_prop_list_update(ret->context);
+
+  return ret;
+}
+
+
+
+
+/* add context to context list */
+uim_agent_context *
+new_uim_agent_context(int id, const char *encoding)
+{
+  uim_agent_context_list *ptr;
+  
+  debug_printf(DEBUG_NOTE, "add_uim_agent_context(%d)\n", id);
+
+  ptr = (uim_agent_context_list *)malloc(sizeof(uim_agent_context_list));
+
+  ptr->agent_context = create_uim_agent_context(encoding);
+  ptr->next = NULL;
+  ptr->prev = NULL;
+
+  ptr->agent_context->context_id = id;
+
+  if (agent_context_list_tail != NULL) {
+	agent_context_list_tail->next = ptr;
+	ptr->prev = agent_context_list_tail;
+  }
+
+  agent_context_list_tail = ptr;
+
+  if (agent_context_list_head == NULL)
+	agent_context_list_head = ptr;
+
+  return ptr->agent_context;
+}
+
+
+/* release context from context list */
+int
+release_uim_agent_context(int id)
+{
+  uim_agent_context_list *ptr;
+  
+  for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
+	if (ptr->agent_context->context_id == id) {
+
+	  preedit_buffer *p, *ptmp;
+
+	  if (current == ptr->agent_context)
+		current = NULL;
+	  
+	  /* release */
+	  uim_release_context(ptr->agent_context->context);
+
+	  clear_candidate(ptr->agent_context->pe->cand);
+	  free(ptr->agent_context->pe->cand);
+
+	  p = ptr->agent_context->pe->head; 
+
+	  while (p) {
+	  	ptmp = p;
+		p = p->next;
+		if (ptmp->str) free(ptmp->str);
+		free (ptmp);
+	  }
+
+	  free(ptr->agent_context->encoding);
+
+	  /* rebuild list */
+	  if (ptr->next != NULL)
+		ptr->next->prev = ptr->prev;
+	  else
+		agent_context_list_tail = ptr->prev;
+
+	  if (ptr->prev != NULL)
+		ptr->prev->next = ptr->next;
+	  else
+		agent_context_list_head = ptr->next;
+
+	  free(ptr);
+
+	  return id;
+	}
+  }
+
+  return -1;
+}
+

Added: trunk/emacs/context.h
===================================================================
--- trunk/emacs/context.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/context.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,87 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_context_h_included_
+#define _uim_agent_context_h_included_
+
+#include <string.h>
+#include <stdlib.h>
+#include <locale.h>
+
+#include <uim/uim.h>
+#include <uim/uim-im-switcher.h>
+
+#include "debug.h"
+#include "prop.h"
+#include "preedit.h"
+#include "im.h"
+#include "callback.h"
+
+typedef struct uim_agent_context {
+  uim_context context;
+  int context_id;
+  char *encoding;
+  char *im;
+  preedit *pe;
+  property *prop;
+} uim_agent_context;
+
+
+typedef struct uim_agent_context_list {
+  uim_agent_context *agent_context;
+  struct uim_agent_context_list *next;
+  struct uim_agent_context_list *prev;
+} uim_agent_context_list;
+
+
+uim_context create_context(const char *encoding, uim_agent_context *ptr);
+
+uim_agent_context *create_uim_agent_context(const char *encoding);
+uim_agent_context *new_uim_agent_context(int id, const char *encoding);
+int release_uim_agent_context(int id);
+
+uim_agent_context *get_uim_agent_context(int id);
+
+uim_agent_context *switch_context_im(uim_agent_context *ua, const char *im,
+									 const char *encoding);
+
+/* current focused context */
+extern uim_agent_context *current;
+
+extern uim_agent_context_list *agent_context_list_head;
+extern uim_agent_context_list *agent_context_list_tail;
+
+
+#endif

Added: trunk/emacs/debug.c
===================================================================
--- trunk/emacs/debug.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/debug.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,54 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "debug.h"
+
+int debug_level = 0;
+
+int
+debug_printf(int level, const char *fmt, ...)
+{
+  int ret = 0;
+  va_list ap;
+
+  if (debug_level >= level) {
+	va_start(ap, fmt);
+	ret = vfprintf(stderr, fmt, ap);
+	va_end(ap);  
+  }
+
+  return ret;
+}
+

Added: trunk/emacs/debug.h
===================================================================
--- trunk/emacs/debug.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/debug.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,53 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef _uim_agent_debug_h_included_
+#define _uim_agent_debug_h_included_
+
+#include <stdio.h>
+#include <stdarg.h>
+
+extern int debug_level;
+
+enum debug_level {
+  DEBUG_ERROR = 1,
+  DEBUG_WARNING,
+  DEBUG_NOTE
+};
+
+int debug_printf(int level, const char *fmt, ...);
+
+#endif

Added: trunk/emacs/encoding.c
===================================================================
--- trunk/emacs/encoding.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/encoding.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,134 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "encoding.h"
+
+im_encoding *im_enc_list_head = NULL, *im_enc_list_tail = NULL;
+
+
+/* search encoding entry */
+im_encoding *
+search_im_encoding(const char *im)
+{
+  im_encoding *im_enc = im_enc_list_head;
+
+  debug_printf(DEBUG_NOTE, "search_im_encoding\n");
+
+  while (im_enc) {
+	if (strcmp(im_enc->im, im) == 0) {
+	  debug_printf(DEBUG_NOTE, " found\n");
+	  return im_enc;
+	}
+	im_enc = im_enc->next;
+  }
+
+  debug_printf(DEBUG_NOTE, " not found\n");
+  return NULL;
+}
+
+
+im_encoding *
+new_im_encoding(const char *im, const char *encoding)
+{
+  im_encoding *im_enc = (im_encoding *)malloc(sizeof(im_encoding));
+
+  debug_printf(DEBUG_NOTE, "new_im_encoding\n");
+
+  im_enc->im = strdup(im);
+
+  if (encoding != NULL)
+	im_enc->encoding = strdup( encoding );
+  else
+	im_enc->encoding = NULL;
+
+  im_enc->next = NULL;
+
+  if (im_enc_list_tail == NULL) {
+	im_enc_list_tail = im_enc;
+	im_enc_list_head = im_enc;
+  } else {
+	im_enc_list_tail->next = im_enc;
+	im_enc_list_tail = im_enc;
+  }
+
+  return im_enc;
+}
+
+
+/*
+ *     Since 21.x or lower version of Emacs doesn't support UTF-8 well,
+ *  uim-el-agent outputs strings which are encoded with each language's
+ *  encoding.  The encoding of each IM are specified by Emacs.
+ */
+int
+set_im_encoding(const char *im, const char *encoding)
+{
+  im_encoding *im_enc;
+
+  if (im == NULL) return -1;
+
+  im_enc = search_im_encoding(im);
+
+  if (im_enc != NULL) {
+	if (im_enc->encoding) free(im_enc->encoding);
+
+	if (encoding)
+	  im_enc->encoding = strdup(encoding);
+	else
+	  im_enc->encoding = NULL;
+
+  } else {
+	new_im_encoding(im, encoding);
+  }
+
+  return 1;
+}
+
+
+/* get encoding from im list */
+const char *
+get_im_encoding(const char *im)
+{
+  im_encoding *im_enc = search_im_encoding(im);
+
+  debug_printf(DEBUG_NOTE, "get_im_encoding %s\n", im);
+
+  if (im_enc != NULL) {
+	debug_printf(DEBUG_NOTE, " encoding = %s\n", im_enc->encoding);
+	return im_enc->encoding;
+  } else {
+	return NULL;
+  }
+}

Added: trunk/emacs/encoding.h
===================================================================
--- trunk/emacs/encoding.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/encoding.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,60 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_encoding_h_included_
+#define _uim_agent_encoding_h_included_
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <uim/uim.h>
+
+#include "debug.h"
+
+typedef struct im_encoding {
+  char *im;                  /* IM name */
+  char *encoding;            /* Encoding name (in uim-encoding.h) */
+  struct im_encoding *next;
+} im_encoding;
+
+extern im_encoding *im_enc_list_head, *im_enc_list_tail;
+
+im_encoding *search_im_encoding(const char *im);
+im_encoding *new_im_encoding(const char *im, const char *encoding);
+int set_im_encoding(const char *im, const char *encoding);
+const char *get_im_encoding(const char *im);
+
+
+#endif

Added: trunk/emacs/helper-server.c
===================================================================
--- trunk/emacs/helper-server.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/helper-server.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,55 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "helper-server.h"
+
+int helper_fd = -1;
+
+/* called when helper_fd is disconnected */
+void
+helper_disconnected_cb(void)
+{
+  debug_printf(DEBUG_WARNING, "helper_disconnected\n");
+  helper_fd = -1;
+}
+
+
+void
+check_helper_connection(void)
+{
+  if (helper_fd < 0)
+    helper_fd = uim_helper_init_client_fd(helper_disconnected_cb);
+}
+

Added: trunk/emacs/helper-server.h
===================================================================
--- trunk/emacs/helper-server.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/helper-server.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,53 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_helper_server_h_included_
+#define _uim_agent_helper_server_h_included_
+
+#include <sys/types.h>
+#include <sys/select.h>
+
+#include <uim/uim.h>
+
+#include <uim/uim-helper.h>
+
+#include "debug.h"
+
+extern int helper_fd;
+
+void helper_disconnected_cb(void);
+void check_helper_connection(void);
+
+#endif

Added: trunk/emacs/helper.c
===================================================================
--- trunk/emacs/helper.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/helper.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,355 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "helper.h"
+
+void
+helper_send_im_list(void)
+{
+  int nim, i;
+  int len = 0, buflen;
+  char *buf;
+  const char *current_im_name;
+
+  debug_printf(DEBUG_NOTE, "helper_send_im_list\n");
+
+  if (current == NULL || current->context == NULL) return;
+
+  nim = uim_get_nr_im(current->context);
+
+  uim_get_current_im_name(current->context);
+  current_im_name = uim_get_current_im_name(current->context);
+
+#define HEADER_FORMAT "im_list\ncharset=%s\n"
+
+  len += strlen(HEADER_FORMAT) + strlen(current->encoding);
+  len += strlen("selected") ;
+
+  for (i = 0; i < uim_get_nr_im(current->context); i++) {
+	const char *name, *lang, *shortd;
+	name = uim_get_im_name(current->context, i);
+	lang = uim_get_im_language(current->context, i);
+	shortd = uim_get_im_short_desc(current->context, i);
+
+	len += name ? strlen(name) : 0;
+	len += lang ? strlen(lang) : 0;
+	len += shortd ? strlen(shortd) : 0;
+	len += strlen( "\t\t\t\n");
+  }
+
+  len++ ;
+
+  buf = (char *)malloc(sizeof(char) * len);
+
+  buflen = snprintf(buf, len, HEADER_FORMAT, current->encoding);
+
+
+  for (i = 0 ; i < uim_get_nr_im(current->context); i++) {
+	const char *name, *lang, *shortd;	
+	name = uim_get_im_name(current->context, i);
+	lang = uim_get_im_language(current->context, i);
+	shortd = uim_get_im_short_desc(current->context, i);
+
+	debug_printf(DEBUG_NOTE, " [%d] = %s %s %s\n", i, name, lang, shortd);
+
+	buflen += snprintf(buf + buflen, len - buflen,
+					   "%s\t%s\t%s\t%s\n",
+					   name ? name : "" ,
+					   lang ? lang : "" ,
+					   shortd ? shortd : "" ,
+					   strcmp(name, 
+							  (current_im_name == NULL ? "" : current_im_name))
+					   == 0 ? "selected" : "");
+  }
+
+  uim_helper_send_message(helper_fd, buf);
+
+  debug_printf(DEBUG_NOTE, " im_list = \"%s\"\n", buf);
+  
+  free(buf);
+}
+
+
+
+void
+helper_im_changed(char *request, char *engine_name)
+{
+  uim_agent_context_list *ptr;
+
+  debug_printf(DEBUG_NOTE, "helper_im_changed: %s\n", engine_name);
+
+  if (strcmp(request, "im_change_this_text_area_only") == 0) {
+
+    if (current) {
+      switch_context_im(current, engine_name, get_im_encoding(engine_name));
+	  if(current->im) free(current->im);
+	  current->im = strdup(engine_name);
+      uim_prop_label_update(current->context);
+      uim_prop_list_update(current->context);
+    }
+
+  } else if (strcmp(request, "im_change_whole_desktop") == 0 
+			 || strcmp(request, "im_change_this_application_only") == 0) {
+
+	char *quot_engine_name;
+
+	/* change default */
+	update_default_engine(engine_name);
+	  /* if (default_engine_name) free(default_engine_name);
+		 default_engine_name = strdup(engine_name); */
+
+	/* check focus state when change IM of current application */
+	if (strcmp(request, "im_change_whole_desktop") == 0 || current) {
+	  quot_engine_name = (char *)malloc(strlen(engine_name) + 2);
+	  quot_engine_name[0] = '\'';
+	  quot_engine_name[1] = '\0';
+	  strcat(quot_engine_name, engine_name);
+	  for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
+
+		switch_context_im(ptr->agent_context, 
+						  engine_name, get_im_encoding(engine_name));
+
+		uim_prop_update_custom(ptr->agent_context->context,
+							   "custom-preserved-default-im-name",
+							   quot_engine_name);
+
+		if (ptr->agent_context->im) free(ptr->agent_context->im);
+		ptr->agent_context->im = strdup(engine_name);
+		
+		if (current && ptr->agent_context == current) {
+		  uim_prop_label_update(ptr->agent_context->context);
+		  uim_prop_list_update(ptr->agent_context->context);
+		}
+	  }
+	  free(quot_engine_name);
+    }
+  }
+}
+
+
+
+/* handle messages from helper */
+void
+helper_handler(void)
+{
+  char *message;
+
+  uim_helper_read_proc(helper_fd);
+
+  debug_printf(DEBUG_NOTE, "helper_handler\n");
+
+  while ((message = uim_helper_get_message())) {
+
+    char *line = message;
+    char *eol;
+
+	int current_exist = (current != NULL && current->context != NULL);
+
+    if ((eol = strchr(line, '\n')) != NULL) {
+	  *eol = '\0';
+    } else {
+	  free(message);
+	  break;
+	}
+
+	debug_printf(DEBUG_NOTE, " message \"%s\"\n", message);
+
+	if (strcmp("prop_list_get", line) == 0) { 
+	  /* for current context */
+
+	  debug_printf(DEBUG_NOTE, "prop_list_get\n");
+	  if (current_exist)
+		uim_prop_list_update(current->context);
+	  else
+		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
+		
+	} else if (strcmp("prop_label_get", line) == 0) { 
+	  /* for current context */
+
+	  if (current_exist)
+		uim_prop_label_update(current->context);
+	  else
+		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
+
+	} else if (strcmp("prop_activate", line) == 0) { 
+	  /* for current context */
+
+	  if (current_exist) {
+		line = eol + 1;
+		if ((eol = strchr(line, '\n')) != NULL) {
+		  *eol = '\0';
+		  uim_prop_activate(current->context, line);
+		} else {
+		  debug_printf(DEBUG_WARNING, 
+					   " invalid message(prop_activate): \"%s\"\n", message);
+		}
+	  } else {
+		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
+	  }
+
+	} else if (strcmp("im_list_get", line) == 0) {
+	  /* for current context */
+
+	  if (current_exist) {
+		debug_printf(DEBUG_NOTE, " im_list_get\n");
+		helper_send_im_list();
+	  } else {
+		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
+	  }
+		
+	} else if (strncmp("focus_in", line, 8) == 0) {
+
+	  if (current_exist) {
+		debug_printf(DEBUG_NOTE, " focus_in\n"); 
+		if (current) unfocused();
+	  } else {
+		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
+	  }
+
+	} else if (strcmp("commit_string", line) == 0) { /* for current context */
+
+	  if (current_exist) {
+		line = eol + 1;
+		if ((eol = strchr(line, '\n')) != NULL) {
+		  *eol = '\0';
+		  /* do nothing */
+		  debug_printf(DEBUG_NOTE, 
+					   " commit_string \"%s\"\n", line);
+		} else {
+		  debug_printf(DEBUG_WARNING, 
+					   " invalid message(commit_string) \"%s\"\n", message);
+		}
+	  } else {
+		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
+	  }
+
+	} else if (strncmp(line, "im_change_", 10) == 0) {
+
+	  char *engine;
+
+	  engine = eol + 1;
+	  if ((eol = strchr(engine, '\n')) != NULL) {
+		*eol = '\0';
+		helper_im_changed(line, engine);
+	  } else {
+		debug_printf(DEBUG_WARNING,
+					 " invalid message(im_change) \"%s\"\n", message);
+	  }
+
+	} else if (strcmp("prop_update_custom", line) == 0) {
+
+	  /* message from uim-pref-{gtk,qt} */
+	  char *custom;
+	  char *val;
+
+	  uim_agent_context_list *ptr;
+
+	  line = eol + 1;
+	  custom = line;
+
+	  if ((eol = strchr(line, '\n')) != NULL) {
+		*eol = '\0';
+		val = eol + 1;
+
+		if ((eol = strchr(val, '\n')) != NULL) {
+		  *eol = '\0';
+		  for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
+			uim_prop_update_custom(ptr->agent_context->context, custom, val);
+		  }
+		} else {
+		  debug_printf(DEBUG_WARNING,
+					   " invalid message val of prop_update_custom: \"%s\"\n",
+					   val);
+		}
+
+	  } else {
+		debug_printf(DEBUG_WARNING,
+					 " invalid message: ",
+					 "custom of prop_update_custom: \"%s\"\n",
+					 line);
+	  }
+
+	} else if (strcmp("prop_list_update", line) == 0) {
+	  /* ignore */
+	  debug_printf(DEBUG_NOTE, " prop_list_update (helper)\n");
+	} else if ( strcmp("prop_label_update", line) == 0) {
+	  /* ignore */
+	  debug_printf(DEBUG_NOTE, " prop_label_update (helper)\n");
+	} else {
+	  debug_printf(DEBUG_WARNING, " undefined helper message: %s\n", message);
+	}
+
+	free(message);
+  }
+}
+
+
+/* focus in to a buffer */
+int
+focused(uim_agent_context *ua)
+{
+  debug_printf(DEBUG_NOTE, "focused\n");
+
+  if (ua == NULL || ua->context == NULL) return -1;
+
+  uim_helper_client_focus_in(ua->context);
+
+  current = ua;
+
+  uim_prop_label_update(ua->context);
+  uim_prop_list_update(ua->context);
+
+  return ua->context_id;
+}
+
+
+/* focus out from current buffer */
+int
+unfocused(void)
+{
+  int ret;
+
+  debug_printf(DEBUG_NOTE, "unfocused\n");
+
+  if (current == NULL || current->context == NULL) return -1;
+
+  ret = current->context_id;
+  uim_helper_client_focus_out(current->context);
+
+  current = NULL;
+
+  return ret;
+}
+

Added: trunk/emacs/helper.h
===================================================================
--- trunk/emacs/helper.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/helper.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,61 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_helper_h_included_
+#define _uim_agent_helper_h_included_
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <uim/uim.h>
+#include <uim/uim-helper.h>
+#include <uim/uim-im-switcher.h>
+
+#include "debug.h"
+
+#include "context.h"
+#include "encoding.h"
+#include "im.h"
+#include "helper-server.h"
+
+void helper_send_im_list(void);
+void helper_im_changed(char *request, char *engine_name);
+
+void helper_handler(void);
+
+int focused(uim_agent_context *ua);
+int unfocused(void);
+
+#endif

Added: trunk/emacs/im.c
===================================================================
--- trunk/emacs/im.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/im.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,147 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "im.h"
+
+/* context's default value */
+char *default_engine_name = NULL;
+
+int default_engine_updated = 0;
+
+/*
+int
+init_default_engine(void)
+{
+  if (default_engine_name) free(default_engine_name);
+
+  default_engine_name 
+	= strdup(uim_get_default_im_name(setlocale(LC_ALL, NULL)));
+
+  return 1;
+}
+*/
+
+void
+update_default_engine(const char *engine_name)
+{
+  if (default_engine_name) free(default_engine_name);
+  default_engine_name = strdup(engine_name);
+
+  default_engine_updated = 1;
+}
+
+void
+output_default_im_engine(void)
+{
+  if (default_engine_name)
+	a_printf(" ( d \"%s\" ) ", default_engine_name);
+}
+
+
+int
+check_im_name(const char *imname)
+{
+  int ret = 0, i;
+  const char *name;
+  uim_context context;
+
+  context = uim_create_context(NULL, "UTF-8", NULL, NULL, NULL, NULL);
+
+  for (i = 0; i < uim_get_nr_im(context); i++) {  
+	name = uim_get_im_name(context, i);
+	if (strcmp(name, imname) == 0) ret = 1;
+  }
+
+  uim_release_context(context);
+
+  return ret;
+}
+
+
+
+
+/* show supported IM engines */
+int
+list_im_engine(void)
+{
+  int i;
+
+  uim_context context;
+
+  context = uim_create_context(NULL, "UTF-8", NULL, NULL, NULL, NULL);
+
+  /*
+  if (default_engine_name)
+	a_printf(" ( L \"%s\" ", default_engine_name);
+  else
+	a_printf(" ( L \"%s\" ", uim_get_default_im_name(setlocale(LC_ALL, NULL)));
+  */
+  /*a_printf(" ( L "); */
+
+  a_printf(" ( L \"%s\" ", uim_get_default_im_name(setlocale(LC_ALL, NULL)));
+  
+  for (i = 0 ; i < uim_get_nr_im(context); i++) {
+	char dummy_str[] = "";
+	const char *name, *lang, *language, *shortd, *encoding;
+
+	if ((name = uim_get_im_name(context, i)) == NULL)
+	  name = dummy_str;
+
+	if ((lang = uim_get_im_language(context, i)) == NULL)
+	  lang = dummy_str;
+
+	if ((language = uim_get_language_name_from_locale(lang)) == NULL)
+	  language = dummy_str;
+
+	if ((shortd = uim_get_im_short_desc(context, i)) == NULL)
+	  shortd = dummy_str;
+	
+	a_printf(" ( \"%s\" \"%s\" \"%s\" \"%s\" ",
+			 name, lang, language, shortd);
+
+	if ((encoding = uim_get_im_encoding(context, i)) == NULL)
+	  a_printf(" %s ) ", encoding);
+	else
+	  a_printf(" UTF-8 ) "); /* or nil? */
+  }
+
+  a_printf(" ) ");
+
+  uim_release_context(context);
+
+  return i;
+}
+
+

Added: trunk/emacs/im.h
===================================================================
--- trunk/emacs/im.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/im.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,58 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_im_h_included_
+#define _uim_agent_im_h_included_
+
+#include <string.h>
+#include <locale.h>
+#include <stdlib.h>
+
+#include <uim/uim.h>
+#include <uim/uim-util.h>
+
+#include "output.h"
+
+extern int default_engine_updated;
+extern char *default_engine_name;
+
+void output_default_im_engine(void);
+int list_im_engine(void);
+int check_im_name(const char *imname);
+
+/*int init_default_engine(void);*/
+void update_default_engine(const char *engine_name);
+
+#endif

Added: trunk/emacs/key.c
===================================================================
--- trunk/emacs/key.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/key.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,178 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "key.h"
+
+/*
+  convert abbreviated key description to generic Emacs-style key description
+  (for XEmacs)
+*/
+void
+convert_keyname_a2e(char *keyname, const char *name)
+{
+  if (strcmp(name, "BS") == 0)
+	strcpy(keyname, "backspace");
+  else if (strcmp(name, "TAB") == 0)
+	strcpy(keyname, "tab");
+  else if (strcmp(name, "RET") == 0)
+	strcpy(keyname, "return");
+  else if (strcmp(name, "ESC") == 0)
+	strcpy(keyname, "escape");
+  else if (strcmp(name, "DEL") == 0)
+	strcpy(keyname, "delete");
+  else if (strcmp(name, "DEL") == 0)
+	strcpy(keyname, "delete");
+  else if (strcmp(name, "SPC") == 0)
+	strcpy(keyname, "space");
+  else
+	strcpy(keyname, name);
+}
+
+
+/*
+  convert generic Emacs-style key description to Uim-style key description
+*/
+enum UKey
+convert_keyname_e2u(const char *keyname)
+{
+  if (strcmp("space", keyname) == 0)
+	return ' ';  /* "space" has no Uim-style key description */
+  else if (strcmp("backspace", keyname) == 0)
+	return UKey_Backspace;
+  else if (strcmp("tab", keyname) == 0)
+	return UKey_Tab;
+  else if (strcmp("return", keyname) == 0)
+	return UKey_Return;
+  else if (strcmp("escape", keyname) == 0)
+	return UKey_Escape;
+  else if (strcmp("prior", keyname) == 0)
+	return UKey_Prior;
+  else if (strcmp("next", keyname) == 0)
+	return UKey_Next;
+  else if (strcmp("end", keyname) == 0)
+	return UKey_End;
+  else if (strcmp("home", keyname) == 0)
+	return UKey_Home;
+  else if (strcmp("left", keyname) == 0)
+	return UKey_Left;
+  else if (strcmp("up", keyname) == 0)
+	return UKey_Up;
+  else if (strcmp("right", keyname) == 0)
+	return UKey_Right;
+  else if (strcmp("down", keyname) == 0)
+	return UKey_Down;
+  else if (strcmp("insert", keyname) == 0)
+	return UKey_Insert;
+  else if (strcmp("delete", keyname) == 0)
+	return UKey_Delete;
+  else if (strcmp("muhenkan", keyname) == 0)
+	return UKey_Muhenkan;
+  else if (strcmp("henkan", keyname) == 0)
+	return UKey_Henkan_Mode;
+  else if (strcmp("zenkaku-hankaku", keyname) == 0)
+	return UKey_Zenkaku_Hankaku;
+  else if (strcmp("f1", keyname) == 0)
+	return UKey_F1;
+  else if (strcmp("f2", keyname) == 0)
+	return UKey_F2;
+  else if (strcmp("f3", keyname) == 0)
+	return UKey_F3;
+  else if (strcmp("f4", keyname) == 0)
+	return UKey_F4;
+  else if (strcmp("f5", keyname) == 0)
+	return UKey_F5;
+  else if (strcmp("f6", keyname) == 0)
+	return UKey_F6;
+  else if (strcmp("f7", keyname) == 0)
+	return UKey_F7;
+  else if (strcmp("f8", keyname) == 0)
+	return UKey_F8;
+  else if (strcmp("f9", keyname) == 0)
+	return UKey_F9;
+  else if (strcmp("f10", keyname) == 0)
+	return UKey_F10;
+  else if (strcmp("f11", keyname) == 0)
+	return UKey_F11;
+  else if (strcmp("f12", keyname) == 0)
+	return UKey_F12;
+  else if (strcmp("f13", keyname) == 0)
+	return UKey_F13;
+  else if (strcmp("f14", keyname) == 0)
+	return UKey_F14;
+  else if (strcmp("f15", keyname) == 0)
+	return UKey_F15;
+  else if (strcmp("f16", keyname) == 0)
+	return UKey_F16;
+  else if (strcmp("f17", keyname) == 0)
+	return UKey_F17;
+  else if (strcmp("f18", keyname) == 0)
+	return UKey_F18;
+  else if (strcmp("f19", keyname) == 0)
+	return UKey_F19;
+  else if (strcmp("f20", keyname) == 0)
+	return UKey_F20;
+  else if (strcmp("f21", keyname) == 0)
+	return UKey_F21;
+  else if (strcmp("f22", keyname) == 0)
+	return UKey_F22;
+  else if (strcmp("f23", keyname) == 0)
+	return UKey_F23;
+  else if (strcmp("f24", keyname) == 0)
+	return UKey_F24;
+  else if (strcmp("f25", keyname) == 0)
+	return UKey_F25;
+  else if (strcmp("f26", keyname) == 0)
+	return UKey_F26;
+  else if (strcmp("f27", keyname) == 0)
+	return UKey_F27;
+  else if (strcmp("f28", keyname) == 0)
+	return UKey_F28;
+  else if (strcmp("f29", keyname) == 0)
+	return UKey_F29;
+  else if (strcmp("f30", keyname) == 0)
+	return UKey_F30;
+  else if (strcmp("f31", keyname) == 0)
+	return UKey_F31;
+  else if (strcmp("f32", keyname) == 0)
+	return UKey_F32;
+  else if (strcmp("f33", keyname) == 0)
+	return UKey_F33;
+  else if (strcmp("f34", keyname) == 0)
+	return UKey_F34;
+  else if (strcmp("f35", keyname) == 0)
+	return UKey_F35;
+  else
+	return UKey_Other;
+}

Added: trunk/emacs/key.h
===================================================================
--- trunk/emacs/key.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/key.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,51 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_key_h_included_
+#define _uim_agent_key_h_included_
+
+#include <string.h>
+
+#include <uim/uim.h>
+
+typedef struct uim_key{
+  int mod;
+  int key;
+} uim_key;
+
+void convert_keyname_a2e(char *keyname, const char *name);
+enum UKey convert_keyname_e2u( const char *keyname );
+
+#endif

Added: trunk/emacs/output.c
===================================================================
--- trunk/emacs/output.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/output.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,92 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "output.h"
+
+int output_enable = 1;
+
+int
+a_putchar(const int c)
+{
+  if (output_enable)
+	return putchar(c);
+  else
+	return 0;
+}
+
+
+int
+a_printf(const char *fmt, ...)
+{
+  int ret = 0;
+  
+  if (output_enable) {
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vfprintf(stdout, fmt, ap);
+	va_end(ap);  
+  }
+
+  return ret;
+}
+
+
+void
+output_with_escape(const char *str)
+{
+  unsigned i;
+
+  a_putchar('"');
+
+  if (str != NULL) {
+
+	if (strchr(str, '"') || strchr(str, '\\')) {
+
+	  for (i = 0; i < strlen(str); i ++) {
+		if (str[i] == '"') 
+		  a_printf("\\\"");
+		else
+		  a_putchar(str[i]);
+	  }
+
+	} else {
+	  a_printf("%s", str);
+	}
+  }
+
+  a_putchar('"');
+}
+

Added: trunk/emacs/output.h
===================================================================
--- trunk/emacs/output.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/output.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,52 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_output_h_included_
+#define _uim_agent_output_h_included_
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include "debug.h"
+
+extern int output_enable;
+
+int a_putchar(int c);
+int a_printf(const char *fmt, ...);
+
+void output_with_escape(const char *str);
+
+#endif

Added: trunk/emacs/preedit.c
===================================================================
--- trunk/emacs/preedit.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/preedit.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,125 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "preedit.h"
+
+void
+add_preedit(preedit *pe, int attr, const char *str)
+{
+  preedit_buffer *pb;
+
+  pb = (preedit_buffer *)malloc(sizeof(preedit_buffer));
+
+  if (pe->head == NULL) {
+	pe->head = pb;
+	pe->tail = pb;
+  } else {
+	pe->tail->next = pb;
+	pe->tail = pb;
+  }
+
+
+  if (strlen(str) > 0) {
+	pb->str = (char *)malloc(strlen(str) + 1);
+	strcpy(pb->str, str);
+	pe->length += strlen(str);
+  } else {
+	pb->str = NULL;
+  }
+
+  pb->attr = attr;
+  pb->next = NULL;
+}
+
+
+void
+clear_preedit(preedit *pe)
+{
+  preedit_buffer *p, *ptmp;
+
+  p = pe->head;
+
+  while (p) {
+	ptmp = p;
+	p = p->next;
+	free(ptmp->str);
+	free(ptmp);
+  }
+
+  pe->head = pe->tail = NULL;
+  pe->length = 0;
+}
+
+
+
+int
+show_preedit(preedit *pe)
+{
+  preedit_buffer *p;
+
+  p = pe->head;
+
+  if (p == NULL || pe->length == 0) {
+	a_printf(" ( e ) ");
+	return 0;
+  }
+
+  a_printf("( p ");
+
+  while (p) {
+	a_printf(" ( ");
+	if (p->attr & UPreeditAttr_Reverse)
+	  a_putchar('r');
+	if (p->attr & UPreeditAttr_UnderLine) 
+	  a_putchar('u');
+	if (p->attr & UPreeditAttr_Cursor) 
+	  a_putchar('c');
+	if (p->attr & UPreeditAttr_Separator)
+	  a_putchar('s');
+
+	a_putchar('t');
+	a_putchar(' ');
+
+	output_with_escape(p->str);
+
+	a_printf(" ) ");
+
+	p = p->next;
+  }
+  a_printf(" ) ");
+
+  return 1;
+}
+

Added: trunk/emacs/preedit.h
===================================================================
--- trunk/emacs/preedit.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/preedit.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,67 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_preedit_h_included_
+#define _uim_agent_preedit_h_included_
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <uim/uim.h>
+
+#include "debug.h"
+#include "output.h"
+#include "candidate.h"
+
+typedef struct preedit_buffer { /* -> preedit_segment */
+  char *str;
+  int attr;
+  unsigned cursor;
+  struct preedit_buffer *next;
+} preedit_buffer;
+
+typedef struct preedit {
+  int length;
+  preedit_buffer *head;
+  preedit_buffer *tail;
+  candidate_info *cand;
+} preedit;
+
+
+void add_preedit(preedit *pe, int attr, const char *str);
+void clear_preedit(preedit *pe);
+int show_preedit(preedit *pe);
+
+#endif

Added: trunk/emacs/prop.c
===================================================================
--- trunk/emacs/prop.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/prop.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,181 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "prop.h"
+
+
+void
+update_prop_list(property *prop, const char *str)
+{
+  if (prop->list != NULL) free(prop->list);
+
+  prop->list = strdup(str);
+  
+  prop->list_update = 1;
+
+}
+
+void
+update_prop_label(property *prop, const char *str)
+{
+  if (prop->label != NULL) free(prop->label);
+
+  prop->label = strdup(str);
+
+  prop->label_update = 1;
+
+}
+
+
+void
+announce_prop_list_update(property *prop, const char *encoding)
+{
+  unsigned len;
+  char *buf;
+
+  if (prop->list == NULL) {
+	debug_printf(DEBUG_ERROR, "no prop_list\n");
+	return;
+  }
+
+#define PROP_LIST_FORMAT "prop_list_update\ncharset=%s\n%s"
+
+  len = strlen(PROP_LIST_FORMAT) + strlen(encoding)
+	+ strlen(prop->list) + 1;
+
+  buf = (char *)malloc(len);
+
+  snprintf(buf, len, PROP_LIST_FORMAT, encoding, prop->list);
+
+  uim_helper_send_message(helper_fd, buf);
+
+  free(buf);
+
+#undef PROP_LIST_FORMAT
+  
+}
+
+
+void
+output_prop_list(property *prop, const char *im)
+{
+  char *buf;
+  char *p[4];
+  
+  /* output new prop_list for Emacs */
+
+  if (prop->list == NULL) {
+	debug_printf(DEBUG_ERROR, "no prop_list\n");
+	return;
+  }
+
+  /*
+  if (im)
+	a_printf(" ( l ( \"%s\" . ", im);
+  else
+	a_printf(" ( l ( \"\" . ");
+
+
+  if (default_engine_name) 
+	a_printf("\"%s\" ) ", default_engine_name);
+  else
+	a_printf("\"%s\" ) ", uim_get_default_im_name(setlocale(LC_ALL, NULL)));
+  */
+
+  if (im)
+	a_printf(" ( l \"%s\"", im);
+  else
+	a_printf(" ( l \"\" ");
+
+  buf = (char *)malloc(strlen(prop->list) + 1);
+  strcpy(buf, prop->list);
+
+  p[0] = buf;
+
+  while (p[0] && *p[0]) { 
+
+	p[1] = strchr(p[0], '\n');
+
+	if (p[1]) 
+	  *p[1] = '\0';
+	else
+	  break;
+
+	/* p[0] always not equal NULL */
+	if (strlen(p[0]) >= 6 && strncmp(p[0], "branch", 6) == 0) {
+	  if ((p[2] = strchr(p[0], '\t')) && (p[3] = strchr(p[2] + 1, '\t'))) {
+		*p[2] = *p[3] = '\0';
+		a_printf(" ( \"%s\" \"%s\" ) ", p[2] + 1, p[3] + 1);
+	  }
+	}
+	p[0] = p[1] + 1;
+  }
+
+  free(buf);
+
+
+  a_printf(" ) ");
+
+}
+
+
+void
+announce_prop_label_update(property *prop, const char *encoding)
+{
+  unsigned len;
+  char *buf;
+
+  if (prop->label == NULL) {
+	debug_printf(DEBUG_ERROR, "no prop_label\n");
+	return;
+  }
+
+#define PROP_LABEL_FORMAT "prop_label_update\ncharset=%s\n%s"
+
+  len = strlen(PROP_LABEL_FORMAT) + strlen(encoding) 
+	+ strlen(prop->label) + 1;
+  
+  buf = (char *)malloc(len);
+
+  snprintf(buf, len, PROP_LABEL_FORMAT, encoding, prop->label);
+
+  uim_helper_send_message(helper_fd, buf);
+
+
+  free(buf);
+
+#undef PROP_LABEL_FORMAT
+
+}

Added: trunk/emacs/prop.h
===================================================================
--- trunk/emacs/prop.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/prop.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,68 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_prop_h_included_
+#define _uim_agent_prop_h_included_
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <uim/uim.h>
+#include <uim/uim-helper.h>
+
+#include "debug.h"
+#include "output.h"
+
+#include "im.h"
+#include "helper-server.h"
+
+/* keep only prop_list (prpo_label is buggy...)  */
+typedef struct property {
+  int list_update;
+  int label_update;
+  char *list;
+  char *label;
+} property;
+
+void update_prop_list(property *prop, const char *str);
+void update_prop_label(property *prop, const char *str);
+
+void announce_prop_list_update(property *prop, const char *encoding);
+void announce_prop_label_update(property *prop, const char *encoding);
+
+void output_prop_list(property *prop, const char *im);
+
+
+#endif

Added: trunk/emacs/uim-candidate.el
===================================================================
--- trunk/emacs/uim-candidate.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-candidate.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,601 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+;;
+;; Checks that the candidate list can be displayed inlinely on current window.
+;;
+(defun uim-check-candidate-space ()
+  ;; don't show the candidate in mini-buffer
+  ;; also thin window is not supported
+  (and (= (minibuffer-depth) 0)
+       (>= (window-width) uim-candidate-minimum-width)))
+
+
+;; 
+;; Merge formatted text into current buffer
+;;
+(defun uim-merge-candidate ()
+
+  (let ((maxwidth (string-width (nth 1 (car uim-candidate-line-list))))
+	offset mark-base mark-cursor)
+
+    ;; format page label
+    (setq uim-candidate-page-label
+	  (concat (make-string (- maxwidth 
+				  (- (string-width uim-candidate-page-label) 1))
+			       (if uim-candidate-display-frame ?- 32))
+		  uim-candidate-page-label))
+
+
+    (goto-char uim-candidate-start)
+
+    ;; mark current-point
+    (setq mark-base (point-marker))
+    (uim-debug (format "before: %s" (marker-position mark-base)))
+
+    ;; save original string
+    (setq uim-candidate-original-str
+	  (buffer-substring uim-candidate-original-start
+			    uim-candidate-original-end))
+
+
+    (if (and uim-preedit-cursor 
+	     (> uim-preedit-cursor (point-min)))
+	(save-excursion
+	  (goto-char uim-preedit-cursor)
+	  (setq mark-cursor (point-marker))))
+
+    ;; set overlay for chasing
+
+    ;; remove tabs/spaces
+    (uim-tab-pad-space uim-candidate-original-start
+		       uim-candidate-original-end)
+
+ 
+    ;; update uim-candidate-start
+    (let (base-ofs)
+      (setq base-ofs (- (marker-position mark-base) uim-candidate-start))
+      (setq uim-candidate-start (+ uim-candidate-start base-ofs)))
+
+    (uim-debug (format "after: %s" (marker-position mark-base)))
+
+    (set-marker mark-base nil)
+
+    (goto-char uim-candidate-start)
+
+    (save-excursion
+      (uim-vertical-motion 0)
+      (setq offset 
+	    (uim-string-width (buffer-substring (point) uim-candidate-start))))
+
+    (uim-debug (format "offset: %s" offset))
+
+    ;; if offset + maxwidth >= window-width then reduce offset
+    (if (>= (+ offset maxwidth 2) (window-width))
+	(setq offset (- (- (window-width) 1) 
+			(+ maxwidth 2))))
+
+
+    (save-excursion
+      (if uim-show-candidate-upward
+	  (uim-vertical-motion (- (+ (length uim-candidate-line-list) 1)))
+	(uim-vertical-motion uim-candidate-vofs))
+
+      (let ((rest t)
+	    mergecount vhead linetmp padding overflow)
+	
+	(save-excursion
+	  (setq mergecount (uim-vertical-motion 
+			       (+ (length uim-candidate-line-list) 1))))
+
+
+	(while rest
+	  (let (candidx candstr candsel)
+	    (if uim-candidate-line-list
+		(progn
+		  ;; normal candidate line
+		  (setq candidx (nth 0 (car uim-candidate-line-list)))
+		  (setq candstr 
+			(uim-format-string (nth 1 (car uim-candidate-line-list))
+					   maxwidth))
+		  (setq candsel (nth 2 (car uim-candidate-line-list)))
+
+		  (setq candstr
+			(if uim-candidate-display-frame
+			    (if candsel
+				(concat ">" candstr "<")
+			      (concat "|" candstr "|"))
+			  (if candsel
+			      (concat "[" candstr "]")
+			    (concat " " candstr " "))))
+		  )
+	      ;; page label
+	      (setq candidx 0)
+
+	      (setq candstr
+		    (if uim-candidate-display-frame
+			(concat "+" uim-candidate-page-label )
+		      (concat " " uim-candidate-page-label )))
+	      (setq candsel nil)
+	      )
+
+	    (if (> mergecount 0)
+		(progn
+		  ;; go virtual head of the next line
+		  (if (not uim-show-candidate-upward)
+		      (uim-vertical-motion 1))
+
+		  (setq vhead (point))
+
+		  ;; make new line
+		  (save-excursion
+
+		    (end-of-line)
+		    
+		    ;; |ABCDEFGH\ + |___aaa__|
+		    ;; |IJKLMN  |
+		    ;;
+		    ;; get region from vhead to physical end
+		    ;;
+		    ;; linetmp = ABCDEFGH
+		    ;; 
+		    (setq linetmp 
+			  (truncate-string-to-width (buffer-substring vhead (point))
+						    (window-width)))
+
+		    ;; make padding by truncating linetmp to offset size
+		    ;;  (add space as padding if shortage)
+		    ;;   witdth of padding is equal to offset
+		    ;; 
+		    ;; padding = ABC
+		    ;;
+		    (setq padding
+			  (truncate-string-to-width linetmp offset nil 32))
+		      
+		    ;;  overflow = GH
+		    ;;
+		    (let ((candwidth (+ maxwidth 2)))
+
+		      (if (>= (uim-string-width linetmp) (+ offset candwidth))
+			  (setq overflow 
+				(truncate-string-to-width linetmp 
+							  (uim-string-width linetmp)
+							  (+ offset candwidth) 32))
+			(setq overflow "")))
+
+		    ;; index string selected appendix
+		    (save-excursion
+		      (goto-char vhead)
+		      (delete-region vhead (+ vhead (length linetmp)))
+			
+		      (insert (concat padding 
+				      candstr
+				      overflow)))
+		
+		    (uim-set-candidate-face candidx candsel 
+					    (+ vhead (length padding))
+					    (length candstr))
+
+
+		    ;; update merge-end
+		    (save-excursion
+		      (end-of-line)
+		      (setq uim-candidate-end (point)))
+	      
+		    (setq mergecount (- mergecount 1))
+		    )
+
+		  (if uim-show-candidate-upward
+		  (uim-vertical-motion 1))
+		    
+		  )
+	      ;; append 
+	      (let (vhead)
+
+		(goto-char (point-max))
+
+		(setq vhead (+ (point) 1))
+
+		(insert (concat "\n"
+				(make-string offset 32)
+				candstr))
+
+		(uim-set-candidate-face candidx candsel 
+					(+ vhead offset)
+					(length candstr))
+
+		(save-excursion
+		  (end-of-line)
+		  (setq uim-candidate-end (point))))))
+	    
+	  (if uim-candidate-line-list
+	      (setq uim-candidate-line-list
+		    (cdr uim-candidate-line-list))
+	    (setq rest nil))
+
+	  )
+	
+	;; move to end of preedit
+	(if uim-show-candidate-upward
+	    (save-excursion
+	      (end-of-line)
+	      (setq uim-candidate-end (point))))
+
+	(force-mode-line-update)
+
+	;; update cursor position
+	(when mark-cursor
+	  
+	  (goto-char (marker-position mark-cursor))
+	  (setq uim-preedit-cursor (point))
+
+	  (set-marker mark-cursor nil)
+	  )
+	))
+    ))
+
+
+
+(defun uim-echo-candidate (cand)
+
+  ;; display candidate in minibuffer 
+
+  (let ((cands "")
+	(selstart 0)
+	(selend 0)
+	(page-current (format "%d" (caar cand)))
+	(page-total (format "%d" (cdar cand)))
+	)
+
+    (setq cand (cdr cand))
+
+
+    (mapcar 
+     '(lambda (x)
+	(let ((selected (nth 0 x))
+	      (candlabel (nth 1 x))
+	      (candstr (nth 2 x)))
+
+	  (if selected
+	      (setq selstart (length cands)))
+
+	  (setq cands
+		(if selected
+		    (concat cands "[" candlabel "." candstr "]")
+		  (concat cands " "  candlabel "." candstr " ")))
+
+	  (if selected
+	      (setq selend (length cands)))
+
+	  )
+	) cand)
+
+    
+    (if (and uim-emacs
+	     (>= emacs-major-version 21))
+	;; Emcas-21 or Emacs-22
+	(let ((page-space (- (string-width page-total) 
+			     (string-width page-current)))
+	      message-log-max)
+	  (setq cands 
+		(concat (if (> page-space 0) (make-string page-space 32))
+			page-current  "/" page-total " " cands))
+	  (message cands)
+	  )
+      ;; Emacs-20 or XEmacs
+      (let* ((page-width (+ (string-width uim-candidate-page-label) 2))
+	     (cands-width (string-width cands))
+	     (echoreg-width (- (- (window-width) 1) page-width)))
+	(if (>= echoreg-width cands-width)
+	    (setq cands
+		  (concat cands
+			  (make-string (- echoreg-width cands-width) 32)
+			  "(" uim-candidate-page-label ")"))
+	  (if (> (string-width (substring cands 0 selend))
+		 (+ (- cands-width echoreg-width) 3))
+	      (setq cands
+		    (concat "..."
+			    (truncate-string-to-width cands
+						      cands-width 
+						      (+ (- cands-width echoreg-width) 3))
+			    "(" uim-candidate-page-label ")"))
+	    (setq cands 
+		  (concat "..."
+			  (truncate-string-to-width (substring cands (- selend 1))
+						    (if (> echoreg-width 6)
+							(- echoreg-width 6)
+						      0))
+			  "..."
+			  "(" uim-candidate-page-label ")")))))
+      
+      (let (message-log-max)
+	(message cands))
+      )
+    
+    )
+  )
+
+
+;;
+;; Make candidate list to be displayed
+(defun uim-make-candlist (cand) 
+  ;; cand: (( <nil|t> "candlabel"  "candstr" ) ... )
+
+  (let* ((i 1)
+	 (truncwidth (min (- (window-width) 3)
+			  (max (+ uim-max-candlabel uim-max-candstr 1)
+			       (- (string-width uim-candidate-page-label) 1))))
+	 (candlist '()))
+
+    (mapcar 
+     '(lambda (x)
+	(let ((selected (nth 0 x))
+	      (candlabel (nth 1 x))
+	      (candstr (nth 2 x)))
+
+	  ;; separate appendix (for prime...)
+	  (if (string-match "\t" candstr)
+	      (setq candstr (substring candstr (match-end 0))))
+
+	  (setq candlabel 
+		(concat (make-string (- uim-max-candlabel 
+					(string-width candlabel)) 32)
+			candlabel))
+
+	  (setq candstr (concat candlabel "." candstr))
+	
+	  (catch 'truncate-loop
+	    (let (candlabelpad)
+	      (while t
+		(let* ((trunc (truncate-string-to-width candstr
+						      truncwidth nil))
+		       (width-truncated (string-width trunc))
+		       )
+		
+		  (setq candlist 
+			(append candlist 
+				(list 
+				 (list i (concat trunc 
+						 (make-string (- truncwidth
+								 width-truncated)
+							      32))
+				       selected))))
+
+		  (if (= width-truncated (string-width candstr))
+		      (throw 'truncate-loop t))
+
+		  (if (not candlabelpad)
+		      (setq candlabelpad
+			    (make-string (+ (string-width candlabel) 1) 32)))
+
+		  (setq candstr
+			(concat candlabelpad
+				(truncate-string-to-width candstr
+							  (string-width candstr)
+							  width-truncated)))
+		  ))))
+	  )
+	(setq i (+ i 1))
+	) cand)
+
+    (setq uim-candidate-line-list candlist)
+    )
+  )
+  
+
+
+;;
+;; Put overlay
+;;
+(defun uim-set-candidate-face (index selected begin length)
+  (let (face ol)
+    (cond 
+     (selected
+      (setq face 'uim-candidate-selected-face))
+     ((= index 0)
+      (setq face 'uim-candidate-nth-face))
+     ((= (% index 2) 1)
+      (setq face 'uim-candidate-odd-face))
+     ((= (% index 2) 0)
+      (setq face 'uim-candidate-even-face)))
+
+    (put-text-property begin (+ begin length) 'face face)
+
+    ))
+
+
+
+
+(defun uim-check-overlay (head tail)
+  (if (> head (point-min))
+      (setq head (- head 1)))
+
+  (if (< tail (point-max))
+      (setq tail (+ tail 1)))
+  
+  (overlays-in  head tail))
+
+
+;;
+;; Insert candidate string
+;;
+(defun uim-show-candidate (candidate)
+
+  (setq uim-max-candlabel 
+	(eval (cons 'max 
+		    (mapcar '(lambda (x) (string-width (nth 1 x)))
+			    (cdr candidate)))))
+
+  ;; get max width 
+  (setq uim-max-candstr 
+	(eval (cons 'max 
+		    (mapcar '(lambda (x) (string-width (nth 2 x)))
+			    (cdr candidate)))))
+
+  (setq uim-candidate-page-label 
+	(format "%d/%d" (caar candidate) (cdar candidate)))
+
+  (setq uim-candidate-original-start nil)
+  (setq uim-candidate-original-end nil)
+
+  (let ((display-inline uim-candidate-display-inline))
+
+    (if (>= (max (+ uim-max-candlabel 6) 
+		 (+ (string-width uim-candidate-page-label) 2))
+	    (window-width))
+	(progn
+	  (setq display-inline nil)
+	  (uim-debug "disable inline: window is too thin")
+	  ))
+
+
+    (if display-inline
+	(uim-make-candlist (cdr candidate)))
+  
+
+    (if display-inline
+	(save-excursion
+	  (goto-char uim-candidate-start)
+
+	  (let ((winofs (uim-get-window-offset))
+		(candlines (+ 1 (length uim-candidate-line-list)))
+		ol-down dhead dtail uhead utail)
+	    
+	    (if (and (not (setq ol-down (uim-check-overlay
+					 (save-excursion
+					   (beginning-of-line)
+					   (setq dhead (point)))
+					 (save-excursion
+					   (uim-vertical-motion 
+					    (+ uim-candidate-vofs 
+					       candlines))
+					   (end-of-line)
+					   (setq dtail(point))))))
+		     (>= (- (- (window-height) 1) (+ winofs 1)) 
+			 candlines))
+
+		(progn
+		  (setq uim-show-candidate-upward nil)
+		  (setq uim-candidate-original-start dhead)
+		  (setq uim-candidate-original-end dtail)
+		  )
+
+	      (if (and (>= winofs candlines)
+		       (not (uim-check-overlay
+			     (save-excursion
+			       (uim-vertical-motion (- candlines))
+			       (beginning-of-line)
+			       (setq uhead (point)))
+			     (save-excursion
+			       (end-of-line)
+			       (setq utail (point)))))
+		       )
+		  (progn
+		    (setq uim-show-candidate-upward t)
+		    (setq uim-candidate-original-start uhead)
+		    (setq uim-candidate-original-end utail)
+		    )
+		
+		;; scroll anyway
+		(if (not ol-down)
+		    (let* ((fspace (- (- (- (window-height) 1) winofs) 1))
+			   (vshift (- candlines fspace)))
+		      (setq uim-show-candidate-upward nil)
+		      (setq uim-window-force-scrolled t)
+
+		      (setq uim-candidate-original-start dhead)
+		      (setq uim-candidate-original-end dtail)
+
+		      (if (> vshift winofs)
+			  (recenter 0)
+			(save-excursion 
+			  ;;(uim-debug (format "vshift %s" vshift))
+			  (uim-vertical-motion (- (- (window-height)
+						     candlines 2)))
+			  (recenter 0))))
+		  ;; disable inline display
+		  (setq display-inline nil)
+		  
+		  ;;(uim-debug (format "ol-down %s" ol-down))
+		  
+		  ))))))
+
+    (if (not display-inline)
+	(uim-debug "disable inline"))
+
+
+    (if display-inline
+	;; inline candidate display mode
+	(let ((inhibit-read-only t))
+	  (uim-merge-candidate))
+      ;; display in echo region
+      (uim-echo-candidate candidate)
+      )
+    )
+  )
+
+;;
+;; Remove candidate
+;;
+(defun uim-remove-candidate ()
+  (if (and uim-candidate-display-inline
+	   uim-candidate-original-start)
+      (let ((inhibit-read-only t))
+
+	;; delete region which includes candidate
+	(delete-region uim-candidate-original-start 
+		       uim-candidate-end)
+
+	;; restore original region
+	(save-excursion
+	  (goto-char uim-candidate-original-start)
+	  (insert uim-candidate-original-str))
+
+	;; delete overlay
+	;;(mapcar 'delete-overlay uim-candidate-overlays)
+	;;(setq uim-candidate-overlays nil)
+
+	)
+
+    ;; clear minibuffer
+    (let (message-log-max)
+      (message nil))
+   
+    )
+  
+  )
+
+
+(provide 'uim-candidate)

Added: trunk/emacs/uim-debug.el
===================================================================
--- trunk/emacs/uim-debug.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-debug.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,80 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+(defvar uim-debug-enable nil) 
+(defvar uim-debug-buffer nil)
+(defconst uim-debug-buffer-name "uim-debug")
+
+(defvar uim-timestamp-list nil)
+
+(defun uim-debug (msg)
+  (if uim-debug-enable
+      (progn
+	(if (not uim-debug-buffer)
+	    (setq uim-debug-buffer (get-buffer-create uim-debug-buffer-name)))
+	(save-current-buffer
+	  (set-buffer uim-debug-buffer)
+	  (goto-char 0)
+	  (insert msg)
+	  (insert "\n")))))
+
+(defun uim-timestamp (name)
+  (setq uim-timestamp-list (append uim-timestamp-list
+				   (list (list (current-time) name)))))
+
+(defun uim-reset-timestamp ()
+  (setq uim-timestamp-list nil))
+
+(defun uim-show-timestamp ()
+  (let (sec1 sec2 microsec current (start 0))
+    (while uim-timestamp-list
+      (setq sec1 (nth 0 (caar uim-timestamp-list)))
+      (setq sec2 (nth 1 (caar uim-timestamp-list)))
+      (setq microsec (nth 2 (caar uim-timestamp-list)))
+      (setq current (+ (* (+ (lsh sec1 16) sec2) 1000) (/ microsec 1000)))
+
+      (if (= start 0)
+	  (setq start current))
+
+      (uim-debug (format "%5d :%s (%d)"
+			 (- current start)
+			 (car (cdar uim-timestamp-list))
+			 (memory-limit)
+			 ))
+
+      (setq uim-timestamp-list (cdr uim-timestamp-list)))))
+
+(provide 'uim-debug)
+

Added: trunk/emacs/uim-el-agent.c
===================================================================
--- trunk/emacs/uim-el-agent.c	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-el-agent.c	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,751 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <locale.h>
+
+#include <sys/select.h>
+
+#include <uim/uim.h>
+#include <uim/uim-helper.h>
+#include <uim/uim-util.h>
+#include <uim/uim-im-switcher.h>
+
+#include "uim-el-agent.h"
+
+
+static int
+cmd_release(int context_id)
+{
+  if (release_uim_agent_context(context_id) < 0)
+	return -1;
+  else
+	return 1;
+}
+
+
+static int
+cmd_unfocused(int context_id)
+{
+  int ret;
+  uim_agent_context *ua;
+
+  /* if context_id is 0, 
+	 this function unfocuses from current focused context 
+	 otherwise,
+	 compare current focused context and unfocuses if they are matching.
+  */
+
+  if (current != NULL) {
+	ua = current;
+	if (context_id != 0 && get_uim_agent_context(context_id) != current)
+	  ret = -1;
+	else
+	  ret = unfocused();
+  } else {
+	/* already unfocused */
+	if ((ua = get_uim_agent_context(context_id)))
+	  ret = context_id;
+	else
+	  ret = -1;
+  }
+	
+  if (ret > 0)
+	if (context_id != 0) {
+	  show_preedit(ua->pe);
+	  return 1;
+	} else {
+	  return 1;
+	}
+
+  else
+	return -1;
+}
+
+
+static int
+cmd_focused(int context_id)
+{
+  uim_agent_context *ua = get_uim_agent_context(context_id);
+
+  if (focused(ua) > 0) {
+	if (show_preedit(ua->pe))
+	  show_candidate(ua->pe->cand);
+	return 1;
+  } else {
+	return -1;
+  }
+
+}
+
+static int
+cmd_hide(int context_id)
+{
+  uim_agent_context *ua = get_uim_agent_context(context_id);
+
+  if (ua != NULL)
+	return 1;
+  else
+	return -1;
+}
+
+static int
+cmd_show(int context_id)
+{
+  uim_agent_context *ua = get_uim_agent_context(context_id);
+  
+  if (ua != NULL) {
+	if (show_preedit(ua->pe))
+	  show_candidate(ua->pe->cand);
+	return 1;
+  } else {
+	return -1;
+  }
+}
+
+
+static int
+cmd_new(int context_id, const char *encoding)
+{
+  if (get_uim_agent_context(context_id)) {
+	debug_printf(DEBUG_WARNING, "context %d already exists\n", context_id);
+	return -1;
+  } else {
+	if (new_uim_agent_context(context_id, encoding) != NULL)
+	  return 1;
+	else
+	  return -1;
+  }
+}
+
+
+static int
+cmd_reset(int context_id)
+{
+  /* reset current context */
+  uim_agent_context *ua = get_uim_agent_context(context_id);
+
+  if (ua != NULL) {
+	/* before reset, clear preedit and candidate */
+	clear_preedit(ua->pe);
+	clear_candidate(ua->pe->cand);
+	uim_reset_context(ua->context);
+	return 1;
+  } else {
+	return -1;
+  }
+}
+
+
+static int
+cmd_change(int context_id, const char *im, const char *encoding)
+{
+  uim_agent_context *ua;
+
+  if (im && encoding && strlen(im) > 0 
+	  && (ua = get_uim_agent_context(context_id))) {
+
+	focused(ua);
+
+	if (check_im_name(im)) {
+	  switch_context_im(ua, im, encoding);
+	  return 1;
+	} else {
+	  return -1;	 
+ 	}
+  } else {
+	return -1;
+  }
+}
+
+
+static int
+cmd_list(void)
+{
+  if (list_im_engine() > 0)
+	return 1;
+  else
+	return -1;
+}
+
+
+static int
+cmd_setenc(const char *im, const char *encoding)
+{
+  if (set_im_encoding(im, encoding) > 0)
+	return 1;
+  else
+	return -1;
+}
+
+static int
+cmd_getenc(const char *im)
+{
+  const char *encoding = get_im_encoding(im);
+
+  if (encoding)
+	a_printf(" ( E \"%s\" ) ", encoding);
+  else
+	a_printf(" ( E \"\" ) ");
+
+  return 1;
+}
+
+
+static int
+cmd_prop(int context_id, const char *prop)
+{
+  uim_agent_context *ua;
+
+  if (prop && strlen(prop) > 0 &&
+	  (ua = get_uim_agent_context(context_id))) {
+	uim_prop_activate(ua->context, prop);
+	return 1;
+  } else {
+	return -1;
+  }
+}
+
+
+static int
+cmd_error(void)
+{
+  return -1;
+}
+
+
+static void
+check_default_engine(void)
+{
+  if (default_engine_updated) {
+	output_default_im_engine();
+	default_engine_updated = 0;
+  }
+}
+
+
+static void
+check_prop(void)
+{
+  if (current == NULL) return;
+
+  if (current->prop->list_update) {
+	announce_prop_list_update(current->prop, current->encoding);
+	output_prop_list(current->prop, current->im);
+	current->prop->list_update = 0;
+  }
+
+  if (current->prop->label_update) {
+	announce_prop_label_update(current->prop, current->encoding);
+	current->prop->label_update = 0;
+  }
+}
+
+
+static int
+process_command(int serial, int cid, char *cmd)
+{
+  char *opt, *opt2;
+  int ret;
+
+  if ((opt = strchr(cmd, ' '))) {
+	*opt = '\0';
+	opt ++;
+	if ((opt2 = strchr(opt, ' '))) {
+	  *opt2 = '\0';
+	  opt2 ++;
+	} else {
+	  opt2 = NULL;
+	}
+  } else {
+	opt = NULL;
+	opt2 = NULL;
+  }
+
+  if (strcmp(cmd, "RELEASE") == 0)
+	ret = cmd_release(cid);
+  else if (strcmp(cmd, "UNFOCUSED") == 0)
+	ret = cmd_unfocused(cid);
+  else if (strcmp(cmd, "FOCUSED") == 0)
+	ret = cmd_focused(cid);
+  else if (strcmp(cmd, "HIDE") == 0)
+	ret = cmd_hide(cid);
+  else if (strcmp(cmd, "SHOW") == 0)
+	ret = cmd_show(cid);
+  else if (strcmp(cmd, "NEW") == 0)
+  	ret = cmd_new(cid, opt);
+  else if (strcmp(cmd, "RESET") == 0)
+	ret = cmd_reset(cid);
+  else if (strcmp(cmd, "CHANGE") == 0)
+  	ret = cmd_change(cid, opt, opt2);
+  else if (strcmp(cmd, "LIST") == 0)
+  	ret = cmd_list();
+  else if (strcmp(cmd, "SETENC") == 0)
+  	ret = cmd_setenc(opt, opt2);
+  else if (strcmp(cmd, "GETENC") == 0)
+  	ret = cmd_getenc(opt); /* for debug */
+  else if (strcmp(cmd, "PROP") == 0)
+  	ret = cmd_prop(cid, opt);
+  else
+	ret = cmd_error();
+
+  check_prop();
+
+  check_default_engine();
+
+  return ret;
+}
+
+
+static int
+analyze_keyvector(char *vector, uim_key *ukey, char *keyname)
+{
+  char *p1, *p2, *c;
+  int key;
+
+  p1 = vector + 1;
+
+  if (strstr(p1, "mouse-")) {
+	debug_printf(DEBUG_NOTE, "mouse event\n");
+	return 1;
+  }
+
+  /* check space */
+  if ((p2 = strchr(vector, ' '))) {
+	/* if there is a space, 1st string must be 27 */
+	key = strtol(p1, &c, 10);
+	if (c != p2 || key != 27) {
+	  debug_printf(DEBUG_WARNING, "1st key is not 27\n");
+	  return -1;
+	} else {
+	  ukey->mod |= UMod_Alt;
+	}
+	p1 = p2 + 1; 
+  }
+
+  if (*p1 == ']') {
+	debug_printf(DEBUG_WARNING, "invalid key vector\n");
+	return -1;
+  }
+
+  key = strtol(p1, &c, 10);
+
+  if (*c == ']') {
+	/* all of rest characters are digit */
+	if (key & (1<<27)) ukey->mod |= UMod_Alt;
+	/* if(key & (1<<27)) mod |= UMod_Meta; */
+	if (key & (1<<26)) ukey->mod |= UMod_Control;
+	if (key & (1<<25)) ukey->mod |= UMod_Shift;
+	if (key & (1<<24)) ukey->mod |= UMod_Hyper;
+	if (key & (1<<23)) ukey->mod |= UMod_Super;
+	if (key & (1<<22)) ukey->mod |= UMod_Alt;
+
+	ukey->key = key & 0xff;
+
+	if (ukey->key == 27) {
+	  ukey->key = UKey_Escape;
+	} else if (ukey->key <= 26) {
+	  ukey->mod |= UMod_Control;
+	  if (ukey->key == 0)
+		ukey->key = 32;
+	  else
+		ukey->key += 96;
+	} else if (ukey->key >= 0x41 && ukey->key <= 0x5a) {
+	  ukey->mod |= UMod_Shift;
+	}
+  } else {
+	/* contains non digit characters */
+	while (1) {
+	  if (*(p1 + 1) == '-') {
+		switch (*p1) {
+		case 'S':
+		  ukey->mod |= UMod_Shift;
+		  break;
+		case 'C':
+		  ukey->mod |= UMod_Control;
+		  break;
+		case 'A':
+		  ukey->mod |= UMod_Alt;
+		  break;
+		case 'M':
+		  /* mod |= UMod_Meta; */
+		  ukey->mod |= UMod_Alt;
+		  break;
+		case 's':
+		  ukey->mod |= UMod_Super;
+		  break;
+		case 'H':
+		  ukey->mod |= UMod_Hyper;
+		  break;
+		case 'X':
+		  /* dummy; */
+		  break;
+		default:
+		  return -1;
+		  break;
+		}
+		p1 += 2;
+	  } else {
+		if ((p2 = strrchr(p1, ']')) == NULL || p1 == p2) {
+		  /* [C-] [C-M-] */
+		  debug_printf(DEBUG_WARNING, "invalid key vector\n");
+		  return -1;
+		} else {
+		  *p2 = '\0';
+
+		  if (strlen(p1) == 1) {
+			/* single character [C-a] [C-1] */
+			ukey->key = *p1;
+		  } else {
+			/* [C-next] [C-M-end] */
+			if (*p1 >= 'A' && *p1 <= 'Z')
+			  /* if the first character is upper case, 
+				 it can be considered as XEmacs style abbrev */
+			  convert_keyname_a2e(keyname, p1);
+			else
+			  strcpy(keyname, p1);
+
+			ukey->key = convert_keyname_e2u(keyname);
+		  }
+
+		  break;
+		}
+	  }
+	}
+  }
+
+  if (ukey->key < 0) return -1;
+  
+  return 1;
+}
+
+
+static int
+process_keyvector(int serial, int cid, uim_key ukey, const char *keyname)
+{
+  int ret;
+
+  if (current == NULL || 
+	  (current != NULL && current->context_id != cid)) {
+
+	if (focused(get_uim_agent_context(cid)) < 0) {
+	  debug_printf(DEBUG_WARNING, "context %d not found\n", cid);
+	  return -1;
+	}
+  }
+
+
+  if (ukey.key >= 0) {
+	/* key input is received by requested context */
+	ret = uim_press_key(current->context, ukey.key, ukey.mod);
+	uim_release_key(current->context , ukey.key, ukey.mod);
+
+	if (ret > 0) {
+	  /* uim did not process the key */
+
+	  if (current->pe->head == NULL || current->pe->length == 0) {
+		/* no preedit */
+
+		if (ukey.mod & UMod_Shift && ukey.key >= 0x41 && ukey.key <= 0x5a)
+		  ukey.mod &= ~UMod_Shift;
+
+		if (ukey.mod != 0 || ukey.key > 255) {
+
+		  a_printf(" ( n [(");
+
+		  if (ukey.mod & UMod_Control) a_printf("control ");
+		  if (ukey.mod & UMod_Alt) a_printf("meta ");
+		  /* if (ukey->mod & UMod_Shift) a_printf("shift "); */
+		  if (ukey.mod & UMod_Hyper) a_printf("hyper ");
+		  if (ukey.mod & UMod_Super) a_printf("super ");
+
+		  if (ukey.key > 255)
+			a_printf("%s", keyname);
+		  else
+			a_printf("%d", ukey.key);
+
+		  a_printf(")] ) ");
+
+		} else {
+		  a_printf(" ( n [%d] ) ", ukey.key);
+		}
+
+	  } else {
+		/* discard the key if preedit exists */
+		show_preedit(current->pe);
+		show_candidate(current->pe->cand);
+		/* a_printf(" ( n ) "); */
+	  }
+			
+	} else {
+	  /* key has been processed by uim */
+	  show_preedit(current->pe);
+	  show_candidate(current->pe->cand);
+	}
+  } else {
+	/* ukey.key < 0 */
+	show_preedit(current->pe);
+	show_candidate(current->pe->cand);
+	a_printf(" ( n ) ");
+  }
+
+  check_prop();
+
+  check_default_engine();
+
+  return 1;
+}
+
+
+
+static void
+wait_until_data_arrival(fd_set *rfds)
+{
+  int fdmax = STDIN_FILENO;
+
+  if (helper_fd > 0) {
+	FD_ZERO(rfds);
+	FD_SET(helper_fd, rfds);
+	if (helper_fd > fdmax) fdmax = helper_fd;
+  }
+
+  FD_SET(STDIN_FILENO, rfds);
+  
+  if (select(fdmax + 1, rfds, NULL, NULL, NULL) < 0) {
+	debug_printf(DEBUG_ERROR, "select error\n");
+  }
+}
+
+
+static int
+take_one_line_from_buffer(char *buf, char *input)
+{
+  char *p = strchr(buf, '\n'); 
+  int rest; 
+
+  if (!p) {
+	debug_printf(DEBUG_ERROR, "something wrong occured\n");
+	return 0;
+  }
+
+  *p = '\0';
+  strcpy(input, buf);
+
+  rest = strlen(p + 1);
+  memmove(buf, (p + 1), rest);
+
+  return rest;
+}
+
+/*
+static int
+uim_agent_init(void)
+{
+  init_default_engine();
+  return 1;
+}
+*/
+
+
+int
+main(int argc, char *argv[])
+{
+  int opt;
+
+  while ((opt = getopt(argc, argv, "d")) != -1) {
+	switch (opt) {
+	case 'd':
+	  debug_level ++;
+	  break;
+	}
+  }
+
+  if (debug_level == 0) fclose(stderr);
+
+  if (uim_init() < 0) {
+	debug_printf(DEBUG_ERROR, "uim_init failed\n");
+	return -1;
+  }
+
+  /*  uim_agent_init();*/
+
+  a_printf("OK\n");
+
+  while (1) {
+	int cid, serial;
+	char *p1, *p2, *c;
+	int offset = 0, more_input = 0;
+	char input[256], buf[256], keyname[32];
+	uim_key ukey;
+	fd_set rfds;
+
+	fflush(stdout);
+
+	buf[sizeof(buf) - 1] = '\0';
+
+	if (!more_input) {
+	  check_helper_connection();   /* keep helper connection */
+
+	  wait_until_data_arrival(&rfds);
+
+	  if (FD_ISSET(STDIN_FILENO, &rfds)) {
+		/* read from STDIN if input data exists  */
+		read(STDIN_FILENO, buf + offset, sizeof(buf) - offset - 1);
+	  } else if (FD_ISSET(helper_fd, &rfds)) {
+		/* process helper message only when no input data */
+		output_enable = 0;
+		helper_handler();
+		output_enable = 1;
+	  }
+	}
+
+	if ((p1 = strchr(buf, '\n'))) {
+	  offset = take_one_line_from_buffer(buf, input);
+	  more_input = strchr(buf, '\n') ? 1 : 0;
+	} else {
+	  /* wait \n */
+	  offset = strlen(buf);
+	  more_input = 0;
+	  continue;
+	}
+
+	p1 = input;
+	serial = -1;
+
+	/*
+	  command format 
+	    serial CID COMMAND OPTION
+
+	  key format
+	    serial CID [keyvector]
+	*/
+
+	if ((p2 = strchr(p1, ' ')) == NULL) {
+	  debug_printf(DEBUG_WARNING, "input error: space after 1st string\n");
+	  goto ERROR;
+	}
+
+	/* 1st string must be digit */
+	*p2 = '\0';
+	serial = strtol(p1, &c, 10);
+	if (c != p2) {
+	  debug_printf(DEBUG_WARNING, "input error: invalid serial %d\n", serial);
+	  goto ERROR;
+	}
+
+	p1 = p2 + 1;
+	if ((p2 = strchr(p1, ' ')) == NULL) {
+	  debug_printf(DEBUG_WARNING, "input error: no space after 2nd string\n");
+	  goto ERROR;
+	}
+
+	/* 2nd string must be digit */
+	*p2 = '\0';
+	cid = strtol(p1, &c, 10);
+	if (c != p2) {
+	  debug_printf(DEBUG_WARNING, "invalid cid %d\n", cid);
+	  goto ERROR;
+	}
+
+	/* 3rd string */
+	p1 = p2 + 1;
+
+	if (*p1 == '[') {
+	  /* keyvector if 3rd string starts with [  */
+
+	  if ((p2 = strchr(p1, ']')) == NULL) {
+		/* no corresponding ]  */
+		debug_printf(DEBUG_WARNING, "']' not found\n");
+		goto ERROR;
+	  }
+
+	  p2 ++; 
+	  if (*p2 == ']') p2 ++; /* for [X-]] */
+	  *p2 = '\0';   /* replace character after ] with \0  */
+
+	  ukey.mod = 0;
+	  ukey.key = -1;
+	  keyname[0] = '\0';
+
+
+	  if (analyze_keyvector(p1, &ukey, keyname) > 0) {
+
+	  	a_printf("( %d %d ", serial, cid);
+		if (process_keyvector(serial, cid, ukey, keyname) < 0)
+		  a_printf(" ( f ) ");
+		else
+		  a_printf(" ( a ) ");
+
+		a_printf(" )\n");
+
+		continue;
+	  }
+
+	  goto ERROR;
+
+
+	} else if (*p1 >= 'A' && *p1 <= 'Z') {
+	  /* command */
+
+	  a_printf("( %d %d ", serial, cid);
+	  if (process_command(serial, cid, p1) < 0) {
+		debug_printf(DEBUG_WARNING, "command error\n");
+		a_printf(" ( f ) ");   /* command error */
+	  } else {
+		a_printf(" ( a ) ");   /* command ok */
+	  }
+
+  a_printf(" )\n");
+
+	  continue;
+	}
+  
+	debug_printf(DEBUG_WARNING, "invalid input\n");
+	
+  ERROR:
+	a_printf("( %d 0 ( x ) )\n", serial);
+  }
+
+
+  uim_quit();
+  return 0;
+}
+

Added: trunk/emacs/uim-el-agent.h
===================================================================
--- trunk/emacs/uim-el-agent.h	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-el-agent.h	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,77 @@
+/*
+  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, are permitted provided that the
+  following conditions are met:
+
+  1. Redistributions of source code must retain the above
+     copyright notice, this list of conditions and the
+     following disclaimer.
+  2. Redistributions in binary form must reproduce the above
+     copyright notice, this list of conditions and the
+     following disclaimer in the documentation and/or other
+     materials provided with the distribution.
+  3. Neither the name of authors nor the names of its
+     contributors may be used to endorse or promote products
+     derived from this software without specific prior written
+     permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef _uim_agent_h_included_
+#define _uim_agent_h_included_
+
+#include "debug.h"
+#include "output.h"
+#include "candidate.h"
+#include "preedit.h"
+#include "context.h"
+#include "encoding.h"
+#include "im.h"
+#include "key.h"
+#include "helper.h"
+#include "callback.h"
+#include "prop.h"
+
+static int cmd_release(int context_id);
+static int cmd_unfocused(int context_id);
+static int cmd_focused(int context_id);
+static int cmd_hide(int context_id);
+static int cmd_show(int context_id);
+static int cmd_new(int context_id, const char *encoding);
+static int cmd_reset(int context_id);
+static int cmd_change(int context_id, const char *im, const char *encoding);
+static int cmd_list(void);
+static int cmd_setenc(const char *im, const char *encoding);
+static int cmd_prop(int context_id, const char *prop);
+static int cmd_error(void);
+
+static void check_prop(void);
+static void check_default_engine(void);
+
+static int process_command(int serial, int cid, char *cmd);
+static int process_keyvector(int serial, int cid,
+							 uim_key ukey, const char *keyname);
+static int analyze_keyvector(char *vector, uim_key *ukey, char *keyname);
+static void wait_until_data_arrival(fd_set *rfds);
+static int take_one_line_from_buffer(char *buf, char *input);
+
+
+/*static int uim_agent_init(void);*/
+
+#endif

Added: trunk/emacs/uim-key.el
===================================================================
--- trunk/emacs/uim-key.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-key.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,599 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+
+;; 
+;; this-command-keys wrapper 
+;;
+(defun uim-this-command-keys-vector ()
+  (if uim-xemacs
+      (this-command-keys)
+    (this-command-keys-vector)))
+
+
+;;
+;; translate XEmacs style key name
+;;
+(defun uim-translate-xemacs-keyname (keyname)
+  (cond ((string= keyname "BS")  "backspace")
+	((string= keyname "TAB") "tab")
+	((string= keyname "LFD") "linefeed")
+	((string= keyname "RET") "return")
+	((string= keyname "ESC") "escape")
+	((string= keyname "DEL") "delete")
+	((string= keyname "SPC") "space")
+	(t keyname)))
+
+
+;; 
+;; Get last one stroke from keyvector
+;;
+(defun uim-last-onestroke-key (keyvec)
+  (let ((len (length keyvec)))
+    (cond ((= len 1)
+ 	   keyvec 
+	   )
+ 	  ((>= len 2)
+ 	   (let ( (last2 (aref keyvec (- len 2)) )
+ 		  (last (aref keyvec (- len 1)) ) )
+ 	     (if (eq last2 27)
+ 		 (vector last2 last)
+ 	       (vector last)))))))
+
+
+;;
+;; Convert keyname 
+;; 
+(defun uim-replace-keyvec-with-functionkeymap (keyvec)
+  (let ((keys kyevec))
+    (while keys
+      (let ((mapto (assq (car keys) function-key-map)))
+	(if mapto
+	    (setcar keys mapto)))))
+  keyvec)
+
+
+;;
+;; Get original key-mapped function
+;;
+(defun uim-getbind (keyvec)
+  (let (bind 
+	(mode uim-mode))
+    (unwind-protect
+	(progn
+	  (setq uim-mode nil)
+
+	  (setq bind (key-binding (vector (aref keyvec 0))))
+
+	  (if (not (memq bind (list 'universal-argument 
+				    'digit-argument 
+				    'negative-argument)))
+	      (setq bind (key-binding keyvec)))
+	  )
+      (setq uim-mode mode))
+    bind
+    ))
+
+
+;;
+;; Stop combining
+;;
+(defun uim-flush-concat-undo ()
+  (setq uim-undo-stacking nil)
+  (undo-boundary)
+  )
+
+
+;;
+;; Combine continuous self-insert-commands
+;; 
+(defun uim-concat-undo ()
+
+  (if (and (listp buffer-undo-list)
+	   (>= (length buffer-undo-list) 2))
+      (if (not uim-undo-stacking)
+	  (setq uim-undo-stacking t)
+	(let (recent previous)
+	  (setq recent (nth 0 buffer-undo-list))
+	  (setq previous (nth 2 buffer-undo-list))
+
+	  (if (and (consp recent) (consp previous)
+		   (not (nth 1 buffer-undo-list))
+		   (= (car recent) (cdr previous)))
+	      (let ((left (car previous))
+		    (right (cdr recent)))
+		(if (and (integerp left) (integerp right)
+			 (<= (- right left) 20))
+		    (progn
+		      (setcar buffer-undo-list (cons left right))
+		      (setcdr buffer-undo-list (cdr (cddr buffer-undo-list)))
+		      )
+		  )
+		))))
+    (setq uim-undo-stacking nil))
+  (undo-boundary) 
+  )
+
+
+(defun uim-command-execute (keyvec)
+  (let ((mode uim-mode))
+    (unwind-protect
+	(progn
+	  (setq uim-mode nil)
+	  (command-execute keyvec))
+      (setq uim-mode mode))))
+
+
+(defun uim-blink-match (char)
+
+  (when 
+      (= ?\) (char-syntax char))
+    (blink-matching-open))
+  )
+
+
+(defun uim-process-mouse-event (event)
+  (cond (uim-emacs
+	 (let* ((mouse-event (car event))
+		(bind (uim-getbind (vector mouse-event))))
+	   (if (commandp bind)
+	       (call-interactively bind nil (vector event))
+	     (if (not (memq 'down (event-modifiers mouse-event)))
+		 (undefined)))))
+	(uim-xemacs
+	 (let* ((bind (uim-getbind (vector event))))
+	   (if (commandp bind)
+	       (call-interactively bind nil (vector event))))))
+  )
+
+
+;;
+;; Process the key vector returned from Uim.
+;; 
+(defun uim-process-keyvec (keyvec &optional count)
+  (let ((bind (uim-getbind keyvec))
+	keyvectmp)
+
+    (if uim-emacs
+	;; for transient-mark-mode
+	(setq deactivate-mark nil))
+    
+    (cond ((or (keymapp bind)
+	       (and (not bind)
+		    (setq keyvectmp (uim-remove-shift keyvec))
+		    (setq keyvec keyvectmp)))
+
+	   (if uim-xemacs
+	       (progn
+		 (setq uim-retry-keys keyvec)
+		 (setq unread-command-events
+		       (cons (aref keyvec 0) unread-command-events))))
+
+	   (if uim-emacs
+	       (progn
+		 (setq uim-retry-keys keyvec)
+		 (setq unread-command-events
+		       (nconc (listify-key-sequence keyvec)
+			      unread-command-events))))
+	   )
+	  (count
+	   (setq prefix-arg count)
+	   (uim-command-execute
+	    (uim-getbind (uim-last-onestroke-key keyvec)))
+	   )
+
+	  ((commandp bind)
+	   (if (eq bind 'self-insert-command)
+	       (progn
+		 (setq this-command bind)
+		 (call-interactively bind)
+		 (uim-concat-undo))
+	     (setq this-command bind)
+	     (command-execute bind) 
+	     (uim-flush-concat-undo)
+	     ))
+	  (t
+	   (uim-flush-concat-undo)
+	   (if uim-xemacs
+	       (error 'undefined-keystroke-sequence 
+		      (uim-xemacs-make-event 
+		       (uim-convert-char-to-symbolvector 
+			(key-description keyvec))))
+	     (undefined))
+	   )
+	  )
+
+    (if uim-emacs
+	(setq uim-deactivate-mark deactivate-mark))
+    )
+  )
+
+
+
+
+(defun uim-xemacs-restore-menubar ()
+  (if uim-menubar-temp
+      (progn
+	(setq current-menubar uim-menubar-temp)
+	(setq uim-menubar-temp nil)
+	)
+    )
+  )
+
+(defun uim-xemacs-save-menubar ()
+  (if (not uim-menubar-temp)
+      (progn
+	(setq uim-menubar-temp current-menubar)
+	(setq current-menubar (mapcar '(lambda (x)
+				     (if x
+					 (list (car x) ["" nil :active nil])
+				       nil))
+				  current-menubar))
+	))
+  )
+
+
+
+;;
+;; convert keyvec to event for XEmacs
+;;
+(defun uim-xemacs-make-event (keyvec)
+  (let* (button 
+	 event
+	 (keylist-tmp (aref keyvec 0))
+	 (keylist (if (listp keylist-tmp) keylist-tmp
+		    (list keylist-tmp)))
+	 (lastkey (nth (- (length keylist) 1) keylist)))
+    (cond ((setq button
+		 (assoc lastkey
+			'((button1 . 1) (button2 . 2) (button3 . 3))))
+	   ;; mouse press
+	   (delq lastkey keylist)
+	   (setq event 
+		 (make-event 'button-press 
+			     (list 'button (cdr button) 'modifiers keylist)))
+	   )
+	  ((setq button
+		 (assoc lastkey
+			'((button1up . 1) (button2up . 2) (button3up . 3))))
+	   ;; mouse up
+	   (delq lastkey keylist)
+	   (setq event 
+		 (make-event 'button-release
+			     (list 'button (cdr button) 'modifiers keylist)))
+	   )
+	  (t
+	   ;; key
+	   (setq keylist (nbutlast keylist))
+	   (setq event 
+		 (make-event 'key-press (list 'key lastkey 'modifiers keylist)))
+	   )
+	  )
+    event))
+
+;;
+;; convert XEmacs style key sequence to symbol list
+;;
+(defun uim-convert-char-to-symbolvector (keychar)
+  (let (symbol-vector keys ofs)
+    (while keychar
+      (if (setq ofs (string-match " " keychar))
+	  (progn
+	    (setq keys (substring keychar 0 ofs))
+	    (setq keychar (substring keychar (+ ofs 1))))
+	(setq keys keychar)
+	(setq keychar nil))
+
+      (let (symbol-list)
+	(progn
+	  (while (string-match "^\\(C\\|M\\|S\\|H\\|A\\|Sh\\)-" keys)
+	    (let ((mod (match-string 0 keys)))
+	      (cond ((string= mod "C-")
+		     (setq symbol-list (cons 'control symbol-list)))
+		    ((string= mod "M-")
+		     (setq symbol-list (cons 'meta symbol-list)))
+		    ((string= mod "S-")
+		     (setq symbol-list (cons 'super symbol-list)))
+		    ((string= mod "H-")
+		     (setq symbol-list (cons 'hyper symbol-list)))
+		    ((string= mod "A-")
+		     (setq symbol-list (cons 'alt symbol-list)))
+		    ((string= mod "Sh-")
+		     (setq symbol-list (cons 'shift symbol-list)))))
+	    (setq keys (substring keys (match-end 0))))
+
+	  (setq keys (uim-translate-xemacs-keyname keys))
+
+
+	  (setq symbol-list 
+		(append symbol-list (list 
+				     (if (= (length keys) 1)
+					 (string-to-char keys)
+				       (read keys)))))
+	  )
+	(setq symbol-vector (vconcat symbol-vector (vector symbol-list)))
+	))
+    symbol-vector
+    ))
+
+
+
+
+;;
+;; remove Shift modifier from key vector
+;;
+(defun uim-remove-shift (keyvec)
+  (cond (uim-emacs
+	 (let ((keyval (aref keyvec 0)))
+	   (if (and (integerp keyval)
+		    (/= (logand (lsh 1 25) keyval) 0))
+	       (setq keyvec (vector (logand (lognot (lsh 1 25)) keyval)))
+	     (let ((keystr (format "%s" keyval)))
+	       (if (string-match "S-" keystr)
+		   (setq keyvec 
+			 (vector (read 
+				  (replace-match "" nil nil keystr))))
+		 (setq keyvec nil))))))
+	(uim-xemacs
+	 (let ((keystr (key-description keyvec)))
+	   (if (string-match "Sh-" keystr)
+	       (setq keyvec 
+		     (vector (uim-xemacs-make-event 
+			      (uim-convert-char-to-symbolvector 
+			       (replace-match "" nil nil keystr)))))
+	     (setq keyvec nil))))
+	(t 
+	 (setq keyvec nil))
+	)
+  keyvec
+  )
+
+
+;;
+;; convert XEmacs style key sequence to FSF key vector
+;;
+(defun uim-convert-keystr-to-uimagent-vector (keystr)
+  (let (symbol-vector keys ofs)
+    (while keystr
+      (if (setq ofs (string-match " " keystr))
+	  (progn
+	    (setq keys (substring keystr 0 ofs))
+	    (setq keystr (substring keystr (+ ofs 1))))
+	(setq keys keystr)
+	(setq keystr nil))
+
+      (let (symbol-str 
+	    (symbol-val 0))
+	(progn
+	  (while (string-match "^\\(C\\|M\\|S\\|H\\|A\\|Sh\\)-" keys)
+	    (let ((mod (match-string 0 keys)))
+	      (cond ((string= mod "C-")
+		     (setq symbol-val (+ symbol-val (lsh 1 26)))
+		     (setq symbol-str (concat "C-" symbol-str)))
+		    ((string= mod "M-")
+		     (setq symbol-val (+ symbol-val (lsh 1 27)))
+		     (setq symbol-str (concat "M-" symbol-str)))
+		    ((string= mod "S-") 
+		     ;; super
+		     (setq symbol-val (+ symbol-val (lsh 1 23)))
+		     (setq symbol-str (concat "s-" symbol-str)))
+		    ((string= mod "H-")
+		     (setq symbol-val (+ symbol-val (lsh 1 24)))
+		     (setq symbol-str (concat "H-" symbol-str)))
+		    ((string= mod "A-")
+		     (setq symbol-val (+ symbol-val (lsh 1 22)))
+		     (setq symbol-str (concat "A-" symbol-str)))
+		    ((string= mod "Sh-")
+		     ;; shift
+		     (setq symbol-val (+ symbol-val (lsh 1 25)))
+		     (setq symbol-str (concat "S-" symbol-str)))))
+
+	    (setq keys (substring keys (match-end 0))))
+
+	  (setq keys (uim-translate-xemacs-keyname keys))
+
+	  (if (= (length keys) 1)
+	      (if (not symbol-str)
+		  (setq symbol-str (format "%d" (string-to-char keys)))
+		(setq symbol-str (format "%d" (+ symbol-val
+						 (string-to-char keys)))))
+	    (setq symbol-str (concat symbol-str keys)))
+
+	  (setq symbol-vector (vconcat symbol-vector 
+				       (vector (read symbol-str))))
+	  )))
+    symbol-vector
+    ))
+
+
+(defun uim-is-single-escape (keyvec)
+  (cond (uim-emacs
+	 (or (equal keyvec [27])
+	     (equal keyvec [escape])))
+	(uim-xemacs
+	 (or (equal keyvec (vector (uim-xemacs-make-event [escape])))
+	     (and (eq (global-key-binding keyvec) esc-map)
+		  (keymapp (uim-getbind keyvec)))))
+	))
+	 
+
+(defun uim-is-start-with-escape (keyvec)
+;  (uim-debug (format "uim-is-start-width-escape: %s" keyvec))
+  (cond (uim-emacs
+	 (uim-is-single-escape (vector (aref keyvec 0))))
+	(uim-xemacs
+	 (or (memq 'meta (aref (uim-convert-char-to-symbolvector (key-description keyvec)) 0))
+	     (uim-is-single-escape (vector (aref keyvec 0)))))))
+
+
+(defun uim-is-escape (keyvec)
+;  (uim-debug (format "uim-is-escape %s" keyvec))
+  (cond (uim-emacs
+	 (if (or window-system
+		 (and (not window-system) uim-use-single-escape-on-terminal))
+	     (uim-is-single-escape keyvec)
+	   (equal keyvec [27 27]))
+	 )
+	(uim-xemacs
+	 (if (or window-system
+		 (and (not window-system) uim-use-single-escape-on-terminal))
+	     (uim-is-single-escape keyvec)
+	   (or (equal keyvec (make-vector 2 (uim-xemacs-make-event [(escape)])))
+	       (equal keyvec (vector (uim-xemacs-make-event (uim-convert-char-to-symbolvector "M-ESC"))))
+	       )
+	   )
+	 )
+	)
+  )
+
+
+;;
+;; get this-command-keys with symbol lists vector
+;; 
+(defun uim-this-command-keys ()
+  (let (keyvec replace-continue)
+
+    (if uim-xemacs
+	(setq keyvec (this-command-keys)))
+
+    (if uim-emacs
+	(setq keyvec (this-command-keys-vector)))
+
+    (if (or (not keyvec)
+	    (and (vectorp keyvec)
+		 (= (length keyvec) 0)))
+	(setq keyvec uim-retry-keys))
+
+;    (uim-debug (format "keyvec %s" keyvec))
+
+    (let* ((newvec (vconcat uim-stacked-key-vector keyvec))
+	   (keylist (append newvec nil))
+	   prefix
+	   replace)
+      (catch 'replace-loop
+	(while keylist
+	  (when (or (not prefix)
+		    (keymapp (uim-getbind prefix)))
+	    (setq replace (uim-lookup-function-key-map (vconcat keylist)))
+	    (cond ((vectorp replace)
+		   (setq uim-stacked-key-vector (vconcat prefix replace))
+		   (throw 'replace-loop nil))
+		  ((keymapp replace)
+		   (setq replace-continue t)
+		   (setq uim-stacked-key-vector newvec)
+		   (throw 'replace-loop nil)
+		   )))
+	  (setq prefix (vconcat prefix (vector (car keylist))))
+	  (setq keylist (cdr keylist))
+	  )
+	;; cannot be replaced
+	(setq uim-stacked-key-vector newvec)))
+
+    
+    (when (and uim-xemacs
+	       (>= (length uim-stacked-key-vector) 2)
+	       (equal (aref uim-stacked-key-vector 0) 
+		      (uim-xemacs-make-event [(escape)])))
+      ;; append meta
+      (setq uim-stacked-key-vector
+	    (vector
+	     (uim-xemacs-make-event
+	      (vector 
+	       (cons 'meta 
+		     (aref (uim-convert-char-to-symbolvector
+			    (key-description (vconcat
+					      (cdr (append 
+						    uim-stacked-key-vector
+						    nil)))))
+			   0))
+	       )))))
+
+    ;;(uim-debug (format "stacked-key-vector: %s" uim-stacked-key-vector))
+
+    (cond ((and uim-preedit-displayed
+		(uim-is-escape uim-stacked-key-vector)) ;; preedit ESC-ESC
+	   (uim-debug "Escape")
+	   ;; stop waiting and return ESC key
+	   (if uim-emacs
+	       (setq keyvec [27]))
+	   (if uim-xemacs
+	       (setq keyvec (vector (uim-xemacs-make-event [escape]))))
+	   (setq uim-stacked-key-vector nil)
+	   )
+	  ((or (and uim-preedit-displayed ;; with preedit
+		    (and replace-continue ;; wait ESC- key vector
+			 (uim-is-start-with-escape uim-stacked-key-vector)))
+	       (and (not uim-preedit-displayed) ;; without preedit
+		    (or replace-continue ;; wait all
+			(keymapp (uim-getbind uim-stacked-key-vector)))))
+	   ;; wait next
+	   (uim-debug "wait next")
+	   (setq keyvec nil))
+	  (t
+	   ;; return keys
+	   (setq keyvec uim-stacked-key-vector)
+	   (setq uim-stacked-key-vector nil)))
+	
+    ;; convert keyvector with key-translation-map
+    (if keyvec
+	(let ((transvec (lookup-key key-translation-map keyvec)))
+	  (if (vectorp transvec)
+	      (setq keyvec transvec))))
+
+    keyvec
+    )
+  )
+
+
+
+(defun uim-lookup-function-key-map (keyvec)
+  (let ((keylist (append keyvec nil))
+	(ret nil)
+	vec)
+    (catch 'fkmap-loop
+      (while keylist
+	(setq vec (vconcat vec (vector (car keylist))))
+	(if (commandp (uim-getbind vec))
+	    (throw 'fkmap-loop nil)
+	    )
+	(setq keylist (cdr keylist)))
+      (setq ret (lookup-key function-key-map keyvec))
+      )
+    ret))
+
+
+
+(provide 'uim-key)
+

Added: trunk/emacs/uim-keymap.el
===================================================================
--- trunk/emacs/uim-keymap.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-keymap.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,270 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+;;
+;; Mouse event for GNU Emacs
+;;
+(defconst uim-mouse-modifiers
+  '(
+    ()     
+    (down)   
+    (drag)
+    (double)  
+    (double down)  
+    (double drag)
+    (triple)  
+    (triple down)  
+    (triple drag)
+    ))
+
+
+(defconst uim-emacs-prefix-keys
+  '(help-command
+    2C-command
+    Control-X-prefix
+    mode-specific-command-prefix
+    ctl-x-4-prefix
+    ctl-x-5-prefix
+    vc-prefix-map
+    facemenu-keymap
+    ))
+
+
+(defun uim-mouse-set-point (event)
+  (interactive "e")
+  (mouse-minibuffer-check event)
+  (let ((posn (event-end event)))
+    (when (windowp (posn-window posn))
+      (select-window (posn-window posn))
+      )))
+
+;;
+;; Bind all mouse event to nil (for GNU Emacs)
+;; 
+(defun uim-unbind-mouse-event ()
+  (let ((mouse-modifiers uim-mouse-modifiers))
+    (while mouse-modifiers
+      (let ((mouse '(mouse-1 mouse-2 mouse-3)))
+	(while mouse
+	  (let ((event (vector (append (car mouse-modifiers)
+				       (list (car mouse))))))
+
+	    (define-key uim-mode-map event nil)
+	    (define-key uim-preedit-map event nil)
+	    )
+
+	  (setq mouse (cdr mouse))))
+      (setq mouse-modifiers (cdr mouse-modifiers))))
+  
+  (define-key uim-mode-map [vertical-scroll-bar] nil)
+  (define-key uim-mode-map [mode-line] nil)
+  (define-key uim-mode-map [vertical-line] nil)
+  (define-key uim-mode-map [menu-bar] nil)
+  (define-key uim-mode-map [tool-bar] nil)
+
+  (define-key uim-mode-map [mouse-movement] nil)
+  (define-key uim-mode-map [scroll-bar-movement] nil)
+  (define-key uim-mode-map [switch-frame] nil)
+  (define-key uim-mode-map [delete-frame] nil)
+  (define-key uim-mode-map [iconify-frame] nil)
+  (define-key uim-mode-map [make-frame-visible] nil)
+  
+
+  ;; for uim-preedit-map
+  ;;  menu-bar/tool-bar operation must be avoided
+  (define-key uim-preedit-map [vertical-scroll-bar] 'ignore)
+  (define-key uim-preedit-map [mode-line] nil)
+  (define-key uim-preedit-map [vertical-line] nil) 
+  (define-key uim-preedit-map [menu-bar] 'ignore) 
+  (define-key uim-preedit-map [tool-bar] 'ignore) 
+
+  (define-key uim-preedit-map [mouse-movement] nil)
+  (define-key uim-preedit-map [scroll-bar-movement] nil)
+  (define-key uim-preedit-map [switch-frame] nil)
+  (define-key uim-preedit-map [delete-frame] nil)
+  (define-key uim-preedit-map [iconify-frame] nil)
+  (define-key uim-preedit-map [make-frame-visible] nil)
+
+  )
+		  
+
+
+;;
+;; Initialize keymap
+;; 
+(defun uim-init-keymap ()
+
+  (setq uim-mode-map (make-sparse-keymap))
+  (setq uim-preedit-map (make-sparse-keymap))
+
+
+  ;; copy special keys
+  (let ((prefixs uim-emacs-prefix-keys))
+    (while prefixs
+      (let ((prefix-keys (where-is-internal (car prefixs))))
+	(while prefix-keys
+	  (define-key uim-mode-map (car prefix-keys) (car prefixs))
+	  (setq prefix-keys (cdr prefix-keys))))
+      (setq prefixs (cdr prefixs))))
+
+  
+  (define-prefix-command 'uim-escape-map)
+
+  ;; set default key-binds
+  (cond (uim-xemacs ;; XEmacs
+	 (set-keymap-default-binding uim-mode-map 'uim-process-input)
+	 (set-keymap-default-binding uim-preedit-map 'uim-process-input)
+	 (define-key uim-mode-map [escape] 'uim-process-input)
+	 (define-key uim-mode-map [(control ?\[)] 'uim-process-input)
+	 )
+
+	((and uim-emacs (= emacs-major-version 20)) ;;; GNU Emacs-20.7
+	 (define-key uim-mode-map [t] 'uim-process-input)
+	 (define-key uim-preedit-map [t] 'uim-process-input)
+
+	 (define-key uim-escape-map [t] 'uim-process-input)
+	 (define-key uim-mode-map [27] 'uim-escape-map)
+	 (define-key uim-preedit-map [27] 'uim-escape-map)
+
+	 (define-key uim-mode-map [escape] nil)
+
+	 )
+
+	((and uim-emacs (= emacs-major-version 21)) ;;; GNU Emacs-21.x 
+	 (define-key uim-mode-map (vector t) 'uim-process-input)
+	 (define-key uim-preedit-map (vector t) 'uim-process-input)
+
+	 (define-key uim-mode-map [escape] nil)
+	 )
+
+	((and uim-emacs (= emacs-major-version 22)) ;;; GNU Emacs-22.x
+	 (define-key uim-mode-map [t] 'uim-process-input)
+	 (define-key uim-preedit-map [t] 'uim-process-input)
+
+	 (define-key uim-escape-map [t] 'uim-process-input)
+	 (define-key uim-mode-map [27] 'uim-escape-map)
+	 (define-key uim-preedit-map [27] 'uim-escape-map)
+	 )
+
+	)
+
+
+  (when uim-emacs
+    (uim-unbind-mouse-event)
+    )
+
+  (when uim-xemacs
+    (setq uim-toolbar-map (make-sparse-keymap))
+    (set-keymap-default-binding uim-toolbar-map 'ignore)
+    )
+  
+  )
+
+
+;;
+;; Switch keymap
+;;
+(defun uim-enable-mode-keymap ()
+  (setcdr (assq 'uim-mode minor-mode-map-alist) 
+	  uim-mode-map))
+
+(defun uim-disable-mode-keymap ()
+  (setcdr (assq 'uim-mode minor-mode-map-alist) 
+	  nil))
+
+(defun uim-enable-preedit-keymap ()
+  (setcdr (assq 'uim-mode minor-mode-map-alist) 
+	  uim-preedit-map) 
+
+  (when (not uim-minor-mode-map-alist)
+    (setq uim-minor-mode-map-alist minor-mode-map-alist)
+    (setq minor-mode-map-alist (list (assq 'uim-mode minor-mode-map-alist)))
+
+    (when (and uim-emacs (= emacs-major-version 22)) 
+      (setq uim-emulation-mode-map-alists emulation-mode-map-alists)
+      (setq emulation-mode-map-alists nil)))
+
+  (when uim-xemacs
+    (make-variable-buffer-local 'toolbar-map)
+    (setq toolbar-map uim-toolbar-map)
+    (uim-xemacs-save-menubar)
+    )
+
+  )
+
+(defun uim-disable-preedit-keymap ()
+
+  (when uim-minor-mode-map-alist
+    (setq minor-mode-map-alist uim-minor-mode-map-alist)
+    (setq uim-minor-mode-map-alist nil)
+
+    (when (and uim-emacs (= emacs-major-version 22)) 
+      (setq emulation-mode-map-alists uim-emulation-mode-map-alists)
+      (setq uim-emulation-mode-map-alists nil)))
+
+  (uim-enable-mode-keymap)
+
+  (when uim-xemacs
+    (kill-local-variable 'toolbar-map)
+    (uim-xemacs-restore-menubar)
+    )
+  )
+
+
+;;
+;; Copy toggle key to uim-mode-map
+;;
+(defun uim-copy-toggle-key (key)
+  (let ((toggle-key-list (where-is-internal key global-map)))
+    (while toggle-key-list
+      (if (not (eq (lookup-key uim-mode-map (car toggle-key-list)) key))
+	  (define-key uim-mode-map (car toggle-key-list) key))
+      (setq toggle-key-list (cdr toggle-key-list)))))
+
+
+(defun uim-reset-keymap ()
+  (uim-init-keymap)
+  (run-hooks 'uim-reset-keymap-hook))
+
+(defun uim-disable-single-escape-on-terminal ()
+  )
+
+(defun uim-enable-single-escape-on-terminal ()
+
+  )
+
+(provide 'uim-keymap)
+
+

Added: trunk/emacs/uim-leim.el
===================================================================
--- trunk/emacs/uim-leim.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-leim.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,147 @@
+;;
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+(require 'uim)
+
+;; alist of LEIM style IM names and its Uim style IM names
+;;  ( japanese-anthy-uim . anthy )
+(defvar uim-leim-inputmethod-alist '())
+
+;; LEIM status
+(uim-deflocalvar uim-leim-active nil)
+
+
+;; Inactivate function
+(defun uim-leim-inactivate ()
+  (setq uim-leim-active nil)
+  (uim-mode-off))
+
+(defadvice toggle-input-method (around uim-toggle-input-method-around activate)
+  (if buffer-read-only
+      (not (message "uim.el: This buffer is read-only."))
+    ad-do-it))
+
+;; Activate function (callback?)
+;;  all Uim related LEIM input methods call this function at activation time
+(defun uim-leim-activate (&optional name)
+
+  ;; copy toggle-input-method bindings to uim-mode-map
+  (uim-update-keybind)
+
+  (let (im)
+    ;; register inactivation function
+    (setq inactivate-current-input-method-function 'uim-leim-inactivate)
+
+    ;; get plain IM engine name from LEIM style name
+    ;;  ex. "Japanese-anthy-uim" => "anthy"
+    (setq im (cdr (assoc name uim-leim-inputmethod-alist)))
+
+    (when (uim-mode-on)
+      ;; switch IM after Uim activation
+      (if (not (equal im uim-current-im-engine))
+	  (uim-change-im im))
+
+      (setq uim-leim-active t))))
+
+
+(defun uim-leim-reset ()
+  (when uim-leim-active
+    (message "uim.el: uim-leim-reset")
+    (inactivate-input-method)))
+
+
+(defun uim-leim-make-im-name (im)
+  (let (lang)
+    (setq lang (downcase (uim-get-emacs-lang im)))
+    (concat lang "-" im "-uim")))
+
+
+(defun uim-leim-init ()
+  ;; register IM to input-method-alist
+  ;;   to display the alist, call list-input-methods
+  (let ((im-list (cdr uim-im-list)) lang name im)
+    (while im-list
+      (setq name (caar im-list))
+      (setq lang (cdr (assoc 'emacs-lang (cdar im-list))))
+
+      (when (and name lang)
+	(setq im (uim-leim-make-im-name name))
+	(register-input-method im lang 'uim-leim-activate "[Uim]"
+			       (concat "Uim " name))
+
+	;; ( japanese-anthy-uim . anthy )
+	(setq uim-leim-inputmethod-alist 
+	      (cons (cons im name) uim-leim-inputmethod-alist)))
+      (setq im-list (cdr im-list))))
+
+  (add-hook 'uim-update-default-engine-hook 
+	    (lambda ()
+	      (if (boundp 'default-input-method)
+		  (setq default-input-method
+			(uim-leim-make-im-name
+			 uim-context-default-im-engine)))))
+
+  (add-hook 'uim-update-current-engine-hook 
+	    (lambda ()
+	      (if (and (boundp 'current-input-method)
+		       current-input-method)
+		  (setq current-input-method
+			(uim-leim-make-im-name uim-current-im-engine)))))
+
+  (add-hook 'uim-force-inactivate-hook
+	    (lambda ()
+	      (when uim-leim-active
+		(message "uim.el: LEIM inactivated"
+			 (inactivate-input-method)))))
+
+  (add-hook 'uim-buffer-init-hook 
+	    (lambda ()
+	      (add-hook 'change-major-mode-hook
+			'inactivate-input-method nil t)))
+	       
+  )
+
+
+;; Overwrite
+(defun uim-im-switch (&optional im)
+  (interactive)
+  (message "uim.el: use \"M-x set-input-method\" when using LEIM"))
+
+(defun uim-update-keybind ()
+  (uim-copy-toggle-key 'toggle-input-method))
+
+(uim-leim-init)
+  
+(provide 'uim-leim)

Added: trunk/emacs/uim-preedit.el
===================================================================
--- trunk/emacs/uim-preedit.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-preedit.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,157 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+;;
+;; Insert preedit
+;;
+(defun uim-insert-preedit (preedit)
+
+  (when uim-preedit-display-fences
+    (setq preedit (append (cons '(t "|") preedit) '((t "|")))))
+
+  (setq uim-preedit-cursor nil)
+
+  ;; disregard read-only temporarily
+  (let ((inhibit-read-only t))
+
+    (save-excursion
+      (setq uim-candidate-start nil)
+;;      (setq uim-candidate-vofs 0)
+      
+      (let ((preedit-blocks preedit) block-start-point)
+
+	(setq uim-preedit-start (point))
+
+	(mapcar
+	 '(lambda (x)
+	    (let (cand-start-cand
+		  (preedit-flag (format "%s" (car x)))
+		  (preedit-str (car (cdr x))))
+
+	      ;; save point for candidate displaying before insertion
+	      ;;  i.e. head of the block
+	      (if (string-match "c" preedit-flag)
+		  (progn
+		    (if (> (length preedit-str) 0)
+			(setq uim-candidate-start (point))
+		      ;; workaround for uim-prime 
+		      (setq uim-candidate-start block-start-point))))
+	    
+	      (setq block-start-point (point))
+
+	      (when (> (length preedit-str) 0)
+
+		(insert preedit-str)
+
+		(let ((face (cond
+			     ((string-match "s" preedit-flag)
+			      'uim-separator-face)
+			     ((string-match "u" preedit-flag)
+			      'uim-preedit-underline-face)
+			     ((string-match "ru" preedit-flag)
+			      'uim-preedit-highlight-underline-face)
+			     ((string-match "r" preedit-flag)
+			      'uim-preedit-highlight-face)
+			     (t 
+			      'uim-preedit-face))))
+
+		  (put-text-property block-start-point (point) 'face face)
+
+		  (if (overlays-in block-start-point (point))
+		      (let (ol)
+			(setq ol (make-overlay block-start-point (point)))
+			(overlay-put ol 'face face)
+			(overlay-put ol 'priority 10)
+			(setq uim-preedit-overlays 
+			      (cons ol uim-preedit-overlays))))
+		  )
+		)
+	      
+
+	      ;; save point for cursor displaying after insertion
+	      (if (string-match "c" preedit-flag)
+		  (setq uim-preedit-cursor (point)))
+
+	      ;; update preedit-end
+	      (setq uim-preedit-end (point))
+
+	      ))
+	 preedit-blocks)
+	)
+      )
+
+    ;; if "c" flag not found in preedit 
+    (if (not uim-candidate-start)
+	(progn
+	  (setq uim-candidate-start uim-preedit-start)
+	  (if (not uim-preedit-cursor)
+	      (setq uim-preedit-cursor uim-preedit-end))))
+
+    ;; set vertical offset
+    (setq uim-candidate-vofs 
+	  (uim-vertical-distance uim-candidate-start uim-preedit-cursor))
+    )
+
+  (setq uim-buffer-read-only buffer-read-only)
+  (setq buffer-read-only t)
+
+  )
+
+
+
+;; Remove preedit
+(defun uim-remove-preedit ()
+
+  (goto-char uim-preedit-start)
+
+  (if uim-preedit-overlays
+      (progn
+	(mapcar 'delete-overlay uim-preedit-overlays)
+	(setq uim-preedit-overlays nil)))
+
+  (let ((inhibit-read-only t))
+
+    (save-excursion
+      ;; remove preedit string
+      (delete-region uim-preedit-start uim-preedit-end))
+  
+    )
+
+  (setq buffer-read-only uim-buffer-read-only)
+  )
+
+
+(provide 'uim-preedit)
+

Added: trunk/emacs/uim-util.el
===================================================================
--- trunk/emacs/uim-util.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-util.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,301 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+;; 
+;; Get vertical distance from beginning-of-line of the target point
+;; to the line of target.
+;;
+(defun uim-relative-vertical-count (target)
+  (let (base (i 1))
+    (save-excursion
+      (goto-char target)
+      (beginning-of-line)
+      (setq base (point))
+      (catch 'rv-loop
+	(while t 
+	  (goto-char base)
+	  ;; move i lines from beginning-of-line
+	  (when (> i (vertical-motion i))
+	      ;; reach end-of-buffer 
+	    (setq i (- i 1))
+	    (throw 'rv-loop t))
+	  (when (= (point) target)
+	      ;; reach the target point
+	    (throw 'rv-loop t))
+	  (when (> (point) target)
+	      ;; over the target point
+	    (setq i (- i 1))
+	    (throw 'rv-loop t))
+	  (setq i (+ i 1)))))
+    i ;; vertical distance
+    ))
+
+
+;;
+;; Get vertical distance from start to end.
+;;  Two points should be in the same line
+;;
+(defun uim-vertical-distance (start end)
+  (let (dist1 dist2)
+    (setq dist1 (uim-relative-vertical-count start))
+    (setq dist2 (uim-relative-vertical-count end))
+    (- dist2 dist1)))
+
+
+;; 
+;; My vertical-motion
+;;   workaround to avoid Emacs-21.x vertical-motion bug
+;;
+(defun uim-vertical-motion-exec (n)
+  (let (start (i 1))
+    (setq start (point))
+    ;; get distance from physical line head
+    (setq i (uim-relative-vertical-count start))
+    (beginning-of-line)
+    (- (vertical-motion (+ i n)) i)
+    ))
+
+;;
+;; My vertical-motion wrapper
+;;
+(defun uim-vertical-motion (n)
+  (if (and (string< "21" emacs-version)
+	   (or (string< emacs-version "21.3.1")
+	       (string= emacs-version "21.3.1")
+	       (string= emacs-version "21.4.1")))
+      (uim-vertical-motion-exec n)
+    (vertical-motion n)))
+
+;;
+;; Fill blank at right edge of the window with white pace
+;;   The blank appears when a double-width character is
+;;   inserted into the last one-character-space of the
+;;   screen-line. (Emacs-21.x with X11 only?)
+;; 
+(defun uim-pad-space (start end)
+  (let (strtmp pad (cnt 0) wwidth)
+    (if (and uim-emacs
+             window-system
+             (>= emacs-major-version 21))
+        (setq wwidth (window-width))
+      (setq wwidth (- (window-width) 1)))
+
+    (save-excursion
+      (while (> (uim-string-width (setq strtmp (buffer-substring start end)))
+                wwidth)
+        (setq strtmp (truncate-string-to-width strtmp wwidth))
+        (setq pad (- wwidth (uim-string-width strtmp)))
+        (setq cnt (+ cnt pad))
+        (goto-char (+ start (length strtmp)))
+	(insert-before-markers (make-string pad 32))
+        (setq start (point))
+        (setq end (+ end pad))
+        ))
+    cnt))
+
+
+
+;;
+;; Replace tabs to the same width white spaces.
+;;
+(defun uim-replace-tab (start end)
+;  (uim-debug (format "uim-replace-tab %s %s" start end))
+  (let (tpos (cnt 0) (ofs 0) tabwidth)
+    (save-excursion
+      (goto-char start)
+      (while (setq tpos (search-forward "\t" end 1))
+
+	(if uim-emacs
+	    (setq ofs (string-width (buffer-substring start (- tpos 1)))))
+	(if uim-xemacs
+	    (save-excursion
+	      (goto-char (- tpos 1))
+	      (vertical-motion 0)
+	      (setq ofs (string-width (buffer-substring (point) (- tpos 1))))))
+
+	(setq tabwidth (- tab-width (% ofs tab-width)))
+	(setq cnt (- (+ cnt tabwidth) 1))
+	(goto-char (- tpos 1))
+	;;(insert-and-inherit (make-string tabwidth 32))
+	(insert (make-string tabwidth 32))
+	(delete-char 1)
+	(setq end (+ end tabwidth (- 1) ))
+	))
+    cnt)) 
+
+
+
+;;
+;; Replace tabs and spaces.
+;;
+(defun uim-tab-pad-space (start end)
+  (let (org lstart lend (endorg end) tabspace)
+    (setq org (point))
+    (save-excursion
+      (goto-char start)
+      (catch 'line-loop
+        (while (< (point) end)
+          (setq lstart (point))
+          (save-excursion
+            (end-of-line)
+            (if (> (point) end)
+                (setq lend end)
+              (setq lend (point))))
+          (setq tabspace (uim-replace-tab lstart lend))
+          (setq end (+ end tabspace ))
+          (setq lend (+ lend tabspace))
+          (setq end (+ end (uim-pad-space lstart lend)))
+          ;; fix lstart
+          (end-of-line)
+          (if (and (> (point-max) (point)) ;; not end of buffer
+                   (< (point) end)) ;; not goal
+              (forward-char 1)
+            (throw 'line-loop t)))))
+    (- end endorg)))
+
+
+
+
+;;
+;; My string-width for XEmacs
+;;   XEmacs returns the displayed width of each tab
+;; 
+(defun uim-string-width (str)
+  (if (not uim-xemacs)
+      (string-width str)
+    (let ((start 0) (cnt 0))
+      (while (setq start (string-match "\n" str start))
+	(setq start (match-end 0))
+	(setq cnt (- cnt 1)))
+      (setq start 0)
+      (while (setq start (string-match "\t" str start))
+	(setq start (match-end 0))
+	(setq cnt (+ cnt (- tab-width 1))))
+      (+ (string-width str) cnt))))
+
+
+
+
+;;
+;; Add white spaces.
+;;
+(defun uim-format-string (str width &optional right)
+  (if right
+      (concat (make-string (- width (uim-string-width str)) 32) str)
+    (concat str (make-string (- width (uim-string-width str)) 32))))
+
+
+;;
+;; Search "target" from "lst" and append "add" after it.
+;;
+(defun uim-list-search-append (lst target add)
+  (let ((new '()))
+    (while lst
+      (if (nlistp lst)
+	  (setq new (append new lst))
+	(if (nlistp (car lst))
+	    (if (eq (car lst) target)
+		(setq new (append new (list target add)))
+	      (setq new (append new (list (car lst)))))
+
+	  (setq new (append new (list (uim-list-search-append 
+				       (car lst) 
+				       target 
+				       add))))))
+      (if (listp lst)
+	  (setq lst (cdr lst))
+	(setq lst nil)))
+    new))
+
+
+;;
+;; Remove "target" from "lst"
+;;
+(defun uim-list-search-delete (lst target)
+  (let ((new '()) newtmp)
+    (while lst
+      (if (nlistp lst)
+          (setq new (append new lst))
+        (if (nlistp (car lst))
+            (unless (eq (car lst) target)
+              (setq new (append new (list (car lst)))))
+          (setq newtmp (uim-list-search-delete (car lst) target))
+          (if (not (equal newtmp nil))
+              (setq new (append new (list newtmp))))))
+      (if (listp lst)
+          (setq lst (cdr lst))
+        (setq lst nil )))
+    new))
+
+
+
+(defun uim-get-window-offset ()
+  (let ((i (or (and (= (window-start) (point)) 0)
+	       (- (count-lines (window-start) (point)) 1)))
+	goal
+	dummy-space
+	)
+
+    ;; for Tab
+    (save-excursion
+      (when (and (char-after)
+		 (= (char-after) ?\t))
+	(insert-char 32)
+	(setq dummy-space t)
+	))
+
+    (save-excursion
+      (uim-vertical-motion 0)
+      (setq goal (point)))
+
+    (save-excursion
+      (catch 'offset-loop
+	(while (< i (window-height))
+	  (goto-char (window-start))
+	  (uim-vertical-motion i)
+	  (when (>= (point) goal)
+	    (throw 'offset-loop nil)
+	    i)
+	  (setq i (+ i 1)))
+	)
+      )
+
+    (if dummy-space
+	(delete-char))
+    i
+    ))
+
+
+(provide 'uim-util)

Added: trunk/emacs/uim-var.el
===================================================================
--- trunk/emacs/uim-var.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim-var.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,402 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+(defconst uim-el-version "0.0.6-beta2")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Variables for Customizing
+
+;; Handle single Escape key press during preedit when Emacs
+;; is executed on the terminal (i.e. Emacs with -nw option).
+;;
+(defvar uim-use-single-escape-on-terminal nil
+  "If the value is non-nil and preedits exist, 
+escape key code is sent immediately to Uim every time the Escape-key is 
+pressed. This value is available only when the Emacs has been executed 
+with -nw option. If the value is valid, key-bindings with Alt key 
+cannot be used and function keys, such as F10 or Delete, are not
+recognized correctly.
+
+If the value is nil and Emacs is running on the terminal, 
+Escape key is mapped to ESC-ESC or M-Esc.
+
+Anyway, non-nil is unrecommended.")
+
+;; Name of default IM engine
+;; 
+;; Set this variable if you want to use different IM
+;; from default IM which is defined at the Uim common
+;; setting.
+(defvar uim-default-im-engine nil
+  "IM name used by default.
+
+If you want to use different IM from default IM defined at the Uim 
+common setting, set IM name you want to use.")
+
+
+;; List of IM engine property
+(defvar uim-default-im-prop nil
+  "List of IM properties which overwrite the common settings of Uim.
+
+Example:
+(setq uim-default-im-prop '(\"action_anthy_hiragana\" \"action_anthy_kana\"))
+")
+
+;; Command name of uim-el-agent
+(defvar uim-el-agent "uim-el-agent"
+  "Overwrite this variable if uim-el-agent is not in command path.
+
+Example:
+(setq uim-el-agent \"~/uim-el/uim-el-agent/uim-el-agent\")
+" )
+
+;; display fences on both edges of preedit
+(defvar uim-preedit-display-fences nil
+  "If the value is non-nil, fences are put on both edges of the preedits."
+  )
+
+;; display frame of candidate by ASCII characters
+(defvar uim-candidate-display-frame nil
+  "If the value is non-nil, frame is put around the candidate list."
+  )
+
+;; candidate display style of this buffer
+(defvar uim-candidate-display-inline nil
+  "If non-nil, a candidate list is displayed below the
+preedit string in vertical direction.  Otherwise, it is 
+displayed at the echo area.")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+
+;; Global Variables
+
+;; Type of Emacs
+(defconst uim-xemacs (featurep 'xemacs))
+(defconst uim-emacs (string-match "^GNU Emacs" (emacs-version)))
+
+;; Supported languages and encodings
+;; ("Uim-Language" "Emacs-Language" Emacs-encoding "Uim-Encoding")
+(defvar uim-lang-code
+  '(("Japanese"              "Japanese"     euc-jp      "EUC-JP")
+    ("Korean"                "Korean"       euc-kr      "EUC-KR")
+    ("Chinese (Simplified)"  "Chinese-GB"   gb2312      "GB2312")
+    ("Chinese (Traditional)" "Chinese-BIG5" big5        "BIG5")
+    ("Chinese"               "Chinese-GB"   gb2312      "GB2312")
+    ("Vietnamese"            "Vietnamese"   viscii      "VISCII")
+    ("Latin"                 "Latin-1"      iso-8859-1  "ISO-8859-1")
+    ("Thai"                  "Thai"         thai-tis620 "TIS-620")
+    ("Greek"                 "Greek"        iso-8859-7  "ISO-8859-7")
+    ("Hebrew"                "Hebrew"       iso-8859-8  "ISO-8859-8")
+    ("Laothian"              "Lao"          lao         "MULELAO-1")
+    ("Croatian"              "Latin-2"      iso-8859-2  "ISO-8859-2")
+    ("Slovenian"             "Latin-2"      iso-8859-2  "ISO-8859-2")
+    ("Serbian"               "Latin-2"      iso-8859-2  "ISO-8859-2")
+    ("Russian"               "Cyrillic-ISO" iso-8859-5  "ISO-8859-5")
+    ("Other"                 "ASCII"        iso-8859-1  "ISO-8859-1")
+    ))
+
+
+
+;; Alist of supported languages and encodings
+(defvar uim-lang-code-alist 
+  (mapcar (lambda (x)
+	    (list (nth 0 x)
+		  (cons 'uim-lang (nth 0 x))
+		  (cons 'emacs-lang (nth 1 x))
+		  (cons 'emacs-code (nth 2 x))
+		  (cons 'uim-code (nth 3 x)))) uim-lang-code))
+
+
+;; Keymaps for minor-mode
+(defvar uim-mode-map nil
+  "Keymap used in buffers that have uim-mode turned on.")
+(defvar uim-preedit-map nil
+  "Keymap used in uim-mode buffers with preedits.")
+
+(defvar uim-escape-map nil
+  "Empty keymap for escape key handling.")
+
+(defvar uim-toolbar-map nil
+  "Empty keymap for preventing toolbar action on XEmacs.")
+
+
+;; uim-el-agent related variables
+(defvar uim-el-agent-process nil
+  "uim-el-agent process.")
+(defvar uim-el-agent-buffer nil
+  "The buffer for communication with uim-el-agent.")
+(defconst uim-el-agent-buffer-name " *uim*"
+  "Name of the buffer for communication with uim-el-agent.")
+
+
+;; Timeout related variables (wait output from uim-el-agent)
+(defvar uim-el-agent-timeout 3)
+(defvar uim-el-agent-accept-timeout 5000
+  "Timeout for communication with uim-el-agent.")
+
+(defvar uim-startup-timeout 2000
+  "How long startup can take before it gets to your nerves, in milliseconds.")
+
+
+;; Minimum window size to display the candidate inline
+(defconst uim-candidate-minimum-width 8
+  "Minimum window size for displaying candidates inline.")
+
+
+;; List of IM engine 
+;; (looking up with IM name and obtain its language, encoding and so on)
+(defvar uim-im-list nil)
+
+;; Current focused buffer
+;;  if current-buffer has no Uim context, this should be nil
+(defvar uim-focused-buffer nil)
+
+;; Last buffer which is used to detect change of current-buffer
+(defvar uim-recent-buffer nil)
+
+;; Current maximum context ID
+(defvar uim-context-id-max 1)
+
+;; List of released context ID
+(defvar uim-context-id-recycle '())
+
+;; Face for preedit
+(defvar uim-preedit-face nil
+  "The face used to display preedit strings in uim-mode.")
+(defvar uim-preedit-underline-face nil
+  "The face used to display preedit strings with underline in uim-mode.")
+(defvar uim-preedit-highlight-face nil
+  "The face used to display highlighted preedit strings in uim-mode.")
+(defvar uim-preedit-highlight-underline-face nil
+  "The face used to display highlighted preedit strings with underline
+ in uim-mode.")
+
+;; face for preedit separator
+(defvar uim-separator-face nil)
+
+;; face for candidate
+(defvar uim-candidate-odd-face nil)
+(defvar uim-candidate-even-face nil)
+(defvar uim-candidate-selected-face nil)
+(defvar uim-candidate-nth-face nil)
+
+
+;; current serial number which is added to message to uim-el-agent
+(defvar uim-communication-serial-number 0)
+
+
+;; hook called when the default IM engine has been changed by agent
+(defvar uim-update-default-engine-hook nil)
+;; hook called when the current IM engine has been changed by agent
+(defvar uim-update-current-engine-hook nil)
+;; hook called when uim is force inactivated
+(defvar uim-force-inactivate-hook nil)
+;; hook called when buffer has been initialized
+(defvar uim-buffer-init-hook nil)
+;; hook called after reset key map 
+(defvar uim-reset-keymap-hook nil)
+
+(defvar uim-last-key-vector nil
+  "Recent key vector.")
+
+(defvar uim-retry-keys nil)
+
+;; Macro for setting up buffer-local variable
+(defmacro uim-deflocalvar (var default &optional documentation)
+  `(progn
+     (defvar ,var ,default
+       (format "%s (local\)" ,documentation))
+     (make-variable-buffer-local ',var)))
+
+
+
+;;; Buffer Local Variables
+
+(uim-deflocalvar uim-mode-line-string " U"
+		 "mode-line string of uim-mode.")
+
+(uim-deflocalvar uim-initialized nil)
+
+;; context ID (0 means "no context")
+(uim-deflocalvar uim-context-id 0)
+
+;; IM name which is used in the buffer
+(uim-deflocalvar uim-current-im-engine nil) 
+
+;; current property label
+(uim-deflocalvar uim-current-prop-label nil)
+
+;; context's encoding of this buffer
+(uim-deflocalvar uim-context-encoding 
+		 (nth 2 (assoc current-language-environment uim-lang-code)))
+
+;; minor-mode status
+(uim-deflocalvar uim-mode nil)
+
+;; code to decode output of uim-el-agent
+(uim-deflocalvar uim-decoding-code nil)
+
+;; unprocessed keys
+(uim-deflocalvar uim-stacked-key-vector nil)
+
+;; if non-nil, pressed keys are displayed at echo region
+(uim-deflocalvar uim-show-keystrokes nil)
+
+(uim-deflocalvar uim-minor-mode-map-alist nil)
+
+(uim-deflocalvar uim-emulation-mode-map-alists nil)
+
+;; preedit string is displayed or not
+(uim-deflocalvar uim-preedit-displayed nil)
+
+;; beginning point of preedit string
+(uim-deflocalvar uim-preedit-start 0)
+;; end point of preedit string 
+(uim-deflocalvar uim-preedit-end 0)
+;; cursor point of current preedit string
+(uim-deflocalvar uim-preedit-cursor 0)
+
+;; list of overlays of preedit string
+(uim-deflocalvar uim-preedit-ol-list '())
+
+(uim-deflocalvar uim-preedit-position-list '())
+
+(uim-deflocalvar uim-preedit-overlays '())
+
+
+;; freeze flag (to save font property)
+(uim-deflocalvar uim-buffer-frozen nil)
+
+;; candidate is displayed or not
+(uim-deflocalvar uim-candidate-displayed nil)
+
+;; candidate insertion base point
+;;  (basically, candidate list is inserted from next virtual line of this point)
+(uim-deflocalvar uim-candidate-start 0)
+;; distance between the candidate insertion base point and the candidate list
+;;  which is used when the preedit string is lapped to next virtual line.
+(uim-deflocalvar uim-candidate-vofs 0)
+;; original data under candidate
+(uim-deflocalvar uim-candidate-original-str nil)
+(uim-deflocalvar uim-candidate-original-start nil)
+(uim-deflocalvar uim-candidate-original-end nil)
+(uim-deflocalvar uim-candidate-end 0)
+;; list of overlays of candidate string
+(uim-deflocalvar uim-candidate-overlays '())
+
+(uim-deflocalvar uim-show-candidate-upward nil)
+
+
+(uim-deflocalvar uim-max-candstr 0)
+(uim-deflocalvar uim-max-candlabel 0)
+
+(uim-deflocalvar uim-candidate-page-label "") 
+(uim-deflocalvar uim-candidate-line-list '())
+
+;; saved undo list and its valid flag
+(uim-deflocalvar uim-buffer-undo-list nil)
+(uim-deflocalvar uim-buffer-undo-list-saved nil)
+
+(uim-deflocalvar uim-undo-stacking nil)
+
+
+;; save font-lock mode
+(uim-deflocalvar uim-font-lock-mode nil)
+(uim-deflocalvar uim-font-lock-verbose nil)
+
+;; save top point of current window to lock scroll
+(uim-deflocalvar uim-window-force-scrolled nil)
+
+(uim-deflocalvar uim-buffer-read-only nil)
+
+;; list of font faces for emulating font-lock mode looks
+(uim-deflocalvar uim-facelist nil)
+
+;; save current menubar temporally for XEmacs
+(uim-deflocalvar uim-menubar-temp nil)
+
+;; save real deactivate-mark
+(uim-deflocalvar uim-deactivate-mark nil)
+
+;; initialize faces
+
+;; for preedit string
+
+;; plain
+(copy-face 'default 'uim-preedit-face)
+
+(copy-face 'uim-preedit-face 'uim-preedit-underline-face)
+(set-face-underline-p        'uim-preedit-underline-face t)
+
+;; highlight
+(copy-face 'default  'uim-preedit-highlight-face)
+(set-face-foreground 'uim-preedit-highlight-face "White")
+(set-face-background 'uim-preedit-highlight-face "Blue3")
+
+(copy-face 'uim-preedit-highlight-face 'uim-preedit-highlight-underline-face)
+(set-face-underline-p                  'uim-preedit-highlight-underline-face t)
+
+;; separator
+(copy-face 'default 'uim-separator-face)
+(set-face-foreground 'uim-separator-face "LightSkyBlue4")
+
+;; for candidate list
+
+;; odd line
+(copy-face 'default 'uim-candidate-odd-face)
+(set-face-foreground 'uim-candidate-odd-face "blue")
+(set-face-background 'uim-candidate-odd-face "snow1")
+
+;; even line
+(copy-face 'default 'uim-candidate-even-face)
+(set-face-foreground 'uim-candidate-even-face "blue")
+(set-face-background 'uim-candidate-even-face "snow2")
+
+;; focused line
+(copy-face 'default  'uim-candidate-selected-face)
+(set-face-foreground 'uim-candidate-selected-face "blue")
+(set-face-background 'uim-candidate-selected-face "snow3")
+;;;(set-face-bold-p     'uim-candidate-selected-face t)
+
+;; total number and focused candidate number
+(copy-face 'default 'uim-candidate-nth-face)
+(set-face-foreground 'uim-candidate-nth-face "blue")
+(set-face-background 'uim-candidate-nth-face "lavender")
+
+
+(provide 'uim-var)

Added: trunk/emacs/uim.el
===================================================================
--- trunk/emacs/uim.el	2005-11-26 11:11:08 UTC (rev 2257)
+++ trunk/emacs/uim.el	2005-11-27 05:59:54 UTC (rev 2258)
@@ -0,0 +1,1304 @@
+;; 
+;;  Copyright (c) 2005, Konosuke Watanabe <nosuke at csc.ne.jp>
+;;  All rights reserved.
+;;
+;;  Redistribution and use in source and binary forms, with or
+;;  without modification, are permitted provided that the
+;;  following conditions are met:
+;;
+;;  1. Redistributions of source code must retain the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer.
+;;  2. Redistributions in binary form must reproduce the above
+;;     copyright notice, this list of conditions and the
+;;     following disclaimer in the documentation and/or other
+;;     materials provided with the distribution.
+;;  3. Neither the name of authors nor the names of its
+;;     contributors may be used to endorse or promote products
+;;     derived from this software without specific prior written
+;;     permission.
+;;
+;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+;;  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+;;  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+;;  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;;  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;;  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+;;  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+;;  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;
+
+(require 'uim-var)
+(require 'uim-keymap)
+(when uim-xemacs
+  (require 'overlay)
+  (load "mule-util"))
+
+(require 'uim-debug)
+(require 'uim-util)
+(require 'uim-key)
+
+(require 'uim-preedit)
+(require 'uim-candidate)
+
+
+;;
+;; Add uim-mode to minor modes
+;;
+(defun uim-init-minor-mode ()
+  ;; register uim-mode to minor-mode alist
+  (if (not (assq 'uim-mode minor-mode-alist))
+      (setq minor-mode-alist
+	    (cons
+	     (cons 'uim-mode '(uim-mode-line-string))
+	     minor-mode-alist)))
+
+  ;; register keymap of uim.el to minor-mode keymap alist
+  (if (not (assq 'uim-mode minor-mode-map-alist))
+      (setq minor-mode-map-alist
+	    (cons
+	     (cons 'uim-mode uim-mode-map)
+	     minor-mode-map-alist))))
+
+
+;;
+;; Get context ID
+;;   If there are any used IDs, use one of them preferentially
+;;
+(defun uim-get-context-id ()
+  (let (id)
+    (if (not (null uim-context-id-recycle))
+	(progn
+	  (setq id (car uim-context-id-recycle))
+	  (setq uim-context-id-recycle (cdr uim-context-id-recycle)))
+      (setq id uim-context-id-max)
+      (setq uim-context-id-max (+ uim-context-id-max 1)))
+    id))
+
+;;
+;; Release context ID
+;;   The released ID is added to the used-ID's list
+;;
+(defun uim-release-context-id (id)
+  (setq uim-context-id-recycle (cons id uim-context-id-recycle)))
+
+;;
+;; Validation IM
+;;
+(defun uim-check-im (im)
+  (if (assoc im (cdr uim-im-list))
+      t
+    (message (format "uim.el: invalid IM engine: %s" im))))
+
+;;
+;; Get default IM engine name.
+;;
+(defun uim-get-default-engine ()
+  (if (and uim-default-im-engine
+	   (uim-check-im uim-default-im-engine))
+      uim-default-im-engine
+    nil))
+
+
+;;
+;; Update default IM name of the uim-el-agent.
+;;   (for uim-im-switcher 
+;;       "Change whole desktop" and "Change this text area only")
+;;
+(defun uim-update-default-engine (engine)
+
+;  (uim-debug (format "update-default-engine: %s" engine))
+
+  (when (not (equal uim-default-im-engine engine))
+    (setq uim-default-im-engine engine)
+    (run-hooks 'uim-update-default-engine-hook)
+    ))
+
+;;
+;; Update IM name currently used in this buffer.
+;;   (for uim-im-switcher "Change this text area only")
+;;
+(defun uim-update-current-engine (engine)
+
+  (uim-debug (format "update-current-engine: %s" engine))
+
+  (when (not (equal uim-current-im-engine engine))
+    (setq uim-current-im-engine engine) 
+    (run-hooks 'uim-update-current-engine-hook))
+
+  ;; update current decoding code   
+  (let ((newcode (uim-get-emacs-code uim-current-im-engine)))
+    (when (not (string= newcode uim-decoding-code))
+      (setq uim-decoding-code newcode)
+      (uim-change-process-encoding uim-decoding-code)))
+  )
+
+
+;; Update mode-line string to "label1 label2".
+(defun uim-update-mode-line (label1 &optional label2)
+  (setq uim-current-prop-label (format "%s" (car label1)))
+  (if label2
+      (setq uim-current-prop-label 
+	    (concat uim-current-prop-label (format "%s" (car label2)))))
+
+  (setq uim-mode-line-string 
+	(format " U %s[%s]"
+		uim-current-im-engine uim-current-prop-label))
+
+  )
+
+
+
+;;	
+;; Create new context
+;;
+(defun uim-context-create ()
+  (let (id)
+    ;; get new context ID
+    (setq id (uim-get-context-id))
+
+    ;;    Default context's encoding is determined by 
+    ;;  the name of default IM 
+    (uim-do-send-recv-cmd 
+     (format "%d NEW %s" id (uim-get-uim-code (uim-get-default-engine))))
+    id))
+
+
+;;
+;; Delete context
+;;   The context is kept until the buffer is killed
+;;
+(defun uim-delete-context ()
+  (uim-do-send-recv-cmd (format "%d RELEASE" uim-context-id))
+  (uim-release-context-id uim-context-id))
+
+
+;;
+;; Reset context
+;;
+(defun uim-reset-context ()
+  (uim-do-send-recv-cmd (format "%d RESET" uim-context-id)))
+
+
+;;
+;; Get serial number for the next message
+;;
+(defun uim-get-communication-serial-number ()
+  (if (= uim-communication-serial-number 65535)
+      (setq uim-communication-serial-number 0))
+  (setq uim-communication-serial-number
+	(+ uim-communication-serial-number 1)))
+
+;;
+;; Focused 
+;;
+(defun uim-focused ()
+  (uim-change-process-encoding uim-decoding-code)
+  (uim-do-send-recv-cmd (format "%d FOCUSED" uim-context-id))
+  (setq uim-focused-buffer (current-buffer))
+  )
+
+;;
+;; Unfocused
+;;
+(defun uim-unfocused ()
+  ;; don't send a message to uim-el-agent if it has been dead
+  (if uim-el-agent-process
+      (uim-do-send-recv-cmd (format "%d UNFOCUSED" uim-context-id)))
+  (setq uim-focused-buffer nil)
+  )
+
+
+;;
+;; Force disable uim-mode
+;;
+(defun uim-force-off ()
+  ;; cleanup displayed preedit and candidate
+  (setq uim-last-key-vector nil)
+  (uim-process-agent-output '(("e")))
+;  (uim-reset-context)
+  (uim-release-context-id uim-context-id)
+  (run-hooks 'uim-force-inactivate-hook)
+  (if uim-mode
+      (uim-mode-off))
+  )
+
+;;
+;; Detect switching of current focused buffer
+;;   This function is hooked on 'post-command-hook and 
+;;  called after every operation
+;;
+(defun uim-post-command ()
+
+  ;; detect switching of current buffer
+  (when (not (eq uim-recent-buffer (current-buffer)))
+
+    (uim-debug (format "current-buffer changed (from %s to %s)"
+		       uim-focused-buffer
+		       (current-buffer)))
+
+    ;; update recent bufferto detect next change
+    (setq uim-recent-buffer (current-buffer))
+    
+    ;; remove Uim focus from previous buffer
+    (if (and (bufferp uim-focused-buffer)
+	     (buffer-name uim-focused-buffer))
+	(save-current-buffer
+	  (set-buffer uim-focused-buffer)
+	  (when (and uim-initialized
+		     uim-mode)
+	    (uim-debug (format "unfocused %s" 
+			       (buffer-name (current-buffer))))
+	    (uim-unfocused)
+	    )))
+	    
+	      
+    ;; set Uim focus to current buffer if it has Uim context
+    (if (and uim-initialized
+	     uim-mode)
+	(progn 
+	  (uim-debug (format "focused %s" 
+			     (buffer-name (current-buffer))))
+
+	  (uim-focused)
+	  )
+      ;; no Uim context in current buffer
+      )
+
+    (uim-debug (format "current-buffer %s / uim-focused-buffer %s" (current-buffer) uim-focused-buffer ))
+
+    )
+  )
+
+
+;;
+;; Overwrite properties of current context
+;;
+(defun uim-prop-activate (proplist)
+  (mapcar 
+   '(lambda (x)
+      (uim-do-send-recv-cmd (format "%d PROP %s" uim-context-id x)))
+   proplist))
+
+;;
+;; Update process encoding 
+;; 
+(defun uim-change-process-encoding (outcode)
+  (uim-debug (format "set-process-encoding to %s" outcode))
+  (set-process-coding-system uim-el-agent-process outcode 'iso-8859-1)
+  )
+
+;;
+;; Get IM information from uim-im-list
+;;
+(defun uim-get-im-info (im info)
+  (cdr (assoc info (cdr (assoc im (cdr uim-im-list))))))
+
+(defun uim-get-uim-code (im)
+  (or (uim-get-im-info im 'uim-code)
+      "ISO-8859-1"))
+
+(defun uim-get-emacs-code (im)
+  (or (uim-get-im-info im 'emacs-code)
+      'iso-8859-1))
+
+(defun uim-get-uim-lang (im)
+  (or (uim-get-im-info im 'uim-lang)
+      "Unknown"))
+
+(defun uim-get-emacs-lang (im)
+  (or (uim-get-im-info im 'emacs-lang)
+      "ASCII"))
+
+;;
+;; Change IM engine.
+;;   im should be valid egine name.
+;; 
+(defun uim-change-im (im)
+  ;; change decoding method temporarily to receive encoded IM label etc.
+  (uim-change-process-encoding (uim-get-emacs-code im))
+  (uim-do-send-recv-cmd 
+   (format "%d CHANGE %s %s" uim-context-id im (uim-get-uim-code im)))
+
+  (if uim-default-im-prop
+      (uim-prop-activate uim-default-im-prop)))
+
+
+;;
+;; Set each IM's output encoding 
+;;
+(defun uim-set-encoding (im)
+  (let ((uim-code (uim-get-uim-code im)))
+    (uim-do-send-recv-cmd 
+     (format "0 SETENC %s %s" im uim-code))))
+
+
+
+;;
+;; Initialize each buffer 
+;;   Called when a context has been created
+;;
+(defun uim-init-buffer ()
+
+  (uim-debug (format "initialize buffer: %s" (current-buffer)))
+
+  ;; if buffer has no context
+  (setq uim-context-id (uim-context-create))
+
+  ;; redraw Uim related objects when window has been resized
+  (make-local-hook 'window-configuration-change-hook)
+  (add-hook 'window-configuration-change-hook 'uim-window-changed nil t)
+
+  (make-local-hook 'kill-buffer-hook)
+  (add-hook 'kill-buffer-hook 'uim-kill-buffer nil t)
+
+  ;; hide candidate/preedit when buffer-save has been called
+  (add-hook 'local-write-file-hooks 
+	    '(lambda ()
+	       (if uim-preedit-displayed
+		   (uim-process-agent-output '(("e"))))))
+
+  ;; change IM engine to uim-default-im-engine
+  (if (and uim-default-im-engine
+	   (uim-check-im uim-default-im-engine))
+      (uim-change-im uim-default-im-engine))
+
+  ;; set properties
+  (if uim-default-im-prop
+      (uim-prop-activate uim-default-im-prop))
+
+  (run-hooks 'uim-buffer-init-hook)
+
+  (setq uim-initialized t)
+  )
+
+
+(defun uim-update-keybind ()
+  (uim-copy-toggle-key 'uim-mode))
+
+;;
+;; Activate uim
+;;
+(defun uim-mode-on ()
+
+  (uim-debug "uim-mode-on")
+
+  (if uim-mode
+      (message "uim.el: uim-mode is already activated. (buffer %s)" (current-buffer)))
+
+  (if (not buffer-read-only)
+      (progn 
+
+	;; initialize context and buffer
+	(when (not uim-initialized)
+	  (uim-init-buffer))
+
+	;; enable and update keymap
+	(uim-enable-mode-keymap)
+	(uim-update-keybind)
+
+	;; focus to current context
+	(uim-focused)
+
+	;; update mode-line
+	(force-mode-line-update)
+
+	;; really enable minor-mode
+	(setq uim-mode t))
+
+    ;; don't activate if the current buffer is read-only
+    (message "uim.el: This buffer is read-only.")
+    )
+  )
+
+
+;;
+;; Deactivate Uim
+;;
+(defun uim-mode-off ()
+  
+  (if (not uim-mode)
+      (message "uim.el: uim-mode is already inactivated."))
+
+  (uim-unfocused)
+
+  ;; update mode-line
+  (force-mode-line-update)
+
+
+  ;; Disable uim-mode
+  (setq uim-mode nil)
+
+  (uim-debug (format "uim-mode: %s" uim-mode))
+
+  )
+
+
+;;
+;; Release context when buffer is killed or major-mode changed
+;;   This function is called by uim-initialized buffer only
+;;
+(defun uim-kill-buffer ()
+
+  (uim-debug (format "kill-bufer %s"
+		     (buffer-name (current-buffer))))
+
+  ;; unfocus
+  (if (eq uim-focused-buffer (current-buffer))
+      (uim-unfocused))
+
+  ;; delete context
+  (uim-delete-context)
+  )
+
+
+;;
+;; Reset context
+;;
+(defun uim-change-major-mode ()
+
+  (when uim-initialized
+       (uim-unfocused)
+       (uim-delete-context))
+  )
+
+
+;;
+;; start uim-el-agent process
+;;
+(defun uim-el-agent-start ()
+  (let (proc
+	(buffer (get-buffer-create uim-el-agent-buffer-name)) )
+
+    ;; erase buffer
+    (save-current-buffer
+      (set-buffer buffer) (erase-buffer))
+
+    (message "uim.el: starting uim-el-agent...")
+
+    (setq proc (start-process "uim-el-agent" buffer uim-el-agent))
+
+    (if (not proc)
+	(error "uim.el: Couldn't invoke uim-el-agent."))
+    
+    ;; don't ask kill
+    (process-kill-without-query proc)
+
+    ;; wait "OK"
+    (let ((patience uim-startup-timeout) (ok nil))
+      (save-current-buffer
+	(set-buffer buffer)
+	(while (not ok)
+	  (accept-process-output proc 0 uim-el-agent-accept-timeout)
+	  (goto-char 1)
+	  (end-of-line)
+	  (if (string= "OK" (buffer-substring 1 (point)))
+	      (setq ok t)
+	    (setq patience (- patience (/ uim-el-agent-accept-timeout 1000)))
+	    (if (<= patience 0)
+		(progn
+		  (kill-process (process-name proc))
+		  (error "uim.el: uim-el-agent is unreponsive.  Giving up.")))))
+	(erase-buffer)))
+	
+    (setq uim-el-agent-buffer buffer)
+
+    (set-process-sentinel proc 'uim-process-sentinel)
+    proc 
+    ))
+
+
+;;
+;; Stop uim-el-agent
+;;
+(defun uim-el-agent-stop (proc)
+  (if (and proc
+	   (process-status proc))
+      (interrupt-process proc)))
+
+
+;;
+;; Restore undo list
+;;
+(defun uim-restore-undo ()
+  (when uim-buffer-undo-list-saved
+    (buffer-enable-undo)
+    (setq buffer-undo-list uim-buffer-undo-list)
+    (setq uim-buffer-undo-list-saved nil))
+  )
+
+
+;;
+;; Save undo list
+;;
+(defun uim-save-undo ()
+  (when (not uim-buffer-undo-list-saved)
+    (setq uim-buffer-undo-list buffer-undo-list)
+    (buffer-disable-undo)
+    (setq uim-buffer-undo-list-saved 't))
+  )
+
+
+;;
+;; Update IM list
+;;
+(defun uim-update-imlist (imlist)
+  ;; imlist: default (engine lang_code Language explanation encoding)
+
+  (let ((default (car imlist)))
+
+    ;; initialize default IM engine name with the context's default value
+    (when (not uim-default-im-engine)
+      (uim-update-default-engine default))
+
+
+    (setq 
+     uim-im-list 
+     (cons default
+	   (mapcar (lambda (x) 
+		     (cons (car x)
+			   (cdr (or (assoc (nth 2 x) uim-lang-code-alist)
+				    (assoc "Other" uim-lang-code-alist)))))
+		   (cdr imlist))))
+    )
+  )
+
+
+;;
+;; Update property label
+;;
+(defun uim-update-label (label)
+  ;; label: ( "current" ("label_abbr"  "label") ... )
+  (let (label1 label2 mode-str)
+    ;; current IM engine name
+    (uim-update-current-engine (car label))
+
+    (setq label (cdr label))
+
+    (setq label1 (car label))
+    (setq label (cdr label))
+
+    (when label
+      (setq label2 (car label)))
+
+    ;; Update mode-line string to "label1 label2".
+    (setq mode-str (format "%s" (car label1)))
+
+    (if label2 
+	(setq mode-str (concat mode-str (format "%s" (car label2)))))
+
+    (setq uim-mode-line-string 
+	  (format " U %s[%s]" uim-current-im-engine mode-str))
+
+
+    )
+  )
+
+
+
+;;
+;; Check lock status of buffer file
+;; 
+(defun uim-buffer-locked-p ()
+  (if (buffer-file-name)
+      (let ((locked (file-locked-p (buffer-file-name))))
+	(not (or (not locked)     ;; nil when unlocked
+		 (eq locked t))))))  ;; locked by this process
+
+	    
+
+;;
+;; Cehck the buffer is editable or not
+;;
+(defun uim-buffer-not-editable ()
+  (or (uim-buffer-locked-p)
+      (not (verify-visited-file-modtime (current-buffer)))
+      buffer-read-only))
+
+
+;; 
+;; Called when the window has been resized
+;;
+(defun uim-window-changed ()
+  (let (candidate-displayed)
+  
+    (when (and uim-candidate-displayed
+	       uim-candidate-display-inline)
+      (setq candidate-displayed uim-candidate-displayed)
+
+      (uim-do-send-recv-cmd (format "%d HIDE" uim-context-id))
+
+      (when (and candidate-displayed
+		 (uim-check-candidate-space))
+	(uim-do-send-recv-cmd (format "%d SHOW" uim-context-id))))))
+
+
+;; 
+;; Sentinel of uim-el-agent 
+;;   STOP state is not supported yet
+;; 
+(defun uim-process-sentinel (proc stat)
+
+  (message "uim.el: %s" stat)
+
+  (setq uim-el-agent-process nil)
+
+  (let ((old-buffer (current-buffer))
+	(bufs (buffer-list)))
+    (while bufs
+      (save-current-buffer
+	(set-buffer (car bufs))
+	(when uim-initialized
+	  ;; disable uim
+	  (uim-force-off)
+	  ;; reset all local variables
+	  (kill-all-local-variables)
+	  ))
+      (setq bufs (cdr bufs)))
+    ))
+
+
+;;
+;; Send command to uim-el-agent
+;; 
+(defun uim-send-cmd (cmd serial)
+
+  (uim-debug (concat (format "%s " serial) cmd ))
+
+  ;; check process status and start if it's not running
+  (if (not uim-el-agent-process)
+      (setq uim-el-agent-process (uim-el-agent-start)))
+
+  (if uim-el-agent-process
+      (progn
+	(save-current-buffer
+	  (set-buffer uim-el-agent-buffer)
+	  (erase-buffer))
+	
+	(process-send-string uim-el-agent-process
+			     (concat (format "%s " serial) cmd "\n"))
+	t)
+    nil))
+
+
+;;
+;; Delete the first line from buffer
+;;
+(defun uim-delete-oneline-from-buffer (buf)
+  (save-current-buffer
+    (set-buffer buf)
+    (beginning-of-buffer)
+    (delete-region 1 (progn (end-of-line) (point)))
+    (if (= (following-char) ?\n)
+	(delete-char 1))))
+
+
+;;
+;; Get 1st one line from buffer
+;;   skip non S-expression line
+;;
+(defun uim-get-oneline-from-buffer (buf)
+  (save-current-buffer
+    (set-buffer buf)
+    (when (> (buffer-size) 0)
+      (goto-char 1)
+      (skip-chars-forward " ")
+      ;; check the first line is beginning with bracket
+      (if (= (following-char) ?\( )
+	  (progn
+	    (end-of-line)
+	    (if (looking-at "\n")
+		(buffer-substring 1 (point))
+	      nil))
+	;; if the first line isn't S-expression, skip and return nil
+	(uim-delete-oneline-from-buffer buf)
+	nil))))
+
+
+;; 
+;; Wait reply from uim-el-agent
+;;   Check serial number 
+;;
+(defun uim-wait-recv(serial)
+
+  (let (rstr)
+
+    (let ((start (nth 1 (current-time)))
+	  (accept uim-el-agent-accept-timeout))
+      (catch 'read-loop
+	(while (and (process-status uim-el-agent-process)
+		    (< (abs (- start (nth 1 (current-time))))
+		      uim-el-agent-timeout))
+	  
+	  (accept-process-output uim-el-agent-process 0 accept)
+
+	  (if (setq rstr (uim-get-oneline-from-buffer uim-el-agent-buffer))
+	      (if (= (car (read rstr)) serial)
+		  (throw 'read-loop t)
+		(uim-delete-oneline-from-buffer uim-el-agent-buffer)))
+	  ;; double the accepting time if waiting again
+	  (setq accept (* accept 2)))))
+
+    (cond ((not (process-status uim-el-agent-process))
+	   ;; uim-el-agent is dead
+	   (message "uim.el: state of uim-el-agent has been changed (died?)"))
+	  
+	  ((not rstr)
+	   (message "uim.el: ***TIMEOUT*** no response from uim-el-agent")
+	   ;; stop uim-el-agent (uim-el-agent will be restarting on-demand)
+	   (uim-el-agent-stop uim-el-agent-process))
+
+	  (t
+	   ;; received
+	   ;;   rstr: ( serial# context-id (...) )
+	   (uim-process-agent-output (cddr (read rstr)))
+	   )
+	  )))
+
+
+;;
+;; Send message to uim-el-agent and wait return
+;;
+(defun uim-do-send-recv-cmd (cmd)
+  (let ((serial (uim-get-communication-serial-number)))
+    (if (uim-send-cmd cmd serial)
+	(uim-wait-recv serial))))
+
+;;
+;; Save face property
+;;
+(defun uim-get-face-list (start end)
+  (let ((facelist '()) tail face)
+    (catch 'face-loop
+      (while t
+	(setq tail
+	      (next-single-property-change start 'face (current-buffer) end))
+	(if (setq face (get-text-property start 'face))
+	    (setq uim-facelist (cons (list face start tail) uim-facelist)))
+	(setq start tail)
+	(if (= start end)
+	    (throw 'face-loop t))))
+    )
+  )
+
+
+
+;;
+;; Save face property of the window
+;;   Save only displayed region
+(defun uim-get-facelist-window (win)
+  (select-window win)
+  (let (end)
+    (save-excursion
+      (goto-char (window-end nil t))
+      (vertical-motion (window-height))
+      (setq end (point)))
+    (save-excursion
+      (uim-get-face-list (window-start) end)
+      )
+    ))
+
+
+;;
+;; Save face property of windows which are displaying the current buffer.
+;;
+(defun uim-get-facelist-buffer ()
+  (save-selected-window
+    (mapcar 'uim-get-facelist-window
+	    (get-buffer-window-list (current-buffer) t 'visible))
+    uim-facelist))
+
+
+;;
+;; Disable font-lock mode
+;;    This function should be called only when the font-lock-mode is 
+;;   already in use
+;;
+(defun uim-disable-font-lock-mode ()
+  ;; save and disable font-lock-mode
+  (setq uim-font-lock-mode font-lock-mode)
+  (setq uim-font-lock-verbose font-lock-verbose)
+  (when font-lock-mode
+    (font-lock-mode 0)
+    (setq font-lock-verbose nil)))
+
+
+;;
+;; Eable font-lock mode
+;;
+(defun uim-enable-font-lock-mode ()
+  (when uim-font-lock-mode
+    (font-lock-mode uim-font-lock-mode)
+    (setq font-lock-verbose uim-font-lock-verbose)))
+
+
+;;
+;; Restore face property
+;;
+(defun uim-put-face (facelist)
+  (put-text-property (nth 1 facelist) (nth 2 facelist)
+		     'face (car facelist)))
+
+
+;;
+;; Lock appearance of buffer
+;;
+(defun uim-freeze-buffer ()
+  (let (facelists)
+
+    (setq uim-facelist nil)
+    (uim-get-facelist-buffer)
+    ;(setq facelists (uim-get-face-list 1 (point-max)))
+    (if (memq 'font-lock features)	     
+	(progn
+	  (uim-disable-font-lock-mode)
+	  (mapcar 'uim-put-face uim-facelist)))
+    )
+  (setq uim-buffer-frozen t))
+
+
+
+;;
+;; Unlock appearance of buffer
+;;
+(defun uim-unfreeze-buffer ()
+  (let (facelists)
+    (if (memq 'font-lock features)
+	(uim-enable-font-lock-mode))
+    )
+  (setq uim-buffer-frozen nil))
+
+ 
+
+
+
+;;
+;; Process inputted key
+;;
+(defun uim-process-input (&optional arg event reg1 reg2)
+  (interactive (list current-prefix-arg 
+		     last-input-event
+		     ))
+
+  (if uim-emacs
+      (setq uim-deactivate-mark t))
+
+  (if (not uim-stacked-key-vector)
+      (setq uim-show-keystrokes nil))
+
+  ;; send an input key code to uim-el-agent
+  (let ((keyvec (uim-this-command-keys))
+	sendkey newvec bypass count mouse)
+
+    (if keyvec
+	(progn
+	  (if uim-show-keystrokes
+	      (let (message-log-max)
+		(message (key-description keyvec))))
+
+	  (setq uim-last-key-vector keyvec)
+
+	  (cond (uim-xemacs 
+		 ;; XEmacs ;;
+		 (setq sendkey 
+		       (uim-convert-keystr-to-uimagent-vector (key-description keyvec)))
+
+		 (cond ((string-match "button\\(1\\|2\\|3\\)" 
+				      (key-description keyvec))
+			;; through mouse event
+			(setq mouse t)
+			(setq bypass t))
+		       
+		       (current-prefix-arg
+			(uim-debug "with prefix arg")
+			(setq bypass t)
+			(setq count (prefix-numeric-value arg)))
+		       
+		       ((and (not uim-preedit-displayed)
+			     (uim-buffer-not-editable) )
+			;; through uim-el-agent when buffer is uneditable
+			(setq bypass t)
+			))
+		 
+		 (if bypass
+		     (setq sendkey 
+			   (uim-convert-char-to-symbolvector 
+			    (key-description keyvec))))
+		 )
+		
+		(uim-emacs 
+		 ;; Emacs ;;
+		 (setq sendkey keyvec)
+		 
+		 (cond (current-prefix-arg
+			;; (uim-debug (format "with prefix arg %s"
+			;; current-prefix-arg))
+			(setq bypass t)
+			(setq count (prefix-numeric-value arg)))
+		       ((and (eventp event)
+			     (memq (event-basic-type event) 
+				   '(mouse-1 mouse-2 mouse-3)))
+			;; detect mouse event
+			;;(uim-debug "mouse event")
+			(setq bypass t)
+			(setq mouse t)
+			)
+		       ((and (not uim-preedit-displayed)
+			     (uim-buffer-not-editable))
+			(setq bypass t))
+		       (t 
+			;; overwrite special keyvector
+			(cond ((equal sendkey [127])   (setq sendkey [backspace]))
+			      ((equal sendkey [27 27]) (setq sendkey [27]))
+			      ((equal sendkey [28])    (setq sendkey [C-\\]))
+			      ((equal sendkey [29])    (setq sendkey [C-\]]))
+			      ((equal sendkey [30])    (setq sendkey [C-~]))
+			      ((equal sendkey [31])    (setq sendkey [C-_]))
+			      ))
+		       )
+		 ))
+	  
+	  ;; pass only Uim supported keys
+	  (when (or (>= (length sendkey) 3)
+		    (and (= (length sendkey) 2)
+			 (not (or (eq (aref sendkey 0) 27)
+				  (eq (aref sendkey 0) 'escape)))))
+	    (uim-debug "bypass")
+	    (setq bypass t))
+		 
+
+	  (if (not bypass)
+	      (uim-do-send-recv-cmd (format "%d %s" uim-context-id sendkey))
+	    (if mouse
+		(uim-process-mouse-event event)
+	      (uim-process-keyvec uim-last-key-vector count)))
+	  )
+      
+      (if (not uim-show-keystrokes)
+	  (if (sit-for echo-keystrokes)
+	      (setq uim-show-keystrokes t)))
+
+      (if uim-show-keystrokes
+	  (let (message-log-max)
+	    (message (concat (key-description uim-stacked-key-vector) "-"))))
+
+      )
+    )
+
+  (if uim-emacs
+      (setq deactivate-mark uim-deactivate-mark))
+  )
+
+
+
+
+
+;; process return expression from uim-el-agent 
+(defun uim-process-agent-output (str)
+  (let (preedit-exists
+	candidate-exists
+	key commit (preedit nil) candidate default label imlist)
+
+    (let ((modified (buffer-modified-p)))
+      ;; remove candidate anyway
+      (when uim-candidate-displayed
+	(setq candidate-exists t)
+	(uim-remove-candidate)
+	(setq uim-candidate-displayed nil))
+
+      ;; remove preedit anyway
+      (when uim-preedit-displayed
+	(setq preedit-exists t)
+	(uim-remove-preedit)
+	(setq uim-preedit-displayed nil))
+
+      ;; restore modified flag
+      (set-buffer-modified-p modified))
+
+    (uim-debug (format "%s" str))
+
+
+    (mapcar 
+     '(lambda (x) 
+	(let ((rcode (car x))
+	      (rval (cdr x)))
+	
+	  (cond ((string= rcode "n") ;; uim returns key code
+		 (if uim-last-key-vector
+		     (progn
+		       (setq key uim-last-key-vector)
+		       (uim-debug (format "%s" key)))
+		   (setq key (car rval)))
+		 )
+		((string= rcode "s") ;; commit string
+		 (setq commit (append commit (list (car rval))))
+		 )
+		((string= rcode "c") ;; candidate data
+		 (setq candidate rval)
+		 )
+		((string= rcode "p") ;; preedit
+		 (setq preedit rval)
+		 )
+		((string= rcode "d") ;; default engine
+		 (setq default (car rval))
+		 )
+		((string= rcode "l") ;; label
+		 (setq label rval)
+		 )
+		((string= rcode "L") ;; IM list
+		 (setq imlist rval)
+		 )
+		((string= rcode "e") ;; IM list
+		 )
+		)
+	  )) 
+     str)
+
+
+    (when default
+      (uim-update-default-engine default))
+
+    (when label
+      (uim-update-label label))
+
+    (when imlist
+      (uim-update-imlist imlist))
+
+    (if (or commit
+	    (and preedit-exists (not preedit)))
+	(uim-restore-undo))
+
+    (if commit
+	(mapcar '(lambda (x) 
+		   (insert x) (undo-boundary)) 
+		commit))
+
+    (if key
+	;; process raw key
+	(progn
+	  (if preedit-exists
+	      (uim-disable-preedit-keymap))
+	  (uim-process-keyvec key))
+
+      ;; process preedit
+      (if preedit
+	  (let ((modified (buffer-modified-p)))
+
+	    (uim-flush-concat-undo)
+
+	    ;; switch keymap to preedit mode
+	    (if (not preedit-exists)
+		(uim-enable-preedit-keymap))
+
+	    (uim-save-undo)
+
+	    (setq uim-preedit-displayed t)
+
+	    ;; freeze buffer if the first preedit display
+	    (if (and (not preedit-exists)
+		     (= (minibuffer-depth) 0))
+		(uim-freeze-buffer))
+
+	    (uim-insert-preedit preedit)
+
+	    ;; show candidate
+	    (if candidate
+		(progn
+		  (setq uim-candidate-displayed t)
+		  (if (uim-check-candidate-space)
+		      (uim-show-candidate candidate))))
+
+	    (set-buffer-modified-p modified)
+	    )
+
+	(when (and preedit-exists
+		   uim-buffer-frozen)
+	  (uim-disable-preedit-keymap)
+	  (uim-unfreeze-buffer)
+
+	  )
+	)
+
+      (when (and candidate-exists
+		 (not uim-candidate-displayed)
+		 uim-window-force-scrolled)
+	(uim-debug "recenter: window-force-scrolled is true")
+	(setq uim-window-force-scrolled nil)
+	(recenter)
+	)
+      
+
+      ;; move cursor
+
+      (when uim-preedit-displayed
+	(goto-char uim-preedit-cursor))
+      )
+
+
+    ))
+
+
+
+
+
+
+;;
+;; Get available IM list from uim-el-agent
+;;
+(defun uim-get-im-list ()
+  (uim-do-send-recv-cmd (format "0 LIST")))
+
+
+;;
+;; Initialize IM list and encoding
+;;
+(defun uim-init-im-encoding ()
+
+  (uim-get-im-list)
+
+  ;; set Uim side encoding to agent
+  (let ((im-list (cdr uim-im-list)))
+    (while im-list
+      ;; cdar exists when im has valid encoding
+      (if (cdar im-list)
+	  (uim-set-encoding (caar im-list)))
+      (setq im-list (cdr im-list)))))
+
+
+
+;;
+;; Called when entering into the mini-buffer
+;;
+(defun uim-minibuffer-enter ()
+  nil)
+
+;;
+;; Called when leaving from the mini-buffer
+;;
+(defun uim-minibuffer-exit ()
+  (if (and uim-initialized
+	   uim-mode)
+      ;(uim-mode-off)
+      (uim-force-off)
+      ))
+
+
+
+;;
+;; Initialize uim
+;;
+(defun uim-init ()
+
+  ;; initialize minor-mode
+  (uim-init-minor-mode)
+
+  ;; initialize encoding
+  (uim-init-im-encoding)
+  
+  ;; initialize keymap
+  (uim-init-keymap)
+
+  ;; add hook to detect status change of buffer
+  (add-hook 'post-command-hook 'uim-post-command)
+
+  ;; disable uim when major-mode has changed
+  (add-hook 'change-major-mode-hook 'uim-change-major-mode)
+
+  ;; add hooks to detect minibuffer entering and leaving
+  (add-hook 'minibuffer-setup-hook 'uim-minibuffer-enter)
+  (add-hook 'minibuffer-exit-hook 'uim-minibuffer-exit)
+
+  (add-hook 'uim-reset-keymap-hook 'uim-update-keybind)
+
+  )
+
+
+;;
+;; Toggle uim
+;;
+
+(defun uim-mode (&optional arg)
+  "Toggle uim mode.
+With argument ARG, turn uim mode on if ARG > 0.
+uim mode facilitates internationalized input through the uim library."
+  (interactive)
+  (if arg
+      (if (> arg 0)
+	  (if (not uim-mode) (uim-mode-on))
+	(if uim-mode (uim-mode-off)))
+    (if uim-mode
+	(uim-mode-off)
+      (uim-mode-on))))
+; compat
+(defun uim-mode-switch ()
+  (interactive)
+  (if uim-mode
+      (uim-mode-off)
+    (uim-mode-on)))
+
+;;
+;; Toggle candidate display style
+;;
+(defun uim-switch-candidate-display-mode (&optional arg)
+  (interactive)
+
+  (if (not (local-variable-p 'uim-candidate-display-inline (current-buffer)))
+      (make-variable-buffer-local 'uim-candidate-display-inline))
+  
+  (if (not uim-candidate-displayed)
+      (if (and arg (integerp arg))
+	  (if (> arg 0)
+	      (setq uim-candidate-display-inline t)
+	    (setq uim-candidate-display-inline nil))
+
+	;; interactive
+	(if uim-candidate-display-inline
+	    (progn
+	      (message "uim.el: mini-buffer candidate display mode")
+	      (setq uim-candidate-display-inline nil))
+	  (message "uim.el: inline candidate display mode")
+	  (setq uim-candidate-display-inline t))))
+  )
+
+
+;;
+;; Switch IM engine
+;;
+(defun uim-im-switch (&optional im)
+  (interactive)
+
+  (if (not uim-mode)
+      (uim-mode-on))
+
+  (when uim-initialized
+    (if (not im)
+	(let (alist)
+	  (setq alist (mapcar (lambda (x) (cons (car x) (car x))) 
+			      (cdr uim-im-list)))
+	  (save-window-excursion
+	    (setq im (cdr (assoc
+			   (completing-read (concat "IM Engine: ") alist nil t)
+			   alist) )))))
+    (if (uim-check-im im)
+	(uim-change-im im))))
+
+;;
+;; Show uim.el version
+;;
+(defun uim-el-version ()
+  (interactive)
+  (message uim-el-version))
+
+
+
+;; Initialize uim.el 
+(uim-init)
+
+
+(provide 'uim)
+



More information about the uim-commit mailing list