Hi,

You should instead use the integrated :make/quickfix feature of vim. You'll 
have a much better user experience.

First be sure that you have set javac as the make program. It's best done by 
sourcing compiler/javac.vim
-> :runtime compiler/javac.vim

I would have done it in a java ftplugin, but as I'm not a Java developer, I'm 
not sure this is a good default setting. So, let's put it in your function.


```vim
command! MakeAndRun :call s:CompileAndRunFolderJava()

function! s:CompileAndRunFolderJava() abort
   runtime compiler/javac.vim

   " old trick to detect compilation errors - part 1
   " --- The following code is borrowed from LaTeXSuite
   "   close the quickfix window before trying to open it again, 
   "   otherwise whether or not we end up in the quickfix window 
   "   after the :cwindow command is not fixed.
   cclose " used to detect errors
   let winnum = winnr()

   " compile all java files in folder of the current buffer
   make %:p:h/*.java

   " old trick to detect compilation errors - part 2
   if winnum == winnr() " => no error detected
     " run Main java file in that folder
     :!(cd .. && java %:p:h:t.Main)

     " delete all the .class files in that folder
     :!rm %:p:h/*.class
   endif

   " :echomsg "Done"
endfunction
```

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to