commit fcf598e79790a3156c277c065186599955017a0d
parent d9cb12f6e3e0610d62d74ffdc8784753bf7f1d4a
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 28 Mar 2022 11:15:04 +0200
execute: stay on the same line number when filtering the whole buffer
When the filter command makes just small, per-line changes, keeping the
cursor at the same line number allows the user to observe the effect of
the changes -- which is not possible when the cursor gets moved to the
end of the buffer.
This partially fulfills https://savannah.gnu.org/bugs/?57248.
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/files.c b/src/files.c
@@ -992,6 +992,7 @@ bool execute_command(const char *command)
/* The pipes through which text will be written and read. */
struct sigaction oldaction, newaction = {{0}};
/* Original and temporary handlers for SIGINT. */
+ ssize_t was_lineno = (openfile->mark ? 0 : openfile->current->lineno);
const bool should_pipe = (command[0] == '|');
FILE *stream;
@@ -1105,8 +1106,11 @@ bool execute_command(const char *command)
else
read_file(stream, 0, "pipe", TRUE);
- if (should_pipe && !ISSET(MULTIBUFFER))
+ if (should_pipe && !ISSET(MULTIBUFFER)) {
+ if (was_lineno)
+ goto_line_posx(was_lineno, 0);
add_undo(COUPLE_END, N_("filtering"));
+ }
/* Wait for the external command (and possibly data sender) to terminate. */
wait(NULL);