Conditional Parts in snippets

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


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

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

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

Thanks!


-- 
Yannick Gingras
http://ygingras.net

-------------- 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: <http://mail.kde.org/pipermail/kwrite-devel/attachments/20201208/882acfab/attachment.sig>


More information about the KWrite-Devel mailing list