From 2b2474b2d141f589692e068ff505abfd76f149e9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 28 Dec 2012 14:07:35 +0100 Subject: [PATCH] add a force mode to delete buffer (db!) --- src/commands.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 5060f0c4..6f32be9f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -225,6 +225,7 @@ void show_buffer(const CommandParameters& params, Context& context) } } +template void delete_buffer(const CommandParameters& params, Context& context) { if (params.size() > 1) @@ -241,7 +242,7 @@ void delete_buffer(const CommandParameters& params, Context& context) if (not buffer) throw runtime_error("buffer " + buffer_name + " does not exists"); } - if (buffer->flags() & Buffer::Flags::File and buffer->is_modified()) + if (not force and (buffer->flags() & Buffer::Flags::File) and buffer->is_modified()) throw runtime_error("buffer " + buffer->name() + " is modified"); if (manager.count() == 1) @@ -688,7 +689,8 @@ void register_commands() { return BufferManager::instance().complete_buffername(prefix, cursor_pos); } }); cm.register_commands({ "b", "buffer" }, show_buffer, buffer_completer); - cm.register_commands({ "db", "delbuf" }, delete_buffer, buffer_completer); + cm.register_commands({ "db", "delbuf" }, delete_buffer, buffer_completer); + cm.register_commands({ "db!", "delbuf!" }, delete_buffer, buffer_completer); cm.register_commands({ "ah", "addhl" }, add_highlighter, [](const Context& context, const CommandParameters& params,