diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-08-25 12:23:05 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2023-08-27 19:27:25 +0100 |
commit | abb8c2c453d1e084f8ab3e9bbaa8b27515c81a9f (patch) | |
tree | 2ccdeaa0e098efe92d32a5c81fd5263468b9da40 /runtime/lua/editorconfig.lua | |
parent | 63802a1dbf0e698b5a8a48bfcb247698a7e07293 (diff) | |
download | rneovim-abb8c2c453d1e084f8ab3e9bbaa8b27515c81a9f.tar.gz rneovim-abb8c2c453d1e084f8ab3e9bbaa8b27515c81a9f.tar.bz2 rneovim-abb8c2c453d1e084f8ab3e9bbaa8b27515c81a9f.zip |
fix(editorconfig): do not set 'endofline'
Problem:
'endofline' can be used to detect if a file ends of <EOL>, however
editorconfig can break this.
Solution:
Set 'endofline' during BufWritePre
Fixes: #24869
Diffstat (limited to 'runtime/lua/editorconfig.lua')
-rw-r--r-- | runtime/lua/editorconfig.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index 48faa54d97..49d63807a6 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -112,7 +112,20 @@ end function M.properties.insert_final_newline(bufnr, val) assert(val == 'true' or val == 'false', 'insert_final_newline must be either "true" or "false"') vim.bo[bufnr].fixendofline = val == 'true' - vim.bo[bufnr].endofline = val == 'true' + + -- 'endofline' can be read to detect if the file contains a final newline, + -- so only change 'endofline' right before writing the file + local endofline = val == 'true' + if vim.bo[bufnr].endofline ~= endofline then + vim.api.nvim_create_autocmd('BufWritePre', { + group = 'editorconfig', + buffer = bufnr, + once = true, + callback = function() + vim.bo[bufnr].endofline = endofline + end, + }) + end end --- Modified version of |glob2regpat()| that does not match path separators on *. |