fully remove 'word_type' datatype from cursor.sml
This commit is contained in:
127
fcore/cursor.sml
127
fcore/cursor.sml
@@ -839,25 +839,6 @@ struct
|
|||||||
cursorIdx
|
cursorIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
(*
|
|
||||||
* nvim's motion.txt document describes a word as:
|
|
||||||
* - A sequence of (letters, digits and underscores)
|
|
||||||
* - or a sequence of other non-blank characters
|
|
||||||
* - separated by white space (space, tab, <EOL>)
|
|
||||||
*)
|
|
||||||
datatype word_type =
|
|
||||||
ALPHA_NUM
|
|
||||||
| SPACE
|
|
||||||
| NON_BLANK
|
|
||||||
|
|
||||||
fun getWordType chr =
|
|
||||||
if Char.isAlphaNum chr orelse chr = #"_" then
|
|
||||||
ALPHA_NUM
|
|
||||||
else if Char.isSpace chr then
|
|
||||||
SPACE
|
|
||||||
else
|
|
||||||
NON_BLANK
|
|
||||||
|
|
||||||
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
|
||||||
@@ -1062,31 +1043,31 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun helpPrevWordString (strPos, str, absIdx, strTl, lineTl) =
|
fun helpPrevWordString (strPos, str, absIdx, strTl, lineTl) =
|
||||||
if strPos < 0 then
|
if strPos < 0 then
|
||||||
helpPrevWordList (strTl, lineTl, absIdx)
|
helpPrevWordList (strTl, lineTl, absIdx)
|
||||||
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 isPrevChrSpace (strPos, str, strTl)
|
if isPrevChrSpace (strPos, str, strTl)
|
||||||
orelse isPrevChrNonBlank (strPos, str, strTl) then
|
orelse isPrevChrNonBlank (strPos, str, strTl) then
|
||||||
absIdx
|
absIdx
|
||||||
else
|
else
|
||||||
helpPrevWordString
|
|
||||||
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
else if Char.isSpace chr then
|
|
||||||
helpPrevWordString
|
helpPrevWordString
|
||||||
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
|
else if Char.isSpace chr then
|
||||||
|
helpPrevWordString
|
||||||
|
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
|
else
|
||||||
|
(* is NON_BLANK *)
|
||||||
|
if isPrevChrSpace (strPos, str, strTl)
|
||||||
|
orelse isPrevChrAlphaNum (strPos, str, strTl) then
|
||||||
|
absIdx
|
||||||
else
|
else
|
||||||
(* is NON_BLANK *)
|
helpPrevWordString
|
||||||
if isPrevChrSpace (strPos, str, strTl)
|
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
||||||
orelse isPrevChrAlphaNum (strPos, str, strTl) then
|
end
|
||||||
absIdx
|
|
||||||
else
|
|
||||||
helpPrevWordString
|
|
||||||
(strPos - 1, str, absIdx - 1, strTl, lineTl)
|
|
||||||
end
|
|
||||||
|
|
||||||
and helpPrevWordList (strings, lines, absIdx) =
|
and helpPrevWordList (strings, lines, absIdx) =
|
||||||
case (strings, lines) of
|
case (strings, lines) of
|
||||||
@@ -1150,33 +1131,32 @@ struct
|
|||||||
| (_, _) => cursorIdx
|
| (_, _) => cursorIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpEndOfWordString
|
fun helpEndOfWordString (strPos, str, absIdx, stl, ltl) =
|
||||||
(strPos, str, absIdx, stl, ltl) =
|
if strPos = String.size str then
|
||||||
if strPos = String.size str then
|
helpEndOfWordList (stl, ltl, absIdx)
|
||||||
helpEndOfWordList (stl, ltl, absIdx)
|
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) then
|
absIdx
|
||||||
absIdx
|
else
|
||||||
else
|
|
||||||
helpEndOfWordString
|
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
else if Char.isSpace chr then
|
|
||||||
helpEndOfWordString
|
helpEndOfWordString
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl)
|
(strPos + 1, str, absIdx + 1, stl, ltl)
|
||||||
|
else if Char.isSpace chr then
|
||||||
|
helpEndOfWordString
|
||||||
|
(strPos + 1, str, absIdx + 1, stl, ltl)
|
||||||
|
else
|
||||||
|
(* is NON_BLANK *)
|
||||||
|
if isNextChrSpace (strPos, str, stl)
|
||||||
|
orelse isNextChrAlphaNum (strPos, str, stl) then
|
||||||
|
absIdx
|
||||||
else
|
else
|
||||||
(* is NON_BLANK *)
|
helpEndOfWordString
|
||||||
if isNextChrSpace (strPos, str, stl)
|
(strPos + 1, str, absIdx + 1, stl, ltl)
|
||||||
orelse isNextChrAlphaNum (strPos, str, stl) then
|
end
|
||||||
absIdx
|
|
||||||
else
|
|
||||||
helpEndOfWordString
|
|
||||||
(strPos + 1, str, absIdx + 1, stl, ltl)
|
|
||||||
end
|
|
||||||
|
|
||||||
and helpEndOfWordList (strings, lines, absIdx) =
|
and helpEndOfWordList (strings, lines, absIdx) =
|
||||||
case (strings, lines) of
|
case (strings, lines) of
|
||||||
@@ -1188,22 +1168,13 @@ struct
|
|||||||
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
|
||||||
let
|
helpEndOfWordString
|
||||||
val nextChr = String.sub (shd, strIdx + 1)
|
(strIdx + 1, shd, absIdx + 1, stl, ltl)
|
||||||
in
|
|
||||||
helpEndOfWordString
|
|
||||||
(strIdx + 1, shd, absIdx + 1, stl, ltl)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
case (stl, ltl) of
|
case (stl, ltl) of
|
||||||
(stlhd::stltl, ltlhd::ltltl) =>
|
(stlhd::stltl, ltlhd::ltltl) =>
|
||||||
let
|
helpEndOfWordString
|
||||||
val nextChr = String.sub (stlhd, 0)
|
(0, stlhd, absIdx + 1, stltl, ltltl)
|
||||||
val wordType = getWordType nextChr
|
|
||||||
in
|
|
||||||
helpEndOfWordString
|
|
||||||
(0, stlhd, absIdx + 1, stltl, ltltl)
|
|
||||||
end
|
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* tl is empty; just return absIdx *)
|
(* tl is empty; just return absIdx *)
|
||||||
absIdx
|
absIdx
|
||||||
|
|||||||
Reference in New Issue
Block a user