[Geany-Users] Highlighting the lexical scope relative to the cursor position

Matthew Brush mbrush at xxxxx
Mon Dec 23 08:40:07 UTC 2013


On 13-12-21 11:30 AM, James Brierley wrote:
> On 20/12/13 01:03, Matthew Brush wrote:
>> This would probably make a good plugin.
>>
>> It should be possible, at least for languages who's lexer supports
>> folding and where folding is roughly equivalent to scope. Maybe
>> something like:
>>
>>    * find the current line's fold level
>>    * walk backwards each line until the fold level decreases
>>        - store that line's start position
>>    * walk forwards each line until the fold level decreases
>>        - store that line's end position
>>    * for each character/cell in between start and end, change style
>
> Indeed, most languages are folded with respect to scope. I hadn’t
> thought of that because I don’t tend to use folds much. This is more or
> less the kind of simple algorithm I had in mind, but more general than
> the concrete brackets/parens example. Good idea.
>
>> You could probably also do something similar but calculate the XY pixel
>> coordinates of a box around the scope and draw an overlay window at that
>> box's size and position, allowing input to go through to the Scintilla
>> widget underneath (similar effect to XCode's scope highlighting). This
>> is kind of a similar effect as my "blackout" experiment except around
>> the scope box instead of the whole editor widget:
>>
>> http://codebrainz.ca/images/blackout-demo.png
>
> Interesting idea. I think I’d do it the simpler and less radical way
> though.
>
> Sounds like writing a little plugin is going on my to-do list then.
>

Just for fun I made a little experiment doing what I was talking about:

http://codebrainz.ca/screencasts/GeanyScopeHighlight.avi

Cheers,
Matthew Brush



More information about the Users mailing list