Skip to content

Commit 2d34f2a

Browse files
committed
updated for version 7.3.1248
Problem: Still have old hacking code for Input Method. Solution: Add 'imactivatefunc' and 'imstatusfunc' as a generic solution to Input Method activation. (Yukihiro Nakadaira)
1 parent 5789a47 commit 2d34f2a

File tree

7 files changed

+93
-31
lines changed

7 files changed

+93
-31
lines changed

runtime/doc/options.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3993,6 +3993,26 @@ A jump table for the options with a short description can be found at |Q_op|.
39933993
Can be overruled by using "\c" or "\C" in the pattern, see
39943994
|/ignorecase|.
39953995

3996+
*'imactivatefunc'* *'imaf'*
3997+
'imactivatefunc' 'imaf' string (default "")
3998+
global
3999+
{not in Vi}
4000+
{only available when compiled with |+xim| and
4001+
|+GUI_GTK|}
4002+
This option specifies a function that will be called to
4003+
activate/inactivate Input Method.
4004+
4005+
Example: >
4006+
function ImActivateFunc(active)
4007+
if a:active
4008+
... do something
4009+
else
4010+
... do something
4011+
endif
4012+
" return value is not used
4013+
endfunction
4014+
set imactivatefunc=ImActivateFunc
4015+
<
39964016
*'imactivatekey'* *'imak'*
39974017
'imactivatekey' 'imak' string (default "")
39984018
global
@@ -4089,6 +4109,24 @@ A jump table for the options with a short description can be found at |Q_op|.
40894109
The value 0 may not work correctly with Athena and Motif with some XIM
40904110
methods. Use 'imdisable' to disable XIM then.
40914111

4112+
*'imstatusfunc'* *'imsf'*
4113+
'imstatusfunc' 'imsf' string (default "")
4114+
global
4115+
{not in Vi}
4116+
{only available when compiled with |+xim| and
4117+
|+GUI_GTK|}
4118+
This option specifies a function that is called to obtain the status
4119+
of Input Method. It must return a positive number when IME is active.
4120+
4121+
Example: >
4122+
function ImStatusFunc()
4123+
let is_active = ...do something
4124+
return is_active ? 1 : 0
4125+
endfunction
4126+
set imstatusfunc=ImStatusFunc
4127+
<
4128+
NOTE: This function is invoked very often. Keep it fast.
4129+
40924130
*'include'* *'inc'*
40934131
'include' 'inc' string (default "^\s*#\s*include")
40944132
global or local to buffer |global-local|

src/fileio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9572,6 +9572,12 @@ unblock_autocmds()
95729572
# endif
95739573
}
95749574

9575+
int
9576+
is_autocmd_blocked()
9577+
{
9578+
return autocmd_blocked != 0;
9579+
}
9580+
95759581
/*
95769582
* Find next autocommand pattern that matches.
95779583
*/

src/mbyte.c

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4447,7 +4447,7 @@ im_set_active(int active)
44474447
{
44484448
int was_active;
44494449

4450-
was_active = !!im_is_active;
4450+
was_active = !!im_get_status();
44514451
im_is_active = (active && !p_imdisable);
44524452

44534453
if (im_is_active != was_active)
@@ -5071,44 +5071,25 @@ xim_reset(void)
50715071
{
50725072
if (xic != NULL)
50735073
{
5074-
/*
5075-
* The third-party imhangul module (and maybe others too) ignores
5076-
* gtk_im_context_reset() or at least doesn't reset the active state.
5077-
* Thus sending imactivatekey would turn it off if it was on before,
5078-
* which is clearly not what we want. Fortunately we can work around
5079-
* that for imhangul by sending GDK_Escape, but I don't know if it
5080-
* works with all IM modules that support an activation key :/
5081-
*
5082-
* An alternative approach would be to destroy the IM context and
5083-
* recreate it. But that means loading/unloading the IM module on
5084-
* every mode switch, which causes a quite noticeable delay even on
5085-
* my rather fast box...
5086-
* *
5087-
* Moreover, there are some XIM which cannot respond to
5088-
* im_synthesize_keypress(). we hope that they reset by
5089-
* xim_shutdown().
5090-
*/
5091-
if (im_activatekey_keyval != GDK_VoidSymbol && im_is_active)
5092-
im_synthesize_keypress(GDK_Escape, 0U);
5093-
50945074
gtk_im_context_reset(xic);
50955075

5096-
/*
5097-
* HACK for Ami: This sequence of function calls makes Ami handle
5098-
* the IM reset graciously, without breaking loads of other stuff.
5099-
* It seems to force English mode as well, which is exactly what we
5100-
* want because it makes the Ami status display work reliably.
5101-
*/
5102-
gtk_im_context_set_use_preedit(xic, FALSE);
5103-
51045076
if (p_imdisable)
51055077
im_shutdown();
51065078
else
51075079
{
5108-
gtk_im_context_set_use_preedit(xic, TRUE);
51095080
xim_set_focus(gui.in_focus);
51105081

5111-
if (im_activatekey_keyval != GDK_VoidSymbol)
5082+
if (p_imaf[0] != NUL)
5083+
{
5084+
char_u *argv[1];
5085+
5086+
if (im_is_active)
5087+
argv[0] = (char_u *)"1";
5088+
else
5089+
argv[0] = (char_u *)"0";
5090+
(void)call_func_retnr(p_imaf, 1, argv, FALSE);
5091+
}
5092+
else if (im_activatekey_keyval != GDK_VoidSymbol)
51125093
{
51135094
if (im_is_active)
51145095
{
@@ -5268,6 +5249,20 @@ xim_queue_key_press_event(GdkEventKey *event, int down)
52685249
int
52695250
im_get_status(void)
52705251
{
5252+
if (p_imsf[0] != NUL)
5253+
{
5254+
int is_active;
5255+
5256+
/* FIXME: Don't execute user function in unsafe situation. */
5257+
if (exiting || is_autocmd_blocked())
5258+
return FALSE;
5259+
/* FIXME: :py print 'xxx' is shown duplicate result.
5260+
* Use silent to avoid it. */
5261+
++msg_silent;
5262+
is_active = call_func_retnr(p_imsf, 0, NULL, FALSE);
5263+
--msg_silent;
5264+
return (is_active > 0);
5265+
}
52715266
return im_is_active;
52725267
}
52735268

src/option.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,15 @@ static struct vimoption
14251425
{"ignorecase", "ic", P_BOOL|P_VI_DEF,
14261426
(char_u *)&p_ic, PV_NONE,
14271427
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1428+
{"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1429+
# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1430+
(char_u *)&p_imaf, PV_NONE,
1431+
{(char_u *)"", (char_u *)NULL}
1432+
# else
1433+
(char_u *)NULL, PV_NONE,
1434+
{(char_u *)NULL, (char_u *)0L}
1435+
# endif
1436+
SCRIPTID_INIT},
14281437
{"imactivatekey","imak",P_STRING|P_VI_DEF,
14291438
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
14301439
(char_u *)&p_imak, PV_NONE,
@@ -1467,6 +1476,15 @@ static struct vimoption
14671476
{(char_u *)B_IMODE_NONE, (char_u *)0L}
14681477
#endif
14691478
SCRIPTID_INIT},
1479+
{"imstatusfunc","imse",P_STRING|P_VI_DEF|P_SECURE,
1480+
# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1481+
(char_u *)&p_imsf, PV_NONE,
1482+
{(char_u *)"", (char_u *)NULL}
1483+
# else
1484+
(char_u *)NULL, PV_NONE,
1485+
{(char_u *)NULL, (char_u *)0L}
1486+
# endif
1487+
SCRIPTID_INIT},
14701488
{"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
14711489
#ifdef FEAT_FIND_ID
14721490
(char_u *)&p_inc, PV_INC,

src/option.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ EXTERN char_u *p_iconstring; /* 'iconstring' */
558558
EXTERN int p_ic; /* 'ignorecase' */
559559
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
560560
EXTERN char_u *p_imak; /* 'imactivatekey' */
561+
EXTERN char_u *p_imaf; /* 'imactivatefunc' */
562+
EXTERN char_u *p_imsf; /* 'imstatusfunc' */
561563
#endif
562564
#ifdef USE_IM_CONTROL
563565
EXTERN int p_imcmdline; /* 'imcmdline' */

src/proto/fileio.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int has_textchangedI __ARGS((void));
4949
int has_insertcharpre __ARGS((void));
5050
void block_autocmds __ARGS((void));
5151
void unblock_autocmds __ARGS((void));
52+
int is_autocmd_blocked __ARGS((void));
5253
char_u *getnextac __ARGS((int c, void *cookie, int indent));
5354
int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
5455
char_u *get_augroup_name __ARGS((expand_T *xp, int idx));

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ static char *(features[]) =
728728

729729
static int included_patches[] =
730730
{ /* Add new patch number below this line */
731+
/**/
732+
1248,
731733
/**/
732734
1247,
733735
/**/

0 commit comments

Comments
 (0)