diff -p -N -r -x '*.orig' ../emacs-22.1/lisp/loadup.el lisp/loadup.el
*** ../emacs-22.1/lisp/loadup.el	2007-01-21 12:53:11.000000000 +0900
--- lisp/loadup.el	2007-06-09 21:38:40.000000000 +0900
***************
*** 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 -p -N -r -x '*.orig' ../emacs-22.1/lisp/term/mac-im.el lisp/term/mac-im.el
*** ../emacs-22.1/lisp/term/mac-im.el	1970-01-01 09:00:00.000000000 +0900
--- lisp/term/mac-im.el	2007-06-28 19:49:03.000000000 +0900
***************
*** 0 ****
--- 1,226 ----
+ ;; mac-im.el --- Input Method for Mac OS X -*-coding: iso-2022-7bit;-*-
+ 
+ ;; Copyright (C) 2005, 2006, 2007 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)
+     (if isearch-mode (isearch-update))))
+ 
+ (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")
+ 
+ 
+ ;;
+ ;; Minor mode of using input methods on MacOS X
+ ;;
+ (define-minor-mode mac-input-method-mode
+   "Use input methods on MacOSX."
+   :init-value nil
+   :group 'mac
+   :global t
+ 
+   (if mac-input-method-mode
+       (progn
+ 	(setq default-input-method "MacOSX")
+ 	(add-hook 'minibuffer-setup-hook 'mac-change-language-to-us))
+     (setq default-input-method nil)))
+ 
+ ;;
+ ;; 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)
+       
+ ;;
+ ;; Convert yen to backslash for JIS keyboard.
+ ;;
+ (defun mac-translate-from-yen-to-backslash () 
+   ;; Convert yen to backslash for JIS keyboard.
+   (interactive)
+ 
+   (define-key global-map [2213] nil)
+   (define-key global-map [3420] nil)
+   (define-key global-map [67111077] nil)
+   (define-key global-map [134219941] nil)
+   (define-key global-map [201328805] nil)
+   (define-key function-key-map [2213] [?\\]) ;; for Intel
+   (define-key function-key-map [3420] [?\\]) ;; for PowerPC
+   (define-key function-key-map [67111077] [?\C-\\])
+   (define-key function-key-map [134219941] [?\M-\\])
+   (define-key function-key-map [201328805] [?\C-\M-\\])
+ )
diff -p -N -r -x '*.orig' ../emacs-22.1/lisp/term/mac-win.el lisp/term/mac-win.el
*** ../emacs-22.1/lisp/term/mac-win.el	2007-05-14 23:56:30.000000000 +0900
--- lisp/term/mac-win.el	2007-06-09 21:38:40.000000000 +0900
*************** either in the current buffer or in the e
*** 2086,2094 ****
  				      (concat msg active-input-string)))
  	      (setq msg active-input-string))
  	    (message "%s" msg)
  	    (overlay-put mac-ts-active-input-overlay 'before-string nil))
  	(move-overlay mac-ts-active-input-overlay
! 		      (point) (point) (current-buffer))
  	(overlay-put mac-ts-active-input-overlay 'before-string
  		     active-input-string))
        (mac-unread-string (funcall decode-fun confirmed coding)))
--- 2086,2104 ----
  				      (concat msg active-input-string)))
  	      (setq msg active-input-string))
  	    (message "%s" msg)
+ 	    (overlay-put mac-ts-active-input-overlay 'face nil)
  	    (overlay-put mac-ts-active-input-overlay 'before-string nil))
+ 	(overlay-put mac-ts-active-input-overlay 'face nil)
+ 	(let ((overlays (overlays-in (point) (point)))
+ 	      (face nil))
+ 	  (while overlays
+ 	    (setq face (overlay-get (car overlays) 'face))
+ 	    (and face
+ 		 (overlay-put mac-ts-active-input-overlay 'face face))
+ 	    (setq overlays (cdr overlays))))
  	(move-overlay mac-ts-active-input-overlay
! 		      (point) (+ (point) (length active-input-string))
! 		      (current-buffer))
  	(overlay-put mac-ts-active-input-overlay 'before-string
  		     active-input-string))
        (mac-unread-string (funcall decode-fun confirmed coding)))
diff -p -N -r -x '*.orig' ../emacs-22.1/src/Makefile.in src/Makefile.in
*** ../emacs-22.1/src/Makefile.in	2007-03-21 23:31:24.000000000 +0900
--- src/Makefile.in	2007-06-09 21:38:40.000000000 +0900
*************** CYGWIN_OBJ = sheap.o
*** 574,580 ****
  
  #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
--- 574,580 ----
  
  #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
*** 601,607 ****
     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
  
--- 601,607 ----
     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
*** 1286,1291 ****
--- 1286,1295 ----
    process.h coding.h $(config_h)
  macselect.o: blockinput.h atimer.h systime.h macterm.h macgui.h frame.h \
    keymap.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)
  
  ${emacsapp}Contents/Resources/English.lproj:
  	mkdir -p $@
diff -p -N -r -x '*.orig' ../emacs-22.1/src/keyboard.c src/keyboard.c
*** ../emacs-22.1/src/keyboard.c	2007-04-02 06:54:54.000000000 +0900
--- src/keyboard.c	2007-06-09 21:38:40.000000000 +0900
*************** Lisp_Object Qmouse_click;
*** 531,536 ****
--- 531,539 ----
  #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
*** 4151,4156 ****
--- 4154,4168 ----
  	  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 ()
*** 11192,11197 ****
--- 11204,11213 ----
    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 -p -N -r -x '*.orig' ../emacs-22.1/src/macim.c src/macim.c
*** ../emacs-22.1/src/macim.c	1970-01-01 09:00:00.000000000 +0900
--- src/macim.c	2007-06-26 23:00:50.000000000 +0900
***************
*** 0 ****
--- 1,267 ----
+ /* Implementation of Inline Input Method for MacOS X.
+    Copyright (C) 2004, 2005, 2006, 2007
+     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;
+ int mac_pass_key_to_system_on_read_only_buffer;
+ 
+ void init_input_method ();
+ 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);
+ }
+ 
+ 
+ int
+ mac_store_change_input_method_event (unsigned long timestamp)
+ {
+   Lisp_Object cim, him, dim;
+   static SInt16 last_key_script = -1;
+   SInt16 current_key_script, count = 0;
+ 
+   BLOCK_INPUT;
+   current_key_script = GetScriptManagerVariable (smKeyScript);
+   
+   cim = Fsymbol_value (Qcurrent_input_method);
+   him = Fcar_safe (intern ("input-method-history"));
+   dim = Fsymbol_value (intern ("default-input-method"));
+ 
+   if ((STRINGP (cim) && !strcmp(SDATA (cim), "MacOSX"))
+       || (STRINGP (him) && !strcmp(SDATA (him), "MacOSX"))
+       || (STRINGP (dim) && !strcmp(SDATA (dim), "MacOSX")))
+     {
+       if (last_key_script != current_key_script
+ 	  || (current_key_script && NILP (cim))
+ 	  || (!current_key_script && !NILP (cim)))
+ 	{
+ 	  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;
+     }
+   else
+     if (current_key_script) KeyScript (smKeyRoman);
+ 
+ 
+   UNBLOCK_INPUT;
+ 
+   return count;
+ }
+ 
+ 
+ int
+ mac_pass_key_to_system (int code, UInt32 modifiers)
+ {
+   Lisp_Object buf = Qnil;
+   SInt16 current_key_script;
+ 
+   buf = Fsymbol_value (intern ("mac-ts-active-input-buf"));
+   current_key_script = GetScriptManagerVariable (smKeyScript);
+   
+   if (current_key_script
+       && (this_command_key_count || cursor_in_echo_area))
+     return FALSE;
+   else if (current_key_script
+ 	   && !mac_pass_key_to_system_on_read_only_buffer
+ 	   && !NILP (current_buffer->read_only)
+ 	   && code != 0x20)
+     return FALSE;
+   else if (!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 ()
+ {
+   Qmac_ignore_shortcut = intern ("mac-ignore-shortcut");
+   staticpro (&Qmac_ignore_shortcut);
+ 
+   DEFVAR_BOOL ("mac-pass-key-to-system-on-read-only-buffer",
+ 	       &mac_pass_key_to_system_on_read_only_buffer,
+     doc: /* If nil, don't pass key to system when buffer is read-only. */);
+   mac_pass_key_to_system_on_read_only_buffer = 0;
+ 
+   defsubr (&Smac_set_key_script);
+   defsubr (&Smac_get_current_key_script);
+   defsubr (&Smac_get_last_key_script);
+ 
+ }
+ 
+ #endif
+ 
diff -p -N -r -x '*.orig' ../emacs-22.1/src/macterm.c src/macterm.c
*** ../emacs-22.1/src/macterm.c	2007-05-25 21:43:34.000000000 +0900
--- src/macterm.c	2007-06-22 21:31:33.000000000 +0900
*************** XTread_socket (sd, expected, hold_quit)
*** 11230,11236 ****
  	       normally.  */
  	    if (!(mapped_modifiers
  		  & ~(mac_pass_command_to_system ? cmdKey : 0)
! 		  & ~(mac_pass_control_to_system ? controlKey : 0)))
  	      {
  		OSStatus err;
  
--- 11230,11238 ----
  	       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)
*** 11465,11470 ****
--- 11467,11473 ----
  	  count++;
  	}
  
+       count += mac_store_change_input_method_event (timestamp);
      }
  
    /* If the focus was just given to an autoraising frame,
*************** init_tsm ()
*** 11809,11814 ****
--- 11812,11819 ----
  
    NewTSMDocument (sizeof (types) / sizeof (types[0]), types,
  		  &tsm_document_id, 0);
+ 
+   init_input_method();
  }
  #endif
  
diff -p -N -r -x '*.orig' ../emacs-22.1/src/termhooks.h src/termhooks.h
*** ../emacs-22.1/src/termhooks.h	2007-01-14 12:24:37.000000000 +0900
--- src/termhooks.h	2007-06-09 21:38:40.000000000 +0900
*************** enum event_kind
*** 265,270 ****
--- 265,274 ----
  				   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
