diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8b2f0e..2bd5b02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ ### General * 2 spaces -* camelCase +* snake_case ### All contributions are very welcome but themes/ extensions require a lot of work on my part if not done properly so here's a guide on how to do them. diff --git a/README.md b/README.md index 31d7a23..d4eba42 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ lualine.sections = { lualine_diagnostics = { } } -lualine.inactiveSections = { +lualine.inactive_sections = { lualine_a = { }, lualine_b = { }, lualine_c = { 'filename' }, @@ -139,7 +139,7 @@ You can define a custom function as a lualine component local function hello() return [[hello world]] end -lualine.sections = { lualine_a = { hello } } +lualine.sections.lualine_a = { hello } ``` @@ -174,9 +174,8 @@ All available extensions are listed in [EXTENSIONS.md](./EXTENSIONS.md) lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' }, lualine_z = { 'location' }, - lualine_diagnostics = { } } - lualine.inactiveSections = { + lualine.inactive_sections = { lualine_a = { }, lualine_b = { }, lualine_c = { 'filename' }, @@ -209,9 +208,8 @@ local lualine = require('lualine') lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' }, lualine_z = { 'location' }, - lualine_diagnostics = { } } - lualine.inactiveSections = { + lualine.inactive_sections = { lualine_a = { }, lualine_b = { }, lualine_c = { 'filename' }, diff --git a/lua/lualine.lua b/lua/lualine.lua index 611e449..026e4c4 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -15,10 +15,9 @@ M.sections = { lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' }, lualine_z = { 'location' }, - lualine_diagnostics = { } } -M.inactiveSections = { +M.inactive_sections = { lualine_a = { }, lualine_b = { }, lualine_c = { 'filename' }, @@ -30,8 +29,8 @@ M.inactiveSections = { M.extensions = { } -local function loadComponents() - local function loadSections(sections) +local function load_components() + local function load_sections(sections) for _, section in pairs(sections) do for index, component in pairs(section) do if type(component) == 'string' then @@ -40,17 +39,17 @@ local function loadComponents() end end end - loadSections(M.sections) - loadSections(M.inactiveSections) + load_sections(M.sections) + load_sections(M.inactive_sections) end -local function loadExtensions() +local function load_extensions() for _, extension in pairs(M.extensions) do if type(extension) == 'string' then - require('lualine.components.extensions.' .. extension).loadExtension() + require('lualine.extensions.' .. extension).load_extension() end if type(extension) == 'table' then - extension.loadExtension() + extension.load_extension() end if type(extension) == 'function' then extension() @@ -58,64 +57,64 @@ local function loadExtensions() end end -local function setLualineTheme() +local function set_lualine_theme() if type(M.theme) == 'string' then - M.theme =require('lualine.themes.'.. M.theme) + M.theme = require('lualine.themes.'.. M.theme) end - highlight.createHighlightGroups(M.theme) + highlight.create_highlight_groups(M.theme) theme_set = M.theme end -local function StatusLine(isFocused) +local function statusline(is_focused) local sections = M.sections - if not isFocused then - sections = M.inactiveSections + if not is_focused then + sections = M.inactive_sections end if M.theme ~= theme_set then - setLualineTheme() + set_lualine_theme() end local status = {} - if sections.lualine_a ~= nil then - table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a')) - table.insert(status, utils.drawSection(sections.lualine_a, M.separator)) + if sections.lualine_a then + table.insert(status, highlight.format_highlight(is_focused, 'lualine_a')) + table.insert(status, utils.draw_section(sections.lualine_a, M.separator)) end - if sections.lualine_b ~= nil then - table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b')) - table.insert(status, utils.drawSection(sections.lualine_b, M.separator)) + if sections.lualine_b then + table.insert(status, highlight.format_highlight(is_focused, 'lualine_b')) + table.insert(status, utils.draw_section(sections.lualine_b, M.separator)) end - if sections.lualine_c ~= nil then - table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c')) - table.insert(status, utils.drawSection(sections.lualine_c, M.separator)) + if sections.lualine_c then + table.insert(status, highlight.format_highlight(is_focused, 'lualine_c')) + table.insert(status, utils.draw_section(sections.lualine_c, M.separator)) end table.insert(status, "%=") - if sections.lualine_x ~= nil then - table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c')) - table.insert(status, utils.drawSection(sections.lualine_x, M.separator)) + if sections.lualine_x then + table.insert(status, highlight.format_highlight(is_focused, 'lualine_c')) + table.insert(status, utils.draw_section(sections.lualine_x, M.separator)) end - if sections.lualine_y ~= nil then - table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b')) - table.insert(status, utils.drawSection(sections.lualine_y, M.separator)) + if sections.lualine_y then + table.insert(status, highlight.format_highlight(is_focused, 'lualine_b')) + table.insert(status, utils.draw_section(sections.lualine_y, M.separator)) end - if sections.lualine_z ~= nil then - table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a')) - table.insert(status, utils.drawSection(sections.lualine_z, M.separator)) + if sections.lualine_z then + table.insert(status, highlight.format_highlight(is_focused, 'lualine_a')) + table.insert(status, utils.draw_section(sections.lualine_z, M.separator)) end return table.concat(status) end -function execAutocommands() - _G.statusline = StatusLine - _G.highlight = setLualineTheme +local function exec_autocommands() + _G.statusline = statusline + _G.set_lualine_theme = set_lualine_theme vim.cmd([[autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.statusline(1)]]) vim.cmd([[autocmd WinLeave,BufLeave * setlocal statusline=%!v:lua.statusline()]]) - vim.cmd([[autocmd ColorScheme * call v:lua.highlight()]]) + vim.cmd([[autocmd ColorScheme * call v:lua.set_lualine_theme()]]) end function M.status() - loadComponents() - loadExtensions() - setLualineTheme() - execAutocommands() + load_components() + load_extensions() + set_lualine_theme() + exec_autocommands() end return M diff --git a/lua/lualine/components/branch.lua b/lua/lualine/components/branch.lua index 1600e2f..8b9574f 100644 --- a/lua/lualine/components/branch.lua +++ b/lua/lualine/components/branch.lua @@ -1,37 +1,37 @@ local async = require('lualine.async') -local branch +local git_branch -local git_branch = async:new({ +local get_git_branch = async:new({ cmd = 'git branch --show-current', on_stdout = function(_, data) if data then - branch = data:gsub('\n', '') + git_branch = data:gsub('\n', '') end end }) local timer = vim.loop.new_timer() timer:start(0, 1000, vim.schedule_wrap(function() - git_branch:start() + get_git_branch:start() end)) -local function Branch() - if not branch or #branch == 0 then return '' end +local function branch() + if not git_branch or #git_branch == 0 then return '' end local ok,devicons = pcall(require,'nvim-web-devicons') if ok then local icon = devicons.get_icon('git') if icon ~= nil then - return icon .. ' ' .. branch + return icon .. ' ' .. git_branch end - return branch + return git_branch end ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol')) if ok ~= 0 then local icon = '' - return icon .. ' ' .. branch + return icon .. ' ' .. git_branch end - return branch + return git_branch end -return Branch +return branch diff --git a/lua/lualine/components/encoding.lua b/lua/lualine/components/encoding.lua index a548b87..bbc840d 100644 --- a/lua/lualine/components/encoding.lua +++ b/lua/lualine/components/encoding.lua @@ -1,6 +1,6 @@ -local function Encoding() - local encoding = [[%{strlen(&fenc)?&fenc:&enc}]] - return encoding +local function encoding() + local data = [[%{strlen(&fenc)?&fenc:&enc}]] + return data end -return Encoding +return encoding diff --git a/lua/lualine/components/fileformat.lua b/lua/lualine/components/fileformat.lua index 4012018..0bbbdab 100644 --- a/lua/lualine/components/fileformat.lua +++ b/lua/lualine/components/fileformat.lua @@ -1,6 +1,6 @@ -local function FileFormat() - local fileformat = [[%{&ff}]] - return fileformat +local function fileformat() + local data = [[%{&ff}]] + return data end -return FileFormat +return fileformat diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index be5bb12..a5bdc7f 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -1,5 +1,6 @@ -local function FileName() - return [[%t %m]] +local function filename() + local data = [[%t %m]] + return data end -return FileName +return filename diff --git a/lua/lualine/components/filetype.lua b/lua/lualine/components/filetype.lua index e28b7d6..4d5e78b 100644 --- a/lua/lualine/components/filetype.lua +++ b/lua/lualine/components/filetype.lua @@ -1,23 +1,23 @@ -local function Filetype() - local filetype = vim.bo.filetype - if filetype:len() > 0 then +local function filetype() + local data = vim.bo.filetype + if #data > 0 then local ok,devicons = pcall(require,'nvim-web-devicons') if ok then local f_name,f_extension = vim.fn.expand('%:t'),vim.fn.expand('%:e') local icon = devicons.get_icon(f_name,f_extension) if icon ~= nil then - return icon .. ' ' .. filetype + return icon .. ' ' .. data end - return filetype + return data end - ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol')) + ok = (vim.fn.exists('*WebDevIconsGetdataSymbol')) if ok ~= 0 then - local icon = vim.call('WebDevIconsGetFileTypeSymbol') - return icon .. ' ' .. filetype + local icon = vim.call('WebDevIconsGetdataSymbol') + return icon .. ' ' .. data end - return filetype + return data end return '' end -return Filetype +return filetype diff --git a/lua/lualine/components/location.lua b/lua/lualine/components/location.lua index 2de53a9..7c51388 100644 --- a/lua/lualine/components/location.lua +++ b/lua/lualine/components/location.lua @@ -1,5 +1,6 @@ -local function Location() - return[[%3l:%-2c]] +local function location() + local data = [[%3l:%-2c]] + return data end -return Location +return location diff --git a/lua/lualine/components/mode.lua b/lua/lualine/components/mode.lua index 6814ca1..f225952 100644 --- a/lua/lualine/components/mode.lua +++ b/lua/lualine/components/mode.lua @@ -1,4 +1,4 @@ -local function Mode() +local function mode() local mode_map = { ['__'] = '------', ['n'] = 'NORMAL', @@ -15,4 +15,4 @@ local function Mode() return mode_map[vim.fn.mode()] end -return Mode +return mode diff --git a/lua/lualine/components/progress.lua b/lua/lualine/components/progress.lua index aac92d8..7a1a24c 100644 --- a/lua/lualine/components/progress.lua +++ b/lua/lualine/components/progress.lua @@ -1,5 +1,6 @@ -local function Progress() - return [[%3P]] +local function progress() + local data = [[%3P]] + return data end -return Progress +return progress diff --git a/lua/lualine/components/signify.lua b/lua/lualine/components/signify.lua index 4726a4a..9547f22 100644 --- a/lua/lualine/components/signify.lua +++ b/lua/lualine/components/signify.lua @@ -4,7 +4,12 @@ local function signify() if added == -1 then added = 0 end if modified == -1 then modified = 0 end if removed == -1 then removed = 0 end - return '+' .. added .. ' ~'.. modified .. ' -' .. removed + local data = { + '+', added, + '~', modified, + '-', removed + } + return table.concat(data, ' ') end return signify diff --git a/lua/lualine/components/extensions/fzf.lua b/lua/lualine/extensions/fzf.lua similarity index 62% rename from lua/lualine/components/extensions/fzf.lua rename to lua/lualine/extensions/fzf.lua index 1e18341..5120706 100644 --- a/lua/lualine/components/extensions/fzf.lua +++ b/lua/lualine/extensions/fzf.lua @@ -1,4 +1,4 @@ -local function fzfStatusline() +local function fzf_statusline() vim.cmd([[hi clear fzf1]]) vim.cmd([[hi link fzf1 lualine_a_normal]]) vim.cmd([[hi clear fzf2]]) @@ -7,11 +7,11 @@ local function fzfStatusline() end -local function loadExtension() - _G.fzfStatusline = fzfStatusline - vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzfStatusline()]])) +local function load_extension() + _G.fzf_statusline = fzf_statusline + vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzf_statusline()]])) end return { - loadExtension = loadExtension + load_extension = load_extension } diff --git a/lua/lualine/highlight.lua b/lua/lualine/highlight.lua index bd13437..2f79601 100644 --- a/lua/lualine/highlight.lua +++ b/lua/lualine/highlight.lua @@ -10,34 +10,35 @@ local function highlight (name, foreground, background, special) return table.concat(command, ' ') end -function M.createHighlightGroups(theme) +function M.create_highlight_groups(theme) for mode, sections in pairs(theme) do for section, colorscheme in pairs(sections) do local special = nil if section == 'a' then special = 'bold' end - vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg, special)) + local highlight_group_name = { 'lualine', section, mode } + vim.cmd(highlight(table.concat(highlight_group_name, '_'), colorscheme.fg, colorscheme.bg, special)) end end end -function M.formatHighlight(isFocused, highlighGroup) +function M.format_highlight(is_focused, highlight_group) local mode = require('lualine.components.mode')() - highlighGroup = [[%#]] .. highlighGroup - if not isFocused then - highlighGroup = highlighGroup .. [[_inactive]] + highlight_group = [[%#]] .. highlight_group + if not is_focused then + highlight_group = highlight_group .. [[_inactive]] else if mode == 'V-BLOCK' or mode == 'V-LINE' then - highlighGroup = highlighGroup .. '_visual' + highlight_group = highlight_group .. '_visual' elseif mode == 'V-REPLACE' then - highlighGroup = highlighGroup .. '_replace' + highlight_group = highlight_group .. '_replace' else - highlighGroup = highlighGroup .. '_' .. mode:lower() + highlight_group = highlight_group .. '_' .. mode:lower() end end - highlighGroup = highlighGroup .. [[#]] - return highlighGroup + highlight_group = highlight_group .. [[#]] + return highlight_group end return M diff --git a/lua/lualine/themes/dracula.lua b/lua/lualine/themes/dracula.lua index 8754fb2..c385080 100644 --- a/lua/lualine/themes/dracula.lua +++ b/lua/lualine/themes/dracula.lua @@ -1,91 +1,91 @@ local M = { } -local Colors = { - grey = "#44475a", - lightGrey = "#5f6a8e", - orange = "#ffb86c", - purple = "#bd93f9", - red = "#ff5555", - yellow = "#f1fa8c", - green = "#50fa7b", +local colors = { + grey = "#44475a", + light_gray = "#5f6a8e", + orange = "#ffb86c", + purple = "#bd93f9", + red = "#ff5555", + yellow = "#f1fa8c", + green = "#50fa7b", - white = "#f8f8f2", - black = "#282a36", + white = "#f8f8f2", + black = "#282a36", } M.normal = { a = { - bg = Colors.purple, - fg = Colors.black, + bg = colors.purple, + fg = colors.black, }, b = { - bg = Colors.lightGrey, - fg = Colors.white, + bg = colors.light_gray, + fg = colors.white, }, c = { - bg = Colors.grey, - fg = Colors.white, + bg = colors.grey, + fg = colors.white, } } M.insert = { a = { - bg = Colors.green, - fg = Colors.black, + bg = colors.green, + fg = colors.black, }, b = { - bg = Colors.lightGrey, - fg = Colors.white, + bg = colors.light_gray, + fg = colors.white, }, c = { - bg = Colors.grey, - fg = Colors.white, + bg = colors.grey, + fg = colors.white, } } M.visual = { a = { - bg = Colors.yellow, - fg = Colors.black, + bg = colors.yellow, + fg = colors.black, }, b = { - bg = Colors.lightGrey, - fg = Colors.white, + bg = colors.light_gray, + fg = colors.white, }, c = { - bg = Colors.grey, - fg = Colors.white, + bg = colors.grey, + fg = colors.white, }, } M.replace = { a = { - bg = Colors.red, - fg = Colors.black, + bg = colors.red, + fg = colors.black, }, b = { - bg = Colors.lightGrey, - fg = Colors.white, + bg = colors.light_gray, + fg = colors.white, }, c = { - bg = Colors.grey, - fg = Colors.white, + bg = colors.grey, + fg = colors.white, }, } M.command = { a = { - bg = Colors.grey, - fg = Colors.white, + bg = colors.grey, + fg = colors.white, }, b = { - bg = Colors.lightGrey, - fg = Colors.white, + bg = colors.light_gray, + fg = colors.white, }, c = { - bg = Colors.purple, - fg = Colors.white + bg = colors.purple, + fg = colors.white }, } @@ -93,16 +93,16 @@ M.terminal = M.normal M.inactive = { a = { - bg = Colors.white, - fg = Colors.purple, + bg = colors.white, + fg = colors.purple, }, b = { - bg = Colors.grey, - fg = Colors.purple, + bg = colors.grey, + fg = colors.purple, }, c = { - bg = Colors.purple, - fg = Colors.purple, + bg = colors.purple, + fg = colors.purple, }, } diff --git a/lua/lualine/themes/gruvbox.lua b/lua/lualine/themes/gruvbox.lua index 29e1db5..68649d8 100644 --- a/lua/lualine/themes/gruvbox.lua +++ b/lua/lualine/themes/gruvbox.lua @@ -1,6 +1,6 @@ local M = { } -local Colors = { +local colors = { black = "#282828", white = '#ebdbb2', red = '#fb4934', @@ -17,77 +17,77 @@ local Colors = { M.normal = { a = { - bg = Colors.gray, - fg = Colors.black, + bg = colors.gray, + fg = colors.black, }, b = { - bg = Colors.lightgray, - fg = Colors.white, + bg = colors.lightgray, + fg = colors.white, }, c = { - bg = Colors.darkgray, - fg = Colors.gray + bg = colors.darkgray, + fg = colors.gray } } M.insert = { a = { - bg = Colors.blue, - fg = Colors.black, + bg = colors.blue, + fg = colors.black, }, b = { - bg = Colors.lightgray, - fg = Colors.white, + bg = colors.lightgray, + fg = colors.white, }, c = { - bg = Colors.lightgray, - fg = Colors.white + bg = colors.lightgray, + fg = colors.white } } M.visual = { a = { - bg = Colors.yellow, - fg = Colors.black, + bg = colors.yellow, + fg = colors.black, }, b = { - bg = Colors.lightgray, - fg = Colors.white, + bg = colors.lightgray, + fg = colors.white, }, c = { - bg = Colors.inactivegray, - fg = Colors.black + bg = colors.inactivegray, + fg = colors.black }, } M.replace = { a = { - bg = Colors.red, - fg = Colors.black, + bg = colors.red, + fg = colors.black, }, b = { - bg = Colors.lightgray, - fg = Colors.white, + bg = colors.lightgray, + fg = colors.white, }, c = { - bg = Colors.black, - fg = Colors.white + bg = colors.black, + fg = colors.white }, } M.command = { a = { - bg = Colors.green, - fg = Colors.black, + bg = colors.green, + fg = colors.black, }, b = { - bg = Colors.lightgray, - fg = Colors.white, + bg = colors.lightgray, + fg = colors.white, }, c = { - bg = Colors.inactivegray, - fg = Colors.black + bg = colors.inactivegray, + fg = colors.black }, } @@ -95,16 +95,16 @@ M.terminal = M.normal M.inactive = { a = { - bg = Colors.darkgray, - fg = Colors.gray, + bg = colors.darkgray, + fg = colors.gray, }, b = { - bg = Colors.darkgray, - fg = Colors.gray, + bg = colors.darkgray, + fg = colors.gray, }, c = { - bg = Colors.darkgray, - fg = Colors.gray + bg = colors.darkgray, + fg = colors.gray }, } diff --git a/lua/lualine/themes/onedark.lua b/lua/lualine/themes/onedark.lua index 157b018..aee6df3 100644 --- a/lua/lualine/themes/onedark.lua +++ b/lua/lualine/themes/onedark.lua @@ -1,6 +1,6 @@ local M = { } -local Colors = { +local colors = { red = "#E06C75", dark_red = "#BE5046", green = "#98C379", @@ -23,61 +23,61 @@ local Colors = { M.normal = { a = { - fg = Colors.black, - bg = Colors.green, + fg = colors.black, + bg = colors.green, }, b = { - fg = Colors.white, - bg = Colors.visual_grey, + fg = colors.white, + bg = colors.visual_grey, }, c = { - fg = Colors.green, - bg = Colors.black, + fg = colors.green, + bg = colors.black, }, } M.insert = { a = { - fg = Colors.black, - bg = Colors.blue, + fg = colors.black, + bg = colors.blue, }, b = { - fg = Colors.white, - bg = Colors.visual_grey, + fg = colors.white, + bg = colors.visual_grey, }, c = { - fg = Colors.blue, - bg = Colors.black, + fg = colors.blue, + bg = colors.black, }, } M.visual = { a = { - fg = Colors.black, - bg = Colors.purple, + fg = colors.black, + bg = colors.purple, }, b = { - fg = Colors.white, - bg = Colors.visual_grey, + fg = colors.white, + bg = colors.visual_grey, }, c = { - fg = Colors.purple, - bg = Colors.black, + fg = colors.purple, + bg = colors.black, }, } M.replace = { a = { - fg = Colors.black, - bg = Colors.red, + fg = colors.black, + bg = colors.red, }, b = { - fg = Colors.white, - bg = Colors.visual_grey, + fg = colors.white, + bg = colors.visual_grey, }, c = { - fg = Colors.red, - bg = Colors.black, + fg = colors.red, + bg = colors.black, }, } @@ -86,16 +86,16 @@ M.command = M.normal M.inactive = { a = { - fg = Colors.black, - bg = Colors.white, + fg = colors.black, + bg = colors.white, }, b = { - fg = Colors.white, - bg = Colors.visual_grey, + fg = colors.white, + bg = colors.visual_grey, }, c = { - fg = Colors.white, - bg = Colors.visual_grey, + fg = colors.white, + bg = colors.visual_grey, }, } diff --git a/lua/lualine/utils.lua b/lua/lualine/utils.lua index 588f994..48c520d 100644 --- a/lua/lualine/utils.lua +++ b/lua/lualine/utils.lua @@ -1,9 +1,9 @@ local M = { } -function M.drawSection(section, separator) +function M.draw_section(section, separator) local status = {} - for _, statusFunction in pairs(section) do - local localstatus = statusFunction() + for _, status_function in pairs(section) do + local localstatus = status_function() if #localstatus > 0 then table.insert(status, localstatus) end