From 407e0fd967f11ad12ce330bf410ebae803c640ca Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 24 Oct 2015 10:51:16 +0200 Subject: [PATCH] Can now use tabs with auto-indentation in clang-files. --- src/files.h | 2 +- src/source_clang.cc | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/files.h b/src/files.h index 2e9389b..6a7947e 100644 --- a/src/files.h +++ b/src/files.h @@ -49,7 +49,7 @@ const std::string configjson = " \"702\": \"def:statement\",\n" " \"705\": \"def:comment\"\n" " },\n" -" \"clang_format_style\": \"UseTab: Never, ColumnLimit: 0\" //See http://clang.llvm.org/docs/ClangFormatStyleOptions.html\n" +" \"clang_format_style\": \"ColumnLimit: 0\" //IndentWidth and UseTab is set automatically. See http://clang.llvm.org/docs/ClangFormatStyleOptions.html\n" " },\n" " \"keybindings\": {\n" " \"new_file\": \"n\",\n" diff --git a/src/source_clang.cc b/src/source_clang.cc index 3cf76f5..06b9532 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -926,7 +926,19 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { auto_indent=[this]() { std::string command="clang-format"; - command+=" -style=\"{IndentWidth: "+std::to_string(tab_size); + unsigned indent_width; + std::string tab_style; + if(tab_char=='\t') { + indent_width=tab_size*8; + tab_style="UseTab: Always"; + } + else { + indent_width=tab_size; + tab_style="UseTab: Never"; + } + command+=" -style=\"{IndentWidth: "+std::to_string(indent_width); + if(tab_style.size()>0) + command+=", "+tab_style; if(Singleton::Config::source()->clang_format_style!="") command+=", "+Singleton::Config::source()->clang_format_style; command+="}\""; @@ -957,7 +969,6 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); } get_source_buffer()->end_user_action(); - set_tab_char_and_size(' ', tab_size); //clang-format only does basic indentation with spaces as I understand it } };