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.
James
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
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:
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.
Thanks guys,
James
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:
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
Am 23.12.2013 09:40, schrieb Matthew Brush:
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:
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:
Nice! Could scope detection potentially also be used to add local variables to autocompletion?
PS: The video didn't play in VLC (stuck on first frame) but did with ffplay.
Best regards.
On 13-12-23 12:52 AM, Thomas Martitz wrote:
Am 23.12.2013 09:40, schrieb Matthew Brush:
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:
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:
Nice! Could scope detection potentially also be used to add local variables to autocompletion?
I'm not sure but I doubt it, it's just using Scintilla fold points as described in the simple algorithm above (roughly).
PS: The video didn't play in VLC (stuck on first frame) but did with ffplay.
Dunno, plays here locally in VLC. IIRC it's using H.264 in an AVI container.
Cheers, Matthew Brush
[...]
Nice! Could scope detection potentially also be used to add local variables to autocompletion?
Thomas,
I looked fairly closely at the possibility of adding local variables a while ago. There are several things missing to get local variables and local scope completion (talking about c.c languages only, other languages mileage may vary :-)
1. our parsers don't parse anything other than global scope, which is only declarations, so they only parse declarations, not statements, and they may be complicated significantly by the addition of the ability to discriminate between declarations and statements that are mixed inside local scopes.
2. tagmanager itself only understands named scopes, not lexical scopes, so whilst the fold info can detect a lexical scope, tagmanager has no way of storing such information. If tagmanager could store it, it would probably fall out of the parser anyway, once the local scopes are parsed, so fold info isn't much benefit.
3. for C, autocomplete would need to understand how to look up local variables, through the nested scopes, also the rules for hiding outer scopes, and for C++, also rules for member lookup in member functions. For other languages whatever rules they may add. And it has to apply these rules to partially complete symbol names, and fast.
All of which is a way of saying: 1. its possible 2. its a lot of work, 3. fold info won't help much if at all.
Cheers Lex
PS: The video didn't play in VLC (stuck on first frame) but did with ffplay.
Sadly can't play it at all, I'm on holidays with very slow internet, effectively email and some browsing only, no IRC and no videos :(
On 20 December 2013 10:42, James Brierley jmb8710@gmail.com 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.
Note that highlighting matching bracket works for parens too, so you could make the style for that ***very*** visible to help with the Lisp problems.
Cheers Lex
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.
James
-- "Unix is the worst computer operating system, except all the others that have been tried." _______________________________________________ Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users