Skip to content

Commit

Permalink
[rename-col] skip gratuitous rewrites (#2092)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pacien authored Oct 30, 2023
1 parent dd67e97 commit 4329e11
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion visidata/features/rename_col_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def setName(col, newname):
for c in col.sheet.columns:
if isinstance(c, ExprColumn):
parsed_expr = ast.parse(c.expr)
canon_expr = ast.unparse(parsed_expr)
new_expr = ast.unparse(Renamer(col.name, newname).visit(parsed_expr))
if new_expr != parsed_expr:
if new_expr != canon_expr:
vd.addUndo(setattr, c, 'expr', c.expr)
c.expr = new_expr

0 comments on commit 4329e11

Please sign in to comment.