delete buffer deletes the current buffer when no params given

This commit is contained in:
Maxime Coste 2012-06-14 18:05:42 +00:00
parent eb34f6db73
commit 0e8add34ae

View File

@ -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)