summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-10-03 14:30:14 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-10-03 14:30:14 +0000
commit6a0b570e50c532c4bc97eda5f6d7f68e780afd6c (patch)
tree6f2479dc6119676461c87fc5f436ee31e8cfc436 /src
parentd99bcd7f2e097470d4574d0bf30d2c2609c9b77d (diff)
Filters: add a colorize_cplusplus filter and use it by default in Window
Diffstat (limited to 'src')
-rw-r--r--src/filters.cc24
-rw-r--r--src/filters.hh2
-rw-r--r--src/window.cc12
3 files changed, 27 insertions, 11 deletions
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));
}