From 2b060b99a00b89286453326787ec136d75704f41 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 20 Jul 2025 13:52:23 +0100 Subject: [PATCH] add a 'MakeNextDfaLoopPlus1' functor to later use in forward word motions which ignore state of current character but start tracking state from next character. To be used in reimplementations of Vi's 'e' and 'E' commands. --- fcore/cursor-dfa/make-dfa-loop.sml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fcore/cursor-dfa/make-dfa-loop.sml b/fcore/cursor-dfa/make-dfa-loop.sml index 7686c50..8913537 100644 --- a/fcore/cursor-dfa/make-dfa-loop.sml +++ b/fcore/cursor-dfa/make-dfa-loop.sml @@ -29,6 +29,32 @@ struct end end +functor MakeNextDfaLoopPlus1(M: MAKE_DFA_LOOP) = +struct + fun next (lineGap: LineGap.t, cursorIdx) = + let + val {rightStrings, idx = bufferIdx, ...} = lineGap + (* convert absolute cursorIdx to idx relative to hd string *) + val strIdx = cursorIdx - bufferIdx + 1 + val absIdx = cursorIdx + 1 + in + case rightStrings of + shd :: stl => + if strIdx < String.size shd then + (* strIdx is in this string *) + M.fStart (strIdx, absIdx, shd, stl, M.startState, 1) + else + (* strIdx is in tl *) + (case stl of + stlhd :: stltl => + let val strIdx = strIdx - String.size shd + in M.fStart (strIdx, absIdx, stlhd, stltl, M.startState, 1) + end + | _ => cursorIdx) + | [] => cursorIdx + end +end + functor MakePrevDfaLoop(M: MAKE_DFA_LOOP) = struct fun prev (lineGap: LineGap.t, cursorIdx) =