From d3e54d4102857f97c97ac81e4bb1119cc23d2a2d Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 20 Jul 2025 17:48:45 +0100 Subject: [PATCH] reimplement vi's 'e' command --- fcore/cursor-dfa/vi-word-dfa.sml | 29 +++++++++++++++++++++++++++++ fcore/cursor.sml | 3 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/fcore/cursor-dfa/vi-word-dfa.sml b/fcore/cursor-dfa/vi-word-dfa.sml index 97ffbd3..e1321c8 100644 --- a/fcore/cursor-dfa/vi-word-dfa.sml +++ b/fcore/cursor-dfa/vi-word-dfa.sml @@ -184,10 +184,39 @@ struct end end) + structure EndOfCurrentWord = MakeNextDfaLoopPlus1 ( + struct + val startState = startState + + fun fStart (idx, absIdx, str, tl, currentState, counter) = + if idx = String.size str then + case tl of + str :: tl => + fStart (0, absIdx, str, tl, currentState, counter) + | [] => Int.max (0, absIdx - 2) + else + let + val chr = String.sub (str, idx) + val newState = next (currentState, chr) + in + if newState = alphaToSpace orelse newState = punctToSpace + orelse newState = alphaToPunct orelse newState = punctToAlpha then + if counter - 1 = 0 then + absIdx - 1 + else + fStart (idx + 1, absIdx + 1, str, tl, startState, counter - 1) + else + fStart (idx + 1, absIdx + 1, str, tl, newState, counter) + end + end + ) + (* w *) val startOfNextWord = StartOfNextWord.next (* ge *) val endOfPrevWord = EndOfPrevWord.prev (* b *) val startOfCurrentWord = StartOfCurrentWord.prev + (* e *) + val endOfCurrentWord = EndOfCurrentWord.next end diff --git a/fcore/cursor.sml b/fcore/cursor.sml index fd73b36..bc0a51f 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -1055,8 +1055,7 @@ struct end (* equivalent of vi's `e` command *) - fun endOfWord (lineGap, cursorIdx) = - toEndOfWord (lineGap, cursorIdx, helpEndOfWord) + val endOfWord = ViWordDfa.endOfCurrentWord (* equivalent of vi's `E` command *) val endOfWORD = ViWORDDfa.endOfCurrentWORD