From 3155e7777c20d938c484ba3e60ce06adc8b092bf Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 21 Aug 2026 15:08:39 +0200 Subject: [PATCH] chores: implement same way as vscode macro --- misc/spaces_to_tabs.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/misc/spaces_to_tabs.py b/misc/spaces_to_tabs.py index 7db3456f7..591d13190 100644 --- a/misc/spaces_to_tabs.py +++ b/misc/spaces_to_tabs.py @@ -14,18 +14,18 @@ for filename in sys.argv[1:]: except UnicodeDecodeError: continue - # Determine whether this file uses tabs for indentation. - uses_tabs = any( - re.match(r"^\t+", line) - for line in text.splitlines() - ) - - if not uses_tabs: + # Only modify files that already use tabs for indentation. + if not re.search(r"(?m)^\t+", text): continue + def convert(match): + tabs = match.group(1) + spaces = match.group(2) + return tabs + "\t" * (len(spaces) // 4) + spaces[len(spaces) // 4 * 4:] + new_text = re.sub( - r"^(?: {4})+", - lambda m: "\t" * (len(m.group()) // 4), + r"^(\t*)( +)", + convert, text, flags=re.MULTILINE, )