More flexible scope manipulation
Motivation: allow painless text manipulation by scopes
Working with scopes is a pain at the moment because we can't be specific about extracting text for a given scope selector. Instead we have to use extract_scope(point) with its 'intelligence' which varies by language. Or, we use find_by_selector(selector), then iterate through the list of regions to find the one that intersects the position we want. Or we move position by position back and forth and check we are in/out of scope. These workarounds are labour & CPU intensive for what should be a very simple thing. The solution:
The above proposed change will extract the region for the given selector if provided. Better still would be:
Where selectors is a space delimited string of selectors, the largest of which (except topmost source.*) is selected.
Finally we could have a greedy flag which allows the above API to choose the least or most specific selector:
extract_scope(point, selectors, greedy, single)
And the single flag will allow an individual scope to be extracted in the case where they are back to back (like
Rounding off, it would be useful to have more flexibility with find_by_selector(selector), so that we can restrict its operation to a given region or regions. Presently it returns all matching regions in the file, a performance overhead if one needs to iterate through it repeatedly.
find_by_selector(selector, Region or [Regions])