To: vim_dev@googlegroups.com Subject: Patch 8.1.2000 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2000 Problem: Plugin cannot get the current IME status. Solution: Add the getimstatus() function. (closes #4904) Files: runtime/doc/eval.txt, src/evalfunc.c, src/mbyte.c, src/proto/mbyte.pro, src/testdir/test_iminsert.vim *** ../vim-8.1.1999/runtime/doc/eval.txt 2019-09-06 22:45:47.574271573 +0200 --- runtime/doc/eval.txt 2019-09-07 14:56:53.676889183 +0200 *************** *** 2463,2468 **** --- 2468,2474 ---- getfsize({fname}) Number size in bytes of file {fname} getftime({fname}) Number last modification time of file getftype({fname}) String description of type of file {fname} + getimstatus() Number |TRUE| if the IME status is active getjumplist([{winnr} [, {tabnr}]]) List list of jump list items getline({lnum}) String line {lnum} of current buffer *************** *** 5194,5199 **** --- 5203,5213 ---- Can also be used as a |method|: > GetFilename()->getftype() + getimstatus() *getimstatus()* + The result is a Number, which is |TRUE| when the IME status is + active. + See 'imstatusfunc'. + getjumplist([{winnr} [, {tabnr}]]) *getjumplist()* Returns the |jumplist| for the specified window. *** ../vim-8.1.1999/src/evalfunc.c 2019-09-06 22:45:47.574271573 +0200 --- src/evalfunc.c 2019-09-07 15:01:39.794359554 +0200 *************** *** 507,512 **** --- 507,513 ---- {"getfsize", 1, 1, FEARG_1, f_getfsize}, {"getftime", 1, 1, FEARG_1, f_getftime}, {"getftype", 1, 1, FEARG_1, f_getftype}, + {"getimstatus", 0, 0, 0, f_getimstatus}, {"getjumplist", 0, 2, FEARG_1, f_getjumplist}, {"getline", 1, 2, FEARG_1, f_getline}, {"getloclist", 1, 2, 0, f_getloclist}, *** ../vim-8.1.1999/src/mbyte.c 2019-07-08 23:30:03.618603190 +0200 --- src/mbyte.c 2019-09-07 15:01:28.126459776 +0200 *************** *** 6497,6502 **** --- 6497,6514 ---- #endif /* FEAT_XIM */ + #if defined(FEAT_EVAL) || defined(PROTO) + /* + * "getimstatus()" function + */ + void + f_getimstatus(typval_T *argvars UNUSED, typval_T *rettv) + { + # if defined(HAVE_INPUT_METHOD) + rettv->vval.v_number = im_get_status(); + # endif + } + #endif /* * Setup "vcp" for conversion from "from" to "to". *** ../vim-8.1.1999/src/proto/mbyte.pro 2019-03-22 16:33:03.487016094 +0100 --- src/proto/mbyte.pro 2019-09-07 15:01:34.770402682 +0200 *************** *** 90,95 **** --- 90,96 ---- int im_is_preediting(void); void xim_set_status_area(void); int xim_get_status_area_height(void); + void f_getimstatus(typval_T *argvars, typval_T *rettv); int convert_setup(vimconv_T *vcp, char_u *from, char_u *to); int convert_setup_ext(vimconv_T *vcp, char_u *from, int from_unicode_is_utf8, char_u *to, int to_unicode_is_utf8); int convert_input(char_u *ptr, int len, int maxlen); *** ../vim-8.1.1999/src/testdir/test_iminsert.vim 2019-01-24 17:59:35.139217458 +0100 --- src/testdir/test_iminsert.vim 2019-09-07 14:56:53.676889183 +0200 *************** *** 2,18 **** let s:imactivatefunc_called = 0 let s:imstatusfunc_called = 0 func IM_activatefunc(active) let s:imactivatefunc_called = 1 endfunc func IM_statusfunc() let s:imstatusfunc_called = 1 ! return 0 endfunc func Test_iminsert2() set imactivatefunc=IM_activatefunc set imstatusfunc=IM_statusfunc set iminsert=2 --- 2,23 ---- let s:imactivatefunc_called = 0 let s:imstatusfunc_called = 0 + let s:imstatus_active = 0 func IM_activatefunc(active) let s:imactivatefunc_called = 1 + let s:imstatus_active = a:active endfunc func IM_statusfunc() let s:imstatusfunc_called = 1 ! return s:imstatus_active endfunc func Test_iminsert2() + let s:imactivatefunc_called = 0 + let s:imstatusfunc_called = 0 + set imactivatefunc=IM_activatefunc set imstatusfunc=IM_statusfunc set iminsert=2 *************** *** 25,27 **** --- 30,58 ---- call assert_equal(expected, s:imactivatefunc_called) call assert_equal(expected, s:imstatusfunc_called) endfunc + + func Test_imgetstatus() + if has('gui_running') + if !has('win32') + throw 'Skipped: running in the GUI, only works on MS-Windows' + endif + set imactivatefunc= + set imstatusfunc= + else + set imactivatefunc=IM_activatefunc + set imstatusfunc=IM_statusfunc + let s:imstatus_active = 0 + endif + + new + set iminsert=2 + call feedkeys("i\=getimstatus()\\", 'nx') + call assert_equal('1', getline(1)) + set iminsert=0 + call feedkeys("o\=getimstatus()\\", 'nx') + call assert_equal('0', getline(2)) + bw! + + set imactivatefunc= + set imstatusfunc= + endfunc *** ../vim-8.1.1999/src/version.c 2019-09-07 15:44:34.789023120 +0200 --- src/version.c 2019-09-07 15:25:52.258638931 +0200 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 2000, /**/ -- hundred-and-one symptoms of being an internet addict: 207. You're given one phone call in prison and you ask them for a laptop. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///