I have a tricky problem and don't know how to solve it. I use
map to declare a shortcut key for the gradle test below:
map <C-S-F10> <Esc>:wa<CR>:let last_test = expand("%")<CR><S-F10> map <S-F10> <Esc>:wa<CR>:call OpenWindow('tests')<CR>:%d<CR>:call RunTests(last_test)<CR> fun! RunTests(...) if(a:0 == 0) silent .!./gradlew test else execute "silent" ".!./gradlew test --tests '*".a:1."'" endif endfun fun! OpenWindow(bufname) let winid = bufwinid(a:bufname) if(winid != -1) "buff window is not closed call win_gotoid(winid) return endif let absent = ! bufexists(a:bufname) execute "new ".a:bufname "move window to bottom let n = winnr('$') - winnr() execute n.'wincmd r' if(absent) "set options & map for new buffer set bufhidden=hide buftype=nofile nobuflisted noswapfile map <buffer> q <Esc>:q<CR> endif endfun
When I press
<C-S-F10> this behavior is what I want:
First, if the tests buffer does not exist, then create a new buffer named tests, otherwise open/focus the window for the existing tests buffer.
Next, clear the last test result in tests buffer by
RunTestsand fill the result of
But when I went to refactor the mapping as below, the behavior is not what I want. All of the steps above will not be done until the bash script is done. How can I make my
OpenRunTests execute the behavior like the mapping?
map <C-F10> <Esc>:wa<CR>:silent OpenWinAndRunTests()<CR> fun! OpenWinAndRunTests() call OpenWindow("tests") %d "clear buffer is not done until the shell command finished, how can I fix it? call RunTests(g:last_test) endfun