So what opens this additional buffer is your command exe ":botright copen"
, :h :copen
is used to open the quickfix window. As you use it no matter how the compilation went, when the compilation is successful the quickfix doesn't contain anything and the buffer looks open.
So the first thing to do is to remove the useless usages of :exe
: In exe ":cclose"
, exe ":update"
and exe ":botright copen"
you don't need an execute command since the strings to pass to execute
are already complete normal commands. So replace these lines by cclose
, update
and botright open
.
Now to prevent the buffer from opening on failed compilation you probably want to move botright copen
to a specific condition. It could be like this:
if empty(v:statusmsg)
let &statusline = "'".obj."':Compiled successfully"
else
botright copen
endif
Also a few different ideas:
- As B.Layer pointed out in the comments you can reduce the cyclomatic complexity of your function by refactoring your
if
conditions - You don't need to use
:
in front of normal commands in a vimscript - I think there is no benefit using the short name of commands in a script
- And I think you don't need to surround your save of
makeprg
between quotes you should be able to dolet save = &makeprg
and thenexecute 'set makeprg = ' . save
So here is how I would refactor your code:
function! makes#Fcompile()
cclose
update
let sou = expand("%:p")
let obj = expand("%:p:r").s:ObjExt
" Don't process any further if the compilation is up to date
if filereadable(obj) && (getftime(obj)>getftime(sou)))
let &statusline = "'" . obj . "':is up to date"
return
endif
let makeprg_saved = '"' . &makeprg . '"'
execute "setlocal makeprg=" . s:Compiler
let v:statusmsg = ''
execute "make " . s:FCFlags . " " . sou . " -o " . obj
execute 'set makeprg=' . makeprg_saved
" Don'r process any further if the compilation was sucessful
if empty(v:statusmsg)
let &statusline = "'" . obj . "':Compiled successfully"
return
endif
if v:shell_error !=0
let &statusline = v:shell_error
endif
botright copen
endfunction