Make indenting with the Tabs indent type preserve spaces on the line,

so it works for the 'tab indents, space aligns' formatting style.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3802 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-05-18 15:17:48 +00:00
parent 14479d1729
commit 2edecade6b
4 changed files with 82 additions and 28 deletions

View File

@ -4,6 +4,9 @@
Add sci_set_selection().
* doc/geany.txt, doc/geany.html:
Update manual for MRU switching.
* src/callbacks.c, src/editor.c, src/editor.h:
Make indenting with the Tabs indent type preserve spaces on the line,
so it works for the 'tab indents, space aligns' formatting style.
2009-05-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -1713,18 +1713,6 @@ on_menu_duplicate_line1_activate (GtkMenuItem *menuitem,
}
static void change_line_indent(GeanyEditor *editor, gboolean increase)
{
const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
ScintillaObject *sci = editor->sci;
gint line = sci_get_current_line(sci);
gint width = sci_get_line_indentation(sci, line);
width += increase ? iprefs->width : -iprefs->width;
sci_set_line_indentation(sci, line, width);
}
void
on_menu_increase_indent1_activate (GtkMenuItem *menuitem,
gpointer user_data)
@ -1732,14 +1720,7 @@ on_menu_increase_indent1_activate (GtkMenuItem *menuitem,
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
if (sci_get_lines_selected(doc->editor->sci) > 1)
{
sci_send_command(doc->editor->sci, SCI_TAB);
}
else
{
change_line_indent(doc->editor, TRUE);
}
editor_indent(doc->editor, TRUE);
}
@ -1750,14 +1731,7 @@ on_menu_decrease_indent1_activate (GtkMenuItem *menuitem,
GeanyDocument *doc = document_get_current();
g_return_if_fail(doc != NULL);
if (sci_get_lines_selected(doc->editor->sci) > 1)
{
sci_send_command(doc->editor->sci, SCI_BACKTAB);
}
else
{
change_line_indent(doc->editor, FALSE);
}
editor_indent(doc->editor, FALSE);
}

View File

@ -4480,3 +4480,78 @@ void editor_apply_update_prefs(GeanyEditor *editor)
editor_prefs.smart_home_key ? SCI_VCHOMEWRAP : SCI_HOMEWRAP);
sci_assign_cmdkey(sci, SCK_END, SCI_LINEENDWRAP);
}
/* This is for tab-indents, space aligns formatted code. Spaces should be preserved. */
static void change_tab_indentation(ScintillaObject *sci, gint line, gboolean increase)
{
gint pos = sci_get_position_from_line(sci, line);
if (increase)
{
sci_insert_text(sci, pos, "\t");
}
else
{
if (sci_get_char_at(sci, pos) == '\t')
{
sci_set_selection(sci, pos, pos + 1);
sci_replace_sel(sci, "");
}
}
}
static void editor_change_line_indent(GeanyEditor *editor, gint line, gboolean increase)
{
const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
ScintillaObject *sci = editor->sci;
if (iprefs->type == GEANY_INDENT_TYPE_TABS /* && iprefs->ignore_spaces */)
change_tab_indentation(sci, line, increase);
else
{
gint width = sci_get_line_indentation(sci, line);
width += increase ? iprefs->width : -iprefs->width;
sci_set_line_indentation(sci, line, width);
}
}
void editor_indent(GeanyEditor *editor, gboolean increase)
{
ScintillaObject *sci = editor->sci;
gint start, end;
gint line, lstart, lend;
if (sci_get_lines_selected(sci) <= 1)
{
line = sci_get_current_line(sci);
editor_change_line_indent(editor, line, increase);
return;
}
editor_select_lines(editor, FALSE);
start = sci_get_selection_start(sci);
end = sci_get_selection_end(sci);
lstart = sci_get_line_from_position(sci, start);
lend = sci_get_line_from_position(sci, end);
for (line = lstart; line < lend; line++)
{
editor_change_line_indent(editor, line, increase);
}
if (lend > lstart)
{
sci_set_selection_start(sci, start);
end = sci_get_position_from_line(sci, lend);
sci_set_selection_end(sci, end);
editor_select_lines(editor, FALSE);
}
else
{
sci_set_current_line(sci, lstart);
}
}

View File

@ -195,6 +195,8 @@ void editor_insert_multiline_comment(GeanyEditor *editor);
void editor_insert_alternative_whitespace(GeanyEditor *editor);
void editor_indent(GeanyEditor *editor, gboolean increase);
void editor_smart_line_indentation(GeanyEditor *editor, gint pos);
void editor_indentation_by_one_space(GeanyEditor *editor, gint pos, gboolean decrease);