Actually variables in PHP are white, because I explicitly did not declare a rule for generic variables in the color scheme, so they just use the basic text color (wich is white in the dark theme). This is also the reason why they were not highlighted in strings yet, because in that case all of the string text (including variables) uses the string color (orange). In contrast to that, there does exists a rule e.g. for keywords (blue) in the color scheme, and that will take precedence for SQL keywords, even if they are part of a string.
To clarify, let me explain the basics how syntax highlighting works in Sublime Text:
- Syntax definition files (.sublime-syntax) provide a set of rules (basically regular expressions) to assign scopes to a region/fraction of the source code. The syntax definitions of Sublime Text’s built-in languages are maintained at GitHub: https://github.com/sublimehq/Packages
- Color schemes declare a set of rules to assign colors and font styles to scopes. Common scope name conventions are used by different languages for comparable language constructs when appropriate, so that color schemes can target them and provide consistent syntax highlighting.
Sublime has a built-in show_scope_name
command (ctrl + alt + shift + p) that will show the scope(s) at the current cursor position. For example variables like $x in PHP have the scope variable.other.php
and JavaScript variables use variable.other.readwrite.js
. Unfortunately sometimes there are inconsistencies with the scope names in different languages, or e.g. in Java or C++ variables don’t get a specific scope at all. Hence it is not always easy to find common highlighting rules and some things could have unintended side effects to other languages.
With your suggestion about PHP variables in strings, I intend to add a rule for variable.other
(that could affect other languages too) or variable.other.php
into the color scheme to ensure that generic variable names always have the basic text color. I’m not sure if there a other languages that use variables in strings like PHP and want to check that first though. In some languages there are some kind of placeholders in strings like %s
that have the scope constant.other.placeholder
and I use italic font style to denote them.
I’ve checked the $x
in single quoted strings and it will still be orange because the syntax definition already handles that correctly. But thanks for the clarification.
For the SQL example, I don’t want to introduce bold style to the color scheme because in my opinion highlighting in Adobe Brackets looks so well just because it doesn’t use that many different highlighting colors and no distracting font style variations. The colors white and blue are certainly not only reserved for PHP variables and functions, blue is actually used for various things like generel keywords, types, language-specific variables like “this” and intrinsic or base framework functions. So my intention would be to create consistent highlighting and I don’t see a reason why highlighting of SQL in PHP should be different from .sql files. Names enclosed by grave accent would be orange because it is recognized as a string by the SQL syntax.
But if you want orange SQL strings with bold keywords/functions, you can easily customize the color scheme. For that just create a file “Brackets Dark.sublime-color-scheme” and/or “Brackets Light.sublime-color-scheme” in your user package (Preferences > Browse Packages… and open the folder “User”), and
insert the following text:
{
"rules": [
{
"scope": "string source.sql",
"foreground": "var(orange)"
},
{
"scope": "string source.sql & (keyword.other | support.function | entity.name | storage.type)",
"foreground": "var(orange)",
"font_style": "bold"
}
]
}
This should produce orange SQL strings with bold keywords (and white variables as soon as I update the package).