After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 586604 - Wrong autoindention after line wrapping in condition
Wrong autoindention after line wrapping in condition
Status: RESOLVED FIXED
Product: anjuta
Classification: Applications
Component: plugins: language-support-c-cpp-java
2.26.x
Other All
: Normal normal
: ---
Assigned To: Naba Kumar
Anjuta maintainers
Depends on:
Blocks:
 
 
Reported: 2009-06-22 08:55 UTC by Sebastian V.
Modified: 2012-04-24 17:48 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26


Attachments
Fixed the autoindentation after line wrapping (19.51 KB, patch)
2012-04-02 20:12 UTC, Mihai Ciocan
none Details | Review
Fixed the autoindentation after line wrapping (19.34 KB, patch)
2012-04-02 20:35 UTC, Mihai Ciocan
reviewed Details | Review
Fixed the autoindentation after line wrapping (4.00 KB, patch)
2012-04-19 22:58 UTC, Mihai Ciocan
none Details | Review
Fixed the autoindentation after line wrapping (2.52 KB, patch)
2012-04-22 20:09 UTC, Mihai Ciocan
needs-work Details | Review
Fixed the autoindentation after line wrapping (2.15 KB, patch)
2012-04-24 10:55 UTC, Mihai Ciocan
accepted-commit_now Details | Review

Description Sebastian V. 2009-06-22 08:55:07 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:
Comment 1 Johannes Schmid 2009-06-22 11:22:25 UTC
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)) {
}

?
Comment 2 Sebastian V. 2009-06-22 12:28:25 UTC
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.
Comment 3 Johannes Schmid 2009-06-22 17:16:47 UTC
OK, sorry I missed the point then. I am never using the { in the same line style so I guess I have missed that.
Comment 4 Mihai Ciocan 2012-04-02 20:12:56 UTC
Created attachment 211185 [details] [review]
Fixed the autoindentation after line wrapping
Comment 5 Mihai Ciocan 2012-04-02 20:35:59 UTC
Created attachment 211186 [details] [review]
Fixed the autoindentation after line wrapping
Comment 6 Johannes Schmid 2012-04-03 08:45:18 UTC
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?
Comment 7 Mihai Ciocan 2012-04-03 17:45:55 UTC
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.
Comment 8 Mihai Ciocan 2012-04-19 22:58:57 UTC
Created attachment 212392 [details] [review]
Fixed the autoindentation after line wrapping

I have unrefed line_end_copy and added the part that was deleted.
Comment 9 Sébastien Granjoux 2012-04-22 15:04:12 UTC
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.
Comment 10 Mihai Ciocan 2012-04-22 20:09:50 UTC
Created attachment 212567 [details] [review]
Fixed the autoindentation after line wrapping

Now it should be ok.
Comment 11 Sébastien Granjoux 2012-04-23 20:18:13 UTC
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.
Comment 12 Mihai Ciocan 2012-04-24 10:55:30 UTC
Created attachment 212684 [details] [review]
Fixed the autoindentation after line wrapping

I did the changes, I hope it is better.
Comment 13 Sébastien Granjoux 2012-04-24 17:47:31 UTC
Review of attachment 212684 [details] [review]:

Yes, that is fine. Thank you very much for you work. I have just committed your patch.