Conditional Parts in snippets

Yannick Gingras ygingras at
Tue Dec 8 13:00:59 GMT 2020

I am trying to write snippets for Python that would have conditional
sections.  For example:

class ${Name}($parent="object"):
    """ ${doc} """

In the above, if parent is not edited, we don't event need the
parentheses, and we can write "class Name:", which is less explicit,
but perfectly in line with the most popular coding style.  Similarly,
if the documentation string is unedited or left empty, it would be
better to remove the enclosing quotes.

I was hoping to use view.cursorPosition to detect when a place holder
has been dealt with then delete the offending characters/line if the
values is empty or unchanged.  Unfortunately, cursorPosition is not set
when expanding a snippet.

Is there another way to know which placeholders have been covered?  Is
there a better way implement conditional sections in snippets? 

By the way, I'm not subscribed to the mailing list so please CC me in


Yannick Gingras

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the KWrite-Devel mailing list