Conditional Parts in snippets
Yannick Gingras <[email protected]>
| Newsgroups | gmane.comp.kde.devel.kwrite |
|---|---|
| Message-ID | <[email protected]> |
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
signature.asc
(application/pgp-signature, 659 B)
-----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEQBAbmQFumbsYmkRfiKQ8CLil3UMFAl/PeQsACgkQiKQ8CLil 3UMndAv/dypujjJkB5ZfNDj6NNEztpATeq9ENHdEPtgokRJmkbCYVja0NmSisvt6 7qM6UB0XHieIbOZ6mocXk6pXqf5/u++Uv/b0KG8IB2YloIgKoPBhJIznNtsxNGVx HTSIuoYFxR4ykyqOmqc+MVfnvEGCe7REbEQDvUrd8TtRWxlPtPDvPbqceUvJOzQk p/J+LzT6WF+/F2SNVlkRtcxfQzqe5a70TBaxeSmAllfPVWhdmepOPRFeuQFbkm2K 8Itq6PT8K91IhxsFetSGvrtA4TuT0iq+KNT7Jpg/KCd+iOHChmUniqsw9AEr+PUa MQVCIcfdUuj1an5G6Fl2kyhv43tjcjhReTFSnuu7x1aNiwSDILWfAUC5c02v36jl X10W5MD2VYlEF2uoqIMEKiP+3/4lbj7C76ZQbZS7ABArehvukXQ67K0fxOAhysVr xXNOHQFgvkojVwv7FUL+2AUkGAftJd/P979O3osdsY+2Q1lykNDx7jAo08wci74Z CPN05Ze1 =cL8o -----END PGP SIGNATURE-----