[uim-commit] r2882 - in branches/r5rs: . emacs

yamaken at freedesktop.org yamaken at freedesktop.org
Tue Jan 10 04:46:26 PST 2006


Author: yamaken
Date: 2006-01-10 04:46:23 -0800 (Tue, 10 Jan 2006)
New Revision: 2882

Modified:
   branches/r5rs/
   branches/r5rs/emacs/callback.c
   branches/r5rs/emacs/candidate.c
   branches/r5rs/emacs/candidate.h
   branches/r5rs/emacs/context.c
   branches/r5rs/emacs/context.h
   branches/r5rs/emacs/helper.c
   branches/r5rs/emacs/helper.h
   branches/r5rs/emacs/im.c
   branches/r5rs/emacs/im.h
   branches/r5rs/emacs/preedit.c
   branches/r5rs/emacs/preedit.h
   branches/r5rs/emacs/prop.c
   branches/r5rs/emacs/prop.h
   branches/r5rs/emacs/uim-candidate.el
   branches/r5rs/emacs/uim-el-agent.c
   branches/r5rs/emacs/uim-key.el
   branches/r5rs/emacs/uim-keymap.el
   branches/r5rs/emacs/uim-leim.el
   branches/r5rs/emacs/uim-preedit.el
   branches/r5rs/emacs/uim-util.el
   branches/r5rs/emacs/uim-var.el
   branches/r5rs/emacs/uim.el
Log:
 r1347 at deepblue (orig r2845):  nosuke | 2006-01-08 19:03:50 +0900
 * emacs/uim-keymap.el
   - Support mouse wheel with modifier keys.
 
 
 r1348 at deepblue (orig r2846):  nosuke | 2006-01-08 19:07:36 +0900
 * emacs/uim-util.el
   - Apply workaround wrapper for vertical-motion to Emacs-21.3.50.
 
 
 r1349 at deepblue (orig r2847):  nosuke | 2006-01-08 19:08:52 +0900
 * emacs/uim.el
   - Support kbd-macro on XEmacs.
   - Fix undo-history after execute kbd-macro.
     undo-history of kbd-macro exection is now recorded 
    atomically.
 
 
 r1350 at deepblue (orig r2848):  nosuke | 2006-01-08 19:09:56 +0900
 * emacs/uim-candidate.el
   - Fix font-face related problem on XEmacs that the face 
    is sometimes applied to a line before the preedit strings.
 
 
 r1351 at deepblue (orig r2849):  nosuke | 2006-01-08 19:11:30 +0900
 * emacs/uim-preedit.el
 * emacs/uim-var.el
   - Abolish overwriting overlay for preedit strings.
 
 
 r1352 at deepblue (orig r2850):  nosuke | 2006-01-08 19:12:01 +0900
 * emacs/uim-keymap.el
 * emacs/uim-leim.el
 * emacs/uim.el
   - Abolish uim-copy-toggle-key to simplify the key bind.
 
 
 r1353 at deepblue (orig r2851):  nosuke | 2006-01-08 19:12:40 +0900
 ---(7)---
 * emacs/uim-candidate.el
 * emacs/uim-keymap.el
   - Remove unnecessary functions and comments.
 
 
 r1354 at deepblue (orig r2852):  nosuke | 2006-01-08 19:13:28 +0900
 * emacs/uim.el
   - Add uim-update-font to update font-faces when buffer font
    has been changed.
 
 
 r1355 at deepblue (orig r2853):  nosuke | 2006-01-08 19:18:54 +0900
 * emacs/callback.c
 * emacs/candidate.c
 * emacs/candidate.h
 * emacs/context.c
 * emacs/context.h
 * emacs/helper.c
 * emacs/helper.h
 * emacs/im.c
 * emacs/im.h
 * emacs/preedit.c
 * emacs/preedit.h
 * emacs/prop.c
 * emacs/prop.h
 * emacs/uim-candidate.el
 * emacs/uim-el-agent.c
 * 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
   - Keep the position of cursor whether unfocused or not
    while candidates or preedit strings are displayed.
   - Support prime-pseudo-mode-cursor partially.
   - Add a command to obtain current IM name.
   - Move focus/unfocus handling functions to context.c.
   - Reorganize uim_agent_context structure and its related 
    functions.
   - Fix memory leaking at buffer killing.
 
 



Property changes on: branches/r5rs
___________________________________________________________________
Name: svk:merge
   - 2f05256a-0800-0410-85e3-84fe06922419:/local/uim/trunk:2176
74100eb5-a104-0410-9326-fdab01523867:/branches/r5rs:267
fb73e508-85ea-0310-95c3-a85c473e0941:/trunk:2775
   + 2f05256a-0800-0410-85e3-84fe06922419:/local/uim/trunk:2176
74100eb5-a104-0410-9326-fdab01523867:/branches/r5rs:267
fb73e508-85ea-0310-95c3-a85c473e0941:/trunk:2853

Modified: branches/r5rs/emacs/callback.c
===================================================================
--- branches/r5rs/emacs/callback.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/callback.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -91,7 +91,7 @@
   debug_printf(DEBUG_NOTE, 
 			   "candidate_activate_cb (num=%d,limit=%d)\n", num, limit);
 
-  new_candidate(ua->context, ua->pe->cand, num, limit);
+  new_candidate(ua->context, ua->cand, num, limit);
 }
 
 
@@ -103,7 +103,7 @@
 
   debug_printf(DEBUG_NOTE, "candidate_select_cb (index: %d)\n", index);
 
-  ua->pe->cand->index = index;
+  ua->cand->index = index;
 }
 
 
@@ -114,7 +114,7 @@
 
   debug_printf(DEBUG_NOTE, "candidate_shift_page_cb\n");
 
-  shift_candidate_page(ua->context, ua->pe->cand, direction);
+  shift_candidate_page(ua->context, ua->cand, direction);
 }
 
 
@@ -125,7 +125,7 @@
 
   debug_printf(DEBUG_NOTE, "candidate_deactivate_cb\n");
 
-  clear_candidate(ua->pe->cand);
+  clear_candidate(ua->cand);
 }
 
 

Modified: branches/r5rs/emacs/candidate.c
===================================================================
--- branches/r5rs/emacs/candidate.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/candidate.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -36,6 +36,17 @@
 
 #include "candidate.h"
 
+candidate_info *
+create_candidate()
+{
+  candidate_info *cand;
+
+  cand = (candidate_info *)malloc(sizeof(candidate_info));
+  cand->valid = 0;
+
+  return cand;
+}
+
 int
 new_candidate(uim_context context, candidate_info *cand, int num, int limit)
 {
@@ -44,7 +55,6 @@
 
   if (cand->valid) clear_candidate(cand);
 
-
   cand->valid = 1;
 
   cand->index = 0; 
@@ -65,14 +75,17 @@
 }
 
 
-void
+int
 show_candidate(candidate_info *cand)
 {
   int i;
   int page;
   int index;
 
-  if (!cand->valid || cand->num == 0) return;
+  if (cand->num == 0) {
+	a_printf("( e )");
+	return 0;
+  }
 
   index = cand->index;
   page = index / cand->disp_limit;
@@ -102,6 +115,8 @@
   }
 
   a_printf(") ");
+
+  return 1;
 }
 
 

Modified: branches/r5rs/emacs/candidate.h
===================================================================
--- branches/r5rs/emacs/candidate.h	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/candidate.h	2006-01-10 12:46:23 UTC (rev 2882)
@@ -59,12 +59,15 @@
 } candidate_info;
 
 
+candidate_info *create_candidate(void);
+
 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);
+int show_candidate(candidate_info *cand);
 
-void shift_candidate_page(uim_context context, candidate_info *cand, int direction);
+void shift_candidate_page(uim_context context, candidate_info *cand, 
+						  int direction);
 
 #endif

Modified: branches/r5rs/emacs/context.c
===================================================================
--- branches/r5rs/emacs/context.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/context.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -64,7 +64,7 @@
   debug_printf(DEBUG_NOTE, "update_context_encoding\n");
 
   /* discard current context */
-  clear_candidate(ua->pe->cand);
+  clear_candidate(ua->cand);
   clear_preedit(ua->pe);
   uim_release_context(ua->context);
   
@@ -92,6 +92,8 @@
 }
 
 
+
+
 uim_agent_context *
 switch_context_im(uim_agent_context *ua, const char *im, const char *encoding)
 {
@@ -209,19 +211,10 @@
   else
 	ret->im = NULL;
 
-  ret->pe = (preedit *)malloc(sizeof(preedit));
+  ret->pe = create_preedit();
+  ret->cand = create_candidate();
+  ret->prop = create_prop();
 
-  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;
@@ -262,35 +255,35 @@
 
 /* release context from context list */
 int
-release_uim_agent_context(int id)
+release_uim_agent_context(int context_id)
 {
   uim_agent_context_list *ptr;
   
   for (ptr = agent_context_list_head; ptr != NULL; ptr = ptr->next) {
-	if (ptr->agent_context->context_id == id) {
+	if (ptr->agent_context->context_id == context_id) {
 
-	  preedit_buffer *p, *ptmp;
+	  uim_agent_context *ua = ptr->agent_context;
 
-	  if (current == ptr->agent_context)
-		current = NULL;
+	  /* clear current */
+	  if (current == ua)
+		clear_current_uim_agent_context();
 	  
 	  /* release */
-	  uim_release_context(ptr->agent_context->context);
+	  uim_release_context(ua->context);
 
-	  clear_candidate(ptr->agent_context->pe->cand);
-	  free(ptr->agent_context->pe->cand);
+	  /* clear candidate */
+	  clear_candidate(ua->cand);
+	  free(ua->cand);
 
-	  p = ptr->agent_context->pe->head; 
+	  /* clear preedit */
+	  clear_preedit(ua->pe);
+	  free(ua->pe);
 
-	  while (p) {
-	  	ptmp = p;
-		p = p->next;
-		if (ptmp->str) free(ptmp->str);
-		free (ptmp);
-	  }
+	  /* free others */
+	  free(ua->encoding);
+	  free(ua->im);
+	  free(ua->prop);
 
-	  free(ptr->agent_context->encoding);
-
 	  /* rebuild list */
 	  if (ptr->next != NULL)
 		ptr->next->prev = ptr->prev;
@@ -304,7 +297,7 @@
 
 	  free(ptr);
 
-	  return id;
+	  return context_id;
 	}
   }
 
@@ -313,6 +306,48 @@
 
 
 
+
+
+int
+set_current_uim_agent_context(uim_agent_context *ua)
+{
+  debug_printf(DEBUG_NOTE, "set_current_context\n");
+
+  if (ua == NULL || ua->context == NULL) {
+	debug_printf(DEBUG_ERROR, "set_current_context: invalid context\n");
+	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;
+}
+
+
+int
+clear_current_uim_agent_context(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;
+}
+
+
+
 /* handle configuration change */
 void
 update_context_configuration(uim_agent_context *ua)
@@ -336,3 +371,44 @@
   update_context_encoding(ua);
 
 }
+
+
+int
+show_preedit_uim_agent_context(uim_agent_context *ua)
+{
+  if (ua == NULL || !ua->pe->valid) 
+	return -1;
+  else
+	return show_preedit(ua->pe);
+}
+
+
+int
+show_candidate_uim_agent_context(uim_agent_context *ua)
+{
+  if (ua == NULL || !ua->cand->valid)
+	return -1;
+  else
+	return show_candidate(ua->cand);
+}
+
+
+int
+show_prop_uim_agent_context(uim_agent_context *ua)
+{
+  if (ua == NULL || !ua->prop->valid)
+	return -1;
+  else
+	return show_prop(ua->prop);
+}
+
+
+int
+show_im_uim_agent_context(uim_agent_context *ua)
+{
+  if (ua == NULL)
+	return -1;
+  else
+	return show_im(ua->im);
+}
+

Modified: branches/r5rs/emacs/context.h
===================================================================
--- branches/r5rs/emacs/context.h	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/context.h	2006-01-10 12:46:23 UTC (rev 2882)
@@ -57,6 +57,7 @@
   char *encoding;
   char *im;
   preedit *pe;
+  candidate_info *cand;
   property *prop;
 } uim_agent_context;
 
@@ -79,8 +80,16 @@
 uim_agent_context *switch_context_im(uim_agent_context *ua, const char *im,
 									 const char *encoding);
 
+int set_current_uim_agent_context(uim_agent_context *ua);
+int clear_current_uim_agent_context(void);
+
 void update_context_configuration(uim_agent_context *ua);
 
+int show_preedit_uim_agent_context(uim_agent_context *ua);
+int show_candidate_uim_agent_context(uim_agent_context *ua);
+int show_prop_uim_agent_context(uim_agent_context *ua);
+int show_im_uim_agent_context(uim_agent_context *ua);
+
 /* current focused context */
 extern uim_agent_context *current;
 

Modified: branches/r5rs/emacs/helper.c
===================================================================
--- branches/r5rs/emacs/helper.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/helper.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -232,7 +232,7 @@
 
 	  if (current_exist) {
 		debug_printf(DEBUG_NOTE, " focus_in\n"); 
-		if (current) unfocused();
+		if (current) clear_current_uim_agent_context();
 	  } else {
 		debug_printf(DEBUG_NOTE, " ignored helper message: %s\n", message);
 	  }
@@ -315,40 +315,3 @@
 }
 
 
-/* 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;
-}
-

Modified: branches/r5rs/emacs/helper.h
===================================================================
--- branches/r5rs/emacs/helper.h	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/helper.h	2006-01-10 12:46:23 UTC (rev 2882)
@@ -56,7 +56,4 @@
 
 void helper_handler(void);
 
-int focused(uim_agent_context *ua);
-int unfocused(void);
-
 #endif

Modified: branches/r5rs/emacs/im.c
===================================================================
--- branches/r5rs/emacs/im.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/im.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -79,8 +79,18 @@
 }
 
 
+int
+show_im(const char *im)
+{
+  if (im == NULL) {
+	a_printf(" ( e ) ");
+	return 0;
+  } else {
+	a_printf(" ( i \"%s\" ) ", im); 
+	return 1;
+  }
+}
 
-
 /* show supported IM engines */
 int
 list_im_engine(void)

Modified: branches/r5rs/emacs/im.h
===================================================================
--- branches/r5rs/emacs/im.h	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/im.h	2006-01-10 12:46:23 UTC (rev 2882)
@@ -50,6 +50,9 @@
 extern char *default_engine_name;
 
 void output_default_im_engine(void);
+
+int show_im(const char *im);
+
 int list_im_engine(void);
 int check_im_name(const char *imname);
 

Modified: branches/r5rs/emacs/preedit.c
===================================================================
--- branches/r5rs/emacs/preedit.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/preedit.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -36,11 +36,24 @@
 
 #include "preedit.h"
 
+preedit *
+create_preedit()
+{
+  preedit *pe;
+  pe = (preedit *)malloc(sizeof(preedit));
+  pe->valid = 0;
+  pe->head = pe->tail = NULL;
+
+  return pe;
+}
+
 void
 add_preedit(preedit *pe, int attr, const char *str)
 {
   preedit_buffer *pb;
 
+  pe->valid = 1;
+
   pb = (preedit_buffer *)malloc(sizeof(preedit_buffer));
 
   if (pe->head == NULL) {
@@ -51,7 +64,6 @@
 	pe->tail = pb;
   }
 
-
   if (strlen(str) > 0) {
 	pb->str = (char *)malloc(strlen(str) + 1);
 	strcpy(pb->str, str);
@@ -70,6 +82,8 @@
 {
   preedit_buffer *p, *ptmp;
 
+  pe->valid = 0;
+
   p = pe->head;
 
   while (p) {
@@ -124,3 +138,4 @@
   return 1;
 }
 
+

Modified: branches/r5rs/emacs/preedit.h
===================================================================
--- branches/r5rs/emacs/preedit.h	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/preedit.h	2006-01-10 12:46:23 UTC (rev 2882)
@@ -54,13 +54,14 @@
 } preedit_buffer;
 
 typedef struct preedit {
+  int valid;
   int length;
   preedit_buffer *head;
   preedit_buffer *tail;
-  candidate_info *cand;
+  /*  candidate_info *cand;*/
 } preedit;
 
-
+preedit *create_preedit(void);
 void add_preedit(preedit *pe, int attr, const char *str);
 void clear_preedit(preedit *pe);
 int show_preedit(preedit *pe);

Modified: branches/r5rs/emacs/prop.c
===================================================================
--- branches/r5rs/emacs/prop.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/prop.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -36,10 +36,29 @@
 
 #include "prop.h"
 
+property *
+create_prop()
+{
+  property *prop;
 
+  prop = (property *)malloc(sizeof(property));
+
+  prop->valid = 0;
+
+  prop->list = NULL;
+  prop->label = NULL;
+  prop->list_update = 0;
+  prop->label_update = 0;
+
+  return prop;
+}
+
 void
 update_prop_list(property *prop, const char *str)
 {
+
+  prop->valid = 1;
+
   if (prop->list != NULL) free(prop->list);
 
   prop->list = strdup(str);
@@ -53,6 +72,8 @@
 void
 update_prop_label(property *prop, const char *str)
 {
+  prop->valid = 1;
+
   if (prop->label != NULL) free(prop->label);
 
   prop->label = strdup(str);
@@ -93,8 +114,8 @@
 }
 
 
-void
-output_prop_list(property *prop, const char *im)
+int
+show_prop(property *prop)
 {
   char *buf;
   char *p[4];
@@ -103,14 +124,12 @@
 
   if (prop->list == NULL) {
 	debug_printf(DEBUG_ERROR, "no prop_list\n");
-	return;
+	a_printf(" ( e ) ");
+	return 0;
   }
 
+  a_printf(" ( l ");
 
-  if (im)
-	a_printf(" ( l \"%s\"", im);
-  else
-	a_printf(" ( l \"\" ");
 
   buf = (char *)malloc(strlen(prop->list) + 1);
   strcpy(buf, prop->list);
@@ -138,9 +157,10 @@
 
   free(buf);
 
-
   a_printf(" ) ");
 
+  return 1;
+
 }
 
 

Modified: branches/r5rs/emacs/prop.h
===================================================================
--- branches/r5rs/emacs/prop.h	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/prop.h	2006-01-10 12:46:23 UTC (rev 2882)
@@ -51,19 +51,22 @@
 
 /* keep only prop_list (prpo_label is buggy...)  */
 typedef struct property {
+  int valid;
   int list_update;
   int label_update;
   char *list;
   char *label;
 } property;
 
+property *create_prop(void);
+
 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);
+int show_prop(property *prop);
 
 
 #endif

Modified: branches/r5rs/emacs/uim-candidate.el
===================================================================
--- branches/r5rs/emacs/uim-candidate.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-candidate.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -59,6 +59,8 @@
 			       (if uim-candidate-display-frame ?- 32))
 		  uim-candidate-page-label))
 
+    ;; make mark for chasing
+    (setq mark-cursor (point-marker))
 
     (goto-char uim-candidate-start)
 
@@ -71,15 +73,6 @@
 	  (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)
@@ -201,9 +194,20 @@
 		      (goto-char vhead)
 		      (delete-region vhead (+ vhead (length linetmp)))
 			
+		      (when uim-xemacs
+			(insert " ")
+			(remove-text-properties (- (point) 1) (point)
+						'(face nil))
+			(goto-char (- (point) 1)))
+
 		      (insert (concat padding 
 				      candstr
-				      overflow)))
+				      overflow))
+
+		      (when uim-xemacs
+			(delete-char 1))
+		      
+		      )
 		
 		    (uim-set-candidate-face candidx candsel 
 					    (+ vhead (length padding))
@@ -260,7 +264,7 @@
 	(when mark-cursor
 	  
 	  (goto-char (marker-position mark-cursor))
-	  (setq uim-preedit-cursor (point))
+	  (setq uim-candidate-cursor (point))
 
 	  (set-marker mark-cursor nil)
 	  )
@@ -316,31 +320,6 @@
 	  (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* ((page-space (- (string-width page-total) 
 			    (string-width page-current)))
 	     (page-label (concat (if (> page-space 0) 
@@ -478,7 +457,7 @@
 ;; Put overlay
 ;;
 (defun uim-set-candidate-face (index selected begin length)
-  (let (face ol)
+  (let (face)
     (cond 
      (selected
       (setq face 'uim-candidate-selected-face))
@@ -640,6 +619,7 @@
 	(save-excursion
 	  (goto-char uim-candidate-original-start)
 	  (insert uim-candidate-original-str))
+
 	)
 
     ;; clear minibuffer

Modified: branches/r5rs/emacs/uim-el-agent.c
===================================================================
--- branches/r5rs/emacs/uim-el-agent.c	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-el-agent.c	2006-01-10 12:46:23 UTC (rev 2882)
@@ -53,52 +53,30 @@
 #include "uim-el-agent.h"
 
 
+/* called when owner buffer is killed  */
 static int
 cmd_release(int context_id)
 {
-  if (release_uim_agent_context(context_id) < 0)
-	return -1;
-  else
-	return 1;
+  return release_uim_agent_context(context_id);
 }
 
 
+
 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 (current) {
+	/* keep preedit if exist */
+	if (get_uim_agent_context(context_id) == current) {
+	  show_preedit_uim_agent_context(current);
+	  show_candidate_uim_agent_context(current);
   }
-	
-  if (ret > 0)
-	if (context_id != 0) {
-	  show_preedit(ua->pe);
-	  return 1;
+	/* unfocus anyway */
+	return clear_current_uim_agent_context();
 	} else {
-	  return 1;
+	return -1;
 	}
 
-  else
-	return -1;
 }
 
 
@@ -107,9 +85,9 @@
 {
   uim_agent_context *ua = get_uim_agent_context(context_id);
 
-  if (focused(ua) > 0) {
-	if (show_preedit(ua->pe))
-	  show_candidate(ua->pe->cand);
+  if (set_current_uim_agent_context(ua) > 0) {
+	show_preedit_uim_agent_context(ua);
+	show_candidate_uim_agent_context(ua);
 	return 1;
   } else {
 	return -1;
@@ -128,14 +106,15 @@
 	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);
+	show_preedit_uim_agent_context(ua);
+	show_candidate_uim_agent_context(ua);
 	return 1;
   } else {
 	return -1;
@@ -167,7 +146,7 @@
   if (ua != NULL) {
 	/* before reset, clear preedit and candidate */
 	clear_preedit(ua->pe);
-	clear_candidate(ua->pe->cand);
+	clear_candidate(ua->cand);
 	uim_reset_context(ua->context);
 	return 1;
   } else {
@@ -184,7 +163,7 @@
   if (im && encoding && strlen(im) > 0 
 	  && (ua = get_uim_agent_context(context_id))) {
 
-	focused(ua);
+	set_current_uim_agent_context(ua);
 
 	if (check_im_name(im)) {
 	  switch_context_im(ua, im, encoding);
@@ -250,12 +229,15 @@
 cmd_label(int context_id)
 {
 
-  if (current == NULL)
-	return -1;
-  else 
-	output_prop_list(current->prop, current->im);
-
+  if (current != NULL) {
+	show_im_uim_agent_context(current);
+	show_prop_uim_agent_context(current);
+	show_preedit_uim_agent_context(current);
+	show_candidate_uim_agent_context(current);
   return 1;
+  } else {
+	return -1;
+  }
 }
 
 
@@ -284,7 +266,8 @@
 
   if (current->prop->list_update) {
 	announce_prop_list_update(current->prop, current->encoding);
-	output_prop_list(current->prop, current->im);
+	show_im_uim_agent_context(current);
+	show_prop_uim_agent_context(current);
 	current->prop->list_update = 0;
   }
 
@@ -345,7 +328,6 @@
 	ret = cmd_error();
 
   check_prop_list_label();
-
   check_default_engine();
 
   return ret;
@@ -478,12 +460,12 @@
 static int
 process_keyvector(int serial, int cid, uim_key ukey, const char *keyname)
 {
-  int ret;
+  int ret, ret2;
 
   if (current == NULL || 
 	  (current != NULL && current->context_id != cid)) {
 
-	if (focused(get_uim_agent_context(cid)) < 0) {
+	if (set_current_uim_agent_context(get_uim_agent_context(cid)) < 0) {
 	  debug_printf(DEBUG_WARNING, "context %d not found\n", cid);
 	  return -1;
 	}
@@ -494,14 +476,13 @@
 	/* 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);
+	ret2 = uim_release_key(current->context, ukey.key, ukey.mod);
 
+	debug_printf(DEBUG_NOTE, "ret = %d, ret2 = %d\n", ret, ret2);
+
 	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;
 
@@ -527,26 +508,18 @@
 		}
 
 	  } else {
-		/* discard the key if preedit exists */
-		show_preedit(current->pe);
-		show_candidate(current->pe->cand);
-		/* a_printf(" ( n ) "); */
+	  show_preedit_uim_agent_context(current);
+	  show_candidate_uim_agent_context(current);
 	  }
 			
 	} 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 ) ");
+	show_preedit_uim_agent_context(current);
+	show_candidate_uim_agent_context(current);
+	a_printf(" ( n ) "); /* dummy */
   }
 
   check_prop_list_label();
-
   check_default_engine();
 
   return 1;
@@ -733,6 +706,7 @@
 		  a_printf(" ( a ) ");
 
 		a_printf(" )\n");
+		fflush(stdout);
 
 		continue;
 	  }
@@ -752,6 +726,7 @@
 	  }
 
   a_printf(" )\n");
+	  fflush(stdout);
 
 	  continue;
 	}
@@ -760,6 +735,7 @@
 	
   ERROR:
 	a_printf("( %d 0 ( x ) )\n", serial);
+	fflush(stdout);
   }
 
 

Modified: branches/r5rs/emacs/uim-key.el
===================================================================
--- branches/r5rs/emacs/uim-key.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-key.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -191,7 +191,9 @@
 	;; for transient-mark-mode
 	(setq deactivate-mark nil))
     
+    (unwind-protect    
     (cond ((or (keymapp bind)
+
 	       (and (not bind)
 		    (setq keyvectmp (uim-remove-shift keyvec))
 		    (setq keyvec keyvectmp)))
@@ -236,11 +238,11 @@
 	     (undefined))
 	   )
 	  )
-
     (if uim-emacs
 	(setq uim-deactivate-mark deactivate-mark))
     )
   )
+  )
 
 
 
@@ -501,9 +503,8 @@
 	    (and (vectorp keyvec)
 		 (= (length keyvec) 0)))
 	(setq keyvec uim-retry-keys))
+    (uim-debug (format "keyvec %s" keyvec))
 
-;    (uim-debug (format "keyvec %s" keyvec))
-
     (let* ((newvec (vconcat uim-stacked-key-vector keyvec))
 	   (keylist (append newvec nil))
 	   prefix
@@ -546,7 +547,7 @@
 			   0))
 	       )))))
 
-    ;;(uim-debug (format "stacked-key-vector: %s" uim-stacked-key-vector))
+    (uim-debug (format "stacked-key-vector: %s" uim-stacked-key-vector))
 
     (cond ((and uim-preedit-keymap-enabled
 		(uim-is-escape uim-stacked-key-vector)) ;; preedit ESC-ESC

Modified: branches/r5rs/emacs/uim-keymap.el
===================================================================
--- branches/r5rs/emacs/uim-keymap.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-keymap.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -50,7 +50,19 @@
     (triple drag)
     ))
 
+(defconst uim-generic-modifiers
+  '(
+    ()     
+    (shift)   
+    (control)
+    (meta)
+    (shift control)
+    (shift meta)
+    (control meta)
+    (shift control meta)  
+    ))
 
+
 (defconst uim-emacs-prefix-keys
   '(help-command
     2C-command
@@ -75,19 +87,20 @@
 ;; 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 mouse-4 mouse-5)))
-	(while mouse
-	  (let ((event (vector (append (car mouse-modifiers)
-				       (list (car mouse))))))
 
+  (mapcar
+   '(lambda (w)
+      (mapcar 
+       '(lambda (x)
+	  (mapcar 
+	   '(lambda (y)
+	      (let ((event (vector (append w x (list y)))))
 	    (define-key uim-mode-map event nil)
 	    (define-key uim-preedit-map event nil)
-	    )
-
-	  (setq mouse (cdr mouse))))
-      (setq mouse-modifiers (cdr mouse-modifiers))))
+	    ))
+	   '(mouse-1 mouse-2 mouse-3 mouse-4 mouse-5)))
+       uim-mouse-modifiers))
+   uim-generic-modifiers)
   
   (define-key uim-mode-map [vertical-scroll-bar] nil)
   (define-key uim-mode-map [mode-line] nil)
@@ -256,37 +269,11 @@
   )
 
 
-;; (defun uim-mode-keymap-enabled ()
-;;   (eq (cdr (assq 'uim-mode minor-mode-map-alist))
-;;       uim-mode-map))
 
-;; (defun uim-preedit-keymap-enabled ()
-;;   (eq (cdr (assq 'uim-mode minor-mode-map-alist))
-;;       uim-preedit-map))
-
-
-;;
-;; 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)
 
 

Modified: branches/r5rs/emacs/uim-leim.el
===================================================================
--- branches/r5rs/emacs/uim-leim.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-leim.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -58,9 +58,6 @@
 ;;  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)
@@ -140,9 +137,6 @@
   (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)

Modified: branches/r5rs/emacs/uim-preedit.el
===================================================================
--- branches/r5rs/emacs/uim-preedit.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-preedit.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -45,16 +45,12 @@
   (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)
+    (setq uim-preedit-current-sentence-start nil)
       
       (let ((preedit-blocks preedit) block-start-point)
 
-	(setq uim-preedit-start (point))
-
 	(mapcar
 	 '(lambda (x)
 	    (let ((preedit-flag (format "%s" (car x)))
@@ -64,9 +60,10 @@
 	      ;;  i.e. head of the block
 	      (if (string-match "c" preedit-flag)
 		  (if (> (length preedit-str) 0)
-		      (setq uim-candidate-start (point))
+		    (setq uim-preedit-current-sentence-start (point))
 		    ;; workaround for uim-prime 
-		    (setq uim-candidate-start block-start-point)))
+		  (setq uim-preedit-current-sentence-start
+			block-start-point)))
 	    
 	      (setq block-start-point (point))
 
@@ -88,13 +85,6 @@
 
 		  (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))))
 		  )
 		)
 	      
@@ -112,19 +102,16 @@
       )
 
     ;; if "c" flag not found in preedit 
-    (if (not uim-candidate-start)
-	(progn
-	  (setq uim-candidate-start uim-preedit-start)
+  (if (not uim-preedit-current-sentence-start)
+      (setq uim-preedit-current-sentence-start uim-preedit-start))
 	  (if (not uim-preedit-cursor)
-	      (setq uim-preedit-cursor uim-preedit-end))))
+      (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-preedit-overlap
+	(uim-vertical-distance uim-preedit-current-sentence-start
+			       uim-preedit-cursor))
 
-  (setq uim-buffer-read-only buffer-read-only)
-  (setq buffer-read-only t)
 
   )
 
@@ -135,21 +122,11 @@
 
   (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)

Modified: branches/r5rs/emacs/uim-util.el
===================================================================
--- branches/r5rs/emacs/uim-util.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-util.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -92,10 +92,8 @@
 ;; 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")))
+  (if (and uim-emacs
+	   (= emacs-major-version 21))
       (uim-vertical-motion-exec n)
     (vertical-motion n)))
 
@@ -162,6 +160,7 @@
 ;; Replace tabs and spaces.
 ;;
 (defun uim-tab-pad-space (start end)
+  (uim-debug (format "uim-tab-pad-space %s %s" start end))
   (let (org lstart lend (endorg end) tabspace)
     (setq org (point))
     (save-excursion
@@ -299,4 +298,11 @@
     ))
 
 
+(defun uim-goto-char (pt)
+  (uim-debug (format "uim-goto-char: %s" pt))
+  (set-window-point (get-buffer-window (current-buffer)) pt))
+
+(defun uim-point ()
+  (window-point (get-buffer-window (current-buffer))))
+
 (provide 'uim-util)

Modified: branches/r5rs/emacs/uim-var.el
===================================================================
--- branches/r5rs/emacs/uim-var.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim-var.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -34,7 +34,7 @@
 ;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ;;
 
-(defconst uim-el-version "0.0.6-beta4")
+(defconst uim-el-version "0.0.6-beta6")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -284,6 +284,10 @@
 
 (uim-deflocalvar uim-emulation-mode-map-alists nil)
 
+
+;;
+(uim-deflocalvar uim-original-cursor nil)
+
 ;; preedit string is displayed or not
 (uim-deflocalvar uim-preedit-displayed nil)
 
@@ -299,9 +303,8 @@
 
 (uim-deflocalvar uim-preedit-position-list '())
 
-(uim-deflocalvar uim-preedit-overlays '())
+(uim-deflocalvar uim-preedit-current-sentence-start nil)
 
-
 ;; freeze flag (to save font property)
 (uim-deflocalvar uim-buffer-frozen nil)
 
@@ -314,6 +317,7 @@
 ;; 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)
+(uim-deflocalvar uim-preedit-overlap 0)
 ;; original data under candidate
 (uim-deflocalvar uim-candidate-original-str nil)
 (uim-deflocalvar uim-candidate-original-start nil)
@@ -322,6 +326,8 @@
 ;; list of overlays of candidate string
 (uim-deflocalvar uim-candidate-overlays '())
 
+(uim-deflocalvar uim-candidate-cursor nil)
+
 (uim-deflocalvar uim-show-candidate-upward nil)
 
 

Modified: branches/r5rs/emacs/uim.el
===================================================================
--- branches/r5rs/emacs/uim.el	2006-01-10 12:16:37 UTC (rev 2881)
+++ branches/r5rs/emacs/uim.el	2006-01-10 12:46:23 UTC (rev 2882)
@@ -126,6 +126,8 @@
 ;;
 (defun uim-update-current-engine (engine)
 
+  (setq engine (car engine))
+
   (uim-debug (format "update-current-engine: %s" engine))
 
   (when (not (equal uim-current-im-engine engine))
@@ -200,18 +202,18 @@
 ;;
 (defun uim-focused ()
   (uim-change-process-encoding uim-decoding-code)
+  (setq uim-focused-buffer (current-buffer))
   (uim-do-send-recv-cmd (format "%d FOCUSED" uim-context-id))
-  (setq uim-focused-buffer (current-buffer))
   )
 
 ;;
 ;; Unfocused
 ;;
 (defun uim-unfocused ()
+  (setq uim-focused-buffer nil)
   ;; 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)
   )
 
 
@@ -247,32 +249,23 @@
     (setq uim-recent-buffer (current-buffer))
     
     ;; remove Uim focus from previous buffer
-    (if (and (bufferp uim-focused-buffer)
+    (when (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))))
+	(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))))
-
+    (when (and uim-initialized uim-mode)
+      (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 ))
-
+    (uim-debug (format "current-buffer %s / uim-focused-buffer %s" 
+		       (current-buffer) uim-focused-buffer ))
     )
   )
 
@@ -386,9 +379,6 @@
   )
 
 
-(defun uim-update-keybind ()
-  (uim-copy-toggle-key 'uim-mode))
-
 ;;
 ;; Activate uim
 ;;
@@ -408,7 +398,6 @@
 
 	;; enable and update keymap
 	(uim-enable-mode-keymap)
-	(uim-update-keybind)
 
 	;; focus to current context
 	(uim-focused)
@@ -435,6 +424,8 @@
 
   (uim-unfocused)
 
+  (uim-process-agent-output '(("e")))
+
   ;; update mode-line
   (force-mode-line-update)
 
@@ -470,6 +461,8 @@
 ;;
 (defun uim-change-major-mode ()
 
+  (uim-debug "uim-change-major-mode")
+
   (when uim-initialized
        (uim-unfocused)
        (uim-delete-context))
@@ -583,13 +576,9 @@
 ;; Update property label
 ;;
 (defun uim-update-label (label)
-  ;; label: ( "current" ("label_abbr"  "label") ... )
+  ;; label: ( ("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))
 
@@ -779,6 +768,7 @@
     (if (uim-send-cmd cmd serial)
 	(uim-wait-recv serial))))
 
+
 ;;
 ;; Save face property
 ;;
@@ -856,6 +846,26 @@
 
 
 ;;
+;; Update font 
+;;
+(defun uim-update-font ()
+  (mapcar 
+   '(lambda (x)
+      (let ((font (or (cdr (assq 'font (frame-parameters)))
+		      (face-font 'default))))
+	(set-face-font x font)))
+		     
+   '(uim-preedit-face 
+     uim-preedit-underline-face 
+     uim-preedit-highlight-face
+     uim-preedit-highlight-underline-face
+     uim-separator-face
+     uim-candidate-odd-face
+     uim-candidate-even-face
+     uim-candidate-selected-face
+     uim-candidate-nth-face)))
+
+;;
 ;; Lock appearance of buffer
 ;;
 (defun uim-freeze-buffer ()
@@ -1009,34 +1019,60 @@
 
 
 
+(defun uim-enter-preedit-mode ()
+  ;; change keymap and freeze faces at first time
+  (uim-enable-preedit-keymap)
+  (when (= (minibuffer-depth) 0)
+    (uim-freeze-buffer)
+    (setq uim-buffer-read-only buffer-read-only)
+    (setq buffer-read-only t))
+  )
 
+(defun uim-leave-preedit-mode ()
+  (uim-disable-preedit-keymap)
+  (uim-unfreeze-buffer)
+  (setq buffer-read-only uim-buffer-read-only)
+  )
+
+
+
 ;; process return expression from uim-el-agent 
 (defun uim-process-agent-output (str)
-  (let (preedit-existed
+  (catch 'process-agent-output
+    (let (;;(inhibit-quit t)
+	  preedit-existed
 	candidate-existed
-	key commit preedit candidate default label imlist)
+	  key commit preedit candidate default im label imlist ;;pc-exists
+	  )
+      
+      (uim-debug (format "%s" str))
+      
 
     (let ((modified (buffer-modified-p)))
+
       ;; remove candidate anyway
       (when uim-candidate-displayed
 	(setq candidate-existed t)
-	(uim-remove-candidate)
+	  (let ((inhibit-read-only t))
+	    (uim-remove-candidate))
 	(setq uim-candidate-displayed nil)
-	(goto-char uim-candidate-start))
+	  (uim-goto-char uim-preedit-start))
 
       ;; remove preedit anyway
       (when uim-preedit-displayed
 	(setq preedit-existed t)
-	(uim-remove-preedit)
+	  (let ((inhibit-read-only t))
+	    (uim-remove-preedit))
 	(setq uim-preedit-displayed nil)
-	(goto-char uim-preedit-start))
+	  (uim-goto-char uim-original-cursor))
 
+	;; restore cursor point
+	(when (and uim-preedit-keymap-enabled uim-original-cursor)
+	  (goto-char uim-original-cursor))
+
       ;; restore modified flag
       (set-buffer-modified-p modified))
 
-    (uim-debug (format "%s" str))
-
-
     (mapcar 
      '(lambda (x) 
 	(let ((rcode (car x))
@@ -1061,14 +1097,15 @@
 		((string= rcode "d") ;; default engine
 		 (setq default (car rval))
 		 )
+		  ((string= rcode "i") ;; current im
+		   (setq im rval)
+		   )
 		((string= rcode "l") ;; label
 		 (setq label rval)
 		 )
 		((string= rcode "L") ;; IM list
 		 (setq imlist rval)
 		 )
-		((string= rcode "e") ;; IM list
-		 )
 		)
 	  )) 
      str)
@@ -1077,6 +1114,9 @@
     (when default
       (uim-update-default-engine default))
 
+      (when im
+	(uim-update-current-engine im))
+
     (when label
       (uim-update-label label))
 
@@ -1085,13 +1125,19 @@
 
 
     (if commit
+
+	  ;; insert committed strings
+	  (let ((inhibit-read-only t)
+		(buffer-frozen uim-buffer-frozen))
+	    (if uim-buffer-frozen
+		(uim-unfreeze-buffer))
+
 	(let ((buffer-undo-list-saved uim-buffer-undo-list-saved))
 	  ;; restore undo history before committing
 	  (when buffer-undo-list-saved
-	    (uim-debug "call restore undo")
+		(uim-debug "call restore undo 1")
 	    (uim-restore-undo))
 
-	  ;; insert committed strings
 	  (mapcar
 	   '(lambda (x) 
 	      (insert x)
@@ -1101,11 +1147,47 @@
 
 	  ;; save undo hisotry again
 	  (when buffer-undo-list-saved
-	    (uim-debug "call save undo")
+		(uim-debug "call save undo 1")
 	    (uim-save-undo)))
+
+	    (if buffer-frozen
+		(uim-freeze-buffer))
       )
 
+	)
 
+
+      (if key
+	  (let (keyproc-done
+		(buffer-undo-list-saved uim-buffer-undo-list-saved))
+	    (when buffer-undo-list-saved
+	      (uim-debug "call restore undo 2")
+	      (uim-restore-undo))
+	    ;; process raw key
+	    ;;  C-o is also processed here ... orz
+	    (let ((inhibit-read-only t))
+	      (unwind-protect
+		  (progn
+		    (uim-process-keyvec key)
+		    (setq keyproc-done t))
+		(when (not keyproc-done)
+		  (uim-leave-preedit-mode)
+		  (uim-debug "leave preedit mode forcibly")
+		  )
+		)
+	      ;; following expressions will not be evaluated
+	      ;; when an error occurs in this function...
+      )
+	    (if (not uim-mode)
+		(throw 'process-agent-output t))
+	    ;; save undo hisotry again
+	    (when buffer-undo-list-saved
+	      (uim-debug "call save undo 2")
+	      (uim-save-undo))))
+
+      (setq uim-original-cursor (uim-point))
+
+
     (if (or preedit candidate)
 	;; process preedit/candidate
 	(let ((modified (buffer-modified-p)))
@@ -1113,52 +1195,55 @@
 	  ;; save undo list if not saved
 	  (when (not uim-buffer-undo-list-saved)
 	    (uim-flush-concat-undo)
-	    (uim-debug "call save undo")
+	      (uim-debug "call save undo 3")
 	    (uim-save-undo))
 
 	  ;; change keymap and freeze faces at first time
 	  (when (not uim-preedit-keymap-enabled)
-	    (uim-debug "call enable keymap")
-	    (uim-enable-preedit-keymap)
-	    (if (= (minibuffer-depth) 0)
-		(uim-freeze-buffer)))
+	      (uim-enter-preedit-mode))
 
+	    (setq uim-preedit-start uim-original-cursor)
+	    (setq uim-preedit-overlap 0)
+	    (setq uim-preedit-current-sentence-start uim-preedit-start)
+	    (setq uim-preedit-cursor uim-preedit-start)
+
 	  ;; show preedit
-	  (if preedit
-	      (progn
+	    (when preedit
 		(setq uim-preedit-displayed t)
-		(uim-insert-preedit preedit))
-	    (setq uim-candidate-start (point))
-	    (setq uim-candidate-vofs 0)
-	    (setq uim-preedit-cursor (point)))
+	      (let ((inhibit-read-only t))
+		(uim-insert-preedit preedit)
+		))
 
+	    (uim-goto-char uim-preedit-cursor)
+
+	    (setq uim-candidate-cursor (uim-point))
+
 	  ;; show candidate
-	  (if candidate
-	      (progn
+	    (when (and candidate
+		       (uim-check-candidate-space)
+		       (eq uim-focused-buffer (current-buffer)))
 		(setq uim-candidate-displayed t)
-		(if (uim-check-candidate-space)
-		    (uim-show-candidate candidate))))
+	      (setq uim-candidate-start uim-preedit-current-sentence-start)
+	      (setq uim-candidate-vofs uim-preedit-overlap)
+	      (let ((inhibit-read-only t))
+		(uim-show-candidate candidate)))
 	  
-	  (set-buffer-modified-p modified)
+	    (uim-goto-char uim-candidate-cursor)
 
+	    (set-buffer-modified-p modified)
 	  )
 
       ;; no preedit/candidate
 
-      ;; restore undo-list before raw key processing
+	;; restore undo-list if saved
       (when uim-buffer-undo-list-saved
-	(uim-debug "call restore undo")
+	  (uim-debug "call restore undo 3")
 	(uim-restore-undo))
 
       ;; no raw-key and no preedit/candidate
       (when uim-preedit-keymap-enabled
-	(uim-debug "call disable preedit keymap")
-	(uim-disable-preedit-keymap)
-	(uim-unfreeze-buffer))
+	  (uim-leave-preedit-mode))
 
-      (if key
-	  ;; process raw key
-	  (uim-process-keyvec key))
       )
 
     ;; scroll buffer after candidate removed
@@ -1170,9 +1255,6 @@
       (setq uim-window-force-scrolled nil)
       (recenter))
 
-    ;; move cursor
-    (when (or uim-preedit-displayed uim-candidate-displayed)
-      (goto-char uim-preedit-cursor))
 
     (if (not uim-send-recv-again)
 	(when label 
@@ -1180,13 +1262,15 @@
 	  (uim-update-im-label))
       (setq uim-send-recv-again nil))
 
+      (uim-debug (format "uim-original-cursor %s" uim-original-cursor))
+      (uim-debug "process-agent-output done")
     ))
+  )
 
 
 
 
 
-
 ;;
 ;; Get available IM list from uim-el-agent
 ;;
@@ -1253,11 +1337,17 @@
   (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)
-
+  ;; advice to support kbd macro
+  (defadvice call-last-kbd-macro (around uim-call-last-kbd-macro activate)
+    (let ((current-uim-mode uim-mode))
+      (setq uim-mode nil)
+      (unwind-protect
+	  ad-do-it
+	(setq uim-mode current-uim-mode))))
   )
 
 
+
 ;;
 ;; Toggle uim
 ;;



More information about the uim-commit mailing list