diff options
author | christianchiarulli <[email protected]> | 2021-07-18 14:10:19 -0400 |
---|---|---|
committer | christianchiarulli <[email protected]> | 2021-07-18 14:10:19 -0400 |
commit | b797c2398fafaaa3e5f81d9e1630a41240a31bf8 (patch) | |
tree | 3dd23047f7fd09a4b13d4728696751b4f685f3fe /lua/lv-utils | |
parent | a3f3f3b60cf675e3a80d3285dff136d193cfbb53 (diff) | |
parent | 6f9c521e227b1c4d3741cb73ee0a9598be73ef10 (diff) |
Merge branch 'rolling' of github.com:ChristianChiarulli/LunarVim into rolling
Diffstat (limited to 'lua/lv-utils')
-rw-r--r-- | lua/lv-utils/init.lua | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lua/lv-utils/init.lua b/lua/lv-utils/init.lua index bc2b51b7..c88c106d 100644 --- a/lua/lv-utils/init.lua +++ b/lua/lv-utils/init.lua @@ -1,5 +1,61 @@ local lv_utils = {} +-- recursive Print (structure, limit, separator) +local function r_inspect_settings(structure, limit, separator) + limit = limit or 100 -- default item limit + separator = separator or "." -- indent string + if limit < 1 then + print "ERROR: Item limit reached." + return limit - 1 + end + if structure == nil then + io.write("-- O", separator:sub(2), " = nil\n") + return limit - 1 + end + local ts = type(structure) + + if ts == "table" then + for k, v in pairs(structure) do + -- replace non alpha keys wih ["key"] + if tostring(k):match "[^%a_]" then + k = '["' .. tostring(k) .. '"]' + end + limit = r_inspect_settings(v, limit, separator .. "." .. tostring(k)) + if limit < 0 then + break + end + end + return limit + end + + if ts == "string" then + -- escape sequences + structure = string.format("%q", structure) + end + separator = separator:gsub("%.%[", "%[") + if type(structure) == "function" then + -- don't print functions + io.write("-- O", separator:sub(2), " = function ()\n") + else + io.write("O", separator:sub(2), " = ", tostring(structure), "\n") + end + return limit - 1 +end + +function lv_utils.generate_settings() + -- Opens a file in append mode + local file = io.open("lv-settings.lua", "w") + + -- sets the default output file as test.lua + io.output(file) + + -- write all `O` related settings to `lv-settings.lua` file + r_inspect_settings(O, 10000, ".") + + -- closes the open file + io.close(file) +end + function lv_utils.reload_lv_config() vim.cmd "source ~/.config/nvim/lua/keymappings.lua" vim.cmd "source ~/.config/nvim/lv-config.lua" @@ -21,6 +77,32 @@ function lv_utils.check_lsp_client_active(name) return false end +function lv_utils.add_keymap(mode, opts, keymaps) + for _, keymap in ipairs(keymaps) do + vim.api.nvim_set_keymap(mode, keymap[1], keymap[2], opts) + end +end + +function lv_utils.add_keymap_normal_mode(opts, keymaps) + lv_utils.add_keymap("n", opts, keymaps) +end + +function lv_utils.add_keymap_visual_mode(opts, keymaps) + lv_utils.add_keymap("v", opts, keymaps) +end + +function lv_utils.add_keymap_visual_block_mode(opts, keymaps) + lv_utils.add_keymap("x", opts, keymaps) +end + +function lv_utils.add_keymap_insert_mode(opts, keymaps) + lv_utils.add_keymap("i", opts, keymaps) +end + +function lv_utils.add_keymap_term_mode(opts, keymaps) + lv_utils.add_keymap("t", opts, keymaps) +end + function lv_utils.define_augroups(definitions) -- {{{1 -- Create autocommand groups based on the passed definitions -- |