Add function do return a vim dictionary with current snippets
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
UltiSnips |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
Hi Sirver,
I wrote two small functions, one in vimL UltiSnips_
list_snippets_dict which is similar to list_snippets but just returns a vim dictionary with the snippets and description.
The purpose of this is to be able to list the matching snippets via a pump instead of in the bottom of the window.
For this the user would need to install two plugins from Ingo Karkat: SnippetComplete and SnippetComplete
I will email the author of those plugins to see if he can change one of them so it will support ultisnips
(the only change will be to replace the line
let l:snippets = GetSnipsInCurre
by the line
let l:snippets = UltiSnips_
so I don't antecipate a big problem there.
I tried to record a short video showing the functionality:
http://
Please accept the patch or let me know issues you see with it.
If you decide to accept and once I hear from Ingo I will also add additional information to the documentation so the users can use this functionality.
Jorge (skeept) wrote : | #1 |
SirVer (sirver) wrote : | #2 |
Changed in ultisnips: | |
status: | New → Incomplete |
Jorge (skeept) wrote : Re: [Bug 1171227] Re: Add function do return a vim dictionary with current snippets | #3 |
I have looked at Mark Webber's fork before, but for the some reason I
decided to stick with the Ultisnips main branch.
I will welcome the new release when it is done...
Regards,
Jorge
On Sun, Apr 21, 2013 at 3:48 PM, SirVer <email address hidden> wrote:
> take a look at the current v3.0 branch. I think what you want is already
> implemented there - though the code is not pretty.
>
>
> ** Changed in: ultisnips
> Status: New => Incomplete
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Add function do return a vim dictionary with current snippets
>
> Status in UltiSnips - The Ultimate Snippet Solution for Vim:
> Incomplete
>
> Bug description:
> Hi Sirver,
>
> I wrote two small functions, one in vimL UltiSnips_
> calls another function in python
> list_snippets_dict which is similar to list_snippets but just returns a
> vim dictionary with the snippets and description.
>
> The purpose of this is to be able to list the matching snippets via a
> pump instead of in the bottom of the window.
> For this the user would need to install two plugins from Ingo Karkat:
> SnippetComplete and SnippetComplete
>
> I will email the author of those plugins to see if he can change one of
> them so it will support ultisnips
> (the only change will be to replace the line
>
> let l:snippets = GetSnipsInCurre
> by the line
> let l:snippets = UltiSnips_
>
> so I don't antecipate a big problem there.
>
> I tried to record a short video showing the functionality:
> http://
>
> Please accept the patch or let me know issues you see with it.
> If you decide to accept and once I hear from Ingo I will also add
> additional information to the documentation so the users can use this
> functionality.
>
> To manage notifications about this bug go to:
> https:/
>
SirVer (sirver) wrote : | #4 |
I am reluctant to apply this patch, mainly because it will likely break with v3.0 again - if you feel very strongly about it, please at least add a test for it, so there is a chance this will make it through.
Jorge (skeept) wrote : | #5 |
I understand your reluctancy to apply the patch, and from my point of view
if you are working actively in the 3.0 branch I might as well switch to
that branch already.
Like I mentioned I tried it before and at the time I didn't have time to do
the change because some things changed slightly, but I will find time in
the near future.
Having said that, all the patch I suggest does it define a function that
returns a dictionary with the current snippets. The pump stuff is all done
outside ultisnips.
I think it will be usefull to ultisnips to have such a function returning
the current snippets so it can be integrated with other tools. I am
thinking about neocomlcache that provides completion from different
sources, but there might be other plugins doing similar things.
But again, there migth even be a way of getting the list of current
snippets without changing the code inside ultisnips, just defining an
external function... Is this possible at this point?
On Mon, Apr 22, 2013 at 12:26 AM, SirVer <email address hidden> wrote:
> I am reluctant to apply this patch, mainly because it will likely break
> with v3.0 again - if you feel very strongly about it, please at least
> add a test for it, so there is a chance this will make it through.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Add function do return a vim dictionary with current snippets
>
> Status in UltiSnips - The Ultimate Snippet Solution for Vim:
> Incomplete
>
> Bug description:
> Hi Sirver,
>
> I wrote two small functions, one in vimL UltiSnips_
> calls another function in python
> list_snippets_dict which is similar to list_snippets but just returns a
> vim dictionary with the snippets and description.
>
> The purpose of this is to be able to list the matching snippets via a
> pump instead of in the bottom of the window.
> For this the user would need to install two plugins from Ingo Karkat:
> SnippetComplete and SnippetComplete
>
> I will email the author of those plugins to see if he can change one of
> them so it will support ultisnips
> (the only change will be to replace the line
>
> let l:snippets = GetSnipsInCurre
> by the line
> let l:snippets = UltiSnips_
>
> so I don't antecipate a big problem there.
>
> I tried to record a short video showing the functionality:
> http://
>
> Please accept the patch or let me know issues you see with it.
> If you decide to accept and once I hear from Ingo I will also add
> additional information to the documentation so the users can use this
> functionality.
>
> To manage notifications about this bug go to:
> https:/
>
SirVer (sirver) wrote : | #6 |
I am working on that branch, but it is not production ready at this point in time.
I am not aware of pump, and I am not aware how snippet 'selection' is done in the future in the new branch, but it might change radically. So if you feel strongly, provide a test and I'll merge it in current trunk. Or make a patch against the new branch, but expect this to be quite a while off still.
Jorge (skeept) wrote : | #7 |
I will try to provide a test...
Can you point me to where I should look to get it ready? Like other
relevant tests?
Thanks!
On Mon, Apr 22, 2013 at 12:01 PM, SirVer <email address hidden> wrote:
> I am working on that branch, but it is not production ready at this
> point in time.
>
> I am not aware of pump, and I am not aware how snippet 'selection' is
> done in the future in the new branch, but it might change radically. So
> if you feel strongly, provide a test and I'll merge it in current trunk.
> Or make a patch against the new branch, but expect this to be quite a
> while off still.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Add function do return a vim dictionary with current snippets
>
> Status in UltiSnips - The Ultimate Snippet Solution for Vim:
> Incomplete
>
> Bug description:
> Hi Sirver,
>
> I wrote two small functions, one in vimL UltiSnips_
> calls another function in python
> list_snippets_dict which is similar to list_snippets but just returns a
> vim dictionary with the snippets and description.
>
> The purpose of this is to be able to list the matching snippets via a
> pump instead of in the bottom of the window.
> For this the user would need to install two plugins from Ingo Karkat:
> SnippetComplete and SnippetComplete
>
> I will email the author of those plugins to see if he can change one of
> them so it will support ultisnips
> (the only change will be to replace the line
>
> let l:snippets = GetSnipsInCurre
> by the line
> let l:snippets = UltiSnips_
>
> so I don't antecipate a big problem there.
>
> I tried to record a short video showing the functionality:
> http://
>
> Please accept the patch or let me know issues you see with it.
> If you decide to accept and once I hear from Ingo I will also add
> additional information to the documentation so the users can use this
> functionality.
>
> To manage notifications about this bug go to:
> https:/
>
SirVer (sirver) wrote : | #8 |
test.py - it is essentially end-to-end tests. write a new one there, just dump the output you expect into the buffer and compare it with a golden state.
Jorge (skeept) wrote : | #9 |
Thanks, I'll look into it later. But in this case there should be no change
in the buffer when this function is called. All it does is to return a vim
dictionary to be used by external tools.
On Mon, Apr 22, 2013 at 12:56 PM, SirVer <email address hidden> wrote:
> test.py - it is essentially end-to-end tests. write a new one there,
> just dump the output you expect into the buffer and compare it with a
> golden state.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Add function do return a vim dictionary with current snippets
>
> Status in UltiSnips - The Ultimate Snippet Solution for Vim:
> Incomplete
>
> Bug description:
> Hi Sirver,
>
> I wrote two small functions, one in vimL UltiSnips_
> calls another function in python
> list_snippets_dict which is similar to list_snippets but just returns a
> vim dictionary with the snippets and description.
>
> The purpose of this is to be able to list the matching snippets via a
> pump instead of in the bottom of the window.
> For this the user would need to install two plugins from Ingo Karkat:
> SnippetComplete and SnippetComplete
>
> I will email the author of those plugins to see if he can change one of
> them so it will support ultisnips
> (the only change will be to replace the line
>
> let l:snippets = GetSnipsInCurre
> by the line
> let l:snippets = UltiSnips_
>
> so I don't antecipate a big problem there.
>
> I tried to record a short video showing the functionality:
> http://
>
> Please accept the patch or let me know issues you see with it.
> If you decide to accept and once I hear from Ingo I will also add
> additional information to the documentation so the users can use this
> functionality.
>
> To manage notifications about this bug go to:
> https:/
>
SirVer (sirver) wrote : | #10 |
I understand: but just dump it into the buffer and compare the output. It is a little awkward, but it makes sure that it's working as expected.
Jorge (skeept) wrote : | #11 |
- snippet_diff_wit_test.diff Edit (1.9 KiB, text/plain)
I finally had some time to work on this.
I have now added a test with the current patch.
The test is very simple, it just checks that the output is a dictionary and that is has the correct number of elements.
However some issues:
I haven't added any documentation yet. The reason for this is that I contacted the author of the plugins I mentioned but he hasn't replied yet.
I can add documentation of an example of using the provided function but it would be better if he could coordinate and provide a simple change in his plugin.
At this point for each pair (key, val) in the dictionary there is redundant information in the val because all the pairs are of the form
('test', '(test) "this is what test does"')
I would prefer them to be of the type:
('test', 'this is what test does')
Any simple way of accomplishing this?
SirVer (sirver) wrote : | #12 |
you should throw in at least one utf-8 and/or unicode symbol in your test and check for it's correctness.
Jorge (skeept) wrote : | #13 |
Sorry, I didn't have much time to work on this but I would like to put it
in a way that you would consider inclusion.
For that I will include some unicode symbol as you suggest, plus I need to
figure out a way of getting the description of the snippet without getting
the snippet definition itself.
Can you tell me what is the correct way of running a specific test?
When I was trying to run the tests it was taking a while because it was
running all the tests, I was just interested in running the test I wrote.
After I am done with this I will write documentation and will submit again
for your consideration.
On Thu, May 9, 2013 at 4:34 AM, SirVer <email address hidden> wrote:
> you should throw in at least one utf-8 and/or unicode symbol in your
> test and check for it's correctness.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Add function do return a vim dictionary with current snippets
>
> Status in UltiSnips - The Ultimate Snippet Solution for Vim:
> Incomplete
>
> Bug description:
> Hi Sirver,
>
> I wrote two small functions, one in vimL UltiSnips_
> calls another function in python
> list_snippets_dict which is similar to list_snippets but just returns a
> vim dictionary with the snippets and description.
>
> The purpose of this is to be able to list the matching snippets via a
> pump instead of in the bottom of the window.
> For this the user would need to install two plugins from Ingo Karkat:
> SnippetComplete and SnippetComplete
>
> I will email the author of those plugins to see if he can change one of
> them so it will support ultisnips
> (the only change will be to replace the line
>
> let l:snippets = GetSnipsInCurre
> by the line
> let l:snippets = UltiSnips_
>
> so I don't antecipate a big problem there.
>
> I tried to record a short video showing the functionality:
> http://
>
> Please accept the patch or let me know issues you see with it.
> If you decide to accept and once I hear from Ingo I will also add
> additional information to the documentation so the users can use this
> functionality.
>
> To manage notifications about this bug go to:
> https:/
>
SirVer (sirver) wrote : | #14 |
you can do ./test.py TestName to only run all tests that contain 'TestName', e.g.
$ ./test.py Simple
is something that I often do to make sure that I didn't break something stupid.
I am really glad that you take this contribution so seriously - I am currently working on the v3 of Ultisnips - and without tests your new feature would break surely again.
Jorge (skeept) wrote : | #15 |
I was trying to test with adding a unicode char and this doesn't work.
The snippet is defined by
snippet testâ "abc123"
xxxô
endsnippet
and the error I get is
An error occured. This is either a bug in UltiSnips or a bug in a
snippet definition. If you think this is a bug, please report it to
https:/
Following is the full stack trace:
Traceback (most recent call last):
File "/home/
return f(self, *args, **kwds)
File "/home/
_vim.
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in position 4: ordinal not in range(128)
so the problematic line is
_vim.command("let g:current_
Any idea how I can solve this? It works fine with regular chars.
Also to make the test more robust I would like to define a snippet and get the description of the snippet in the test.
So when I define a snippet as above the dict would be {'testâ', "abc123"} but I don't know how to define a snippet with description on the test file.
Currently I am defining the snippet as
snippets = ('test', 'abc123') but in this case 'abc123' is what the snippet will be expanded to.
thanks!
SirVer (sirver) wrote : | #16 |
> Any idea how I can solve this? It works fine with regular chars.
International characters are very much regular chars :). We had plenty of bug reports about them before in UltiSnips, so it is a very good thing that you added tests for them now.
The problem here is that you are trying to format a bytes string with a unicode object. Something along these lines should work:
_vim.
This should help with this problem.
Also think about what happens here if val or the trigger contain a " or a '. A test case for this might be indicated as well.
> So when I define a snippet as above the dict would be {'testâ', "abc123"} but I don't know how to define a snippet with description on the test file.
The code that spilts this tuple is in test.py, line 281. you can define a snippet as
("trigger", "content", "description", "options"), but you can leave out descriptions and/or options.
Hope that helps.
Jorge (skeept) wrote : | #17 |
Thanks for the suggestions but I am still stuck.
I have in the code
description = as_unicode(
key = as_unicode(
_vim.command(
'{val}'
but when trying on the snippets I mentioned before I get the error:
_vim.command(
'{val}'
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in
position 4: ordinal not in range(128)
I may try to ask this on the vim list since someone there might have an
idea on how to solve this (if it is possible to solve this at all).
Jorge
On Tue, May 28, 2013 at 12:49 AM, SirVer <email address hidden> wrote:
> > Any idea how I can solve this? It works fine with regular chars.
>
> International characters are very much regular chars :). We had plenty
> of bug reports about them before in UltiSnips, so it is a very good
> thing that you added tests for them now.
>
> The problem here is that you are trying to format a bytes string with a
> unicode object. Something along these lines should work:
>
> _vim.command(
> '{val}'
>
> This should help with this problem.
>
> Also think about what happens here if val or the trigger contain a " or
> a '. A test case for this might be indicated as well.
>
> > So when I define a snippet as above the dict would be {'testâ',
> "abc123"} but I don't know how to define a snippet with description on the
> test file.
> The code that spilts this tuple is in test.py, line 281. you can define a
> snippet as
> ("trigger", "content", "description", "options"), but you can leave out
> descriptions and/or options.
>
> Hope that helps.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Add function do return a vim dictionary with current snippets
>
> Status in UltiSnips - The Ultimate Snippet Solution for Vim:
> Incomplete
>
> Bug description:
> Hi Sirver,
>
> I wrote two small functions, one in vimL UltiSnips_
> calls another function in python
> list_snippets_dict which is similar to list_snippets but just returns a
> vim dictionary with the snippets and description.
>
> The purpose of this is to be able to list the matching snippets via a
> pump instead of in the bottom of the window.
> For this the user would need to install two plugins from Ingo Karkat:
> SnippetComplete and SnippetComplete
>
> I will email the author of those plugins to see if he can change one of
> them so it will support ultisnips
> (the only change will be to replace the line
>
> let l:snippets = GetSnipsInCurre
> by the line
> let l:snippets = UltiSnips_
>
> so I don't antecipate a big problem there.
>
> I tried to record a short video showing the functionality:
> http://
>
> Please accept the patch or let me know issues you see with it.
> If you decide to accept and once I hear from Ingo I will also add
> additional informa...
SirVer (sirver) wrote : | #18 |
no need to post to the vim list - this is a python problem alone. And I can still spot the problem:
You are doing
as_unicode(
you need to be doing
as_unicode(
Jorge (skeept) wrote : | #19 |
Thanks for spotting the mistake.
I send a patch that includes tests for the things you mentioned, international chars and ' or " in trigger.
Please read the patch when you have a chance, and let me know if there is something that need to be changed.
The function defined is called UltiSnips_
Regards,
Jorge
SirVer (sirver) wrote : | #20 |
Jorge, that seems like a very solid patch that you baked there. Some comments:
- add the new chapter to the contents of the help file.
the tests fail for me on mac os x (all three of them). How do you run them (i mean which OS and which workflow).
Jorge (skeept) wrote : | #21 |
For some reason I sent the patch with a minor mistake. The tests should pass now.
Also do you have any comment regarding the name of the function. I used UltiSnips_
trying to replicate from SnippetMate is GetSnipsInCurre
Do you want to just use the same name for the implemented function? Or maybe UltiSnips_
You can just change the name in the patch or I can send another one later.
SirVer (sirver) wrote : | #22 |
The tests pass now, great.
I renamed the method to UltiSnips_
Thanks for you contribution!
Changed in ultisnips: | |
status: | Incomplete → Fix Committed |
Jorge (skeept) wrote : | #23 |
You're welcome :)
take a look at the current v3.0 branch. I think what you want is already implemented there - though the code is not pretty.