[gnome-builder] python: be mindful of parenthesis upon newline indent
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] python: be mindful of parenthesis upon newline indent
- Date: Thu, 8 Jan 2015 01:18:00 +0000 (UTC)
commit fb49238f6e64845ed1b22894fbb1ce4058ec69f4
Author: Christian Hergert <christian hergert me>
Date: Wed Jan 7 17:17:54 2015 -0800
python: be mindful of parenthesis upon newline indent
src/auto-indent/gb-source-auto-indenter-python.c | 52 ++++++++++++++++++++++
1 files changed, 52 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 e5b4a85..a3c5bf9 100644
--- a/src/auto-indent/gb-source-auto-indenter-python.c
+++ b/src/auto-indent/gb-source-auto-indenter-python.c
@@ -164,6 +164,55 @@ indent_colon (GbSourceAutoIndenterPython *python,
return g_string_free (str, FALSE);
}
+static gboolean
+find_paren (gunichar ch,
+ gpointer state)
+{
+ gint *count = state;
+
+ switch (ch)
+ {
+ case '(':
+ (*count)--;
+ break;
+
+ case ')':
+ (*count)++;
+ break;
+
+ default:
+ break;
+ }
+
+ return (*count) == 0;
+}
+
+static gchar *
+indent_parens (GbSourceAutoIndenterPython *python,
+ GtkTextView *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;
+ gint i;
+
+ 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,
@@ -190,6 +239,9 @@ gb_source_auto_indenter_python_format (GbSourceAutoIndenter *indenter,
case ':':
return indent_colon (python, text_view, begin, end, &iter);
+ case ',':
+ return indent_parens (python, text_view, begin, end, &iter);
+
default:
if (in_pydoc (&iter))
return copy_indent (python, begin, end, &iter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]