Tuesday, August 16, 2011

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

On Tuesday, August 16, 2011 05:29:39 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 . I
> wanna use vim's function filereadable() to judge whether
> there is any error (if there is error , javac will not create
> a class file ), but when I try to use this function, I found
> that the function filereadable() can't receive arguments like
> % and %<, the result is , ":echo filereadable("test.class")"
> is 1, but ":echo filereadable("%<.class")" is 0 .The current
> file I am editing is test.java, so this confused me a lot .

> I wonder whether fuctions like filereadable() can receive
> arguments like % or %<, and anyone who can help me to write
> my own function ? Thanks a lot .

> sorry for my poor English , I hope you guys can understand
> what I mean .

i can guarandamntee your english is better than my $(your
first language)

i think the command you are looking for is

:execute

what you do is put the static part of your command in quotes,
and the part that'll need interpretation outside the quotes,
so in your case you'd wind up with something like [untested]:

:execute 'let t = filereadable(' %< '.class)'

that may not be necessary but it's a fallback --

:let

also causes interpretation, and you may be able to get by with
a simple

:let t = filereadable("%<".class)

or a variation on that theme

hth, and your english is fine

sc

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