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

Reply via email to