[quote=âfacelessuserâ]Something like this? API calls in green.
[attachment=0]Screen Shot 2012-03-10 at 4.16.05 PM.png[/attachment][/quote]
So how did you achieve this - just for the API calls??
[quote=âfacelessuserâ]Something like this? API calls in green.
[attachment=0]Screen Shot 2012-03-10 at 4.16.05 PM.png[/attachment][/quote]
So how did you achieve this - just for the API calls??
[quote=âagibsonswâ]
[quote=âfacelessuserâ]Something like this? API calls in green.
[attachment=0]Screen Shot 2012-03-10 at 4.16.05 PM.png[/attachment][/quote]
So how did you achieve this - just for the API calls??[/quote]
I will update with the info later when I get some time. Hang tight. Gotta spend time with the kids .
@facelessuser. Okay. Go play with the kids and their âgamestationsâ
When you get back⌠Iâm sooo⌠close to what I want with this expression:
<string>(?:\.)?(size|substr|begin_edit|end_edit|insert|erase|replace|sel|line|full_line|lines|split_by_newlines|word|find|find_all|
rowcol|text_point)\s*(?=\()</string>
It works if I follow the dot with a space â. begin_edit()â but not (currently) without the space?!
No worries. I needed a more complex expression - following your lead⌠That is, I looked through some of your additional regex in .tmLanguage.
<string>(?:[a-zA-Z_][a-zA-Z0-9_]*\.)?(size|substr|begin_edit|end_edit|insert|erase|replace|sel|line|full_line|lines|split_by_newlines|
word|find|find_all|rowcol|text_point)\s*(?=\()</string>
This is in place of the keyword âglobalâ which is very near the top of the tmLanguage file. I should then be able to modify the theme colour (that refers to the scope for âglobalâ), and if I want to format the word âglobalâ I can* bung it in* with something appropriate.
I might go for something yellow-ish or orange
Using the my Python modifications that I pointed you to earlier (it needs the other changes I made in the github version to work), I inserted a ST2 API check before checking for normal functions.
And I defined the API section by copying the function section and placing it under the Repository part in the XML with the same name you see above. Donât replace the original function section, but make sure to add it before. You still want to make sure non API calls get scoped as functions.
<key>st2_api</key>
<dict>
<key>begin</key>
<string>(?:\.)?(size|substr|begin_edit|end_edit|insert|erase|replace|sel|line|full_line|lines|split_by_newlines|word|find|find_all|rowcol|text_point)\s*(?=\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>meta.function-call.st2-api.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>name</key>
<string>meta.function-call.python</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?=[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*\s*\()</string>
<key>end</key>
<string>(?=\s*\()</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#dotted_name</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.arguments.begin.python</string>
</dict>
</dict>
<key>contentName</key>
<string>meta.function-call.arguments.python</string>
<key>end</key>
<string>(?=\))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#keyword_arguments</string>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</array>
</dict>
I attached the modified python language. Diff it against the version I pointed to on github if you need to.
Python.tmLanguage.zip (6.07 KB)
@facelessuser. Thank you, I shall study at length
Iâm guessing that your (?:.)? worked because it was registered within a beginCapture.
I thought my task was complete, but not of the theme files contain âstorage.modifier.global.pythonâ, or even the word âglobalâ at all. Am I able to just create a new dict entry, following an existing structure:
<dict>
<key>name</key>
<string>Keyword</string>
<key>scope</key>
<string>keyword</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#FF3854</string>
</dict>
</dict>
and making up a name (Global?)? Iâm optimistic that I can.
Iâm not so concerned about other function calls at the moment - at least everything will not be the same colour
There are a couple of advantages to what my version does over yours. There were a number of changes to make sure self and cls still get scoped proper in lines like this:
self.object.api_call()
self and cls donât get colored in the theme, but they are getting scoped, and my requirement was not to break any other scoping. The one thing I did change was that if you had this:
self.object.another_object.function()
object.another_object.function() would all get scoped as meta.function-call. I found this to be overzealous, so I reduced it to only scope function() as meta.function-call. After that, all I did was add generic to the function call so that all was pretty much the same meta.function-call.generic, but you add an extra specifier you could target it in your theme, but you donât have to and it would then be unhighlighted and benign.
By inserting the api check right before the normal function check, you get two kinds of function calls to target (keep in mind, built in functions are not touched by these, so they still get scoped like normal; I think I might have made some adjustments to ensure this).
meta.function-call.generic.python and meta.function-call.st2-api.python
I highlight like this if all I want to highlight is the api:
<dict>
<key>name</key>
<string>Function Call</string>
<key>scope</key>
<string>meta.function-call.st2-api</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#A6E22E</string>
</dict>
</dict>
Cool, so I can copy a dictionary entry, use my scope and make up a name - and colour.
Iâm not concerned about any other functions, variables, etc., at the moment - I just want(ed) the code a little less monochrome. Iâm still learning the API at the moment, so I was particularly interested in these methods.
The ST API documentation is quite limited, and Iâm sure itâs only mentioning a fraction of whatâs available. It doesnât mention on_query_completions, extract_completions, match_selector, or describe arguments in enough detail. So itâs been mainly a question of trawling through, and deciphering, any code samples I can find.
Iâm quite keen to pursue âon_query_completionsâ and might build on this, together with a completions (or other source) file. Python and/or, more specifically, the API would be a sensible choice for this (as I can learn the language at the same time ). Besides, CodeIntel seems to have fallen by the wayside. *
Iâll modify the theme file tomorrow⌠and possibly come back if I canât get a nice orange effect . Andy.
Off-topic: Whatâs a straight-forward way (with the API) to position the cursor? I know I could use run_command, butâŚ*
Glad I could help. I just happened to have done this stuff about a week or two ago. Had I not, I would have been pretty clueless.
What do you mean position the cursorâŚmove the cursor to postion x on line y?
This is assuming you know how to calculate your new position and create a region.
You usually need to account for multiselect so you would clear the current selections and then add each new selection region:
view.sel().clear()
map(lambda x: view.sel().add(x), new_sel_array)
or for one:
view.sel().clear()
view.sel().add(new_sel)
Basically you can parse the view.sel keeping the regions you want or just delete them all without checking and add the new one/or ones you want.
Thank you @facelessuser
So something like:
sel = view.sel()[0]
view.sel().clear()
view.sel().add(sel)
would clear all selections and re-instate the cursor to the latest position
Well this works, thank you @facelessuser. Although Iâm not entirely happy with my choice of colour (a sort of lilacâŚ) but at list I achieved my aim
Iâm not sure I want to pursue this any further just at the moment. I can imagine spending hours (daysâŚ) on this . I would learn a little more about regex, ST themes, and have control over colours I suppose.
Regards, Andy.
Edited: I also modified the scope from ââŚglobal.pythonâ to âstorage.type.function.api.pythonâ so that it should behave better, and chucked the word âglobalâ in with def|lambda.
@facelessuser. Sorry to bore but Iâve got *control *now without too much effort, wheâhay! I copied my new category/dictionary entry âstorage.type.function.api.pythonâ to create âstorage.type.function.general.pythonâ, and added a few standard, and commonly used library, functions to it - see the yellow text in the screenshot. These two categories are near the front of the tmLanguage file, so conflict seems unlikely.
I was under the impression that I would need to study the whole language file to be able to slip these in . So now I can add functions as I go along, and create more categories if I so chose, wheâhay! Job done.
I might try and tackle objects like window, view⌠This might prove a little trickier though, as I havenât got an opening brace â(â to latch on to
Regards, Andy.
Window and view should be targetable. In the method I am using, I catch all of the object members (even the ones without (); I just donât scope them with anything; like I said I changed it a lot of things to help me out in the future).
But yeah, there are always more ways than one to do things.
I see now what you were indicating with self, cls . In a line such as
self.window.focus_view(OrderedFilesCommand.file_views[index][1])
focus_view is my chosen colour, but self and index are no longer the colour they should be. My expression
<string>(?:[a-zA-Z_][a-zA-Z0-9_]*\.)*(append|lower|sort|split|itemgetter)\s*(?=\()</string>
is not sufficient to discount everything else on the line.
Can you elaborate on âI just donât scope them with anythingâ please? This should help meâŚ
**
[quote=âagibsonswâ]I see now what you were indicating with self, cls . In a line such as
self.window.focus_view(OrderedFilesCommand.file_views[index][1])
focus_view is my chosen colour, but self and index are no longer the colour they should be. My expression
<string>(?:[a-zA-Z_][a-zA-Z0-9_]*\.)*(append|lower|sort|split|itemgetter)\s*(?=\()</string>
is not sufficient to discount everything else on the line.
Can you elaborate on âI just donât scope them with anythingâ please? This should help meâŚ
[/quote]
This is what I was trying to say earlier. I already accounted for all of the stuff, so I was suggesting that you leverage the work I already did.
Basically in my version I donât do this (?:[a-zA-Z_][a-zA-Z0-9_].). This will greedily include any parent object that happens to come before your target. That is the way it was doing things before I touched it. If an object had a function in it, all preceding object members got pulled into the scope which I though overzealous. So what I did is change the default function check to not greedily include those members, and then I catch them with this and give them no additional scope (I should probably check for lists here as well):
<key>generic_object_names</key>
<dict>
<key>match</key>
<string>(\.\b([A-Za-z_][A-Za-z0-9_]*)\b(?!\()|\b([A-Za-z_][A-Za-z0-9_]*)\b\.)</string>
</dict>
So you can see here I look for built in things first, and if I donât find those, I throw out all the dot members that arenât function calls etc, then I check for API and then functions, and then lists etc.:
<dict>
<key>include</key>
<string>#builtin_functions</string>
</dict>
<dict>
<key>include</key>
<string>#builtin_types</string>
</dict>
<dict>
<key>include</key>
<string>#magic_function_names</string>
</dict>
<dict>
<key>include</key>
<string>#language_variables</string>
</dict>
<dict>
<key>include</key>
<string>#generic_object_names</string>
</dict>
<dict>
<key>include</key>
<string>#st2_api</string>
</dict>
<dict>
<key>begin</key>
<string>(?:\.)?([a-zA-Z_][a-zA-Z_0-9]*)\s*(?=\()</string>
<key>beginCaptures</key>
I think I also made some minor adjustments to ensure that scope and built in globals get highlighted correctly too, but I would have to diff my changes to remember what I did.
[quote=âagibsonswâ]**
Not so silly now eh? [/quote]
@facelessuser. What seems to be relatively straight-forward is getting complicated . Part of my confusion was/is that even though I use a non-capturing group (?: ), it seems that the more general term âfunctionâ later on collects this text.
It also seems odd that only the word âselfâ gets caught out, although I think âkeyâ has also lost its colour, and (possibly) index.
So changing the key âcapturesâ to âmatchâ is not likely to help me? And you wouldnât recommend that I ditch the name-part âfunctionâ all-together? Edited: Ignore this remark about âfunctionâ - I realise this wouldnât help (it IS a function, regardless).
I apologise . I should be studying all the content you have supplied me with in great depth, but Iâm still taking pigeon steps at the mo. I could just âborrowâ your language file, but Iâm a bit obstinate
It is what makes us programmers. Early on with javascript, I wrote my own simple framework (not because I thought I could do better than Jquery; I think Jquery is great and way better) but I just wanted to learn as much as I could about javascriptâŚit was both fun and painful, but I ended up with a pretty usable framework. In the end, I think I learned more about web browsers and javascript than I ever cared to learn.
@facelessuser. Ditto. I wrote my own JavaScript library . Admittedly, some methods such as $() and getElementsByClassName() I pretty much copied letter for letter, but most methods I adapted (improved uponâŚ), including creating my own sort procedure and date parser. I wanted to look at jQuery, but I didnât fancy reading another book. So I went on to the jQuery forum and answered tons of questions (before Iâd even typed a line of jQuery code ).
Anyway, I think Iâve short-circuited my labours. I realised that the function greediness is how the language file behaves. I wasnât looking to correct this behaviour, merely to add a number of specific methods/terms to the language. And itâs mainly the term âselfâ that was an issue (the word âkeyâ isnât even in the file!).
For the moment Iâve added the terms self and cls in with global, very near the top of the file. The screenshot shows that self, and my api calls, are colour-coded . If the function scope gobbles up other terms then thatâs SEP! [Actually, placing âselfâ near the top of the file may prevent âfunctionâ from gobbling up text anywayâŚ]
All I need to do now (hopefully) is decide what words/methods/additional categories I want and flatten out the colours a bit.
Regards, and thanks again, Andy.
⌠in fact, I might just make *everything * orange and be done with it - it will remind me of a simpler time. Andy.
I have to admit, I understand what you mean. Digging around in these tmLanguage files isnât that funâŚwith all of the regex, and ensuring the proper order of definitions, and the recursionâŚ