forked from bfredl/bfredl.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.lua
More file actions
111 lines (97 loc) · 2.28 KB
/
util.lua
File metadata and controls
111 lines (97 loc) · 2.28 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
local h = _G._bfredl_util or {}
_G._bfredl_util = h
h.counter = h.counter or 0
function h.id()
h.counter = h.counter + 1
return h.counter
end
function h.unprefix(str, pre, to)
if vim.startswith(str, pre) then
local val = string.sub(str, string.len(pre)+1)
if to then
return to(val)
else
return val
end
end
return nil
end
h.a = {}
h.buf, h.win, h.tabpage = {}, {}, {}
local a, buf, win, tabpage = h.a, h.buf, h.win, h.tabpage
for k,v in pairs(vim.api) do
a[k] = v
h.unprefix(k, 'nvim_', function (x)
a[x] = v
h.unprefix(x, 'buf_', function (m)
buf[m] = v
end)
h.unprefix(x, 'win_', function (m)
win[m] = v
end)
h.unprefix(x, 'tabpage_', function (m)
tabpage[m] = v
end)
h.unprefix(x, '_buf_', function (m)
buf['_'..m] = v
end)
end)
end
function h.exec(block)
a.exec(block, false)
end
function h.code(str)
return a.replace_termcodes(str, true, true, true)
end
function h.namelist()
local list = {}
local function byggare(name)
if name == nil then
return list
end
return function (value)
value.name = name
table.insert(list, value)
return byggare
end
end
return byggare
end
h.options = a.get_all_options_info()
for n,v in pairs(a.get_all_options_info()) do
if v.shortname ~= "" then h.options[v.shortname] = h.options[n] end
end
h.set = (function()
local function meta(name)
local boolval = true
h.unprefix(name, 'no', function(nam)
if h.options[nam] and h.options[nam].type == 'boolean' then
name = nam
boolval = false
end
end)
local o = h.options[name]
if not o then
error(name)
end
local function unmeta(val)
-- all options except window options have global value,
-- because reasons.
if o.global_local or o.scope ~= "win" then
a.set_option(name, val)
end
if o.scope == "win" then
win.set_option(0, name, val)
elseif o.scope == "buf" then
buf.set_option(0, name, val)
end
return meta
end
return o.type == "boolean" and unmeta(boolval) or unmeta
end
return meta
end)()
function h.mapcmd(lhs) return function(cmd)
a.set_keymap('', lhs, '<cmd>'..string.gsub(cmd,'<','<lt>')..'<cr>', {noremap=true})
end end
return h