gtksourceview r2208 - in branches/indenters: . gtksourceview
- From: icq svn gnome org
- To: svn-commits-list gnome org
- Subject: gtksourceview r2208 - in branches/indenters: . gtksourceview
- Date: Sat, 7 Mar 2009 18:55:57 +0000 (UTC)
Author: icq
Date: Sat Mar 7 18:55:57 2009
New Revision: 2208
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2208&view=rev
Log:
2009-03-07 Ignacio Casal Quinteiro <nacho resa gmail com>
* gtksourceview/c-indenter.c:
Manage indentation and relocations in switch ().
Modified:
branches/indenters/ChangeLog
branches/indenters/gtksourceview/c-indenter.c
Modified: branches/indenters/gtksourceview/c-indenter.c
==============================================================================
--- branches/indenters/gtksourceview/c-indenter.c (original)
+++ branches/indenters/gtksourceview/c-indenter.c Sat Mar 7 18:55:57 2009
@@ -41,8 +41,15 @@
NULL
};
+static const gchar * case_regexes[] =
+{
+ "^\\s*(default|case [^ ]*)\\s*:\\s*(if|while|else if|for|switch)\\s*\\(.*\\)\\s*$",
+ NULL
+};
+
static gboolean
-match_regexes (GtkTextIter *iter)
+match_regexes (GtkTextIter *iter,
+ const gchar * const *regexes)
{
gint i = 0;
gboolean match = FALSE;
@@ -227,7 +234,7 @@
gtk_text_iter_backward_char (©);
- if (match_regexes (©))
+ if (match_regexes (©, regexes))
{
gtk_source_indenter_find_open_char (©, '(', ')', FALSE);
@@ -249,7 +256,7 @@
gtk_text_iter_backward_char (&iter);
- if (match_regexes (&iter))
+ if (match_regexes (&iter, regexes))
{
gtk_source_indenter_find_open_char (&iter, '(', ')', FALSE);
@@ -289,13 +296,51 @@
if (relocating)
{
- if (match_regexes (&iter))
+ if (match_regexes (&iter, regexes))
{
gtk_source_indenter_find_open_char (&iter, '(', ')', FALSE);
amount = gtk_source_indenter_get_amount_indents (view,
&iter);
}
+ else if (match_regexes (&iter, case_regexes))
+ {
+ gunichar ch;
+
+ /* We are in a case label like: case 0: if (hello)
+ * so we first look backward for the ':' and then look forward
+ * for the first char
+ */
+ find_char_inline (&iter, ':');
+ gtk_text_iter_forward_char (&iter);
+ ch = gtk_text_iter_get_char (&iter);
+
+ while (g_unichar_isspace (ch))
+ {
+ gtk_text_iter_forward_char (&iter);
+ ch = gtk_text_iter_get_char (&iter);
+ }
+
+ amount = gtk_source_indenter_get_amount_indents_from_position (view, &iter);
+ }
+ else
+ {
+ GtkTextIter start;
+ gchar *label;
+
+ start = iter;
+ gtk_text_iter_set_line_offset (&start, 0);
+ gtk_source_indenter_move_to_no_space (&start, 1);
+
+ label = gtk_text_iter_get_text (&start, &iter);
+
+ if (is_caselabel (label))
+ {
+ amount = gtk_source_indenter_get_amount_indents (view, &iter);
+ }
+
+ g_free (label);
+ }
}
else
{
@@ -364,13 +409,34 @@
amount = gtk_source_indenter_get_amount_indents (view, &iter);
amount = gtk_source_indenter_add_indent (view, amount);
}
- else if (match_regexes (&iter))
+ else if (match_regexes (&iter, regexes))
{
gtk_source_indenter_find_open_char (&iter, '(', ')', FALSE);
amount = gtk_source_indenter_get_amount_indents (view, &iter);
amount = gtk_source_indenter_add_indent (view, amount);
}
+ else if (match_regexes (&iter, case_regexes))
+ {
+ gunichar ch;
+
+ /* We are in a case label like: case 0: if (hello)
+ * so we first look backward for the ':' and then look forward
+ * for the first char
+ */
+ find_char_inline (&iter, ':');
+ gtk_text_iter_forward_char (&iter);
+ ch = gtk_text_iter_get_char (&iter);
+
+ while (g_unichar_isspace (ch))
+ {
+ gtk_text_iter_forward_char (&iter);
+ ch = gtk_text_iter_get_char (&iter);
+ }
+
+ amount = gtk_source_indenter_get_amount_indents_from_position (view, &iter);
+ amount = gtk_source_indenter_add_indent (view, amount);
+ }
else
{
GtkTextIter copy;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]