From d78fe81e21f23f0984ce80c9c47c7b81e903bdd7 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 24 Feb 2020 22:31:05 -0500 Subject: [PATCH] line_array insert for eofnewline and make default Makes the `eofnewline` option enabled by default. Fixes #1525 --- internal/buffer/save.go | 2 +- internal/config/settings.go | 2 +- runtime/help/options.md | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/buffer/save.go b/internal/buffer/save.go index 74b890eb..6f07ea6c 100644 --- a/internal/buffer/save.go +++ b/internal/buffer/save.go @@ -112,7 +112,7 @@ func (b *Buffer) saveToFile(filename string, withSudo bool) error { if b.Settings["eofnewline"].(bool) { end := b.End() if b.RuneAt(Loc{end.X, end.Y}) != '\n' { - b.Insert(end, "\n") + b.insert(end, []byte{'\n'}) } } diff --git a/internal/config/settings.go b/internal/config/settings.go index 81c431d8..5f5694e2 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -191,7 +191,7 @@ var defaultCommonSettings = map[string]interface{}{ "cursorline": true, "diffgutter": false, "encoding": "utf-8", - "eofnewline": false, + "eofnewline": true, "fastdirty": false, "fileformat": "unix", "filetype": "unknown", diff --git a/runtime/help/options.md b/runtime/help/options.md index 709bd5da..8b118380 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -85,9 +85,10 @@ Here are the available options: default value: `utf-8` -* `eofnewline`: micro will automatically add a newline to the file. +* `eofnewline`: micro will automatically add a newline to the end of the + file if one does not exist. - default value: `false` + default value: `true` * `fastdirty`: this determines what kind of algorithm micro uses to determine if a buffer is modified or not. When `fastdirty` is on, micro just uses a