Filters: add a colorize_cplusplus filter and use it by default in Window

This commit is contained in:
Maxime Coste 2011-10-03 14:30:14 +00:00
parent d99bcd7f2e
commit 6a0b570e50
3 changed files with 27 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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));
}