Commit 9f24a112 authored by Johannes Schmid's avatar Johannes Schmid Committed by Johannes Schmid

#540989 – Should not insert tabs on empty lines

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

svn path=/trunk/; revision=4768
parent 0ceb59fb
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
2009-02-20 Johannes Schmid <jhs@gnome.org>
* plugins/language-support-cpp-java/plugin.c
......@@ -758,7 +758,7 @@ set_line_indentation (IAnjutaEditor *editor, gint line_num, gint indentation, gi
/* 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 @@ is_iter_inside_string (IAnjutaIterable *iter)
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,7 +1249,21 @@ get_line_auto_indentation (CppJavaPlugin *plugin, IAnjutaEditor *editor,
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);
......@@ -1252,8 +1284,8 @@ get_line_auto_indentation (CppJavaPlugin *plugin, IAnjutaEditor *editor,
/* 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),
......@@ -1412,6 +1444,7 @@ on_editor_char_inserted_cpp (IAnjutaEditor *editor,
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 @@ on_editor_char_inserted_cpp (IAnjutaEditor *editor,
/* If the previous char is a ' we don't have to autocomplete */
if (*prev_char != '\'')
{
ianjuta_iterable_next (iter, NULL);
ianjuta_iterable_next (iter, NULL);
switch (ch)
{
case '[': ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (editor), NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment