I am writing a vim plugin for the fortran filetype.
In an autoload script, I have done:
" File Name: autoload/makes.vim
let s:Compiler = get(g:, "fortran_compiler", "gfortran")
let s:ObjExt = '.o'
let s:ModExt = '.mod'
let s:ExeExt = ''
let s:VimComp = 'gfortran'
let s:FCFlags = '-Wall -g -O0 -c'
let s:FLFlags = '-Wall -g -O0'
let s:OutputGvim= 'vim'
function! makes#Fcompile()
exe ":cclose"
exe ":update"
let sou = expand("%:p")
let obj = expand("%:p:r").s:ObjExt
if !filereadable(obj) || (filereadable(obj) && (getftime(obj)<getftime(sou)))
let makeprg_saved = '"'.&makeprg.'"'
exe "setlocal makeprg=".s:Compiler
let v:statusmsg = ''
exe "make ".s:FCFlags. " " .sou. " -o " .obj
if empty(v:statusmsg)
:let &statusline = "'".obj."':Compiled successfully"
endif
if v:shell_error !=0
:let &statusline = v:shell_error
endif
":redraw!
exe ":botright copen"
else
:let &statusline = "'".obj."':is up to date"
endif
endfunction
I use it from ftplugin/fortran_mk.vim
like this:
function! Compile()
:call makes#Fcompile()
endfunction
Now, I compile a program, say, foo.f90
as:
Program foo
Implicit None
write (*, *) "Hello"+i
End Program foo
The problem is that when compilation succeeds (:exe Compile()
), a buffer opens named "<Integer>: -- NO NAME --"
. If there is an error the buffer does not open and shows the error in quickfix
.
I want no buffer to open when compilation succeeds and a oneline error when it failed.
obj
file being "up to date". Why not justreturn
after the "Compiled succesfully" message?if
to check the opposite condition and if true set status line to "up to date" andreturn
. Then the rest of the code wouldn't have to all be indented in a largeif
block.