[gnome-builder/gnome-builder-3-18] python: copy previous line indentation if it was non-zero-width space
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-18] python: copy previous line indentation if it was non-zero-width space
- Date: Tue, 13 Oct 2015 07:36:42 +0000 (UTC)
commit 578ba80d2bce9da69c25e293963e245c51f02258
Author: Christian Hergert <christian hergert me>
Date: Sat Oct 3 18:34:27 2015 -0700
python: copy previous line indentation if it was non-zero-width space
Just a precaution to avoid annoying users with what we think the current
ranking indentation should be.
plugins/python-pack/python_indenter.py | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/plugins/python-pack/python_indenter.py b/plugins/python-pack/python_indenter.py
index 94386cd..648d0b1 100644
--- a/plugins/python-pack/python_indenter.py
+++ b/plugins/python-pack/python_indenter.py
@@ -480,6 +480,11 @@ class PythonIndenter(GObject.Object): #, Ide.Indenter):
nearest = discoveries.nearest
+ # If the previous line is non-zero-width whitespace, we should
+ # just copy that line instead of annoying the user.
+ if line_is_space(begin):
+ return self.copy_indent(view, iter)
+
# If we are in a comment, continue the comment on the new line,
# possibly adding the prefixing "# ".
if nearest.rank == Rank.COMMENT:
@@ -567,6 +572,16 @@ def copy_line(iter):
end.forward_to_line_end()
return begin.get_slice(end)
+def line_is_space(iter):
+ iter = iter.copy()
+ iter.set_line_offset(0)
+ while not iter.ends_line():
+ if iter.get_char().isspace():
+ iter.forward_char()
+ continue
+ return False
+ return iter.get_line_offset() != 0
+
def forward_to_nonspace(iter):
"""
Moves forward but stays on the same line.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]