From 6f135c0c8e4d4d5b66cd6b56394ad7d690a16252 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 24 Jan 2022 21:48:51 +1100 Subject: [PATCH] Do not insert any end-of-line when piping data out This will unfortunately break some use case which will require using wrapper scripts to add the necessary newline. It is however harder to do the contrary, and it makes a lot of other use case possible, such as checksuming. Fixes #3669 --- src/main.cc | 3 +++ src/normal.cc | 13 +++---------- test/regression/3669-pipe-adds-extra-newline/cmd | 1 + test/regression/3669-pipe-adds-extra-newline/in | 1 + test/regression/3669-pipe-adds-extra-newline/out | 1 + 5 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 test/regression/3669-pipe-adds-extra-newline/cmd create mode 100644 test/regression/3669-pipe-adds-extra-newline/in create mode 100644 test/regression/3669-pipe-adds-extra-newline/out diff --git a/src/main.cc b/src/main.cc index e078efc5..98e33d83 100644 --- a/src/main.cc +++ b/src/main.cc @@ -44,6 +44,9 @@ struct { unsigned int version; StringView notes; } constexpr version_notes[] = { { + 0, + "» pipe commands do not append final end-of-lines anymore\n" + }, { 20211107, "» colored and curly underlines support (undocumented in 20210828)\n" }, { diff --git a/src/normal.cc b/src/normal.cc index 4e94fe57..ca7063fd 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -582,10 +582,6 @@ void pipe(Context& context, NormalParams params) const auto end = changes_tracker.get_new_coord_tolerant(sel.max()); String in = buffer.string(beg, buffer.char_next(end)); - const bool insert_eol = in.back() != '\n'; - if (insert_eol) - in += '\n'; - // Needed in case we read selections inside the cmdline context.selections_write_only().set({keep_direction(Selection{beg, end}, sel)}, 0); @@ -593,12 +589,9 @@ void pipe(Context& context, NormalParams params) cmdline, context, in, ShellManager::Flags::WaitForStdout).first; - if (insert_eol) - { - in.resize(in.length()-1, 0); - if (not out.empty() and out.back() == '\n') - out.resize(out.length()-1, 0); - } + if (in.back() != '\n' and not out.empty() and out.back() == '\n') + out.resize(out.length()-1, 0); + auto new_end = apply_diff(buffer, beg, in, out); if (new_end != beg) new_sels.push_back(keep_direction({beg, buffer.char_prev(new_end), std::move(sel.captures())}, sel)); diff --git a/test/regression/3669-pipe-adds-extra-newline/cmd b/test/regression/3669-pipe-adds-extra-newline/cmd new file mode 100644 index 00000000..5d3dd21b --- /dev/null +++ b/test/regression/3669-pipe-adds-extra-newline/cmd @@ -0,0 +1 @@ +|cksum diff --git a/test/regression/3669-pipe-adds-extra-newline/in b/test/regression/3669-pipe-adds-extra-newline/in new file mode 100644 index 00000000..c2267c2e --- /dev/null +++ b/test/regression/3669-pipe-adds-extra-newline/in @@ -0,0 +1 @@ +%(foo) diff --git a/test/regression/3669-pipe-adds-extra-newline/out b/test/regression/3669-pipe-adds-extra-newline/out new file mode 100644 index 00000000..972abe5a --- /dev/null +++ b/test/regression/3669-pipe-adds-extra-newline/out @@ -0,0 +1 @@ +2470157969 3