feat: user defined extensions

This commit is contained in:
hubert 2021-05-14 20:24:54 +02:00
parent a65168662e
commit 9d9ee2d60e
3 changed files with 29 additions and 4 deletions

View File

@ -398,6 +398,17 @@ extensions = {'quickfix'}
</details> </details>
<details>
<summary><b>Custom extensions</b></summary>
You can define your own extensions. If you think an extension might be useful for others then please submit a pr.
```lua
local my_extension = {sections = {lualine_a = 'mode'}, filetypes = {'lua'}}
require'lualine'.setup {extensions = {my_extension}}
```
</details>
--- ---
### Disabling lualine ### Disabling lualine
You can disable lualine for specific filetypes You can disable lualine for specific filetypes

View File

@ -313,13 +313,22 @@ You can load extensions with:
> >
extensions = {'quickfix'} extensions = {'quickfix'}
< <
Available extensions Available extensions~
* |chadtree| * |chadtree|
* |fugitive| * |fugitive|
* |fzf| * |fzf|
* |nerdtree| * |nerdtree|
* |nvim-tree| * |nvim-tree|
* |quickfix| * |quickfix|
*
Custom extensions~
You can define your own extensions.
If you think an extension might be useful for others then please submit a pr.
>
local my_extension = {sections = {lualine_a = 'mode'}, filetypes = {'lua'}}
require'lualine'.setup {extensions = {my_extension}}
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
DISABLING LUALINE *lualine-disable* DISABLING LUALINE *lualine-disable*

View File

@ -52,9 +52,14 @@ end
local function load_extensions(config) local function load_extensions(config)
for index, extension in pairs(config.extensions) do for index, extension in pairs(config.extensions) do
if type(extension) == 'string' then
local local_extension = require('lualine.extensions.' .. extension) local local_extension = require('lualine.extensions.' .. extension)
load_sections(local_extension.sections, config.options) load_sections(local_extension.sections, config.options)
config.extensions[index] = local_extension config.extensions[index] = local_extension
elseif type(extension) == 'table' then
load_sections(extension.sections, config.options)
config.extensions[index] = extension
end
end end
end end