My subconscious complained doing the work by hand, but I have just completed the first draft of a script that removes hanging indents automatically. So I do plan to remove these hangnails for 6.6.2. This project will help clear my mind for what's next.
Edward
P.S. Here is the first draft of the heart of the script:
compound_statement = (
# Leo doesn't use 'match'
'async ', 'class ', 'def ', 'else:', 'elif ', 'except',
'finally:', 'for ', 'if ', 'try:', 'while ', 'with ',
)
pat = re.compile(r'\)\s*->.*:\s*$') # End of multiline def.
def convert(p: Any) -> None:
"""Convert all hanging comments in p.b."""
changed, last_lws, last_s, result = False, '', '', []
for s in p.b.split('\n'):
s1 = last_s.lstrip()
s2 = s.lstrip()
n = len(s) - len(s2)
lws = s[:n]
if (
s1 and s2.startswith('#')
and not pat.match(s1)
and not s1.startswith(('#', '"""', "'''"))
and not s1.endswith(('[', '(', '{'))
and not s1.startswith(compound_statement)
and last_lws < lws
):
changed = True
if len(last_s) + len(s2) < 85: # Emit one line.
result.append(f"{last_s} {s2}")
g.printObj([last_s, s, f"{last_s} {s2}\n"], tag=p.h)
else: # Emit two lines.
result.append(f"{last_lws}{s2}")
result.append(last_s)
g.printObj([last_s, s, f"{last_lws}{s2}", last_s], tag=p.h)
else:
result.append(s)
last_lws = lws
last_s = s
if changed:
g.printObj('\n'.join(result), tag=f"RESULT: {p.h}")
# p.b = '\n'.join(result)
The script is looking good on initial tests. The changed text will be part of Leo 6.6.2.
Edward