reimplement vi's 'E' command

This commit is contained in:
2025-07-20 14:00:59 +01:00
parent 2b060b99a0
commit 90c0d657bc
2 changed files with 32 additions and 2 deletions

View File

@@ -136,7 +136,38 @@ struct
end end
end) end)
val startOfNextWORD = StartOfNextWORD.next structure EndOfCurrentWORD =
val endOfPrevWORD = EndOfPrevWORD.prev MakeNextDfaLoopPlus1
val startOfCurrentWORD = StartOfCurrentWORD.prev (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 end

View File

@@ -1169,8 +1169,7 @@ struct
toEndOfWord (lineGap, cursorIdx, helpEndOfWord) toEndOfWord (lineGap, cursorIdx, helpEndOfWord)
(* equivalent of vi's `E` command *) (* equivalent of vi's `E` command *)
fun endOfWORD (lineGap, cursorIdx) = val endOfWORD = ViWORDDfa.endOfCurrentWORD
toEndOfWord (lineGap, cursorIdx, helpEndOfWORD)
(* vi's 'e' command takes user last char in word (* vi's 'e' command takes user last char in word
* but 'de' deletes up to and including last char of word * but 'de' deletes up to and including last char of word