From 6cb97e3cbabd61ab5e4da79891724aae9d72b02f Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Fri, 7 Oct 2016 11:08:23 -0400 Subject: [PATCH] Only add the newline for new files. Existing files without eols should not get eols added. Also fixed byrune to allow placing the cursor just after the last rune in the document --- buf.c | 7 +++---- foo | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 foo diff --git a/buf.c b/buf.c index 9385113..dbfa318 100644 --- a/buf.c +++ b/buf.c @@ -13,10 +13,9 @@ void buf_load(Buf* buf, char* path) { while (RUNE_EOF != (r = fgetrune(in))) buf_ins(buf, i++, r); fclose(in); - } - /* Make sure it ends with a newline */ - if (r != '\n') + } else { buf_ins(buf, i, (Rune)'\n'); + } buf->insert_mode = false; } @@ -122,7 +121,7 @@ unsigned buf_byrune(Buf* buf, unsigned pos, int count) { if (move < 0) { if (pos > 0) pos--; } else { - if (pos < buf_end(buf)-1) pos++; + if (pos < buf_end(buf)) pos++; } return pos; } diff --git a/foo b/foo new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/foo @@ -0,0 +1 @@ +foo \ No newline at end of file -- 2.49.0