pass window param to highlighters

This commit is contained in:
Maxime Coste 2013-05-23 13:39:00 +02:00
parent 6c290eff9a
commit 81ce4e4720
3 changed files with 20 additions and 20 deletions

View File

@ -20,14 +20,14 @@ class Window;
// color, adding information text (line numbering for example) or replacing // color, adding information text (line numbering for example) or replacing
// buffer content (folding for example) // buffer content (folding for example)
typedef std::function<void (DisplayBuffer& display_buffer)> HighlighterFunc; typedef std::function<void (const Window& window, DisplayBuffer& display_buffer)> HighlighterFunc;
typedef std::pair<String, HighlighterFunc> HighlighterAndId; typedef std::pair<String, HighlighterFunc> HighlighterAndId;
typedef memoryview<String> HighlighterParameters; typedef memoryview<String> HighlighterParameters;
using HighlighterFactory = std::function<HighlighterAndId (const HighlighterParameters& params, using HighlighterFactory = std::function<HighlighterAndId (const HighlighterParameters& params,
Window& window)>; Window& window)>;
using HighlighterGroup = FunctionGroup<DisplayBuffer&>; using HighlighterGroup = FunctionGroup<const Window&, DisplayBuffer&>;
struct HighlighterRegistry : FunctionRegistry<HighlighterFactory>, struct HighlighterRegistry : FunctionRegistry<HighlighterFactory>,
Singleton<HighlighterRegistry> Singleton<HighlighterRegistry>

View File

@ -71,7 +71,7 @@ public:
{ {
} }
void operator()(DisplayBuffer& display_buffer) void operator()(const Window&, DisplayBuffer& display_buffer)
{ {
update_cache_ifn(display_buffer.range()); update_cache_ifn(display_buffer.range());
for (auto& match : m_cache_matches) for (auto& match : m_cache_matches)
@ -160,7 +160,7 @@ public:
DynamicRegexHighlighter(const ColorSpec& colors, RegexGetter getter) DynamicRegexHighlighter(const ColorSpec& colors, RegexGetter getter)
: m_regex_getter(getter), m_colors(colors), m_colorizer(Regex(), m_colors) {} : m_regex_getter(getter), m_colors(colors), m_colorizer(Regex(), m_colors) {}
void operator()(DisplayBuffer& display_buffer) void operator()(const Window& window, DisplayBuffer& display_buffer)
{ {
Regex regex = m_regex_getter(); Regex regex = m_regex_getter();
if (regex != m_last_regex) if (regex != m_last_regex)
@ -170,7 +170,7 @@ public:
m_colorizer = RegexColorizer{m_last_regex, m_colors}; m_colorizer = RegexColorizer{m_last_regex, m_colors};
} }
if (not m_last_regex.empty()) if (not m_last_regex.empty())
m_colorizer(display_buffer); m_colorizer(window, display_buffer);
} }
private: private:
@ -214,9 +214,9 @@ HighlighterAndId highlight_regex_option_factory(const HighlighterParameters para
return {"hloption_" + option_name, DynamicRegexHighlighter<decltype(get_regex)>{colors, get_regex}}; return {"hloption_" + option_name, DynamicRegexHighlighter<decltype(get_regex)>{colors, get_regex}};
} }
void expand_tabulations(const OptionManager& options, DisplayBuffer& display_buffer) void expand_tabulations(const Window& window, DisplayBuffer& display_buffer)
{ {
const int tabstop = options["tabstop"].get<int>(); const int tabstop = window.options()["tabstop"].get<int>();
for (auto& line : display_buffer.lines()) for (auto& line : display_buffer.lines())
{ {
for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it) for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it)
@ -258,9 +258,9 @@ void expand_tabulations(const OptionManager& options, DisplayBuffer& display_buf
} }
} }
void show_line_numbers(DisplayBuffer& display_buffer) void show_line_numbers(const Window& window, DisplayBuffer& display_buffer)
{ {
LineCount last_line = display_buffer.range().first.buffer().line_count(); LineCount last_line = window.buffer().line_count();
int digit_count = 0; int digit_count = 0;
for (LineCount c = last_line; c > 0; c /= 10) for (LineCount c = last_line; c > 0; c /= 10)
++digit_count; ++digit_count;
@ -301,7 +301,7 @@ void highlight_selections(const Window& window, DisplayBuffer& display_buffer)
} }
} }
void expand_unprintable(DisplayBuffer& display_buffer) void expand_unprintable(const Window&, DisplayBuffer& display_buffer)
{ {
for (auto& line : display_buffer.lines()) for (auto& line : display_buffer.lines())
{ {
@ -345,7 +345,7 @@ public:
update_shared_option_updater(); update_shared_option_updater();
} }
void operator()(DisplayBuffer& display_buffer) void operator()(const Window&, DisplayBuffer& display_buffer)
{ {
update_shared_option_updater(); update_shared_option_updater();
auto& lines = m_window.options()[m_option_name].get<std::vector<LineAndFlag>>(); auto& lines = m_window.options()[m_option_name].get<std::vector<LineAndFlag>>();
@ -451,7 +451,7 @@ HighlighterAndId flag_lines_factory(const HighlighterParameters& params, Window&
return {"hlflags_" + params[1], FlagLines{str_to_color(params[0]), params[1], window}}; return {"hlflags_" + params[1], FlagLines{str_to_color(params[0]), params[1], window}};
} }
template<void (*highlighter_func)(DisplayBuffer&)> template<void (*highlighter_func)(const Window&, DisplayBuffer&)>
class SimpleHighlighterFactory class SimpleHighlighterFactory
{ {
public: public:

View File

@ -13,8 +13,8 @@ namespace Kakoune
// Implementation in highlighters.cc // Implementation in highlighters.cc
void highlight_selections(const Window& window, DisplayBuffer& display_buffer); void highlight_selections(const Window& window, DisplayBuffer& display_buffer);
void expand_tabulations(const OptionManager& options, DisplayBuffer& display_buffer); void expand_tabulations(const Window& window, DisplayBuffer& display_buffer);
void expand_unprintable(DisplayBuffer& display_buffer); void expand_unprintable(const Window& window, DisplayBuffer& display_buffer);
Window::Window(Buffer& buffer) Window::Window(Buffer& buffer)
: Editor(buffer), : Editor(buffer),
@ -25,9 +25,9 @@ Window::Window(Buffer& buffer)
m_hooks.run_hook("WinCreate", buffer.name(), hook_context); m_hooks.run_hook("WinCreate", buffer.name(), hook_context);
m_options.register_watcher(*this); m_options.register_watcher(*this);
m_builtin_highlighters.append({"tabulations", [this](DisplayBuffer& db) { expand_tabulations(m_options, db); }}); m_builtin_highlighters.append({"tabulations", expand_tabulations});
m_builtin_highlighters.append({"unprintable", expand_unprintable}); m_builtin_highlighters.append({"unprintable", expand_unprintable});
m_builtin_highlighters.append({"selections", [this](DisplayBuffer& db) { highlight_selections(*this, db); }}); m_builtin_highlighters.append({"selections", highlight_selections});
for (auto& option : m_options.flatten_options()) for (auto& option : m_options.flatten_options())
on_option_changed(*option); on_option_changed(*option);
@ -80,8 +80,8 @@ void Window::update_display_buffer()
} }
m_display_buffer.compute_range(); m_display_buffer.compute_range();
m_highlighters(m_display_buffer); m_highlighters(*this, m_display_buffer);
m_builtin_highlighters(m_display_buffer); m_builtin_highlighters(*this, m_display_buffer);
m_display_buffer.optimize(); m_display_buffer.optimize();
m_timestamp = buffer().timestamp(); m_timestamp = buffer().timestamp();
@ -134,8 +134,8 @@ void Window::scroll_to_keep_cursor_visible_ifn()
lines.back().push_back(DisplayAtom(AtomContent(line_begin, line_end))); lines.back().push_back(DisplayAtom(AtomContent(line_begin, line_end)));
display_buffer.compute_range(); display_buffer.compute_range();
m_highlighters(display_buffer); m_highlighters(*this, display_buffer);
m_builtin_highlighters(display_buffer); m_builtin_highlighters(*this, display_buffer);
// now we can compute where the cursor is in display columns // now we can compute where the cursor is in display columns
// (this is only valid if highlighting one line and multiple lines put // (this is only valid if highlighting one line and multiple lines put