Home Download Buy Blog Forum Support

Nested snippets not expanding

Nested snippets not expanding

Postby shawnoster on Fri Aug 12, 2011 9:21 pm


I noticed nested snippets aren't working.

In an HTML file when I type ul it correctly expands to <ul></ul>. I next type li and normally that would expand to <li></li> but when it's the first thing I type after the ul expands it just sits there.

It appears that the stack that tracks expansions isn't currently setup to check if the text just entered was a snippet and instead stays within the scope of the first snippet. I'd LOVE to see this fixed.

Posts: 5
Joined: Fri Aug 12, 2011 9:16 pm

Re: Nested snippets not expanding

Postby Leimi on Thu Sep 15, 2011 7:37 am


I don't know if this is a bug or if this is on purpose but it is kind of annoying in fact.

For example if I want to quickly type in PHP
Code: Select all
if (!empty(...)) {

I'd like to be able to insert the if snippet and the empty snippet right after it.

It would be really great if nested snippets were available :)
Posts: 3
Joined: Thu Sep 15, 2011 7:31 am

Re: Nested snippets not expanding

Postby janpolsen on Thu Sep 15, 2011 7:57 am

Is this the keypress sequence you are looking for?
Code: Select all
Best regards,
Posts: 4
Joined: Thu Sep 08, 2011 5:43 am
Location: Denmark

Re: Nested snippets not expanding

Postby Leimi on Thu Sep 15, 2011 12:20 pm

In this example the perfect thing would be :
  • I type if<tab>
  • the "if" parentheses appear, I directly type empty<tab>
  • the "empty" parentheses appear, I type what I want in it and press <tab>
  • the prompt is now outside the "empty" parentheses (it gets out of the "empty' snippet) but still inside the "if"
  • if I press tab again it goes inside the if { } to type the rest of the code
This kind of behavior is already available by accessing to "sub snippets" with ctrl+space instead of tab but it's kind of annoying.
For example in php I can have an "array" snippet that I want to trigger when I'm already in the process of a snippet:
  • I type array<ctrl+space>
  • the list of all possible snippets and functions appear
  • I potentially have to go through the list for a while before finding my snippet between similarly named functions
  • I type enter, the "array" snippet appears
  • I can tab in it as usual and after going out of it I can continue to tab in the "parent" snippet.

So, in one hand you now have "ctrl + space + finding snippet in list" and in other (not existing?) hand you have "tab". I want that "tab" :P
Posts: 3
Joined: Thu Sep 15, 2011 7:31 am

Re: Nested snippets not expanding

Postby Leimi on Sat Sep 24, 2011 8:27 pm

Hey, thanks for your answer and your code snippet!

I changed the keys to ctrl+space and set the exact parameter to false. This enables me to stop having to go through a list of possible snippets when I want to trigger one. So in the end I trigger normal snippets with tab, I trigger nested snippets with ctrl+space and go through all of them normally with tab. I didn't have lots of time to test but right now it seems the best option for me :)

I couldn't find a way to have something that works perfectly only by using "tab" based on your code though.
With the code given, I can trigger snippets in other snippets, but I can't go through the snippets anymore with tab: tab just inserts a real tab.

I'm all ears if you have any other idea to find something perfect, otherwise this is already more productive than before, thanks ;)
Posts: 3
Joined: Thu Sep 15, 2011 7:31 am

Re: Nested snippets not expanding

Postby grayrest on Thu Sep 29, 2011 5:45 pm

I'm going to bump this as well with two questions:

Is there a command like insert_best_completion that only does snippet expansion?

Is there a good place to request a new condition? I'd like to be able to write:

Code: Select all
   { "keys": ["tab"], "command": "insert_best_completion", "args": {"exact": true}, "context":
         { "key": "has_next_field", "operator": "equal", "operand": true, "match_all": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "at_tab_trigger", "operator": "equal", "operand": true, "match_all": true }
         //{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\<(?i:a|b)\\>$", "match_all": true } // workaround

I'm guessing I could hack around it at the scripting level, but it seems like something that'd be relatively easy to add and the smallest change to the system to get tab working as expected. I'm currently working around it by hard coding my nested snippets as shown above but that's obviously not ideal. Kudos to Jon for allowing the expansion system to work with non-tab characters (I like ; for snippet expansion/jumping) without me having to hack around in the system.
Posts: 12
Joined: Thu Sep 29, 2011 5:03 pm

Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 23 guests