enhance: change method of getting file encoding

Currently, lualine gets the encoding using this:
[[%{strlen(&fenc)?&fenc:&enc}]] My suggestion is to change this string
to `vim.opt.fileencoding:get()` This suggestion is because I would like
to use the option "fmt = string.upper", and with the current string it
doesn't work, but using vim.opt function correctly
This commit is contained in:
André Augusto 2021-10-21 10:16:12 -03:00 committed by shadmansaleh
parent 71f6fed3c3
commit e917677a3a
2 changed files with 8 additions and 2 deletions

View File

@ -1,7 +1,7 @@
-- Copyright (c) 2020-2021 hoob3rt -- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local function encoding() local function encoding()
return [[%{strlen(&fenc)?&fenc:&enc}]] return vim.opt.fileencoding:get()
end end
return encoding return encoding

View File

@ -210,7 +210,13 @@ describe('Encoding component', function()
component_separators = { left = '', right = '' }, component_separators = { left = '', right = '' },
padding = 0, padding = 0,
} }
assert_component('encoding', opts, '%{strlen(&fenc)?&fenc:&enc}') 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)
assert_component('encoding', opts, 'utf-8')
os.remove(tmp_path)
end) end)
end) end)