From 90c0d657bc653ee6d10cfb9a95de445881119490 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 20 Jul 2025 14:00:59 +0100 Subject: [PATCH] reimplement vi's 'E' command --- fcore/cursor-dfa/vi-WORD-dfa.sml | 31 +++++++++++++++++++++++++++++++ fcore/cursor.sml | 3 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/fcore/cursor-dfa/vi-WORD-dfa.sml b/fcore/cursor-dfa/vi-WORD-dfa.sml index f661f60..6662df0 100644 --- a/fcore/cursor-dfa/vi-WORD-dfa.sml +++ b/fcore/cursor-dfa/vi-WORD-dfa.sml @@ -136,7 +136,38 @@ 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 = spaceAfterNonBlankState then + if counter - 1 = 0 then + Int.max (0, 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 7f32166..955b0af 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -1169,8 +1169,7 @@ struct toEndOfWord (lineGap, cursorIdx, helpEndOfWord) (* equivalent of vi's `E` command *) - fun endOfWORD (lineGap, cursorIdx) = - toEndOfWord (lineGap, cursorIdx, helpEndOfWORD) + val endOfWORD = ViWORDDfa.endOfCurrentWORD (* vi's 'e' command takes user last char in word * but 'de' deletes up to and including last char of word