Editing color scheme for php in Sublime Text 2

I would like to have a $ (dollar) sign that indicates that the php variable will display as native color (# ff0000) in ST2. I've edited my own color scheme file, but I can't get a specific color for just this symbol.

+3


source to share


2 answers


An important addition to the prefix

The following explanation assumes that you are writing the syntax definition in JSON and then creating an XML Plist file using the PackageDev plugin (as described in the unofficial sublime docs below). It is from the latest files that ST2 reads the parsing instructions.

= = = =

I am informing you of my first foray into this territory, so I may be wrong at some point.

If your parser does not identify $

as having its own visibility selector, you cannot set the color of that single character via color scheme files. As you already know, you can test the element's scope selector by selecting it and pressing option + command + p (alt + super + p on not-macs): it reports information in the status bar.

I just tested the php parser on my own software and there is no difference between the scope $

and the string it is prefixed to. Thus, if your setup is similar to mine, you need to write your own syntax definition. This can be done either in an existing php syntax file, or (certainly more secure) in a new definition document that you will use as the main one for editing.

You can find a tutorial describing the basic steps of writing your own syntax definitions in high text informal docs. In fact, the section in it, entitled " Fine Tuning Matches" , explains how to define an area selector, especially for the "Dolla" prefix characters, using "grips." You can refer to the documentation for specifics about creating syntax definition files and all, but in order to solidify my own understanding of the process and make the answer readily available here, I'll do my best to explain the JSON definition of a selector.

This is the regex pattern you need to use:

{ "match": "\\$([A-Za-z][A-Za-z0-9_]+)",
  "name": "keyword.syntaxTypeAbbreviation",
  "captures": {
    "1": { "name": "moreSpecific.selectorName.syntaxTypeAbbreviation " }
  },
  "comment": "Variables like $PARAM1, $TM_SELECTION..."
}

      

Analysis of the meaning of the above:



"match"

gives a regular expression that identifies the string pattern to be selected. If I'm not mistaken, it reads "any line starting with" $ "([followed by one uppercase or lowercase letter] and [at least one additional letter or number] plus any additional characters)." (Sublime Text uses oniguruma regex specs .)

"name"

contains the string with which the region should be selected in the color scheme document. In the xml schema, this matches <key>name</key> <string>specific.selector.syntaxTypeAbbreviation</string>

.

"captures"

(and this is a critical element for your purpose) specifies a subset of the template that should be given its own, more specific scope selector. Each set of regular expressions enclosed in parentheses takes up one space, and an integer ( "1"

here) indicates which location should be "captured". In our case, of course, there is only one group captured.

"name"

does the same as before, but as a subspecies of the previous notation and "comment"

offers you the opportunity to comment on the significance of the definition.

Finally, it is important to note that the first object selector will set the color of the entire line, while the second will override its predecessor to give a different color to the following letters and numbers. That is, the first selector will allow you the color $

, and the second will be the color of the added row.

So we can translate the template like this:

"Any line starting with '$' ((followed by one uppercase or lowercase letter] and [at least one additional letter or number] plus any additional characters) should be named NAME, except for the portion enclosed in the first set of parentheses which should be named OTHERNAME instead.

Hope this explanation is half as helpful to you as it was for me to write. Also, I would appreciate it if people would correct all the mistakes that I definitely made.

Hello,

aBath

+5


source


In your color scheme file:

<dict>
    <key>name</key>
    <string>Variable start</string>
    <key>scope</key>
    <string>punctuation.definition.variable</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#ff0000</string>
    </dict>
</dict>

      



Note: fontstyle = bold is also an option

+5


source







All Articles