[gnome-builder] python: handle indented function parameter lists in function calls
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] python: handle indented function parameter lists in function calls
- Date: Thu, 8 Jan 2015 11:30:22 +0000 (UTC)
commit 5ee3f537d2a57596a010aac5b671463c51b03c3d
Author: Christian Hergert <christian hergert me>
Date: Thu Jan 8 03:28:23 2015 -0800
python: handle indented function parameter lists in function calls
Still some work to do with generic statements.
src/auto-indent/gb-source-auto-indenter-python.c | 42 ++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/auto-indent/gb-source-auto-indenter-python.c
b/src/auto-indent/gb-source-auto-indenter-python.c
index afe28d8..238c34a 100644
--- a/src/auto-indent/gb-source-auto-indenter-python.c
+++ b/src/auto-indent/gb-source-auto-indenter-python.c
@@ -255,6 +255,45 @@ indent_parens (GbSourceAutoIndenterPython *python,
}
static gchar *
+indent_previous_stmt (GbSourceAutoIndenterPython *python,
+ GtkTextView *text_view,
+ GtkTextIter *begin,
+ GtkTextIter *end,
+ GtkTextIter *iter)
+{
+ gint count = 1;
+
+ if (gtk_text_iter_backward_find_char (iter, find_paren, &count, NULL))
+ {
+ GString *str;
+ guint offset;
+ guint i;
+
+ gtk_text_iter_set_line_offset (iter, 0);
+
+ /*
+ * TODO:
+ *
+ * If the previous line ended in backslash (\), then we need to keep
+ * walking backwards. We also need to handle statements like:
+ */
+
+ while (g_unichar_isspace (gtk_text_iter_get_char (iter)))
+ if (!gtk_text_iter_forward_char (iter))
+ break;
+
+ offset = gtk_text_iter_get_line_offset (iter);
+
+ str = g_string_new (NULL);
+ for (i = 0; i < offset; i++)
+ g_string_append (str, " ");
+ return g_string_free (str, FALSE);
+ }
+
+ return NULL;
+}
+
+static gchar *
gb_source_auto_indenter_python_format (GbSourceAutoIndenter *indenter,
GtkTextView *text_view,
GtkTextBuffer *buffer,
@@ -281,6 +320,9 @@ gb_source_auto_indenter_python_format (GbSourceAutoIndenter *indenter,
case '(':
return indent_colon (python, text_view, begin, end, &iter);
+ case ')':
+ return indent_previous_stmt (python, text_view, begin, end, &iter);
+
case ',':
return indent_parens (python, text_view, begin, end, &iter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]