diff options
author | Brendan Long <self@brendanlong.com> | 2019-02-20 21:05:41 +0300 |
---|---|---|
committer | Brendan Long <self@brendanlong.com> | 2019-02-20 21:12:04 +0300 |
commit | d919c675a3fc221ca289a43476c92f338275c11c (patch) | |
tree | e04c1c055b02909e4e191a3945390a7247d7f71a | |
parent | 33e9ebee64be11fc7f9bbaecaa2ab661f01e0869 (diff) |
Add script to cleanup Vala indentation
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | scripts/fix-indent.py | 21 |
2 files changed, 22 insertions, 0 deletions
@@ -1,6 +1,7 @@ build/ builddir/ _build/ +.mypy_cache .vscode/ *.~ .DS_Store diff --git a/scripts/fix-indent.py b/scripts/fix-indent.py new file mode 100755 index 00000000..10198e57 --- /dev/null +++ b/scripts/fix-indent.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import os +import sys + + +for file_name in sys.argv[1:]: + out_name = os.path.dirname(file_name) + "/new." + \ + os.path.basename(file_name) + with open(file_name, "r") as f, open(out_name, "w") as o: + indent = 0 + for line in f: + line = line.strip() + if line.startswith("}") or line.count(")") > line.count("("): + indent -= 1 + for _ in range(indent): + o.write("\t") + o.write(line) + o.write("\n") + if line.endswith("{") or line.count("(") > line.count(")"): + indent += 1 + os.rename(out_name, file_name) |