Sublime Forum

Disambiguate v1 from v2 syntax definitions when extension is the same

#1

I have two syntax versions: v1 and v2. Each is in its own .sublime-syntax file for ease of editing/comparison etc.

They are differentiated by an optional “shebang”/first line indicator, but since they use the same file extension, and file extensions have a higher priority vs. first_line_match ST header, I can’t directly use this header property to differentiate them.

Now, I’ve found an alternative: using a third “loader” syntax definition (let’s call it v1or2) that will have its main rules matching shebang and setting whatever version matches, and if nothing matches, sets the newer v2.

But there are a few issues:

  1. how to prioritize a given file to make it parse the same extension first? So far it seems that whichever is named alphabetically last wins. Is there an explicit way?

  2. How to replace the bottom-right indicator with whatever the new v1 or v2 is set? I’ve made the v1or2 syntax hidden: true, so it disappears from the command palette or the bottom-right menu, but it’s still shown as the name of the active syntax

  3. Since each syntax definition has a default scope, I now always have dupe scope: from v1or2 and from v1 or v2. Is there a way, when setting the scope, replace the original main?

Basically, I’m looking for a way to completely eliminate this loader syntax or have an alternative way for the original v1 or v2 files to be selected within the same extension based on the first line

Or is this only possible via a plugin?

0 Likes

#2

Some prior related discussions at

1 Like