summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorJason Felice <jason.m.felice@gmail.com>2019-02-14 09:53:36 -0500
committerJason Felice <jason.m.felice@gmail.com>2019-02-17 20:18:19 -0500
commit7cf6eddc30f8d0f704e92fe13c447df3aa664ddd (patch)
tree3147062b21f686f7ef5f384580116832fe073e50 /src/normal.cc
parente169a1893b117e6d8983146c3bcbc2efd1371092 (diff)
Add object mode expansions
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/normal.cc b/src/normal.cc
index 66eec914..9be1cd4a 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -9,6 +9,7 @@
#include "commands.hh"
#include "context.hh"
#include "diff.hh"
+#include "enum.hh"
#include "face_registry.hh"
#include "file.hh"
#include "flags.hh"
@@ -37,6 +38,14 @@ enum class SelectMode
Append,
};
+constexpr auto enum_desc(Meta::Type<SelectMode>)
+{
+ return make_array<EnumDesc<SelectMode>, 3>({
+ { SelectMode::Replace, "replace" },
+ { SelectMode::Extend, "extend" },
+ { SelectMode::Append, "append" },
+ });
+}
void merge_selections(Selection& sel, const Selection& new_sel)
{
const bool forward = sel.cursor() >= sel.anchor();
@@ -437,7 +446,7 @@ void for_each_codepoint(Context& context, NormalParams)
selections.insert(strings, InsertMode::Replace);
}
-void command(Context& context, NormalParams params)
+void command(Context& context, EnvVarMap env_vars)
{
if (not CommandManager::has_instance())
throw runtime_error{"commands are not supported"};
@@ -451,7 +460,7 @@ void command(Context& context, NormalParams params)
StringView cmd_line, ByteCount pos) {
return CommandManager::instance().complete(context, flags, cmd_line, pos);
},
- [params](StringView cmdline, PromptEvent event, Context& context) {
+ [env_vars = std::move(env_vars)](StringView cmdline, PromptEvent event, Context& context) {
if (context.has_client())
{
context.client().info_hide();
@@ -479,16 +488,21 @@ void command(Context& context, NormalParams params)
else if (not is_blank(cmdline[0]))
RegisterManager::instance()[':'].set(context, cmdline.str());
- EnvVarMap env_vars = {
- { "count", to_string(params.count) },
- { "register", String{&params.reg, 1} }
- };
CommandManager::instance().execute(
cmdline, context, { {}, env_vars });
}
});
}
+void command(Context& context, NormalParams params)
+{
+ EnvVarMap env_vars = {
+ { "count", to_string(params.count) },
+ { "register", String{&params.reg, 1} }
+ };
+ command(context, std::move(env_vars));
+}
+
BufferCoord apply_diff(Buffer& buffer, BufferCoord pos, StringView before, StringView after)
{
const auto lines_before = before | split_after<StringView>('\n') | gather<Vector<StringView>>();
@@ -1313,7 +1327,13 @@ void select_object(Context& context, NormalParams params)
if (key == alt(';'))
{
- command(context, params);
+ EnvVarMap env_vars = {
+ { "count", to_string(params.count) },
+ { "register", String{&params.reg, 1} },
+ { "select_mode", option_to_string(mode) },
+ { "object_flags", option_to_string(flags) }
+ };
+ command(context, std::move(env_vars));
return;
}