Code style tweaks
This commit is contained in:
parent
d4962d94ce
commit
5df8073c3c
|
@ -487,13 +487,10 @@ struct command_not_found : runtime_error
|
||||||
: runtime_error(format("no such command: '{}'", name)) {}
|
: runtime_error(format("no such command: '{}'", name)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandManager::CommandMap::const_iterator
|
StringView resolve_alias(const Context& context, StringView name)
|
||||||
CommandManager::find_command(const Context& context, StringView name) const
|
|
||||||
{
|
{
|
||||||
auto alias = context.aliases()[name];
|
auto alias = context.aliases()[name];
|
||||||
StringView cmd_name = alias.empty() ? name : alias;
|
return alias.empty() ? name : alias;
|
||||||
|
|
||||||
return m_commands.find(cmd_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandManager::execute_single_command(CommandParameters params,
|
void CommandManager::execute_single_command(CommandParameters params,
|
||||||
|
@ -512,7 +509,7 @@ void CommandManager::execute_single_command(CommandParameters params,
|
||||||
auto pop_cmd = on_scope_end([this] { --m_command_depth; });
|
auto pop_cmd = on_scope_end([this] { --m_command_depth; });
|
||||||
|
|
||||||
ParameterList param_view(params.begin()+1, params.end());
|
ParameterList param_view(params.begin()+1, params.end());
|
||||||
auto command_it = find_command(context, params[0]);
|
auto command_it = m_commands.find(resolve_alias(context, params[0]));
|
||||||
if (command_it == m_commands.end())
|
if (command_it == m_commands.end())
|
||||||
throw command_not_found(params[0]);
|
throw command_not_found(params[0]);
|
||||||
|
|
||||||
|
@ -587,7 +584,7 @@ Optional<CommandInfo> CommandManager::command_info(const Context& context, Strin
|
||||||
tokens.front().type != Token::Type::RawQuoted))
|
tokens.front().type != Token::Type::RawQuoted))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto cmd = find_command(context, tokens.front().content);
|
auto cmd = m_commands.find(resolve_alias(context, tokens.front().content));
|
||||||
if (cmd == m_commands.end())
|
if (cmd == m_commands.end())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -729,7 +726,7 @@ Completions CommandManager::complete(const Context& context,
|
||||||
flags |= CompletionFlags::Start;
|
flags |= CompletionFlags::Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto command_it = find_command(context, command_name);
|
auto command_it = m_commands.find(resolve_alias(context, command_name));
|
||||||
if (command_it == m_commands.end())
|
if (command_it == m_commands.end())
|
||||||
return Completions{};
|
return Completions{};
|
||||||
|
|
||||||
|
@ -786,7 +783,7 @@ Completions CommandManager::complete(const Context& context,
|
||||||
flags |= CompletionFlags::Start;
|
flags |= CompletionFlags::Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto command_it = find_command(context, command_name);
|
auto command_it = m_commands.find(resolve_alias(context, command_name));
|
||||||
if (command_it != m_commands.end() and command_it->value.completer)
|
if (command_it != m_commands.end() and command_it->value.completer)
|
||||||
return command_it->value.completer(
|
return command_it->value.completer(
|
||||||
context, flags, params.subrange(1),
|
context, flags, params.subrange(1),
|
||||||
|
|
|
@ -166,9 +166,6 @@ private:
|
||||||
};
|
};
|
||||||
using ModuleMap = HashMap<String, Module, MemoryDomain::Commands>;
|
using ModuleMap = HashMap<String, Module, MemoryDomain::Commands>;
|
||||||
ModuleMap m_modules;
|
ModuleMap m_modules;
|
||||||
|
|
||||||
CommandMap::const_iterator find_command(const Context& context,
|
|
||||||
StringView name) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
String expand(StringView str, const Context& context,
|
String expand(StringView str, const Context& context,
|
||||||
|
|
|
@ -2080,23 +2080,22 @@ const CommandDesc prompt_cmd = {
|
||||||
const auto flags = parser.get_switch("password") ?
|
const auto flags = parser.get_switch("password") ?
|
||||||
PromptFlags::Password : PromptFlags::None;
|
PromptFlags::Password : PromptFlags::None;
|
||||||
|
|
||||||
String on_change = parser.get_switch("on-change").value_or("").str();
|
|
||||||
String on_abort = parser.get_switch("on-abort").value_or("").str();
|
|
||||||
|
|
||||||
CapturedShellContext sc{shell_context};
|
|
||||||
context.input_handler().prompt(
|
context.input_handler().prompt(
|
||||||
parser[0], initstr.str(), {}, context.faces()["Prompt"],
|
parser[0], initstr.str(), {}, context.faces()["Prompt"],
|
||||||
flags, '_', std::move(completer),
|
flags, '_', std::move(completer),
|
||||||
[=](StringView str, PromptEvent event, Context& context) mutable
|
[command,
|
||||||
|
on_change = parser.get_switch("on-change").value_or("").str(),
|
||||||
|
on_abort = parser.get_switch("on-abort").value_or("").str(),
|
||||||
|
sc = CapturedShellContext{shell_context}]
|
||||||
|
(StringView str, PromptEvent event, Context& context) mutable
|
||||||
{
|
{
|
||||||
if ((event == PromptEvent::Abort and on_abort.empty()) or
|
if ((event == PromptEvent::Abort and on_abort.empty()) or
|
||||||
(event == PromptEvent::Change and on_change.empty()))
|
(event == PromptEvent::Change and on_change.empty()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& text = sc.env_vars["text"_sv] = str.str();
|
sc.env_vars["text"_sv] = String{String::NoCopy{}, str};
|
||||||
auto clear_password = on_scope_end([&] {
|
auto remove_text = on_scope_end([&] {
|
||||||
if (flags & PromptFlags::Password)
|
sc.env_vars.erase("text"_sv);
|
||||||
std::fill(text.begin(), text.end(), '\0');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ScopedSetBool disable_history{context.history_disabled()};
|
ScopedSetBool disable_history{context.history_disabled()};
|
||||||
|
@ -2114,10 +2113,8 @@ const CommandDesc prompt_cmd = {
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
context.print_status({ fix_atom_text(error.what().str()),
|
context.print_status({fix_atom_text(error.what()), context.faces()["Error"]});
|
||||||
context.faces()["Error"] });
|
context.hooks().run_hook(Hook::RuntimeError, error.what(), context);
|
||||||
context.hooks().run_hook(Hook::RuntimeError, error.what(),
|
|
||||||
context);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,8 @@ struct HashMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void erase(const Key& key) { unordered_remove(key); }
|
template<typename KeyType, typename = EnableIfHashCompatible<KeyType>>
|
||||||
|
constexpr void erase(const KeyType& key) { unordered_remove(key); }
|
||||||
|
|
||||||
template<typename KeyType, typename = EnableIfHashCompatible<KeyType>>
|
template<typename KeyType, typename = EnableIfHashCompatible<KeyType>>
|
||||||
constexpr void remove_all(const KeyType& key)
|
constexpr void remove_all(const KeyType& key)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user