summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-31 15:33:21 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-31 15:33:21 -0500
commitd7e2d3d4f13c5f6e52ad36aa890eb09a650d1238 (patch)
tree9e4d883716a34fcbaef46fe943bb35242a33b675 /buffer.c
parent5a7ca9106a305555922ef78c2dd84ab8779c7718 (diff)
fixed Ctrl+Left/Right being double-set, cleaned up core options code, auto-add-newline
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index 3649a68..41c5d09 100644
--- a/buffer.c
+++ b/buffer.c
@@ -643,6 +643,7 @@ void buffer_new_file(TextBuffer *buffer, char const *filename) {
// Save the buffer to its current filename. This will rewrite the entire file, regardless of
// whether there are any unsaved changes.
bool buffer_save(TextBuffer *buffer) {
+ Settings const *settings = buffer_settings(buffer);
if (!buffer->is_line_buffer && buffer->filename) {
FILE *out = fopen(buffer->filename, "wb");
if (out) {
@@ -659,6 +660,13 @@ bool buffer_save(TextBuffer *buffer) {
if (line != end-1) {
putc('\n', out);
+ } else {
+ if (settings->auto_add_newline) {
+ if (line->len) {
+ // if the last line isn't empty, add a newline.
+ putc('\n', out);
+ }
+ }
}
}
if (ferror(out)) {