From 81ce4e472059e482dae54f7479fe9bb1c6144595 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 23 May 2013 13:39:00 +0200 Subject: [PATCH] pass window param to highlighters --- src/highlighter.hh | 4 ++-- src/highlighters.cc | 20 ++++++++++---------- src/window.cc | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/highlighter.hh b/src/highlighter.hh index 7d2249730..dba7fe115 100644 --- a/src/highlighter.hh +++ b/src/highlighter.hh @@ -20,14 +20,14 @@ class Window; // color, adding information text (line numbering for example) or replacing // buffer content (folding for example) -typedef std::function HighlighterFunc; +typedef std::function HighlighterFunc; typedef std::pair HighlighterAndId; typedef memoryview HighlighterParameters; using HighlighterFactory = std::function; -using HighlighterGroup = FunctionGroup; +using HighlighterGroup = FunctionGroup; struct HighlighterRegistry : FunctionRegistry, Singleton diff --git a/src/highlighters.cc b/src/highlighters.cc index 05d740ed7..ea66550df 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -71,7 +71,7 @@ public: { } - void operator()(DisplayBuffer& display_buffer) + void operator()(const Window&, DisplayBuffer& display_buffer) { update_cache_ifn(display_buffer.range()); for (auto& match : m_cache_matches) @@ -160,7 +160,7 @@ public: DynamicRegexHighlighter(const ColorSpec& colors, RegexGetter getter) : 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(); if (regex != m_last_regex) @@ -170,7 +170,7 @@ public: m_colorizer = RegexColorizer{m_last_regex, m_colors}; } if (not m_last_regex.empty()) - m_colorizer(display_buffer); + m_colorizer(window, display_buffer); } private: @@ -214,9 +214,9 @@ HighlighterAndId highlight_regex_option_factory(const HighlighterParameters para return {"hloption_" + option_name, DynamicRegexHighlighter{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(); + const int tabstop = window.options()["tabstop"].get(); for (auto& line : display_buffer.lines()) { 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; for (LineCount c = last_line; c > 0; c /= 10) ++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()) { @@ -345,7 +345,7 @@ public: update_shared_option_updater(); } - void operator()(DisplayBuffer& display_buffer) + void operator()(const Window&, DisplayBuffer& display_buffer) { update_shared_option_updater(); auto& lines = m_window.options()[m_option_name].get>(); @@ -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}}; } -template +template class SimpleHighlighterFactory { public: diff --git a/src/window.cc b/src/window.cc index 91ce2f12d..86f305e16 100644 --- a/src/window.cc +++ b/src/window.cc @@ -13,8 +13,8 @@ namespace Kakoune // Implementation in highlighters.cc void highlight_selections(const Window& window, DisplayBuffer& display_buffer); -void expand_tabulations(const OptionManager& options, DisplayBuffer& display_buffer); -void expand_unprintable(DisplayBuffer& display_buffer); +void expand_tabulations(const Window& window, DisplayBuffer& display_buffer); +void expand_unprintable(const Window& window, DisplayBuffer& display_buffer); Window::Window(Buffer& buffer) : Editor(buffer), @@ -25,9 +25,9 @@ Window::Window(Buffer& buffer) m_hooks.run_hook("WinCreate", buffer.name(), hook_context); 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({"selections", [this](DisplayBuffer& db) { highlight_selections(*this, db); }}); + m_builtin_highlighters.append({"selections", highlight_selections}); for (auto& option : m_options.flatten_options()) on_option_changed(*option); @@ -80,8 +80,8 @@ void Window::update_display_buffer() } m_display_buffer.compute_range(); - m_highlighters(m_display_buffer); - m_builtin_highlighters(m_display_buffer); + m_highlighters(*this, m_display_buffer); + m_builtin_highlighters(*this, m_display_buffer); m_display_buffer.optimize(); 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))); display_buffer.compute_range(); - m_highlighters(display_buffer); - m_builtin_highlighters(display_buffer); + m_highlighters(*this, display_buffer); + m_builtin_highlighters(*this, display_buffer); // now we can compute where the cursor is in display columns // (this is only valid if highlighting one line and multiple lines put