[gnome-builder/auto-indent] editor: more indentation work.



commit 6f1eb31e74dc495e025f9b5d46d329b42e8e4beb
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 16 18:07:09 2014 -0700

    editor: more indentation work.

 src/editor/gb-source-auto-indenter-c.c |   47 +++++++++++++++++++------------
 1 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
index c93fda7..b7adb4b 100644
--- a/src/editor/gb-source-auto-indenter-c.c
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -73,7 +73,8 @@ build_indent (GbSourceAutoIndenterC *c,
       break;
     }
   } while (gtk_text_iter_forward_char (&iter) &&
-           gtk_text_iter_compare (&iter, matching_line) <= 0);
+           (gtk_text_iter_compare (&iter, matching_line) <= 0) &&
+           (str->len < line_offset));
 
   while (str->len < line_offset)
     g_string_append_c (str, ' ');
@@ -197,22 +198,6 @@ gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
   ch = gtk_text_iter_get_char (iter);
 
   /*
-   * We just started a new scope. Try to find the indentation of the previous
-   * scope and our indentation past it.
-   */
-  if (ch == '{')
-    {
-      if (line_is_space (iter))
-        {
-          guint offset;
-
-          offset = gtk_text_iter_get_line_offset (iter);
-          build_indent (c, offset + priv->scope_indent, iter, str);
-          GOTO (cleanup);
-        }
-    }
-
-  /*
    * If we just placed a terminating parenthesis, we need to work our way back
    * to it's match. That way we can peak at what it was and determine
    * indentation from that.
@@ -230,10 +215,13 @@ gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
    */
   if (ch == ',')
     {
+      guint offset;
+
       if (!backward_find_matching_char (iter, ')'))
         GOTO (cleanup);
 
-      build_indent (c, gtk_text_iter_get_line_offset (iter), iter, str);
+      offset = gtk_text_iter_get_line_offset (iter);
+      build_indent (c, offset + 1, iter, str);
       GOTO (cleanup);
     }
 
@@ -259,6 +247,29 @@ gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
       GOTO (cleanup);
     }
 
+  /*
+   * Work our way back to the most recent scope. Then apply our scope
+   * indentation to that.
+   */
+  if (ch == '{' || backward_find_matching_char (iter, '}'))
+    {
+      if (line_is_space (iter))
+        {
+          guint offset;
+
+          offset = gtk_text_iter_get_line_offset (iter);
+          build_indent (c, offset + priv->scope_indent, iter, str);
+          GOTO (cleanup);
+        }
+      else
+        {
+          /*
+           * XXX: We need to determine where the beginning of a prefixed
+           *      condition is.
+           */
+        }
+    }
+
 cleanup:
   gtk_text_iter_assign (iter, &cur);
 


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