Should overwrite apply to regex triggers?

Asked by Brian Gates

A short (contrived) example:

snippet /x..*/ "low priority" r
this has an x
endsnippet

snippet /xy.*/ "high priority" !r
this has x and y
endsnippet

xyz [expand]
1: (x..*) "low priority"
2: (xy.*) "high priority"
Type number

Could the ! flag be made to work in this situation, so
xyz[expand] => this has x and y?

Question information

Language:
English Edit question
Status:
Answered
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

No, this does not work - I am not sure if it should. for example would you want r"." do overwrite all other regexp snippets? I mean you might want to do that, but it might also surprise others. Otoh, when you define such a short regexp snippet, you will have a good reason. So I am pro this feature.

A patch to add this behavior should be possible, but it might not be completely trivial. Wanna give it a try?

Revision history for this message
Brian Gates (bmathg) said :
#2

I wouldn't expect ri, rw, rt (which I'm guessing is roughly what you mean by r".") to overwrite other regexp snippets, since the only overwrite flag is "!".
The way you define !, referring to identical triggers, there's a not an expectation that it will work with regexp like I am describing, but I think it's a natural extension.
Knowing nothing about Python, I had imagined the current implementation might be something like
1) iterate through every snippet looking for matches, accumulating matching snippets into an array
2) if there is only one match, 'fire' the snippet
3) if there are more than one, list them

and in that scenario a step 1.5) "if the matching snippet array has one or more members with the ! flag, reduce the array to just those" would do what I want.

Unfortunately, literally everything I know about Python came from building snippets - my current skill level may not rise to the level of "completely trivial". As I get more comfortable with the language, I might return to this, but if you are moved to patch it first don't wait for me. :)

Revision history for this message
SirVer (sirver) said :
#3

That's kinda the way it is actually implemented. Feel free to open a bug for this feature if you feel strongly about it.

Can you help with this problem?

Provide an answer of your own, or ask Brian Gates for more information if necessary.

To post a message you must log in.