🪴 a tiny, customizable statusline for neovim
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: prevent early module loading

robin f9aa9625 53a290b9

+84 -94
+2 -2
.nvim.lua
··· 5 5 6 6 vim.opt.rtp:prepend(".") 7 7 8 - -- 8 + R('lylla') 9 9 10 - R("lylla.init") 10 + vim.cmd([[ runtime plugin/lylla.lua ]])
+3 -88
lua/lylla/init.lua
··· 1 1 local M = {} 2 2 3 3 local lzrq = function(modname) 4 - return setmetatable({ 5 - modname = modname, 6 - }, { 7 - __index = function(t, k) 8 - local m = rawget(t, "modname") 9 - return m and require(m)[k] or nil 10 - end, 11 - }) 4 + return vim.defaulttable(function(k) 5 + return require(modname)[k] 6 + end) 12 7 end 13 8 14 9 local config = lzrq("lylla.config") 15 - local utils = lzrq("lylla.utils") 16 - 17 - ---@type table<'normal'|'visual'|'command'|'insert'|'replace'|'operator', vim.api.keyset.highlight> 18 - local default_hls = { 19 - normal = { link = "@property" }, 20 - visual = { link = "@constant" }, 21 - command = { link = "@function" }, 22 - insert = { link = "@variable" }, 23 - replace = { link = "@type" }, 24 - operator = { link = "NonText" }, 25 - } 26 10 27 11 ---@param cfg? lylla.config 28 12 function M.setup(cfg) 29 13 cfg = cfg or {} 30 14 config.set(config.override(cfg)) 31 - end 32 - 33 - function M.inithls() 34 - vim.iter(pairs(default_hls)):each(function(mode, defaulthl) 35 - local hl = config.get().hls[mode] 36 - local name, revname = utils.get_modehl_name(mode) 37 - if hl then 38 - vim.api.nvim_set_hl(0, name, hl) 39 - elseif vim.tbl_isempty(vim.api.nvim_get_hl(0, { name = name })) then 40 - vim.api.nvim_set_hl(0, name, defaulthl) 41 - end 42 - vim.api.nvim_set_hl(0, revname, utils.reverse_hl(name)) 43 - end) 44 - end 45 - 46 - function M.resethl() 47 - vim.iter(pairs(default_hls)):each(function(mode, _) 48 - local name, revname = utils.get_modehl_name(mode) 49 - vim.api.nvim_set_hl(0, name, {}) 50 - vim.api.nvim_set_hl(0, revname, {}) 51 - end) 52 - end 53 - 54 - M.initialized = false 55 - 56 - function M.init() 57 - if M.initialized then 58 - return 59 - end 60 - 61 - M.initialized = true 62 - 63 - vim.api.nvim_create_autocmd({ "UIEnter", "WinNew", "WinEnter" }, { 64 - group = vim.api.nvim_create_augroup("@lylla.win", { clear = true }), 65 - callback = function() 66 - local win = vim.api.nvim_get_current_win() 67 - if not require("lylla.statusline").wins[win] then 68 - require("lylla.statusline"):new(win):init() 69 - end 70 - end, 71 - }) 72 - 73 - vim.api.nvim_create_autocmd("WinClosed", { 74 - group = vim.api.nvim_create_augroup("@lylla.close", { clear = true }), 75 - callback = function(ev) 76 - local stl = require("lylla.statusline").wins[ev.match] 77 - if stl then 78 - stl:close() 79 - end 80 - end, 81 - }) 82 - 83 - if config.get().tabline ~= vim.NIL then 84 - require("lylla.tabline").setup() 85 - end 86 - 87 - vim.api.nvim_create_autocmd("ColorSchemePre", { 88 - group = vim.api.nvim_create_augroup("@lylla.resethl", { clear = true }), 89 - callback = function() 90 - M.resethl() 91 - end, 92 - }) 93 - vim.api.nvim_create_autocmd("ColorScheme", { 94 - group = vim.api.nvim_create_augroup("@lylla.inithls", { clear = true }), 95 - callback = function() 96 - M.inithls() 97 - end, 98 - }) 99 - M.inithls() 100 15 end 101 16 102 17 -- helpers
+79 -4
plugin/lylla.lua
··· 1 - if vim.g.loaded_statusline then 1 + if vim.g.loaded_lylla then 2 2 return 3 3 end 4 4 5 - vim.g.loaded_statusline = true 5 + vim.g.loaded_lylla = true 6 + 7 + local lzrq = function(modname) 8 + return vim.defaulttable(function(k) 9 + return require(modname)[k] 10 + end) 11 + end 12 + 13 + local config = lzrq("lylla.config") 14 + local utils = lzrq("lylla.utils") 15 + 16 + -- highlights ================================================================= 17 + 18 + ---@type table<'normal'|'visual'|'command'|'insert'|'replace'|'operator', vim.api.keyset.highlight> 19 + local default_hls = { 20 + normal = { link = "@property" }, 21 + visual = { link = "@constant" }, 22 + command = { link = "@function" }, 23 + insert = { link = "@variable" }, 24 + replace = { link = "@type" }, 25 + operator = { link = "NonText" }, 26 + } 27 + 28 + local function set_hl(name, hl) 29 + hl.default = true 30 + vim.api.nvim_set_hl(0, name, hl) 31 + end 32 + 33 + local function inithls() 34 + vim.iter(pairs(default_hls)):each(function(mode, defaulthl) 35 + local hl = config.get().hls[mode] 36 + local name, revname = utils.get_modehl_name(mode) 37 + if hl then 38 + set_hl(name, hl) 39 + elseif vim.tbl_isempty(vim.api.nvim_get_hl(0, { name = name })) then 40 + set_hl(name, defaulthl) 41 + end 42 + set_hl(revname, utils.reverse_hl(name)) 43 + end) 44 + end 45 + 46 + -- init ======================================================================= 47 + 48 + local function init() 49 + vim.api.nvim_create_autocmd({ "UIEnter", "WinNew", "WinEnter" }, { 50 + group = vim.api.nvim_create_augroup("@lylla.win", { clear = true }), 51 + callback = function() 52 + local win = vim.api.nvim_get_current_win() 53 + if not require("lylla.statusline").wins[win] then 54 + require("lylla.statusline"):new(win):init() 55 + end 56 + end, 57 + }) 58 + 59 + vim.api.nvim_create_autocmd("WinClosed", { 60 + group = vim.api.nvim_create_augroup("@lylla.close", { clear = true }), 61 + callback = function(ev) 62 + local stl = require("lylla.statusline").wins[ev.match] 63 + if stl then 64 + stl:close() 65 + end 66 + end, 67 + }) 68 + 69 + if config.get().tabline ~= vim.NIL then 70 + require("lylla.tabline").setup() 71 + end 72 + 73 + vim.api.nvim_create_autocmd("ColorScheme", { 74 + group = vim.api.nvim_create_augroup("@lylla.hls", { clear = true }), 75 + callback = function() 76 + inithls() 77 + end, 78 + }) 79 + inithls() 80 + end 6 81 7 82 if vim.v.vim_did_enter > 0 then 8 - require("lylla").init() 83 + init() 9 84 else 10 85 vim.api.nvim_create_autocmd("VimEnter", { 11 86 group = vim.api.nvim_create_augroup("@lylla.init", { clear = true }), 12 87 callback = function() 13 - require("lylla").init() 88 + init() 14 89 end, 15 90 }) 16 91 end