diff options
author | glepnir <glephunter@gmail.com> | 2024-02-29 18:50:40 +0800 |
---|---|---|
committer | glepnir <glephunter@gmail.com> | 2024-03-01 14:35:52 +0800 |
commit | a5ade3c63d88e93244c43ff0f0635f4774f890ce (patch) | |
tree | 8c6122e85e42005d592a11536788dd8a522d8730 /runtime/lua/vim/snippet.lua | |
parent | 0eaae1bc057a2a4672d3e485498137a0d2282ad3 (diff) | |
download | rneovim-a5ade3c63d88e93244c43ff0f0635f4774f890ce.tar.gz rneovim-a5ade3c63d88e93244c43ff0f0635f4774f890ce.tar.bz2 rneovim-a5ade3c63d88e93244c43ff0f0635f4774f890ce.zip |
fix(snippet): correct indent with newline
Problem: snippet newline use before line indent after expand.
Solution: it should level + 1.
Diffstat (limited to 'runtime/lua/vim/snippet.lua')
-rw-r--r-- | runtime/lua/vim/snippet.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua index 09b7576d97..a660d6f301 100644 --- a/runtime/lua/vim/snippet.lua +++ b/runtime/lua/vim/snippet.lua @@ -446,14 +446,18 @@ function M.expand(input) base_indent = base_indent .. (snippet_lines[#snippet_lines]:match('(^%s*)%S') or '') --- @type string end + local shiftwidth = vim.fn.shiftwidth() + local curbuf = vim.api.nvim_get_current_buf() + local expandtab = vim.bo[curbuf].expandtab local lines = vim.iter.map(function(i, line) -- Replace tabs by spaces. - if vim.o.expandtab then - line = line:gsub('\t', (' '):rep(vim.fn.shiftwidth())) --- @type string + if expandtab then + line = line:gsub('\t', (' '):rep(shiftwidth)) --- @type string end -- Add the base indentation. if i > 1 then - line = base_indent .. line + line = #line ~= 0 and base_indent .. line + or (expandtab and (' '):rep(shiftwidth) or '\t'):rep(vim.fn.indent('.') / shiftwidth + 1) end return line end, ipairs(text_to_lines(text))) |