<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">diff -Naurw emacs-20.7.orig/src/xfns.c emacs-20.7/src/xfns.c
--- emacs-20.7.orig/src/xfns.c	Thu Jul  1 09:09:39 1999
+++ emacs-20.7/src/xfns.c	Sat Jun 17 00:18:36 2000
@@ -2719,6 +2719,259 @@
 }
 #endif
 
+/* Support routines for XIC (X Input Context). */
+#ifdef HAVE_X_I18N
+
+/* Create X fontset. */
+static XFontSet
+xic_create_xfontset (f, base_fontname)
+     struct frame *f;
+     char *base_fontname;
+{
+  XFontSet xfs;
+  char **missing_list;
+  int missing_count;
+  char *def_string;
+  
+  xfs = XCreateFontSet (FRAME_X_DISPLAY (f),
+			base_fontname, &amp;missing_list,
+			&amp;missing_count, &amp;def_string);
+  if (missing_list)
+    XFreeStringList (missing_list);
+  /* Don't need to free def_string. */
+
+  return xfs;
+}
+
+/* Supported XIM styles, ordered in preferences. */
+static XIMStyle supported_styles[] =
+{
+  XIMPreeditPosition | XIMStatusArea,
+  XIMPreeditPosition | XIMStatusNothing,
+  XIMPreeditPosition | XIMStatusNone,
+  XIMPreeditNothing | XIMStatusArea,
+  XIMPreeditNothing | XIMStatusNothing,
+  XIMPreeditNothing | XIMStatusNone,
+  XIMPreeditNone | XIMStatusArea,
+  XIMPreeditNone | XIMStatusNothing,
+  XIMPreeditNone | XIMStatusNone,
+  0,
+};
+
+/* Choose the best style, given:
+ * - user preferences (already checked to be supported by Emacs)
+ * - styles supported by the input method */
+#define DEFAULTStyle  (XIMPreeditNothing | XIMStatusNothing)
+static XIMStyle
+best_style (user, xim)
+     XIMStyles *user;
+     XIMStyles *xim;
+{
+  int i, j;
+
+  for (i = 0; i &lt; user-&gt;count_styles; i++)
+    {
+      for (j = 0; j &lt; xim-&gt;count_styles; j++)
+        {
+          if (user-&gt;supported_styles[i] == xim-&gt;supported_styles[j])
+            return user-&gt;supported_styles[i];
+        }
+    }
+  return DEFAULTStyle; /* Default Style */
+}
+
+/* Create XIC for a frame. */
+void
+xic_create_frame (f)
+     struct frame *f;
+{
+#ifndef X_I18N_INHIBITED
+  XIM xim;
+  XIC xic = NULL;
+  XFontSet xfs = NULL;
+  static XIMStyle xic_style;
+
+  if (FRAME_XIC (f))
+    return;
+  xim = FRAME_X_XIM (f);
+
+  if (xim)
+    {
+      XRectangle s_area = {0, 0, 1, 1};
+      XPoint spot = {0, 1};
+      XVaNestedList preedit_attr;
+      XVaNestedList status_attr;
+      static const char DEFAULT_FONT[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
+      char *base_fontname;
+      int fontset;
+
+      /* Create X fontset. */
+      fontset = FRAME_FONTSET (f);
+      if (fontset &lt; 0)
+	base_fontname = DEFAULT_FONT;
+      else
+	{
+	  struct fontset_info *fontsetp;
+	  int len = 0;
+	  int i;
+	  
+	  fontsetp = FRAME_FONTSET_DATA (f)-&gt;fontset_table[fontset];
+	  for (i = 0; i &lt;= MAX_CHARSET; i++)
+	    if (fontsetp-&gt;fontname[i])
+	      len += strlen (fontsetp-&gt;fontname[i]) + 1;
+	  base_fontname = alloca (len);
+	  strcpy (base_fontname, fontsetp-&gt;fontname[CHARSET_ASCII]);
+	  for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i &lt;= MAX_CHARSET; i++)
+	    if (fontsetp-&gt;fontname[i])
+	      {
+		strcat (base_fontname, ",");
+		strcat (base_fontname, fontsetp-&gt;fontname[i]);
+	      }
+	}
+      xfs = xic_create_xfontset (f, base_fontname);
+
+      /* Determine XIC style. */
+      if (xic_style == 0)
+	{
+	  XIMStyles supported_list;
+	  supported_list.count_styles = sizeof (supported_styles) / sizeof (supported_styles[0]);
+	  supported_list.supported_styles = supported_styles;
+	  xic_style = best_style (&amp;supported_list, FRAME_X_XIM_STYLES (f));
+	}
+
+      preedit_attr = XVaCreateNestedList (0,
+					  XNFontSet, xfs,
+					  XNForeground, FRAME_FOREGROUND_PIXEL (f),
+					  XNBackground, FRAME_BACKGROUND_PIXEL (f),
+					  xic_style &amp; XIMPreeditPosition ? XNSpotLocation : NULL, &amp;spot,
+					  NULL);
+      status_attr = XVaCreateNestedList (0,
+					 XNArea,         &amp;s_area,
+					 XNFontSet,      xfs,
+					 XNForeground, FRAME_FOREGROUND_PIXEL (f),
+					 XNBackground, FRAME_BACKGROUND_PIXEL (f),
+					 NULL);
+
+      xic = XCreateIC (xim,
+		       XNInputStyle,   xic_style,
+		       XNClientWindow, FRAME_X_WINDOW(f),
+		       XNFocusWindow,  FRAME_X_WINDOW(f),
+		       XNStatusAttributes,  status_attr,
+		       XNPreeditAttributes, preedit_attr,
+		       NULL);
+      XFree (preedit_attr);
+      XFree (status_attr);
+    }
+  
+  FRAME_XIC (f) = xic;
+  FRAME_XIC_STYLE (f) = xic_style;
+  FRAME_XIC_FONTSET (f) = xfs;
+#else /* X_I18N_INHIBITED */
+  FRAME_XIC (f) = NULL;
+  FRAME_XIC_STYLE (f) = 0;
+  FRAME_XIC_FONTSET (f) = NULL;
+#endif /* X_I18N_INHIBITED */
+}
+
+/* Destroy XIC for a frame. */
+void
+xic_destroy_frame (f)
+     struct frame *f;
+{
+  if (FRAME_XIC (f) == NULL)
+    return;
+  
+  XDestroyIC (FRAME_XIC (f));
+  if (FRAME_XIC_FONTSET (f))
+    XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
+
+  FRAME_XIC (f) = NULL;
+  FRAME_XIC_FONTSET (f) = NULL;
+}
+
+/* Place preedit area for XIC in cursor position. */
+void
+xic_set_preeditarea (f, x, y)
+     struct frame *f;
+     int x, y;
+{
+  XVaNestedList attr;
+  XPoint spot;
+      
+  spot.x = CHAR_TO_PIXEL_COL (f, x);
+  spot.y = CHAR_TO_PIXEL_ROW (f, y) + FONT_BASE (FRAME_FONT (f));
+  attr = XVaCreateNestedList (0,
+			      XNSpotLocation, &amp;spot,
+			      NULL);
+  XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
+  XFree (attr);
+}
+
+/* Place status area for XIC in bottom right corner. */
+void
+xic_set_statusarea (f)
+     struct frame *f;
+{
+  XIC xic = FRAME_XIC (f);
+  XVaNestedList attr;
+  XRectangle area;
+  XRectangle *needed;
+
+  /* Basically, I follow the way of XEmacs20.4. */
+  /* Negotiate geometry of status area. */
+  /* If input method has existing status area, use its current size */
+  area.x = area.y = area.width = area.height = 0;
+  attr = XVaCreateNestedList (0, XNAreaNeeded, &amp;area, NULL);
+  XSetICValues (xic, XNStatusAttributes, attr, NULL);
+  XFree (attr);
+  
+  attr = XVaCreateNestedList (0, XNAreaNeeded, &amp;needed, NULL);
+  XGetICValues (xic, XNStatusAttributes, attr, NULL);
+  XFree (attr);
+
+  if (needed-&gt;width == 0) /* Use XNArea instead of XNAreaNeeded */
+    {
+      attr = XVaCreateNestedList (0, XNArea, &amp;needed, NULL);
+      XGetICValues (xic, XNStatusAttributes, attr, NULL);
+      XFree (attr);
+    }
+
+  area.width  = needed-&gt;width;
+  area.height = needed-&gt;height;
+  area.x = PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f);
+  area.y = PIXEL_HEIGHT (f) - area.height - FRAME_MENUBAR_HEIGHT (f) - FRAME_INTERNAL_BORDER_WIDTH (f);
+  XFree(needed);
+
+  attr = XVaCreateNestedList (0, XNArea, &amp;area, NULL);
+  XSetICValues(xic, XNStatusAttributes, attr, NULL);
+  XFree(attr);
+}
+
+/* Set X fontset for XIC, called when a new Emacs fontset is chosen. */
+void
+xic_set_xfontset (f, base_fontname)
+     struct frame *f;
+     char *base_fontname;
+{
+  XVaNestedList attr;
+  XFontSet xfs;
+
+  xfs = xic_create_xfontset (f, base_fontname);
+
+  attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL);
+  if (FRAME_XIC_STYLE (f) &amp; XIMPreeditPosition)
+    XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
+  if (FRAME_XIC_STYLE (f) &amp; XIMStatusArea)
+    XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL);
+  XFree (attr);
+  
+  if (FRAME_XIC_FONTSET (f))
+    XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
+  FRAME_XIC_FONTSET (f) = xfs;
+}  
+#endif /* HAVE_X_I18N */
+
+
 #ifdef USE_X_TOOLKIT
 
 /* Create and set up the X widget for frame F.  */
@@ -2876,34 +3129,8 @@
   XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &amp;class_hints);
 
 #ifdef HAVE_X_I18N
-#ifndef X_I18N_INHIBITED
-  { 
-    XIM xim;
-    XIC xic = NULL;
-
-    xim = XOpenIM (FRAME_X_DISPLAY (f), NULL, NULL, NULL);
-
-    if (xim)
-      {
-	xic = XCreateIC (xim,  
-			 XNInputStyle,   XIMPreeditNothing | XIMStatusNothing,
-			 XNClientWindow, FRAME_X_WINDOW(f),
-			 XNFocusWindow,  FRAME_X_WINDOW(f),
-			 NULL);
-
-	if (xic == 0)
-	  {
-	    XCloseIM (xim);
-	    xim = NULL;
-	  }
-      }
-    FRAME_XIM (f) = xim;
-    FRAME_XIC (f) = xic;
-  }
-#else /* X_I18N_INHIBITED */
-  FRAME_XIM (f) = 0;
-  FRAME_XIC (f) = 0;
-#endif /* X_I18N_INHIBITED */
+  FRAME_XIC (f) = NULL;
+  xic_create_frame (f);
 #endif /* HAVE_X_I18N */
 
   f-&gt;output_data.x-&gt;wm_hints.input = True;
@@ -2928,6 +3155,16 @@
 
  /* Make all the standard events reach the Emacs frame.  */
   attributes.event_mask = STANDARD_EVENT_SET;
+#ifdef HAVE_X_I18N
+  if (FRAME_XIC (f))
+    {
+      /* XIM server might require some X events. */
+      unsigned long fevent = NoEventMask;
+
+      XGetICValues(FRAME_XIC (f), XNFilterEvents, &amp;fevent, NULL);
+      attributes.event_mask |= fevent;
+    }
+#endif /* HAVE_X_I18N */
   attribute_mask = CWEventMask;
   XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget),
 			   attribute_mask, &amp;attributes);
@@ -2998,38 +3235,21 @@
 		     InputOutput, /* class */
 		     FRAME_X_DISPLAY_INFO (f)-&gt;visual,
 		     attribute_mask, &amp;attributes);
-#ifdef HAVE_X_I18N
-#ifndef X_I18N_INHIBITED
-  { 
-    XIM xim;
-    XIC xic = NULL;
 
-    xim = XOpenIM (FRAME_X_DISPLAY(f), NULL, NULL, NULL);
-
-    if (xim)
-      {
-	xic = XCreateIC (xim,  
-			 XNInputStyle,   XIMPreeditNothing | XIMStatusNothing,
-			 XNClientWindow, FRAME_X_WINDOW(f),
-			 XNFocusWindow,  FRAME_X_WINDOW(f),
-			 NULL);
-
-	if (!xic)
+#ifdef HAVE_X_I18N
+  xic_create_frame (f);
+  if (FRAME_XIC (f))
 	  {
-	    XCloseIM (xim);
-	    xim = NULL;
-	  }
-      }
+      /* XIM server might require some X events. */
+      unsigned long fevent = NoEventMask;
 
-    FRAME_XIM (f) = xim;
-    FRAME_XIC (f) = xic;
+      XGetICValues(FRAME_XIC (f), XNFilterEvents, &amp;fevent, NULL);
+      attributes.event_mask |= fevent;
+      attribute_mask = CWEventMask;
+      XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+			       attribute_mask, &amp;attributes);
   }
-#else /* X_I18N_INHIBITED */
-  FRAME_XIM (f) = 0;
-  FRAME_XIC (f) = 0;
-#endif /* X_I18N_INHIBITED */
 #endif /* HAVE_X_I18N */
-
   validate_x_resource_name ();
 
   class_hints.res_name = (char *) XSTRING (Vx_resource_name)-&gt;data;
diff -Naurw emacs-20.7.orig/src/xterm.c emacs-20.7/src/xterm.c
--- emacs-20.7.orig/src/xterm.c	Mon Aug  2 09:16:43 1999
+++ emacs-20.7/src/xterm.c	Wed Jul 12 23:28:40 2000
@@ -3791,9 +3791,6 @@
   int prefix;
   Lisp_Object part;
   struct x_display_info *dpyinfo;
-#ifdef HAVE_X_I18N
-  Status status_return;
-#endif
 
   if (interrupt_input_blocked)
     {
@@ -3862,7 +3859,7 @@
 						      event.xclient.window);
 	    /* The necessity of the following line took me
 	       a full work-day to decipher from the docs!!  */
-	    if (f1 != 0 &amp;&amp; FRAME_XIC (f1) &amp;&amp; XFilterEvent (&amp;event, None))
+	    if (XFilterEvent (&amp;event, f1 ? FRAME_X_WINDOW(f1) : None))
 	      break;
 	  }
 #endif
@@ -4235,18 +4232,30 @@
 #ifdef HAVE_X_I18N
 		  if (FRAME_XIC (f))
 		    {
-		      /* The necessity of the following line took me
-			 a full work-day to decipher from the docs!!  */
-		      if (XFilterEvent (&amp;event, None))
-			break;
+		      unsigned char *copy_bufptr = copy_buffer;
+		      int copy_bufsiz = sizeof (copy_buffer);
+		      Status status_return;
+
+		      nbytes = XmbLookupString (FRAME_XIC (f),
+						&amp;event.xkey, copy_bufptr,
+						copy_bufsiz, &amp;keysym,
+						&amp;status_return);
+		      if (status_return == XBufferOverflow)
+			{
+			  copy_bufsiz = nbytes + 1;
+			  copy_bufptr = (char *) alloca (copy_bufsiz);
 		      nbytes = XmbLookupString (FRAME_XIC (f),
-						&amp;event.xkey, copy_buffer,
-						80, &amp;keysym,
+						    &amp;event.xkey, copy_bufptr,
+						    copy_bufsiz, &amp;keysym,
 						&amp;status_return);
+			}
 		      if (status_return == XLookupNone)
 			break;
 		      else if (status_return == XLookupChars)
+			{
 			keysym = NoSymbol;
+			  modifiers = 0;
+			}
 		      else if (status_return != XLookupKeySym
 			       &amp;&amp; status_return != XLookupBoth)
 			abort ();
@@ -4378,7 +4387,10 @@
 		  else
 		    abort ();
 		}
-	      goto OTHER;
+	      break;
+
+	    case KeyRelease:
+	      break;
 
 	      /* Here's a possible interpretation of the whole
 		 FocusIn-EnterNotify FocusOut-LeaveNotify mess.  If you get a
@@ -4515,6 +4527,13 @@
 		  x_real_positions (f, &amp;f-&gt;output_data.x-&gt;left_pos,
 				    &amp;f-&gt;output_data.x-&gt;top_pos);
 
+#ifdef HAVE_X_I18N
+		  if (FRAME_XIC (f) &amp;&amp; (FRAME_XIC_STYLE (f) &amp; XIMStatusArea))
+		    {
+		      xic_set_statusarea (f);
+		    }
+#endif
+
 		  if (f-&gt;output_data.x-&gt;parent_desc != FRAME_X_DISPLAY_INFO (f)-&gt;root_window)
 		    {
 		      /* Since the WM decorations come below top_pos now,
@@ -4992,6 +5011,13 @@
     /* Those are the only two we have implemented!  */
     abort ();
 
+#ifdef HAVE_X_I18N
+  if (FRAME_XIC (f) &amp;&amp; (FRAME_XIC_STYLE (f) &amp; XIMPreeditPosition))
+    {
+      xic_set_preeditarea (f, x, y);
+    }
+#endif
+  
   UNBLOCK_INPUT;
 }
 
@@ -5463,9 +5489,176 @@
   FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f),
 		CHARSET_ASCII, fontsetp-&gt;fontname[CHARSET_ASCII], fontset);
 
+#ifdef HAVE_X_I18N
+  if (FRAME_XIC (f)
+      &amp;&amp; (FRAME_XIC_STYLE (f) &amp; (XIMPreeditPosition | XIMStatusArea)))
+    {
+      xic_set_xfontset (f, fontsetp-&gt;fontname[CHARSET_ASCII]);
+    }
+#endif /* HAVE_X_I18N */
   return build_string (fontsetname);
 }
 
+
+/* Support routines for XIM (X Input Method). */
+#ifdef HAVE_X_I18N
+
+#ifdef HAVE_X11R6
+/* XIM destroy callback function,
+   which is called whenever the connected XIM server dies.
+   Clear XIM information. */
+static void
+xim_destroy_callback (xim, client_data, call_data)
+     XIM xim;
+     XPointer client_data;
+     XPointer call_data;
+{
+  struct x_display_info *dpyinfo = (struct x_display_info *)client_data;
+  Lisp_Object frame, tail;
+  
+  BLOCK_INPUT;
+  /* Don't need to call XDestroyIC. */
+  FOR_EACH_FRAME (tail, frame)
+    if (FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
+      {
+	FRAME_XIC (XFRAME (frame)) = NULL;
+	if (FRAME_XIC_FONTSET (XFRAME (frame)))
+	  {
+	    XFreeFontSet (FRAME_X_DISPLAY (XFRAME (frame)), FRAME_XIC_FONTSET (XFRAME (frame)));
+	    FRAME_XIC_FONTSET (XFRAME (frame)) = NULL;
+	  }
+      }
+  
+  /* Don't need to call XCloseIM. */
+  dpyinfo-&gt;xim = NULL;
+  XFree (dpyinfo-&gt;xim_styles);
+  UNBLOCK_INPUT;
+}
+#endif /* HAVE_X11R6 */
+
+/* Open the connection with XIM server. */
+static void
+xim_open_dpy (dpyinfo, resource_name)
+     struct x_display_info *dpyinfo;
+     char *resource_name;
+{
+  XIM xim;
+
+  xim = XOpenIM (dpyinfo-&gt;display, dpyinfo-&gt;xrdb, resource_name, EMACS_CLASS);
+  dpyinfo-&gt;xim = xim;
+
+  if (xim)
+    {
+      XIMValuesList *xim_values_list;
+#ifdef HAVE_X11R6
+      XIMCallback destroy;
+#endif
+      
+      /* Get supported styles and XIM values */
+      XGetIMValues (xim,
+		    XNQueryInputStyle, &amp;dpyinfo-&gt;xim_styles,
+		    NULL);
+#ifdef HAVE_X11R6
+      destroy.callback = xim_destroy_callback;
+      destroy.client_data = (XPointer)dpyinfo;
+      XSetIMValues (xim, XNDestroyCallback, &amp;destroy, NULL);
+#endif
+    }
+}
+
+#ifdef HAVE_X11R6
+struct xim_inst_t
+{
+  struct x_display_info *dpyinfo;
+  char *resource_name;
+};
+
+/* XIM instantiate callback function,
+   which is called whenever an XIM server is available. */
+static void
+xim_instantiate_callback(display, client_data, call_data)
+     Display *display;
+     XPointer client_data;
+     XPointer call_data;
+{
+  struct xim_inst_t *xim_inst = (struct xim_inst_t *)client_data;
+  struct x_display_info *dpyinfo = xim_inst-&gt;dpyinfo;
+
+  /* We don't support multiple XIM connections. */
+  if (dpyinfo-&gt;xim)
+    return;
+  
+  xim_open_dpy (dpyinfo, xim_inst-&gt;resource_name);
+
+  /* Create XIC for the existing frames on the same display,
+     as long as they have no XIC. */
+  if (dpyinfo-&gt;xim &amp;&amp; dpyinfo-&gt;reference_count &gt; 0)
+    {
+      Lisp_Object tail, frame;
+
+      BLOCK_INPUT;
+      FOR_EACH_FRAME (tail, frame)
+	if (FRAME_X_DISPLAY_INFO (XFRAME (frame)) == xim_inst-&gt;dpyinfo)
+	  if (FRAME_XIC (XFRAME (frame)) == NULL)
+	    {
+	      xic_create_frame (XFRAME (frame));
+	      if (FRAME_XIC_STYLE (XFRAME (frame)) &amp; XIMStatusArea)
+		xic_set_statusarea (XFRAME (frame));
+	      if (FRAME_XIC_STYLE (XFRAME (frame)) &amp; XIMPreeditPosition)
+		xic_set_preeditarea (XFRAME (frame),
+				     FRAME_CURSOR_X (XFRAME (frame)),
+				     FRAME_CURSOR_Y (XFRAME (frame)));
+	    }
+      UNBLOCK_INPUT;
+    }
+}
+#endif /* HAVE_X11R6 */
+
+/* It's dependent on X11R5 or X11R6 to open the connection with XIM server.
+   On X11R5, open the connection only at the first time.
+   On X11R6, open the connection in XIM instantiate callback function. */
+static void
+xim_initialize (dpyinfo, resource_name)
+     struct x_display_info *dpyinfo;
+     char *resource_name;
+{
+#ifdef HAVE_X11R6
+  struct xim_inst_t *xim_inst;
+  int len;
+  
+  dpyinfo-&gt;xim = NULL;
+  xim_inst = (struct xim_inst_t *) xmalloc (sizeof (struct xim_inst_t));
+  xim_inst-&gt;dpyinfo = dpyinfo;
+  len = strlen (resource_name);
+  xim_inst-&gt;resource_name = (char *) xmalloc (len + 1);
+  bcopy (resource_name, xim_inst-&gt;resource_name, len + 1);
+  XRegisterIMInstantiateCallback (dpyinfo-&gt;display, dpyinfo-&gt;xrdb,
+				  resource_name, EMACS_CLASS,
+				  xim_instantiate_callback, (XPointer)xim_inst);
+#else /* not HAVE_X11R6 */
+  dpyinfo-&gt;xim = NULL;
+  xim_open_dpy (dpyinfo, resource_name);
+#endif /* not HAVE_X11R6 */
+}
+
+/* Close the connection with XIM server. */
+static void
+xim_close_dpy (dpyinfo)
+     struct x_display_info *dpyinfo;
+{
+#ifdef HAVE_X11R6
+  XUnregisterIMInstantiateCallback(dpyinfo-&gt;display, dpyinfo-&gt;xrdb,
+				   NULL, EMACS_CLASS,
+				   xim_instantiate_callback, NULL);
+#endif /* HAVE_X11R6 */
+  XCloseIM (dpyinfo-&gt;xim);
+  dpyinfo-&gt;xim = NULL;
+
+  XFree (dpyinfo-&gt;xim_styles);
+}
+#endif /* HAVE_X_I18N */
+
+
 /* Calculate the absolute position in frame F
    from its current recorded position values and gravity.  */
 
@@ -6175,15 +6368,9 @@
       if (f-&gt;output_data.x-&gt;icon_desc != 0)
 	XDestroyWindow (FRAME_X_DISPLAY (f), f-&gt;output_data.x-&gt;icon_desc);
 #ifdef HAVE_X_I18N
-      if (FRAME_XIM (f))
+      if (FRAME_XIC (f))
 	{
-	  XDestroyIC (FRAME_XIC (f));
-#if ! defined (SOLARIS2) || defined (HAVE_X11R6)
-	  /* This line causes crashes on Solaris with Openwin,
-	     due to an apparent bug in XCloseIM.
-	     X11R6 seems not to have the bug.  */
-	  XCloseIM (FRAME_XIM (f));
-#endif
+	  xic_destroy_frame (f);
 	}
 #endif
       XDestroyWindow (FRAME_X_DISPLAY (f), f-&gt;output_data.x-&gt;window_desc);
@@ -7335,6 +7522,10 @@
 				     1);
   }
 
+#ifdef HAVE_X_I18N
+  xim_initialize (dpyinfo, resource_name);
+#endif
+  
 #ifdef subprocesses
   /* This is only needed for distinguishing keyboard and process input.  */
   if (connection != 0)
@@ -7440,6 +7631,11 @@
   if (--dpyinfo-&gt;kboard-&gt;reference_count == 0)
     delete_kboard (dpyinfo-&gt;kboard);
 #endif
+#ifdef HAVE_X_I18N
+  if (dpyinfo-&gt;xim)
+    xim_close_dpy (dpyinfo);
+#endif
+  
   xfree (dpyinfo-&gt;font_table);
   xfree (dpyinfo-&gt;x_id_name);
   xfree (dpyinfo);
diff -Naurw emacs-20.7.orig/src/xterm.h emacs-20.7/src/xterm.h
--- emacs-20.7.orig/src/xterm.h	Sun Aug 16 07:58:10 1998
+++ emacs-20.7/src/xterm.h	Sat Jun 17 00:18:37 2000
@@ -297,6 +297,12 @@
   /* The null pixel used for filling a character background with
      background color of a gc.  */
   Pixmap null_pixel;
+
+#ifdef HAVE_X_I18N
+  /* XIM(X Input method) */
+  XIM xim;
+  XIMStyles *xim_styles;
+#endif
 };
 
 /* This is a chain of structures for all the X displays currently in use.  */
@@ -492,10 +498,11 @@
   char has_been_visible;
 
 #ifdef HAVE_X_I18N
-  /* Input method. */
-  XIM xim;
+  /* XIM(X Input method) */
   /* Input context (currently, this means Compose key handler setup).  */
   XIC xic;
+  XIMStyle xic_style;
+  XFontSet xic_xfs;
 #endif
 };
 
@@ -526,6 +533,7 @@
 #define FRAME_FONT(f) ((f)-&gt;output_data.x-&gt;font)
 #define FRAME_FONTSET(f) ((f)-&gt;output_data.x-&gt;fontset)
 #define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)-&gt;output_data.x-&gt;internal_border_width)
+#define FRAME_MENUBAR_HEIGHT(f) ((f)-&gt;output_data.x-&gt;menubar_height)
 #define FRAME_LINE_HEIGHT(f) ((f)-&gt;output_data.x-&gt;line_height)
 
 /* This gives the x_display_info structure for the display F is on.  */
@@ -546,8 +554,11 @@
 
 #define FRAME_DESIRED_CURSOR(f) ((f)-&gt;output_data.x-&gt;desired_cursor)
 
-#define FRAME_XIM(f) ((f)-&gt;output_data.x-&gt;xim)
+#define FRAME_X_XIM(f) (FRAME_X_DISPLAY_INFO (f)-&gt;xim)
+#define FRAME_X_XIM_STYLES(f) (FRAME_X_DISPLAY_INFO (f)-&gt;xim_styles)
 #define FRAME_XIC(f) ((f)-&gt;output_data.x-&gt;xic)
+#define FRAME_XIC_STYLE(f) ((f)-&gt;output_data.x-&gt;xic_style)
+#define FRAME_XIC_FONTSET(f) ((f)-&gt;output_data.x-&gt;xic_xfs)
 
 /* X-specific scroll bar stuff.  */
 
@@ -877,6 +888,11 @@
 extern void x_set_border_pixel P_ ((struct frame *, int));
 extern void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
 extern void x_implicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
+extern void xic_create_frame P_ ((struct frame *));
+extern void xic_destroy_frame P_ ((struct frame *));
+extern void xic_set_preeditarea P_ ((struct frame *, int, int));
+extern void xic_set_statusarea P_ ((struct frame *));
+extern void xic_set_xfontset P_ ((struct frame *, char *));
 extern int x_pixel_width P_ ((struct frame *));
 extern int x_pixel_height P_ ((struct frame *));
 extern int x_char_width P_ ((struct frame *));
</pre></body></html>