@@ -55,7 +55,7 @@ def parse(s, path='<string>'):
55
55
def strip_blanks (tree ):
56
56
return File ([x for x in tree if not isinstance (x , BlankLine )])
57
57
58
- def compose_lines (tree ):
58
+ def compose_lines (tree , max_width = 79 ):
59
59
"""
60
60
Yields pretty-printed lines of a CMakeLists file.
61
61
"""
@@ -72,14 +72,23 @@ def compose_lines(tree):
72
72
level -= 1
73
73
for i , line in enumerate (command_to_lines (item )):
74
74
offset = 1 if i > 0 else 0
75
- yield (level + offset ) * tab + line
75
+ line2 = (level + offset ) * tab + line
76
+ if len (line2 ) <= max_width :
77
+ yield line2
78
+ else :
79
+ command_to_lines
80
+ # Line is too long. Try again.
81
+ for _ , (ty , contents ) in tokenize (line ):
82
+ yield (level + offset ) * tab + contents
83
+
76
84
if name in ('function' , 'macro' , 'if' , 'else' ):
77
85
level += 1
78
86
79
- def command_to_lines (cmd ):
87
+ # FIXME: Make this split into more lines if the result would be too wide.
88
+ def command_to_lines (cmd , sep ):
80
89
final_paren = ')' if cmd .body and cmd .body [- 1 ].comments else ')'
81
90
comment_part = ' ' + cmd .comment if cmd .comment else ''
82
- result = cmd .name + '(' + ' ' .join (map (arg_to_str , cmd .body )) + final_paren + comment_part
91
+ result = cmd .name + '(' + sep .join (map (arg_to_str , cmd .body )) + final_paren + comment_part
83
92
return [l .strip () for l in result .splitlines ()]
84
93
85
94
def arg_to_str (arg ):
0 commit comments