Refresh generated neovim config
This commit is contained in:
@ -670,6 +670,20 @@ sections = {
|
||||
}
|
||||
```
|
||||
|
||||
#### encoding component options
|
||||
|
||||
```lua
|
||||
sections = {
|
||||
lualine_a = {
|
||||
{
|
||||
'encoding',
|
||||
-- Show '[BOM]' when the file has a byte-order mark
|
||||
show_bomb = false,
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### searchcount component options
|
||||
|
||||
```lua
|
||||
|
||||
@ -699,6 +699,21 @@ Component specific options These are options that are available on
|
||||
<
|
||||
|
||||
|
||||
*lualine-encoding-component-options*
|
||||
|
||||
>
|
||||
sections = {
|
||||
lualine_a = {
|
||||
{
|
||||
'encoding',
|
||||
-- Show '[BOM]' when the file has a byte-order mark
|
||||
show_bomb = false,
|
||||
}
|
||||
}
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
*lualine-searchcount-component-options*
|
||||
|
||||
>
|
||||
|
||||
@ -17,6 +17,7 @@ lualine-contributing lualine.txt /*lualine-contributing*
|
||||
lualine-datetime-component-options lualine.txt /*lualine-datetime-component-options*
|
||||
lualine-diagnostics-component-options lualine.txt /*lualine-diagnostics-component-options*
|
||||
lualine-diff-component-options lualine.txt /*lualine-diff-component-options*
|
||||
lualine-encoding-component-options lualine.txt /*lualine-encoding-component-options*
|
||||
lualine-fileformat-component-options lualine.txt /*lualine-fileformat-component-options*
|
||||
lualine-filename-component-options lualine.txt /*lualine-filename-component-options*
|
||||
lualine-filetype-component-options lualine.txt /*lualine-filetype-component-options*
|
||||
|
||||
@ -141,9 +141,9 @@ ins_left {
|
||||
sources = { 'nvim_diagnostic' },
|
||||
symbols = { error = ' ', warn = ' ', info = ' ' },
|
||||
diagnostics_color = {
|
||||
color_error = { fg = colors.red },
|
||||
color_warn = { fg = colors.yellow },
|
||||
color_info = { fg = colors.cyan },
|
||||
error = { fg = colors.red },
|
||||
warn = { fg = colors.yellow },
|
||||
info = { fg = colors.cyan },
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -77,6 +77,14 @@ function M.find_git_dir(dir_path)
|
||||
-- get file dir so we can search from that dir
|
||||
local file_dir = dir_path or vim.fn.expand('%:p:h')
|
||||
|
||||
if package.loaded.oil then
|
||||
local oil = require('oil')
|
||||
local ok, dir = pcall(oil.get_current_dir)
|
||||
if ok and dir and dir ~= '' then
|
||||
file_dir = vim.fn.fnamemodify(dir, ':p:h')
|
||||
end
|
||||
end
|
||||
|
||||
-- extract correct file dir from terminals
|
||||
if file_dir and file_dir:match('term://.*') then
|
||||
file_dir = vim.fn.expand(file_dir:gsub('term://(.+)//.+', '%1'))
|
||||
|
||||
@ -33,8 +33,19 @@ M.sources = {
|
||||
workspace_diag(diag_severity.HINT)
|
||||
end,
|
||||
nvim_diagnostic = function()
|
||||
local count
|
||||
|
||||
if vim.diagnostic.count ~= nil then -- neovim >= 0.10.0
|
||||
count = vim.diagnostic.count(0)
|
||||
return count[vim.diagnostic.severity.ERROR] or 0,
|
||||
count[vim.diagnostic.severity.WARN] or 0,
|
||||
count[vim.diagnostic.severity.INFO] or 0,
|
||||
count[vim.diagnostic.severity.HINT] or 0
|
||||
end
|
||||
|
||||
-- fallback
|
||||
local diagnostics = vim.diagnostic.get(0)
|
||||
local count = { 0, 0, 0, 0 }
|
||||
count = { 0, 0, 0, 0 }
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
count[diagnostic.severity] = count[diagnostic.severity] + 1
|
||||
end
|
||||
|
||||
@ -1,7 +1,32 @@
|
||||
-- Copyright (c) 2020-2021 hoob3rt
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local function encoding()
|
||||
return vim.opt.fileencoding:get()
|
||||
local lualine_require = require('lualine_require')
|
||||
local M = lualine_require.require('lualine.component'):extend()
|
||||
|
||||
local default_options = {
|
||||
-- Show '[BOM]' when the file has a byte-order mark
|
||||
show_bomb = false,
|
||||
}
|
||||
|
||||
function M:init(options)
|
||||
M.super.init(self, options)
|
||||
self.options = vim.tbl_deep_extend('keep', self.options or {}, default_options)
|
||||
end
|
||||
|
||||
return encoding
|
||||
function M:update_status()
|
||||
local show_bomb = self.options.show_bomb
|
||||
|
||||
local result = vim.opt.fileencoding:get()
|
||||
|
||||
if not show_bomb then
|
||||
return result
|
||||
end
|
||||
|
||||
if vim.opt.bomb:get() then
|
||||
result = result .. ' [BOM]'
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local function location()
|
||||
local line = vim.fn.line('.')
|
||||
local col = vim.fn.virtcol('.')
|
||||
local col = vim.fn.charcol('.')
|
||||
return string.format('%3d:%-2d', line, col)
|
||||
end
|
||||
|
||||
|
||||
@ -242,6 +242,37 @@ describe('Encoding component', function()
|
||||
vim.cmd('bd!')
|
||||
os.remove(tmp_path)
|
||||
end)
|
||||
it('works with BOM and default config', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
local tmp_path = 'tmp.txt'
|
||||
local tmp_fp = io.open(tmp_path, 'w')
|
||||
tmp_fp:write('test file')
|
||||
tmp_fp:close()
|
||||
vim.cmd('e ' .. tmp_path)
|
||||
vim.cmd('set bomb')
|
||||
assert_component('encoding', opts, 'utf-8')
|
||||
vim.cmd('bd!')
|
||||
os.remove(tmp_path)
|
||||
end)
|
||||
it('works with BOM and option enabled', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
show_bomb = true
|
||||
}
|
||||
local tmp_path = 'tmp.txt'
|
||||
local tmp_fp = io.open(tmp_path, 'w')
|
||||
tmp_fp:write('test file')
|
||||
tmp_fp:close()
|
||||
vim.cmd('e ' .. tmp_path)
|
||||
vim.cmd('set bomb')
|
||||
assert_component('encoding', opts, 'utf-8 [BOM]')
|
||||
vim.cmd('bd!')
|
||||
os.remove(tmp_path)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Fileformat component', function()
|
||||
|
||||
Reference in New Issue
Block a user