mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-24 03:56:32 +03:00
Change remove-hooks to take a regular expression
All hooks whose group match this regex will be removed. Fixes #2380.
This commit is contained in:
parent
b8d312cfe0
commit
0c3d9ccd20
@ -3,6 +3,11 @@
|
||||
This changelog contains major and/or breaking changes to Kakoune between
|
||||
released versions.
|
||||
|
||||
== Development version
|
||||
|
||||
* `remove-hooks` <group> argument is now a regex and removes all
|
||||
hooks whose group matches it.
|
||||
|
||||
== Kakoune 2018.09.04
|
||||
|
||||
This version contains a significant overhaul of various Kakoune
|
||||
|
@ -30,7 +30,7 @@ remove-hooks <scope> <group>
|
||||
----------------------------
|
||||
|
||||
A call to the command above will remove every hooks in *scope* that are part
|
||||
of the given *group*.
|
||||
of whose group match the given *group* regex.
|
||||
|
||||
Hooks declared with the `-once` switch are automatically removed after running.
|
||||
|
||||
|
@ -867,7 +867,7 @@ const CommandDesc add_hook_cmd = {
|
||||
const CommandDesc remove_hook_cmd = {
|
||||
"remove-hooks",
|
||||
"rmhooks",
|
||||
"remove-hooks <scope> <group>: remove all hooks whose group is <group>",
|
||||
"remove-hooks <scope> <group>: remove all hooks whose group matches the regex <group>",
|
||||
ParameterDesc{ {}, ParameterDesc::Flags::None, 2, 2 },
|
||||
CommandFlags::None,
|
||||
CommandHelper{},
|
||||
@ -888,7 +888,7 @@ const CommandDesc remove_hook_cmd = {
|
||||
},
|
||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
||||
{
|
||||
get_scope(parser[0], context).hooks().remove_hooks(parser[1]);
|
||||
get_scope(parser[0], context).hooks().remove_hooks(Regex{parser[1]});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,15 +32,13 @@ void HookManager::add_hook(StringView hook_name, String group, HookFlags flags,
|
||||
hooks.emplace_back(new Hook{std::move(group), flags, std::move(filter), std::move(commands)});
|
||||
}
|
||||
|
||||
void HookManager::remove_hooks(StringView group)
|
||||
void HookManager::remove_hooks(const Regex& regex)
|
||||
{
|
||||
if (group.empty())
|
||||
throw runtime_error("invalid id");
|
||||
for (auto& list : m_hooks)
|
||||
{
|
||||
auto it = std::remove_if(list.value.begin(), list.value.end(),
|
||||
[&](const std::unique_ptr<Hook>& h)
|
||||
{ return h->group == group; });
|
||||
{ return regex_match(h->group.begin(), h->group.end(), regex); });
|
||||
if (not m_running_hooks.empty()) // we are running some hooks, defer deletion
|
||||
m_hooks_trash.insert(m_hooks_trash.end(), std::make_move_iterator(it),
|
||||
std::make_move_iterator(list.value.end()));
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
void add_hook(StringView hook_name, String group, HookFlags flags,
|
||||
Regex filter, String commands);
|
||||
void remove_hooks(StringView group);
|
||||
void remove_hooks(const Regex& regex);
|
||||
CandidateList complete_hook_group(StringView prefix, ByteCount pos_in_token);
|
||||
void run_hook(StringView hook_name, StringView param,
|
||||
Context& context);
|
||||
|
1
test/hooks/remove-regex/cmd
Normal file
1
test/hooks/remove-regex/cmd
Normal file
@ -0,0 +1 @@
|
||||
if<esc>:remove-hooks global group[12]<ret>if<esc>
|
1
test/hooks/remove-regex/in
Normal file
1
test/hooks/remove-regex/in
Normal file
@ -0,0 +1 @@
|
||||
|
1
test/hooks/remove-regex/out
Normal file
1
test/hooks/remove-regex/out
Normal file
@ -0,0 +1 @@
|
||||
foof
|
2
test/hooks/remove-regex/rc
Normal file
2
test/hooks/remove-regex/rc
Normal file
@ -0,0 +1,2 @@
|
||||
hook global -group group1 InsertChar f %{ exec o }
|
||||
hook global -group group2 InsertChar f %{ exec o }
|
Loading…
Reference in New Issue
Block a user