diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-08-07 23:20:11 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-08-07 23:20:11 +0200 |
| commit | 207f2f6bb9cbf65b9db61b766fc7a39d8c2d38d3 (patch) | |
| tree | 398aadf83a60b2b805e9ee3d04c6116e2eb425a8 /src | |
| parent | dd05d6c6f57c0b8f2f956b169bcdbb93e70147dd (diff) | |
edit commands accept a -scratch flag to edit not to be saved file
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/commands.cc b/src/commands.cc index 929911f1..44e754ed 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -232,24 +232,32 @@ Buffer* open_or_create(const String& filename) template<bool force_reload> void edit(const CommandParameters& params, Context& context) { - if (params.size() == 0 or params.size() > 3) + ParametersParser parser(params, { { "scratch", false } }); + + const size_t param_count = parser.positional_count(); + if (param_count == 0 or param_count > 3) throw wrong_argument_count(); - const String& filename = params[0]; + const String& filename = parser[0]; Buffer* buffer = nullptr; if (not force_reload) buffer = BufferManager::instance().get_buffer(filename); if (not buffer) - buffer = open_or_create(filename); + { + if (parser.has_option("scratch")) + buffer = new Buffer(filename, Buffer::Type::Scratch); + else + buffer = open_or_create(filename); + } Window& window = *buffer->get_or_create_window(); - if (params.size() > 1) + if (param_count > 1) { - int line = std::max(0, str_to_int(params[1]) - 1); - int column = params.size() > 2 ? - std::max(0, str_to_int(params[2]) - 1) : 0; + int line = std::max(0, str_to_int(parser[1]) - 1); + int column = param_count > 2 ? + std::max(0, str_to_int(parser[2]) - 1) : 0; window.select(window.buffer().iterator_at({line, column})); } |
