-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathenv.vim
54 lines (48 loc) · 1.06 KB
/
env.vim
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
" env module
let Env = {}
function NewEnv(outer)
let e = copy(g:Env)
let e.data = {}
let e.outer = a:outer
return e
endfunction
function NewEnvWithBinds(outer, binds, exprs)
let env = NewEnv(a:outer)
let i = 0
while i < ListCount(a:binds)
let varname = ListNth(a:binds, i).val
if varname == "&"
let restvarname = ListNth(a:binds, i + 1).val
let restvarvalues = ListDrop(a:exprs, i)
call env.set(restvarname, restvarvalues)
break
else
unlet! varvalue
let varvalue = ListNth(a:exprs, i)
call env.set(varname, varvalue)
endif
let i = i + 1
endwhile
return env
endfunction
function Env.set(key, value) dict
let self.data[a:key] = a:value
return a:value
endfunction
function Env.get(key) dict
let curr = self
while !has_key(curr.data, a:key)
let curr = curr.outer
if empty(curr)
return ""
endif
endwhile
return curr.data[a:key]
endfunction
function Env.root() dict
let curr = self
while !empty(curr.outer)
let curr = curr.outer
endwhile
return curr
endfunction