Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active November 17, 2017 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/35526ec896b3baa9b11e4f78fa2755fb to your computer and use it in GitHub Desktop.
Save mattn/35526ec896b3baa9b11e4f78fa2755fb to your computer and use it in GitHub Desktop.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index b9e82d73a..dcdf51efd 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -4245,8 +4245,7 @@ A jump table for the options with a short description can be found at |Q_op|.
'imactivatefunc' 'imaf' string (default "")
global
{not in Vi}
- {only available when compiled with |+xim| and
- |+GUI_GTK|}
+ {only available when compiled with |+mbyte|}
This option specifies a function that will be called to
activate/inactivate Input Method.
@@ -4297,8 +4296,7 @@ A jump table for the options with a short description can be found at |Q_op|.
'imcmdline' 'imc' boolean (default off)
global
{not in Vi}
- {only available when compiled with the |+xim|,
- |+multi_byte_ime| or |global-ime| features}
+ {only available when compiled with |+mbyte|}
When set the Input Method is always on when starting to edit a command
line, unless entering a search pattern (see 'imsearch' for that).
Setting this option is useful when your input method allows entering
@@ -4309,8 +4307,7 @@ A jump table for the options with a short description can be found at |Q_op|.
'imdisable' 'imd' boolean (default off, on for some systems (SGI))
global
{not in Vi}
- {only available when compiled with the |+xim|,
- |+multi_byte_ime| or |global-ime| features}
+ {only available when compiled with |+mbyte|}
When set the Input Method is never used. This is useful to disable
the IM when it doesn't work properly.
Currently this option is on by default for SGI/IRIX machines. This
@@ -4325,8 +4322,6 @@ A jump table for the options with a short description can be found at |Q_op|.
0 :lmap is off and IM is off
1 :lmap is ON and IM is off
2 :lmap is off and IM is ON
- 2 is available only when compiled with the |+multi_byte_ime|, |+xim|
- or |global-ime|.
To always reset the option to zero when leaving Insert mode with <Esc>
this can be used: >
:inoremap <ESC> <ESC>:set iminsert=0<CR>
@@ -4339,6 +4334,10 @@ A jump table for the options with a short description can be found at |Q_op|.
The value 0 may not work correctly with Athena and Motif with some XIM
methods. Use 'imdisable' to disable XIM then.
+ You can set 'imactivatefunc' and 'imstatusfunc' to handle IME/XIM
+ via external command if vim is not compiled with the |+xim|,
+ |+multi_byte_ime| or |global-ime|.
+
*'imsearch'* *'ims'*
'imsearch' 'ims' number (default -1)
local to buffer
@@ -4361,8 +4360,7 @@ A jump table for the options with a short description can be found at |Q_op|.
'imstatusfunc' 'imsf' string (default "")
global
{not in Vi}
- {only available when compiled with |+xim| and
- |+GUI_GTK|}
+ {only available when compiled with |+mbyte|}
This option specifies a function that is called to obtain the status
of Input Method. It must return a positive number when IME is active.
diff --git a/src/mbyte.c b/src/mbyte.c
index 3592ddbdd..a7eb20ff9 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -6442,6 +6442,56 @@ xim_get_status_area_height(void)
}
# endif
+#else
+
+# 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)
+{
+ if (p_imdisable)
+ active = FALSE;
+
+# ifdef FEAT_EVAL
+ if (p_imaf[0] != NUL)
+ {
+ char_u *argv[1];
+
+ if (!im_get_status())
+ argv[0] = (char_u *)"1";
+ else
+ argv[0] = (char_u *)"0";
+ (void)call_func_retnr(p_imaf, 1, argv, FALSE);
+ }
+# endif
+}
+# endif
+
#endif /* FEAT_XIM */
#if defined(FEAT_MBYTE) || defined(PROTO)
diff --git a/src/option.c b/src/option.c
index 4f25c1ff4..21cdca684 100644
--- a/src/option.c
+++ b/src/option.c
@@ -1530,7 +1530,7 @@ static struct vimoption options[] =
(char_u *)&p_ic, PV_NONE,
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
{"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
-# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
+#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
(char_u *)&p_imaf, PV_NONE,
{(char_u *)"", (char_u *)NULL}
# else
@@ -1573,7 +1573,7 @@ static struct vimoption options[] =
{(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
SCRIPTID_INIT},
{"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
-#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
+#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
(char_u *)&p_imsf, PV_NONE,
{(char_u *)"", (char_u *)NULL}
#else
diff --git a/src/option.h b/src/option.h
index f9972f21a..8775ac055 100644
--- a/src/option.h
+++ b/src/option.h
@@ -574,7 +574,7 @@ EXTERN int p_icon; /* 'icon' */
EXTERN char_u *p_iconstring; /* 'iconstring' */
#endif
EXTERN int p_ic; /* 'ignorecase' */
-#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
+#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
EXTERN char_u *p_imak; /* 'imactivatekey' */
EXTERN char_u *p_imaf; /* 'imactivatefunc' */
EXTERN char_u *p_imsf; /* 'imstatusfunc' */
diff --git a/src/structs.h b/src/structs.h
index 774104cf5..6aaccc511 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -2091,12 +2091,8 @@ struct file_buffer
#define B_IMODE_USE_INSERT -1 /* Use b_p_iminsert value for search */
#define B_IMODE_NONE 0 /* Input via none */
#define B_IMODE_LMAP 1 /* Input via langmap */
-#ifndef USE_IM_CONTROL
-# define B_IMODE_LAST 1
-#else
-# define B_IMODE_IM 2 /* Input via input method */
-# define B_IMODE_LAST 2
-#endif
+#define B_IMODE_IM 2 /* Input via input method */
+#define B_IMODE_LAST 2
#ifdef FEAT_KEYMAP
short b_kmap_state; /* using "lmap" mappings */
diff --git a/src/vim.h b/src/vim.h
index d12c46cd8..d990d31c6 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -531,9 +531,7 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */
/*
* Check input method control.
*/
-#if defined(FEAT_XIM) \
- || (defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME))) \
- || (defined(FEAT_GUI_MAC) && defined(FEAT_MBYTE))
+#if defined(FEAT_MBYTE)
# define USE_IM_CONTROL
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment