@facelessuser Ta. Iâll have a look.
Does ST have a Diff feature? Although, I have WinMerge which is a nice app
@facelessuser Ta. Iâll have a look.
Does ST have a Diff feature? Although, I have WinMerge which is a nice app
[quote=âagibsonswâ]@facelessuser Ta. Iâll have a look.
Does ST have a Diff feature? Although, I have WinMerge which is a nice app [/quote]
Not really. There are some diff plugins, but they donât really let you copy things from one to another. More of a simple diff view.
When I am on Windows, I usually use WinMerge as well. I use this other free diff thing when I am on Mac, but I am not very happy with it; I need to find a better one.
Oh keep in mind, my changes to highlight function calls was adding a new scope, but you could use an existing one and then you would not need a color theme change.
[quote=âagibsonswâ]Iâm making some sort of progress with the following code. It manages to find the words and change their formatting, but with a weird background?! I tried a scope of âcommentâ but a similar effect occurs(?).
[/quote]
A plugin to highlight the API stuff isnât going to be nearly as nice as it is being built into the tmLanguage file. Highlighted regions are not quite like scoping with a tmLanguage, they are literally a colored region; you canât change the text color, font-style, or anything else. All you can do is create colored blocks, colored outlines, and colored underlines.
Ahh, thatâs a shame, thought I was almost there! But an interesting exercise non-the less.
Testing your regex skills, how can I make this:
api_regions = view.find_all(âview|sel|beginâ)
only capture if preceded by a dot or other (non-word) character and followed by another non-word character, but NOT capture these additional bits?
Sublime has âShow Unsaved ChangesâŚâ option in the context menu which can be used for âdiffingâ. Open original file, paste changed file and use this option (without saving file).
[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.