On 13-12-19 03:42 PM, James Brierley wrote:
Hello everyone,
I might just be being dense, but I can’t seem to find any hard info about this, so I’ll just throw it out there.
Suppose I’m writing a function such as the following C/Java-ish pseudocode (the spurious symbols will be explained in due course):
void some_function(int foo, double spam) { int pointless_var = 0xD00D; *[1]*
while (HELL_HASNT_FROZEN_OVER) { if (some_condition) { do_something(); *[2]* } else { do_something_else(); *[3]* } } return;
}
Now, what would be useful is, to give some concrete examples, when the cursor is at position *[1]*, everything between some_function’s braces would be highlighted in some way, say with a slightly off-white background; at position *[2]* everything between the if statement’s braces would be highlighted, and at *[3]* — you guessed it — everything within the else block would be highlighted. In other words, the extent of the scope of declarations would always be highlighted.
Would it be possible in any way to extend the brace matching capabilities of Geany to make anything like this possible? Of course, in some languages scope is more complicated than “everything between a { and a }” but even something this simple and stupid would be useful in a lot of cases.
I should point out that this was prompted by me writing quite a lot of Lisp, and occasionally getting ‘Lost In Silly Parentheses’, but I presented a C-esque example for the benefit of anyone who would rather eat their own toenails than program in Lisp.
Anyway, just wondering if the various components of Geany can be persuaded to make something like this possible, whether that means me writing a patch or something else.
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
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
Cheers, Matthew Brush