feat: implement wordTrig
behavior as a condition
#1288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
Maybe this pr should just be a code example in documentation or
even a post on a luansip community forum. I apologize if so. I do not mean to spam.
Upshot
I think the repo should guide users how to custom the characters used in
wordTrig=true
(from the default of[%w_]
) . A condition function seems like the best way to do it. This PR attempts to show one such way.The wordTrig flag will only expand the snippet if
the proceeding character is NOT %w or
_
.This is quite useful. The only issue is that the characters on which we negate on hard coded. See here for the actual implementation snippet.lua#L827
As a result, authors will turn their plain triggers into
regexTrig=true
triggers and precede their regex with a negated capture group. The capture group on which the pattern is matched, although negated, still expands with the rest of the trigger. So people have worked around that by inserting the capture group back into the snippet via function node.Why the workaround is an issue
This is an issue because it can break LuaSnip's understanding of parent and child snippets, resulting in broken jump_next() etc. For instance, consider
Some latex snippet authors will have their snippet definition for mbb look like s(trig="([^%w])mbb", t("\mathbb{}") The problem is that this consume the leading
$
character, and even if the snippet re-inserts the$
back, the parent snippet$$
will be broken.