From 4d230e4051983d965c92f43ecc955cce1ff5da5e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 23 Dec 2015 22:56:33 +0000 Subject: [PATCH] Support passing + parameter to specify the first buffer target line on open Fixes #336 --- src/main.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main.cc b/src/main.cc index 6e99e12d..267eec23 100644 --- a/src/main.cc +++ b/src/main.cc @@ -413,7 +413,7 @@ int run_client(StringView session, StringView init_command) int run_server(StringView session, StringView init_command, bool ignore_kakrc, bool daemon, bool dummy_ui, - ConstArrayView files) + ConstArrayView files, LineCount target_line) { static bool terminate = false; if (daemon) @@ -510,6 +510,10 @@ int run_server(StringView session, StringView init_command, local_client = client_manager.create_client( create_local_ui(dummy_ui), get_env_vars(), init_command); + auto& selections = local_client->context().selections_write_only(); + auto& buffer = selections.buffer(); + selections = SelectionList(buffer, buffer.clamp(target_line)); + if (startup_error) local_client->print_status({ "error during startup, see *debug* buffer for details", @@ -732,9 +736,21 @@ int main(int argc, char* argv[]) } else { + LineCount target_line = 0; Vector files; - for (size_t i = 0; i < parser.positional_count(); ++i) - files.emplace_back(parser[i]); + for (auto& name : parser) + { + if (not name.empty() and name[0_byte] == '+') + { + if (auto line = str_to_int_ifp(name.substr(1_byte))) + { + target_line = *line - 1; + continue; + } + } + + files.emplace_back(name); + } StringView session = parser.get_switch("s").value_or(StringView{}); try @@ -743,7 +759,7 @@ int main(int argc, char* argv[]) (bool)parser.get_switch("n"), (bool)parser.get_switch("d"), (bool)parser.get_switch("u"), - files); + files, target_line); } catch (convert_to_client_mode& convert) {