[Geany-devel] Auto-close parenthesis - ID: 2957958 Need Info

shan chak shankholove at xxxxx
Tue Nov 2 18:19:10 UTC 2010


Hi,
Thanks Lex,

>
> > The problem is in file editor.c function auto_close_char Line:1397
> >
> > In the switch-case block the ifs have a compulsory condition which is
> > end_pos == -1 , as far as I understand end_pos is the current position of
> > the brace ( caret ) returned by SSM(sci, SCI_BRACEMATCH, pos, 0) and when
> > the second opening brace is typed the end_pos becomes >0 so the code
> never
> > enters the if block. Just by removing the condition the problem is
> fixed.I
> > was unable to get why that specific condition was added, can anybody
> please
> > help me here?
>
> I haven't analyzed it carefully, but I think what it is trying to do
> is to only add a new close bracket only if one is needed.  If
> sci_find_matching_brace finds a match then it won't add one, whereas
> if there is no matching close bracket then one will be added.
>
> Of course the use case shown in the bug shows this is flawed in some
> cases, but in other cases its useful eg if the end == -1 wasn't there
>
> a = ( b + 1 ? c : d ) + 1  oops I need a bracket around the b+1
>
> type the (
>
> a = ( () b + 1 ? c : d ) + 1  ...  !@#$%^&*()
>
> So you can't win, no simple algorithm is right all the time.  I guess
> the autoclose users need to decide which is more useful (I don't use
> it so I don't care)
>

I missed this case. Surely its pretty annoying.
Now if we see how eclipse implement this  , it will never autocomplete the
braces  for cases like these:
a = (  b + 1 ? c : d ) + 1
Now if we type the bracket around b+1 then
a = ( ( b + 1 ? c : d ) + 1
and let the user decide how to close it.
The algorithm is complex taking into consideration many corner cases.

> >
> > Also if there is auto completion of braces when a '(' is typed why there
> is
> > no auto removal of ')' when a brace is deleted?
>
> No one wrote the code, patches are welcome, but beware of similar
> issues to above.  Actually I think this patch may not be welcome since
> silently deleting characters is *bad*.
>
> Yeah its bad, but take the case:
A user inputs '(' and ')' is automatically added, now what if user deletes
the '(' , he/she also has to delete the ')'. I think in such cases its not a
big risk to delete the ')'. Like the above case if there is any character in
between '(' and ')' let the user decide.

> >
> > I am sorry if the mail looks pretty unprofessional but I have just begun
> to
> > learn geany code base.
>
> No problem.
>
> Eagerly waiting for your comments.

Thank you
shankhs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.geany.org/pipermail/devel/attachments/20101102/a402d8f2/attachment.html>


More information about the Devel mailing list