🪴 my neovim config:)
1
fork

Configure Feed

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

plugin: clean guicursor code

robin 24444910 70ee235c

+50 -39
+50 -39
config/plugin/guicursor.lua
··· 1 + if vim.g.loaded_guicursor then 2 + return 3 + end 4 + 5 + vim.g.loaded_guicursor = true 6 + 1 7 local mode_lookup = { 2 8 normal = "n-v", 3 9 insert = "i-c-ci-ve", ··· 12 18 horizontal = "hor", 13 19 } 14 20 21 + local function validate(mode, opts) 22 + vim.validate("mode", mode, function(v) 23 + return vim.tbl_contains({ "normal", "insert", "replace", "operator", "showmatch" }, v) 24 + end, "valid mode") 25 + vim.validate("opts", opts, function(v) 26 + vim.validate("type", v.type, function(t) 27 + return vim.tbl_contains({ "block", "vertical", "horizontal" }, t) 28 + end, "valid type") 29 + if v.type ~= "block" then 30 + vim.validate("size", v.size, function(s) 31 + return type(s) == "number" 32 + end, "valid size with type ~= block") 33 + end 34 + 35 + vim.validate("animate", v.animate, function(anim) 36 + vim.validate("wait", anim.wait, "number") 37 + vim.validate("on", anim.on, "number") 38 + vim.validate("off", anim.off, "number") 39 + return true 40 + end, true, "valid animation") 41 + 42 + return true 43 + end, "valid opts") 44 + end 45 + 15 46 vim.once(function() 16 - local guicursor = vim.iter(pairs(vim.g.guicursor_config or {})):fold("", function(str, mode, opts) 17 - vim.validate("mode", mode, function(v) 18 - return vim.tbl_contains({ "normal", "insert", "replace", "operator", "showmatch" }, v) 19 - end, "valid mode") 20 - vim.validate("opts", opts, function(v) 21 - vim.validate("type", v.type, function(t) 22 - return vim.tbl_contains({ "block", "vertical", "horizontal" }, t) 23 - end, "valid type") 24 - if v.type ~= "block" then 25 - vim.validate("size", v.size, function(s) 26 - return type(s) == "number" 27 - end, "valid size with type ~= block") 28 - end 47 + vim.g.guicursor_config = vim.g.guicursor_config or {} 29 48 30 - if v.animate then 31 - vim.validate("animate", v.animate, function(anim) 32 - vim.validate("wait", anim.wait, "number") 33 - vim.validate("on", anim.on, "number") 34 - vim.validate("off", anim.off, "number") 35 - return true 36 - end, "valid animation") 37 - end 49 + local guicursorset = vim 50 + .iter(pairs(vim.g.guicursor_config)) 51 + :map(function(mode, opts) 52 + validate(mode, opts) 38 53 39 - return true 40 - end, "valid opts") 41 - if #str > 0 then 42 - str = str .. "," 43 - end 44 - local s = string.format( 45 - "%s:%s", 46 - mode_lookup[mode], 47 - opts.type ~= "block" and string.format("%s%d", type_lookup[opts.type], opts.size) or type_lookup[opts.type] 48 - ) 54 + local s = string.format( 55 + "%s:%s", 56 + mode_lookup[mode], 57 + opts.type ~= "block" and string.format("%s%d", type_lookup[opts.type], opts.size) or type_lookup[opts.type] 58 + ) 49 59 50 - if opts.animate then 51 - local anim = opts.animate 52 - local anim_str = string.format("blinkwait%d-blinkon%d-blinkoff%d", anim.wait, anim.on, anim.off) 53 - s = s .. "-" .. anim_str 54 - end 60 + if opts.animate then 61 + local anim = opts.animate 62 + local anim_str = string.format("blinkwait%d-blinkon%d-blinkoff%d", anim.wait, anim.on, anim.off) 63 + s = s .. "-" .. anim_str 64 + end 55 65 56 - return str .. s 57 - end) 66 + return s 67 + end) 68 + :totable() 58 69 59 - vim.opt.guicursor = guicursor 70 + vim.opt.guicursor = table.concat(guicursorset, ",") 60 71 end)