In a .sublime-syntax file, how can I write it so that when context foo is popped, context bar if it is in the stack is also popped?
[sublime-syntax] How to automatically end a scope when another scope ends
If you know that bar is the next context in the stack and you use ST built 4050 or newer, then you can use pop: 2.
Alternatively you can add a “immediately-pop” rule to the bar context with
- match: ''
pop: true
This is usually used for contexts supposed to provide a “meta”-scope over a larger region and which are pushed together with other context(s) onto the stack.
Hm, but I don’t unfortunately. Actually I think I did not explain it correctly. What I want is that when bar is in scope inside some context(s) foo1 or … or fooN, the rules that terminate foo1, … fooN also terminate bar. E.g. if we have
bar
foo1
regexes that would terminate foo1 here also terminate bar with it, leaving the context stack in the same state as if we had just foo1.
Probably there’s no better way to do this other than repeating all regexes that terminate foo1, …, fooN in bar with pop: 2 instead? The thing is we can have
bar
foo1
foo2
but then it would work out fine as long as we use look-ahead regexes which do not consume the input, so that matching that end in bar pops 2 and matching in foo2 pops the remaining context.
Sorry if this is basic or confusing, I’m still getting to grips with this stuff.
PS: I’m trying to fix some annoying bugs with the OCaml syntax highlight file that ships with sublime.