Skip to content

Commit

Permalink
change default char style and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 4, 2024
1 parent 45469be commit 59d786d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ install with any plugin management or default vim package.

available config values in setup table.

- char -- string type default is ``,
- char -- string type default is ``,
- current -- boolean highlight current indent level
- exclude -- table type add exclude filetype in this table ie `{ 'markdown', 'xxx'}`

```lua
config = function()
require("indentmini").setup({}) -- use default config
require("indentmini").setup() -- use default config
end,
```

Expand Down
46 changes: 21 additions & 25 deletions lua/indentmini/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
local api = vim.api
local au, nvim_buf_set_extmark = api.nvim_create_autocmd, api.nvim_buf_set_extmark
local au, buf_set_extmark = api.nvim_create_autocmd, api.nvim_buf_set_extmark
local set_decoration_provider = api.nvim_set_decoration_provider
local ns = api.nvim_create_namespace('IndentLine')
local g = api.nvim_create_augroup('IndentMini', { clear = true })
local indent_fn = vim.fn.indent
local UP, DOWN, opt = -1, 1, {}
local UP, DOWN = -1, 1
local opt = {
config = {
virt_text_pos = 'overlay',
hl_mode = 'combine',
ephemeral = true,
},
}

---check column in screen
local function col_in_screen(col)
Expand Down Expand Up @@ -85,7 +93,7 @@ local function on_line(_, _, bufnr, row)
if line_is_empty and col > 0 then
opt.config.virt_text_win_col = i - 1
end
nvim_buf_set_extmark(bufnr, ns, row, col, opt.config)
buf_set_extmark(bufnr, ns, row, col, opt.config)
opt.config.virt_text_win_col = nil
api.nvim_set_hl(ns, hi_name, { link = 'IndentLine', default = true })
end
Expand All @@ -101,17 +109,14 @@ local function on_line(_, _, bufnr, row)
local curindent = indent_fn(line)
local srow = find_row(data.buf, line - 1, curindent, UP, false) or 0
local erow = find_row(data.buf, line - 1, curindent, DOWN, false) or 0
local hls = api.nvim_get_hl(ns, {})
--TODO(glepnir): can there use w0 or w$ for clear the visible screen indent highlight ?
for k, v in pairs(hls) do
for k, v in pairs(api.nvim_get_hl(ns, {}) or {}) do
if v.link and v.link == cur_hi then
api.nvim_set_hl(ns, k, { link = 'IndentLine', force = true })
end
end
if erow < 1 then
return
end

local level = math.floor(curindent / shiftw)
for i = srow + 1, erow, 1 do
api.nvim_set_hl(ns, ('IndentLine%d%d'):format(i + 1, level), { link = cur_hi })
Expand All @@ -123,23 +128,14 @@ end

return {
setup = function(conf)
opt = {
current = conf.current or true,
exclude = vim.tbl_extend(
'force',
{ 'dashboard', 'lazy', 'help', 'markdown', 'nofile', 'terminal' },
conf.exclude or {}
),
config = {
virt_text = { { conf.char or '' } },
virt_text_pos = 'overlay',
hl_mode = 'combine',
ephemeral = true,
},
}
api.nvim_set_decoration_provider(ns, {
on_win = on_win,
on_line = on_line,
})
conf = conf or {}
opt.current = conf.current or true
opt.exclude = vim.tbl_extend(
'force',
{ 'dashboard', 'lazy', 'help', 'markdown', 'nofile', 'terminal' },
conf.exclude or {}
)
opt.config.virt_text = { { conf.char or '' } }
set_decoration_provider(ns, { on_win = on_win, on_line = on_line })
end,
}

0 comments on commit 59d786d

Please sign in to comment.