From 7c9e55e6233cf6fe1c7eb8a2ec868aff646bb323 Mon Sep 17 00:00:00 2001 From: carlos <2carlos.wong@gmail.com> Date: Fri, 21 Oct 2022 18:52:19 +0800 Subject: [PATCH 1/2] add neovim async job support --- plugin/smartim.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/smartim.vim b/plugin/smartim.vim index 16dc72e..6fe03e9 100644 --- a/plugin/smartim.vim +++ b/plugin/smartim.vim @@ -69,6 +69,9 @@ function! Smartim_SelectDefault() if has('job') call job_start([s:imselect_path], {'callback': 'Smartim_GetInputMethodHandler'}) + elseif has('nvim') + echo "get nvim" + call jobstart([s:imselect_path], {'callback': 'Smartim_GetInputMethodHandler'}) else silent let b:saved_im = system(s:imselect_path) silent call system(s:imselect_path . ' ' . g:smartim_default) @@ -88,10 +91,12 @@ function! Smartim_SelectSaved() if exists("b:saved_im") && b:saved_im != g:smartim_default if has('job') call job_start([s:imselect_path, b:saved_im]) + elseif has('nvim') + echo "xxxx" + call jobstart([s:imselect_path, b:saved_im]) else silent call system(s:imselect_path . ' '. b:saved_im) endif - call Smartim_debug_print('b:saved_im=' . b:saved_im.'') call Smartim_debug_print('<<< Smartim_SelectSaved returned ' . v:shell_error) else From f4509d54c50afb2c0c717b1c3b7ae973ba92705b Mon Sep 17 00:00:00 2001 From: carlos <2carlos.wong@gmail.com> Date: Wed, 26 Oct 2022 11:23:21 +0800 Subject: [PATCH 2/2] compatible with nvim's job-control --- im-select.m | 1 + plugin/smartim.vim | 37 +++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/im-select.m b/im-select.m index 084cf47..0b45c5e 100644 --- a/im-select.m +++ b/im-select.m @@ -28,6 +28,7 @@ int main(int argc, const char * argv[]) { TISInputSourceRef current = TISCopyCurrentKeyboardInputSource(); NSString *sourceId = (NSString *)(TISGetInputSourceProperty(current, kTISPropertyInputSourceID)); fprintf(stdout, "%s\n", [sourceId UTF8String]); + fflush(stdout); CFRelease(current); } diff --git a/plugin/smartim.vim b/plugin/smartim.vim index 6fe03e9..39098fb 100644 --- a/plugin/smartim.vim +++ b/plugin/smartim.vim @@ -53,11 +53,22 @@ endfunction call Smartim_start_debug() -function! Smartim_GetInputMethodHandler(channel, msg) - silent let b:saved_im = a:msg - silent call system(s:imselect_path . ' ' .g:smartim_default) - call Smartim_debug_print('b:saved_im = ' . b:saved_im) - call Smartim_debug_print('<<< Smartim_SelectDefault returned ' . v:shell_error) +function! s:Smartim_GetInputMethodHandler_Vim(channel, msg) + call s:Smartim_RestoreDefaultIm(a:msg) +endfunction + +function! s:Smartim_GetInputMethodHandler_Nvim(job_id, data, event) dict + let output = a:data[0][:-1] + if len(output) + call s:Smartim_RestoreDefaultIm(output) + endif +endfunction + +function! s:Smartim_RestoreDefaultIm(current) + silent let b:saved_im = a:current + silent call system(s:imselect_path . ' ' .g:smartim_default) + call Smartim_debug_print('b:saved_im = ' . b:saved_im) + call Smartim_debug_print('<<< Smartim_SelectDefault returned ' . v:shell_error) endfunction function! Smartim_SelectDefault() @@ -68,31 +79,25 @@ function! Smartim_SelectDefault() endif if has('job') - call job_start([s:imselect_path], {'callback': 'Smartim_GetInputMethodHandler'}) + call job_start([s:imselect_path], {'callback': 's:Smartim_GetInputMethodHandler_Vim'}) elseif has('nvim') - echo "get nvim" - call jobstart([s:imselect_path], {'callback': 'Smartim_GetInputMethodHandler'}) + call jobstart([s:imselect_path], {'on_stdout' : function('s:Smartim_GetInputMethodHandler_Nvim')}) else - silent let b:saved_im = system(s:imselect_path) - silent call system(s:imselect_path . ' ' . g:smartim_default) - call Smartim_debug_print('b:saved_im = ' . b:saved_im) - call Smartim_debug_print('<<< Smartim_SelectDefault returned ' . v:shell_error) + silent let output = system(s:imselect_path) + silent call s:Smartim_RestoreDefaultIm(output) endif endfunction function! Smartim_SelectSaved() call Smartim_debug_print('>>> Smartim_SelectSaved') - if g:smartim_disable == 1 return endif - if exists("b:saved_im") && b:saved_im != g:smartim_default if has('job') call job_start([s:imselect_path, b:saved_im]) elseif has('nvim') - echo "xxxx" call jobstart([s:imselect_path, b:saved_im]) else silent call system(s:imselect_path . ' '. b:saved_im) @@ -111,4 +116,4 @@ augroup smartim autocmd InsertEnter * call Smartim_SelectSaved() augroup end -" vim:ts=2:sw=2:sts=2 +" vim:ts=2:sw=2:sts=2 \ No newline at end of file