From 6b447a0ecb018256c574fc2a36be99698f603cc3 Mon Sep 17 00:00:00 2001 From: Delapouite Date: Thu, 18 Jan 2018 09:57:14 +0100 Subject: Add declare-user-mode / enter-user-mode commands --- src/keymap_manager.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/keymap_manager.cc') 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 @@ -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); +} + } -- cgit v1.2.3