AAAPackageDev required a fix to correctly highlight your syntax definition converted to YAML. (https://github.com/FichteFoll/AAAPackag ... 04fcf3ae1c
+ a few other enhancements that came to my mind)
But back on the topic -- here is a list of what I consider to be useful in the aspect of injecting into syntax definitions:
- Injecting afterwards: Add a new pattern onto an already highlighted file. This will use a scope name selector and apply the pattern to every Region specified by the scope. Problems: You are limited to the already matched scope and this is not as flexible as actually nested patterns which can extend the matched region if they themselves match beyond it.
- Injecting before: Injecting a new pattern into an existing syntax file. This would need something to determine its target location such as a scope name which is used in the existing syntax. Then the pattern will either be added at the beginning of the location's child patterns or at the end (beginning would be required in order to override existing sub-patterns which would interfere with the added pattern). Problem: Only using the target pattern's scope to determine the target location might be too vague as there might be two or more patterns with the same scope name. Furthermore, it is not necessary to define a "name" key in a pattern since you may as well just use matches or sub-patterns to define scopes.
- Replacing/Deleting a pattern: Simply replacing an existing pattern with your own definition; similar to "Injecting before". Replacing should usually be doable with the "Injecting before" procedure as you can create a match which would make the targetted pattern unable to match anymore. However, it "feels" dirty and matching stuff with no scope just to make the following pattern not match ... well, you get what I mean. Encounters the same problems as "Injecting before".
The latter two can be implemented using a plugin when modifying the existing syntax definition "on the fly" and overriding the default one. The former one can practically be implemented with `add_regions()` except that it will only color the background.
So, it's not impossible but it is probably hard to fix the problems and work out some logic for multiple injections.
When there is a dependency management system for Package Control I can imagine this being more useful because the syntax injection plugin can then be required by languages/packages which require these injections.
(Btw, I wrote this post over quite some time because I had many things in mind, sorry if it's too clustered.)