[gnome-builder/auto-indent] auto-indent: handle unindent when { is not the first character.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/auto-indent] auto-indent: handle unindent when { is not the first character.
- Date: Thu, 18 Sep 2014 23:39:56 +0000 (UTC)
commit 1f9d81d4551860a13689e79e83e59eeedb38236a
Author: Christian Hergert <christian hergert me>
Date: Thu Sep 18 16:39:51 2014 -0700
auto-indent: handle unindent when { is not the first character.
src/editor/gb-source-auto-indenter-c.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
index 90eebcf..366af1b 100644
--- a/src/editor/gb-source-auto-indenter-c.c
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -177,6 +177,26 @@ line_is_space (GtkTextIter *iter)
}
static gboolean
+starts_line_space_ok (GtkTextIter *iter)
+{
+ GtkTextIter tmp;
+
+ gtk_text_buffer_get_iter_at_line (gtk_text_iter_get_buffer (iter),
+ &tmp,
+ gtk_text_iter_get_line (iter));
+
+ for (;
+ gtk_text_iter_compare (&tmp, iter) < 0;
+ gtk_text_iter_forward_char (&tmp))
+ {
+ if (!g_unichar_isspace (gtk_text_iter_get_char (&tmp)))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
backward_find_stmt_expr (GtkTextIter *iter)
{
return FALSE;
@@ -591,6 +611,13 @@ maybe_unindent_brace (GbSourceAutoIndenterC *c,
GString *str;
guint offset;
+ /*
+ * Handle the case where { is not the first non-whitespace
+ * character on the line.
+ */
+ if (!starts_line_space_ok (begin))
+ backward_to_line_first_char (begin);
+
offset = gtk_text_iter_get_line_offset (begin);
str = g_string_new (NULL);
build_indent (c, offset, begin, str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]