[Geany-devel] Parentheses auto-indentation

Colomban Wendling lists.ban at xxxxx
Sat Jun 12 17:09:31 UTC 2010


Le 09/06/2010 02:48, Lex Trotman a écrit :
>>> 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…
>>     
> Which pos? there are lots in brace_match, what about if pos-1 is
> replaced by pos?
>   
I'm talking about this code chunk:

chAtPos = sci_get_char_at(sci, pos - 1);
styAtPos = sci_get_style_at(sci, pos);

And I doubt that simply using pos and not pos-1 would fix the problem,
even if it'd probably be less hackish not to use pos-1 (which might even
become -1 if I read this right).
>>>> 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.
>>
>>     
> I was thinking something similar to the brace matching settings for
> the reasons you give below.  There is plenty of room in that page of
> the prefs dialog.  Of course with my GUI record Enrico is sure to
> disgree :D
>   
Let's wait for other thoughts then ^^

>> 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 */
>> }
>>     
> Sadly this example came through the email without any indentation at
> all so I'm not sure what you mean.
>   
Oh, sorry. with s/ /_/g, it is:

if (a &&
____b) {
__/* code */
}

results to:

if (a &&
____b) {
__/* code */
____}

...the closing bracket is aligned with the indentation of the maching opening one, but here it isn't indentation but alignment; then it breaks.

>> 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.
>>
>>     
> I don't have a chance just now but will as soon as possible, I like
> the idea of assisted function parameter indentation.
Cool, I'm not alone! :D

Regards,
Colomban




More information about the Devel mailing list