Sunday, August 29, 2010

Re: getting the source code for an anonymous function

A

2010/8/4 Andy Wokula <anwoku@yahoo.de>
Am 04.08.2010 13:20, schrieb Bram Moolenaar:

Ted cecinemapasderange wrote:

I asked [this question] a while back on stackoverflow.com: how to get
the source code for an anonymous VimL function.

The response that I got explained that doing e.g.

    :function {42}

would display the source code for anonymous function #42.

This is particularly useful when debugging errors or exceptions in
anonymous functions, as the function number is the only way to
identify the function.

However neither I nor the responder seem to be able to find the
documentation for this feature.  Is vim intended to work this way?
Can this command be expected to continue to function in subsequent
versions of vim?

[this question]: http://stackoverflow.com/questions/2626137

I'd like to say it's a cool workaround, thanks for sharing!


You are not supposed to use the function number.  Use the name under
which it is stored.  E.g. for the example:

     :let mydict = {'data': [0, 1, 2, 3]}
     :function mydict.len() dict
     :   return len(self.data)
     :endfunction
     :echo mydict.len()

You can use
     :function mydict.len

The obvious question is: If all you get from the error message is a
number, how do you know this number represents mydict.len()?

The topic has come up before:

getting more information about numbered functions in traces?
http://groups.google.com/group/vim_use/browse_thread/thread/63f4de4d7afd900/b8357da9088ad333

And there is an item in the todo list (:h todo):

It's difficult to debug numbered functions (function in a Dictionary).  Print
the function name before resolving it to a number?
       let d = {}
       fun! d.foo()
         echo "here"
       endfun
       call d.foo(9)

--
Andy


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