>On 05/15/13 13:06, Bram Moolenaar wrote:
>> 
>> ZyX wrote:
>> 
>>>> 3. vim.functions:
>>>>   Again, the introspection is not strictly necessary, but a convenience 
>>>>   wrapper that pulls the FuncRefs will make code look much nicer.
>>>>   In that regard I'd also offer attribute access for builtin/ global 
>>>>   functions in addition to the getitem syntax. That way you can do 
>>>>   things like:
>>>>       curbuf = vim.functions.bufnr("%")
>>>
>>> Good idea.
>> 
>> Would it be possible to have most Vim functions made callable from
>> Python this way?  Obviously it's much better than using vim.eval().
>Yes, I think it should work with all builtins (and user functions as
>well, basically anything where function("name") works).

It does.

>
>> 
>> An example from the help:
>> 
>>     :py tagList = vim.eval('taglist("eval_expr")')
>> 
>> Would then be something like:
>> 
>>     :py tagList = vim.functions.taglist(eval_expr)
>> 
>> With the difference that eval_expr would be a Python expression.
>
>Yes, thats exactly the way it would be used. It looks much nicer that
>way and there is no need to escape "eval_expr" appropriately.

You already don’t need this, vim.function type works fine. `vim.functions` is 
a convenience wrapper that also avoids `vim.bindeval` (and thus all that 
expression parsing). I thought Bram is talking about using python regular 
expressions here: otherwise there is no need to record argument types anywhere.

Though now another thought: automatic type conversion (e.g. when deciding 
whether some object that can be converted to float, number or string should be 
converted to one of this). Automatic type conversion is not pythonic: unlike 
Vim 
trying to e.g. add number to string will result in TypeError, not in string 
being converted to number. Making using existing types less strict (i.e. using 
number protocol in place of strict checking for expected number being an 
integer) though is a good idea, I will add it to RFC.

>> 
>> For the internals we would need to have a list of all funtions with
>> their argument types, so that the arguments can be converted from Python
>> to the Vim type.  Could be added to the functions array in eval.c
>In my experiments on the weekend I made a simple wrapper class that
>returned vim.bindeval("function('{0}')".format(attribute_name)).
>I assumed that the FuncRef takes care of the appropriate
>argument conversion when called (but I have not tested it extensively).
>If it does, this should also be doable purely in python with the
>exception of enumerating the available functions.

You can do this purely in python even without `vim.bindeval`. I bet I can 
create 
`vim.bindeval` using only VimL, python own capabilities and `vim.eval`, but it 
would be hackish and very slow.

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Raspunde prin e-mail lui