diff --git a/src/commands.cc b/src/commands.cc index e1cfcb10..1ba4a3a2 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -375,6 +375,54 @@ const CommandDesc buffer_cmd = { } }; +Buffer& next_buffer(Context& context) { + auto& buffer_manager = BufferManager::instance(); + if (buffer_manager.end()->get() == &context.buffer()) + { + return **buffer_manager.begin(); + } + else + { + bool found_current = false; + Buffer& current_buffer = context.buffer(); + for (auto& it : buffer_manager) + { + Buffer& buffer = *it; + if (&buffer == ¤t_buffer) + { + found_current = true; + } + else if (found_current) + { + return buffer; + } + } + + return **buffer_manager.begin(); + } +} + +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) + { + Buffer& nb = next_buffer(context); + BufferManager::instance().set_last_used_buffer(nb); + + if (&nb != &context.buffer()) + { + context.push_jump(); + context.change_buffer(nb); + } + } +}; + template void delete_buffer(const ParametersParser& parser, Context& context) { @@ -1497,6 +1545,7 @@ void register_commands() register_command(write_quit_cmd); register_command(force_write_quit_cmd); register_command(buffer_cmd); + register_command(nextbuffer_cmd); register_command(delbuf_cmd); register_command(force_delbuf_cmd); register_command(namebuf_cmd);