Tuesday, August 16, 2011

Re: functions in vim does't respond to % or %<

On Tue, 16 Aug 2011, zhufeng wrote:

> hey guys, I want to write a function in _vimrc to compile some source
> code file .
>
> For example, I want to use "set makeprg=javac\ %" to compile .java
> file, and if there is no error I wanna vim to continue run the "java
> %<", and if there are any errors , I wanna vim to open the quickfix
> windows automatically. So , the problem is how to judge whether there
> is error after compile .

If there is a problem, most compilers will respect standard UNIX
conventions and return an error value.


> I wanna use vim's function filereadable() to judge whether there is
> any error

Don't. It might be left over from the last time you compiled, for
example.


I accomplish exactly what you seem to be trying to do via:

let &makeprg='javac %:p && java -cp $CLASSPATH:%:h %:t:r'

javac %:p Compiles
&& Tests that javac returned true (success)
java -cp %:h %:t:r Runs the file by classname

Using `:let-&` rather than `:set` is to avoid having to escape the
spaces.

Then :make compiles the class, runs it, and returns to the first error,
if any.

You should ensure your $CLASSPATH is setup elsewhere.

--
Best,
Ben

--
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

No comments: