diff options
| author | Delapouite <delapouite@gmail.com> | 2018-03-02 07:45:04 +0100 |
|---|---|---|
| committer | Delapouite <delapouite@gmail.com> | 2018-03-02 09:28:27 +0100 |
| commit | c4eb4438d26aa03d6008800133a5178d3752393a (patch) | |
| tree | ed3eadf3fd177188fa2c281c652499af7c567464 /src | |
| parent | 7a54c0edfe36a0a3fb428cfee211a3f87cf4f7a2 (diff) | |
Remove <scope> from user-modes commands
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 32 | ||||
| -rw-r--r-- | src/keymap_manager.cc | 5 | ||||
| -rw-r--r-- | src/keymap_manager.hh | 6 | ||||
| -rw-r--r-- | src/main.cc | 4 |
4 files changed, 25 insertions, 22 deletions
diff --git a/src/commands.cc b/src/commands.cc index 818002d4..35f6a593 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1192,10 +1192,11 @@ const CommandDesc debug_cmd = { auto& keymaps = context.keymaps(); auto modes = {"normal", "insert", "prompt", "menu", "goto", "view", "user", "object"}; + auto user_modes = keymaps.user_modes(); write_to_debug_buffer("Mappings:"); - for (auto& mode : modes) + for (auto& mode : concatenated(modes, user_modes) | gather<Vector<String>>()) { - KeymapMode m = parse_keymap_mode(mode, keymaps.user_modes()); + KeymapMode m = parse_keymap_mode(mode, user_modes); for (auto& key : keymaps.get_mapped_keys(m)) write_to_debug_buffer(format(" * {} {}: {}", mode, key_to_str(key), @@ -2123,15 +2124,14 @@ const CommandDesc fail_cmd = { const CommandDesc declare_user_mode_cmd = { "declare-user-mode", nullptr, - "declare-user-mode <scope> <name>: add a new user keymap mode in given <scope>", - ParameterDesc{ {}, ParameterDesc::Flags::None, 2, 2 }, + "declare-user-mode <name>: add a new user keymap mode", + single_param, CommandFlags::None, CommandHelper{}, - make_completer(complete_scope), + CommandCompleter{}, [](const ParametersParser& parser, Context& context, const ShellContext&) { - KeymapManager& keymaps = get_scope(parser[0], context).keymaps(); - keymaps.add_user_mode(std::move(parser[1])); + context.keymaps().add_user_mode(std::move(parser[0])); } }; @@ -2162,10 +2162,10 @@ void enter_user_mode(Context& context, const String mode_name, KeymapMode mode, const CommandDesc enter_user_mode_cmd = { "enter-user-mode", nullptr, - "enter-user-mode <switches> <scope> <name>: enable <name> keymap mode for next key", + "enter-user-mode <switches> <name>: enable <name> keymap mode for next key", ParameterDesc{ { { "lock", { false, "stay in mode until <esc> is pressed" } } }, - ParameterDesc::Flags::SwitchesOnlyAtStart, 2, 2 + ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1 }, CommandFlags::None, CommandHelper{}, @@ -2174,23 +2174,17 @@ const CommandDesc enter_user_mode_cmd = { ByteCount pos_in_token) -> Completions { if (token_to_complete == 0) - return { 0_byte, params[0].length(), - complete(params[0], pos_in_token, scopes) }; - if (token_to_complete == 1) { - KeymapManager& keymaps = get_scope(params[0], context).keymaps(); - return { 0_byte, params[1].length(), - complete(params[1], pos_in_token, keymaps.user_modes()) }; + return { 0_byte, params[0].length(), + complete(params[0], pos_in_token, context.keymaps().user_modes()) }; } return {}; }, [](const ParametersParser& parser, Context& context, const ShellContext&) { auto lock = (bool)parser.get_switch("lock"); - KeymapManager& keymaps = get_scope(parser[0], context).keymaps(); - KeymapMode mode = parse_keymap_mode(parser[1], keymaps.user_modes()); - - enter_user_mode(context, std::move(parser[1]), mode, lock); + KeymapMode mode = parse_keymap_mode(parser[0], context.keymaps().user_modes()); + enter_user_mode(context, std::move(parser[0]), mode, lock); } }; diff --git a/src/keymap_manager.cc b/src/keymap_manager.cc index 2b560706..658c7e42 100644 --- a/src/keymap_manager.cc +++ b/src/keymap_manager.cc @@ -54,16 +54,17 @@ KeymapManager::KeyList KeymapManager::get_mapped_keys(KeymapMode mode) const void KeymapManager::add_user_mode(String user_mode_name) { auto modes = {"normal", "insert", "prompt", "menu", "goto", "view", "user", "object"}; + if (contains(modes, user_mode_name)) throw runtime_error(format("'{}' is already a regular mode", user_mode_name)); - if (contains(m_user_modes, user_mode_name)) + if (contains(user_modes(), user_mode_name)) throw runtime_error(format("user mode '{}' already defined", user_mode_name)); if (contains_that(user_mode_name, [](char c){ return not isalnum(c); })) throw runtime_error(format("invalid mode name: '{}'", user_mode_name)); - m_user_modes.push_back(std::move(user_mode_name)); + user_modes().push_back(std::move(user_mode_name)); } } diff --git a/src/keymap_manager.hh b/src/keymap_manager.hh index 3c8d52ee..21a291e3 100644 --- a/src/keymap_manager.hh +++ b/src/keymap_manager.hh @@ -45,7 +45,11 @@ public: const KeymapInfo& get_mapping(Key key, KeymapMode mode) const; using UserModeList = Vector<String>; - const UserModeList& user_modes() const { return m_user_modes; } + UserModeList& user_modes() { + if (m_parent) + return m_parent->user_modes(); + return m_user_modes; + } void add_user_mode(const String user_mode_name); private: diff --git a/src/main.cc b/src/main.cc index 8edfe82f..a3802a85 100644 --- a/src/main.cc +++ b/src/main.cc @@ -193,6 +193,10 @@ static const EnvVarDesc builtin_env_vars[] = { { "window_height", false, [](StringView name, const Context& context) -> String { return to_string(context.window().dimensions().line); } + }, { + "user_modes", false, + [](StringView name, const Context& context) -> String + { return join(context.keymaps().user_modes(), ':'); } } }; |
