Skip to content

Commit 6315a9a

Browse files
committed
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)
1 parent 291a9d1 commit 6315a9a

11 files changed

Lines changed: 146 additions & 38 deletions

File tree

runtime/doc/mbyte.txt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ For changing the language of messages and menus see |mlang.txt|.
2626
7. Input on X11 |mbyte-XIM|
2727
8. Input on MS-Windows |mbyte-IME|
2828
9. Input with a keymap |mbyte-keymap|
29-
10. Using UTF-8 |mbyte-utf8|
30-
11. Overview of options |mbyte-options|
29+
10. Input with imactivatefunc() |mbyte-func|
30+
11. Using UTF-8 |mbyte-utf8|
31+
12. Overview of options |mbyte-options|
3132

3233
NOTE: This file contains UTF-8 characters. These may show up as strange
3334
characters or boxes when using another encoding.
@@ -1254,7 +1255,35 @@ Combining forms:
12541255
ﭏ 0xfb4f Xal alef-lamed
12551256

12561257
==============================================================================
1257-
10. Using UTF-8 *mbyte-utf8* *UTF-8* *utf-8* *utf8*
1258+
10. Input with imactivatefunc() *mbyte-func*
1259+
1260+
Vim has |imactivatefunc()| and |imstatusfunc()|. This is useful to
1261+
activate/deativate input method from Vim in any way, also with an external
1262+
command. For example, fcitx provide fcitx-remote command: >
1263+
1264+
set iminsert=2
1265+
set imsearch=2
1266+
set imcmdline
1267+
1268+
set imactivatefunc=ImActivate
1269+
function! ImActivate(active)
1270+
if a:active
1271+
call system('fcitx-remote -o')
1272+
else
1273+
call system('fcitx-remote -c')
1274+
endif
1275+
endfunction
1276+
1277+
set imstatusfunc=ImStatus
1278+
function! ImStatus()
1279+
return system('fcitx-remote')[0] is# '2'
1280+
endfunction
1281+
1282+
Using this script, you can activate/deactivate XIM via Vim even when it is not
1283+
compiled with |+xim|.
1284+
1285+
==============================================================================
1286+
11. Using UTF-8 *mbyte-utf8* *UTF-8* *utf-8* *utf8*
12581287
*Unicode* *unicode*
12591288
The Unicode character set was designed to include all characters from other
12601289
character sets. Therefore it is possible to write text in any language using
@@ -1402,7 +1431,7 @@ not everybody is able to type a composing character.
14021431

14031432

14041433
==============================================================================
1405-
11. Overview of options *mbyte-options*
1434+
12. Overview of options *mbyte-options*
14061435

14071436
These options are relevant for editing multi-byte files. Check the help in
14081437
options.txt for detailed information.

runtime/doc/options.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,8 +4256,7 @@ A jump table for the options with a short description can be found at |Q_op|.
42564256
'imactivatefunc' 'imaf' string (default "")
42574257
global
42584258
{not in Vi}
4259-
{only available when compiled with |+xim| and
4260-
|+GUI_GTK|}
4259+
{only available when compiled with |+mbyte|}
42614260
This option specifies a function that will be called to
42624261
activate/inactivate Input Method.
42634262

@@ -4308,8 +4307,7 @@ A jump table for the options with a short description can be found at |Q_op|.
43084307
'imcmdline' 'imc' boolean (default off)
43094308
global
43104309
{not in Vi}
4311-
{only available when compiled with the |+xim|,
4312-
|+multi_byte_ime| or |global-ime| features}
4310+
{only available when compiled with |+mbyte|}
43134311
When set the Input Method is always on when starting to edit a command
43144312
line, unless entering a search pattern (see 'imsearch' for that).
43154313
Setting this option is useful when your input method allows entering
@@ -4320,8 +4318,7 @@ A jump table for the options with a short description can be found at |Q_op|.
43204318
'imdisable' 'imd' boolean (default off, on for some systems (SGI))
43214319
global
43224320
{not in Vi}
4323-
{only available when compiled with the |+xim|,
4324-
|+multi_byte_ime| or |global-ime| features}
4321+
{only available when compiled with |+mbyte|}
43254322
When set the Input Method is never used. This is useful to disable
43264323
the IM when it doesn't work properly.
43274324
Currently this option is on by default for SGI/IRIX machines. This
@@ -4336,8 +4333,6 @@ A jump table for the options with a short description can be found at |Q_op|.
43364333
0 :lmap is off and IM is off
43374334
1 :lmap is ON and IM is off
43384335
2 :lmap is off and IM is ON
4339-
2 is available only when compiled with the |+multi_byte_ime|, |+xim|
4340-
or |global-ime|.
43414336
To always reset the option to zero when leaving Insert mode with <Esc>
43424337
this can be used: >
43434338
:inoremap <ESC> <ESC>:set iminsert=0<CR>
@@ -4350,6 +4345,10 @@ A jump table for the options with a short description can be found at |Q_op|.
43504345
The value 0 may not work correctly with Athena and Motif with some XIM
43514346
methods. Use 'imdisable' to disable XIM then.
43524347

4348+
You can set 'imactivatefunc' and 'imstatusfunc' to handle IME/XIM
4349+
via external command if vim is not compiled with the |+xim|,
4350+
|+multi_byte_ime| or |global-ime|.
4351+
43534352
*'imsearch'* *'ims'*
43544353
'imsearch' 'ims' number (default -1)
43554354
local to buffer
@@ -4372,8 +4371,7 @@ A jump table for the options with a short description can be found at |Q_op|.
43724371
'imstatusfunc' 'imsf' string (default "")
43734372
global
43744373
{not in Vi}
4375-
{only available when compiled with |+xim| and
4376-
|+GUI_GTK|}
4374+
{only available when compiled with |+mbyte|}
43774375
This option specifies a function that is called to obtain the status
43784376
of Input Method. It must return a positive number when IME is active.
43794377

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,7 @@ test_arglist \
21902190
test_highlight \
21912191
test_history \
21922192
test_hlsearch \
2193+
test_iminsert \
21932194
test_increment \
21942195
test_increment_dbcs \
21952196
test_ins_complete \

src/mbyte.c

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,6 +4782,20 @@ iconv_end(void)
47824782

47834783
#endif /* FEAT_MBYTE */
47844784

4785+
#ifdef FEAT_EVAL
4786+
static void
4787+
call_imactivatefunc(int active)
4788+
{
4789+
char_u *argv[1];
4790+
4791+
if (active)
4792+
argv[0] = (char_u *)"1";
4793+
else
4794+
argv[0] = (char_u *)"0";
4795+
(void)call_func_retnr(p_imaf, 1, argv, FALSE);
4796+
}
4797+
#endif
4798+
47854799
#if defined(FEAT_XIM) || defined(PROTO)
47864800

47874801
# if defined(FEAT_GUI_GTK) || defined(PROTO)
@@ -4824,7 +4838,14 @@ im_set_active(int active)
48244838
im_is_active = (active && !p_imdisable);
48254839

48264840
if (im_is_active != was_active)
4827-
xim_reset();
4841+
{
4842+
#ifdef FEAT_EVAL
4843+
if (p_imaf[0] != NUL)
4844+
call_imactivatefunc(im_is_active);
4845+
else
4846+
#endif
4847+
xim_reset();
4848+
}
48284849
}
48294850

48304851
void
@@ -5666,15 +5687,7 @@ xim_reset(void)
56665687

56675688
# ifdef FEAT_EVAL
56685689
if (p_imaf[0] != NUL)
5669-
{
5670-
char_u *argv[1];
5671-
5672-
if (im_is_active)
5673-
argv[0] = (char_u *)"1";
5674-
else
5675-
argv[0] = (char_u *)"0";
5676-
(void)call_func_retnr(p_imaf, 1, argv, FALSE);
5677-
}
5690+
call_imactivatefunc(im_is_active);
56785691
else
56795692
# endif
56805693
if (im_activatekey_keyval != GDK_VoidSymbol)
@@ -6442,6 +6455,45 @@ xim_get_status_area_height(void)
64426455
}
64436456
# endif
64446457

6458+
#else /* !defined(FEAT_XIM) */
6459+
6460+
# ifndef FEAT_GUI_W32
6461+
int
6462+
im_get_status()
6463+
{
6464+
# ifdef FEAT_EVAL
6465+
if (p_imsf[0] != NUL)
6466+
{
6467+
int is_active;
6468+
6469+
/* FIXME: Don't execute user function in unsafe situation. */
6470+
if (exiting
6471+
# ifdef FEAT_AUTOCMD
6472+
|| is_autocmd_blocked()
6473+
# endif
6474+
)
6475+
return FALSE;
6476+
/* FIXME: :py print 'xxx' is shown duplicate result.
6477+
* Use silent to avoid it. */
6478+
++msg_silent;
6479+
is_active = call_func_retnr(p_imsf, 0, NULL, FALSE);
6480+
--msg_silent;
6481+
return (is_active > 0);
6482+
}
6483+
# endif
6484+
return FALSE;
6485+
}
6486+
6487+
void
6488+
im_set_active(int active)
6489+
{
6490+
# ifdef(USE_IM_CONTROL) && defined(FEAT_EVAL)
6491+
if (p_imaf[0] != NUL)
6492+
call_imactivatefunc(p_imdisable ? FALSE : active);
6493+
# endif
6494+
}
6495+
# endif
6496+
64456497
#endif /* FEAT_XIM */
64466498

64476499
#if defined(FEAT_MBYTE) || defined(PROTO)

src/option.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ static struct vimoption options[] =
15391539
(char_u *)&p_ic, PV_NONE,
15401540
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
15411541
{"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1542-
# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1542+
#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
15431543
(char_u *)&p_imaf, PV_NONE,
15441544
{(char_u *)"", (char_u *)NULL}
15451545
# else
@@ -1582,7 +1582,7 @@ static struct vimoption options[] =
15821582
{(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
15831583
SCRIPTID_INIT},
15841584
{"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
1585-
#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1585+
#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
15861586
(char_u *)&p_imsf, PV_NONE,
15871587
{(char_u *)"", (char_u *)NULL}
15881588
#else

src/option.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,13 @@ EXTERN char_u *p_iconstring; /* 'iconstring' */
581581
EXTERN int p_ic; /* 'ignorecase' */
582582
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
583583
EXTERN char_u *p_imak; /* 'imactivatekey' */
584+
#define IM_ON_THE_SPOT 0L
585+
#define IM_OVER_THE_SPOT 1L
586+
EXTERN long p_imst; /* 'imstyle' */
587+
#endif
588+
#if defined(FEAT_EVAL) && defined(USE_IM_CONTROL)
584589
EXTERN char_u *p_imaf; /* 'imactivatefunc' */
585590
EXTERN char_u *p_imsf; /* 'imstatusfunc' */
586-
EXTERN long p_imst; /* 'imstyle' */
587-
# define IM_ON_THE_SPOT 0L
588-
# define IM_OVER_THE_SPOT 1L
589591
#endif
590592
#ifdef USE_IM_CONTROL
591593
EXTERN int p_imcmdline; /* 'imcmdline' */

src/structs.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,12 +2091,8 @@ struct file_buffer
20912091
#define B_IMODE_USE_INSERT -1 /* Use b_p_iminsert value for search */
20922092
#define B_IMODE_NONE 0 /* Input via none */
20932093
#define B_IMODE_LMAP 1 /* Input via langmap */
2094-
#ifndef USE_IM_CONTROL
2095-
# define B_IMODE_LAST 1
2096-
#else
2097-
# define B_IMODE_IM 2 /* Input via input method */
2098-
# define B_IMODE_LAST 2
2099-
#endif
2094+
#define B_IMODE_IM 2 /* Input via input method */
2095+
#define B_IMODE_LAST 2
21002096

21012097
#ifdef FEAT_KEYMAP
21022098
short b_kmap_state; /* using "lmap" mappings */

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ NEW_TESTS = test_arabic.res \
115115
test_highlight.res \
116116
test_history.res \
117117
test_hlsearch.res \
118+
test_iminsert.res \
118119
test_increment.res \
119120
test_increment_dbcs.res \
120121
test_ins_complete.res \

src/testdir/test_iminsert.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
if !has('multi_byte')
2+
finish
3+
endif
4+
5+
source view_util.vim
6+
7+
let s:imactivatefunc_called = 0
8+
let s:imstatusfunc_called = 0
9+
10+
func IM_activatefunc(active)
11+
let s:imactivatefunc_called = 1
12+
endfunc
13+
14+
func IM_statusfunc()
15+
let s:imstatusfunc_called = 1
16+
return 0
17+
endfunc
18+
19+
func Test_iminsert2()
20+
set imactivatefunc=IM_activatefunc
21+
set imstatusfunc=IM_statusfunc
22+
set iminsert=2
23+
normal! i
24+
set iminsert=0
25+
set imactivatefunc=
26+
set imstatusfunc=
27+
call assert_equal(1, s:imactivatefunc_called)
28+
call assert_equal(1, s:imstatusfunc_called)
29+
endfunc

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1336,
774776
/**/
775777
1335,
776778
/**/

0 commit comments

Comments
 (0)