Refactor nextbuffer_cmd
This commit is contained in:
parent
0f9b210e3f
commit
2cf45ddb21
|
@ -377,24 +377,28 @@ const CommandDesc buffer_cmd = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const CommandDesc nextbuffer_cmd = {
|
template<bool next>
|
||||||
"nextbuffer",
|
void cycle_buffer(const ParametersParser& parser, Context& context)
|
||||||
"nb",
|
{
|
||||||
"nextbuffer: move to the next buffer in the list",
|
|
||||||
no_params,
|
|
||||||
CommandFlags::None,
|
|
||||||
CommandHelper{},
|
|
||||||
CommandCompleter{},
|
|
||||||
[](const ParametersParser& parser, Context& context)
|
|
||||||
{
|
|
||||||
Buffer* oldbuf = &context.buffer();
|
Buffer* oldbuf = &context.buffer();
|
||||||
auto it = find_if(BufferManager::instance(),
|
auto it = find_if(BufferManager::instance(),
|
||||||
[oldbuf](const SafePtr<Buffer>& lhs)
|
[oldbuf](const SafePtr<Buffer>& lhs)
|
||||||
{ return lhs.get() == oldbuf; });
|
{ return lhs.get() == oldbuf; });
|
||||||
|
|
||||||
kak_assert(it != BufferManager::instance().end());
|
kak_assert(it != BufferManager::instance().end());
|
||||||
|
|
||||||
|
if (not next)
|
||||||
|
{
|
||||||
|
if (it == BufferManager::instance().begin())
|
||||||
|
it = BufferManager::instance().end();
|
||||||
|
|
||||||
|
it = std::prev(it,1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (++it == BufferManager::instance().end())
|
if (++it == BufferManager::instance().end())
|
||||||
it = BufferManager::instance().begin();
|
it = BufferManager::instance().begin();
|
||||||
|
}
|
||||||
|
|
||||||
Buffer* newbuf = it->get();
|
Buffer* newbuf = it->get();
|
||||||
|
|
||||||
|
@ -404,7 +408,28 @@ const CommandDesc nextbuffer_cmd = {
|
||||||
context.push_jump();
|
context.push_jump();
|
||||||
context.change_buffer(*newbuf);
|
context.change_buffer(*newbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CommandDesc buffernext_cmd = {
|
||||||
|
"buffernext",
|
||||||
|
"bn",
|
||||||
|
"buffernext: move to the next buffer in the list",
|
||||||
|
no_params,
|
||||||
|
CommandFlags::None,
|
||||||
|
CommandHelper{},
|
||||||
|
CommandCompleter{},
|
||||||
|
cycle_buffer<true>
|
||||||
|
};
|
||||||
|
|
||||||
|
const CommandDesc bufferprev_cmd = {
|
||||||
|
"bufferprev",
|
||||||
|
"bp",
|
||||||
|
"bufferprev: move to the previous buffer in the list",
|
||||||
|
no_params,
|
||||||
|
CommandFlags::None,
|
||||||
|
CommandHelper{},
|
||||||
|
CommandCompleter{},
|
||||||
|
cycle_buffer<false>
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool force>
|
template<bool force>
|
||||||
|
@ -1549,7 +1574,8 @@ void register_commands()
|
||||||
register_command(write_quit_cmd);
|
register_command(write_quit_cmd);
|
||||||
register_command(force_write_quit_cmd);
|
register_command(force_write_quit_cmd);
|
||||||
register_command(buffer_cmd);
|
register_command(buffer_cmd);
|
||||||
register_command(nextbuffer_cmd);
|
register_command(buffernext_cmd);
|
||||||
|
register_command(bufferprev_cmd);
|
||||||
register_command(delbuf_cmd);
|
register_command(delbuf_cmd);
|
||||||
register_command(force_delbuf_cmd);
|
register_command(force_delbuf_cmd);
|
||||||
register_command(namebuf_cmd);
|
register_command(namebuf_cmd);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user