delete dead code
This commit is contained in:
327
fcore/cursor.sml
327
fcore/cursor.sml
@@ -709,270 +709,12 @@ struct
|
|||||||
| (_, _) => (* nowhere to go rightward, so return cursorIdx *) cursorIdx
|
| (_, _) => (* nowhere to go rightward, so return cursorIdx *) cursorIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
fun isNextChrSpace (strPos, str, strTl) =
|
|
||||||
if strPos + 1 < String.size str then
|
|
||||||
let val chr = String.sub (str, strPos + 1)
|
|
||||||
in Char.isSpace chr
|
|
||||||
end
|
|
||||||
else
|
|
||||||
case strTl of
|
|
||||||
hd :: _ => let val chr = String.sub (hd, 0) in Char.isSpace chr end
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun notIsNextChrSpace (strPos, str, strTl) =
|
|
||||||
let val isSpace = isNextChrSpace (strPos, str, strTl)
|
|
||||||
in not isSpace
|
|
||||||
end
|
|
||||||
|
|
||||||
fun isNextChrNonBlank (strPos, str, strTl) =
|
|
||||||
if strPos + 1 < String.size str then
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, strPos + 1)
|
|
||||||
val isNotBlank =
|
|
||||||
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
in
|
|
||||||
not isNotBlank
|
|
||||||
end
|
|
||||||
else
|
|
||||||
case strTl of
|
|
||||||
hd :: _ =>
|
|
||||||
let
|
|
||||||
val chr = String.sub (hd, 0)
|
|
||||||
val isNotBlank =
|
|
||||||
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
in
|
|
||||||
not isNotBlank
|
|
||||||
end
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun isNextChrAlphaNum (strPos, str, stl) =
|
|
||||||
if strPos + 1 < String.size str then
|
|
||||||
let val chr = String.sub (str, strPos + 1)
|
|
||||||
in Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
case stl of
|
|
||||||
hd :: _ =>
|
|
||||||
let val chr = String.sub (str, 0)
|
|
||||||
in Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun isPrevChrSpace (strPos, str, strTl) =
|
|
||||||
if strPos > 0 then
|
|
||||||
let val prevChr = String.sub (str, strPos - 1)
|
|
||||||
in Char.isSpace prevChr
|
|
||||||
end
|
|
||||||
else
|
|
||||||
case strTl of
|
|
||||||
hd :: _ =>
|
|
||||||
let val prevChr = String.sub (hd, String.size hd - 1)
|
|
||||||
in Char.isSpace prevChr
|
|
||||||
end
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun notIsPrevChrSpace (strPos, str, strTl) =
|
|
||||||
let val isSpace = isPrevChrSpace (strPos, str, strTl)
|
|
||||||
in not isSpace
|
|
||||||
end
|
|
||||||
|
|
||||||
fun isPrevChrAlphaNum (strPos, str, strTl) =
|
|
||||||
if strPos > 0 then
|
|
||||||
let val chr = String.sub (str, strPos - 1)
|
|
||||||
in Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
case strTl of
|
|
||||||
hd :: _ =>
|
|
||||||
let val chr = String.sub (hd, String.size hd - 1)
|
|
||||||
in Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun isPrevChrNonBlank (strPos, str, strTl) =
|
|
||||||
if strPos > 0 then
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, strPos - 1)
|
|
||||||
val isNotBlank =
|
|
||||||
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
in
|
|
||||||
not isNotBlank
|
|
||||||
end
|
|
||||||
else
|
|
||||||
case strTl of
|
|
||||||
hd :: _ =>
|
|
||||||
let
|
|
||||||
val chr = String.sub (hd, String.size hd - 1)
|
|
||||||
val isNotBlank =
|
|
||||||
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
in
|
|
||||||
not isNotBlank
|
|
||||||
end
|
|
||||||
| [] => false
|
|
||||||
|
|
||||||
fun helpNextWord (strPos, str, absIdx, strTl, lineTl) =
|
|
||||||
if strPos = String.size str then
|
|
||||||
case (strTl, lineTl) of
|
|
||||||
(shd :: stl, lhd :: ltl) => helpNextWord (0, shd, absIdx, stl, ltl)
|
|
||||||
| (_, _) =>
|
|
||||||
(* reached end of lineGap;
|
|
||||||
* return last valid chr position *)
|
|
||||||
absIdx - 1
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, strPos)
|
|
||||||
in
|
|
||||||
if Char.isAlphaNum chr orelse chr = #"_" then
|
|
||||||
if isNextChrNonBlank (strPos, str, strTl) then absIdx + 1
|
|
||||||
else helpNextWord (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
else if Char.isSpace chr then
|
|
||||||
if notIsNextChrSpace (strPos, str, strTl) then
|
|
||||||
absIdx + 1
|
|
||||||
else
|
|
||||||
(* nothing to do on space, except keep iterating *)
|
|
||||||
helpNextWord (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
else (* chr is NON_BLANK. *) if isNextChrAlphaNum (strPos, str, strTl) then
|
|
||||||
absIdx + 1
|
|
||||||
else
|
|
||||||
helpNextWord (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun toNextWord (lineGap: LineGap.t, cursorIdx, fNext) =
|
|
||||||
let
|
|
||||||
val {rightStrings, rightLines, 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 *)
|
|
||||||
fNext (strIdx, shd, cursorIdx, stl, ltl)
|
|
||||||
else
|
|
||||||
(* strIdx is in tl *)
|
|
||||||
(case (stl, ltl) of
|
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
|
||||||
let val strIdx = strIdx - String.size shd
|
|
||||||
in fNext (strIdx, stlhd, cursorIdx, stltl, ltltl)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx
|
|
||||||
end
|
|
||||||
|
|
||||||
(* equivalent of vi's 'w' command *)
|
(* equivalent of vi's 'w' command *)
|
||||||
val nextWord = ViWordDfa.startOfNextWord
|
val nextWord = ViWordDfa.startOfNextWord
|
||||||
|
|
||||||
(* equivalent of vi's 'W' command *)
|
(* equivalent of vi's 'W' command *)
|
||||||
val nextWORD = ViWORDDfa.startOfNextWORD
|
val nextWORD = ViWORDDfa.startOfNextWORD
|
||||||
|
|
||||||
fun helpPrevWord (strPos, str, absIdx, strTl, lineTl) =
|
|
||||||
if strPos < 0 then
|
|
||||||
case (strTl, lineTl) of
|
|
||||||
(shd :: stl, lhd :: ltl) =>
|
|
||||||
helpPrevWord (String.size shd - 1, shd, absIdx, stl, ltl)
|
|
||||||
| (_, _) =>
|
|
||||||
(* reached start of lineGap;
|
|
||||||
* return 0 which is start idx *)
|
|
||||||
0
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, strPos)
|
|
||||||
in
|
|
||||||
if
|
|
||||||
Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
then
|
|
||||||
if
|
|
||||||
isPrevChrSpace (strPos, str, strTl)
|
|
||||||
orelse isPrevChrNonBlank (strPos, str, strTl)
|
|
||||||
then absIdx
|
|
||||||
else helpPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
else if
|
|
||||||
Char.isSpace chr
|
|
||||||
then
|
|
||||||
helpPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
else (* is NON_BLANK *) if
|
|
||||||
isPrevChrSpace (strPos, str, strTl)
|
|
||||||
orelse isPrevChrAlphaNum (strPos, str, strTl)
|
|
||||||
then
|
|
||||||
absIdx
|
|
||||||
else
|
|
||||||
helpPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun helpEndOfPrevWord (strPos, str, absIdx, strTl, lineTl) =
|
|
||||||
if strPos < 0 then
|
|
||||||
case (strTl, lineTl) of
|
|
||||||
(shd :: stl, lhd :: ltl) =>
|
|
||||||
helpEndOfPrevWord (String.size shd - 1, shd, absIdx, stl, ltl)
|
|
||||||
| (_, _) => 0
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, strPos)
|
|
||||||
in
|
|
||||||
if Char.isAlphaNum chr orelse chr = #"_" then
|
|
||||||
if isPrevChrNonBlank (strPos, str, strTl) then absIdx - 1
|
|
||||||
else helpEndOfPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
else if Char.isSpace chr then
|
|
||||||
if isPrevChrSpace (strPos, str, strTl) then
|
|
||||||
helpEndOfPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
else
|
|
||||||
absIdx - 1
|
|
||||||
else (* is NON_BLANK *) if isPrevChrAlphaNum (strPos, str, strTl) then
|
|
||||||
absIdx - 1
|
|
||||||
else
|
|
||||||
helpEndOfPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun startPrevWord (shd, strIdx, absIdx, stl, ltl, fPrev) =
|
|
||||||
(* we want to start iterating from previous character
|
|
||||||
* and ignore the character the cursor is at
|
|
||||||
* so check previous character *)
|
|
||||||
if strIdx > 0 then
|
|
||||||
fPrev (strIdx - 1, shd, absIdx - 1, stl, ltl)
|
|
||||||
else
|
|
||||||
case (stl, ltl) of
|
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
|
||||||
let val prevIdx = String.size stlhd - 1
|
|
||||||
in fPrev (prevIdx, stlhd, absIdx - 1, stltl, ltltl)
|
|
||||||
end
|
|
||||||
| (_, _) => (* tl is empty; just return idx 0 *) 0
|
|
||||||
|
|
||||||
fun toPrevWord (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 *)
|
|
||||||
startPrevWord
|
|
||||||
(shd, strIdx, cursorIdx, leftStrings, leftLines, fPrev)
|
|
||||||
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
|
|
||||||
startPrevWord
|
|
||||||
(stlhd, strIdx, cursorIdx, leftStrings, leftLines, fPrev)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx
|
|
||||||
end
|
|
||||||
|
|
||||||
(* equivalent of vi's 'b' command *)
|
(* equivalent of vi's 'b' command *)
|
||||||
val prevWord = ViWordDfa.startOfCurrentWord
|
val prevWord = ViWordDfa.startOfCurrentWord
|
||||||
|
|
||||||
@@ -985,75 +727,6 @@ struct
|
|||||||
(* equivalent of vi's 'gE' command *)
|
(* equivalent of vi's 'gE' command *)
|
||||||
val endOfPrevWORD = ViWORDDfa.endOfPrevWORD
|
val endOfPrevWORD = ViWORDDfa.endOfPrevWORD
|
||||||
|
|
||||||
fun helpEndOfWord (strPos, str, absIdx, stl, ltl) =
|
|
||||||
if strPos = String.size str then
|
|
||||||
case (stl, ltl) of
|
|
||||||
(shd :: stl, lhd :: ltl) => helpEndOfWord (0, shd, absIdx, stl, ltl)
|
|
||||||
| (_, _) => absIdx - 1
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, strPos)
|
|
||||||
in
|
|
||||||
if
|
|
||||||
Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
then
|
|
||||||
if
|
|
||||||
isNextChrSpace (strPos, str, stl)
|
|
||||||
orelse isNextChrNonBlank (strPos, str, stl)
|
|
||||||
then absIdx
|
|
||||||
else helpEndOfWord (strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
else if
|
|
||||||
Char.isSpace chr
|
|
||||||
then
|
|
||||||
helpEndOfWord (strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
else (* is NON_BLANK *) if
|
|
||||||
isNextChrSpace (strPos, str, stl)
|
|
||||||
orelse isNextChrAlphaNum (strPos, str, stl)
|
|
||||||
then
|
|
||||||
absIdx
|
|
||||||
else
|
|
||||||
helpEndOfWord (strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun startEndOfWord (shd, strIdx, absIdx, stl, ltl, fEnd) =
|
|
||||||
(* we want to start iterating from next char after strIdx *)
|
|
||||||
if strIdx - 1 < String.size shd then
|
|
||||||
fEnd (strIdx + 1, shd, absIdx + 1, stl, ltl)
|
|
||||||
else
|
|
||||||
case (stl, ltl) of
|
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
|
||||||
fEnd (0, stlhd, absIdx + 1, stltl, ltltl)
|
|
||||||
| (_, _) => (* tl is empty; just return absIdx *) absIdx
|
|
||||||
|
|
||||||
fun toEndOfWord (lineGap: LineGap.t, cursorIdx, fEnd) =
|
|
||||||
let
|
|
||||||
val
|
|
||||||
{rightStrings, rightLines, leftStrings, leftLines, idx = bufferIdx, ...} =
|
|
||||||
lineGap
|
|
||||||
in
|
|
||||||
case (rightStrings, rightLines) of
|
|
||||||
(shd :: stl, lhd :: ltl) =>
|
|
||||||
let
|
|
||||||
val strIdx = cursorIdx - bufferIdx
|
|
||||||
in
|
|
||||||
if strIdx < String.size shd then
|
|
||||||
(* strIdx is in this string *)
|
|
||||||
startEndOfWord (shd, strIdx, cursorIdx, stl, ltl, fEnd)
|
|
||||||
else
|
|
||||||
(* strIdx is in tl *)
|
|
||||||
(case (stl, ltl) of
|
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
|
||||||
let
|
|
||||||
val strIdx = strIdx - String.size shd
|
|
||||||
in
|
|
||||||
startEndOfWord
|
|
||||||
(stlhd, strIdx, cursorIdx, stltl, ltltl, fEnd)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx)
|
|
||||||
end
|
|
||||||
| (_, _) => cursorIdx
|
|
||||||
end
|
|
||||||
|
|
||||||
(* equivalent of vi's `e` command *)
|
(* equivalent of vi's `e` command *)
|
||||||
val endOfWord = ViWordDfa.endOfCurrentWord
|
val endOfWord = ViWordDfa.endOfCurrentWord
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user