GNOME Bugzilla – Bug 586604
Wrong autoindention after line wrapping in condition
Last modified: 2012-04-24 17:48:08 UTC
Please describe the problem: Consider the following code: while (function(parameter1, parameter2, parameter3)) { } Inside this while block the autoindenting is wrong. Instead of adding the indention space to the position of while, it is added to the position of parameter3. So one needs to delete a lot of whitespace for every line. Steps to reproduce: 1. Use autoidention 2. Wrap a condition of if, while, for... 3. Try to write inside the block Actual results: Indented code gets aligned to the wrapped parameter Expected results: Indented code should be aligned to the keyword Does this happen every time? Yes, it does. Other information:
Hmm, actually this is the intended indentation. Consider function (param1, param2, param3); this is correct (at least in the style supported by anjuta). So naturally, if you put this into a while (or if) condition, it will be indented in the same way. Is there really a (common) coding style which would indent it this way while (function(parameter1, parameter2, parameter3)) { } ?
No, you understood me wrong. I think this style is the intended: while (function(parameter1, parameter2, parameter3)) { parameter1 + parameter2; } But what you get is: while (function(parameter1, parameter2, parameter3)) { parameter1 + parameter2; } A simple example would even be if (a && b) { f(a, b); } this will become if (a && b) { f(a, b); } I think the point is the same. I think the body of the block should only be indented by 4 spaces (if it's the default indention) and not more.
OK, sorry I missed the point then. I am never using the { in the same line style so I guess I have missed that.
Created attachment 211185 [details] [review] Fixed the autoindentation after line wrapping
Created attachment 211186 [details] [review] Fixed the autoindentation after line wrapping
Review of attachment 211186 [details] [review]: Thanks a lot for your contribution. Didn't have time to fully test it yet so just some comments on the coding below. ::: plugins/language-support-cpp-java/cpp-java-indentation.c @@ +137,3 @@ + /* Find the line which contains the left brace matching last right brace on current line */ + + line_end_copy = ianjuta_iterable_clone (line_end, NULL); You need to unref your line_end_copy iterator somewhere. @@ -613,3 @@ gchar c; - - /* Skip strings */ Is there a special reason why you delete this?
Actually I haven't delete it, I used the 3.2.2 version because it was easier for me to build and probably it was modified meanwhile. Thanks for your feedback. It is my first patch I made for GSOC application.
Created attachment 212392 [details] [review] Fixed the autoindentation after line wrapping I have unrefed line_end_copy and added the part that was deleted.
Review of attachment 212392 [details] [review]: I have looked at your latest patch but I don't understand why you have "g_object_unref (line_end_copy);" while line_end_copy is not defined earlier. Is this patch should be applied with the previous one? Else, it would be a better if your patch can be applied on the master version, ask me if you have troubles to compile the latest version of Anjuta.
Created attachment 212567 [details] [review] Fixed the autoindentation after line wrapping Now it should be ok.
Review of attachment 212567 [details] [review]: I understand your patch better but I think it can be improved a bit. If right_braces != left_braces, the two iterators line_begin and line_end that you have created at the beginning are just overwritten without really using them. if (right_braces != left_braces) { current_line_num --; line_begin = ianjuta_editor_get_line_begin_position (editor, current_line_num, NULL); line_end = ianjuta_editor_get_line_end_position (editor, current_line_num, NULL); line_end_copy = ianjuta_iterable_clone (line_end, NULL); } First, you have to unref all these iterator before overwriting them, as ianjuta_editor_get_line_begin_position, ianjuta_editor_get_line_end_position and ianjuta_iterable_clone all return a new iterator object. But, I think it's better to simply not create them at the beginning. You need only a line_end iterator for your loop. I think you should create only this one. Then, when your loop is over and you know the line that you want to check, you can create both iterators. The check if the line is empty at the beginning could be moved after your loop just before calling ianjuta_editor_get_text because your loop will work fine even on an empty line. Eventually you can reuse the line_end variable and the even the line_num because integer parameters are copied in C (passed by value). I suppose the C compiler will optimize this anyway.
Created attachment 212684 [details] [review] Fixed the autoindentation after line wrapping I did the changes, I hope it is better.
Review of attachment 212684 [details] [review]: Yes, that is fine. Thank you very much for you work. I have just committed your patch.