Browse Source

Fixes #133

merge-requests/365/head
eidheim 10 years ago
parent
commit
ea0d65e178
  1. 20
      src/source_clang.cc
  2. 6
      src/terminal.cc

20
src/source_clang.cc

@ -960,6 +960,23 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
auto_indent=[this]() { auto_indent=[this]() {
auto command=Config::get().terminal.clang_format_command; auto command=Config::get().terminal.clang_format_command;
bool use_style_file=false;
auto style_file_search_path=this->file_path.parent_path();
while(true) {
auto style_file=style_file_search_path/"CMakeLists.txt";
if(boost::filesystem::exists(style_file_search_path/".clang-format") || boost::filesystem::exists(style_file_search_path/"_clang-format")) {
use_style_file=true;
break;
}
if(style_file_search_path==style_file_search_path.root_directory())
break;
style_file_search_path=style_file_search_path.parent_path();
}
if(use_style_file)
command+=" -style=file";
else {
unsigned indent_width; unsigned indent_width;
std::string tab_style; std::string tab_style;
if(tab_char=='\t') { if(tab_char=='\t') {
@ -976,10 +993,11 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
if(Config::get().source.clang_format_style!="") if(Config::get().source.clang_format_style!="")
command+=", "+Config::get().source.clang_format_style; command+=", "+Config::get().source.clang_format_style;
command+="}\""; command+="}\"";
}
std::stringstream stdin_stream(get_buffer()->get_text()), stdout_stream; std::stringstream stdin_stream(get_buffer()->get_text()), stdout_stream;
auto exit_status=Terminal::get().process(stdin_stream, stdout_stream, command); auto exit_status=Terminal::get().process(stdin_stream, stdout_stream, command, this->file_path.parent_path());
if(exit_status==0) { if(exit_status==0) {
get_source_buffer()->begin_user_action(); get_source_buffer()->begin_user_action();
auto iter=get_buffer()->get_insert()->get_iter(); auto iter=get_buffer()->get_insert()->get_iter();

6
src/terminal.cc

@ -79,7 +79,7 @@ int Terminal::process(const std::string &command, const boost::filesystem::path
process=std::unique_ptr<Process>(new Process(command, path.string())); process=std::unique_ptr<Process>(new Process(command, path.string()));
if(process->get_id()<=0) { if(process->get_id()<=0) {
async_print("Error: Failed to run command: " + command + "\n", true); async_print("Error: failed to run command: " + command + "\n", true);
return -1; return -1;
} }
@ -101,7 +101,7 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c
}, true); }, true);
if(process.get_id()<=0) { if(process.get_id()<=0) {
async_print("Error: Failed to run command: " + command + "\n", true); async_print("Error: failed to run command: " + command + "\n", true);
return -1; return -1;
} }
@ -132,7 +132,7 @@ void Terminal::async_process(const std::string &command, const boost::filesystem
auto pid=process->get_id(); auto pid=process->get_id();
if (pid<=0) { if (pid<=0) {
processes_mutex.unlock(); processes_mutex.unlock();
async_print("Error: Failed to run command: " + command + "\n", true); async_print("Error: failed to run command: " + command + "\n", true);
if(callback) if(callback)
callback(-1); callback(-1);
return; return;

Loading…
Cancel
Save