diff -prN -x '*.orig' ../emacs-20060603-0/lisp/loadup.el lisp/loadup.el
*** ../emacs-20060603-0/lisp/loadup.el	Sun Jun  4 21:08:09 2006
--- lisp/loadup.el	Mon Jun  5 00:07:03 2006
***************
*** 207,212 ****
--- 207,215 ----
  (if (fboundp 'atan)	; preload some constants and
      (progn		; floating pt. functions if we have float support.
        (load "emacs-lisp/float-sup")))
+ (if (eq system-type 'darwin)
+     (progn
+       (load "term/mac-im")))
  (message "%s" (garbage-collect))
  
  (load "vc-hooks")
diff -prN -x '*.orig' ../emacs-20060603-0/lisp/term/mac-im.el lisp/term/mac-im.el
*** ../emacs-20060603-0/lisp/term/mac-im.el	Thu Jan  1 09:00:00 1970
--- lisp/term/mac-im.el	Tue Jun  6 00:45:18 2006
***************
*** 0 ****
--- 1,211 ----
+ ;; mac-im.el --- Input Method for Mac OS X -*-coding: iso-2022-7bit;-*-
+ 
+ ;; Copyright (C) 2005, 2006 HASHIMOTO Taiichi <taiichi2@mac.com>
+ ;; Keywords: input method, Mac OS X
+ 
+ ;; This file is not part of GNU Emacs.
+ 
+ ;; GNU Emacs is free software; you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation; either version 2, or (at your option)
+ ;; any later version.
+ 
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with GNU Emacs; see the file COPYING.  If not, write to the
+ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ ;; Boston, MA 02111-1307, USA.
+ 
+ ;; Written by Taiichi Hashimoto (taiichi2@mac.com).
+ 
+ 
+ ;;
+ ;; Variables and functions to change a input method 
+ ;;
+ (defvar mac-input-method-parameters
+   '((0 (title . "")
+        (cursor-color)
+        (cursor-type))
+     (1 (title . "あ")
+        (cursor-color)
+        (cursor-type))
+     (2 (title . "繁")
+        (cursor-color)
+        (cursor-type))
+     (3 (title . "가")
+        (cursor-color)
+        (cursor-type))
+     (7 (title . "Cy")
+        (cursor-color)
+        (cursor-type))
+     (25 (title . "簡")
+ 	(cursor-color)
+ 	(cursor-type))
+     (29 (title . "EU")
+ 	(cursor-color)
+ 	(cursor-type))
+     )
+   "Alist of Mac script code vs parameters for input method on MacOSX.")
+ 
+ (defun mac-key-script (lang)
+   "Funtion to convert a language name to a key script."
+   (cond ((symbolp lang)
+ 	 (cond ((eq lang 'roman) 0)
+ 	       ((eq lang 'japanese) 1)
+ 	       ((eq lang 'traditional-chinese) 2)
+ 	       ((eq lang 'korean) 3)
+ 	       ((eq lang 'cyrillic) 7)
+ 	       ((eq lang 'simple-chinese) 25)
+ 	       ((eq lang 'central-euro-roman) 25)
+ 	       (t -1)))
+ 	((numberp lang) lang)
+ 	(t -1)))
+ 
+ (defun mac-set-input-method-parameter (language key value)
+   "Function to set a parameter of a input method."
+   (let* ((key-script (mac-key-script language))
+ 	 (lang-param (assq key-script mac-input-method-parameters))
+ 	 (param (assq key lang-param)))
+     (if lang-param
+ 	(if param
+ 	    (setcdr param value)
+ 	  (setcdr lang-param (cons (cons key value) (cdr lang-param))))
+       (setq mac-input-method-parameters
+ 	    (cons (list key-script (cons key value))
+ 		  mac-input-method-parameters)))))
+ 
+ (defun mac-get-input-method-parameter (language key)
+   "Function to get a parameter of a input method."
+   (assq key (cdr (assq (mac-key-script language)
+ 		       mac-input-method-parameters))))
+ 
+ (defun mac-input-method-update (lang)
+   "Funtion to update parameters of a input method."
+   (let ((title (cdr (mac-get-input-method-parameter lang 'title)))
+ 	(ctype (or (cdr (mac-get-input-method-parameter lang 'cursor-type))
+ 		   (cdr (assq 'cursor-type default-frame-alist))
+ 		   default-cursor-type))
+ 	(ccolor (or (cdr (mac-get-input-method-parameter lang 'cursor-color))
+ 		    (cdr (assq 'cursor-color default-frame-alist)))))
+     (setq current-input-method-title title)
+     (if ctype (setq cursor-type ctype))
+     (if ccolor (set-cursor-color ccolor))
+     (force-mode-line-update 'all)))
+ 
+ (defun mac-toggle-input-method (&optional arg)
+   "Function to toggle input method on MacOSX."
+   (interactive)
+   (let ((lang (mac-get-current-key-script)))
+     (if arg
+ 	(progn
+ 	  (make-local-variable 'input-method-function)
+ 	  (make-local-variable 'cursor-type)
+ 
+ 	  (setq inactivate-current-input-method-function
+ 		'mac-toggle-input-method)
+ 	  (setq input-method-function nil)
+ 	  (setq describe-current-input-method-function nil)
+ 
+ 	  (mac-input-method-update (mac-get-last-key-script))
+ 	  (if (= lang 0) (mac-set-key-script -1)))
+       (kill-local-variable 'input-method-function)
+       (kill-local-variable 'cursor-type)
+       
+       (setq describe-current-input-method-function nil)
+ 
+       (mac-input-method-update 0)
+       (if (not (= lang 0)) (mac-set-key-script -17)))))
+ 
+ (defun mac-change-language-to-us ()
+   "Function to change language (Apple Key Script) to us."
+   (interactive)
+   (mac-toggle-input-method nil))
+ 
+ (defun mac-handle-input-method-change (event)
+   "Function run when a input method change."
+   (interactive "e")
+   
+   (let ((lang (car (cadr event))))
+ 
+     (if (and (not current-input-method) (> lang 0))
+         (if isearch-mode
+             (isearch-toggle-input-method)
+           (set-input-method "MacOSX"))
+       (if (and current-input-method (= lang 0))
+ 	  (if isearch-mode
+ 	      (isearch-toggle-input-method)
+ 	    (toggle-input-method nil))))
+ 
+     (mac-input-method-update lang)))
+ 
+ 
+ ;;
+ ;; Emacs input method for input method on MacOSX.
+ ;;
+ (register-input-method "MacOSX" "MacOSX" 'mac-toggle-input-method
+ 		       "Mac" "Input Method on MacOSX System")
+ 
+ 
+ ;;
+ ;; Setup/Unsetup function of inline input method
+ ;;
+ (defun mac-setup-inline-input-method ()
+   (interactive)
+   (if (fboundp 'mac-set-inline-input-method)
+       (progn
+ 	(mac-set-inline-input-method t)
+ 	(setq default-input-method "MacOSX"))))
+ 
+ (defun mac-exit-inline-input-method ()
+   (interactive)
+   (if (fboundp 'mac-set-inline-input-method)
+       (progn
+  	(mac-set-inline-input-method nil)
+  	(set-input-method (get-language-info current-language-environment
+  					     'input-method)))))
+ 
+ 
+ ;;
+ ;; Valiable and functions to ignore system shortcut.
+ ;;
+ (defvar mac-ignore-shortcut nil
+   "A list of ignore shortcut on MacOSX.")
+ 
+ (defun mac-add-ignore-shortcut (key)
+   (let ((command '(command cmd))
+ 	(option '(option opt))
+ 	(control '(control ctrl ctl)))
+     (add-to-list 'mac-ignore-shortcut
+ 		 (cond ((symbolp key)
+ 			(cond ((memq key command) (cons #x100 nil))
+ 			      ((memq key option)  (cons #x800 nil))
+ 			      ((memq key control) (cons #x1000 nil))
+ 			      (t (cons nil nil))))
+ 		       ((numberp key) (cons 0 key))
+ 		       ((listp key) 
+ 			(let ((l key)
+ 			      (k nil)
+ 			      (m 0))
+ 			  (while l
+ 			    (cond ((memq (car l) command)
+ 				   (if (= (logand m #x100) 0)
+ 				       (setq m (logior m #x100))))
+ 				  ((memq (car l) option)
+ 				   (if (= (logand m #x800) 0)
+ 				       (setq m (logior m #x800))))
+ 				  ((memq (car l) control)
+ 				   (if (= (logand m #x1000) 0)
+ 				       (setq m (logior m #x1000))))
+ 				  ((numberp (car l))
+ 				   (if (not k)
+ 				       (setq k (car l)))))
+ 			    (setq l (cdr l)))
+ 			  (cons m k)))
+ 		       (t (cons nil nil))))))
+ 
+ 
+ ;;
+ ;; Entry Emacs event for inline input method on MacOSX.
+ ;;
+ (define-key special-event-map
+   [mac-change-input-method] 'mac-handle-input-method-change)
+       
diff -prN -x '*.orig' ../emacs-20060603-0/src/Makefile.in src/Makefile.in
*** ../emacs-20060603-0/src/Makefile.in	Sun Jun  4 21:08:15 2006
--- src/Makefile.in	Mon Jun  5 00:07:03 2006
*************** CYGWIN_OBJ = sheap.o
*** 569,575 ****
  
  #ifdef HAVE_CARBON
  mac = $(dot)$(dot)/mac/
! MAC_OBJ = mac.o macterm.o macfns.o macmenu.o macselect.o fontset.o fringe.o image.o
  emacsapp = $(PWD)/$(mac)Emacs.app/
  emacsappsrc = ${srcdir}/../mac/Emacs.app/
  #endif
--- 569,575 ----
  
  #ifdef HAVE_CARBON
  mac = $(dot)$(dot)/mac/
! MAC_OBJ = mac.o macterm.o macfns.o macmenu.o macselect.o fontset.o fringe.o image.o macim.o
  emacsapp = $(PWD)/$(mac)Emacs.app/
  emacsappsrc = ${srcdir}/../mac/Emacs.app/
  #endif
*************** obj=    dispnew.o frame.o scroll.o xdisp
*** 596,602 ****
     in case they are needed there.  */
  SOME_MACHINE_OBJECTS = sunfns.o dosfns.o msdos.o \
    xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
!   mac.o macterm.o macfns.o macmenu.o macselect.o fontset.o \
    w32.o w32bdf.o w32console.o w32fns.o w32heap.o w32inevt.o \
    w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o
  
--- 596,602 ----
     in case they are needed there.  */
  SOME_MACHINE_OBJECTS = sunfns.o dosfns.o msdos.o \
    xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
!   mac.o macterm.o macfns.o macmenu.o macselect.o macim.o fontset.o \
    w32.o w32bdf.o w32console.o w32fns.o w32heap.o w32inevt.o \
    w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o
  
*************** macterm.o: blockinput.h atimer.h systime
*** 1273,1278 ****
--- 1273,1282 ----
    frame.h charset.h ccl.h dispextern.h fontset.h termhooks.h termopts.h \
    termchar.h gnu.h disptab.h buffer.h window.h keyboard.h $(INTERVAL_SRC) \
    process.h coding.h $(config_h)
+ macim.o: blockinput.h atimer.h systime.h syssignal.h macterm.h macgui.h \
+   frame.h charset.h ccl.h dispextern.h fontset.h termhooks.h termopts.h \
+   termchar.h gnu.h disptab.h buffer.h window.h keyboard.h $(INTERVAL_SRC) \
+   process.h coding.h $(config_h)
  macselect.o: blockinput.h macterm.h macgui.h frame.h keymap.h $(config_h)
  
  ${emacsapp}Contents/Resources/English.lproj:
diff -prN -x '*.orig' ../emacs-20060603-0/src/keyboard.c src/keyboard.c
*** ../emacs-20060603-0/src/keyboard.c	Sun Jun  4 21:08:15 2006
--- src/keyboard.c	Mon Jun  5 00:07:03 2006
*************** Lisp_Object Qmouse_click;
*** 528,533 ****
--- 528,536 ----
  #if defined (WINDOWSNT) || defined (MAC_OS)
  Lisp_Object Qlanguage_change;
  #endif
+ #if defined (MAC_OSX)
+ Lisp_Object Qmac_change_input_method;
+ #endif
  Lisp_Object Qdrag_n_drop;
  Lisp_Object Qsave_session;
  #ifdef MAC_OS
*************** kbd_buffer_get_event (kbp, used_mouse_me
*** 4056,4061 ****
--- 4059,4073 ----
  	  kbd_fetch_ptr = event + 1;
  	}
  #endif
+ #if defined (MAC_OSX)
+       else if (event->kind == MAC_CHANGE_INPUT_METHOD_EVENT)
+ 	{
+ 	  /* Make an event (mac-change-input-method (KEY_SCRIPT)).  */
+ 	  obj = Fcons (make_number (event->code), Qnil);
+ 	  obj = Fcons (Qmac_change_input_method, Fcons (obj, Qnil));
+ 	  kbd_fetch_ptr = event + 1;
+ 	}
+ #endif
        else if (event->kind == SAVE_SESSION_EVENT)
          {
            obj = Fcons (Qsave_session, Qnil);
*************** syms_of_keyboard ()
*** 10898,10903 ****
--- 10910,10919 ----
    Qlanguage_change = intern ("language-change");
    staticpro (&Qlanguage_change);
  #endif
+ #if defined (MAC_OSX)
+   Qmac_change_input_method = intern ("mac-change-input-method");
+   staticpro (&Qmac_change_input_method);
+ #endif
    Qdrag_n_drop = intern ("drag-n-drop");
    staticpro (&Qdrag_n_drop);
  
diff -prN -x '*.orig' ../emacs-20060603-0/src/macim.c src/macim.c
*** ../emacs-20060603-0/src/macim.c	Thu Jan  1 09:00:00 1970
--- src/macim.c	Tue Jun  6 00:42:30 2006
***************
*** 0 ****
--- 1,272 ----
+ /* Implementation of Inline Input Method for MacOS X.
+    Copyright (C) 2004, 2005, 2006 Taiichi Hashimoto <taiichi2@mac.com>.
+ 
+ This file is not part of GNU Emacs.
+ 
+ GNU Emacs is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+ 
+ GNU Emacs is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with GNU Emacs; see the file COPYING.  If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.  */
+ 
+ /* Written by Taiichi Hashimoto (taiichi2@mac.com).  */
+ 
+ 
+ #include <config.h>
+ #include <signal.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include "lisp.h"
+ #include "charset.h"
+ #include "blockinput.h"
+ 
+ #include "macterm.h"
+ 
+ #ifndef MAC_OSX
+ #include <alloca.h>
+ #endif
+ 
+ #ifdef MAC_OSX
+ #undef mktime
+ #undef DEBUG
+ #undef free
+ #undef malloc
+ #undef realloc
+ /* Macros max and min defined in lisp.h conflict with those in
+    precompiled header Carbon.h.  */
+ #undef max
+ #undef min
+ #undef init_process
+ #include <Carbon/Carbon.h>
+ #undef free
+ #define free unexec_free
+ #undef malloc
+ #define malloc unexec_malloc
+ #undef realloc
+ #define realloc unexec_realloc
+ #undef min
+ #define min(a, b) ((a) < (b) ? (a) : (b))
+ #undef max
+ #define max(a, b) ((a) > (b) ? (a) : (b))
+ #undef init_process
+ #define init_process emacs_init_process
+ /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
+    obtain events from the event queue.  If set to 0, WaitNextEvent is
+    used instead.  */
+ #define USE_CARBON_EVENTS 1
+ #else /* not MAC_OSX */
+ #include <Quickdraw.h>
+ #include <ToolUtils.h>
+ #include <Sound.h>
+ #include <Events.h>
+ #include <Script.h>
+ #include <Resources.h>
+ #include <Fonts.h>
+ #include <TextUtils.h>
+ #include <LowMem.h>
+ #include <Controls.h>
+ #if defined (__MRC__) || (__MSL__ >= 0x6000)
+ #include <ControlDefinitions.h>
+ #endif
+ #include <Gestalt.h>
+ 
+ #if __profile__
+ #include <profiler.h>
+ #endif
+ #endif /* not MAC_OSX */
+ 
+ #include "systty.h"
+ #include "systime.h"
+ #include "atimer.h"
+ #include "keymap.h"
+ 
+ #include <ctype.h>
+ #include <errno.h>
+ #include <setjmp.h>
+ #include <sys/stat.h>
+ 
+ #include "keyboard.h"
+ #include "frame.h"
+ #include "dispextern.h"
+ #include "fontset.h"
+ #include "termhooks.h"
+ #include "termopts.h"
+ #include "termchar.h"
+ #include "gnu.h"
+ #include "disptab.h"
+ #include "buffer.h"
+ #include "window.h"
+ #include "intervals.h"
+ #include "composite.h"
+ #include "coding.h"
+ 
+ #ifdef USE_CARBON_EVENTS && defined (MAC_OSX) && USE_TSM
+ 
+ extern Lisp_Object Qcurrent_input_method;
+ static Lisp_Object Qmac_ignore_shortcut;
+ static TSMDocumentID tsm_document_id;
+ int mac_use_inline_input_method = 1;
+ 
+ void init_input_method (TSMDocumentID id);
+ int mac_store_change_input_method_event (unsigned long timestamp);
+ 
+ DEFUN ("mac-set-key-script", Fmac_set_key_script,
+        Smac_set_key_script, 1, 1, 0,
+        doc: /* change languge environment of MacOSX */)
+      (code)
+      Lisp_Object code;
+ {
+   BLOCK_INPUT;
+   KeyScript (XINT (code));
+   UNBLOCK_INPUT;
+ 
+   return Qnil;
+ }
+ 
+ DEFUN ("mac-get-current-key-script", Fmac_get_current_key_script,
+        Smac_get_current_key_script, 0, 0, 0,
+        doc: /* get current languge environment of MacOSX */)
+      ()
+ {
+   SInt16 current_key_script;
+ 
+   BLOCK_INPUT;
+   current_key_script = GetScriptManagerVariable (smKeyScript);
+   UNBLOCK_INPUT;
+ 
+   return make_number (current_key_script);
+ }
+ 
+ DEFUN ("mac-get-last-key-script", Fmac_get_last_key_script,
+        Smac_get_last_key_script, 0, 0, 0,
+        doc: /* get last languge environment of MacOSX */)
+      ()
+ {
+   SInt16 last_key_script;
+   
+   BLOCK_INPUT;
+   last_key_script = GetScriptManagerVariable (smLastScript);
+   UNBLOCK_INPUT;
+   
+   return make_number (last_key_script);
+ }
+ 
+ DEFUN ("mac-set-inline-input-method", Fmac_set_inline_input_method,
+        Smac_set_inline_input_method, 1, 1, 0,
+        doc: /* set inline input method */)
+      (on_p)
+      Lisp_Object on_p;
+ {
+ 
+   BLOCK_INPUT;
+   if (NILP (on_p))
+     {
+       DeactivateTSMDocument (tsm_document_id);
+       mac_use_inline_input_method = 0;
+     }
+   else
+     {
+       ActivateTSMDocument (tsm_document_id);
+       mac_use_inline_input_method = 1;
+     }
+   UNBLOCK_INPUT;
+ 
+   return on_p;
+ }
+ 
+ int
+ mac_store_change_input_method_event (unsigned long timestamp)
+ {
+   Lisp_Object input_method;
+   static SInt16 last_key_script = -1;
+   SInt16 current_key_script, count = 0; 
+ 
+   BLOCK_INPUT;
+ 
+   if (mac_use_inline_input_method)
+     {
+       current_key_script = GetScriptManagerVariable (smKeyScript);
+       input_method = Fsymbol_value (Qcurrent_input_method);
+ 
+       if (last_key_script != current_key_script
+ 	  || (current_key_script && NILP (input_method))
+ 	  || (!current_key_script && !NILP (input_method)))
+ 	{
+ 	  struct input_event event;
+       
+ 	  EVENT_INIT (event);
+ 	  event.kind = MAC_CHANGE_INPUT_METHOD_EVENT;
+ 	  event.arg = Qnil;
+ 	  event.code = current_key_script;
+ 	  event.timestamp = timestamp;
+ 	  kbd_buffer_store_event (&event);
+ 	  count++;
+ 	}
+       
+       last_key_script = current_key_script;
+     }
+ 
+   UNBLOCK_INPUT;
+ 
+   return count;
+ }
+ 
+ 
+ int
+ mac_pass_key_to_system (int code, UInt32 modifiers)
+ {
+   Lisp_Object buf = Qnil;
+ 
+   buf = Fsymbol_value (intern ("mac-ts-active-input-buf"));
+ 
+   if (GetScriptManagerVariable (smKeyScript)
+       && (this_command_key_count || cursor_in_echo_area))
+     return FALSE;
+   else if (mac_use_inline_input_method && !Flength (buf))
+     {
+       Fsymbol_value (Qcurrent_input_method);
+       Lisp_Object keys = Fsymbol_value (Qmac_ignore_shortcut);
+       Lisp_Object m, k;
+ 
+       while (!NILP (keys))
+ 	{
+ 	  m = XCAR (XCAR (keys));
+ 	  k = XCDR (XCAR (keys));
+ 	  keys = XCDR (keys);
+ 	  
+ 	  if (NUMBERP (m) && modifiers == XINT (m))
+ 	    if (NILP (k)
+ 		|| (NUMBERP (k) && code == XINT (k)))
+ 	      return FALSE;
+ 	}
+       return TRUE;
+     }
+   else
+     return TRUE;
+ }
+ 
+ 
+ void init_input_method (TSMDocumentID id)
+ {
+   tsm_document_id = id;
+ 
+   Qmac_ignore_shortcut = intern ("mac-ignore-shortcut");
+   staticpro (&Qmac_ignore_shortcut);
+ 
+   defsubr (&Smac_set_inline_input_method);
+   defsubr (&Smac_set_key_script);
+   defsubr (&Smac_get_current_key_script);
+   defsubr (&Smac_get_last_key_script);
+ }
+ 
+ #endif
+ 
diff -prN -x '*.orig' ../emacs-20060603-0/src/macterm.c src/macterm.c
*** ../emacs-20060603-0/src/macterm.c	Sun Jun  4 21:08:15 2006
--- src/macterm.c	Tue Jun  6 00:37:25 2006
*************** Lisp_Object Vx_toolkit_scroll_bars;
*** 95,100 ****
--- 95,101 ----
     rendering which may anti-alias the text.  */
  int mac_use_core_graphics;
  
+ extern int mac_use_inline_input_method;
  
  /* Non-zero means that a HELP_EVENT has been generated since Emacs
     start.  */
*************** static void
*** 8865,8871 ****
  do_app_resume ()
  {
  #if USE_MAC_TSM
!   ActivateTSMDocument (tsm_document_id);
  #endif
  }
  
--- 8866,8873 ----
  do_app_resume ()
  {
  #if USE_MAC_TSM
!   if (mac_use_inline_input_method)
!     ActivateTSMDocument (tsm_document_id);
  #endif
  }
  
*************** mac_handle_window_event (next_handler, e
*** 9330,9336 ****
  #if USE_MAC_TSM
      case kEventWindowFocusAcquired:
        result = CallNextEventHandler (next_handler, event);
!       err = ActivateTSMDocument (tsm_document_id);
        return err == noErr ? noErr : result;
  
      case kEventWindowFocusRelinquish:
--- 9332,9341 ----
  #if USE_MAC_TSM
      case kEventWindowFocusAcquired:
        result = CallNextEventHandler (next_handler, event);
!       if (mac_use_inline_input_method)
! 	err = ActivateTSMDocument (tsm_document_id);
!       else
! 	err = noErr;
        return err == noErr ? noErr : result;
  
      case kEventWindowFocusRelinquish:
*************** XTread_socket (sd, expected, hold_quit)
*** 10587,10593 ****
  	       normally.  */
  	    if (!(mapped_modifiers
  		  & ~(mac_pass_command_to_system ? cmdKey : 0)
! 		  & ~(mac_pass_control_to_system ? controlKey : 0)))
  	      {
  		OSStatus err;
  
--- 10592,10600 ----
  	       normally.  */
  	    if (!(mapped_modifiers
  		  & ~(mac_pass_command_to_system ? cmdKey : 0)
! 		  & ~(mac_pass_control_to_system ? controlKey : 0))
! 		&& mac_pass_key_to_system (er.message & charCodeMask,
! 					   modifiers))
  	      {
  		OSStatus err;
  
*************** XTread_socket (sd, expected, hold_quit)
*** 10809,10814 ****
--- 10816,10822 ----
  	  count++;
  	}
  
+       count += mac_store_change_input_method_event (timestamp);
      }
  
    /* If the focus was just given to an autoraising frame,
*************** init_tsm ()
*** 11248,11253 ****
--- 11256,11263 ----
  
    NewTSMDocument (sizeof (types) / sizeof (types[0]), types,
  		  &tsm_document_id, 0);
+ 
+   init_input_method(tsm_document_id);
  }
  #endif
  
diff -prN -x '*.orig' ../emacs-20060603-0/src/termhooks.h src/termhooks.h
*** ../emacs-20060603-0/src/termhooks.h	Sun Jun  4 21:08:16 2006
--- src/termhooks.h	Mon Jun  5 00:07:03 2006
*************** enum event_kind
*** 260,265 ****
--- 260,269 ----
  				   language is changed by the
  				   user.  */
  #endif
+ #if defined (MAC_OSX)
+   MAC_CHANGE_INPUT_METHOD_EVENT,/* A MAC_CHANGE_INPUT_METHOD_EVENT is generated
+ 				   for changing input method on MacOSX. */  
+ #endif
    SCROLL_BAR_CLICK_EVENT,	/* .code gives the number of the mouse button
  				   that was clicked.
  				   .modifiers holds the state of the modifier
