anjuta r4768 - in trunk: . plugins/language-support-cpp-java



Author: jhs
Date: Fri Feb 20 11:50:20 2009
New Revision: 4768
URL: http://svn.gnome.org/viewvc/anjuta?rev=4768&view=rev

Log:
2009-02-20  Johannes Schmid  <jhs gnome org>

	* plugins/language-support-cpp-java/plugin.c
	(set_line_indentation), (spaces_only), (get_line_auto_indentation),
	(on_editor_char_inserted_cpp):
	#540989 â Should not insert tabs on empty lines

Modified:
   trunk/ChangeLog
   trunk/plugins/language-support-cpp-java/plugin.c

Modified: trunk/plugins/language-support-cpp-java/plugin.c
==============================================================================
--- trunk/plugins/language-support-cpp-java/plugin.c	(original)
+++ trunk/plugins/language-support-cpp-java/plugin.c	Fri Feb 20 11:50:20 2009
@@ -178,7 +178,7 @@
 		else
 			line_indent++;
 		idx++; /* Since we are looking for first non-space char, simple
-	            * increment of the utf8 chars would do */
+				* increment of the utf8 chars would do */
 	}
 	g_free (line_string);
 	return line_indent;
@@ -758,7 +758,7 @@
 	/* If indentation == 0, we really didn't enter the previous code block,
 	 * but we may need to clear existing indentation.
 	 */
-	if (indentation == 0)
+	if ((indentation + line_indent_spaces) == 0)
 	{
 		/* Get existing indentation */
 		if (ianjuta_iterable_compare (indent_position, line_begin, NULL) > 0)
@@ -1218,6 +1218,24 @@
 	return FALSE;
 }
 
+static gboolean
+spaces_only (IAnjutaEditor* editor, IAnjutaIterable* begin, IAnjutaIterable* end)
+{
+	gboolean empty = TRUE;
+	gchar* text = ianjuta_editor_get_text (editor, begin, end, NULL);
+	gchar* idx;
+	for (idx = text; *idx != '\0'; idx++)
+	{
+		if (!isspace(*idx))
+		{
+			empty = FALSE;
+			break;
+		}
+	}
+	g_free(text);
+	return empty;
+}
+
 static gint
 get_line_auto_indentation (CppJavaPlugin *plugin, IAnjutaEditor *editor,
 						   gint line, gint *line_indent_spaces)
@@ -1231,10 +1249,24 @@
 	g_return_val_if_fail (line > 0, 0);
 	
 	if (line == 1) /* First line */
+	{
 		return 0;
+	}
+	else
+	{
+		IAnjutaIterable* begin = ianjuta_editor_get_line_begin_position (editor, line -1 , NULL);
+		IAnjutaIterable* end = ianjuta_editor_get_line_end_position (editor, line -1 , NULL);
+
+		if (spaces_only (editor, begin, end))
+		{
+			set_line_indentation (editor, line -1, 0, 0);
+		}
+		g_object_unref (begin);
+		g_object_unref (end);
+	}
 	
 	iter = ianjuta_editor_get_line_begin_position (editor, line, NULL);
-	
+
 	if (is_iter_inside_string (iter))
 	{
 		line_indent = get_line_indentation (editor, line - 1);
@@ -1246,18 +1278,18 @@
 												 line_indent_spaces,
 												 &colon_indent);
 	}
-	
+
 	if (colon_indent)
 	{
 		/* If the last non-whitespace character in the line is ":" then
 		 * we remove the extra colon_indent
 		 */
-		gchar ch;
 		end_iter = ianjuta_editor_get_line_end_position (editor, line, NULL);
+		gchar ch;
 		while (ianjuta_iterable_previous (end_iter, NULL))
 		{
 			ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (end_iter),
-											   0, NULL);
+			                                   0, NULL);
 			if (ch == ':')
 			{
 				line_indent -= INDENT_SIZE;
@@ -1412,6 +1444,7 @@
 		
 			ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT(editor), NULL);
 			initialize_indentation_params (plugin);
+			
 			insert_line = ianjuta_editor_get_lineno (editor, NULL);
 			line_indent = get_line_auto_indentation (plugin, editor, insert_line, &line_indent_spaces);
 			set_line_indentation (editor, insert_line, line_indent, line_indent_spaces);
@@ -1433,8 +1466,8 @@
 			/* If the previous char is a ' we don't have to autocomplete */
 			if (*prev_char != '\'')
 			{
+				
 				ianjuta_iterable_next (iter, NULL);
-		
 				switch (ch)
 				{
 					case '[': ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (editor), NULL);
@@ -1461,14 +1494,14 @@
 		{
 			gchar *prev_char;
 			IAnjutaIterable *previous;
-			
+
 			previous = ianjuta_iterable_clone (iter, NULL);
 			ianjuta_iterable_previous (previous, NULL);
 			prev_char = ianjuta_editor_get_text (editor, previous, iter, NULL);
 
 			/* First iter*/
 			ianjuta_iterable_next (iter, NULL);
-		
+
 			/*
 			 * If the character is " we have to decide if we need insert
 			 * another " or we have to skip the character



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