drmingdrmer / xptemplate

Code snippets engine for Vim, with snippets library. XPTemplate let you write codes in a smooth, quick and comfortable way.

Home Page:http://www.vim.org/scripts/script.php?script_id=2611

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expandable inside of repetition.

NCSantos opened this issue · comments

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.

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

@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.

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...^

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

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?

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