1
- --- @diagnostic disable-next-line : redefined-local
1
+ local api = vim . api
2
2
local F = {}
3
3
4
4
-- Core FP utilities
@@ -37,44 +37,46 @@ F.pipe = function(x, ...)
37
37
end
38
38
39
39
-- Maybe Monad
40
- local Maybe = {}
41
- Maybe .of = function (x )
42
- return { value = x }
43
- end
44
- Maybe .nothing = Maybe .of (nil )
45
- Maybe .isNothing = function (maybe )
46
- return maybe .value == nil
47
- end
48
- Maybe .fromNullable = function (x )
49
- return x == nil and Maybe .nothing or Maybe .of (x )
50
- end
51
-
52
- Maybe .map = F .curry (function (fn , maybe )
53
- if Maybe .isNothing (maybe ) then
54
- return Maybe .nothing
55
- end
56
- return Maybe .of (fn (maybe .value ))
57
- end )
58
-
59
- Maybe .chain = F .curry (function (fn , maybe )
60
- if Maybe .isNothing (maybe ) then
61
- return Maybe .nothing
62
- end
63
- return fn (maybe .value )
64
- end )
40
+ F .Maybe = {
41
+ of = function (x )
42
+ return { kind = ' Maybe' , value = x }
43
+ end ,
44
+ nothing = { kind = ' Maybe' , value = nil },
45
+ isNothing = function (maybe )
46
+ return maybe .value == nil
47
+ end ,
48
+ fromNullable = function (x )
49
+ return x == nil and F .Maybe .nothing or F .Maybe .of (x )
50
+ end ,
51
+ map = function (maybe , f )
52
+ if F .Maybe .isNothing (maybe ) then
53
+ return F .Maybe .nothing
54
+ end
55
+ return F .Maybe .of (f (maybe .value ))
56
+ end ,
57
+ chain = function (maybe , f )
58
+ if F .Maybe .isNothing (maybe ) then
59
+ return F .Maybe .nothing
60
+ end
61
+ return f (maybe .value )
62
+ end ,
63
+ getOrElse = function (maybe , default )
64
+ return maybe .value or default
65
+ end ,
66
+ }
65
67
66
68
-- Pure state management
67
69
local StateManager = {}
68
70
StateManager .get = function ()
69
71
return {
70
72
get_line = function ()
71
- return vim . api .nvim_get_current_line ()
73
+ return api .nvim_get_current_line ()
72
74
end ,
73
75
get_cursor = function ()
74
- return vim . api .nvim_win_get_cursor (0 )
76
+ return api .nvim_win_get_cursor (0 )
75
77
end ,
76
78
get_mode = function ()
77
- return vim . api .nvim_get_mode ().mode
79
+ return api .nvim_get_mode ().mode
78
80
end ,
79
81
}
80
82
end
@@ -90,7 +92,7 @@ State.new = function()
90
92
}
91
93
end
92
94
93
- -- BracketPair ADT
95
+ -- BracketPair ADT with configuration support
94
96
local BracketPair = {
95
97
[' (' ] = ' )' ,
96
98
[' [' ] = ' ]' ,
@@ -115,7 +117,7 @@ local Action = {
115
117
116
118
-- Pure functions for character handling
117
119
local get_char_at = F .curry (function (pos , state )
118
- return Maybe .fromNullable (state .line :sub (pos (state ), pos (state )))
120
+ return F . Maybe .fromNullable (state .line :sub (pos (state ), pos (state )))
119
121
end )
120
122
121
123
local get_char_before = get_char_at (function (state )
@@ -162,7 +164,7 @@ local determine_action = F.curry(function(char, state)
162
164
end
163
165
164
166
local next_char = get_char_after (state )
165
- if not Maybe .isNothing (next_char ) and next_char .value == BracketPair [char ] then
167
+ if not F . Maybe .isNothing (next_char ) and next_char .value == BracketPair [char ] then
166
168
local substr = state .line :sub (state .cursor [2 ] + 1 , state .cursor [2 ] + 1 )
167
169
if check_bracket_balance (substr , char ) then
168
170
return Action .Skip
176
178
local handle_skip = function ()
177
179
return ' <Right>'
178
180
end
181
+
179
182
local handle_insert = function (action )
180
183
return action .opening .. action .closing .. ' <Left>'
181
184
end
0 commit comments