diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-11-29 22:37:20 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-11-29 22:37:20 +0000 |
| commit | 0859b20bcfd47d28fbd1e4b5e1aa6873f7bf617f (patch) | |
| tree | e1fade2a05d93439c5aa45644731125c12e577bb /src | |
| parent | e89516f2a30f215aa735be685d7082c734d933e6 (diff) | |
Rename Filter to Highlighter to be more explicit
Diffstat (limited to 'src')
| -rw-r--r-- | src/filter.hh | 16 | ||||
| -rw-r--r-- | src/filter_registry.cc | 45 | ||||
| -rw-r--r-- | src/filter_registry.hh | 40 | ||||
| -rw-r--r-- | src/filters.hh | 11 | ||||
| -rw-r--r-- | src/highlighter.hh | 16 | ||||
| -rw-r--r-- | src/highlighter_registry.cc | 45 | ||||
| -rw-r--r-- | src/highlighter_registry.hh | 40 | ||||
| -rw-r--r-- | src/highlighters.cc (renamed from src/filters.cc) | 38 | ||||
| -rw-r--r-- | src/highlighters.hh | 11 | ||||
| -rw-r--r-- | src/kakrc | 2 | ||||
| -rw-r--r-- | src/main.cc | 38 | ||||
| -rw-r--r-- | src/window.cc | 36 | ||||
| -rw-r--r-- | src/window.hh | 20 |
13 files changed, 179 insertions, 179 deletions
diff --git a/src/filter.hh b/src/filter.hh deleted file mode 100644 index 3efa664e..00000000 --- a/src/filter.hh +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef filter_hh_INCLUDED -#define filter_hh_INCLUDED - -#include <functional> - -namespace Kakoune -{ - -class DisplayBuffer; - -typedef std::function<void (DisplayBuffer& display_buffer)> FilterFunc; -typedef std::pair<std::string, FilterFunc> FilterAndId; - -} - -#endif // filter_hh_INCLUDED diff --git a/src/filter_registry.cc b/src/filter_registry.cc deleted file mode 100644 index a4f1d817..00000000 --- a/src/filter_registry.cc +++ /dev/null @@ -1,45 +0,0 @@ -#include "filter_registry.hh" - -#include "exception.hh" -#include "window.hh" - -namespace Kakoune -{ - -struct factory_not_found : public runtime_error -{ - factory_not_found() : runtime_error("factory not found") {} -}; - -void FilterRegistry::register_factory(const std::string& name, - const FilterFactory& factory) -{ - assert(m_factories.find(name) == m_factories.end()); - m_factories[name] = factory; -} - -void FilterRegistry::add_filter_to_window(Window& window, - const std::string& name, - const FilterParameters& parameters) -{ - auto it = m_factories.find(name); - if (it == m_factories.end()) - throw factory_not_found(); - - window.add_filter(it->second(window, parameters)); -} - -CandidateList FilterRegistry::complete_filter(const std::string& prefix, - size_t cursor_pos) -{ - std::string real_prefix = prefix.substr(0, cursor_pos); - CandidateList result; - for (auto& filter : m_factories) - { - if (filter.first.substr(0, real_prefix.length()) == real_prefix) - result.push_back(filter.first); - } - return result; -} - -} diff --git a/src/filter_registry.hh b/src/filter_registry.hh deleted file mode 100644 index 572e30af..00000000 --- a/src/filter_registry.hh +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef filter_registry_h_INCLUDED -#define filter_registry_h_INCLUDED - -#include <string> -#include <unordered_map> - -#include "filter.hh" -#include "utils.hh" -#include "completion.hh" - -namespace Kakoune -{ - -class Window; - -typedef std::vector<std::string> FilterParameters; - -typedef std::function<FilterAndId (Window& window, - const FilterParameters& params)> FilterFactory; - -class FilterRegistry : public Singleton<FilterRegistry> -{ -public: - void register_factory(const std::string& name, - const FilterFactory& factory); - - void add_filter_to_window(Window& window, - const std::string& factory_name, - const FilterParameters& parameters); - - CandidateList complete_filter(const std::string& prefix, - size_t cursor_pos); - -private: - std::unordered_map<std::string, FilterFactory> m_factories; -}; - -} - -#endif // filter_registry_h_INCLUDED diff --git a/src/filters.hh b/src/filters.hh deleted file mode 100644 index 0d88da46..00000000 --- a/src/filters.hh +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef filters_hh_INCLUDED -#define filters_hh_INCLUDED - -namespace Kakoune -{ - -void register_filters(); - -} - -#endif // filters_hh_INCLUDED diff --git a/src/highlighter.hh b/src/highlighter.hh new file mode 100644 index 00000000..3000dd27 --- /dev/null +++ b/src/highlighter.hh @@ -0,0 +1,16 @@ +#ifndef highlighter_hh_INCLUDED +#define highlighter_hh_INCLUDED + +#include <functional> + +namespace Kakoune +{ + +class DisplayBuffer; + +typedef std::function<void (DisplayBuffer& display_buffer)> HighlighterFunc; +typedef std::pair<std::string, HighlighterFunc> HighlighterAndId; + +} + +#endif // highlighter_hh_INCLUDED diff --git a/src/highlighter_registry.cc b/src/highlighter_registry.cc new file mode 100644 index 00000000..fdf8d15f --- /dev/null +++ b/src/highlighter_registry.cc @@ -0,0 +1,45 @@ +#include "highlighter_registry.hh" + +#include "exception.hh" +#include "window.hh" + +namespace Kakoune +{ + +struct factory_not_found : public runtime_error +{ + factory_not_found() : runtime_error("factory not found") {} +}; + +void HighlighterRegistry::register_factory(const std::string& name, + const HighlighterFactory& factory) +{ + assert(m_factories.find(name) == m_factories.end()); + m_factories[name] = factory; +} + +void HighlighterRegistry::add_highlighter_to_window(Window& window, + const std::string& name, + const HighlighterParameters& parameters) +{ + auto it = m_factories.find(name); + if (it == m_factories.end()) + throw factory_not_found(); + + window.add_highlighter(it->second(window, parameters)); +} + +CandidateList HighlighterRegistry::complete_highlighter(const std::string& prefix, + size_t cursor_pos) +{ + std::string real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + for (auto& highlighter : m_factories) + { + if (highlighter.first.substr(0, real_prefix.length()) == real_prefix) + result.push_back(highlighter.first); + } + return result; +} + +} diff --git a/src/highlighter_registry.hh b/src/highlighter_registry.hh new file mode 100644 index 00000000..19a285ea --- /dev/null +++ b/src/highlighter_registry.hh @@ -0,0 +1,40 @@ +#ifndef highlighter_registry_h_INCLUDED +#define highlighter_registry_h_INCLUDED + +#include <string> +#include <unordered_map> + +#include "highlighter.hh" +#include "utils.hh" +#include "completion.hh" + +namespace Kakoune +{ + +class Window; + +typedef std::vector<std::string> HighlighterParameters; + +typedef std::function<HighlighterAndId (Window& window, + const HighlighterParameters& params)> HighlighterFactory; + +class HighlighterRegistry : public Singleton<HighlighterRegistry> +{ +public: + void register_factory(const std::string& name, + const HighlighterFactory& factory); + + void add_highlighter_to_window(Window& window, + const std::string& factory_name, + const HighlighterParameters& parameters); + + CandidateList complete_highlighter(const std::string& prefix, + size_t cursor_pos); + +private: + std::unordered_map<std::string, HighlighterFactory> m_factories; +}; + +} + +#endif // highlighter_registry_h_INCLUDED diff --git a/src/filters.cc b/src/highlighters.cc index 668a582a..7c4d9bb0 100644 --- a/src/filters.cc +++ b/src/highlighters.cc @@ -1,9 +1,9 @@ -#include "filters.hh" +#include "highlighters.hh" #include "assert.hh" #include "window.hh" #include "display_buffer.hh" -#include "filter_registry.hh" +#include "highlighter_registry.hh" #include <boost/regex.hpp> namespace Kakoune @@ -80,8 +80,8 @@ Color parse_color(const std::string& color) return Color::Default; } -FilterAndId colorize_regex_factory(Window& window, - const FilterParameters params) +HighlighterAndId colorize_regex_factory(Window& window, + const HighlighterParameters params) { if (params.size() != 3) throw runtime_error("wrong parameter count"); @@ -93,7 +93,7 @@ FilterAndId colorize_regex_factory(Window& window, std::string id = "colre'" + params[0] + "'"; - return FilterAndId(id, std::bind(colorize_regex, std::placeholders::_1, + return HighlighterAndId(id, std::bind(colorize_regex, std::placeholders::_1, ex, fg_color, bg_color)); } @@ -194,16 +194,16 @@ void show_line_numbers(DisplayBuffer& display_buffer) } } -template<void (*filter_func)(DisplayBuffer&)> -class SimpleFilterFactory +template<void (*highlighter_func)(DisplayBuffer&)> +class SimpleHighlighterFactory { public: - SimpleFilterFactory(const std::string& id) : m_id(id) {} + SimpleHighlighterFactory(const std::string& id) : m_id(id) {} - FilterAndId operator()(Window& window, - const FilterParameters& params) const + HighlighterAndId operator()(Window& window, + const HighlighterParameters& params) const { - return FilterAndId(m_id, FilterFunc(filter_func)); + return HighlighterAndId(m_id, HighlighterFunc(highlighter_func)); } private: std::string m_id; @@ -280,10 +280,10 @@ public: } - static FilterAndId create(Window& window, - const FilterParameters& params) + static HighlighterAndId create(Window& window, + const HighlighterParameters& params) { - return FilterAndId("highlight_selections", + return HighlighterAndId("highlight_selections", SelectionsHighlighter(window)); } @@ -291,14 +291,14 @@ private: const Window& m_window; }; -void register_filters() +void register_highlighters() { - FilterRegistry& registry = FilterRegistry::instance(); + HighlighterRegistry& registry = HighlighterRegistry::instance(); registry.register_factory("highlight_selections", SelectionsHighlighter::create); - registry.register_factory("expand_tabs", SimpleFilterFactory<expand_tabulations>("expand_tabs")); - registry.register_factory("number_lines", SimpleFilterFactory<show_line_numbers>("number_lines")); - registry.register_factory("hlcpp", SimpleFilterFactory<colorize_cplusplus>("hlcpp")); + registry.register_factory("expand_tabs", SimpleHighlighterFactory<expand_tabulations>("expand_tabs")); + registry.register_factory("number_lines", SimpleHighlighterFactory<show_line_numbers>("number_lines")); + registry.register_factory("hlcpp", SimpleHighlighterFactory<colorize_cplusplus>("hlcpp")); registry.register_factory("regex", colorize_regex_factory); } diff --git a/src/highlighters.hh b/src/highlighters.hh new file mode 100644 index 00000000..53738e94 --- /dev/null +++ b/src/highlighters.hh @@ -0,0 +1,11 @@ +#ifndef highlighters_hh_INCLUDED +#define highlighters_hh_INCLUDED + +namespace Kakoune +{ + +void register_highlighters(); + +} + +#endif // highlighters_hh_INCLUDED @@ -1,2 +1,2 @@ -hook WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) addfilter hlcpp +hook WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) addhl hlcpp diff --git a/src/main.cc b/src/main.cc index 2b1ca02e..bd1775fb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,8 +7,8 @@ #include "selectors.hh" #include "assert.hh" #include "debug.hh" -#include "filters.hh" -#include "filter_registry.hh" +#include "highlighters.hh" +#include "highlighter_registry.hh" #include "hooks_manager.hh" #include <unordered_map> @@ -433,17 +433,17 @@ void show_buffer(const CommandParameters& params, const Context& context) main_context = Context(*buffer->get_or_create_window()); } -void add_filter(const CommandParameters& params, const Context& context) +void add_highlighter(const CommandParameters& params, const Context& context) { if (params.size() < 1) throw wrong_argument_count(); try { - FilterRegistry& registry = FilterRegistry::instance(); - FilterParameters filter_params(params.begin()+1, params.end()); - registry.add_filter_to_window(*context.window, params[0], - filter_params); + HighlighterRegistry& registry = HighlighterRegistry::instance(); + HighlighterParameters highlighter_params(params.begin()+1, params.end()); + registry.add_highlighter_to_window(*context.window, params[0], + highlighter_params); } catch (runtime_error& err) { @@ -451,12 +451,12 @@ void add_filter(const CommandParameters& params, const Context& context) } } -void rm_filter(const CommandParameters& params, const Context& context) +void rm_highlighter(const CommandParameters& params, const Context& context) { if (params.size() != 1) throw wrong_argument_count(); - context.window->remove_filter(params[0]); + context.window->remove_highlighter(params[0]); } void add_hook(const CommandParameters& params, const Context& context) @@ -679,11 +679,11 @@ int main(int argc, char* argv[]) { init_ncurses(); - CommandManager command_manager; - BufferManager buffer_manager; - RegisterManager register_manager; - FilterRegistry filter_registry; - HooksManager hooks_manager; + CommandManager command_manager; + BufferManager buffer_manager; + RegisterManager register_manager; + HighlighterRegistry highlighter_registry; + HooksManager hooks_manager; command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit, PerArgumentCommandCompleter{ complete_filename }); @@ -697,21 +697,21 @@ int main(int argc, char* argv[]) PerArgumentCommandCompleter { std::bind(&BufferManager::complete_buffername, &buffer_manager, _1, _2) }); - command_manager.register_command(std::vector<std::string>{ "af", "addfilter" }, add_filter, + command_manager.register_command(std::vector<std::string>{ "ah", "addhl" }, add_highlighter, PerArgumentCommandCompleter { - std::bind(&FilterRegistry::complete_filter, &filter_registry, _1, _2) + std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2) }); - command_manager.register_command(std::vector<std::string>{ "rf", "rmfilter" }, rm_filter, + command_manager.register_command(std::vector<std::string>{ "rh", "rmhl" }, rm_highlighter, PerArgumentCommandCompleter { [&](const std::string& prefix, size_t cursor_pos) - { return main_context.window->complete_filterid(prefix, cursor_pos); } + { return main_context.window->complete_highlighterid(prefix, cursor_pos); } }); command_manager.register_command(std::vector<std::string>{ "hook" }, add_hook); command_manager.register_command(std::vector<std::string>{ "source" }, exec_commands_in_file, PerArgumentCommandCompleter{ complete_filename }); - register_filters(); + register_highlighters(); try { diff --git a/src/window.cc b/src/window.cc index 69a91d97..02625fc5 100644 --- a/src/window.cc +++ b/src/window.cc @@ -1,7 +1,7 @@ #include "window.hh" #include "assert.hh" -#include "filter_registry.hh" +#include "highlighter_registry.hh" #include "hooks_manager.hh" #include <algorithm> @@ -54,13 +54,13 @@ Window::Window(Buffer& buffer) { m_selections.push_back(Selection(buffer.begin(), buffer.begin())); - FilterRegistry& registry = FilterRegistry::instance(); + HighlighterRegistry& registry = HighlighterRegistry::instance(); HooksManager::instance().run_hook("WinCreate", buffer.name(), Context(*this)); - registry.add_filter_to_window(*this, "expand_tabs", FilterParameters()); - registry.add_filter_to_window(*this, "highlight_selections", FilterParameters()); + registry.add_highlighter_to_window(*this, "expand_tabs", HighlighterParameters()); + registry.add_highlighter_to_window(*this, "highlight_selections", HighlighterParameters()); } void Window::check_invariant() const @@ -293,9 +293,9 @@ void Window::update_display_buffer() m_display_buffer.append(DisplayAtom(DisplayCoord(0,0), begin, end)); - for (auto& filter : m_filters) + for (auto& highlighter : m_highlighters) { - filter.second(m_display_buffer); + highlighter.second(m_display_buffer); m_display_buffer.check_invariant(); } } @@ -343,37 +343,37 @@ std::string Window::status_line() const return oss.str(); } -void Window::add_filter(FilterAndId&& filter) +void Window::add_highlighter(HighlighterAndId&& highlighter) { - for (auto it = m_filters.begin(); it != m_filters.end(); ++it) + for (auto it = m_highlighters.begin(); it != m_highlighters.end(); ++it) { - if (it->first == filter.first) - throw filter_id_not_unique(filter.first); + if (it->first == highlighter.first) + throw highlighter_id_not_unique(highlighter.first); } - m_filters.push_back(filter); + m_highlighters.push_back(highlighter); } -void Window::remove_filter(const std::string& id) +void Window::remove_highlighter(const std::string& id) { - for (auto it = m_filters.begin(); it != m_filters.end(); ++it) + for (auto it = m_highlighters.begin(); it != m_highlighters.end(); ++it) { if (it->first == id) { - m_filters.erase(it); + m_highlighters.erase(it); return; } } } -CandidateList Window::complete_filterid(const std::string& prefix, +CandidateList Window::complete_highlighterid(const std::string& prefix, size_t cursor_pos) { std::string real_prefix = prefix.substr(0, cursor_pos); CandidateList result; - for (auto& filter : m_filters) + for (auto& highlighter : m_highlighters) { - if (filter.first.substr(0, real_prefix.length()) == real_prefix) - result.push_back(filter.first); + if (highlighter.first.substr(0, real_prefix.length()) == real_prefix) + result.push_back(highlighter.first); } return result; } diff --git a/src/window.hh b/src/window.hh index aa8c066e..0f989ece 100644 --- a/src/window.hh +++ b/src/window.hh @@ -7,7 +7,7 @@ #include "dynamic_buffer_iterator.hh" #include "display_buffer.hh" #include "completion.hh" -#include "filter.hh" +#include "highlighter.hh" namespace Kakoune { @@ -87,17 +87,17 @@ public: std::string status_line() const; - struct filter_id_not_unique : public runtime_error + struct highlighter_id_not_unique : public runtime_error { - filter_id_not_unique(const std::string& id) - : runtime_error("filter id not unique: " + id) {} + highlighter_id_not_unique(const std::string& id) + : runtime_error("highlighter id not unique: " + id) {} }; - void add_filter(FilterAndId&& filter); - void remove_filter(const std::string& id); + void add_highlighter(HighlighterAndId&& highlighter); + void remove_highlighter(const std::string& id); - CandidateList complete_filterid(const std::string& prefix, - size_t cursor_pos = std::string::npos); + CandidateList complete_highlighterid(const std::string& prefix, + size_t cursor_pos = std::string::npos); private: friend class Buffer; @@ -121,8 +121,8 @@ private: SelectionList m_selections; DisplayBuffer m_display_buffer; - typedef std::vector<FilterAndId> FilterList; - FilterList m_filters; + typedef std::vector<HighlighterAndId> HighlighterList; + HighlighterList m_highlighters; }; class IncrementalInserter |
