Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Important Addendum Prefixed To The Answer</strong></p> <p>The following explanation assumes that one is writing the syntax definition in JSON and then building the Plist xml file with the PackageDev plugin (as described in the unofficial sublime docs linked below). It is from the latter files that ST2 reads syntax parsing instructions.</p> <p>= = = = </p> <p>I'm reporting to you from my own first foray into this territory, so I may be mistaken on a point or two in what follows.</p> <p>Unless your syntax parser defines <code>$</code> as having its own scope selector, you won't be able to set the color for that lone sign through the color scheme files. As you may already know, you can check the scope selector of an element by selecting it and pressing option+command+p (alt+super+p on not-macs): it reports the information in the status bar.</p> <p>I just checked the php syntax parser on my own software, and there's no differentiation between the scope of the <code>$</code> and the string to which it is prefixed. Thus, assuming your setup is like my own, you'll need to write your own syntax definition. This can be done either in the existing php syntax file, or (surely a safer option) in a new definition document which you'll use as your primary one for editing.</p> <p>You can find a tutorial covering the basic steps of writing your own syntax definitions in the unofficial sublime text docs. In fact, a section therein, entitled "<a href="http://sublimetext.info/docs/en/extensibility/syntaxdefs.html#fine-tuning-matches" rel="nofollow">Fine Tuning Matches</a>", explains how to define a scope selector especially for prefixed dolla' signs by using "captures". You can refer to the documentation for the specifics on creating syntax definition files and all that, but, for the sake of solidifying my own understanding of the process and to make the answer readily available here, I'll do my best to explain the JSON determination of the selector.</p> <p>This is the regex pattern you'll need to use:</p> <pre><code>{ "match": "\\$([A-Za-z][A-Za-z0-9_]+)", "name": "keyword.syntaxTypeAbbreviation", "captures": { "1": { "name": "moreSpecific.selectorName.syntaxTypeAbbreviation " } }, "comment": "Variables like $PARAM1, $TM_SELECTION..." } </code></pre> <p>Analysis of the meaning of the above:</p> <p><code>"match"</code> gives the regex which identifies the string pattern to be selected. Unless I'm mistaken, it reads, "any string beginning with '$' ([followed by one uppercase or lowercase letter] and [at least one additional letter or numeral] plus any additional characters)". (Sublime Text uses the <a href="http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt" rel="nofollow">oniguruma regex specifications</a>.)</p> <p><code>"name"</code> provides the string by which the the scope is to be selected in the color scheme document. In the scheme xml, this corresponds to the <code>&lt;key&gt;name&lt;/key&gt; &lt;string&gt;specific.selector.syntaxTypeAbbreviation&lt;/string&gt;</code>.</p> <p><code>"captures"</code> (and this is the critical element for your aim) specifies the subset of the pattern which is to be given its own, more specific, scope selector. Each set of regex terms enclosed within parenthesis occupies one place, and the integer (<code>"1"</code>, here) specifies which of the places is to be "captured". In our case, of course, there is only the one capturable group.</p> <p><code>"name"</code> does the same as before, but as a subspecies of the previous designation and, <code>"comment"</code> offers the option for you to comment on the significance of the definition.</p> <p>Finally, it is important to note that the <em>first</em> scope selector will set the color of the whole string and the <em>second</em> overrides its predecessor to give a different color <em>to the following letters and numbers</em>. That is to say, the first selector will let you color the <code>$</code> and the second will be the color of the appended string.</p> <p>We can therefore translate the pattern thus:</p> <blockquote> <p>"Any string beginning with '$' ([followed by one uppercase or lowercase letter] and [at least one additional letter or numeral] plus any additional characters) is to be named <em>NAME</em>, except for the part which is enclosed in the first set of parenthesis, which is to be named <em>OTHERNAME</em> instead.</p> </blockquote> <p>I hope that this explanation will be at lest half as useful for you to read as it has been for me to write. Also, I'd appreciate folks correcting whatever mistakes I surely did make.</p> <p>Regards,</p> <p>aBath</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload