From 3b5530ac09bc688f39cd4cd3c4845d8750664ce9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 22 Nov 2012 13:50:29 +0100 Subject: [PATCH] rename (hook|option)_manager to (hook|option)s. And Global(Hook|Option)Manager to Global(Hook|Option)s --- src/buffer.cc | 12 ++++++------ src/buffer.hh | 12 ++++++------ src/command_manager.cc | 2 +- src/commands.cc | 24 ++++++++++++------------ src/context.hh | 8 ++++---- src/file.cc | 10 +++++----- src/filters.cc | 2 +- src/highlighters.cc | 2 +- src/hook_manager.hh | 6 +++--- src/main.cc | 10 +++++----- src/option_manager.cc | 2 +- src/option_manager.hh | 8 ++++---- src/window.cc | 16 ++++++++-------- src/window.hh | 12 ++++++------ 14 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index a540772a1..937cd6bcf 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -18,8 +18,8 @@ Buffer::Buffer(String name, Flags flags, m_history(), m_history_cursor(m_history.begin()), m_last_save_undo_index(0), m_timestamp(0), - m_hook_manager(GlobalHookManager::instance()), - m_option_manager(GlobalOptionManager::instance()) + m_hooks(GlobalHooks::instance()), + m_options(GlobalOptions::instance()) { BufferManager::instance().register_buffer(*this); if (initial_content.empty() or initial_content.back() != '\n') @@ -29,11 +29,11 @@ Buffer::Buffer(String name, Flags flags, Editor editor_for_hooks(*this); Context context(editor_for_hooks); if (flags & Flags::File and flags & Flags::New) - m_hook_manager.run_hook("BufNew", m_name, context); + m_hooks.run_hook("BufNew", m_name, context); else - m_hook_manager.run_hook("BufOpen", m_name, context); + m_hooks.run_hook("BufOpen", m_name, context); - m_hook_manager.run_hook("BufCreate", m_name, context); + m_hooks.run_hook("BufCreate", m_name, context); // now we may begin to record undo data m_flags = flags; @@ -41,7 +41,7 @@ Buffer::Buffer(String name, Flags flags, Buffer::~Buffer() { - m_hook_manager.run_hook("BufClose", m_name, Context(Editor(*this))); + m_hooks.run_hook("BufClose", m_name, Context(Editor(*this))); m_windows.clear(); BufferManager::instance().unregister_buffer(*this); diff --git a/src/buffer.hh b/src/buffer.hh index 27b5ae790..db61d3713 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -177,10 +177,10 @@ public: const String& line_content(LineCount line) const { return m_lines[line].content; } - OptionManager& option_manager() { return m_option_manager; } - const OptionManager& option_manager() const { return m_option_manager; } - HookManager& hook_manager() { return m_hook_manager; } - const HookManager& hook_manager() const { return m_hook_manager; } + OptionManager& options() { return m_options; } + const OptionManager& options() const { return m_options; } + HookManager& hooks() { return m_hooks; } + const HookManager& hooks() const { return m_hooks; } private: friend class BufferIterator; @@ -230,8 +230,8 @@ private: // observable state. mutable std::vector m_change_listeners; - OptionManager m_option_manager; - HookManager m_hook_manager; + OptionManager m_options; + HookManager m_hooks; }; constexpr Buffer::Flags operator|(Buffer::Flags lhs, Buffer::Flags rhs) diff --git a/src/command_manager.cc b/src/command_manager.cc index 8a30d9d25..6a130ec79 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -265,7 +265,7 @@ void CommandManager::execute(const String& command_line, } if (it->type() == Token::Type::OptionExpand) { - const Option& option = context.option_manager()[it->content()]; + const Option& option = context.options()[it->content()]; params.push_back(option.as_string()); } if (it->type() == Token::Type::CommandSeparator) diff --git a/src/commands.cc b/src/commands.cc index d862a61ac..c28985b5d 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -238,7 +238,7 @@ Buffer* open_fifo(const String& name , const String& filename, Context& context) throw runtime_error("unable to open " + filename); Buffer* buffer = new Buffer(name, Buffer::Flags::Fifo | Buffer::Flags::NoUndo); - buffer->hook_manager().add_hook("BufClose", + buffer->hooks().add_hook("BufClose", [fd, buffer](const String&, const Context&) { // Check if fifo is still alive, else fd may // refer to another file/socket @@ -526,11 +526,11 @@ void add_hook(const CommandParameters& params, Context& context) const String& scope = params[0]; const String& name = params[1]; if (scope == "global") - GlobalHookManager::instance().add_hook(name, hook_func); + GlobalHooks::instance().add_hook(name, hook_func); else if (scope == "buffer") - context.buffer().hook_manager().add_hook(name, hook_func); + context.buffer().hooks().add_hook(name, hook_func); else if (scope == "window") - context.window().hook_manager().add_hook(name , hook_func); + context.window().hooks().add_hook(name , hook_func); else throw runtime_error("error: no such hook container " + scope); } @@ -636,13 +636,13 @@ void exec_commands_in_file(const CommandParameters& params, CommandManager::instance().execute(file_content, context); } -void set_option(OptionManager& option_manager, const CommandParameters& params, +void set_option(OptionManager& options, const CommandParameters& params, Context& context) { if (params.size() != 2) throw wrong_argument_count(); - option_manager.set_option(params[0], Option(params[1])); + options.set_option(params[0], Option(params[1])); } class RegisterRestorer @@ -869,24 +869,24 @@ void register_commands() cm.register_commands({ "setg", "setglobal" }, [](const CommandParameters& params, Context& context) - { set_option(GlobalOptionManager::instance(), params, context); }, + { set_option(GlobalOptions::instance(), params, context); }, PerArgumentCommandCompleter({ [](const Context& context, const String& prefix, ByteCount cursor_pos) - { return GlobalOptionManager::instance().complete_option_name(prefix, cursor_pos); } + { return GlobalOptions::instance().complete_option_name(prefix, cursor_pos); } })); cm.register_commands({ "setb", "setbuffer" }, [](const CommandParameters& params, Context& context) - { set_option(context.buffer().option_manager(), params, context); }, + { set_option(context.buffer().options(), params, context); }, PerArgumentCommandCompleter({ [](const Context& context, const String& prefix, ByteCount cursor_pos) - { return context.buffer().option_manager().complete_option_name(prefix, cursor_pos); } + { return context.buffer().options().complete_option_name(prefix, cursor_pos); } })); cm.register_commands({ "setw", "setwindow" }, [](const CommandParameters& params, Context& context) - { set_option(context.window().option_manager(), params, context); }, + { set_option(context.window().options(), params, context); }, PerArgumentCommandCompleter({ [](const Context& context, const String& prefix, ByteCount cursor_pos) - { return context.window().option_manager().complete_option_name(prefix, cursor_pos); } + { return context.window().options().complete_option_name(prefix, cursor_pos); } })); cm.register_commands({"ca", "colalias"}, define_color_alias); diff --git a/src/context.hh b/src/context.hh index c29066a9d..9fc63ed86 100644 --- a/src/context.hh +++ b/src/context.hh @@ -84,13 +84,13 @@ struct Context m_ui.reset(&ui); } - OptionManager& option_manager() const + OptionManager& options() const { if (has_window()) - return window().option_manager(); + return window().options(); if (has_buffer()) - return buffer().option_manager(); - return GlobalOptionManager::instance(); + return buffer().options(); + return GlobalOptions::instance(); } void print_status(const String& status) const diff --git a/src/file.cc b/src/file.cc index cf8df91e3..9416afbd8 100644 --- a/src/file.cc +++ b/src/file.cc @@ -123,9 +123,9 @@ Buffer* create_buffer_from_file(const String& filename) at_file_begin = false; } - OptionManager& option_manager = buffer->option_manager(); - option_manager.set_option("eolformat", Option(crlf ? "crlf" : "lf")); - option_manager.set_option("BOM", Option(bom ? "utf-8" : "no")); + OptionManager& options = buffer->options(); + options.set_option("eolformat", Option(crlf ? "crlf" : "lf")); + options.set_option("BOM", Option(bom ? "utf-8" : "no")); // if the file ended with a \n, remove the \n added by the buffer if (*(buffer->end() - 2) == '\n') @@ -155,7 +155,7 @@ static void write(int fd, const memoryview& data, const String& filename) void write_buffer_to_file(const Buffer& buffer, const String& filename) { - String eolformat = buffer.option_manager()["eolformat"].as_string(); + String eolformat = buffer.options()["eolformat"].as_string(); if (eolformat == "crlf") eolformat = "\r\n"; else @@ -168,7 +168,7 @@ void write_buffer_to_file(const Buffer& buffer, const String& filename) throw file_access_error(filename, strerror(errno)); auto close_fd = on_scope_end([fd]{ close(fd); }); - if (buffer.option_manager()["BOM"].as_string() == "utf-8") + if (buffer.options()["BOM"].as_string() == "utf-8") ::write(fd, "\xEF\xBB\xBF", 3); for (LineCount i = 0; i < buffer.line_count(); ++i) diff --git a/src/filters.cc b/src/filters.cc index 9a2fcf280..bd24fe23c 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -37,7 +37,7 @@ void cleanup_whitespaces(Buffer& buffer, Selection& selection, String& content) void expand_tabulations(Buffer& buffer, Selection& selection, String& content) { - const int tabstop = buffer.option_manager()["tabstop"].as_int(); + const int tabstop = buffer.options()["tabstop"].as_int(); if (content == "\t") { int column = 0; diff --git a/src/highlighters.cc b/src/highlighters.cc index 260a0cd8f..ac66e50fc 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -153,7 +153,7 @@ HighlighterAndId colorize_regex_factory(Window& window, void expand_tabulations(Window& window, DisplayBuffer& display_buffer) { - const int tabstop = window.option_manager()["tabstop"].as_int(); + const int tabstop = window.options()["tabstop"].as_int(); for (auto& line : display_buffer.lines()) { for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it) diff --git a/src/hook_manager.hh b/src/hook_manager.hh index 96df0a8c8..a1da230f6 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -24,14 +24,14 @@ private: HookManager() : m_parent(nullptr) {} // the only one allowed to construct a root hook manager - friend class GlobalHookManager; + friend class GlobalHooks; HookManager* m_parent; std::unordered_map> m_hook; }; -class GlobalHookManager : public HookManager, - public Singleton +class GlobalHooks : public HookManager, + public Singleton { }; diff --git a/src/main.cc b/src/main.cc index 2aedb5101..d0606f21a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -239,7 +239,7 @@ void do_join(Context& context) void do_indent(Context& context) { const char* spaces = " "; - int width = std::min(context.option_manager()["indentwidth"].as_int(), 16); + int width = std::min(context.options()["indentwidth"].as_int(), 16); String indent(spaces, spaces + width); Editor& editor = context.editor(); @@ -252,7 +252,7 @@ void do_indent(Context& context) void do_deindent(Context& context) { - int width = context.option_manager()["indentwidth"].as_int(); + int width = context.options()["indentwidth"].as_int(); Editor& editor = context.editor(); SelectionAndCapturesList sels = editor.selections(); auto restore_sels = on_scope_end([&]{ editor.select(std::move(sels)); }); @@ -571,7 +571,7 @@ void register_env_vars() { return runtime_directory(); }); shell_manager.register_env_var("opt_.+", [](const String& name, const Context& context) - { return context.option_manager()[name.substr(4_byte)].as_string(); }); + { return context.options()[name.substr(4_byte)].as_string(); }); shell_manager.register_env_var("reg_.+", [](const String& name, const Context& context) { return RegisterManager::instance()[name[4]].values(context)[0]; }); @@ -678,8 +678,8 @@ int main(int argc, char* argv[]) return 0; } - GlobalOptionManager option_manager; - GlobalHookManager hook_manager; + GlobalOptions global_options; + GlobalHooks global_hooks; ShellManager shell_manager; CommandManager command_manager; BufferManager buffer_manager; diff --git a/src/option_manager.cc b/src/option_manager.cc index b3e6c5a43..fd6869348 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -90,7 +90,7 @@ void OptionManager::on_option_changed(const String& name, const Option& value) watcher->on_option_changed(name, value); } -GlobalOptionManager::GlobalOptionManager() +GlobalOptions::GlobalOptions() : OptionManager() { set_option("tabstop", Option(8)); diff --git a/src/option_manager.hh b/src/option_manager.hh index 2fa2f2968..d31902f24 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -69,7 +69,7 @@ private: OptionManager() : m_parent(nullptr) {} // the only one allowed to construct a root option manager - friend class GlobalOptionManager; + friend class GlobalOptions; OptionMap m_options; OptionManager* m_parent; @@ -80,11 +80,11 @@ private: std::vector m_watchers; }; -class GlobalOptionManager : public OptionManager, - public Singleton +class GlobalOptions : public OptionManager, + public Singleton { public: - GlobalOptionManager(); + GlobalOptions(); }; diff --git a/src/window.cc b/src/window.cc index 78a5fe00d..e5b619104 100644 --- a/src/window.cc +++ b/src/window.cc @@ -13,24 +13,24 @@ namespace Kakoune Window::Window(Buffer& buffer) : Editor(buffer), - m_hook_manager(buffer.hook_manager()), - m_option_manager(buffer.option_manager()) + m_hooks(buffer.hooks()), + m_options(buffer.options()) { HighlighterRegistry& registry = HighlighterRegistry::instance(); - m_hook_manager.run_hook("WinCreate", buffer.name(), Context(*this)); - m_option_manager.register_watcher(*this); + m_hooks.run_hook("WinCreate", buffer.name(), Context(*this)); + m_options.register_watcher(*this); registry.add_highlighter_to_group(*this, m_highlighters, "expand_tabs", HighlighterParameters()); registry.add_highlighter_to_group(*this, m_highlighters, "highlight_selections", HighlighterParameters()); - for (auto& option : m_option_manager.flatten_options()) + for (auto& option : m_options.flatten_options()) on_option_changed(option.first, option.second); } Window::~Window() { - m_option_manager.unregister_watcher(*this); + m_options.unregister_watcher(*this); } void Window::center_selection() @@ -176,14 +176,14 @@ String Window::status_line() const void Window::on_incremental_insertion_end() { SelectionAndCapturesList backup(selections()); - hook_manager().run_hook("InsertEnd", "", Context(*this)); + hooks().run_hook("InsertEnd", "", Context(*this)); select(backup); } void Window::on_option_changed(const String& name, const Option& option) { String desc = name + "=" + option.as_string(); - m_hook_manager.run_hook("WinSetOption", desc, Context(*this)); + m_hooks.run_hook("WinSetOption", desc, Context(*this)); } } diff --git a/src/window.hh b/src/window.hh index 1433bd2cf..396e00691 100644 --- a/src/window.hh +++ b/src/window.hh @@ -41,10 +41,10 @@ public: HighlighterGroup& highlighters() { return m_highlighters; } - OptionManager& option_manager() { return m_option_manager; } - const OptionManager& option_manager() const { return m_option_manager; } - HookManager& hook_manager() { return m_hook_manager; } - const HookManager& hook_manager() const { return m_hook_manager; } + OptionManager& options() { return m_options; } + const OptionManager& options() const { return m_options; } + HookManager& hooks() { return m_hooks; } + const HookManager& hooks() const { return m_hooks; } size_t timestamp() const { return m_timestamp; } void forget_timestamp() { m_timestamp = -1; } @@ -66,8 +66,8 @@ private: HighlighterGroup m_highlighters; - HookManager m_hook_manager; - OptionManager m_option_manager; + HookManager m_hooks; + OptionManager m_options; size_t m_timestamp = -1; };