[uim-commit] r3154 - trunk/emacs

nosuke at freedesktop.org nosuke at freedesktop.org
Thu Mar 2 10:50:54 PST 2006


Author: nosuke
Date: 2006-03-02 10:50:49 -0800 (Thu, 02 Mar 2006)
New Revision: 3154

Modified:
   trunk/emacs/prop.c
   trunk/emacs/uim-leim.el
   trunk/emacs/uim-var.el
   trunk/emacs/uim.el
Log:
* emacs/prop.c
* emacs/uim-leim.el
* emacs/uim-var.el
* emacs/uim.el
  - Improve IM status displayed on mode-line.



Modified: trunk/emacs/prop.c
===================================================================
--- trunk/emacs/prop.c	2006-03-02 05:21:12 UTC (rev 3153)
+++ trunk/emacs/prop.c	2006-03-02 18:50:49 UTC (rev 3154)
@@ -88,6 +88,8 @@
 
   snprintf(buf, len, PROP_LIST_FORMAT, encoding, prop->list);
 
+  debug_printf(DEBUG_NOTE, PROP_LIST_FORMAT, encoding, prop->list);
+
   uim_helper_send_message(helper_fd, buf);
 
   free(buf);
@@ -102,7 +104,9 @@
 {
   char *buf;
   char *head, *tail;
-  char *p[4];
+  char *p[6];
+  char *indication_id = NULL, *iconic_label =NULL, *label_string = NULL;
+  int check_leaf = 0;
   
   /* output new prop_list for Emacs */
 
@@ -120,6 +124,10 @@
 
   head = buf;
 
+#define PART_BRANCH "branch"
+#define PART_LEAF   "leaf"
+#define ACTION_ID_IMSW "action_imsw_"
+
   while (head && *head) { 
 
 	/* 
@@ -135,13 +143,40 @@
 	  break;
 
 	/* head always not equal NULL */
-	if (strlen(head) >= 6 && strncmp(head, "branch", 6) == 0) {
+	if (strlen(head) >= strlen(PART_BRANCH)
+		&& strncmp(head, PART_BRANCH, strlen(PART_BRANCH)) == 0) {
 	  if ((p[0] = strchr(head, '\t')) 
 		  && (p[1] = strchr(p[0] + 1, '\t'))
 		  && (p[2] = strchr(p[1] + 1, '\t'))) {
 		*p[0] = *p[1] = *p[2] = '\0';
-		a_printf(" ( \"%s\" \"%s\" \"%s\" ) ", p[0] + 1, p[1] + 1, p[2] + 1);
+		indication_id = p[0] + 1;
+		iconic_label = p[1] + 1;
+		label_string = p[2] + 1;
+
+		check_leaf = 1; /* check next leaf */
+		/*a_printf(" ( \"%s\" \"%s\" \"%s\" ) ", p[0] + 1, p[1] + 1, p[2] + 1);*/
 	  }
+	} else if (strlen(head) >= strlen(PART_LEAF) 
+			   && strncmp(head, PART_LEAF, strlen(PART_LEAF)) == 0) {
+	  if (check_leaf && indication_id && iconic_label && label_string) {
+		check_leaf = 0;
+		/* im_switcher detection */
+		if ((p[0] = strchr(head, '\t')) 
+			&& (p[1] = strchr(p[0] + 1, '\t'))
+			&& (p[2] = strchr(p[1] + 1, '\t'))
+			&& (p[3] = strchr(p[2] + 1, '\t'))
+			&& (p[4] = strchr(p[3] + 1, '\t'))
+			&& (p[5] = strchr(p[4] + 1, '\t')))
+		  *p[0] = *p[1] = *p[2] = *p[3] = *p[4] = *p[5] = '\0';
+
+		  if (strlen(p[4] + 1) >= strlen(ACTION_ID_IMSW)
+			  && strncmp(p[4] + 1, ACTION_ID_IMSW, strlen(ACTION_ID_IMSW)) == 0)
+			a_printf(" ( \"im-name\" \"%s\" \"%s\" \"%s\" ) ", 
+					 indication_id, iconic_label, label_string);
+		  else
+			a_printf(" ( \"im-mode\" \"%s\" \"%s\" \"%s\" ) ", 
+					 indication_id, iconic_label, label_string);
+	  }
 	}
 	head = tail + 1;
   }
@@ -152,6 +187,9 @@
 
   return 1;
 
+#undef PART_BRANCH
+#undef PART_LEAF
+#undef ACTION_ID_IMSW
 }
 
 

Modified: trunk/emacs/uim-leim.el
===================================================================
--- trunk/emacs/uim-leim.el	2006-03-02 05:21:12 UTC (rev 3153)
+++ trunk/emacs/uim-leim.el	2006-03-02 18:50:49 UTC (rev 3154)
@@ -36,13 +36,15 @@
 
 (require 'uim)
 
-;; alist of LEIM style IM names and its Uim style IM names
+;; 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)
 
+;; LEIM mode-line-string
+(uim-deflocalvar uim-leim-mode-line-string "")
 
 ;; Inactivate function
 (defun uim-leim-inactivate ()
@@ -55,7 +57,7 @@
     ad-do-it))
 
 ;; Activate function (callback?)
-;;  all Uim related LEIM input methods call this function at activation time
+;;  all uim related LEIM input methods call this function at activation time
 (defun uim-leim-activate (&optional name)
 
   (let (im)
@@ -67,13 +69,14 @@
     (setq im (cdr (assoc name uim-leim-inputmethod-alist)))
 
     (when (uim-mode-on)
-      ;; switch IM after Uim activation
+      ;; 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")
@@ -86,19 +89,48 @@
     (concat lang "-" im "-uim")))
 
 
+(defun uim-leim-xemacs-modeline-init ()
+  (unless (assq 'uim-leim-active mode-line-format)
+    (setq mode-line-format
+	  (append (list (list 'uim-leim-active 
+			      'current-input-method-title))
+		  mode-line-format))
+    ))
+
+(defun uim-leim-update-label ()
+
+  (setq uim-leim-mode-line-string
+	(format "%s[%s]" uim-im-name-str uim-im-mode-str))
+
+  (setq current-input-method-title uim-leim-mode-line-string)
+
+  (if uim-xemacs
+      (uim-leim-xemacs-modeline-init))
+  )
+
+(defun uim-leim-input-method-activate-hook ()
+  (setq current-input-method-title uim-leim-mode-line-string)
+
+  (if uim-xemacs
+      (uim-leim-xemacs-modeline-init))
+  )
+
 (defun uim-leim-init ()
   ;; register IM to input-method-alist
   ;;   to display the alist, call list-input-methods
   (uim-im-init)
 
+  (setq uim-show-im-name nil)
+  (setq uim-show-im-mode nil)
+
   (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))
+	  (register-input-method im lang 'uim-leim-activate "uim"
+				 (concat "uim " name))
 
 	  ;; ( japanese-anthy-uim . anthy )
 	  (setq uim-leim-inputmethod-alist 
@@ -130,6 +162,16 @@
 	      (add-hook 'change-major-mode-hook
 			'inactivate-input-method nil t)))
 	       
+  ;; 
+  ;;uim-leim-update-label 
+  (add-hook 'uim-update-label-hook
+	    (lambda ()
+	      (uim-leim-update-label)))
+
+  (add-hook 'input-method-activate-hook
+	    (lambda ()
+	      (uim-leim-input-method-activate-hook)))
+
   )
 
 
@@ -138,6 +180,7 @@
   (interactive)
   (message "uim.el: use \"M-x set-input-method\" when using LEIM"))
 
+(uim-debug "LEIM")
 (uim-leim-init)
   
 (provide 'uim-leim)

Modified: trunk/emacs/uim-var.el
===================================================================
--- trunk/emacs/uim-var.el	2006-03-02 05:21:12 UTC (rev 3153)
+++ trunk/emacs/uim-var.el	2006-03-02 18:50:49 UTC (rev 3154)
@@ -34,7 +34,7 @@
 ;;  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ;;
 
-(defconst uim-el-version "0.0.7")
+(defconst uim-el-version "0.0.7.1")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -222,6 +222,8 @@
 ;; hook called after reset key map 
 (defvar uim-reset-keymap-hook nil)
 
+(defvar uim-update-label-hook nil)
+
 (defvar uim-send-recv-again nil)
 
 (defvar uim-last-key-vector nil
@@ -243,12 +245,27 @@
 ;; Encoding initialized flag
 (defvar uim-im-initialized nil)
 
+(defvar uim-show-im-mode t
+  "If the value is non-nil, IM mode is displayed on mode-line.")
 
+(defvar uim-show-im-name t
+  "If the value is non-nil, IM name is displayed on mode-line.")
+
+
 ;;; Buffer Local Variables
 
 (uim-deflocalvar uim-mode-line-string " U"
 		 "mode-line string of uim-mode.")
 
+;; IM name label (may not equal to uim-current-im-engine)
+(uim-deflocalvar uim-im-name-str "")
+;; IM's indication ID 
+(uim-deflocalvar uim-im-indication-id "")
+
+;; IM mode indicator
+(uim-deflocalvar uim-im-mode-str "")
+
+
 (uim-deflocalvar uim-initialized nil)
 
 ;; context ID (0 means "no context")
@@ -257,9 +274,6 @@
 ;; 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)
-
 ;; minor-mode status
 (uim-deflocalvar uim-mode nil)
 

Modified: trunk/emacs/uim.el
===================================================================
--- trunk/emacs/uim.el	2006-03-02 05:21:12 UTC (rev 3153)
+++ trunk/emacs/uim.el	2006-03-02 18:50:49 UTC (rev 3154)
@@ -142,21 +142,6 @@
   )
 
 
-;; 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
 ;;
@@ -576,14 +561,30 @@
 ;; Update property label
 ;;
 (defun uim-update-label (label)
-  ;; label: ( ("indication_id" "iconic_label"  "buttontooltip_string") ... )
+  ;; label: ( ("type" "indication_id" "iconic_label" "buttontooltip_string") ... )
   (let ((mode-str ""))
     (mapcar
      '(lambda (x)
-	(setq mode-str (concat mode-str (nth 1 x))))
+	(cond ((string= (nth 0 x) "im-mode")
+	       (setq mode-str (concat mode-str (nth 2 x))))
+	      ((string= (nth 0 x) "im-name")
+	       (setq uim-im-indication-id (nth 1 x))
+	       (setq uim-im-name-str (nth 3 x)))
+	      )
+	)
      label)
+
+    (setq uim-im-mode-str mode-str)
+
     (setq uim-mode-line-string 
-	  (format " U %s[%s]" uim-current-im-engine mode-str)))
+	  (concat (if (or uim-show-im-name uim-show-im-mode) " ")
+		  (if uim-show-im-name
+		      uim-im-name-str "")
+		  (if uim-show-im-mode
+		      (format "[%s]" uim-im-mode-str) "")))
+    )
+
+  (run-hooks 'uim-update-label-hook)  
   )
 
 



More information about the uim-commit mailing list