Skip to content

Commit 6112008

Browse files
add condition presets
1 parent 63925f0 commit 6112008

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lua/luasnip/extras/expand_conditions.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
local M = {}
22

3-
function M.line_begin(line_to_cursor, matched_trigger)
4-
-- +1 because `string.sub("abcd", 1, -2)` -> abc
5-
return line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$")
6-
end
7-
8-
function M.line_end(line_to_cursor)
9-
local line = vim.api.nvim_get_current_line()
10-
return #line_to_cursor == #line
11-
end
12-
3+
-----------------------
4+
-- CONDITION OBJECTS --
5+
-----------------------
136
local memoization_mt = {
147
-- logic operators
158
-- not
@@ -38,14 +31,21 @@ function M.memoization_factory(func, invalidate)
3831
return setmetatable({func=func, invalidate=invalidate}, memoization_mt)
3932
end
4033

41-
-- F1 = memoization_factory(function() return true end)
42-
-- F2 = memoization_factory(function() return false end)
43-
-- F3 = F1 + F2
44-
-- F4 = F1 * -F2
45-
--
46-
-- local m = {F1=F1, F2=F2, F3=F3, F4=F4}
47-
-- for _,name in ipairs{"F1", "F2", "F3", "F4"} do
48-
-- print(name, m[name]())
49-
-- end
34+
-------------
35+
-- PRESETS --
36+
-------------
37+
local function line_begin(line_to_cursor, matched_trigger)
38+
-- +1 because `string.sub("abcd", 1, -2)` -> abc
39+
return line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$")
40+
end
41+
function M.line_begin() return M.memoization_factory(line_begin, nil) -- TODO invalidation function
42+
end
43+
44+
local function line_end(line_to_cursor)
45+
local line = vim.api.nvim_get_current_line()
46+
return #line_to_cursor == #line
47+
end
48+
function M.line_end() return M.memoization_factory(line_end, nil) -- TODO invalidation function
49+
end
5050

5151
return M

0 commit comments

Comments
 (0)