Refactor nextbuffer_cmd
This commit is contained in:
parent
0f9b210e3f
commit
2cf45ddb21
|
@ -377,15 +377,8 @@ const CommandDesc buffer_cmd = {
|
|||
}
|
||||
};
|
||||
|
||||
const CommandDesc nextbuffer_cmd = {
|
||||
"nextbuffer",
|
||||
"nb",
|
||||
"nextbuffer: move to the next buffer in the list",
|
||||
no_params,
|
||||
CommandFlags::None,
|
||||
CommandHelper{},
|
||||
CommandCompleter{},
|
||||
[](const ParametersParser& parser, Context& context)
|
||||
template<bool next>
|
||||
void cycle_buffer(const ParametersParser& parser, Context& context)
|
||||
{
|
||||
Buffer* oldbuf = &context.buffer();
|
||||
auto it = find_if(BufferManager::instance(),
|
||||
|
@ -393,8 +386,19 @@ const CommandDesc nextbuffer_cmd = {
|
|||
{ return lhs.get() == oldbuf; });
|
||||
|
||||
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())
|
||||
it = BufferManager::instance().begin();
|
||||
}
|
||||
|
||||
Buffer* newbuf = it->get();
|
||||
|
||||
|
@ -405,6 +409,27 @@ const CommandDesc nextbuffer_cmd = {
|
|||
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>
|
||||
|
@ -1549,7 +1574,8 @@ void register_commands()
|
|||
register_command(write_quit_cmd);
|
||||
register_command(force_write_quit_cmd);
|
||||
register_command(buffer_cmd);
|
||||
register_command(nextbuffer_cmd);
|
||||
register_command(buffernext_cmd);
|
||||
register_command(bufferprev_cmd);
|
||||
register_command(delbuf_cmd);
|
||||
register_command(force_delbuf_cmd);
|
||||
register_command(namebuf_cmd);
|
||||
|
|
Loading…
Reference in New Issue
Block a user