aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/user/utils.lua
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-02-10 11:22:07 +0200
committersrdusr <trevorgray@srdusr.com>2023-02-10 11:22:07 +0200
commit7cee6e5a673defef72c803eca094d1247c31bb9c (patch)
tree1dbc97c5ece5f574ef5091d549fb434a8b59a625 /.config/nvim/lua/user/utils.lua
parentb91ee8da3ef2c1c154833b4b6e99250fe2c280e7 (diff)
parentf76f2c4bbc1ddde4b5c0882863060e4c58a11733 (diff)
downloaddotfiles-7cee6e5a673defef72c803eca094d1247c31bb9c.tar.gz
dotfiles-7cee6e5a673defef72c803eca094d1247c31bb9c.zip
Add '.config/nvim/' from commit 'e707f3abc83e0621eab64b4828defd0c80dff5c0'
git-subtree-dir: .config/nvim git-subtree-mainline: bb29321714929e1b7b962dd47b486325fd77e67a git-subtree-split: e707f3abc83e0621eab64b4828defd0c80dff5c0
Diffstat (limited to '.config/nvim/lua/user/utils.lua')
-rw-r--r--.config/nvim/lua/user/utils.lua111
1 files changed, 111 insertions, 0 deletions
diff --git a/.config/nvim/lua/user/utils.lua b/.config/nvim/lua/user/utils.lua
new file mode 100644
index 0000000..07867a4
--- /dev/null
+++ b/.config/nvim/lua/user/utils.lua
@@ -0,0 +1,111 @@
+local M = {}
+
+--- Shorten Function Names
+local fn = vim.fn
+function M.executable(name)
+ if fn.executable(name) > 0 then
+ return true
+ end
+
+ return false
+end
+
+
+--------------------------------------------------
+
+--- Check whether a feature exists in Nvim
+--- @feat: string
+--- the feature name, like `nvim-0.7` or `unix`.
+--- return: bool
+M.has = function(feat)
+ if fn.has(feat) == 1 then
+ return true
+ end
+
+ return false
+end
+
+
+--------------------------------------------------
+
+--- Create a dir if it does not exist
+function M.may_create_dir(dir)
+ local res = fn.isdirectory(dir)
+
+ if res == 0 then
+ fn.mkdir(dir, "p")
+ end
+end
+
+
+--------------------------------------------------
+
+--- Toggle cmp completion
+vim.g.cmp_toggle_flag = false -- initialize
+local normal_buftype = function()
+ return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt"
+end
+M.toggle_completion = function()
+ local ok, cmp = pcall(require, "cmp")
+ if ok then
+ local next_cmp_toggle_flag = not vim.g.cmp_toggle_flag
+ if next_cmp_toggle_flag then
+ print("completion on")
+ else
+ print("completion off")
+ end
+ cmp.setup({
+ enabled = function()
+ vim.g.cmp_toggle_flag = next_cmp_toggle_flag
+ if next_cmp_toggle_flag then
+ return normal_buftype
+ else
+ return next_cmp_toggle_flag
+ end
+ end,
+ })
+ else
+ print("completion not available")
+ end
+end
+
+
+--------------------------------------------------
+
+--- Make sure using latest neovim version
+function M.get_nvim_version()
+ local actual_ver = vim.version()
+
+ local nvim_ver_str = string.format("%d.%d.%d", actual_ver.major, actual_ver.minor, actual_ver.patch)
+ return nvim_ver_str
+end
+
+function M.add_pack(name)
+ local status, error = pcall(vim.cmd, "packadd " .. name)
+
+ return status
+end
+
+
+--------------------------------------------------
+
+--- Toggle autopairs on/off (requires "windwp/nvim-autopairs")
+function M.Toggle_autopairs()
+ local ok, autopairs = pcall(require, "nvim-autopairs")
+ if ok then
+ if autopairs.state.disabled then
+ autopairs.enable()
+ print("autopairs on")
+ else
+ autopairs.disable()
+ print("autopairs off")
+ end
+ else
+ print("autopairs not available")
+ end
+end
+
+return M
+
+
+--------------------------------------------------