From 9a4831d5c2d9060d83743f881d71ae7cc0752fde Mon Sep 17 00:00:00 2001 From: Guldoman Date: Thu, 30 Nov 2023 16:51:10 +0100 Subject: [PATCH] Use `\r\n` for new files on Windows (#1596) * Use `\r\n` for new files on Windows * Add `config.line_endings` --- data/core/config.lua | 6 ++++++ data/core/doc/init.lua | 3 +++ 2 files changed, 9 insertions(+) diff --git a/data/core/config.lua b/data/core/config.lua index 2381639f..88f8d96d 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -153,6 +153,12 @@ config.tab_type = "soft" ---@type boolean config.keep_newline_whitespace = false +---Default line endings for new files. +--- +---Defaults to `crlf` (`\r\n`) on Windows and `lf` (`\n`) on everything else. +---@type "crlf" | "lf" +config.line_endings = PLATFORM == "Windows" and "crlf" or "lf" + ---Maximum number of characters per-line for the line guide. --- ---Defaults to 80. diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 3c0a30d7..e44610e5 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -28,6 +28,9 @@ function Doc:new(filename, abs_filename, new_file) self:load(filename) end end + if new_file then + self.crlf = config.line_endings == "crlf" + end end function Doc:reset()