blob: 160fbcea29cbcd2f3714294f2ac6e451d1e4397e (
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 m {})
(local window {})
(local aug vim.api.nvim_create_augroup)
(local del-aug vim.api.nvim_del_augroup_by_id)
(local au vim.api.nvim_create_autocmd)
(local winvar (fn [...] (pcall vim.api.nvim_win_get_var ...)))
(local unmap (fn [{: mode : lhs : opts}] (pcall vim.keymap.del mode lhs opts)))
(local map (fn [mode lhs rhs opts] (vim.keymap.set mode lhs rhs opts)))
(fn window.close [self]
(if (self:open?)
(set self.handle (vim.api.nvim_win_close self.handle true))))
(fn window.open [self buf frame]
(set frame.style :minimal)
(set self.handle (vim.api.nvim_open_win buf false frame))
(vim.api.nvim_win_set_var self.handle :effect-window self)
(if self.enter
(vim.api.nvim_set_current_win self.handle)))
(fn window.id [self]
self.handle)
(fn window.open? [self]
(if self.handle
(vim.api.nvim_win_is_valid self.handle) false))
(fn window.new [self i enter maps]
(local w (setmetatable {: i : enter : maps} window))
(set self.__index self)
w)
(fn m.new-window [self maps]
(local w (window:new (+ (length self.windows) 1) (= (length self.windows) 0)
maps))
(table.insert self.windows w)
w)
(fn m.close [self]
(each [_ w (ipairs self.windows)]
(w:close))
(if self.augroup
(set self.augroup (del-aug self.augroup)))
(if self.unmap
(set self.unmap (self.unmap))))
(fn m.attach [self]
(set self.augroup (aug :EffectsMgr {:clear true}))
(au [:WinEnter :BufEnter]
{:group self.augroup
:pattern "*"
:callback (fn [cb-info]
(local (ok? win) (winvar 0 :effect-window))
(if (not ok?)
(self:close)
(do
(if win.maps
(self:win-maps win)))))}))
(fn m.win-maps [self win]
(if self.unmap
(self.unmap))
(set self.unmap (fn []
(each [_ m (ipairs win.maps)]
(unmap m))))
(each [_ {: mode : lhs : rhs : opts} (ipairs win.maps)]
(map mode lhs (rhs self win) opts)))
(fn m.new [self opts]
(local effects {:windows []})
(setmetatable effects self)
(set self.__index self)
effects)
m
|