Sublime Forum

Syntax definition included in any file type

#1

Hi there,

I’ve been stuck for the last 2 days trying to figure out this fairly simple problem and it’s driving me mad.

What I want:

  • Enter certain tags < x y z> < /xyz > in any filetype.

  • This should apply an “xyz” scope to the text.

  • My eventlistener which performs a certain autocomplete will activate if the selector matches this scope.

  • I also have other keybinding that trigger textcommands based on the selector matching that scope. I also have a command that needs to grab all regions with that scope.

I realise this can likely be done with basic regex matching in the keybinding’s context and a global flag to activate the eventlistener but I just felt it should somehow work using scopes and syntax definitions.

But the only way I can think of so far is to create an xyz syntax definition and then include it in a begin-end block in every other syntax definition file like this but that doesn’t seem right.

Any help would be much appreciated.

0 Likes

#2

No, trying to use syntax definitions to do something globally (i.e. that applies to all syntaxes) definitely doesn’t sound right.

You can implement custom context provides by implementing a on_query_context hook (should be in the API docs), if you can’t manage to make it work with the existing context keys.

1 Like

#3

Perfect! Thanks for taking the time to reply.

One issue though, is that if I don’t define a scope for these regions, there’s no way for me to change their colour. From looking around, I can’t see a workaround for this…

0 Likes

#4

View.add_regions is able to add background, outline or underline color to arbitrary regions. Linter plugins use this a lot. You just can’t freely define the color and have to rely on a scope name like keyword instead.

0 Likes