[Geany-devel] Parentheses auto-indentation

Colomban Wendling lists.ban at xxxxx
Wed Jun 9 00:08:03 UTC 2010


Le 08/06/2010 04:34, Lex Trotman a écrit :
> On 8 June 2010 00:43, Colomban Wendling <lists.ban at herbesfolles.org> wrote:
>   
>> How to know if a character is or not part of a comment, string or so? (e.g.
>> should be interpreted as a syntactic element by itself) I need this to find
>> the parenthesis -- and no, I can't do the same than brace_match() since I
>> don't know the position of any of the parentheses.
>>     
> Use editor.c/is_comment_style()
>   
Hey, almost perfect, found is_code_style() which is exactly what I need,
thanks a lot!
> The brace match indenting code needs fixing too, since it adjusts the
> indent of a } in a comment!!!
>   
True, and same for opening ones. Should be relatively easy to fix
though, even if it's perhaps not a change trivial enough to be in 0.19.
> Also brace_match ability to go forward and backward is wasted since it
> is only ever called from close_brace which AFAICT is only ever called
> with the current character a }
>
>   
>> Why brace_match() uses the character at (pos - 1) but the style at (pos)?
>> This seems to be needed for brackets but breaks with parentheses (see
>> comments in the WIP patch).
>>     
> Hmmm, actually the question is how do braces work when it does that?
>
> Probably pos is always > sci_get_end_styling since a } has just been
> added to the buffer and the scintilla documentation says the charadded
> notification is called before styling is done.
>   
It doesn't seems that simple since if I replace pos by pos - 1, the
brace matching indentation breaks…
>> And now the unique question (not that urgent since the patch isn't ready):
>> how to add this as part of the auto-indentation? (I mean, always enable it
>> -- I don't think everybody will like --, add a new indent method, a new
>> separated setting, or what?)
>>     
> I think it needs to be a separate setting, parentheses indent mode
>   
You mean a complete setting like the indent mode (with different levels,
etc) or simply a kinda boolean setting like "auto-indent parentheses"?
Maybe a complex setting might be interesting to allow not only
alignment, but also Geany-style of extra-indentation that isn't
alignment and even other if somebody needs it.

Ah, and there is another thing I would have to improve bracket matching
indentation when the opening one is indented because of an alignment:
backward parentheses matching after bracket matching. This would fix
indentation of something like:
if (a &&
b) {
/* code */
}
which currently result to:
if (a &&
b) {
/* code */
}
which is obviously wrong here. I mean that the bracket is first matched,
and then if there is a non-balanced parenthesis, it is matched to
finally get the indentation. Well, of course it's probably not enough in
some cases an/or languages, but it would probably fix the majority of
scenario.
Not sure if it should be completely related to parentheses
auto-indentation and/or matching, or if it should be part of a sort of
"intelligent detection of alignment vs. indentation".

Anyway, I join an updated patch that seems to work very well (at least
for me), thanks to is_code_style()! It still misses settings, and I
would like to know your thoughts about what should depend on which
setting (there's FIXME in the patch for them); and even how you'd like
to see it in the preference dialogue.

Regards,
Colomban
-------------- next part --------------
A non-text attachment was scrubbed...
Name: indent-matching-parentheses-draft-3.patch
Type: text/x-patch
Size: 3715 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/devel/attachments/20100609/a3cb0625/attachment.bin>


More information about the Devel mailing list