summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJimmy Thrasher <jimmy@jimmythrasher.com>2015-04-09 10:14:28 -0400
committerJimmy Thrasher <jimmy@jimmythrasher.com>2015-04-09 10:14:32 -0400
commitba59033935d643f4a7f50da35c7cd033c5790252 (patch)
tree016f512e00b294c3a7ceb681f41623fc3399e081 /src
parentac70b3e6d76dc5c8f8c3619ca953e41bcf22d325 (diff)
Add nextbuffer command
Wraps around at the end. If only 1 buffer loaded, does nothing.
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc49
1 files changed, 49 insertions, 0 deletions
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 == &current_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<bool force>
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);