From: Mike Lowis Date: Fri, 7 Oct 2016 15:08:23 +0000 (-0400) Subject: Only add the newline for new files. Existing files without eols should not get eols... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=6cb97e3cbabd61ab5e4da79891724aae9d72b02f;p=projs%2Ftide.git 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 --- 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