Colors come from the color scheme, not from the syntax definition. Or more specifically, the syntax definition says what a thing is, and the color scheme specifies how the thing looks.
So in that regard the syntax needs to be able to detect the thing you want and apply a scope
to it. The Python syntax already has the ability to do that, so all you need is a color scheme rule to color it somehow. All else being equal when it comes to augmenting a syntax (when it’s needed) it’s better to make an override
on the original one and add things; if you make your own you need to apply rules for everything.
The color scheme rule you want needs to apply a background color to source.python meta.function
, which is the scope applied to the line that defines a function (this assumes you’re using a recent build of Sublime though; if it doesn’t seem to work you might need to update).
For example, assuming that you were using the Monokai
color scheme, then the following content in a Monokai.sublime-color-scheme
file in your User
package would highlight Python function definitions red:
{
"rules":
[
{
"scope": "source.python meta.function",
"background": "color(var(red) alpha(0.67))",
},
]
}
You would change the name of the file depending on your color scheme (keep the extension though, even if you’re using a tmTheme
color scheme) and you would have to adjust the color
line as well.
For me the result looks something like: