SF.net SVN: geany:[3802] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Mon May 18 15:17:49 UTC 2009
Revision: 3802
http://geany.svn.sourceforge.net/geany/?rev=3802&view=rev
Author: ntrel
Date: 2009-05-18 15:17:48 +0000 (Mon, 18 May 2009)
Log Message:
-----------
Make indenting with the Tabs indent type preserve spaces on the line,
so it works for the 'tab indents, space aligns' formatting style.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/editor.c
trunk/src/editor.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-05-18 15:01:21 UTC (rev 3801)
+++ trunk/ChangeLog 2009-05-18 15:17:48 UTC (rev 3802)
@@ -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>
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2009-05-18 15:01:21 UTC (rev 3801)
+++ trunk/src/callbacks.c 2009-05-18 15:17:48 UTC (rev 3802)
@@ -1713,18 +1713,6 @@
}
-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 @@
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 @@
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);
}
Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c 2009-05-18 15:01:21 UTC (rev 3801)
+++ trunk/src/editor.c 2009-05-18 15:17:48 UTC (rev 3802)
@@ -4480,3 +4480,78 @@
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);
+ }
+}
+
+
Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h 2009-05-18 15:01:21 UTC (rev 3801)
+++ trunk/src/editor.h 2009-05-18 15:17:48 UTC (rev 3802)
@@ -195,6 +195,8 @@
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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list