just formatting cursor.sml
This commit is contained in:
283
fcore/cursor.sml
283
fcore/cursor.sml
@@ -4,16 +4,12 @@ struct
|
|||||||
if strPos < 0 then
|
if strPos < 0 then
|
||||||
case (strTl, lineTl) of
|
case (strTl, lineTl) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) =>
|
||||||
helpVi0
|
helpVi0 (String.size shd - 1, shd, absIdx, stl, ltl)
|
||||||
(String.size shd - 1, shd, absIdx, stl, ltl)
|
| (_, _) => 0
|
||||||
| (_, _) =>
|
|
||||||
0
|
|
||||||
else
|
else
|
||||||
case String.sub (str, strPos) of
|
case String.sub (str, strPos) of
|
||||||
#"\n" =>
|
#"\n" => absIdx + 1
|
||||||
absIdx + 1
|
| _ => helpVi0 (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
| _ =>
|
|
||||||
helpVi0 (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
|
|
||||||
fun vi0 (lineGap: LineGap.t, cursorIdx) =
|
fun vi0 (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
@@ -35,10 +31,7 @@ struct
|
|||||||
cursorIdx
|
cursorIdx
|
||||||
else
|
else
|
||||||
(* not at newline so start iterating *)
|
(* not at newline so start iterating *)
|
||||||
helpVi0
|
helpVi0 (strIdx - 1, strHd, cursorIdx - 1, strTl, lnTl)
|
||||||
( strIdx - 1, strHd, cursorIdx - 1
|
|
||||||
, strTl, lnTl
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
(* strIdx must be in the strTl *)
|
(* strIdx must be in the strTl *)
|
||||||
(case (strTl, lnTl) of
|
(case (strTl, lnTl) of
|
||||||
@@ -52,8 +45,11 @@ struct
|
|||||||
else
|
else
|
||||||
(* not in linebreak *)
|
(* not in linebreak *)
|
||||||
helpVi0
|
helpVi0
|
||||||
( strIdx - 1, nestStrHd, cursorIdx - 1
|
( strIdx - 1
|
||||||
, strHd :: leftStrings, lnHd :: leftLines
|
, nestStrHd
|
||||||
|
, cursorIdx - 1
|
||||||
|
, strHd :: leftStrings
|
||||||
|
, lnHd :: leftLines
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
@@ -66,17 +62,12 @@ struct
|
|||||||
fun helpViDlr (strPos, str, absIdx, strTl, lineTl) =
|
fun helpViDlr (strPos, str, absIdx, strTl, lineTl) =
|
||||||
if strPos = String.size str then
|
if strPos = String.size str then
|
||||||
case (strTl, lineTl) of
|
case (strTl, lineTl) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) => helpViDlr (0, shd, absIdx, stl, ltl)
|
||||||
helpViDlr
|
| (_, _) => absIdx - 1
|
||||||
(0, shd, absIdx, stl, ltl)
|
|
||||||
| (_, _) =>
|
|
||||||
absIdx - 1
|
|
||||||
else
|
else
|
||||||
case String.sub (str, strPos) of
|
case String.sub (str, strPos) of
|
||||||
#"\n" =>
|
#"\n" => absIdx - 1
|
||||||
absIdx - 1
|
| _ => helpViDlr (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
||||||
| _ =>
|
|
||||||
helpViDlr (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
|
|
||||||
fun viDlr (lineGap: LineGap.t, cursorIdx) =
|
fun viDlr (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
@@ -93,8 +84,7 @@ struct
|
|||||||
if strIdx < String.size strHd then
|
if strIdx < String.size strHd then
|
||||||
if String.sub (strHd, strIdx) <> #"\n" then
|
if String.sub (strHd, strIdx) <> #"\n" then
|
||||||
(* not in double linebreak *)
|
(* not in double linebreak *)
|
||||||
helpViDlr
|
helpViDlr (strIdx + 1, strHd, cursorIdx + 1, strTl, lnTl)
|
||||||
(strIdx + 1, strHd, cursorIdx + 1, strTl, lnTl)
|
|
||||||
else
|
else
|
||||||
(* check if we are in double linebreak *)
|
(* check if we are in double linebreak *)
|
||||||
if strIdx - 1 >= 0 then
|
if strIdx - 1 >= 0 then
|
||||||
@@ -103,8 +93,7 @@ struct
|
|||||||
cursorIdx
|
cursorIdx
|
||||||
else
|
else
|
||||||
(* not in double linebreak, so iterate *)
|
(* not in double linebreak, so iterate *)
|
||||||
helpViDlr
|
helpViDlr (strIdx + 1, strHd, cursorIdx + 1, strTl, lnTl)
|
||||||
(strIdx + 1, strHd, cursorIdx + 1 , strTl, lnTl)
|
|
||||||
else
|
else
|
||||||
(* check if double linebreak in strTl *)
|
(* check if double linebreak in strTl *)
|
||||||
(case strTl of
|
(case strTl of
|
||||||
@@ -112,8 +101,7 @@ struct
|
|||||||
if String.sub (nestStrHd, 0) = #"\n" then
|
if String.sub (nestStrHd, 0) = #"\n" then
|
||||||
cursorIdx
|
cursorIdx
|
||||||
else
|
else
|
||||||
helpViDlr
|
helpViDlr (strIdx + 1, strHd, cursorIdx + 1, strTl, lnTl)
|
||||||
(strIdx + 1, strHd, cursorIdx + 1, strTl, lnTl)
|
|
||||||
| [] => cursorIdx)
|
| [] => cursorIdx)
|
||||||
else
|
else
|
||||||
(* strIdx must be in the strTl *)
|
(* strIdx must be in the strTl *)
|
||||||
@@ -123,7 +111,12 @@ struct
|
|||||||
val strIdx = strIdx - String.size strHd
|
val strIdx = strIdx - String.size strHd
|
||||||
in
|
in
|
||||||
helpViDlr
|
helpViDlr
|
||||||
(strIdx + 1, nestStrHd, cursorIdx + 1, nestStrTl, nestLnTl)
|
( strIdx + 1
|
||||||
|
, nestStrHd
|
||||||
|
, cursorIdx + 1
|
||||||
|
, nestStrTl
|
||||||
|
, nestLnTl
|
||||||
|
)
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
@@ -246,7 +239,8 @@ struct
|
|||||||
(* no chars before this idx; have to check leftStrings *)
|
(* no chars before this idx; have to check leftStrings *)
|
||||||
(case leftStrings of
|
(case leftStrings of
|
||||||
lHd :: lTl =>
|
lHd :: lTl =>
|
||||||
(* if there is another string after current head, we can increment cursorIdx
|
(* if there is another string after current head,
|
||||||
|
* we can increment cursorIdx
|
||||||
* however, first we need to check if next char is \n. *)
|
* however, first we need to check if next char is \n. *)
|
||||||
let
|
let
|
||||||
val lastChr = String.sub (lHd, String.size lHd - 1)
|
val lastChr = String.sub (lHd, String.size lHd - 1)
|
||||||
@@ -575,7 +569,7 @@ struct
|
|||||||
helpViJ
|
helpViJ
|
||||||
( strIdx + 1, nestStrHd, cursorIdx + 1
|
( strIdx + 1, nestStrHd, cursorIdx + 1
|
||||||
, lineColumn, lineColumn, false
|
, lineColumn, lineColumn, false
|
||||||
, nestStrTl, nestStrTl
|
, nestStrTl, nestLnTl
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -605,9 +599,7 @@ struct
|
|||||||
else
|
else
|
||||||
case String.sub (str, strPos) of
|
case String.sub (str, strPos) of
|
||||||
#"\n" =>
|
#"\n" =>
|
||||||
if
|
if hasPassedLine then
|
||||||
hasPassedLine
|
|
||||||
then
|
|
||||||
(* reached end of line twice,
|
(* reached end of line twice,
|
||||||
* but line has fewer chars than preferredColumn
|
* but line has fewer chars than preferredColumn
|
||||||
* note: if in double \n\n linebreak,
|
* note: if in double \n\n linebreak,
|
||||||
@@ -725,15 +717,20 @@ struct
|
|||||||
if String.sub (lStrHd, String.size lStrHd - 1) = #"\n" then
|
if String.sub (lStrHd, String.size lStrHd - 1) = #"\n" then
|
||||||
(* in double linebreak *)
|
(* in double linebreak *)
|
||||||
helpVi0
|
helpVi0
|
||||||
(String.size lStrHd - 2, lStrHd, cursorIdx - 2, lStrTl, lLnTl)
|
( String.size lStrHd - 2, lStrHd, cursorIdx - 2
|
||||||
|
, lStrTl, lLnTl
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(* in single linebreak *)
|
(* in single linebreak *)
|
||||||
helpVi0
|
helpVi0
|
||||||
(strIdx - 1, strHd, cursorIdx - 1, leftStrings, leftLines)
|
( strIdx - 1, strHd, cursorIdx - 1
|
||||||
|
, leftStrings, leftLines
|
||||||
|
)
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
helpViK
|
helpViK
|
||||||
( strIdx - 1, strHd, cursorIdx - 1
|
( strIdx - 1, strHd, cursorIdx - 1
|
||||||
, 0, 0, true, leftStrings, lnHd, leftLines
|
, 0, 0, true
|
||||||
|
, leftStrings, lnHd, leftLines
|
||||||
))
|
))
|
||||||
else
|
else
|
||||||
(* not at newline
|
(* not at newline
|
||||||
@@ -776,9 +773,7 @@ struct
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
(* must check strHd for second linebreak *)
|
(* must check strHd for second linebreak *)
|
||||||
if
|
if String.sub (strHd, String.size strHd - 1) = #"\n" then
|
||||||
String.sub (strHd, String.size strHd - 1) = #"\n"
|
|
||||||
then
|
|
||||||
(* is in double linebreak *)
|
(* is in double linebreak *)
|
||||||
helpVi0
|
helpVi0
|
||||||
( String.size strHd - 2, nestStrHd, cursorIdx - 2
|
( String.size strHd - 2, nestStrHd, cursorIdx - 2
|
||||||
@@ -798,7 +793,9 @@ struct
|
|||||||
helpViK
|
helpViK
|
||||||
( strIdx - 1, nestStrHd, cursorIdx - 1
|
( strIdx - 1, nestStrHd, cursorIdx - 1
|
||||||
, lineColumn, lineColumn, false
|
, lineColumn, lineColumn, false
|
||||||
, strHd :: leftStrings, nestLnHd, lnHd :: leftLines
|
, strHd :: leftStrings
|
||||||
|
, nestLnHd
|
||||||
|
, lnHd :: leftLines
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -811,26 +808,17 @@ struct
|
|||||||
|
|
||||||
fun isNextChrSpace (strPos, str, strTl) =
|
fun isNextChrSpace (strPos, str, strTl) =
|
||||||
if strPos + 1 < String.size str then
|
if strPos + 1 < String.size str then
|
||||||
let
|
let val chr = String.sub (str, strPos + 1)
|
||||||
val chr = String.sub (str, strPos + 1)
|
in Char.isSpace chr
|
||||||
in
|
|
||||||
Char.isSpace chr
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
case strTl of
|
case strTl of
|
||||||
hd :: _ =>
|
hd :: _ => let val chr = String.sub (hd, 0) in Char.isSpace chr end
|
||||||
let
|
|
||||||
val chr = String.sub (hd, 0)
|
|
||||||
in
|
|
||||||
Char.isSpace chr
|
|
||||||
end
|
|
||||||
| [] => false
|
| [] => false
|
||||||
|
|
||||||
fun notIsNextChrSpace (strPos, str, strTl) =
|
fun notIsNextChrSpace (strPos, str, strTl) =
|
||||||
let
|
let val isSpace = isNextChrSpace (strPos, str, strTl)
|
||||||
val isSpace = isNextChrSpace (strPos, str, strTl)
|
in not isSpace
|
||||||
in
|
|
||||||
not isSpace
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun isNextChrNonBlank (strPos, str, strTl) =
|
fun isNextChrNonBlank (strPos, str, strTl) =
|
||||||
@@ -838,9 +826,7 @@ struct
|
|||||||
let
|
let
|
||||||
val chr = String.sub (str, strPos + 1)
|
val chr = String.sub (str, strPos + 1)
|
||||||
val isNotBlank =
|
val isNotBlank =
|
||||||
Char.isSpace chr
|
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
||||||
orelse Char.isAlphaNum chr
|
|
||||||
orelse chr = #"_"
|
|
||||||
in
|
in
|
||||||
not isNotBlank
|
not isNotBlank
|
||||||
end
|
end
|
||||||
@@ -850,9 +836,7 @@ struct
|
|||||||
let
|
let
|
||||||
val chr = String.sub (hd, 0)
|
val chr = String.sub (hd, 0)
|
||||||
val isNotBlank =
|
val isNotBlank =
|
||||||
Char.isSpace chr
|
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
||||||
orelse Char.isAlphaNum chr
|
|
||||||
orelse chr = #"_"
|
|
||||||
in
|
in
|
||||||
not isNotBlank
|
not isNotBlank
|
||||||
end
|
end
|
||||||
@@ -860,59 +844,45 @@ struct
|
|||||||
|
|
||||||
fun isNextChrAlphaNum (strPos, str, stl) =
|
fun isNextChrAlphaNum (strPos, str, stl) =
|
||||||
if strPos + 1 < String.size str then
|
if strPos + 1 < String.size str then
|
||||||
let
|
let val chr = String.sub (str, strPos + 1)
|
||||||
val chr = String.sub (str, strPos + 1)
|
in Char.isAlphaNum chr orelse chr = #"_"
|
||||||
in
|
|
||||||
Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
case stl of
|
case stl of
|
||||||
hd :: _ =>
|
hd :: _ =>
|
||||||
let
|
let val chr = String.sub (str, 0)
|
||||||
val chr = String.sub (str, 0)
|
in Char.isAlphaNum chr orelse chr = #"_"
|
||||||
in
|
|
||||||
Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
end
|
||||||
| [] => false
|
| [] => false
|
||||||
|
|
||||||
fun isPrevChrSpace (strPos, str, strTl) =
|
fun isPrevChrSpace (strPos, str, strTl) =
|
||||||
if strPos > 0 then
|
if strPos > 0 then
|
||||||
let
|
let val prevChr = String.sub (str, strPos - 1)
|
||||||
val prevChr = String.sub (str, strPos - 1)
|
in Char.isSpace prevChr
|
||||||
in
|
|
||||||
Char.isSpace prevChr
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
case strTl of
|
case strTl of
|
||||||
hd :: _ =>
|
hd :: _ =>
|
||||||
let
|
let val prevChr = String.sub (hd, String.size hd - 1)
|
||||||
val prevChr = String.sub (hd, String.size hd - 1)
|
in Char.isSpace prevChr
|
||||||
in
|
|
||||||
Char.isSpace prevChr
|
|
||||||
end
|
end
|
||||||
| [] => false
|
| [] => false
|
||||||
|
|
||||||
fun notIsPrevChrSpace (strPos, str, strTl) =
|
fun notIsPrevChrSpace (strPos, str, strTl) =
|
||||||
let
|
let val isSpace = isPrevChrSpace (strPos, str, strTl)
|
||||||
val isSpace = isPrevChrSpace (strPos, str, strTl)
|
in not isSpace
|
||||||
in
|
|
||||||
not isSpace
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun isPrevChrAlphaNum (strPos, str, strTl) =
|
fun isPrevChrAlphaNum (strPos, str, strTl) =
|
||||||
if strPos > 0 then
|
if strPos > 0 then
|
||||||
let
|
let val chr = String.sub (str, strPos - 1)
|
||||||
val chr = String.sub (str, strPos - 1)
|
in Char.isAlphaNum chr orelse chr = #"_"
|
||||||
in
|
|
||||||
Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
case strTl of
|
case strTl of
|
||||||
hd :: _ =>
|
hd :: _ =>
|
||||||
let
|
let val chr = String.sub (hd, String.size hd - 1)
|
||||||
val chr = String.sub (hd, String.size hd - 1)
|
in Char.isAlphaNum chr orelse chr = #"_"
|
||||||
in
|
|
||||||
Char.isAlphaNum chr orelse chr = #"_"
|
|
||||||
end
|
end
|
||||||
| [] => false
|
| [] => false
|
||||||
|
|
||||||
@@ -921,9 +891,7 @@ struct
|
|||||||
let
|
let
|
||||||
val chr = String.sub (str, strPos - 1)
|
val chr = String.sub (str, strPos - 1)
|
||||||
val isNotBlank =
|
val isNotBlank =
|
||||||
Char.isSpace chr
|
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
||||||
orelse Char.isAlphaNum chr
|
|
||||||
orelse chr = #"_"
|
|
||||||
in
|
in
|
||||||
not isNotBlank
|
not isNotBlank
|
||||||
end
|
end
|
||||||
@@ -933,15 +901,13 @@ struct
|
|||||||
let
|
let
|
||||||
val chr = String.sub (hd, String.size hd - 1)
|
val chr = String.sub (hd, String.size hd - 1)
|
||||||
val isNotBlank =
|
val isNotBlank =
|
||||||
Char.isSpace chr
|
Char.isSpace chr orelse Char.isAlphaNum chr orelse chr = #"_"
|
||||||
orelse Char.isAlphaNum chr
|
|
||||||
orelse chr = #"_"
|
|
||||||
in
|
in
|
||||||
not isNotBlank
|
not isNotBlank
|
||||||
end
|
end
|
||||||
| [] => false
|
| [] => false
|
||||||
|
|
||||||
fun helpNextWord (strPos, str, absIdx , strTl, lineTl) =
|
fun helpNextWord (strPos, str, absIdx, strTl, lineTl) =
|
||||||
if strPos = String.size str then
|
if strPos = String.size str then
|
||||||
case (strTl, lineTl) of
|
case (strTl, lineTl) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) =>
|
||||||
@@ -955,30 +921,24 @@ struct
|
|||||||
val chr = String.sub (str, strPos)
|
val chr = String.sub (str, strPos)
|
||||||
in
|
in
|
||||||
if Char.isAlphaNum chr orelse chr = #"_" then
|
if Char.isAlphaNum chr orelse chr = #"_" then
|
||||||
if isNextChrNonBlank (strPos, str, strTl) then
|
if isNextChrNonBlank (strPos, str, strTl) then absIdx + 1
|
||||||
absIdx + 1
|
else helpNextWord (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
||||||
else
|
|
||||||
helpNextWord
|
|
||||||
(strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
else if Char.isSpace chr then
|
else if Char.isSpace chr then
|
||||||
if notIsNextChrSpace (strPos, str, strTl) then
|
if notIsNextChrSpace (strPos, str, strTl) then
|
||||||
absIdx + 1
|
absIdx + 1
|
||||||
else
|
else
|
||||||
(* nothing to do on space, except keep iterating *)
|
(* nothing to do on space, except keep iterating *)
|
||||||
helpNextWord
|
helpNextWord (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
||||||
(strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
else
|
else
|
||||||
(* chr is NON_BLANK. *)
|
(* chr is NON_BLANK. *)
|
||||||
if isNextChrAlphaNum (strPos, str, strTl) then
|
if isNextChrAlphaNum (strPos, str, strTl) then
|
||||||
absIdx + 1
|
absIdx + 1
|
||||||
else
|
else
|
||||||
helpNextWord
|
helpNextWord (strPos + 1, str, absIdx + 1, strTl, lineTl)
|
||||||
(strPos + 1, str, absIdx + 1, strTl, lineTl)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun startNextWord (shd, strIdx, absIdx, stl, ltl) =
|
fun startNextWord (shd, strIdx, absIdx, stl, ltl) =
|
||||||
helpNextWord
|
helpNextWord (strIdx, shd, absIdx, stl, ltl)
|
||||||
(strIdx, shd, absIdx, stl, ltl)
|
|
||||||
|
|
||||||
fun nextWord (lineGap: LineGap.t, cursorIdx) =
|
fun nextWord (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
@@ -997,11 +957,8 @@ struct
|
|||||||
(* strIdx is in tl *)
|
(* strIdx is in tl *)
|
||||||
(case (stl, ltl) of
|
(case (stl, ltl) of
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
let
|
let val strIdx = strIdx - String.size shd
|
||||||
val strIdx = strIdx - String.size shd
|
in startNextWord (stlhd, strIdx, cursorIdx, stltl, ltltl)
|
||||||
in
|
|
||||||
startNextWord
|
|
||||||
(stlhd, strIdx, cursorIdx, stltl, ltltl)
|
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
@@ -1012,8 +969,7 @@ struct
|
|||||||
if strPos < 0 then
|
if strPos < 0 then
|
||||||
case (strTl, lineTl) of
|
case (strTl, lineTl) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) =>
|
||||||
helpPrevWord
|
helpPrevWord (String.size shd - 1, shd, absIdx, stl, ltl)
|
||||||
(String.size shd - 1, shd, absIdx, stl, ltl)
|
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* reached start of lineGap;
|
(* reached start of lineGap;
|
||||||
* return 0 which is start idx *)
|
* return 0 which is start idx *)
|
||||||
@@ -1022,24 +978,25 @@ struct
|
|||||||
let
|
let
|
||||||
val chr = String.sub (str, strPos)
|
val chr = String.sub (str, strPos)
|
||||||
in
|
in
|
||||||
if Char.isAlphaNum chr orelse chr = #"_" then
|
if
|
||||||
|
Char.isAlphaNum chr orelse chr = #"_"
|
||||||
|
then
|
||||||
if isPrevChrSpace (strPos, str, strTl)
|
if isPrevChrSpace (strPos, str, strTl)
|
||||||
orelse isPrevChrNonBlank (strPos, str, strTl) then
|
orelse isPrevChrNonBlank (strPos, str, strTl)
|
||||||
absIdx
|
then absIdx
|
||||||
else
|
else helpPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
helpPrevWord
|
else if
|
||||||
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
Char.isSpace chr
|
||||||
else if Char.isSpace chr then
|
then
|
||||||
helpPrevWord
|
helpPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
else
|
else
|
||||||
(* is NON_BLANK *)
|
(* is NON_BLANK *)
|
||||||
if isPrevChrSpace (strPos, str, strTl)
|
if isPrevChrSpace (strPos, str, strTl)
|
||||||
orelse isPrevChrAlphaNum (strPos, str, strTl) then
|
orelse isPrevChrAlphaNum (strPos, str, strTl)
|
||||||
|
then
|
||||||
absIdx
|
absIdx
|
||||||
else
|
else
|
||||||
helpPrevWord
|
helpPrevWord (strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun startPrevWord (shd, strIdx, absIdx, stl, ltl) =
|
fun startPrevWord (shd, strIdx, absIdx, stl, ltl) =
|
||||||
@@ -1047,16 +1004,12 @@ struct
|
|||||||
* and ignore the character the cursor is at
|
* and ignore the character the cursor is at
|
||||||
* so check previous character *)
|
* so check previous character *)
|
||||||
if strIdx > 0 then
|
if strIdx > 0 then
|
||||||
helpPrevWord
|
helpPrevWord (strIdx - 1, shd, absIdx - 1, stl, ltl)
|
||||||
(strIdx - 1, shd, absIdx - 1, stl, ltl)
|
|
||||||
else
|
else
|
||||||
case (stl, ltl) of
|
case (stl, ltl) of
|
||||||
(stlhd::stltl, ltlhd::ltltl) =>
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
let
|
let val prevIdx = String.size stlhd - 1
|
||||||
val prevIdx = String.size stlhd - 1
|
in helpPrevWord (prevIdx, stlhd, absIdx - 1, stltl, ltltl)
|
||||||
in
|
|
||||||
helpPrevWord
|
|
||||||
(prevIdx, stlhd, absIdx - 1, stltl, ltltl)
|
|
||||||
end
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* tl is empty; just return idx 0 *)
|
(* tl is empty; just return idx 0 *)
|
||||||
@@ -1065,7 +1018,9 @@ struct
|
|||||||
(* equivalent of vi's `b` command *)
|
(* equivalent of vi's `b` command *)
|
||||||
fun prevWord (lineGap: LineGap.t, cursorIdx) =
|
fun prevWord (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
val {rightStrings, rightLines, leftStrings, leftLines, idx = bufferIdx, ...} = lineGap
|
val
|
||||||
|
{rightStrings, rightLines, leftStrings, leftLines, idx = bufferIdx, ...} =
|
||||||
|
lineGap
|
||||||
in
|
in
|
||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) =>
|
||||||
@@ -1075,8 +1030,7 @@ struct
|
|||||||
in
|
in
|
||||||
if strIdx < String.size shd then
|
if strIdx < String.size shd then
|
||||||
(* strIdx is in this string *)
|
(* strIdx is in this string *)
|
||||||
startPrevWord
|
startPrevWord (shd, strIdx, cursorIdx, leftStrings, leftLines)
|
||||||
(shd, strIdx, cursorIdx, leftStrings, leftLines)
|
|
||||||
else
|
else
|
||||||
(* strIdx is in tl *)
|
(* strIdx is in tl *)
|
||||||
(case (stl, ltl) of
|
(case (stl, ltl) of
|
||||||
@@ -1097,44 +1051,41 @@ struct
|
|||||||
fun helpEndOfWord (strPos, str, absIdx, stl, ltl) =
|
fun helpEndOfWord (strPos, str, absIdx, stl, ltl) =
|
||||||
if strPos = String.size str then
|
if strPos = String.size str then
|
||||||
case (stl, ltl) of
|
case (stl, ltl) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) => helpEndOfWord (0, shd, absIdx, stl, ltl)
|
||||||
helpEndOfWord (0, shd, absIdx, stl, ltl)
|
| (_, _) => absIdx - 1
|
||||||
| (_, _) =>
|
|
||||||
absIdx - 1
|
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val chr = String.sub (str, strPos)
|
val chr = String.sub (str, strPos)
|
||||||
in
|
in
|
||||||
if Char.isAlphaNum chr orelse chr = #"_" then
|
if
|
||||||
|
Char.isAlphaNum chr orelse chr = #"_"
|
||||||
|
then
|
||||||
if isNextChrSpace (strPos, str, stl)
|
if isNextChrSpace (strPos, str, stl)
|
||||||
orelse isNextChrNonBlank (strPos, str, stl) then
|
orelse isNextChrNonBlank (strPos, str, stl)
|
||||||
absIdx
|
then absIdx
|
||||||
else
|
else helpEndOfWord (strPos + 1, str, absIdx + 1, stl, ltl)
|
||||||
helpEndOfWord
|
else if
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl)
|
Char.isSpace chr
|
||||||
else if Char.isSpace chr then
|
then
|
||||||
helpEndOfWord
|
helpEndOfWord (strPos + 1, str, absIdx + 1, stl, ltl)
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
else
|
else
|
||||||
(* is NON_BLANK *)
|
(* is NON_BLANK *)
|
||||||
if isNextChrSpace (strPos, str, stl)
|
if isNextChrSpace (strPos, str, stl)
|
||||||
orelse isNextChrAlphaNum (strPos, str, stl) then
|
orelse isNextChrAlphaNum (strPos, str, stl)
|
||||||
|
then
|
||||||
absIdx
|
absIdx
|
||||||
else
|
else
|
||||||
helpEndOfWord
|
helpEndOfWord (strPos + 1, str, absIdx + 1, stl, ltl)
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun startEndOfWord (shd, strIdx, absIdx, stl, ltl) =
|
fun startEndOfWord (shd, strIdx, absIdx, stl, ltl) =
|
||||||
(* we want to start iterating from next char after strIdx *)
|
(* we want to start iterating from next char after strIdx *)
|
||||||
if strIdx - 1 < String.size shd then
|
if strIdx - 1 < String.size shd then
|
||||||
helpEndOfWord
|
helpEndOfWord (strIdx + 1, shd, absIdx + 1, stl, ltl)
|
||||||
(strIdx + 1, shd, absIdx + 1, stl, ltl)
|
|
||||||
else
|
else
|
||||||
case (stl, ltl) of
|
case (stl, ltl) of
|
||||||
(stlhd::stltl, ltlhd::ltltl) =>
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
helpEndOfWord
|
helpEndOfWord (0, stlhd, absIdx + 1, stltl, ltltl)
|
||||||
(0, stlhd, absIdx + 1, stltl, ltltl)
|
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* tl is empty; just return absIdx *)
|
(* tl is empty; just return absIdx *)
|
||||||
absIdx
|
absIdx
|
||||||
@@ -1142,7 +1093,9 @@ struct
|
|||||||
(* equivalent of vi's `e` command *)
|
(* equivalent of vi's `e` command *)
|
||||||
fun endOfWord (lineGap: LineGap.t, cursorIdx) =
|
fun endOfWord (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
val {rightStrings, rightLines, leftStrings, leftLines, idx = bufferIdx, ...} = lineGap
|
val
|
||||||
|
{rightStrings, rightLines, leftStrings, leftLines, idx = bufferIdx, ...} =
|
||||||
|
lineGap
|
||||||
in
|
in
|
||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(shd :: stl, lhd :: ltl) =>
|
(shd :: stl, lhd :: ltl) =>
|
||||||
@@ -1151,17 +1104,13 @@ struct
|
|||||||
in
|
in
|
||||||
if strIdx < String.size shd then
|
if strIdx < String.size shd then
|
||||||
(* strIdx is in this string *)
|
(* strIdx is in this string *)
|
||||||
startEndOfWord
|
startEndOfWord (shd, strIdx, cursorIdx, rightStrings, rightLines)
|
||||||
(shd, strIdx, cursorIdx, rightStrings, rightLines)
|
|
||||||
else
|
else
|
||||||
(* strIdx is in tl *)
|
(* strIdx is in tl *)
|
||||||
(case (stl, ltl) of
|
(case (stl, ltl) of
|
||||||
(stlhd :: stltl, ltlhd :: ltltl) =>
|
(stlhd :: stltl, ltlhd :: ltltl) =>
|
||||||
let
|
let val strIdx = strIdx - String.size shd
|
||||||
val strIdx = strIdx - String.size shd
|
in startEndOfWord (stlhd, strIdx, cursorIdx, stltl, ltltl)
|
||||||
in
|
|
||||||
startEndOfWord
|
|
||||||
(stlhd, strIdx, cursorIdx, stltl, ltltl)
|
|
||||||
end
|
end
|
||||||
| (_, _) => cursorIdx)
|
| (_, _) => cursorIdx)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user