Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expandable inside of repetition. #85

Open
NCSantos opened this issue Apr 7, 2018 · 6 comments
Open

Expandable inside of repetition. #85

NCSantos opened this issue Apr 7, 2018 · 6 comments

Comments

@NCSantos
Copy link

NCSantos commented Apr 7, 2018

Hi,

Is it possible to get something like this?

if condition {
    ...
} else if cond {
    ...
} else if conf {
    ...
} else {
    ...
}

else is a repetition and if is expandable.

Thanks for your help.

@drmingdrmer
Copy link
Owner

In C language ifee is just what you want.
When focused on else_if..., the key stroke to move to next place holder(by default <tab>) expands it to a else-if clause. the key stroke to clear a place holder(by default <cr>) stops repetition.

if (condition) {
    
}
else if (condition) {
    /* cursor */
} else_if...

@NCSantos
Copy link
Author

NCSantos commented Apr 7, 2018

@drmingdrmer No, ifeedoesn't seem to be what I want, it doesn't even have a expandable part.
With ifee you get:

if ( condition ) {
  
} else_if...

Being the else_if... part highlighted, if you press <tab>on this part you get:

if ( ghjghj ) {
  ffgh
}
else if ( condition ) {
  /* cursor */
} else_if...

Now condition is highlighted and what I would want is to have an expandable part on if ( condition ).

Let me try to explain what I want in more detail:

if condition {
   ...
} else_if...

else_if... is highlighted, now comes 2 possible outcomes:
If on else_if... you press <CR> you get:

if conditon {
   ...
}

Snippet ended.

If you press <tab> you get:

if condition {
   ...
} else if_cond... {
   ...
}

if_cond... is highlighted, here you also have 2 possible outcomes:
You press <CR>you get:

if condition {
   ...
} else {
   ...
}

Snippet ended.

But if you press <tab> you get:

if condition {
   ...
} else if condition {
   cursor
}

Again thanks for you help.

@drmingdrmer
Copy link
Owner

This is a snippet definition for what you want I believe(_if already exists. I simplified it here).
ife is what you need. It is just a nested expandable defined with pair of xx...{{ and }}.

XPT _if hidden
if (`condition^) {
    `cursor^
}

XPT ife
`:_if:^` `else_if...{{^ else` `if_cond...{{^ `Include:_if^` `else_if...^`}}^`}}^

else_if... expands to

 else` `if_cond...{{^ `Include:_if^` `else_if...^`}}^

And if_cond... expands to

 `Include:_if^` `else_if...^

@drmingdrmer
Copy link
Owner

BTW I do not like multi levels expandable. It is not easy to use in practice. I prefer short simple snippets :).

@NCSantos
Copy link
Author

NCSantos commented Apr 8, 2018

Yes, you are correct short simple snippets are better :).

Just another question, with a snippet like this:

append(`slice^, `value^)

I'm getting 3 items in the snippet template, one on slice, another on value and the last at the end, after ).
I guess this happens because the template doesn't have cursor, is there a way to disable this?

@drmingdrmer
Copy link
Owner

No there is not a way to do it like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants