mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-15 01:11:09 +03:00
Add object mode expansions
This commit is contained in:
parent
e169a1893b
commit
7cf6eddc30
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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{¶ms.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{¶ms.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{¶ms.reg, 1} },
|
||||
{ "select_mode", option_to_string(mode) },
|
||||
{ "object_flags", option_to_string(flags) }
|
||||
};
|
||||
command(context, std::move(env_vars));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user