diff --git a/Makefile b/Makefile index 3b2ab3b..a0c3109 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ $(BUILD_VIRTUAL_ENV)/bin/beautysh: | $(BUILD_VIRTUAL_ENV) docker-clang-format: docker pull unibeautify/clang-format +$(BUILD_VIRTUAL_ENV)/bin/cmake-format: | $(BUILD_VIRTUAL_ENV) + $|/bin/python -m pip install -q cmake-format==0.6.10 + isort: $(BUILD_VIRTUAL_ENV)/bin/isort $(BUILD_VIRTUAL_ENV)/bin/isort --help @@ -34,7 +37,10 @@ beautysh: $(BUILD_VIRTUAL_ENV)/bin/beautysh clang-format: docker-clang-format docker run --rm -i unibeautify/clang-format "-help" -check: isort yapf beautysh clang-format +cmake-format: $(BUILD_VIRTUAL_ENV)/bin/cmake-format + $(BUILD_VIRTUAL_ENV)/bin/cmake-format --help + +check: isort yapf beautysh clang-format cmake-format clean: rm -rf build diff --git a/plugin/main.vim b/plugin/main.vim index fdb454c..e9e8509 100644 --- a/plugin/main.vim +++ b/plugin/main.vim @@ -36,6 +36,11 @@ let g:VimFormatterCppStyle = { \ "BinPackParameters": "false", \ "AlignAfterOpenBracket": "true" \ } +let g:VimFormatterCMakeStyle = { + \ "enable-sort": "True", + \ "autosort": "True", + \ "max-pargs-hwrap": 2 + \ } function! Main() python main.main() diff --git a/python/cmake_formatter.py b/python/cmake_formatter.py new file mode 100644 index 0000000..1728c9e --- /dev/null +++ b/python/cmake_formatter.py @@ -0,0 +1,17 @@ +import vim +from abstract_formatter import AbstractFormatter + + +class CMakeFormatter(AbstractFormatter): + + def __init__(self): + super(self.__class__, self).__init__() + self._cmake_format = self._getAbsPath(self._getRootDir(), + "build/venv/bin/cmake-format") + + def _getFormatCommand(self, formattedFilename, guideFilname): + style = vim.eval("g:VimFormatterCMakeStyle") + style = map(lambda ele: "--{}={}".format(ele[0], ele[1]), style.items()) + style = " ".join(style) + cmd = "{} {} {}".format(self._cmake_format, style, formattedFilename) + return cmd diff --git a/python/cpp_formatter.py b/python/cpp_formatter.py index 2024309..b4eb2c5 100644 --- a/python/cpp_formatter.py +++ b/python/cpp_formatter.py @@ -1,5 +1,3 @@ -import json - import vim from abstract_formatter import AbstractFormatter diff --git a/python/main.py b/python/main.py index 295f7d3..bb469ac 100644 --- a/python/main.py +++ b/python/main.py @@ -1,5 +1,6 @@ import vim from bash_formatter import BashFormatter +from cmake_formatter import CMakeFormatter from cpp_formatter import CppFormatter from json_formatter import JsonFormatter from python_formatter import PythonFormatter @@ -19,5 +20,7 @@ def main(): PythonFormatter().run() elif name.endswith(".h") or name.endswith(".cpp"): CppFormatter().run() + elif name.endswith("CMakeLists.txt"): + CMakeFormatter().run() else: raise RuntimeError("Unknown filetype.")