diff src/mbyte.c @ 12920:327e1264b9bf v8.0.1336

patch 8.0.1336: cannot use imactivatefunc() unless compiled with +xim commit https://github.com/vim/vim/commit/6315a9ae924d2104b61d1667ea71af3ac7cf48fa Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 25 15:20:02 2017 +0100 patch 8.0.1336: cannot use imactivatefunc() unless compiled with +xim Problem: Cannot use imactivatefunc() unless compiled with +xim. Solution: Allow using imactivatefunc() when not compiled with +xim. (Yasuhiro Matsumoto, closes #2349)
author Christian Brabandt <cb@256bit.org>
date Sat, 25 Nov 2017 15:30:06 +0100
parents 351cf7c67bbe
children 6bafba651e20
line wrap: on
line diff
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -4782,6 +4782,20 @@ iconv_end(void)
 
 #endif /* FEAT_MBYTE */
 
+#ifdef FEAT_EVAL
+    static void
+call_imactivatefunc(int active)
+{
+    char_u *argv[1];
+
+    if (active)
+	argv[0] = (char_u *)"1";
+    else
+	argv[0] = (char_u *)"0";
+    (void)call_func_retnr(p_imaf, 1, argv, FALSE);
+}
+#endif
+
 #if defined(FEAT_XIM) || defined(PROTO)
 
 # if defined(FEAT_GUI_GTK) || defined(PROTO)
@@ -4824,7 +4838,14 @@ im_set_active(int active)
     im_is_active = (active && !p_imdisable);
 
     if (im_is_active != was_active)
-	xim_reset();
+    {
+#ifdef FEAT_EVAL
+	if (p_imaf[0] != NUL)
+	    call_imactivatefunc(im_is_active);
+	else
+#endif
+	    xim_reset();
+    }
 }
 
     void
@@ -5666,15 +5687,7 @@ xim_reset(void)
 
 #  ifdef FEAT_EVAL
 	    if (p_imaf[0] != NUL)
-	    {
-		char_u *argv[1];
-
-		if (im_is_active)
-		    argv[0] = (char_u *)"1";
-		else
-		    argv[0] = (char_u *)"0";
-		(void)call_func_retnr(p_imaf, 1, argv, FALSE);
-	    }
+		call_imactivatefunc(im_is_active);
 	    else
 #  endif
 		if (im_activatekey_keyval != GDK_VoidSymbol)
@@ -6442,6 +6455,45 @@ xim_get_status_area_height(void)
 }
 # endif
 
+#else /* !defined(FEAT_XIM) */
+
+# ifndef FEAT_GUI_W32
+    int
+im_get_status()
+{
+#  ifdef FEAT_EVAL
+    if (p_imsf[0] != NUL)
+    {
+	int is_active;
+
+	/* FIXME: Don't execute user function in unsafe situation. */
+	if (exiting
+#   ifdef FEAT_AUTOCMD
+		|| is_autocmd_blocked()
+#   endif
+		)
+	    return FALSE;
+	/* FIXME: :py print 'xxx' is shown duplicate result.
+	 * Use silent to avoid it. */
+	++msg_silent;
+	is_active = call_func_retnr(p_imsf, 0, NULL, FALSE);
+	--msg_silent;
+	return (is_active > 0);
+    }
+#  endif
+    return FALSE;
+}
+
+    void
+im_set_active(int active)
+{
+#  ifdef(USE_IM_CONTROL) && defined(FEAT_EVAL)
+    if (p_imaf[0] != NUL)
+	call_imactivatefunc(p_imdisable ? FALSE : active);
+#  endif
+}
+# endif
+
 #endif /* FEAT_XIM */
 
 #if defined(FEAT_MBYTE) || defined(PROTO)