feat: Allow (neo)vim's statusline items to be used as component directly

This commit is contained in:
shadmansaleh 2021-08-20 08:15:57 +06:00
parent aa65ef46fd
commit 849d6acc66
3 changed files with 17 additions and 1 deletions

View File

@ -207,6 +207,12 @@ sections = {lualine_a = {hello}}
sections = {lualine_a = {'FugitiveHead'}} sections = {lualine_a = {'FugitiveHead'}}
``` ```
#### Vim's statusline items as lualine component
```lua
sections = {lualine_c = {'%=', '%t%m', '%3p'}}
```
##### Vim variables as lualine component ##### Vim variables as lualine component
Variables from `g:`, `v:`, `t:`, `w:`, `b:`, `o`, `go:`, `vo:`, `to:`, `wo:`, `bo:` scopes can be used. 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 * global variables
* require statements * require statements
```lua ```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. `data` is a global variable in this example.

View File

@ -149,6 +149,11 @@ Vim functions as lualine component~
> >
sections = {lualine_a = {'FugitiveHead'}} sections = {lualine_a = {'FugitiveHead'}}
< <
Vim's statusline items as lualine component~
>
sections = {lualine_c = {'%=', '%t%m', '%3p'}}
<
Vim variables as lualine component~ Vim variables as lualine component~
Variables from `g:`, `v:`, `t:`, `w:`, `b:`, `o`, `go:`, `vo:`, `to:`, `wo:`, `bo:` scopes can be used. Variables from `g:`, `v:`, `t:`, `w:`, `b:`, `o`, `go:`, `vo:`, `to:`, `wo:`, `bo:` scopes can be used.

View File

@ -70,6 +70,11 @@ local function component_loader(component)
if ok then if ok then
component.component_name = component[1] component.component_name = component[1]
loaded_component = loaded_component:new(component) 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 elseif component[1]:find('[gvtwb]?o?:') == 1 then
loaded_component = loaded_component =
lualine_load({'lua', 'lualine', 'components', 'special', 'vim_var_component'}, true):new(component) lualine_load({'lua', 'lualine', 'components', 'special', 'vim_var_component'}, true):new(component)