diff --git a/src/commands.cc b/src/commands.cc index de9aec62..71c4e561 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -938,6 +938,7 @@ KeymapMode parse_keymap_mode(const String& str) if (prefix_match("prompt", str)) return KeymapMode::Prompt; if (prefix_match("goto", str)) return KeymapMode::Goto; if (prefix_match("view", str)) return KeymapMode::View; + if (prefix_match("user", str)) return KeymapMode::User; throw runtime_error("unknown keymap mode '" + str + "'"); } @@ -954,7 +955,8 @@ const CommandDesc map_key_cmd = { " normal\n" " insert\n" " menu\n" - " prompt\n", + " prompt\n" + " user\n", ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 4, 4 }, CommandFlags::None, [](const Context& context, CompletionFlags flags, @@ -1380,7 +1382,7 @@ private: } -void exec_keys(const KeyList& keys, Context& context) +void exec_keys(memoryview keys, Context& context) { RegisterRestorer quote('"', context); RegisterRestorer slash('/', context); diff --git a/src/commands.hh b/src/commands.hh index 4042740e..0cc74dff 100644 --- a/src/commands.hh +++ b/src/commands.hh @@ -2,6 +2,7 @@ #define commands_hh_INCLUDED #include "keys.hh" +#include "memoryview.hh" namespace Kakoune { @@ -9,7 +10,7 @@ namespace Kakoune class Context; void register_commands(); -void exec_keys(const KeyList& keys, Context& context); +void exec_keys(memoryview keys, Context& context); } diff --git a/src/keymap_manager.hh b/src/keymap_manager.hh index b6b0bf52..5743a18e 100644 --- a/src/keymap_manager.hh +++ b/src/keymap_manager.hh @@ -19,6 +19,7 @@ enum class KeymapMode : int Menu, Goto, View, + User, }; template class memoryview; diff --git a/src/normal.cc b/src/normal.cc index 5f0f285d..d1e311dc 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1262,6 +1262,19 @@ void redo(Context& context, NormalParams) context.print_status({ "nothing left to redo", get_face("Information") }); } +void exec_user_mappings(Context& context, NormalParams params) +{ + on_next_key_with_autoinfo(context, KeymapMode::None, + [params](Key key, Context& context) mutable { + if (not context.keymaps().is_mapped(key, KeymapMode::User)) + return; + + auto mapping = context.keymaps().get_mapping(key, KeymapMode::User); + ScopedEdition edition(context); + exec_keys(mapping, context); + }, "user mapping", "enter user key"); +} + template class Repeated { @@ -1448,6 +1461,8 @@ KeyMap keymap = { '@', { "convert tabs to spaces in selections", tabs_to_spaces } }, { alt('@'), { "convert spaces to tabs in selections", spaces_to_tabs } }, + { ',', { "user mappings", exec_user_mappings } }, + { Key::Left, { "move left", move } }, { Key::Down, { "move down", move } }, { Key::Up, { "move up", move } },