Code style tweaks

This commit is contained in:
Maxime Coste 2020-07-18 14:29:44 +10:00
parent d4962d94ce
commit 5df8073c3c
4 changed files with 18 additions and 26 deletions

View File

@ -487,13 +487,10 @@ struct command_not_found : runtime_error
: runtime_error(format("no such command: '{}'", name)) {}
};
CommandManager::CommandMap::const_iterator
CommandManager::find_command(const Context& context, StringView name) const
StringView resolve_alias(const Context& context, StringView name)
{
auto alias = context.aliases()[name];
StringView cmd_name = alias.empty() ? name : alias;
return m_commands.find(cmd_name);
return alias.empty() ? name : alias;
}
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; });
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())
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))
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())
return {};
@ -729,7 +726,7 @@ Completions CommandManager::complete(const Context& context,
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())
return Completions{};
@ -786,7 +783,7 @@ Completions CommandManager::complete(const Context& context,
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)
return command_it->value.completer(
context, flags, params.subrange(1),

View File

@ -166,9 +166,6 @@ private:
};
using ModuleMap = HashMap<String, Module, MemoryDomain::Commands>;
ModuleMap m_modules;
CommandMap::const_iterator find_command(const Context& context,
StringView name) const;
};
String expand(StringView str, const Context& context,

View File

@ -2080,23 +2080,22 @@ const CommandDesc prompt_cmd = {
const auto flags = parser.get_switch("password") ?
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(
parser[0], initstr.str(), {}, context.faces()["Prompt"],
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
(event == PromptEvent::Change and on_change.empty()))
return;
auto& text = sc.env_vars["text"_sv] = str.str();
auto clear_password = on_scope_end([&] {
if (flags & PromptFlags::Password)
std::fill(text.begin(), text.end(), '\0');
sc.env_vars["text"_sv] = String{String::NoCopy{}, str};
auto remove_text = on_scope_end([&] {
sc.env_vars.erase("text"_sv);
});
ScopedSetBool disable_history{context.history_disabled()};
@ -2114,10 +2113,8 @@ const CommandDesc prompt_cmd = {
}
catch (Kakoune::runtime_error& error)
{
context.print_status({ fix_atom_text(error.what().str()),
context.faces()["Error"] });
context.hooks().run_hook(Hook::RuntimeError, error.what(),
context);
context.print_status({fix_atom_text(error.what()), context.faces()["Error"]});
context.hooks().run_hook(Hook::RuntimeError, error.what(), context);
}
});
}

View File

@ -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>>
constexpr void remove_all(const KeyType& key)