Skip to content

Commit

Permalink
Added :CCError to show the last error
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Oct 12, 2014
1 parent 98549b4 commit 185cf9d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
12 changes: 10 additions & 2 deletions include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ namespace color_coded
return dir.string();
}

static std::string const& last_error(std::string const &e = "")
{
static std::string error;
if(e.size())
{ error = e; }
return error;
}

static auto& queue()
{
static async::queue<async::task, async::result> q
Expand All @@ -59,12 +67,12 @@ namespace color_coded
{
/* TODO: We shouldn't just blindly log every error, but this
* will be helpful for meow. */
ruby::vim::message(e.what());
last_error(e.what());
return async::result{{}, {}};
}
catch(...)
{
ruby::vim::message("unknown compilation error");
last_error("unknown compilation error");
return async::result{{}, {}};
}
}
Expand Down
5 changes: 3 additions & 2 deletions include/detail/safe_func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <utility>
#include <stdexcept>

#include "core.hpp"
#include "ruby/vim.hpp"

namespace color_coded
Expand All @@ -22,12 +23,12 @@ namespace color_coded
{ return F(std::forward<Args_>(args)...); }
catch(std::exception const &e)
{
ruby::vim::message(std::string{"exception: "} + e.what());
core::last_error(std::string{"exception: "} + e.what());
std::exit(1);
}
catch(...)
{
ruby::vim::message("unknown error");
core::last_error("unknown error");
std::exit(1);
}
};
Expand Down
7 changes: 0 additions & 7 deletions include/ruby/vim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ namespace color_coded
+ std::to_string(len)
+ "]], -1)\")");
}

inline void message(std::string str)
{
std::transform(std::begin(str), std::end(str), std::begin(str),
[](char const c){ return c == '"' ? '\'' : c; });
eval("VIM::message(\"" + str + "\")");
}
}
}
}
11 changes: 11 additions & 0 deletions plugin/color_coded.vim
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ EOF
unlet s:file
endfunction!

function! s:color_coded_last_error()
if index(g:color_coded_filetypes, &ft) < 0
return
endif
ruby << EOF
VIM::command("echo \"" + color_coded_last_error().gsub("\"", "'") + "\"")
EOF
endfunction!

command! CCError call s:color_coded_last_error()

let $VIMHOME=expand('<sfile>:p:h:h')
augroup color_coded
au VimEnter,ColorScheme * source $VIMHOME/after/syntax/color_coded.vim
Expand Down
8 changes: 7 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <fstream>
#include <iostream>

#include "core.hpp"
#include "detail/safe_func.hpp"

namespace color_coded
Expand Down Expand Up @@ -53,6 +52,9 @@ namespace color_coded

static void destroy(std::string const &file)
{ core::buffers().erase(file); }

static std::string last_error()
{ return core::last_error(); }
}

extern "C" void Init_color_coded()
Expand All @@ -77,4 +79,8 @@ extern "C" void Init_color_coded()
(color_coded::safe_func<decltype(&color_coded::destroy),
&color_coded::destroy>(),
"color_coded_destroy"));
script::registrar::add(script::func
(color_coded::safe_func<decltype(&color_coded::last_error),
&color_coded::last_error>(),
"color_coded_last_error"));
}

0 comments on commit 185cf9d

Please sign in to comment.