[gnome-builder] c-indenter: handle non-GNU style indentation better
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] c-indenter: handle non-GNU style indentation better
- Date: Wed, 31 Aug 2016 19:55:21 +0000 (UTC)
commit ecac5d1780d1490453ae5d4d7018c041142dabe8
Author: Christian Hergert <chergert redhat com>
Date: Wed Aug 31 12:55:09 2016 -0700
c-indenter: handle non-GNU style indentation better
While we are still waiting on our new indenter engine, we can make things
a bit better for those that are not using GNU-style C like we do in Gtk,
GLib, and Builder.
This falls back to the indent width for determining the indent after
conditions, and potential braces pre/post indent. This manages to not
effect GNU-style because it is 2 for both pre and post and should be
reflected by the current indentation.
plugins/c-pack/ide-c-indenter.c | 44 ++++++++++++++++++++++++++++++--------
1 files changed, 34 insertions(+), 10 deletions(-)
---
diff --git a/plugins/c-pack/ide-c-indenter.c b/plugins/c-pack/ide-c-indenter.c
index 9b3fb2f..22b9578 100644
--- a/plugins/c-pack/ide-c-indenter.c
+++ b/plugins/c-pack/ide-c-indenter.c
@@ -60,6 +60,30 @@ enum {
COMMENT_C99
};
+static inline guint
+get_post_scope_indent (IdeCIndenter *c)
+{
+ if (c->post_scope_indent == -1)
+ return c->indent_width;
+ return c->post_scope_indent;
+}
+
+static inline guint
+get_pre_scope_indent (IdeCIndenter *c)
+{
+ if (c->pre_scope_indent == -1)
+ return c->indent_width;
+ return c->pre_scope_indent;
+}
+
+static inline guint
+get_condition_indent (IdeCIndenter *c)
+{
+ if (c->condition_indent == -1)
+ return c->indent_width;
+ return c->condition_indent;
+}
+
static inline void
build_indent (IdeCIndenter *c,
guint line_offset,
@@ -630,7 +654,7 @@ c_indenter_indent (IdeCIndenter *c,
*/
if (backward_to_line_first_char (iter))
offset = GET_LINE_OFFSET (iter);
- offset += c->post_scope_indent;
+ offset += get_post_scope_indent (c);
}
build_indent (c, offset, iter, str);
@@ -682,7 +706,7 @@ c_indenter_indent (IdeCIndenter *c,
if (backward_find_matching_char (iter, '}'))
{
offset = GET_LINE_OFFSET (iter);
- offset += c->post_scope_indent;
+ offset += get_post_scope_indent (c);
}
build_indent (c, offset, iter, str);
@@ -703,7 +727,7 @@ c_indenter_indent (IdeCIndenter *c,
backward_find_condition_keyword (iter))
{
guint offset = GET_LINE_OFFSET (iter);
- build_indent (c, offset + c->condition_indent, iter, str);
+ build_indent (c, offset + get_condition_indent (c), iter, str);
IDE_GOTO (cleanup);
}
@@ -725,7 +749,7 @@ c_indenter_indent (IdeCIndenter *c,
backward_to_line_first_char (&match_begin);
offset = GET_LINE_OFFSET (&match_begin);
- build_indent (c, offset + c->pre_scope_indent, iter, str);
+ build_indent (c, offset + get_pre_scope_indent (c), iter, str);
IDE_GOTO (cleanup);
}
@@ -740,7 +764,7 @@ c_indenter_indent (IdeCIndenter *c,
guint offset;
offset = GET_LINE_OFFSET (iter);
- build_indent (c, offset + c->post_scope_indent, iter, str);
+ build_indent (c, offset + get_post_scope_indent (c), iter, str);
IDE_GOTO (cleanup);
}
else
@@ -750,7 +774,7 @@ c_indenter_indent (IdeCIndenter *c,
guint offset;
offset = GET_LINE_OFFSET (iter);
- build_indent (c, offset + c->post_scope_indent, iter, str);
+ build_indent (c, offset + get_post_scope_indent (c), iter, str);
IDE_GOTO (cleanup);
}
}
@@ -838,7 +862,7 @@ maybe_unindent_opening_brace (IdeCIndenter *c,
offset = GET_LINE_OFFSET (©);
str = g_string_new (NULL);
- build_indent (c, offset + c->post_scope_indent + c->pre_scope_indent, ©, str);
+ build_indent (c, offset + get_post_scope_indent(c) + get_pre_scope_indent (c), ©, str);
g_string_append_c (str, '{');
if (ide_source_view_get_insert_matching_brace (IDE_SOURCE_VIEW (view)))
@@ -1430,9 +1454,9 @@ ide_c_indenter_class_finalize (IdeCIndenterClass *klass)
static void
ide_c_indenter_init (IdeCIndenter *self)
{
- self->condition_indent = 2;
- self->pre_scope_indent = 2;
- self->post_scope_indent = 2;
+ self->condition_indent = -1;
+ self->pre_scope_indent = -1;
+ self->post_scope_indent = -1;
self->directive_indent = G_MININT;
self->case_indent = 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]