Add unique_tail formatter

This commit is contained in:
Olivier Roques
2020-12-28 11:19:05 +01:00
parent 8039e8b25a
commit e094a03d8c
3 changed files with 29 additions and 4 deletions

View File

@@ -65,12 +65,13 @@ end
local function set_hlgroups()
for class, attr in pairs(M.options.theme) do
for state, args in pairs(attr) do
local hlgroup = string.format('Hardline_%s_%s', class, state)
local a = {}
for k, v in pairs(args) do
table.insert(a, string.format('%s=%s', k, v))
end
a = table.concat(a, ' ')
cmd(string.format('hi Hardline_%s_%s %s', class, state, a))
cmd(string.format('autocmd ColorScheme * hi %s %s', hlgroup, a))
end
end
end

View File

@@ -1,9 +1,34 @@
local fn = vim.fn
local fn, vim = vim.fn, vim
local function exclude(bufnr)
return (fn.buflisted(bufnr) == 0 or fn.getbufvar(bufnr, '&filetype') == 'qf')
end
local function get_head(path, tail)
local result = path
for i = 1, #vim.split(tail, '/', true) do
result = fn.fnamemodify(result, ':~:h')
end
return fn.fnamemodify(result, ':t')
end
local function unique_tail(buffers)
local hist = {}
local duplicate = false
for _, buffer in ipairs(buffers) do
hist[buffer.name] = not hist[buffer.name] and 1 or hist[buffer.name] + 1
duplicate = duplicate or hist[buffer.name] > 1
end
if not duplicate then return end
for _, buffer in ipairs(buffers) do
if hist[buffer.name] > 1 then
local parent = get_head(fn.bufname(buffer.bufnr), buffer.name)
buffer.name = string.format('%s/%s', parent, buffer.name)
end
end
unique_tail(buffers)
end
local function to_section(buffer)
local flags = {}
local item = buffer.name == '' and '[No Name]' or buffer.name
@@ -37,6 +62,7 @@ local function get_buffers()
})
end
end
unique_tail(buffers)
return buffers
end

View File

@@ -6,6 +6,4 @@ if exists('g:loaded_hardline')
finish
endif
lua require('hardline').setup {}
let g:loaded_hardline = 1