From f6308409a16bb80f8daaf14d4e9ed25f6801d3d3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 24 Jul 2013 13:38:26 +0100 Subject: [PATCH] pipe: auto insert and end of line if needed --- src/normal.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 4c50bc03..f1e0cac2 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -261,9 +261,17 @@ void pipe(Context& context) Editor& editor = context.editor(); std::vector strings; for (auto& sel : context.editor().selections()) - strings.push_back(ShellManager::instance().pipe(content(context.buffer(), sel), - cmdline, context, {}, - EnvVarMap{})); + { + auto str = content(context.buffer(), sel); + bool insert_eol = str.back() != '\n'; + if (insert_eol) + str += '\n'; + str = ShellManager::instance().pipe(str, cmdline, context, + {}, EnvVarMap{}); + if (insert_eol and str.back() == '\n') + str = str.substr(0, str.length()-1); + strings.push_back(str); + } editor.insert(strings, InsertMode::Replace); }); }