[gnome-builder/auto-indent] auto-indent: move backwards to the next non-space character.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/auto-indent] auto-indent: move backwards to the next non-space character.
- Date: Wed, 17 Sep 2014 22:47:53 +0000 (UTC)
commit f1bbcfd583845a1e5657e0c12f3087487248b17e
Author: Christian Hergert <christian hergert me>
Date: Wed Sep 17 15:47:47 2014 -0700
auto-indent: move backwards to the next non-space character.
src/editor/gb-source-auto-indenter-c.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
index 13917c3..8a4708c 100644
--- a/src/editor/gb-source-auto-indenter-c.c
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -159,7 +159,7 @@ backward_find_stmt_expr (GtkTextIter *iter)
}
static guint
-backward_first_char (GtkTextIter *iter)
+backward_to_line_first_char (GtkTextIter *iter)
{
GtkTextIter tmp;
@@ -183,6 +183,13 @@ backward_first_char (GtkTextIter *iter)
}
static gboolean
+non_space_predicate (gunichar ch,
+ gpointer user_data)
+{
+ return !g_unichar_isspace (ch);
+}
+
+static gboolean
in_c89_comment (GtkTextIter *iter)
{
GtkTextIter cur;
@@ -255,11 +262,11 @@ gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
str = g_string_new (NULL);
/*
- * Move back to the character before the \n that was inserted.
- *
- * TODO: This assumption may change.
+ * Move backwards to the last non-space character inserted. We need to
+ * start by moving back one character to get to the pre-newline insertion
+ * point.
*/
- if (!gtk_text_iter_backward_char (iter))
+ if (!gtk_text_iter_backward_find_char (iter, non_space_predicate, NULL, NULL))
GOTO (cleanup);
/*
@@ -321,7 +328,7 @@ gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
if (!backward_find_stmt_expr (iter))
{
gtk_text_iter_assign (iter, &cur);
- offset = backward_first_char (iter);
+ offset = backward_to_line_first_char (iter);
build_indent (c, offset, iter, str);
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]