reimplement vi's 'l' motion so that we only skip a newline when it is preceded by a non-newline character
This commit is contained in:
53
fcore/cursor-dfa/vi-l-dfa.sml
Normal file
53
fcore/cursor-dfa/vi-l-dfa.sml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
structure ViLDfa =
|
||||||
|
struct
|
||||||
|
val startState: Word8.word = 0w0
|
||||||
|
val newlineState: Word8.word = 0w1
|
||||||
|
val chrState: Word8.word = 0w2
|
||||||
|
val newlineAfterCHrState: Word8.word = 0w3
|
||||||
|
|
||||||
|
fun makeStart i =
|
||||||
|
if Char.chr i = #"\n" then newlineState else chrState
|
||||||
|
|
||||||
|
fun makeChr i =
|
||||||
|
if Char.chr i = #"\n" then newlineAfterCHrState else chrState
|
||||||
|
|
||||||
|
val startTable = Vector.tabulate (255, makeStart)
|
||||||
|
val newlineTable = startTable
|
||||||
|
val chrTable = Vector.tabulate (255, makeChr)
|
||||||
|
val newlineAfterCHrTable = startTable
|
||||||
|
|
||||||
|
val tables = #[startTable, newlineTable, chrTable, newlineAfterCHrTable]
|
||||||
|
|
||||||
|
fun next (currentState, chr) =
|
||||||
|
let val table = Vector.sub (tables, Word8.toInt currentState)
|
||||||
|
in Vector.sub (table, Char.ord chr)
|
||||||
|
end
|
||||||
|
|
||||||
|
structure ViL =
|
||||||
|
MakeNextDfaLoop
|
||||||
|
(struct
|
||||||
|
val startState = startState
|
||||||
|
|
||||||
|
fun loop (idx, absIdx, str, tl, currentState, counter) =
|
||||||
|
if idx = String.size str then
|
||||||
|
case tl of
|
||||||
|
str :: tl => loop (0, absIdx, str, tl, currentState, counter)
|
||||||
|
| [] => absIdx
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (str, idx)
|
||||||
|
val newState = next (currentState, chr)
|
||||||
|
in
|
||||||
|
if newState = newlineAfterCHrState then
|
||||||
|
loop (idx + 1, absIdx + 1, str, tl, newState, counter)
|
||||||
|
else if counter - 1 = ~1 then
|
||||||
|
absIdx
|
||||||
|
else
|
||||||
|
loop (idx + 1, absIdx + 1, str, tl, newState, counter - 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
val fStart = loop
|
||||||
|
end)
|
||||||
|
|
||||||
|
val next = ViL.next
|
||||||
|
end
|
||||||
@@ -56,7 +56,7 @@ struct
|
|||||||
val viDlr = ViDlrDfa.next
|
val viDlr = ViDlrDfa.next
|
||||||
val viDlrForDelete = ViDlrDfa.nextForDelete
|
val viDlrForDelete = ViDlrDfa.nextForDelete
|
||||||
|
|
||||||
val viL = ViHlDfa.l
|
val viL = ViLDfa.next
|
||||||
val viH = ViHlDfa.h
|
val viH = ViHlDfa.h
|
||||||
|
|
||||||
fun helpGetCursorColumn (distanceFromLine, strList, lineList) =
|
fun helpGetCursorColumn (distanceFromLine, strList, lineList) =
|
||||||
|
|||||||
@@ -137,8 +137,6 @@ struct
|
|||||||
acc
|
acc
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val posX = #startX env
|
|
||||||
val posY = posY + TC.ySpace
|
|
||||||
val acc =
|
val acc =
|
||||||
if absIdx = cursorIdx then
|
if absIdx = cursorIdx then
|
||||||
Utils.makeCursor (posX, posY, env) :: acc
|
Utils.makeCursor (posX, posY, env) :: acc
|
||||||
@@ -151,8 +149,8 @@ struct
|
|||||||
, stl
|
, stl
|
||||||
, line
|
, line
|
||||||
, ltl
|
, ltl
|
||||||
, posX
|
, #startX env
|
||||||
, posY
|
, posY + TC.ySpace
|
||||||
, 0
|
, 0
|
||||||
, lineNumber + 1
|
, lineNumber + 1
|
||||||
, absIdx + 1
|
, absIdx + 1
|
||||||
|
|||||||
@@ -234,8 +234,6 @@ struct
|
|||||||
acc
|
acc
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val posX = #startX env
|
|
||||||
val posY = posY + TC.ySpace
|
|
||||||
val acc =
|
val acc =
|
||||||
if absIdx = cursorIdx then
|
if absIdx = cursorIdx then
|
||||||
Utils.makeCursor (posX, posY, env) :: acc
|
Utils.makeCursor (posX, posY, env) :: acc
|
||||||
@@ -248,8 +246,8 @@ struct
|
|||||||
, stl
|
, stl
|
||||||
, line
|
, line
|
||||||
, ltl
|
, ltl
|
||||||
, posX
|
, #startX env
|
||||||
, posY
|
, posY + TC.ySpace
|
||||||
, 0
|
, 0
|
||||||
, lineNumber + 1
|
, lineNumber + 1
|
||||||
, absIdx + 1
|
, absIdx + 1
|
||||||
|
|||||||
1
shf.mlb
1
shf.mlb
@@ -34,6 +34,7 @@ in
|
|||||||
fcore/cursor-dfa/vi-word-dfa.sml
|
fcore/cursor-dfa/vi-word-dfa.sml
|
||||||
fcore/cursor-dfa/vi-caps-word-dfa.sml
|
fcore/cursor-dfa/vi-caps-word-dfa.sml
|
||||||
fcore/cursor-dfa/vi-dlr-dfa.sml
|
fcore/cursor-dfa/vi-dlr-dfa.sml
|
||||||
|
fcore/cursor-dfa/vi-l-dfa.sml
|
||||||
fcore/cursor-dfa/vi-hl-dfa.sml
|
fcore/cursor-dfa/vi-hl-dfa.sml
|
||||||
fcore/rect.sml
|
fcore/rect.sml
|
||||||
fcore/pipe-cursor.sml
|
fcore/pipe-cursor.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user