[anjuta] indentation-c-style: Fix get_line_indentation().



commit e27cade3ec1ce883182ff1b99637d781ae6b128c
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Mon Nov 12 23:37:20 2012 +0100

    indentation-c-style: Fix get_line_indentation().
    
    get_line_indentation() was broken since 166f7f2cb4eaabb4b148841881cccf2855fa081a. Fix it
    by only looking for matching left brace if the current line has a right brace.
    
    Also break on the first line where the number of left braces are more than or equal to the right
    braces instead of just breaking on the line where the total number of left and right braces are
    equal.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688275

 plugins/indentation-c-style/indentation.c |   45 ++++++++++++++++++----------
 1 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/plugins/indentation-c-style/indentation.c b/plugins/indentation-c-style/indentation.c
index 0cade36..5c18229 100644
--- a/plugins/indentation-c-style/indentation.c
+++ b/plugins/indentation-c-style/indentation.c
@@ -132,29 +132,42 @@ get_line_indentation (IAnjutaEditor *editor, gint line_num)
 
 	line_end = ianjuta_editor_get_line_end_position (editor, line_num, NULL);
 
-	/* Find the line which contains the left brace matching last right brace on current line */
-
-	do
+	while (ianjuta_iterable_previous (line_end, NULL))
 	{
-		while (ianjuta_iterable_previous (line_end, NULL))
+		ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (line_end), 0, NULL);
+		if (ch == ')')
+			right_braces++;
+		if (ch == '(')
+			left_braces++;
+		if (iter_is_newline (line_end, ch))
 		{
-			ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (line_end), 0, NULL);
-			if (ch == ')')
-				right_braces++;
-			if (ch == '(')
-				left_braces++;
-			if (iter_is_newline (line_end, ch))
-			{
-				break;
-			}
+			break;
 		}
-		if (right_braces != left_braces)
+	}
+
+	/* Find the line which contains the left brace matching last right brace on current line */
+	if (right_braces > 0)
+	{
+		while (right_braces >= left_braces && line_num >= 0)
 		{
-			line_num --;
+			line_num--;
 			g_object_unref (line_end);
 			line_end = ianjuta_editor_get_line_end_position (editor, line_num, NULL);
+
+			while (ianjuta_iterable_previous (line_end, NULL))
+			{
+				ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (line_end), 0, NULL);
+				if (ch == ')')
+					right_braces++;
+				if (ch == '(')
+					left_braces++;
+				if (iter_is_newline (line_end, ch))
+				{
+					break;
+				}
+			}
 		}
-	} while (right_braces != left_braces && line_num >= 0);
+	}
 
 	g_object_unref (line_end);
 	line_begin = ianjuta_editor_get_line_begin_position (editor, line_num, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]