From ecaa491c3c780596b02349e300533d8ef4098508 Mon Sep 17 00:00:00 2001 From: Shadman <13149513+shadmansaleh@users.noreply.github.com> Date: Fri, 29 Oct 2021 19:07:11 +0600 Subject: [PATCH] feat: add support for function in max_length option (tabs & buffers) --- README.md | 2 ++ lua/lualine/components/buffers/init.lua | 4 ++++ lua/lualine/components/tabs/init.lua | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index a08f5fc..ba24c8c 100644 --- a/README.md +++ b/README.md @@ -413,6 +413,7 @@ sections = { show_filename_only = true, -- shows shortened relative path when false show_modified_status = true -- shows indicator then bufder is modified max_length = vim.o.columns * 2 / 3, -- maximum width of buffers component + -- can also be a function that returns value of max_length dynamicaly filetype_names = { TelescopePrompt = 'Telescope', dashboard = 'Dashboard', @@ -538,6 +539,7 @@ sections = { { 'tabs', max_length = vim.o.columns / 3, -- maximum width of tabs component + -- can also be a function that returns value of max_length dynamicaly mode = 0, -- 0 shows tab_nr -- 1 shows tab_name -- 2 shows tab_nr + tab_name diff --git a/lua/lualine/components/buffers/init.lua b/lua/lualine/components/buffers/init.lua index 5aa2b17..f8ed029 100644 --- a/lua/lualine/components/buffers/init.lua +++ b/lua/lualine/components/buffers/init.lua @@ -93,6 +93,10 @@ function M:update_status() end local max_length = self.options.max_length + if type(max_length) == 'function' then + max_length = max_length(self) + end + if max_length == 0 then max_length = math.floor(2 * vim.o.columns / 3) end diff --git a/lua/lualine/components/tabs/init.lua b/lua/lualine/components/tabs/init.lua index a48cb05..3304198 100644 --- a/lua/lualine/components/tabs/init.lua +++ b/lua/lualine/components/tabs/init.lua @@ -76,6 +76,10 @@ function M:update_status() end local max_length = self.options.max_length + if type(max_length) == 'function' then + max_length = max_length(self) + end + if max_length == 0 then max_length = math.floor(vim.o.columns / 3) end