From 0e8add34ae137c8f314146c647baffc7e65290f9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 14 Jun 2012 18:05:42 +0000 Subject: [PATCH] delete buffer deletes the current buffer when no params given --- src/commands.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 347fa539..74f71820 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -317,21 +317,26 @@ void show_buffer(const CommandParameters& params, const Context& context) void delete_buffer(const CommandParameters& params, const Context& context) { - if (params.size() != 1) + if (params.size() > 1) throw wrong_argument_count(); BufferManager& manager = BufferManager::instance(); - - Buffer* buffer = manager.get_buffer(params[0]); - if (not buffer) - throw runtime_error("buffer " + params[0] + " does not exists"); + Buffer* buffer = nullptr; + if (params.empty()) + buffer = &context.buffer(); + else + { + buffer = manager.get_buffer(params[0]); + if (not buffer) + throw runtime_error("buffer " + params[0] + " does not exists"); + } if (buffer->type()!= Buffer::Type::Scratch and buffer->is_modified()) throw runtime_error("buffer " + params[0] + " is modified"); if (&main_context.buffer() == buffer) { if (manager.count() == 1) - throw runtime_error("buffer " + params[0] + " is the last one"); + throw runtime_error("buffer " + buffer->name() + " is the last one"); for (Buffer& buf : manager) { if (&buf != buffer)