reimplemented vi's 'B' command (although it needs a little refactoring)
This commit is contained in:
@@ -3,7 +3,8 @@ struct
|
|||||||
val startState: Word8.word = 0w0
|
val startState: Word8.word = 0w0
|
||||||
val startNonBlankState: Word8.word = 0w1
|
val startNonBlankState: Word8.word = 0w1
|
||||||
val startSpaceState: Word8.word = 0w2
|
val startSpaceState: Word8.word = 0w2
|
||||||
val nonBlankAfterSpaceState: Word8.word = 0w4
|
val nonBlankAfterSpaceState: Word8.word = 0w3
|
||||||
|
val spaceAfterNonBlankState = 0w4
|
||||||
|
|
||||||
fun makeStart i =
|
fun makeStart i =
|
||||||
let val chr = Char.chr i
|
let val chr = Char.chr i
|
||||||
@@ -12,7 +13,7 @@ struct
|
|||||||
|
|
||||||
fun makeStartNonBlankState i =
|
fun makeStartNonBlankState i =
|
||||||
let val chr = Char.chr i
|
let val chr = Char.chr i
|
||||||
in if Char.isSpace chr then startSpaceState else startNonBlankState
|
in if Char.isSpace chr then spaceAfterNonBlankState else startNonBlankState
|
||||||
end
|
end
|
||||||
|
|
||||||
fun makeStartSpace i =
|
fun makeStartSpace i =
|
||||||
@@ -20,11 +21,27 @@ struct
|
|||||||
in if Char.isSpace chr then startSpaceState else nonBlankAfterSpaceState
|
in if Char.isSpace chr then startSpaceState else nonBlankAfterSpaceState
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun makeNonBlankAfterSpace i =
|
||||||
|
let
|
||||||
|
val chr = Char.chr i
|
||||||
|
in
|
||||||
|
if Char.isSpace chr then spaceAfterNonBlankState
|
||||||
|
else nonBlankAfterSpaceState
|
||||||
|
end
|
||||||
|
|
||||||
val startTable = Vector.tabulate (255, makeStart)
|
val startTable = Vector.tabulate (255, makeStart)
|
||||||
val startNonBlankTable = Vector.tabulate (255, makeStartNonBlankState)
|
val startNonBlankTable = Vector.tabulate (255, makeStartNonBlankState)
|
||||||
val startSpaceTable = Vector.tabulate (255, makeStartSpace)
|
val startSpaceTable = Vector.tabulate (255, makeStartSpace)
|
||||||
|
val nonBlankAfterSpaceTable = Vector.tabulate (255, makeNonBlankAfterSpace)
|
||||||
|
val spaceAfterNonBlankTable = nonBlankAfterSpaceTable
|
||||||
|
|
||||||
val tables = #[startTable, startNonBlankTable, startSpaceTable]
|
val tables =
|
||||||
|
#[ startTable
|
||||||
|
, startNonBlankTable
|
||||||
|
, startSpaceTable
|
||||||
|
, nonBlankAfterSpaceTable
|
||||||
|
, spaceAfterNonBlankTable
|
||||||
|
]
|
||||||
|
|
||||||
fun next (currentState, currentChar) =
|
fun next (currentState, currentChar) =
|
||||||
let
|
let
|
||||||
@@ -91,6 +108,39 @@ struct
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
structure StartOfCurrentWORD =
|
||||||
|
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 = spaceAfterNonBlankState 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)
|
||||||
|
|
||||||
val startOfNextWORD = StartOfNextWORD.next
|
val startOfNextWORD = StartOfNextWORD.next
|
||||||
val endOfPrevWORD = EndOfPrevWORD.prev
|
val endOfPrevWORD = EndOfPrevWORD.prev
|
||||||
|
|
||||||
|
fun startOfCurrentWORD (lineGap: LineGap.t, cursorIdx) =
|
||||||
|
let val lineGap = LineGap.goToIdx (cursorIdx - 1, lineGap)
|
||||||
|
in StartOfCurrentWORD.prev (lineGap, cursorIdx - 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1038,8 +1038,7 @@ struct
|
|||||||
toPrevWord (lineGap, cursorIdx, helpPrevWord)
|
toPrevWord (lineGap, cursorIdx, helpPrevWord)
|
||||||
|
|
||||||
(* equivalent of vi's 'B' command *)
|
(* equivalent of vi's 'B' command *)
|
||||||
fun prevWORD (lineGap, cursorIdx) =
|
val prevWORD = ViWORDDfa.startOfCurrentWORD
|
||||||
toPrevWord (lineGap, cursorIdx, helpPrevWORD)
|
|
||||||
|
|
||||||
fun toEndOfPrevWord (lineGap: LineGap.t, cursorIdx, fPrev) =
|
fun toEndOfPrevWord (lineGap: LineGap.t, cursorIdx, fPrev) =
|
||||||
let
|
let
|
||||||
|
|||||||
Reference in New Issue
Block a user