From: Michael D. Lowis Date: Fri, 17 Mar 2017 17:18:41 +0000 (-0400) Subject: Make sure files end in newlines X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2812eb21f2b71a8afd2a4f453a81c39d179c2672;p=projs%2Ftide.git Make sure files end in newlines --- diff --git a/TODO.md b/TODO.md index c43e099..2efdf12 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ Up Next: * picker should only draw visible lines -* files should always end in newlines * ctrl+d on last line segfaults/asserts * Tweak the scrollbar for use with the picker diff --git a/docs/crlf.txt b/docs/crlf.txt index e6c3387..dab8c54 100644 Binary files a/docs/crlf.txt and b/docs/crlf.txt differ diff --git a/docs/lf.txt b/docs/lf.txt index e44b242..d8027d5 100644 Binary files a/docs/lf.txt and b/docs/lf.txt differ diff --git a/lib/buf.c b/lib/buf.c index 22e1281..7164974 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -234,6 +234,12 @@ unsigned buf_load(Buf* buf, char* path) { void buf_save(Buf* buf) { if (0 == buf_end(buf)) return; + + /* text files should always end in a new line. If we detected a + binary file or at least a non-utf8 file, skip this part. */ + if (!buf_iseol(buf, buf_end(buf)-1) && (buf->charset != BINARY)) + buf_insert(buf, false, buf_end(buf), '\n'); + size_t wrlen = 0; if (!buf->path) return; FMap file = mmap_readwrite(buf->path, buf_end(buf) * UTF_MAX);