[Bf-blender-cvs] [86250c26a30] temp-clang-format: Fix expanding tabs for 2 space indentation.

Campbell Barton noreply at git.blender.org
Fri Feb 1 16:24:57 CET 2019


Commit: 86250c26a30d01c8bf9ba2df03a1310db8a28bc6
Author: Campbell Barton
Date:   Sat Feb 2 02:15:13 2019 +1100
Branches: temp-clang-format
https://developer.blender.org/rB86250c26a30d01c8bf9ba2df03a1310db8a28bc6

Fix expanding tabs for 2 space indentation.

===================================================================

M	clang-format-paths.py

===================================================================

diff --git a/clang-format-paths.py b/clang-format-paths.py
index fb7d7dbe1f5..4157ac3bffe 100755
--- a/clang-format-paths.py
+++ b/clang-format-paths.py
@@ -64,7 +64,23 @@ def convert_tabs_to_spaces(files):
         print("TabExpand", f)
         with open(f, 'r', encoding="utf-8") as fh:
             data = fh.read()
-            data = data.expandtabs(4)
+            if False:
+                # Simple 4 space
+                data = data.expandtabs(4)
+            else:
+                # Complex 2 space
+                # because some comments have tabs for alignment.
+                def handle(l):
+                    ls = l.lstrip("\t")
+                    d = len(l) - len(ls)
+                    if d != 0:
+                        return ("  " * d) + ls.expandtabs(4)
+                    else:
+                        return l.expandtabs(4)
+
+                lines = data.splitlines(keepends=True)
+                lines = [handle(l) for l in lines]
+                data = "".join(lines)
         with open(f, 'w', encoding="utf-8") as fh:
             fh.write(data)



More information about the Bf-blender-cvs mailing list