nvimdev / indentmini.nvim

A minimal and blazing fast indentline plugin
MIT License
171 stars 12 forks source link

Support for tab-indentation #15

Closed chrisgrieser closed 3 months ago

chrisgrieser commented 3 months ago

Neat plugin, nice that something like this can be done in ~100 lines.

Could indentation with tabs also be supported?

emersonfbarros commented 3 months ago

I would like that too. Tab indentation is what's needed for me to replace indent-blankline (which has many features that I don't use) with indentmini.

glepnir commented 3 months ago

Sorry for the late reply. These days I try to do some optimizations to make it faster. about tab , I usually use the tab option in listchars.

glepnir commented 3 months ago

this is my listchar setting listchars=tab:»·,nbsp:+,trail:·,extends:→,precedes:←, and i think its enough for tab ?

image
AyushRawal commented 3 months ago

Hey, I know this issue was closed, but I thought it would look coherent to have indent lines with tab indentation, so I tried doing it. The following diff shows the changes I made if you are interested:

@@ -5,7 +5,7 @@ local ffi = require('ffi')
 local opt = {
   config = {
     virt_text_pos = 'overlay',
-    hl_mode = 'combine',
+    hl_mode = 'replace',
     ephemeral = true,
   },
 }
@@ -42,7 +42,7 @@ end
 local function non_or_space(row, col)
   local line = ffi.string(ml_get(row + 1))
   local text = line:sub(col, col)
-  return text and (#text == 0 or text == ' ') or false
+  return text and (#text == 0 or text == ' ' or text == '  ') or false
 end

 local function find_in_snapshot(lnum)
@@ -103,6 +103,7 @@ local function on_line(_, _, bufnr, row)
     if row > cache.reg_srow and row < cache.reg_erow and level == cache.cur_inlevel then
       higroup = 'IndentLineCurrent'
     end
+    if not vim.o.expandtab then col = level - 1 end
     if col >= cache.leftcol and non_or_space(row, col) then
       opt.config.virt_text[1][2] = higroup
       if is_empty and col > 0 then
@@ -117,7 +118,7 @@ end
 local function on_win(_, winid, bufnr, toprow, botrow)
   if
     bufnr ~= api.nvim_get_current_buf()
-    or not api.nvim_get_option_value('expandtab', { buf = bufnr })
+    -- or not api.nvim_get_option_value('expandtab', { buf = bufnr })
     or vim.iter(opt.exclude):find(function(v)
       return v == vim.bo[bufnr].ft or v == vim.bo[bufnr].buftype
     end)
glepnir commented 3 months ago

how it looks like on tab indent file then. if looking great this minimal patch it's okay :)

AyushRawal commented 3 months ago

It looks good to me. Here is a screenshot of some code in golang: image

Should I make a pull request or will you add it yourself in the next commit ?

glepnir commented 3 months ago

PR welcome :)