summaryrefslogtreecommitdiff
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
parente169a1893b117e6d8983146c3bcbc2efd1371092 (diff)
Add object mode expansions
-rw-r--r--doc/pages/expansions.asciidoc15
-rw-r--r--doc/pages/keys.asciidoc4
-rw-r--r--src/normal.cc34
-rw-r--r--src/selectors.hh10
4 files changed, 52 insertions, 11 deletions
diff --git a/doc/pages/expansions.asciidoc b/doc/pages/expansions.asciidoc
index 36e5d020..754cf573 100644
--- a/doc/pages/expansions.asciidoc
+++ b/doc/pages/expansions.asciidoc
@@ -215,7 +215,7 @@ The following expansions are supported (with required context _in italics_):
directory containing the user configuration
*%val{count}*::
- _in `map` command <keys> parameter_ +
+ _in `map` command <keys> parameter and `<a-;>` from object menu_ +
current count when the mapping was triggered, defaults to 0 if no
count given
@@ -262,14 +262,25 @@ The following expansions are supported (with required context _in italics_):
_in buffer, window scope_ +
`true` if the buffer has modifications not saved, otherwise `false`
+*%val{object_flags}*::
+ _for commands executed from the object menu's `<a-;>` only_ +
+ a pipe-separted list of words including `inner` if the user wants
+ an inner selection, `to_begin` if the user wants to select to the
+ beginning, and `to_end` if the user wants to select to the end
+
*%val{register}*::
- _in `map` command <keys> parameter_ +
+ _in `map` command <keys> parameter and `<a-;>` from the object menu_ +
current register when the mapping was triggered
*%val{runtime}*::
directory containing the kak support files, determined from Kakoune's
binary location
+*%val{select_mode}*::
+ _for commands executed from the object menu's `<a-;>` only_ +
+ `replace` if the new selection should replace the existing, `extend`
+ otherwise
+
*%val{selection}*::
_in window scope_ +
content of the main selection
diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc
index 012f142a..c144e34e 100644
--- a/doc/pages/keys.asciidoc
+++ b/doc/pages/keys.asciidoc
@@ -682,8 +682,8 @@ in order to specify the wanted object:
select user defined object, will prompt for open and close text
*<a-;>*::
- run a command in object context. The expansions `%val{count}` and
- `%val{register}` are available here.
+ run a command with additional expansions describing the selection
+ context (See <<expansions#,`:doc expansions`>>)
== Prompt commands
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;
}
diff --git a/src/selectors.hh b/src/selectors.hh
index a82e29a2..d2cbd040 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -1,6 +1,7 @@
#ifndef selectors_hh_INCLUDED
#define selectors_hh_INCLUDED
+#include "enum.hh"
#include "optional.hh"
#include "meta.hh"
#include "unicode.hh"
@@ -62,6 +63,15 @@ enum class ObjectFlags
constexpr bool with_bit_ops(Meta::Type<ObjectFlags>) { return true; }
+constexpr auto enum_desc(Meta::Type<ObjectFlags>)
+{
+ return make_array<EnumDesc<ObjectFlags>, 3>({
+ { ObjectFlags::ToBegin, "to_begin" },
+ { ObjectFlags::ToEnd, "to_end" },
+ { ObjectFlags::Inner, "inner" },
+ });
+}
+
template<WordType word_type>
Optional<Selection>
select_word(const Context& context, const Selection& selection,