Re: Variable amount of snippet arguments in ultisnips plugin

2012-11-03 Thread skeept
On Friday, November 2, 2012 5:44:35 PM UTC-4, Marco wrote:
 Hi,
 
 
 
 I discovered the plugin ultisnips and like it a lot. However, I have
 
 problems setting up the snippets (BTW: I don't know python). I need
 
 a snippet that has two mandatory arguments and several optional ones
 
 (no more than four). Here an example:
 
 
 
   snippet def def
 
   def ${1:${VISUAL:foo}}
 
   {${2}} {${3}} {${4}}
 
   $0
 
   endsnippet
 
 
 
 Typing def Tab foo C-JbarC-JC-JC-J yields
 
 
 
   def foo
 
   {bar} {} {}
 
 
 
 I don't need the last two braces. How can I omit the empty braces in
 
 this example without defining a snippet for each number of braces?
 
 
 
 
 
 Marco

I have two suggestions for this.

snippet def def
def ${1:${VISUAL:foo}}
{${2}} ${3:{${4}}} ${5:{${6}}}
$0
endsnippet 

global !p
def ins1(t1, t2):
  return t2 if t1 else ''
endglobal

snippet def2 def
def ${1:${VISUAL:foo}}
{${2}} `!p snip.rv=ins1(t[3], '{')`$3`!p snip.rv=ins1(t[3], '}')` `!p 
snip.rv=ins1(t[4], '{')`$4`!p snip.rv=ins1(t[4], '}')`
$0
endsnippet 


the first one is similar to the one you have right now, but if you have to hit 
c-j to go inside the braces, if you hit backspace there the braces are just 
deleted and you move to the next one (you could even nest this one more level 
so if you hit backspace after the first parenthesis the optional ones would be 
skipped.


The second one just creates the parenthesis if you type something there. The 
disadvantage here is that you don't see the optional parenthesis until you type 
something there.

Try the two approaches and see if which one of them (if any) is more convenient 
to you.

Jorge

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


Re: Variable amount of snippet arguments in ultisnips plugin

2012-11-03 Thread Marco
2012-11-03 skeept:

 I have two suggestions for this.
 
 snippet def def
 def ${1:${VISUAL:foo}}
 {${2}} ${3:{${4}}} ${5:{${6}}}
 $0
 endsnippet 

This does not work for me. The optional text is not surrounded by
braces.

 global !p
 def ins1(t1, t2):
   return t2 if t1 else ''
 endglobal
 
 snippet def2 def
 def ${1:${VISUAL:foo}}
 {${2}} `!p snip.rv=ins1(t[3], '{')`$3`!p snip.rv=ins1(t[3], '}')` `!p 
 snip.rv=ins1(t[4], '{')`$4`!p snip.rv=ins1(t[4], '}')`
 $0
 endsnippet 

This one is not perfect, but it works.

 The second one just creates the parenthesis if you type something
 there. The disadvantage here is that you don't see the optional
 parenthesis until you type something there.

Exactly. Maybe someone with python experience knows how to to tweak
it to insert the braces and remove them if the field turns out to be
empty.

 Try the two approaches and see if which one of them (if any) is
 more convenient to you.

I went for the second option. Thanks a lot for your effort.


Marco


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


Re: Variable amount of snippet arguments in ultisnips plugin

2012-11-03 Thread skeept

 
  
 
  snippet def def
 
  def ${1:${VISUAL:foo}}
 
  {${2}} ${3:{${4}}} ${5:{${6}}}
 
  $0
 
  endsnippet 
 
 
 
 This does not work for me. The optional text is not surrounded by
 
 braces.


It should work (it works for me), but you have to hit c-j twice (the first 
one corresponds to $3 and the second one correspond to $4. If you hit backspace 
while on $3 then both $3 and $4 are deleted.

What I was saying about further nesting would be something like this

${3:{$4} ${5:{$6}}}
The idea here is exactly the same, except that now if you hit backspace while 
on $3 you will remove both optional braces, in the first one you only remove 
one at a time. 

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


Variable amount of snippet arguments in ultisnips plugin

2012-11-02 Thread Marco
Hi,

I discovered the plugin ultisnips and like it a lot. However, I have
problems setting up the snippets (BTW: I don't know python). I need
a snippet that has two mandatory arguments and several optional ones
(no more than four). Here an example:

  snippet def def
  def ${1:${VISUAL:foo}}
  {${2}} {${3}} {${4}}
  $0
  endsnippet

Typing def Tab foo C-JbarC-JC-JC-J yields

  def foo
  {bar} {} {}

I don't need the last two braces. How can I omit the empty braces in
this example without defining a snippet for each number of braces?


Marco


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