[gnome-builder] indenter-c: Allow multi-line conditions to end a line with ')'



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 (&copy, ')') &&
+     ((ch != ')') || ((ch == ')') && backward_find_matching_char (&copy, ')'))))
     {
       guint offset;
 
-      offset = GET_LINE_OFFSET (iter);
-      build_indent (c, offset + 1, iter, str);
+      offset = GET_LINE_OFFSET (&copy);
+      build_indent (c, offset + 1, &copy, str);
       IDE_GOTO (cleanup);
     }
 
@@ -657,8 +657,6 @@ c_indenter_indent (IdeCIndenter  *c,
    */
   if (ch == '}')
     {
-      GtkTextIter copy;
-
       gtk_text_iter_assign (&copy, 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 (&copy, iter);
 
       if (backward_find_matching_char (iter, ')') &&


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]