diff --git a/src/filters.cc b/src/filters.cc index acb546d3..6a7d0113 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -25,4 +25,28 @@ void colorize_regex(DisplayBuffer& display_buffer, } } +void colorize_cplusplus(DisplayBuffer& display_buffer) +{ + static boost::regex preprocessor("(?<=\\n)\\h*#\\h*[^\\n]*(?=\\n)"); + colorize_regex(display_buffer, preprocessor, Color::Magenta); + + static boost::regex strings("\"(\\\\\"|[^\"])*\""); + colorize_regex(display_buffer, strings, Color::Magenta); + + static boost::regex values("\\<(true|false|NULL|nullptr)\\>|-?\\d+[fdiu]?|'[^']*'"); + colorize_regex(display_buffer, values, Color::Red); + + static boost::regex builtin_types("\\<(void|int|float|bool|size_t)\\>"); + colorize_regex(display_buffer, builtin_types, Color::Yellow); + + static boost::regex control_keywords("\\<(while|for|if|else|do|switch|case|default|goto|return|using|try|catch|throw)\\>"); + colorize_regex(display_buffer, control_keywords, Color::Blue); + + static boost::regex types_keywords("\\<(const|auto|namespace|static|volatile|class|struct|enum|union|public|protected|private)\\>"); + colorize_regex(display_buffer, types_keywords, Color::Green); + + static boost::regex comments("//[^\\n]*\\n"); + colorize_regex(display_buffer, comments, Color::Cyan); +} + } diff --git a/src/filters.hh b/src/filters.hh index 2366ac9a..2dc6370c 100644 --- a/src/filters.hh +++ b/src/filters.hh @@ -10,6 +10,8 @@ namespace Kakoune void colorize_regex(DisplayBuffer& display_buffer, const boost::regex& ex, Color color); +void colorize_cplusplus(DisplayBuffer& display_buffer); + } #endif // filters_hh_INCLUDED diff --git a/src/window.cc b/src/window.cc index 82088435..86be7d18 100644 --- a/src/window.cc +++ b/src/window.cc @@ -115,17 +115,7 @@ Window::Window(Buffer& buffer) m_current_inserter(nullptr) { m_selections.push_back(Selection(buffer.begin(), buffer.begin())); - m_filters.push_back(std::bind(colorize_regex, std::placeholders::_1, - boost::regex("\\<(void|int|float|size_t)\\>"), Color::Yellow)); - m_filters.push_back(std::bind(colorize_regex, std::placeholders::_1, - boost::regex("\\<(while|for|if|else|do|switch|case|default|goto|return|using|namespace|try|catch|throw|class|struct|enum|union)\\>"), Color::Blue)); - m_filters.push_back(std::bind(colorize_regex, std::placeholders::_1, - boost::regex("\\<(const|auto|static|volatile)\\>"), Color::Green)); - m_filters.push_back(std::bind(colorize_regex, std::placeholders::_1, - boost::regex("\\<(true|false|NULL|nullptr|\\d+[fdiu]?)\\>"), Color::Red)); - m_filters.push_back(std::bind(colorize_regex, std::placeholders::_1, - boost::regex("//.*$"), Color::Cyan)); - //m_filters.push_back(std::bind(colorize_regex, std::placeholders::_1, boost::regex("^\\h*.\\w+"), Color::Yellow)); + m_filters.push_back(colorize_cplusplus); m_filters.push_back(HighlightSelections(*this)); }