[uim-commit] r3104 - trunk/emacs

nosuke at freedesktop.org nosuke at freedesktop.org
Wed Feb 8 00:52:53 PST 2006


Author: nosuke
Date: 2006-02-08 00:52:49 -0800 (Wed, 08 Feb 2006)
New Revision: 3104

Modified:
   trunk/emacs/context.c
   trunk/emacs/context.h
   trunk/emacs/encoding.c
   trunk/emacs/helper.c
   trunk/emacs/im.c
   trunk/emacs/uim-el-agent.c
   trunk/emacs/uim-el-agent.h
   trunk/emacs/uim-leim.el
   trunk/emacs/uim-var.el
   trunk/emacs/uim.el
Log:
* emacs/context.c
* emacs/context.h
* emacs/encoding.c
* emacs/helper.c
* emacs/im.c
* emacs/uim-el-agent.c
* emacs/uim-el-agent.h
* emacs/uim-leim.el
* emacs/uim-var.el
* emacs/uim.el
 - Simplify language and encoding managing.



Modified: trunk/emacs/context.c
===================================================================
--- trunk/emacs/context.c	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/context.c	2006-02-08 08:52:49 UTC (rev 3104)
@@ -93,19 +93,16 @@
 
 
 
-
 uim_agent_context *
-switch_context_im(uim_agent_context *ua, const char *im, const char *encoding)
+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;
-  }
+  encoding = get_im_encoding(im);
 
+  /* update IM name */
   if (ua->im) free(ua->im);
 
   if (im)
@@ -116,8 +113,7 @@
   if (strcmp(ua->encoding, encoding) == 0) {
 	/* encodings are same */
 
-	debug_printf(DEBUG_NOTE,
-				 "same encoding %s %s\n", ua->im, im);
+	debug_printf(DEBUG_NOTE, "same encoding %s %s\n", ua->im, im);
 
 	update_context_im(ua);
 

Modified: trunk/emacs/context.h
===================================================================
--- trunk/emacs/context.h	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/context.h	2006-02-08 08:52:49 UTC (rev 3104)
@@ -77,8 +77,7 @@
 
 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);
+uim_agent_context *switch_context_im(uim_agent_context *ua, const char *im);
 
 int set_current_uim_agent_context(uim_agent_context *ua);
 int clear_current_uim_agent_context(void);

Modified: trunk/emacs/encoding.c
===================================================================
--- trunk/emacs/encoding.c	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/encoding.c	2006-02-08 08:52:49 UTC (rev 3104)
@@ -127,11 +127,12 @@
 
   debug_printf(DEBUG_NOTE, "get_im_encoding %s\n", im);
 
-  if (im_enc != NULL) {
+  if (im_enc && im_enc->encoding) {
 	debug_printf(DEBUG_NOTE, " encoding = %s\n", im_enc->encoding);
 	return im_enc->encoding;
   } else {
 	/*return NULL;*/
+	debug_printf(DEBUG_WARNING, " default encoding (%s)\n", default_encoding);
 	return default_encoding;
   }
 }

Modified: trunk/emacs/helper.c
===================================================================
--- trunk/emacs/helper.c	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/helper.c	2006-02-08 08:52:49 UTC (rev 3104)
@@ -114,7 +114,7 @@
   if (strcmp(request, "im_change_this_text_area_only") == 0) {
 
     if (current) {
-      switch_context_im(current, engine_name, get_im_encoding(engine_name));
+	  switch_context_im(current, engine_name);
 	  if(current->im) free(current->im);
 	  current->im = strdup(engine_name);
       uim_prop_label_update(current->context);
@@ -137,8 +137,7 @@
 	  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));
+		switch_context_im(ptr->agent_context, engine_name);
 
 		uim_prop_update_custom(ptr->agent_context->context,
 							   "custom-preserved-default-im-name",

Modified: trunk/emacs/im.c
===================================================================
--- trunk/emacs/im.c	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/im.c	2006-02-08 08:52:49 UTC (rev 3104)
@@ -56,6 +56,9 @@
 {
   if (default_engine_name)
 	a_printf(" ( d \"%s\" ) ", default_engine_name);
+  else
+	a_printf(" ( d \"%s\" ) ", 
+			 uim_get_default_im_name(setlocale(LC_ALL, NULL)));
 }
 
 
@@ -101,8 +104,8 @@
 
   context = uim_create_context(NULL, "UTF-8", NULL, NULL, NULL, NULL);
 
-  a_printf(" ( L \"%s\" ", uim_get_default_im_name(setlocale(LC_ALL, NULL)));
-  
+  a_printf(" ( L ");
+
   for (i = 0 ; i < uim_get_nr_im(context); i++) {
 	char dummy_str[] = "";
 	const char *name, *lang, *language, *shortd, *encoding;

Modified: trunk/emacs/uim-el-agent.c
===================================================================
--- trunk/emacs/uim-el-agent.c	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/uim-el-agent.c	2006-02-08 08:52:49 UTC (rev 3104)
@@ -70,12 +70,12 @@
 	if (get_uim_agent_context(context_id) == current) {
 	  show_preedit_uim_agent_context(current);
 	  show_candidate_uim_agent_context(current);
-  }
+	}
 	/* unfocus anyway */
 	return clear_current_uim_agent_context();
-	} else {
+  } else {
 	return -1;
-	}
+  }
 
 }
 
@@ -111,7 +111,7 @@
 cmd_show(int context_id)
 {
   uim_agent_context *ua = get_uim_agent_context(context_id);
-  
+
   if (ua != NULL) {
 	show_preedit_uim_agent_context(ua);
 	show_candidate_uim_agent_context(ua);
@@ -156,17 +156,17 @@
 
 
 static int
-cmd_change(int context_id, const char *im, const char *encoding)
+cmd_change(int context_id, const char *im)
 {
   uim_agent_context *ua;
 
-  if (im && encoding && strlen(im) > 0 
+  if (im && strlen(im) > 0 
 	  && (ua = get_uim_agent_context(context_id))) {
 
 	set_current_uim_agent_context(ua);
 
 	if (check_im_name(im)) {
-	  switch_context_im(ua, im, encoding);
+	  switch_context_im(ua, im);
 	  return 1;
 	} else {
 	  return -1;	 
@@ -180,6 +180,8 @@
 static int
 cmd_list(void)
 {
+  output_default_im_engine();
+
   if (list_im_engine() > 0)
 	return 1;
   else
@@ -234,7 +236,7 @@
 	show_prop_uim_agent_context(current);
 	show_preedit_uim_agent_context(current);
 	show_candidate_uim_agent_context(current);
-  return 1;
+	return 1;
   } else {
 	return -1;
   }
@@ -313,7 +315,7 @@
   else if (strcmp(cmd, "RESET") == 0)
 	ret = cmd_reset(cid);
   else if (strcmp(cmd, "CHANGE") == 0)
-  	ret = cmd_change(cid, opt, opt2);
+  	ret = cmd_change(cid, opt);
   else if (strcmp(cmd, "LIST") == 0)
   	ret = cmd_list();
   else if (strcmp(cmd, "SETENC") == 0)
@@ -483,36 +485,36 @@
 	if (ret > 0) {
 	  /* uim did not process the key */
 
-		if (ukey.mod & UMod_Shift && ukey.key >= 0x41 && ukey.key <= 0x5a)
-		  ukey.mod &= ~UMod_Shift;
+	  if (ukey.mod & UMod_Shift && ukey.key >= 0x41 && ukey.key <= 0x5a)
+		ukey.mod &= ~UMod_Shift;
 
-		if (ukey.mod != 0 || ukey.key > 255) {
+	  if (ukey.mod != 0 || ukey.key > 255) {
 
-		  a_printf(" ( n [(");
+		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.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);
+		if (ukey.key > 255)
+		  a_printf("%s", keyname);
+		else
+		  a_printf("%d", ukey.key);
 
-		  a_printf(")] ) ");
+		a_printf(")] ) ");
 
-		} else {
-		  a_printf(" ( n [%d] ) ", ukey.key);
-		}
-
 	  } else {
-	  show_preedit_uim_agent_context(current);
-	  show_candidate_uim_agent_context(current);
+		a_printf(" ( n [%d] ) ", ukey.key);
 	  }
 			
 	} else {
+	  show_preedit_uim_agent_context(current);
+	  show_candidate_uim_agent_context(current);
+	}
+
+  } else {
 	/* ukey.key < 0 */
 	show_preedit_uim_agent_context(current);
 	show_candidate_uim_agent_context(current);
@@ -725,7 +727,7 @@
 		a_printf(" ( a ) ");   /* command ok */
 	  }
 
-  a_printf(" )\n");
+	  a_printf(" )\n");
 	  fflush(stdout);
 
 	  continue;

Modified: trunk/emacs/uim-el-agent.h
===================================================================
--- trunk/emacs/uim-el-agent.h	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/uim-el-agent.h	2006-02-08 08:52:49 UTC (rev 3104)
@@ -56,7 +56,7 @@
 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_change(int context_id, const char *im);
 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);

Modified: trunk/emacs/uim-leim.el
===================================================================
--- trunk/emacs/uim-leim.el	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/uim-leim.el	2006-02-08 08:52:49 UTC (rev 3104)
@@ -89,21 +89,20 @@
 (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))))
+  (mapcar
+   '(lambda (x)
+      (let* ((name (car x))
+	     (lang (uim-get-emacs-lang name)))
+	(when (and name lang)
+	  (setq im (uim-leim-make-im-name name))
+	  (register-input-method im lang 'uim-leim-activate "[Uim]"
+				 (concat "Uim " name))
 
-      (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)))))
+   uim-im-alist)
 
-	;; ( 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)

Modified: trunk/emacs/uim-var.el
===================================================================
--- trunk/emacs/uim-var.el	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/uim-var.el	2006-02-08 08:52:49 UTC (rev 3104)
@@ -34,7 +34,7 @@
 ;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ;;
 
-(defconst uim-el-version "0.0.6-beta6")
+(defconst uim-el-version "0.0.7")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -111,8 +111,8 @@
 (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
+;; ("UIM-Language" "Emacs-Language" Emacs-encoding "UIM-Encoding")
+(defvar uim-lang-code-alist
   '(("Japanese"              "Japanese"     euc-jp      "EUC-JP")
     ("Korean"                "Korean"       euc-kr      "EUC-KR")
     ("Chinese (Simplified)"  "Chinese-GB"   gb2312      "GB2312")
@@ -133,16 +133,6 @@
 
 
 
-;; 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.")
@@ -181,7 +171,7 @@
 
 ;; List of IM engine 
 ;; (looking up with IM name and obtain its language, encoding and so on)
-(defvar uim-im-list nil)
+(defvar uim-im-alist nil)
 
 ;; Current focused buffer
 ;;  if current-buffer has no Uim context, this should be nil
@@ -264,10 +254,6 @@
 ;; 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)
 

Modified: trunk/emacs/uim.el
===================================================================
--- trunk/emacs/uim.el	2006-02-08 01:30:33 UTC (rev 3103)
+++ trunk/emacs/uim.el	2006-02-08 08:52:49 UTC (rev 3104)
@@ -92,7 +92,7 @@
 ;; Validation IM
 ;;
 (defun uim-check-im (im)
-  (if (assoc im (cdr uim-im-list))
+  (if (assoc im uim-im-alist)
       t
     (message (format "uim.el: invalid IM engine: %s" im))))
 
@@ -135,7 +135,7 @@
     (run-hooks 'uim-update-current-engine-hook))
 
   ;; update current decoding code   
-  (let ((newcode (uim-get-emacs-code uim-current-im-engine)))
+  (let ((newcode (uim-get-emacs-encoding uim-current-im-engine)))
     (when (not (string= newcode uim-decoding-code))
       (setq uim-decoding-code newcode)
       (uim-change-process-encoding uim-decoding-code)))
@@ -168,7 +168,7 @@
     ;;    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))))
+     (format "%d NEW %s" id (uim-get-uim-encoding (uim-get-default-engine))))
     id))
 
 
@@ -294,37 +294,34 @@
   (set-process-coding-system uim-el-agent-process outcode 'iso-8859-1)
   )
 
+;; 
+;; Get IM information from uim-im-alist
 ;;
-;; 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-im-info (im field)
+  (nth field (or (assoc im uim-im-alist)
+		 (assoc "direct" uim-im-alist))))
 
-(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"))
+  (uim-get-im-info im 1))
 
 (defun uim-get-emacs-lang (im)
-  (or (uim-get-im-info im 'emacs-lang)
-      "ASCII"))
+  (uim-get-im-info im 2))
 
+(defun uim-get-emacs-encoding (im)
+  (uim-get-im-info im 3))
+
+(defun uim-get-uim-encoding (im)
+  (uim-get-im-info im 4))
+
+
 ;;
 ;; 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-change-process-encoding (uim-get-emacs-encoding im))
   (uim-do-send-recv-cmd 
-   (format "%d CHANGE %s %s" uim-context-id im (uim-get-uim-code im)))
+   (format "%d CHANGE %s" uim-context-id im))
 
   (if uim-default-im-prop
       (uim-prop-activate uim-default-im-prop)))
@@ -333,10 +330,9 @@
 ;;
 ;; 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))))
+(defun uim-set-encoding (im encoding)
+  (uim-do-send-recv-cmd 
+   (format "0 SETENC %s %s" im encoding)))
 
 
 
@@ -387,7 +383,8 @@
   (uim-debug "uim-mode-on")
 
   (if uim-mode
-      (message "uim.el: uim-mode is already activated. (buffer %s)" (current-buffer)))
+      (message "uim.el: uim-mode is already activated. (buffer %s)" 
+	       (current-buffer)))
 
   (if (not buffer-read-only)
       (progn 
@@ -551,24 +548,16 @@
 ;; Update IM list
 ;;
 (defun uim-update-imlist (imlist)
-  ;; imlist: default (engine lang_code Language explanation encoding)
+  ;; imlist: (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))))
-    )
+  (setq uim-im-alist 
+	(mapcar '(lambda (x) 
+		   (let ((im (nth 0 x))
+			 (lang-uim (nth 2 x)))
+		     (cons im
+			   (or (assoc lang-uim uim-lang-code-alist)
+			       (assoc "Other" uim-lang-code-alist)))))
+		imlist))
   )
 
 
@@ -1277,24 +1266,23 @@
 (defun uim-get-im-list ()
   (uim-do-send-recv-cmd (format "0 LIST")))
 
+(defun uim-initialize-im-alist ()
+  (uim-get-im-list))
 
 ;;
 ;; Initialize IM list and encoding
 ;;
 (defun uim-init-im-encoding ()
 
-  (uim-get-im-list)
+  (uim-initialize-im-alist)
 
   ;; 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)))))
+  (mapcar 
+   '(lambda (x)
+      (let ((im (car x)))
+	(uim-set-encoding im (uim-get-uim-encoding im))))
+   uim-im-alist))
 
-
-
 ;;
 ;; Called when entering into the mini-buffer
 ;;
@@ -1408,8 +1396,9 @@
   (when uim-initialized
     (if (not im)
 	(let (alist)
-	  (setq alist (mapcar (lambda (x) (cons (car x) (car x))) 
-			      (cdr uim-im-list)))
+	  (setq alist (mapcar '(lambda (x) 
+				 (cons (car x) (car x))) 
+			      uim-im-alist))
 	  (save-window-excursion
 	    (setq im (cdr (assoc
 			   (completing-read (concat "IM Engine: ") alist nil t)



More information about the uim-commit mailing list