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 32f355d..55dbf2c 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,30 +79,29 @@ 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') + 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') + 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 @@ -106,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