From 4329e113e545c9aa749d883f76fbe464cf053e59 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 30 Oct 2023 03:54:26 +0100 Subject: [PATCH] [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. --- visidata/features/rename_col_cascade.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/visidata/features/rename_col_cascade.py b/visidata/features/rename_col_cascade.py index f6c43b05f..bab43e932 100644 --- a/visidata/features/rename_col_cascade.py +++ b/visidata/features/rename_col_cascade.py @@ -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