diff src/gui_xim.c @ 26408:8f17f8f327f3 v8.2.3735

patch 8.2.3735: cannot use a lambda for 'imactivatefunc' Commit: https://github.com/vim/vim/commit/7645da568c5e3b4ee339a2e99c3b3af790619787 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Dec 4 14:02:30 2021 +0000 patch 8.2.3735: cannot use a lambda for 'imactivatefunc' Problem: Cannot use a lambda for 'imactivatefunc'. Solution: Add lambda support for 'imactivatefunc' and 'imstatusfunc'. (Yegappan Lakshmanan, closes #9275)
author Bram Moolenaar <Bram@vim.org>
date Sat, 04 Dec 2021 15:15:03 +0100
parents 038eb6d9003a
children 13ba00ef7687
line wrap: on
line diff
--- a/src/gui_xim.c
+++ b/src/gui_xim.c
@@ -67,8 +67,24 @@ xim_log(char *s, ...)
 # define USE_IMSTATUSFUNC (*p_imsf != NUL)
 #endif
 
-#if defined(FEAT_EVAL) && \
-    (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
+#if (defined(FEAT_EVAL) && \
+     (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))) || \
+    defined(PROTO)
+static callback_T imaf_cb;	    // 'imactivatefunc' callback function
+static callback_T imsf_cb;	    // 'imstatusfunc' callback function
+
+    int
+set_imactivatefunc_option(void)
+{
+    return option_set_callback_func(p_imaf, &imaf_cb);
+}
+
+    int
+set_imstatusfunc_option(void)
+{
+    return option_set_callback_func(p_imsf, &imsf_cb);
+}
+
     static void
 call_imactivatefunc(int active)
 {
@@ -77,7 +93,7 @@ call_imactivatefunc(int active)
     argv[0].v_type = VAR_NUMBER;
     argv[0].vval.v_number = active ? 1 : 0;
     argv[1].v_type = VAR_UNKNOWN;
-    (void)call_func_retnr(p_imaf, 1, argv);
+    (void)call_callback_retnr(&imaf_cb, 1, argv);
 }
 
     static int
@@ -91,12 +107,25 @@ call_imstatusfunc(void)
     // FIXME: :py print 'xxx' is shown duplicate result.
     // Use silent to avoid it.
     ++msg_silent;
-    is_active = call_func_retnr(p_imsf, 0, NULL);
+    is_active = call_callback_retnr(&imsf_cb, 0, NULL);
     --msg_silent;
     return (is_active > 0);
 }
 #endif
 
+#if defined(EXITFREE) || defined(PROTO)
+    void
+free_xim_stuff(void)
+{
+#if defined(FEAT_EVAL) && \
+    (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
+    free_callback(&imaf_cb);
+    free_callback(&imsf_cb);
+# endif
+}
+#endif
+
+
 #if defined(FEAT_XIM) || defined(PROTO)
 
 # if defined(FEAT_GUI_GTK) || defined(PROTO)