Strip trailing newlines from editor output

This commit is contained in:
Přemysl Eric Janouch 2020-09-01 19:26:37 +02:00
parent b7c9bfd9f5
commit e49ff84b74
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 10 additions and 3 deletions

View File

@ -3177,9 +3177,16 @@ process_edited_input (struct app_context *ctx)
print_error ("%s: %s", "input editing failed", e->message); print_error ("%s: %s", "input editing failed", e->message);
error_free (e); error_free (e);
} }
else if (!ctx->input->vtable->replace_line (ctx->input, input.str)) else
{
// Strip trailing newlines, added automatically by editors
while (input.len && strchr ("\r\n", input.str[input.len - 1]))
input.str[--input.len] = 0;
if (!ctx->input->vtable->replace_line (ctx->input, input.str))
print_error ("%s: %s", "input editing failed", print_error ("%s: %s", "input editing failed",
"could not re-insert modified text"); "could not re-insert modified text");
}
if (unlink (ctx->editor_filename)) if (unlink (ctx->editor_filename))
print_error ("could not unlink `%s': %s", print_error ("could not unlink `%s': %s",