From 9d9ee2d60ed22a603bd92afabd38e10eb15b413b Mon Sep 17 00:00:00 2001 From: hubert Date: Fri, 14 May 2021 20:24:54 +0200 Subject: [PATCH] feat: user defined extensions --- README.md | 11 +++++++++++ doc/lualine.txt | 11 ++++++++++- lua/lualine/utils/loader.lua | 11 ++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 31cf344..e0689df 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,17 @@ extensions = {'quickfix'} +
+Custom extensions + +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}} +``` + +
+ --- ### Disabling lualine You can disable lualine for specific filetypes diff --git a/doc/lualine.txt b/doc/lualine.txt index a904339..c1a3a31 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -313,13 +313,22 @@ You can load extensions with: > extensions = {'quickfix'} < -Available extensions +Available extensions~ * |chadtree| * |fugitive| * |fzf| * |nerdtree| * |nvim-tree| * |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* diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index 066a652..50b80f6 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -52,9 +52,14 @@ end local function load_extensions(config) for index, extension in pairs(config.extensions) do - local local_extension = require('lualine.extensions.' .. extension) - load_sections(local_extension.sections, config.options) - config.extensions[index] = local_extension + if type(extension) == 'string' then + local local_extension = require('lualine.extensions.' .. extension) + load_sections(local_extension.sections, config.options) + config.extensions[index] = local_extension + elseif type(extension) == 'table' then + load_sections(extension.sections, config.options) + config.extensions[index] = extension + end end end