Home Download Buy Blog Forum Support

Syntax colour for ST API

Re: Syntax colour for ST API

Postby agibsonsw on Sun Apr 01, 2012 1:36 pm

quodlibet wrote:
agibsonsw wrote:Am I mistaken, or does ST not recognise regex-lookbehinds? I tried and it seemed to fail.


If you still haven't worked this out, you need to escape the "less than" sign. E.g., (?<=\W) should read (?&lt;=\W)

Alex


Thanks Alex. I caught that ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Syntax colour for ST API

Postby agibsonsw on Sun Apr 01, 2012 9:10 pm

(Just an update). I believe I've finally got this sussed with the code below, placed before 'meta.function-call.python' :D

What I wanted to do was scope specific method-names, but only if they are preceded by a dot. 'meta.function-call' kept interfering, grabbing any remaining text on the line and, therefore, applying one colour. My previous attempt was working, but the brackets and arguments (following my named-methods) remained as 'source.python'.

My code captures general methods, but only if preceded by a dot. It colours the method-name, ignoring any preceding text. It also works with nested function/method calls. [Part of the solution is to name the method's arguments 'meta.method.call.arguments.python', but do nothing with them - but perhaps I can colour these as well.]

I copied this code and substituted all the ST-API method calls, and also gave a different name to the brackets ( ) - so now I can colour-code all bracket pairs, whe'hay :D

I believe I should be able to modify 'meta.function-call' with code similar to this, so that it won't misbehave at all.

Code: Select all
      <dict>
         <key>begin</key>
         <string>(?:[a-zA-Z_][a-zA-Z0-9_]*\.)*(?&lt;=\.)([a-zA-z_][a-zA-Z0-9_]*)\s*(\()</string>
         <key>beginCaptures</key>
         <dict>
            <key>1</key>
            <dict>
               <key>name</key>
               <string>meta.method.call.python</string>
            </dict>
            <key>2</key>
            <dict>
               <key>name</key>
               <string>punctuation.definition.arguments.begin.python</string>
            </dict>
         </dict>
         <key>end</key>
         <string>(\))</string>
         <key>endCaptures</key>
         <dict>
            <key>1</key>
            <dict>
               <key>name</key>
               <string>punctuation.definition.arguments.end.python</string>
            </dict>
         </dict>
         <key>contentName</key>
         <string>meta.method.call.arguments.python</string>
         <key>patterns</key>
         <array>
            <dict>
               <key>include</key>
               <string>#keyword_arguments</string>
            </dict>
            <dict>
               <key>include</key>
               <string>$self</string>
            </dict>
         </array>
      </dict>
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Previous

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 29 guests