Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions im-select.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
38 changes: 24 additions & 14 deletions plugin/smartim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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