Skip to content

Commit 4329e11

Browse files
authored
[rename-col] skip gratuitous rewrites (#2092)
Going to and from the AST changes the formatting and pollutes the undo stack even if the expression is logically the same. Now comparing against the canonicalized version to detect worthy changes.
1 parent dd67e97 commit 4329e11

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

visidata/features/rename_col_cascade.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def setName(col, newname):
2323
for c in col.sheet.columns:
2424
if isinstance(c, ExprColumn):
2525
parsed_expr = ast.parse(c.expr)
26+
canon_expr = ast.unparse(parsed_expr)
2627
new_expr = ast.unparse(Renamer(col.name, newname).visit(parsed_expr))
27-
if new_expr != parsed_expr:
28+
if new_expr != canon_expr:
2829
vd.addUndo(setattr, c, 'expr', c.expr)
2930
c.expr = new_expr

0 commit comments

Comments
 (0)