[gnome-builder/auto-indent] auto-indent: if last item is a c89 comment, move before it.



commit dc31650e669dc39d484594063c666182692880de
Author: Christian Hergert <christian hergert me>
Date:   Wed Sep 17 16:11:42 2014 -0700

    auto-indent: if last item is a c89 comment, move before it.
    
    This let's us ignore things like /* */ after commas in parameter lists.

 src/editor/gb-source-auto-indenter-c.c |   45 ++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
index 8a4708c..98df401 100644
--- a/src/editor/gb-source-auto-indenter-c.c
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -189,6 +189,39 @@ non_space_predicate (gunichar ch,
   return !g_unichar_isspace (ch);
 }
 
+static void
+backward_before_c89_comment (GtkTextIter *iter)
+{
+  GtkTextIter copy;
+  GtkTextIter match_start;
+  GtkTextIter match_end;
+  gunichar ch;
+
+  gtk_text_iter_assign (&copy, iter);
+
+  while (g_unichar_isspace (gtk_text_iter_get_char (iter)))
+    if (!gtk_text_iter_backward_char (iter))
+      GOTO (cleanup);
+
+  if (!(ch = gtk_text_iter_get_char (iter)) ||
+      (ch != '/') ||
+      !gtk_text_iter_backward_char (iter) ||
+      !(ch = gtk_text_iter_get_char (iter)) ||
+      (ch != '*') ||
+      !gtk_text_iter_backward_search (iter, "/*",
+                                      GTK_TEXT_SEARCH_TEXT_ONLY,
+                                      &match_start, &match_end, NULL) ||
+      !gtk_text_iter_backward_find_char (&match_start, non_space_predicate,
+                                         NULL, NULL))
+    GOTO (cleanup);
+
+  gtk_text_iter_assign (iter, &match_start);
+  return;
+
+cleanup:
+  gtk_text_iter_assign (iter, &copy);
+}
+
 static gboolean
 in_c89_comment (GtkTextIter *iter)
 {
@@ -290,6 +323,18 @@ gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
     }
 
   /*
+   * If the next thing looking backwards is a complete c89 comment, let's
+   * move the iter to before the comment so that we can work with the syntax
+   * that is before it.
+   */
+  backward_before_c89_comment (iter);
+
+  /*
+   * Get our new character as we possibely moved.
+   */
+  ch = gtk_text_iter_get_char (iter);
+
+  /*
    * 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.


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