Sublime Forum

Looking for API calls for getting styling information

#1

I want to be able to know the syntax group for a certain word or for wherever the caret is in. By syntax group I mean if it’s a string/comment and so on. I’ve tried going the code in scope hunter and html exporter but still can’t find that one call that gives all these info.

RTFM answers are welcome. Can’t seem to find the right mix of words to bring up documentation on this

0 Likes

#2

View.scope_name(<point>)

If you want to match a scope selector against, e.g., comment or string, use View.score_selector(<point>, <selector>), which is actually undocumented but available through other, documented means.

2 Likes

#3

How big a slowdown would there be if I for example decided to iterate through all the characters querying their syntax groups using the two methods?

0 Likes

#4

Try it? It’s only a few lines of code.

@facelessuser might be able to give more info because of his ScopeHunter package.

0 Likes

#5

yeah, I’ll do that. Thanks, you’ve been very helpful

0 Likes

#6

I haven’t read over all the details in this thread yet, but hit me up with any specific questions you have.

0 Likes

#7

There is no need to query every single character. A view also has a extract_scope(point) method which will return the extent of the syntax name assigned to the character at the given point as a Region.

I believe this should be more efficient, if you get the syntax at a character, then get the extent of the scope, then get the syntax of the character after the end of that scope and so on.

0 Likes

#8

Unfortunately, that won’t work.
First, the method is inconsistent at times in that it does not work as expected.
Second, it does not consider scopes that get inserted on top of the current scope. Meaning: If you use this inside of a string, you will get the entire string including quotation marks and potential character escape sequences, even though the actuall characters have a different scope ontop of the string scope.

0 Likes

#9

Ah, I see - thanks for explaining - I should probably not use it in my own plugins then :wink:

0 Likes

#10

It all depends on what you’re going for. ScopeHunter gets the scope at the given point and then searches the view for that exact scope and filters it to just show the region under the cursor.

0 Likes

#11

And yet the question still remains… do you know what’s the meaning of “extent of the scope”… The only reference I’ve found on the whole internet to solve this question I’ve had for few days already is living in the abandoned limetext repo, ie:

ExtractScope which calls to ScopeExtent which calls to something living here https://github.com/limetext/text… maybe?

Dunno :sweat:, unfortunately… although I’m a go player I never coded in go so I couldn’t say hehe… Plus, even if I did, would that be the exact implementation used by SublimeText? Probably not…

0 Likes