Skip to content

Commit

Permalink
Neovim-friendly modification
Browse files Browse the repository at this point in the history
The compile error message did not show in neovim, so this commit make
the message show and the run command will not be executed if there is
any message output after compiling.

This modification is only for C and C++.
  • Loading branch information
aben20807 committed Nov 25, 2021
1 parent 0f19af8 commit ac32f09
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions autoload/runner.vim
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,17 @@ endfunction
" To do all subfunctions.
function! runner#DoAll() abort
if b:supported
call runner#Before()
call runner#Compile()
call runner#Run()
call runner#After()
try
call runner#Before()
call runner#Compile()
call runner#Run()
call runner#After()
catch /.*/
echo "Error: " . v:exception
return
endtry
else
call runner#ShowInfo("不支援")
call runner#ShowInfo("not supported")
endif
endfunction

Expand All @@ -117,13 +122,9 @@ function! runner#Before() abort
endif
if g:runner_print_timestamp && b:ft !=# 'markdown'
let l:date = strftime("%Y-%m-%d_%T")
silent execute "!printf '\033[31m' "
silent execute '!printf "\n<<<< \%s \%s >>>>\n" ' .
let l:info_msg = 'printf "\n<<<< %s %s >>>>\n" ' .
\l:date . " " . expand('%:t')
silent execute "!printf '\033[0m'"
if b:supported == 0
execute "!printf ''"
endif
echo system(l:info_msg)
endif
endfunction

Expand All @@ -133,19 +134,29 @@ endfunction
function! runner#Compile() abort
let b:tmp_name = strftime("%s")
if b:ft ==# 'c'
silent execute "!" . g:runner_c_executable . " " .
\ g:runner_c_compile_options .
\ " % -o " .
let l:compile_cmd = g:runner_c_executable . " " .
\ g:runner_c_compile_options . " " .
\ expand('%:t') .
\ " -o " .
\ b:tmp_dir .
\ b:tmp_name .
\ ".out"
let l:compile_msg = system(l:compile_cmd)
if len(l:compile_msg) != 0
throw l:compile_msg
endif
elseif b:ft ==# 'cpp'
silent execute "!" . g:runner_cpp_executable . " " .
\ g:runner_cpp_compile_options .
\ " % -o " .
let l:compile_cmd = g:runner_cpp_executable . " " .
\ g:runner_cpp_compile_options . " " .
\ expand('%:t') .
\ " -o " .
\ b:tmp_dir .
\ b:tmp_name .
\ ".out"
let l:compile_msg = system(l:compile_cmd)
if len(l:compile_msg) != 0
throw l:compile_msg
endif
elseif b:ft ==# 'rust'
if g:runner_rust_executable ==# "rustc"
" Change output path if running in cygwin and use absolute path
Expand Down

0 comments on commit ac32f09

Please sign in to comment.