[gnome-builder] indenter-c: Allow multi-line conditions to end a line with ')'
- From: Matthew Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] indenter-c: Allow multi-line conditions to end a line with ')'
- Date: Wed, 6 Jul 2016 02:55:28 +0000 (UTC)
commit c80d3d726937b730da920964d871a427976486f2
Author: Matthew Leeds <mleeds redhat com>
Date: Mon Jul 4 19:36:08 2016 -0400
indenter-c: Allow multi-line conditions to end a line with ')'
Currently the indenter assumes that a condition is complete if one of
its lines ends with a matched ')'. If for some reason you want to end a
line with ')' but not end the condition, the auto indenting would be
wrong. This commit fixes that by checking for an unmatched '(' when a
line ends with ')'.
https://bugzilla.gnome.org/show_bug.cgi?id=768459
plugins/c-pack/ide-c-indenter.c | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)
---
diff --git a/plugins/c-pack/ide-c-indenter.c b/plugins/c-pack/ide-c-indenter.c
index c5231f3..f47b09f 100644
--- a/plugins/c-pack/ide-c-indenter.c
+++ b/plugins/c-pack/ide-c-indenter.c
@@ -516,6 +516,7 @@ c_indenter_indent (IdeCIndenter *c,
{
GtkTextIter cur;
GtkTextIter match_begin;
+ GtkTextIter copy;
gunichar ch;
GString *str;
gchar *ret = NULL;
@@ -637,17 +638,16 @@ c_indenter_indent (IdeCIndenter *c,
}
/*
- * Maybe we are in a conditional.
- *
- * TODO: This technically isn't right since it is perfectly reasonable to
- * end a line on a ) but not be done with the entire conditional.
+ * Maybe we are in a conditional if there's an unmatched (.
*/
- if ((ch != ')') && backward_find_matching_char (iter, ')'))
+ copy = *iter;
+ if (backward_find_matching_char (©, ')') &&
+ ((ch != ')') || ((ch == ')') && backward_find_matching_char (©, ')'))))
{
guint offset;
- offset = GET_LINE_OFFSET (iter);
- build_indent (c, offset + 1, iter, str);
+ offset = GET_LINE_OFFSET (©);
+ build_indent (c, offset + 1, ©, str);
IDE_GOTO (cleanup);
}
@@ -657,8 +657,6 @@ c_indenter_indent (IdeCIndenter *c,
*/
if (ch == '}')
{
- GtkTextIter copy;
-
gtk_text_iter_assign (©, iter);
if (gtk_text_iter_forward_char (iter))
@@ -683,8 +681,6 @@ c_indenter_indent (IdeCIndenter *c,
*/
if (ch == ')')
{
- GtkTextIter copy;
-
gtk_text_iter_assign (©, iter);
if (backward_find_matching_char (iter, ')') &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]