[gnome-builder] python: auto indent 2 levels for multi-line parameter list
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] python: auto indent 2 levels for multi-line parameter list
- Date: Thu, 8 Jan 2015 22:03:05 +0000 (UTC)
commit 5e615cb76f714341d86fc02aa91d73cc5ada60c9
Author: Christian Hergert <christian hergert me>
Date: Thu Jan 8 14:02:56 2015 -0800
python: auto indent 2 levels for multi-line parameter list
This only affects parameter lists where the first parameter is not on the
same line as the function definition. Such as:
def foo(
param1,
param2):
pass
src/auto-indent/gb-source-auto-indenter-python.c | 22 ++++++++++++++++++++++
1 files changed, 22 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 5dde210..fc47060 100644
--- a/src/auto-indent/gb-source-auto-indenter-python.c
+++ b/src/auto-indent/gb-source-auto-indenter-python.c
@@ -159,6 +159,7 @@ indent_colon (GbSourceAutoIndenterPython *python,
GtkTextIter *iter)
{
GString *str;
+ gboolean is_colon;
guint tab_width = 4;
guint offset;
guint i;
@@ -167,6 +168,8 @@ indent_colon (GbSourceAutoIndenterPython *python,
* TODO: Assign tab width from source view.
*/
+ is_colon = gtk_text_iter_get_char (iter) == ':';
+
/*
* Work our way back to the first character of the first line. Jumping past
* strings and parens.
@@ -222,6 +225,25 @@ indent_colon (GbSourceAutoIndenterPython *python,
offset = gtk_text_iter_get_line_offset (iter);
+ /*
+ * If we are actually still in the parameter list, possibly indent more.
+ * I don't like that this code is here, it really belongs somewhere else.
+ */
+ if (!is_colon) {
+ GtkTextIter copy = *iter;
+
+ if (gtk_text_iter_forward_chars (©, 4))
+ {
+ gchar *slice;
+
+ slice = gtk_text_iter_get_slice (iter, ©);
+ g_print ("SLICE: %s\n", slice);
+ if (g_strcmp0 (slice, "def ") == 0)
+ offset += tab_width;
+ g_free (slice);
+ }
+ }
+
str = g_string_new (NULL);
for (i = 0; i < (offset + tab_width); i++)
g_string_append (str, " ");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]