reimplement vi's 'e' command

This commit is contained in:
2025-07-20 17:48:45 +01:00
parent 146953c25d
commit d3e54d4102
2 changed files with 30 additions and 2 deletions

View File

@@ -184,10 +184,39 @@ struct
end end
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 *) (* w *)
val startOfNextWord = StartOfNextWord.next val startOfNextWord = StartOfNextWord.next
(* ge *) (* ge *)
val endOfPrevWord = EndOfPrevWord.prev val endOfPrevWord = EndOfPrevWord.prev
(* b *) (* b *)
val startOfCurrentWord = StartOfCurrentWord.prev val startOfCurrentWord = StartOfCurrentWord.prev
(* e *)
val endOfCurrentWord = EndOfCurrentWord.next
end end

View File

@@ -1055,8 +1055,7 @@ struct
end end
(* equivalent of vi's `e` command *) (* equivalent of vi's `e` command *)
fun endOfWord (lineGap, cursorIdx) = val endOfWord = ViWordDfa.endOfCurrentWord
toEndOfWord (lineGap, cursorIdx, helpEndOfWord)
(* equivalent of vi's `E` command *) (* equivalent of vi's `E` command *)
val endOfWORD = ViWORDDfa.endOfCurrentWORD val endOfWORD = ViWORDDfa.endOfCurrentWORD