Repository: nvim-lualine/lualine.nvim
Pull request #1246 (2024-05-23 17:23:39)

Deprecated function in example evil_lualine.lua
When using the example of [evil_line.lua](https://github.com/nvim-lualine/lualine.nvim/blob/master/examples/evil_lualine.lua#L163), show the following error:

![remove](https://github.com/nvim-lualine/lualine.nvim/assets/45508933/27b52109-cd18-4969-abf9-643161257ff7)

In neovim 0.12 vim.lsp.get_active_clients() function will be [deprecated](https://neovim.io/doc/user/deprecated.html#vim.lsp.get_active_clients()), vim.lsp.get_clients() solve the problem and works perfectly



Patch:
diff --git a/README.md b/README.md
index eeb8d42..7605da6 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,7 @@ require('lualine').setup {
     },
     ignore_focus = {},
     always_divide_middle = true,
+    always_show_tabline = true,
     globalstatus = false,
     refresh = {
       statusline = 1000,
@@ -378,6 +379,10 @@ options = {
                                -- can't take over the entire statusline even
                                -- if neither of 'x', 'y' or 'z' are present.
 
+  always_show_tabline = true -- When set to true, if you have configured lualine for displaying tabline
+                          -- then tabline will always show. If set to false, then tabline will be displayed
+                          -- only when there are more than 1 tab. (see :h showtabline)
+
   globalstatus = false,        -- enable global statusline (have a single statusline
                                -- at bottom of neovim instead of one for  every window).
                                -- This feature is only available in neovim 0.7 and higher.
@@ -670,6 +675,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
diff --git a/doc/lualine.txt b/doc/lualine.txt
index 05d4566..cc1f452 100644
--- a/doc/lualine.txt
+++ b/doc/lualine.txt
@@ -124,6 +124,7 @@ For more information, check out `:help lua-heredoc`.
         },
         ignore_focus = {},
         always_divide_middle = true,
+        always_show_tabline = true,
         globalstatus = false,
         refresh = {
           statusline = 1000,
@@ -393,6 +394,10 @@ in component.
                                    -- can't take over the entire statusline even
                                    -- if neither of 'x', 'y' or 'z' are present.
     
+      always_show_tabline = true -- When set to true, if you have configured lualine for displaying tabline
+                              -- then tabline will always show. If set to false, then tabline will be displayed
+                              -- only when there are more than 1 tab. (see :h showtabline)
+    
       globalstatus = false,        -- enable global statusline (have a single statusline
                                    -- at bottom of neovim instead of one for  every window).
                                    -- This feature is only available in neovim 0.7 and higher.
@@ -699,6 +704,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*
 
 >
diff --git a/examples/evil_lualine.lua b/examples/evil_lualine.lua
index 1386920..6fdb837 100644
--- a/examples/evil_lualine.lua
+++ b/examples/evil_lualine.lua
@@ -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 },
   },
 }
 
@@ -160,7 +160,7 @@ ins_left {
   function()
     local msg = 'No Active Lsp'
     local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
-    local clients = vim.lsp.get_active_clients()
+    local clients = vim.lsp.get_clients()
     if next(clients) == nil then
       return msg
     end
diff --git a/lua/lualine.lua b/lua/lualine.lua
index 6093049..0e3b1b4 100644
--- a/lua/lualine.lua
+++ b/lua/lualine.lua
@@ -479,7 +479,7 @@ local function set_tabline(hide)
       "call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['tabline'], 'trigger': 'autocmd'})",
       'lualine_tal_refresh'
     )
-    modules.nvim_opts.set('showtabline', 2, { global = true })
+    modules.nvim_opts.set('showtabline', config.options.always_show_tabline and 2 or 1, { global = true })
     timers.halt_tal_refresh = false
   else
     modules.nvim_opts.restore('tabline', { global = true })
diff --git a/lua/lualine/components/branch/git_branch.lua b/lua/lualine/components/branch/git_branch.lua
index dcc9775..9474f32 100644
--- a/lua/lualine/components/branch/git_branch.lua
+++ b/lua/lualine/components/branch/git_branch.lua
@@ -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'))
diff --git a/lua/lualine/components/diagnostics/sources.lua b/lua/lualine/components/diagnostics/sources.lua
index c0ef78c..48fdd21 100644
--- a/lua/lualine/components/diagnostics/sources.lua
+++ b/lua/lualine/components/diagnostics/sources.lua
@@ -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
diff --git a/lua/lualine/components/encoding.lua b/lua/lualine/components/encoding.lua
index 80a5ece..936b265 100644
--- a/lua/lualine/components/encoding.lua
+++ b/lua/lualine/components/encoding.lua
@@ -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
+
+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 encoding
+return M
diff --git a/lua/lualine/components/location.lua b/lua/lualine/components/location.lua
index 1b276ac..a15eb91 100644
--- a/lua/lualine/components/location.lua
+++ b/lua/lualine/components/location.lua
@@ -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
 
diff --git a/lua/lualine/config.lua b/lua/lualine/config.lua
index cc92099..56f56ec 100644
--- a/lua/lualine/config.lua
+++ b/lua/lualine/config.lua
@@ -18,6 +18,7 @@ local config = {
     },
     ignore_focus = {},
     always_divide_middle = true,
+    always_show_tabline = true,
     globalstatus = vim.go.laststatus == 3,
     refresh = {
       statusline = 1000,
diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua
index e0c0385..323403b 100644
--- a/lua/lualine/utils/loader.lua
+++ b/lua/lualine/utils/loader.lua
@@ -220,8 +220,10 @@ local function load_theme(theme_name)
   end
   local n_files = #files
   if n_files == 0 then
-    -- No match found
-    error(path .. ' Not found')
+    -- No match found on runtimepath. Fall back to package.path
+    local file =
+      assert(package.searchpath('lualine.themes.' .. theme_name, package.path), 'Theme ' .. theme_name .. ' not found')
+    retval = dofile(file)
   elseif n_files == 1 then
     -- when only one is found run that and return it's return value
     retval = dofile(files[1])
diff --git a/lua/lualine_require.lua b/lua/lualine_require.lua
index 968e9af..a4a369b 100644
--- a/lua/lualine_require.lua
+++ b/lua/lualine_require.lua
@@ -54,16 +54,17 @@ function M.require(module)
   end
 
   pattern_path = table.concat { 'lua/', module:gsub('%.', '/'), '.lua' }
-  local paths = vim.api.nvim_get_runtime_file(pattern_path, false)
+  local paths = vim.api.nvim_get_runtime_file(pattern_path, true)
   if #paths <= 0 then
     pattern_path = table.concat { 'lua/', module:gsub('%.', '/'), '/init.lua' }
-    paths = vim.api.nvim_get_runtime_file(pattern_path, false)
+    paths = vim.api.nvim_get_runtime_file(pattern_path, true)
   end
   if #paths > 0 then
     -- put entries from user config path in front
     local user_config_path = vim.fn.stdpath('config')
     table.sort(paths, function(a, b)
-      return vim.startswith(a, user_config_path) or not vim.startswith(b, user_config_path)
+      local pattern = table.concat { user_config_path, M.sep }
+      return string.match(a, pattern) or not string.match(b, pattern)
     end)
     local mod_result = dofile(paths[1])
     package.loaded[module] = mod_result


Test patch:
diff --git a/tests/spec/component_spec.lua b/tests/spec/component_spec.lua
index 7be377b..3311b95 100644
--- a/tests/spec/component_spec.lua
+++ b/tests/spec/component_spec.lua
@@ -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()
diff --git a/tests/spec/lualine_spec.lua b/tests/spec/lualine_spec.lua
index eb46a3c..b3990f7 100644
--- a/tests/spec/lualine_spec.lua
+++ b/tests/spec/lualine_spec.lua
@@ -21,6 +21,7 @@ describe('Lualine', function()
         },
         ignore_focus = {},
         always_divide_middle = true,
+        always_show_tabline = true,
         globalstatus = false,
         refresh = {
           statusline = 1000,