diff --git a/docs/en/blank.md b/docs/en/blank.md index cf75eee..bbabc93 100644 --- a/docs/en/blank.md +++ b/docs/en/blank.md @@ -7,8 +7,9 @@ blank have four configurable items 1. enable 2. notify 3. chars -4. style -5. exclude_filetype +4. tab_chars +5. style +6. exclude_filetype `enable` is used to control whether enable hl_blank, if set it to false, its usercmd and autocmd will not set, so it will not work @@ -27,6 +28,8 @@ chars = { }, ``` +`tab_chars` is used to configure what char to render the ``, it is a table likes the `chars` table. + `style` is a RGB string or RGB string list, if it is a table, it will choice different color to render different blank (indent) `exclude_filetype` is opposite of support_filetypes, it is a lua table like this, same as chunk mod diff --git a/docs/zh_CN/blank.md b/docs/zh_CN/blank.md index ccbb5e4..44a5212 100644 --- a/docs/zh_CN/blank.md +++ b/docs/zh_CN/blank.md @@ -7,8 +7,9 @@ blank mod 有四个配置项 1. enable 2. notify 3. chars -4. style -5. exclude_filetype +4. tab_chars +5. style +6. exclude_filetype `enable` 是用来控制该 mod 是否启动的,如果设置为 false,其所携带的 usercmd 和 autocmd 均不会产生,此时该 mod 关闭 @@ -27,6 +28,8 @@ chars = { }, ``` +`tab_chars` 是一个 lua 表,其中的字符用来指示如何渲染 `` 字符,它和`chars`类似。 + `style` 是一个 RGB 字符串或者一个表,如果是表,他将会使用不同颜色来渲染 blank `exclude_filetype` 是 support_filetype 的反面,用来控制在哪些文件类型不渲染 blank,默认的 exclude_filetypes 可以在 [default config](../../lua/hlchunk/utils/filetype.lua) 中找到 diff --git a/lua/hlchunk/mods/blank.lua b/lua/hlchunk/mods/blank.lua index 887a722..b9a41a6 100644 --- a/lua/hlchunk/mods/blank.lua +++ b/lua/hlchunk/mods/blank.lua @@ -21,6 +21,7 @@ local blank_mod = BaseMod:new({ chars = { "․", }, + tab_chars = {}, style = { api.nvim_get_hl(0, { name = "Whitespace" }), }, @@ -38,8 +39,16 @@ function blank_mod:render_line(index, indent) local render_char_num = math.floor(indent / shiftwidth) local win_info = fn.winsaveview() local text = "" - for _ = 1, render_char_num do - text = text .. "." .. (" "):rep(shiftwidth - 1) + + local space_tab = ("\t"):rep(vim.o.tabstop) + local line_val = fn.getline(index):gsub("\t", space_tab) + for i = 1, render_char_num do + local char = line_val:sub(shiftwidth * i - 1, shiftwidth * i - 1) + if char == "\t" then + text = text .. ("t") .. (" "):rep(shiftwidth - 1) + elseif char ~= "" then + text = text .. "." .. (" "):rep(shiftwidth - 1) + end end text = text:sub(win_info.leftcol + 1) @@ -50,7 +59,14 @@ function blank_mod:render_line(index, indent) count = count + 1 local Blank_chars_num = Array:from(self.options.chars):size() local Blank_style_num = Array:from(self.options.style):size() - local char = self.options.chars[(count - 1) % Blank_chars_num + 1]:rep(shiftwidth) + + local char + if self.options.tab_chars and c:match("t") then + char = self.options.tab_chars[(count - 1) % Blank_chars_num + 1]:rep(shiftwidth) + else + char = self.options.chars[(count - 1) % Blank_chars_num + 1]:rep(shiftwidth) + end + local style = "HLBlank" .. tostring((count - 1) % Blank_style_num + 1) row_opts.virt_text = { { char, style } } row_opts.virt_text_win_col = i - 1