anjuta r4026 - in branches/anjuta-2-4: . plugins/language-support-cpp-java



Author: jhs
Date: Mon Jun 16 12:14:08 2008
New Revision: 4026
URL: http://svn.gnome.org/viewvc/anjuta?rev=4026&view=rev

Log:
2008-06-16  Johannes Schmid  <jhs gnome org>

	* plugins/language-support-cpp-java/plugin.c
	(set_indentation_param_emacs), (set_indentation_param_vim),
	(set_line_indentation), (get_line_indentation_base),
	(get_line_auto_indentation), (on_editor_char_inserted_cpp):
	
	Fixed #528699 â Auto-indent ignores spaces-per-indent settings (from trunk)

Modified:
   branches/anjuta-2-4/ChangeLog
   branches/anjuta-2-4/plugins/language-support-cpp-java/plugin.c

Modified: branches/anjuta-2-4/plugins/language-support-cpp-java/plugin.c
==============================================================================
--- branches/anjuta-2-4/plugins/language-support-cpp-java/plugin.c	(original)
+++ branches/anjuta-2-4/plugins/language-support-cpp-java/plugin.c	Mon Jun 16 12:14:08 2008
@@ -411,7 +411,7 @@
 set_indentation_param_emacs (CppJavaPlugin* plugin, const gchar *param,
 					   const gchar *value)
 {
-	DEBUG_PRINT ("Setting indent param: %s = %s", param, value);
+	//DEBUG_PRINT ("Setting indent param: %s = %s", param, value);
 	if (strcasecmp (param, "indent-tabs-mode") == 0)
 	{
 		if (strcasecmp (value, "t") == 0)
@@ -443,7 +443,7 @@
 set_indentation_param_vim (CppJavaPlugin* plugin, const gchar *param,
 					   const gchar *value)
 {
-	DEBUG_PRINT ("Setting indent param: %s = %s", param, value);
+	//DEBUG_PRINT ("Setting indent param: %s = %s", param, value);
 	if (g_str_equal (param, "expandtab") ||
 		g_str_equal (param, "et"))
 	{
@@ -692,7 +692,7 @@
 		gchar *line_string = ianjuta_editor_get_text (editor, line_begin,
 														   line_end, NULL);
 		
-		DEBUG_PRINT ("line_string = '%s'", line_string);
+		//DEBUG_PRINT ("line_string = '%s'", line_string);
 		if (line_string)
 		{
 			idx = line_string;
@@ -712,7 +712,7 @@
 	*/
 	current_pos = ianjuta_editor_get_position (editor, NULL);
 	carat_offset = ianjuta_iterable_diff (indent_position, current_pos, NULL);
-	DEBUG_PRINT ("carat offset is = %d", carat_offset);
+	//DEBUG_PRINT ("carat offset is = %d", carat_offset);
 	
 	/* Set new indentation */
 	if (indentation > 0)
@@ -730,7 +730,7 @@
 					ianjuta_editor_get_text (editor, line_begin,
 												  indent_position, NULL);
 				
-				DEBUG_PRINT ("old_indent_string = '%s'", old_indent_string);
+				//DEBUG_PRINT ("old_indent_string = '%s'", old_indent_string);
 				nchars_removed = g_utf8_strlen (old_indent_string, -1);
 			}
 			
@@ -1101,14 +1101,17 @@
 			/* This is a forward reference, all lines below should have
 			 * increased indentation until the next statement has
 			 * a ':'
+			 * If current line indentation is zero, that we don't indent
 			 */
 			IAnjutaIterable* new_iter = ianjuta_iterable_clone (iter, NULL);
-			gboolean indent = FALSE;		
+			IAnjutaIterable* line_begin;
+			gboolean indent = FALSE;
+			gchar c;
 			
 			/* Is the last non-whitespace in line */
 			while (ianjuta_iterable_next (new_iter, NULL))
 			{
-				gchar c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (new_iter),
+				c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (new_iter),
 													   0, NULL);
 				if (!isspace(c))
 					break;
@@ -1118,14 +1121,23 @@
 					break;
 				}
 			}
-			g_object_unref (new_iter);
+			line_begin = ianjuta_editor_get_line_begin_position(editor,
+																ianjuta_editor_get_line_from_position(editor, iter, NULL),
+																NULL);
+			c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (line_begin),
+														0, NULL);
 			if (indent)
 			{
 				*colon_indent = TRUE;
-				extra_indent += INDENT_SIZE;
 				if (*incomplete_statement == -1)
 					*incomplete_statement = 0;
 			}
+			if (indent && isspace(c))
+			{
+				extra_indent += INDENT_SIZE;
+			}
+			g_object_unref (new_iter);
+			g_object_unref (line_begin);
 		}	
 		else if (iter_is_newline (iter, point_ch))
 		{
@@ -1158,7 +1170,6 @@
 	}
 	if (!line_indent && extra_indent)
 	{
-		DEBUG_PRINT ("Adding special indent");
 		line_indent += extra_indent;
 	}
 	g_object_unref (iter);
@@ -1237,9 +1248,9 @@
 		/* If the last non-whitespace character in the line is ":" then
 		 * we remove the extra colon_indent
 		 */
-		end_iter = ianjuta_editor_get_line_end_position (editor, line, NULL);
 		gchar ch;
-		do
+		end_iter = ianjuta_editor_get_line_end_position (editor, line, NULL);
+		while (ianjuta_iterable_previous (end_iter, NULL))
 		{
 			ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (end_iter),
 											   0, NULL);
@@ -1248,8 +1259,9 @@
 				line_indent -= INDENT_SIZE;
 				break;
 			}
+			if (!isspace(ch) || iter_is_newline (end_iter, ch))
+				break;
 		}
-		while (isspace(ch) && ianjuta_iterable_previous (end_iter, NULL));
 		g_object_unref (end_iter);
 	}
 	
@@ -1386,10 +1398,6 @@
 			}
 		}
 	}
-	else if (ch == ':')
-	{
-		should_auto_indent = TRUE;
-	}
 	if (should_auto_indent)
 	{
 		gint insert_line;



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