Skip to content
Snippets Groups Projects
Commit e46f8762 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[bad] save this for posterity

parent 213c4ec0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -301,8 +301,12 @@ class NodeList(UserList, GenericNodesUtils):
self.data.insert(-1, self._convert_input_to_node_object(value, parent=parent, on_attribute=on_attribute))
 
def increase_indentation(self, number_of_spaces):
for node in self.filtered():
node.increase_indentation(number_of_spaces)
for endl in self("endl"):
if endl.next and endl.next.type == "endl":
continue
endl.indent += " " * number_of_spaces
# for node in self.filtered():
# node.increase_indentation(number_of_spaces)
 
 
class Node(GenericNodesUtils):
Loading
Loading
@@ -716,14 +720,23 @@ class Node(GenericNodesUtils):
self.replace(result)
 
def increase_indentation(self, number_of_spaces):
if self.indentation_node_is_direct() is False:
return
indentation_node = self.get_indentation_node()
indentation_node.indent += " " * number_of_spaces
print self.type, [self], [indentation_node]
if indentation_node is not None:
indentation_node.indent += " " * number_of_spaces
 
if not isinstance(self.value, NodeList):
return
 
for node in self.value.filtered():
node.increase_indentation(number_of_spaces)
for key in filter(lambda x: "formatting" not in x, self._list_keys):
for node in getattr(self, key).filtered():
node.increase_indentation(number_of_spaces)
for key in self._dict_keys:
getattr(self, key).increase_indentation(number_of_spaces)
 
@property
def index(self):
Loading
Loading
Loading
Loading
@@ -1371,4 +1371,15 @@ def test_indent():
red = RedBaron(test_indent_code)
red.increase_indentation(4)
indented_code = "\n" + "\n".join(map(lambda x: " " + x, test_indent_code.split("\n")[1:-2])) + "\n\n"
print "----"
print red.dumps()
print "----"
print indented_code
print "----"
assert red.dumps() == indented_code
def test_indent_no_previous():
red = RedBaron("a")
red.increase_indentation(4)
assert red.dumps() == "\n a"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment