blob: 3c6f89ece5bed973b673dda56615fd2c841ba6de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
local fn = vim.fn
local M = {}
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
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
return M
|