aboutsummaryrefslogtreecommitdiff
path: root/plugins/indent_convert.lua
diff options
context:
space:
mode:
authorGuldoman <giulio.lettieri@gmail.com>2021-11-21 17:17:26 +0100
committerGuldoman <giulio.lettieri@gmail.com>2021-11-21 17:17:26 +0100
commit139886fe31ff462e78d30c85baf76a1bab17aabb (patch)
tree41f2583442182bfd66d5e89f5f4eea65c2729bd8 /plugins/indent_convert.lua
parentbcc2c09c4f900a1895e3a57b26e46b64a44c4671 (diff)
downloadlite-xl-plugins-139886fe31ff462e78d30c85baf76a1bab17aabb.tar.gz
lite-xl-plugins-139886fe31ff462e78d30c85baf76a1bab17aabb.zip
`indent_convert`: Use compatible `null` in patterns
As LuaJIT uses patterns from Lua 5.1, we have to use `%z` instead of `\0`.
Diffstat (limited to 'plugins/indent_convert.lua')
-rw-r--r--plugins/indent_convert.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/plugins/indent_convert.lua b/plugins/indent_convert.lua
index 61d4a98..c86686d 100644
--- a/plugins/indent_convert.lua
+++ b/plugins/indent_convert.lua
@@ -7,6 +7,8 @@ config.plugins.indent_convert = {
update_indent_type = true -- set to false to avoid updating the document indent type
}
+local zero_pattern = _VERSION == "Lua 5.1" and "%z" or "\0"
+
-- TODO: only set document indent type if there are no selections
-- TODO: correctly restore selections accounting for the offset caused by the conversion
@@ -47,12 +49,12 @@ local function spaces_replacer(text, indent_size)
-- find the longest repetition of indent_size*spaces
repeat
reps = reps + 1
- local s, _ = string.find(text, "%f[^\0\n]"..string.rep(spaces, reps))
+ local s, _ = string.find(text, "%f[^"..zero_pattern.."\n]"..string.rep(spaces, reps))
until not s
reps = reps - 1
while reps > 0 do
text, n = string.gsub(text,
- "(%f[^\0\n])("..string.rep(spaces, reps)..")",
+ "(%f[^"..zero_pattern.."\n])("..string.rep(spaces, reps)..")",
"%1"..string.rep("\t", reps))
total = total + n
reps = reps - 1
@@ -66,7 +68,7 @@ local function tabs_replacer(text, indent_size)
local n
-- replace the last tab before the text until there aren't anymore
repeat
- text, n = string.gsub(text, "(%f[^\0\n]\t*)(\t)", "%1"..spaces)
+ text, n = string.gsub(text, "(%f[^"..zero_pattern.."\n]\t*)(\t)", "%1"..spaces)
total = total + n
until n == 0
return text, total