aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/builtin.txt3
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua3
-rw-r--r--runtime/lua/vim/snippet.lua10
3 files changed, 13 insertions, 3 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 68d1874542..be81451d08 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -5486,6 +5486,9 @@ printf({fmt}, {expr1} ...) *printf()*
echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
< 1.41
+ You will get an overflow error |E1510|, when the field-width
+ or precision will result in a string longer than 6400 chars.
+
*E1500*
You cannot mix positional and non-positional arguments: >vim
echo printf("%s%1$s", "One", "Two")
diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
index fb5e2a727e..da251f89ad 100644
--- a/runtime/lua/vim/_meta/vimfn.lua
+++ b/runtime/lua/vim/_meta/vimfn.lua
@@ -6520,6 +6520,9 @@ function vim.fn.prevnonblank(lnum) end
--- echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
--- < 1.41
---
+--- You will get an overflow error |E1510|, when the field-width
+--- or precision will result in a string longer than 6400 chars.
+---
--- *E1500*
--- You cannot mix positional and non-positional arguments: >vim
--- echo printf("%s%1$s", "One", "Two")
diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua
index 5e60efa778..2ffd89367f 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)))