reimplement vi's 'ge' command (endOfPrevWord)
This commit is contained in:
@@ -108,6 +108,36 @@ struct
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
structure EndOfPrevWord =
|
||||||
|
MakePrevDfaLoop (
|
||||||
|
struct
|
||||||
|
val startState = startState
|
||||||
|
|
||||||
|
fun fStart (idx, absIdx, str, tl, currentState, counter) =
|
||||||
|
if idx < 0 then
|
||||||
|
case tl of
|
||||||
|
str :: tl => fStart (String.size str - 1, absIdx, str, tl, currentState, counter)
|
||||||
|
| [] => 0
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (str, idx)
|
||||||
|
val newState = next (currentState, chr)
|
||||||
|
in
|
||||||
|
if newState = alphaToPunct orelse newState = punctToAlpha
|
||||||
|
orelse newState = spaceToAlpha orelse newState = spaceToPunct
|
||||||
|
then
|
||||||
|
if counter - 1 = 0 then
|
||||||
|
absIdx
|
||||||
|
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 *)
|
||||||
|
val endOfPrevWord = EndOfPrevWord.prev
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -980,40 +980,8 @@ struct
|
|||||||
(* equivalent of vi's 'B' command *)
|
(* equivalent of vi's 'B' command *)
|
||||||
val prevWORD = ViWORDDfa.startOfCurrentWORD
|
val prevWORD = ViWORDDfa.startOfCurrentWORD
|
||||||
|
|
||||||
fun toEndOfPrevWord (lineGap: LineGap.t, cursorIdx, fPrev) =
|
|
||||||
let
|
|
||||||
val
|
|
||||||
{rightStrings, rightLines, leftStrings, leftLines, idx = bufferIdx, ...} =
|
|
||||||
lineGap
|
|
||||||
in
|
|
||||||
case (rightStrings, rightLines) of
|
|
||||||
(shd :: stl, lhd :: ltl) =>
|
|
||||||
let
|
|
||||||
(* convert absolute cursorIdx to idx relative to hd string *)
|
|
||||||
val strIdx = cursorIdx - bufferIdx
|
|
||||||
in
|
|
||||||
if strIdx < String.size shd then
|
|
||||||
(* strIdx is in this string *)
|
|
||||||
fPrev (strIdx, shd, cursorIdx, leftStrings, leftLines)
|
|
||||||
else
|
|
||||||
(* strIdx is in tl *)
|
|
||||||
(case (stl, ltl) of
|
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
|
||||||
let
|
|
||||||
val strIdx = strIdx - String.size shd
|
|
||||||
val leftStrings = shd :: leftStrings
|
|
||||||
val leftLines = lhd :: leftLines
|
|
||||||
in
|
|
||||||
fPrev (strIdx, shd, cursorIdx, leftStrings, leftLines)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx
|
|
||||||
end
|
|
||||||
|
|
||||||
(* equivalent of vi's 'ge' command *)
|
(* equivalent of vi's 'ge' command *)
|
||||||
fun endOfPrevWord (lineGap, cursorIdx) =
|
val endOfPrevWord = ViWordDfa.endOfPrevWord
|
||||||
toEndOfPrevWord (lineGap, cursorIdx, helpEndOfPrevWord)
|
|
||||||
|
|
||||||
(* equivalent of vi's 'gE' command *)
|
(* equivalent of vi's 'gE' command *)
|
||||||
val endOfPrevWORD = ViWORDDfa.endOfPrevWORD
|
val endOfPrevWORD = ViWORDDfa.endOfPrevWORD
|
||||||
|
|||||||
Reference in New Issue
Block a user