From 0d02884572e7867420f81aca45c2c3f413000720 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Thu, 16 Aug 2018 11:38:35 +0900 Subject: [PATCH] Fix end-of-file line feed handling --- apps/bim.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/bim.c b/apps/bim.c index 0358a6cb..b8754cbb 100644 --- a/apps/bim.c +++ b/apps/bim.c @@ -677,6 +677,10 @@ void add_buffer(uint8_t * buf, int size) { state = 0; } } + if (env->lines[env->line_no-1]->actual == 0) { + /* Remove blank line from end */ + remove_line(env->lines, env->line_no-1); + } } @@ -797,6 +801,7 @@ void write_file(char * file) { if (!f) { render_error("Failed to open file for writing."); + return; } int i, j; @@ -813,9 +818,7 @@ void write_file(char * file) { fwrite(tmp, i, 1, f); } } - if (i + 1 < env->line_count) { - fputc('\n', f); - } + fputc('\n', f); } fclose(f);