From 849d6acc6626b5d6340ebf70e8f1310057d80096 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Fri, 20 Aug 2021 08:15:57 +0600 Subject: [PATCH] feat: Allow (neo)vim's statusline items to be used as component directly --- README.md | 8 +++++++- doc/lualine.txt | 5 +++++ lua/lualine/utils/loader.lua | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e45fa6..cddb2c8 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,12 @@ sections = {lualine_a = {hello}} sections = {lualine_a = {'FugitiveHead'}} ``` +#### Vim's statusline items as lualine component + +```lua +sections = {lualine_c = {'%=', '%t%m', '%3p'}} +``` + ##### Vim variables as lualine component Variables from `g:`, `v:`, `t:`, `w:`, `b:`, `o`, `go:`, `vo:`, `to:`, `wo:`, `bo:` scopes can be used. @@ -222,7 +228,7 @@ You can use any valid lua expression as a component including * global variables * require statements ```lua -sections = {lualine_c = {"os.data('%a')", 'data', require'lsp-status'.status}} +sections = {lualine_c = {"os.data('%a')", 'data', "require'lsp-status'.status()"}} ``` `data` is a global variable in this example. diff --git a/doc/lualine.txt b/doc/lualine.txt index 20c780a..b624ffc 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -149,6 +149,11 @@ Vim functions as lualine component~ > sections = {lualine_a = {'FugitiveHead'}} < +Vim's statusline items as lualine component~ +> + sections = {lualine_c = {'%=', '%t%m', '%3p'}} +< + Vim variables as lualine component~ Variables from `g:`, `v:`, `t:`, `w:`, `b:`, `o`, `go:`, `vo:`, `to:`, `wo:`, `bo:` scopes can be used. diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index c5adb51..8ef0dd0 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -70,6 +70,11 @@ local function component_loader(component) if ok then component.component_name = component[1] loaded_component = loaded_component:new(component) + elseif string.char(component[1]:byte(1)) == '%' then + local stl_expr = component[1] -- Vim's %p %l statusline elements + component[1] = function() return stl_expr end + loaded_component = + lualine_load({'lua', 'lualine', 'components', 'special', 'function_component'}, true):new(component) elseif component[1]:find('[gvtwb]?o?:') == 1 then loaded_component = lualine_load({'lua', 'lualine', 'components', 'special', 'vim_var_component'}, true):new(component)