gtksourceview r2215 - in branches/indenters: . gtksourceview
- From: icq svn gnome org
- To: svn-commits-list gnome org
- Subject: gtksourceview r2215 - in branches/indenters: . gtksourceview
- Date: Wed, 11 Mar 2009 16:51:34 +0000 (UTC)
Author: icq
Date: Wed Mar 11 16:51:34 2009
New Revision: 2215
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2215&view=rev
Log:
2009-03-11 Ignacio Casal Quinteiro <nacho resa gmail com>
* gtksourceview/c-indenter.c:
* gtksourceview/gtksourceindenter-utils.c:
* gtksourceview/gtksourceindenter-utils.h:
Skip preprocessor sentences when looking for the level.
Do not indent when we have something like var =\n
Modified:
branches/indenters/ChangeLog
branches/indenters/gtksourceview/c-indenter.c
branches/indenters/gtksourceview/gtksourceindenter-utils.c
branches/indenters/gtksourceview/gtksourceindenter-utils.h
Modified: branches/indenters/gtksourceview/c-indenter.c
==============================================================================
--- branches/indenters/gtksourceview/c-indenter.c (original)
+++ branches/indenters/gtksourceview/c-indenter.c Wed Mar 11 16:51:34 2009
@@ -44,6 +44,7 @@
static const gchar * case_regexes[] =
{
"^\\s*(default|case [^ ]*)\\s*:\\s*(if|while|else if|for|switch)\\s*\\(.*\\)\\s*$",
+ "^\\s*(default|case [^ ]*)\\s*:\\s*do\\s*$",
NULL
};
@@ -144,6 +145,10 @@
iter = *cur;
+ /* Skip all preprocessor sentences */
+ while (!relocating && gtk_source_indenter_move_to_no_preprocessor (&iter))
+ continue;
+
if (!gtk_source_indenter_move_to_no_space (&iter, -1))
return 0;
@@ -371,11 +376,6 @@
g_free (label);
}
- else if (c == '=')
- {
- amount = gtk_source_indenter_get_amount_indents (view, &iter);
- amount = gtk_source_indenter_add_indent (view, amount);
- }
else if (match_regexes (&iter, regexes))
{
gtk_source_indenter_find_open_char (&iter, '(', ')', FALSE);
@@ -404,6 +404,11 @@
amount = gtk_source_indenter_get_amount_indents_from_position (view, &iter);
amount = gtk_source_indenter_add_indent (view, amount);
}
+ /* # is always indent 0. Example: #ifdef */
+ else if (relocating && c == '#')
+ {
+ amount = 0;
+ }
else
{
GtkTextIter copy;
@@ -425,18 +430,15 @@
©);
}
}
- else
+ /*
+ * Are we in something like: if (hello\n
+ */
+ else if (gtk_source_indenter_find_open_char (©, '(', ')',
+ TRUE))
{
- gunichar ch;
-
- gtk_source_indenter_move_to_no_space (©, 1);
- ch = gtk_text_iter_get_char (©);
-
- /* # is always indent 0. Example: #ifdef */
- if (relocating && ch == '#')
- {
- amount = 0;
- }
+ amount = gtk_source_indenter_get_amount_indents_from_position (view,
+ ©);
+ amount += 1;
}
}
Modified: branches/indenters/gtksourceview/gtksourceindenter-utils.c
==============================================================================
--- branches/indenters/gtksourceview/gtksourceindenter-utils.c (original)
+++ branches/indenters/gtksourceview/gtksourceindenter-utils.c Wed Mar 11 16:51:34 2009
@@ -184,6 +184,42 @@
}
gboolean
+gtk_source_indenter_move_to_no_preprocessor (GtkTextIter *iter)
+{
+ gunichar c;
+ GtkTextIter copy;
+ gboolean moved = TRUE;
+
+ copy = *iter;
+
+ gtk_text_iter_set_line_offset (©, 0);
+ gtk_source_indenter_move_to_no_space (©, 1);
+
+ c = gtk_text_iter_get_char (©);
+
+ if (c == '#')
+ {
+ /*
+ * Move back until we get a no space char
+ */
+ do
+ {
+ if (!gtk_text_iter_backward_char (©))
+ moved = FALSE;
+ c = gtk_text_iter_get_char (©);
+ } while (g_unichar_isspace (c));
+
+ *iter = copy;
+ }
+ else
+ {
+ moved = FALSE;
+ }
+
+ return moved;
+}
+
+gboolean
gtk_source_indenter_find_open_char (GtkTextIter *iter,
gchar open,
gchar close,
Modified: branches/indenters/gtksourceview/gtksourceindenter-utils.h
==============================================================================
--- branches/indenters/gtksourceview/gtksourceindenter-utils.h (original)
+++ branches/indenters/gtksourceview/gtksourceindenter-utils.h Wed Mar 11 16:51:34 2009
@@ -40,6 +40,8 @@
gboolean gtk_source_indenter_move_to_no_comments (GtkTextIter *iter);
+gboolean gtk_source_indenter_move_to_no_preprocessor (GtkTextIter *iter);
+
gboolean gtk_source_indenter_find_open_char (GtkTextIter *iter,
gchar open,
gchar close,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]