diff options
| author | Delapouite <delapouite@gmail.com> | 2018-01-18 09:57:14 +0100 |
|---|---|---|
| committer | Delapouite <delapouite@gmail.com> | 2018-02-12 14:19:58 +0100 |
| commit | 6b447a0ecb018256c574fc2a36be99698f603cc3 (patch) | |
| tree | 6561f4c13cc5f27ad31be9ab4353f44c0d70f018 /src/keymap_manager.cc | |
| parent | 9c25e955dfdddd0ee63c2edb56cde79b18452da8 (diff) | |
Add declare-user-mode / enter-user-mode commands
Diffstat (limited to 'src/keymap_manager.cc')
| -rw-r--r-- | src/keymap_manager.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/keymap_manager.cc b/src/keymap_manager.cc index 859f420b..8c359082 100644 --- a/src/keymap_manager.cc +++ b/src/keymap_manager.cc @@ -2,6 +2,8 @@ #include "array_view.hh" #include "assert.hh" +#include "exception.hh" +#include "string_utils.hh" #include <algorithm> @@ -49,4 +51,19 @@ KeymapManager::KeyList KeymapManager::get_mapped_keys(KeymapMode mode) const return res; } +void KeymapManager::add_user_mode(const 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)) + 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(user_mode_name); +} + } |
