[gnome-builder] python: copy previous lines indent when applicable



commit d35b722a85bf53bf53d3ef0e2893e01319f4b9ab
Author: Christian Hergert <christian hergert me>
Date:   Thu Jan 8 03:37:41 2015 -0800

    python: copy previous lines indent when applicable

 src/auto-indent/gb-source-auto-indenter-python.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/src/auto-indent/gb-source-auto-indenter-python.c 
b/src/auto-indent/gb-source-auto-indenter-python.c
index 238c34a..09e3fe0 100644
--- a/src/auto-indent/gb-source-auto-indenter-python.c
+++ b/src/auto-indent/gb-source-auto-indenter-python.c
@@ -305,12 +305,19 @@ gb_source_auto_indenter_python_format (GbSourceAutoIndenter *indenter,
   GbSourceAutoIndenterPython *python = (GbSourceAutoIndenterPython *)indenter;
   GtkTextIter iter = *begin;
   gunichar ch;
+  gint line;
+
+  line = gtk_text_iter_get_line (&iter);
 
   /* move to the last character of the last line */
   if (!gtk_text_iter_backward_char (&iter) ||
       !gtk_text_iter_backward_char (&iter))
     return NULL;
 
+  /* if the previous line was empty, don't do any indenting. */
+  if ((line - gtk_text_iter_get_line (&iter)) > 1)
+    return NULL;
+
   /* get the last character */
   ch = gtk_text_iter_get_char (&iter);
 
@@ -327,7 +334,8 @@ gb_source_auto_indenter_python_format (GbSourceAutoIndenter *indenter,
       return indent_parens (python, text_view, begin, end, &iter);
 
     default:
-      if (in_pydoc (&iter))
+      if (in_pydoc (&iter) ||
+          g_unichar_isspace (gtk_text_iter_get_char (&iter)))
         return copy_indent (python, begin, end, &iter);
 
       if (line_starts_with (&iter, "return") ||


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