@@ -24,28 +24,42 @@ local memoization_mt = {
2424-- low level factory
2525-- invalidate(table) -> bool: decides if the memoization should be invalidated,
2626-- can store state in table
27- -- TODO provide invalidate defaults (buffer, cursor, changes, none)
2827function M .memoization_factory (func , invalidate )
2928 -- always invalidare by default
3029 invalidate = invalidate or function () return true end
3130 return setmetatable ({func = func , invalidate = invalidate }, memoization_mt )
3231end
3332
34- ---- ---------
35- -- PRESETS --
36- ---- ---------
33+ ---- ---------------
34+ -- INVAL PRESETS --
35+ ---- ---------------
36+ -- TODO provide invalidate defaults (buffer, cursor, changes, none)
37+ M .inval = {}
38+ -- just a small example to illustrate the usage (will most probably have to be
39+ -- changed)
40+ function M .inval .line (tab , _ , _ , _ , line )
41+ return tab .line ~= line
42+ end
43+
44+ ---- --------------
45+ -- COND PRESETS --
46+ ---- --------------
3747local function line_begin (line_to_cursor , matched_trigger )
3848 -- +1 because `string.sub("abcd", 1, -2)` -> abc
3949 return line_to_cursor :sub (1 , - (# matched_trigger + 1 )):match (" ^%s*$" )
4050end
41- function M .line_begin () return M .memoization_factory (line_begin , nil ) -- TODO invalidation function
51+ function M .line_begin ()
52+ -- TODO invalidation function
53+ return M .memoization_factory (line_begin , nil )
4254end
4355
4456local function line_end (line_to_cursor )
4557 local line = vim .api .nvim_get_current_line ()
4658 return # line_to_cursor == # line
4759end
48- function M .line_end () return M .memoization_factory (line_end , nil ) -- TODO invalidation function
60+ function M .line_end ()
61+ -- TODO invalidation function
62+ return M .memoization_factory (line_end , nil )
4963end
5064
5165return M
0 commit comments