From 03976e0a016d9e4d403e02584f4a0661d8e7eca3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 13 Feb 2012 21:54:30 +0000 Subject: [PATCH] edit command supports optional line and column parameter --- src/main.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.cc b/src/main.cc index 27f8f09e..0136fd83 100644 --- a/src/main.cc +++ b/src/main.cc @@ -532,7 +532,7 @@ Buffer* open_or_create(const std::string& filename) template void edit(const CommandParameters& params, const Context& context) { - if (params.size() != 1) + if (params.size() == 0 or params.size() > 3) throw wrong_argument_count(); std::string filename = params[0]; @@ -543,7 +543,18 @@ void edit(const CommandParameters& params, const Context& context) if (not buffer) buffer = open_or_create(filename); - main_context = Context(*buffer->get_or_create_window()); + Window& window = *buffer->get_or_create_window(); + + if (params.size() > 1) + { + int line = std::max(0, atoi(params[1].c_str()) - 1); + int column = params.size() > 2 ? + std::max(0, atoi(params[2].c_str()) - 1) : 0; + + window.select(window.buffer().iterator_at({line, column})); + } + + main_context = Context(window); } void write_buffer(const CommandParameters& params, const Context& context)