From 61e4707a61e69553cb4600f5dcb75a10aae58da2 Mon Sep 17 00:00:00 2001 From: glepnir Date: Sun, 28 Apr 2024 21:06:25 +0800 Subject: [PATCH] better behavior on blank line --- lua/indentmini/init.lua | 6 +++--- test.lua | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test.lua diff --git a/lua/indentmini/init.lua b/lua/indentmini/init.lua index df430cd..b504898 100644 --- a/lua/indentmini/init.lua +++ b/lua/indentmini/init.lua @@ -32,6 +32,7 @@ local function indentline(opt) return end local line_is_empty = #lines[1] == 0 + local shiftw = vim.fn.shiftwidth() if indent == 0 and line_is_empty then local prev_row = row - 1 while true do @@ -42,15 +43,14 @@ local function indentline(opt) local prev_indent = indent_fn(prev_row + 1) if prev_indent == 0 and #lines[1] ~= 0 then break - else - indent = prev_indent + elseif #lines[1] ~= 0 and prev_indent > 0 then + indent = prev_indent + shiftw break end prev_row = prev_row - 1 end end - local shiftw = vim.fn.shiftwidth() local last_defined_level = 0 for i = 1, indent - 1, shiftw do local col = i - 1 diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..b46549d --- /dev/null +++ b/test.lua @@ -0,0 +1,9 @@ +local function test_tab() + if true then + if true then + if true then + print('hello') + end + end + end +end