a bit of refactoring
This commit is contained in:
@@ -2,141 +2,6 @@ structure AppWith =
|
|||||||
struct
|
struct
|
||||||
open AppType
|
open AppType
|
||||||
|
|
||||||
fun bufferAndSize
|
|
||||||
( app: app_type
|
|
||||||
, newBuffer
|
|
||||||
, newWidth
|
|
||||||
, newHeight
|
|
||||||
, newSearchList
|
|
||||||
, newMsgs
|
|
||||||
, newBufferModifyTime
|
|
||||||
) =
|
|
||||||
let
|
|
||||||
val
|
|
||||||
{ mode
|
|
||||||
, buffer = _
|
|
||||||
, bufferModifyTime = _
|
|
||||||
, windowWidth = _
|
|
||||||
, windowHeight = _
|
|
||||||
, searchList = _
|
|
||||||
, msgs = _
|
|
||||||
, searchString
|
|
||||||
, startLine
|
|
||||||
, cursorIdx
|
|
||||||
} = app
|
|
||||||
in
|
|
||||||
{ mode = mode
|
|
||||||
, buffer = newBuffer
|
|
||||||
, bufferModifyTime = newBufferModifyTime
|
|
||||||
, windowWidth = newWidth
|
|
||||||
, windowHeight = newHeight
|
|
||||||
, searchList = newSearchList
|
|
||||||
, msgs = newMsgs
|
|
||||||
, searchString = searchString
|
|
||||||
, startLine = startLine
|
|
||||||
, cursorIdx = cursorIdx
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
fun bufferAndCursorIdx
|
|
||||||
( app: app_type
|
|
||||||
, newBuffer
|
|
||||||
, newCursorIdx
|
|
||||||
, newMode
|
|
||||||
, newStartLine
|
|
||||||
, newSearchList
|
|
||||||
, newMsgs
|
|
||||||
, newBufferModifyTime
|
|
||||||
) =
|
|
||||||
let
|
|
||||||
val
|
|
||||||
{ mode = _
|
|
||||||
, buffer = _
|
|
||||||
, bufferModifyTime = _
|
|
||||||
, cursorIdx = _
|
|
||||||
, startLine = _
|
|
||||||
, searchList = _
|
|
||||||
, msgs = _
|
|
||||||
, searchString
|
|
||||||
, windowWidth
|
|
||||||
, windowHeight
|
|
||||||
} = app
|
|
||||||
in
|
|
||||||
{ mode = newMode
|
|
||||||
, buffer = newBuffer
|
|
||||||
, bufferModifyTime = newBufferModifyTime
|
|
||||||
, cursorIdx = newCursorIdx
|
|
||||||
, startLine = newStartLine
|
|
||||||
, searchList = newSearchList
|
|
||||||
, msgs = newMsgs
|
|
||||||
, searchString = searchString
|
|
||||||
, windowWidth = windowWidth
|
|
||||||
, windowHeight = windowHeight
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
fun mode (app: app_type, newMode, newMsgs) =
|
|
||||||
let
|
|
||||||
val
|
|
||||||
{ mode = _
|
|
||||||
, msgs = _
|
|
||||||
, buffer
|
|
||||||
, bufferModifyTime
|
|
||||||
, searchList
|
|
||||||
, searchString
|
|
||||||
, cursorIdx
|
|
||||||
, windowWidth
|
|
||||||
, windowHeight
|
|
||||||
, startLine
|
|
||||||
} = app
|
|
||||||
in
|
|
||||||
{ mode = newMode
|
|
||||||
, msgs = newMsgs
|
|
||||||
, buffer = buffer
|
|
||||||
, bufferModifyTime = bufferModifyTime
|
|
||||||
, searchList = searchList
|
|
||||||
, searchString = searchString
|
|
||||||
, cursorIdx = cursorIdx
|
|
||||||
, windowWidth = windowWidth
|
|
||||||
, windowHeight = windowHeight
|
|
||||||
, startLine = startLine
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
fun searchList
|
|
||||||
( app: app_type
|
|
||||||
, newSearchList
|
|
||||||
, newBuffer
|
|
||||||
, newSearchString
|
|
||||||
, newBufferModifyTime
|
|
||||||
) =
|
|
||||||
let
|
|
||||||
val
|
|
||||||
{ searchList = _
|
|
||||||
, buffer = _
|
|
||||||
, bufferModifyTime
|
|
||||||
, searchString = _
|
|
||||||
, msgs
|
|
||||||
, mode
|
|
||||||
, cursorIdx
|
|
||||||
, windowWidth
|
|
||||||
, windowHeight
|
|
||||||
, startLine
|
|
||||||
} = app
|
|
||||||
in
|
|
||||||
{ searchList = newSearchList
|
|
||||||
, buffer = newBuffer
|
|
||||||
, bufferModifyTime = newBufferModifyTime
|
|
||||||
, searchString = newSearchString
|
|
||||||
, msgs = msgs
|
|
||||||
, mode = mode
|
|
||||||
, cursorIdx = cursorIdx
|
|
||||||
, windowWidth = windowWidth
|
|
||||||
, windowHeight = windowHeight
|
|
||||||
, startLine = startLine
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
(* this function exists only for testing *)
|
(* this function exists only for testing *)
|
||||||
fun idx (app, newIdx) =
|
fun idx (app, newIdx) =
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ struct
|
|||||||
let
|
let
|
||||||
val {searchList, bufferModifyTime, ...} = app
|
val {searchList, bufferModifyTime, ...} = app
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -67,7 +67,7 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val cursorIdx = Fn.fMove (buffer, cursorIdx, count)
|
val cursorIdx = Fn.fMove (buffer, cursorIdx, count)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time)
|
NormalFinish.buildTextAndClear
|
||||||
|
(app, buffer, low, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
(* equivalent of vi's 'x' command **)
|
(* equivalent of vi's 'x' command **)
|
||||||
@@ -31,7 +32,7 @@ struct
|
|||||||
val searchList =
|
val searchList =
|
||||||
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
|
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, cursorIdx, searchList, initialMsg, time)
|
(app, buffer, cursorIdx, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -119,7 +120,7 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
val cursorIdx = Cursor.clipIdx (buffer, low)
|
val cursorIdx = Cursor.clipIdx (buffer, low)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, cursorIdx, searchList, initialMsg, time)
|
(app, buffer, cursorIdx, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -158,7 +159,7 @@ struct
|
|||||||
if Cursor.isCursorAtStartOfLine (buffer, cursorIdx) then
|
if Cursor.isCursorAtStartOfLine (buffer, cursorIdx) then
|
||||||
(* if we are on \n, we don't want to delete or do anything
|
(* if we are on \n, we don't want to delete or do anything
|
||||||
* so reset the mode *)
|
* so reset the mode *)
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
(* viDlr takes us to the last chr in the line
|
(* viDlr takes us to the last chr in the line
|
||||||
@@ -317,7 +318,7 @@ struct
|
|||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg, time)
|
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -335,7 +336,8 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time)
|
NormalFinish.buildTextAndClear
|
||||||
|
(app, buffer, low, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun deleteToNextMatch (app: app_type, count, time) =
|
fun deleteToNextMatch (app: app_type, count, time) =
|
||||||
@@ -344,7 +346,7 @@ struct
|
|||||||
val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count)
|
val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 orelse newCursorIdx <= cursorIdx then
|
if newCursorIdx = ~1 orelse newCursorIdx <= cursorIdx then
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
helpDeleteToMatch (app, cursorIdx, newCursorIdx, time)
|
helpDeleteToMatch (app, cursorIdx, newCursorIdx, time)
|
||||||
end
|
end
|
||||||
@@ -355,7 +357,7 @@ struct
|
|||||||
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then
|
if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
helpDeleteToMatch (app, newCursorIdx, cursorIdx, time)
|
helpDeleteToMatch (app, newCursorIdx, cursorIdx, time)
|
||||||
end
|
end
|
||||||
@@ -383,7 +385,7 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, low, searchList, initialMsg, time)
|
(app, buffer, low, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -411,14 +413,14 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, low, searchList, initialMsg, time)
|
(app, buffer, low, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun finishAfterDeleteInside (app: app_type, origLow, high, time) =
|
fun finishAfterDeleteInside (app: app_type, origLow, high, time) =
|
||||||
if origLow = high then
|
if origLow = high then
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val {cursorIdx, buffer, searchString, ...} = app
|
val {cursorIdx, buffer, searchString, ...} = app
|
||||||
@@ -430,11 +432,12 @@ struct
|
|||||||
val initialMsg = [SEARCH (buffer, searchString)]
|
val initialMsg = [SEARCH (buffer, searchString)]
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (low - 1111, buffer)
|
val buffer = LineGap.goToIdx (low - 1111, buffer)
|
||||||
val searchList = SearchList.buildRange (buffer, searchString, low + 1111)
|
val searchList =
|
||||||
|
SearchList.buildRange (buffer, searchString, low + 1111)
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (origLow, buffer)
|
val buffer = LineGap.goToIdx (origLow, buffer)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, origLow, searchList, initialMsg, time)
|
(app, buffer, origLow, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -477,7 +480,7 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
val high = Cursor.matchPair (buffer, low)
|
val high = Cursor.matchPair (buffer, low)
|
||||||
in
|
in
|
||||||
if low = high then Finish.clearMode app
|
if low = high then NormalFinish.clearMode app
|
||||||
else deleteAndFinish (app, low, high - low + 1, buffer, time)
|
else deleteAndFinish (app, low, high - low + 1, buffer, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -492,7 +495,7 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (high, buffer)
|
val buffer = LineGap.goToIdx (high, buffer)
|
||||||
val low = Cursor.matchPair (buffer, high)
|
val low = Cursor.matchPair (buffer, high)
|
||||||
in
|
in
|
||||||
if low = high then Finish.clearMode app
|
if low = high then NormalFinish.clearMode app
|
||||||
else deleteAndFinish (app, low, high - low + 1, buffer, time)
|
else deleteAndFinish (app, low, high - low + 1, buffer, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -502,7 +505,7 @@ struct
|
|||||||
val otherIdx = Cursor.matchPair (buffer, cursorIdx)
|
val otherIdx = Cursor.matchPair (buffer, cursorIdx)
|
||||||
in
|
in
|
||||||
if otherIdx = cursorIdx then
|
if otherIdx = cursorIdx then
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val low = Int.min (cursorIdx, otherIdx)
|
val low = Int.min (cursorIdx, otherIdx)
|
||||||
@@ -530,7 +533,7 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, low, searchList, initialMsg, time)
|
(app, buffer, low, searchList, initialMsg, time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
structure Finish =
|
structure NormalFinish =
|
||||||
struct
|
struct
|
||||||
open AppType
|
open AppType
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ struct
|
|||||||
open InputMsg
|
open InputMsg
|
||||||
|
|
||||||
fun clearMode app =
|
fun clearMode app =
|
||||||
AppWith.mode (app, NORMAL_MODE "", [])
|
NormalModeWith.mode (app, NORMAL_MODE "", [])
|
||||||
|
|
||||||
fun buildTextAndClear
|
fun buildTextAndClear
|
||||||
(app: app_type, buffer, cursorIdx, searchList, msgs, bufferModifyTime) =
|
(app: app_type, buffer, cursorIdx, searchList, msgs, bufferModifyTime) =
|
||||||
@@ -37,7 +37,7 @@ struct
|
|||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -52,7 +52,7 @@ struct
|
|||||||
fun withSearchList (app: app_type, searchList) =
|
fun withSearchList (app: app_type, searchList) =
|
||||||
let
|
let
|
||||||
val {buffer, searchString, cursorIdx, bufferModifyTime, ...} = app
|
val {buffer, searchString, cursorIdx, bufferModifyTime, ...} = app
|
||||||
val app = AppWith.searchList
|
val app = NormalModeWith.searchList
|
||||||
(app, searchList, buffer, searchString, bufferModifyTime)
|
(app, searchList, buffer, searchString, bufferModifyTime)
|
||||||
in
|
in
|
||||||
buildTextAndClear
|
buildTextAndClear
|
||||||
@@ -87,7 +87,7 @@ struct
|
|||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
AppWith.bufferAndSize
|
NormalModeWith.bufferAndSize
|
||||||
( app
|
( app
|
||||||
, newBuffer
|
, newBuffer
|
||||||
, newWidth
|
, newWidth
|
||||||
@@ -132,7 +132,7 @@ struct
|
|||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -176,7 +176,7 @@ struct
|
|||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
139
fcore/normal-mode/normal-mode-with.sml
Normal file
139
fcore/normal-mode/normal-mode-with.sml
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
structure NormalModeWith =
|
||||||
|
struct
|
||||||
|
open AppType
|
||||||
|
|
||||||
|
fun bufferAndSize
|
||||||
|
( app: app_type
|
||||||
|
, newBuffer
|
||||||
|
, newWidth
|
||||||
|
, newHeight
|
||||||
|
, newSearchList
|
||||||
|
, newMsgs
|
||||||
|
, newBufferModifyTime
|
||||||
|
) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ mode
|
||||||
|
, buffer = _
|
||||||
|
, bufferModifyTime = _
|
||||||
|
, windowWidth = _
|
||||||
|
, windowHeight = _
|
||||||
|
, searchList = _
|
||||||
|
, msgs = _
|
||||||
|
, searchString
|
||||||
|
, startLine
|
||||||
|
, cursorIdx
|
||||||
|
} = app
|
||||||
|
in
|
||||||
|
{ mode = mode
|
||||||
|
, buffer = newBuffer
|
||||||
|
, bufferModifyTime = newBufferModifyTime
|
||||||
|
, windowWidth = newWidth
|
||||||
|
, windowHeight = newHeight
|
||||||
|
, searchList = newSearchList
|
||||||
|
, msgs = newMsgs
|
||||||
|
, searchString = searchString
|
||||||
|
, startLine = startLine
|
||||||
|
, cursorIdx = cursorIdx
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
fun bufferAndCursorIdx
|
||||||
|
( app: app_type
|
||||||
|
, newBuffer
|
||||||
|
, newCursorIdx
|
||||||
|
, newMode
|
||||||
|
, newStartLine
|
||||||
|
, newSearchList
|
||||||
|
, newMsgs
|
||||||
|
, newBufferModifyTime
|
||||||
|
) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ mode = _
|
||||||
|
, buffer = _
|
||||||
|
, bufferModifyTime = _
|
||||||
|
, cursorIdx = _
|
||||||
|
, startLine = _
|
||||||
|
, searchList = _
|
||||||
|
, msgs = _
|
||||||
|
, searchString
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
} = app
|
||||||
|
in
|
||||||
|
{ mode = newMode
|
||||||
|
, buffer = newBuffer
|
||||||
|
, bufferModifyTime = newBufferModifyTime
|
||||||
|
, cursorIdx = newCursorIdx
|
||||||
|
, startLine = newStartLine
|
||||||
|
, searchList = newSearchList
|
||||||
|
, msgs = newMsgs
|
||||||
|
, searchString = searchString
|
||||||
|
, windowWidth = windowWidth
|
||||||
|
, windowHeight = windowHeight
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
fun mode (app: app_type, newMode, newMsgs) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ mode = _
|
||||||
|
, msgs = _
|
||||||
|
, buffer
|
||||||
|
, bufferModifyTime
|
||||||
|
, searchList
|
||||||
|
, searchString
|
||||||
|
, cursorIdx
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, startLine
|
||||||
|
} = app
|
||||||
|
in
|
||||||
|
{ mode = newMode
|
||||||
|
, msgs = newMsgs
|
||||||
|
, buffer = buffer
|
||||||
|
, bufferModifyTime = bufferModifyTime
|
||||||
|
, searchList = searchList
|
||||||
|
, searchString = searchString
|
||||||
|
, cursorIdx = cursorIdx
|
||||||
|
, windowWidth = windowWidth
|
||||||
|
, windowHeight = windowHeight
|
||||||
|
, startLine = startLine
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
fun searchList
|
||||||
|
( app: app_type
|
||||||
|
, newSearchList
|
||||||
|
, newBuffer
|
||||||
|
, newSearchString
|
||||||
|
, newBufferModifyTime
|
||||||
|
) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ searchList = _
|
||||||
|
, buffer = _
|
||||||
|
, bufferModifyTime
|
||||||
|
, searchString = _
|
||||||
|
, msgs
|
||||||
|
, mode
|
||||||
|
, cursorIdx
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, startLine
|
||||||
|
} = app
|
||||||
|
in
|
||||||
|
{ searchList = newSearchList
|
||||||
|
, buffer = newBuffer
|
||||||
|
, bufferModifyTime = newBufferModifyTime
|
||||||
|
, searchString = newSearchString
|
||||||
|
, msgs = msgs
|
||||||
|
, mode = mode
|
||||||
|
, cursorIdx = cursorIdx
|
||||||
|
, windowWidth = windowWidth
|
||||||
|
, windowHeight = windowHeight
|
||||||
|
, startLine = startLine
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -12,7 +12,7 @@ struct
|
|||||||
NORMAL_SEARCH_MODE
|
NORMAL_SEARCH_MODE
|
||||||
{searchString = "", tempSearchList = Vector.fromList []}
|
{searchString = "", tempSearchList = Vector.fromList []}
|
||||||
in
|
in
|
||||||
AppWith.mode (app, mode, [])
|
NormalModeWith.mode (app, mode, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getNumLength (pos, str) =
|
fun getNumLength (pos, str) =
|
||||||
@@ -28,7 +28,7 @@ struct
|
|||||||
val str = str ^ Char.toString chr
|
val str = str ^ Char.toString chr
|
||||||
val mode = NORMAL_MODE str
|
val mode = NORMAL_MODE str
|
||||||
in
|
in
|
||||||
AppWith.mode (app, mode, [])
|
NormalModeWith.mode (app, mode, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
fun parseMoveToChr (count, app, fMove, chrCmd) =
|
fun parseMoveToChr (count, app, fMove, chrCmd) =
|
||||||
@@ -39,7 +39,7 @@ struct
|
|||||||
#"e" => MoveToEndOfPrevWord.move (app, count)
|
#"e" => MoveToEndOfPrevWord.move (app, count)
|
||||||
| #"E" => MoveToEndOfPrevWORD.move (app, count)
|
| #"E" => MoveToEndOfPrevWORD.move (app, count)
|
||||||
| #"g" => NormalMove.moveToStart app
|
| #"g" => NormalMove.moveToStart app
|
||||||
| _ => Finish.clearMode app
|
| _ => NormalFinish.clearMode app
|
||||||
|
|
||||||
fun parseChr (app: app_type, count, chr, str, time) =
|
fun parseChr (app: app_type, count, chr, str, time) =
|
||||||
case chr of
|
case chr of
|
||||||
@@ -55,7 +55,7 @@ struct
|
|||||||
| #"E" => MoveToEndOfWORD.move (app, count)
|
| #"E" => MoveToEndOfWORD.move (app, count)
|
||||||
| #"n" => NormalMove.moveToNextMatch (app, count)
|
| #"n" => NormalMove.moveToNextMatch (app, count)
|
||||||
| #"N" => NormalMove.moveToPrevMatch (app, count)
|
| #"N" => NormalMove.moveToPrevMatch (app, count)
|
||||||
| #"z" => Finish.centreToCursor app
|
| #"z" => NormalFinish.centreToCursor app
|
||||||
(* can only move to start or end of line once
|
(* can only move to start or end of line once
|
||||||
* so hardcode count as 1 *)
|
* so hardcode count as 1 *)
|
||||||
| #"0" =>
|
| #"0" =>
|
||||||
@@ -75,7 +75,7 @@ struct
|
|||||||
val str = str ^ chr
|
val str = str ^ chr
|
||||||
val mode = NORMAL_MODE str
|
val mode = NORMAL_MODE str
|
||||||
in
|
in
|
||||||
AppWith.mode (app, mode, [])
|
NormalModeWith.mode (app, mode, [])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MoveToStartOfLine.move (app, 1)
|
MoveToStartOfLine.move (app, 1)
|
||||||
@@ -110,7 +110,7 @@ struct
|
|||||||
val str = if Char.isDigit chr then str ^ Char.toString chr else ""
|
val str = if Char.isDigit chr then str ^ Char.toString chr else ""
|
||||||
val mode = NORMAL_MODE str
|
val mode = NORMAL_MODE str
|
||||||
in
|
in
|
||||||
AppWith.mode (app, mode, [])
|
NormalModeWith.mode (app, mode, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
fun parseDeleteInside (app, chr, time) =
|
fun parseDeleteInside (app, chr, time) =
|
||||||
@@ -125,7 +125,7 @@ struct
|
|||||||
| #"]" => NormalDelete.deleteInsideChrClose (app, chr, time)
|
| #"]" => NormalDelete.deleteInsideChrClose (app, chr, time)
|
||||||
| #"}" => NormalDelete.deleteInsideChrClose (app, chr, time)
|
| #"}" => NormalDelete.deleteInsideChrClose (app, chr, time)
|
||||||
| #">" => NormalDelete.deleteInsideChrClose (app, chr, time)
|
| #">" => NormalDelete.deleteInsideChrClose (app, chr, time)
|
||||||
| _ => Finish.clearMode app
|
| _ => NormalFinish.clearMode app
|
||||||
|
|
||||||
fun parseDeleteAround (app, chr, time) =
|
fun parseDeleteAround (app, chr, time) =
|
||||||
case chr of
|
case chr of
|
||||||
@@ -137,7 +137,7 @@ struct
|
|||||||
| #"]" => NormalDelete.deleteAroundChrClose (app, chr, time)
|
| #"]" => NormalDelete.deleteAroundChrClose (app, chr, time)
|
||||||
| #"}" => NormalDelete.deleteAroundChrClose (app, chr, time)
|
| #"}" => NormalDelete.deleteAroundChrClose (app, chr, time)
|
||||||
| #">" => NormalDelete.deleteAroundChrClose (app, chr, time)
|
| #">" => NormalDelete.deleteAroundChrClose (app, chr, time)
|
||||||
| _ => Finish.clearMode app
|
| _ => NormalFinish.clearMode app
|
||||||
|
|
||||||
fun parseDeleteTerminal (str, count, app, chrCmd, time) =
|
fun parseDeleteTerminal (str, count, app, chrCmd, time) =
|
||||||
case chrCmd of
|
case chrCmd of
|
||||||
@@ -174,14 +174,14 @@ struct
|
|||||||
| #"i" => appendChr (app, chrCmd, str)
|
| #"i" => appendChr (app, chrCmd, str)
|
||||||
| #"a" => appendChr (app, chrCmd, str)
|
| #"a" => appendChr (app, chrCmd, str)
|
||||||
(* invalid command: reset mode *)
|
(* invalid command: reset mode *)
|
||||||
| _ => Finish.clearMode app
|
| _ => NormalFinish.clearMode app
|
||||||
|
|
||||||
fun parseDeleteGo (app, count, chrCmd, time) =
|
fun parseDeleteGo (app, count, chrCmd, time) =
|
||||||
case chrCmd of
|
case chrCmd of
|
||||||
#"e" => NormalDelete.deleteByDfa (app, count, Cursor.endOfPrevWord, time)
|
#"e" => NormalDelete.deleteByDfa (app, count, Cursor.endOfPrevWord, time)
|
||||||
| #"E" => NormalDelete.deleteByDfa (app, count, Cursor.endOfPrevWORD, time)
|
| #"E" => NormalDelete.deleteByDfa (app, count, Cursor.endOfPrevWORD, time)
|
||||||
| #"g" => NormalDelete.deleteToStart (app, time)
|
| #"g" => NormalDelete.deleteToStart (app, time)
|
||||||
| _ => Finish.clearMode app
|
| _ => NormalFinish.clearMode app
|
||||||
|
|
||||||
fun parseDelete (strPos, str, count, app, chrCmd, time) =
|
fun parseDelete (strPos, str, count, app, chrCmd, time) =
|
||||||
if strPos = String.size str - 1 then
|
if strPos = String.size str - 1 then
|
||||||
@@ -204,7 +204,7 @@ struct
|
|||||||
| #"g" => parseDeleteGo (app, count, chrCmd, time)
|
| #"g" => parseDeleteGo (app, count, chrCmd, time)
|
||||||
| #"i" => parseDeleteInside (app, chrCmd, time)
|
| #"i" => parseDeleteInside (app, chrCmd, time)
|
||||||
| #"a" => parseDeleteAround (app, chrCmd, time)
|
| #"a" => parseDeleteAround (app, chrCmd, time)
|
||||||
| _ => Finish.clearMode app
|
| _ => NormalFinish.clearMode app
|
||||||
|
|
||||||
(* useful reference as list of non-terminal commands *)
|
(* useful reference as list of non-terminal commands *)
|
||||||
fun parseAfterCount (strPos, str, count, app, chrCmd, time) =
|
fun parseAfterCount (strPos, str, count, app, chrCmd, time) =
|
||||||
@@ -224,7 +224,7 @@ struct
|
|||||||
| #"T" =>
|
| #"T" =>
|
||||||
(* to just before chr, backward *)
|
(* to just before chr, backward *)
|
||||||
parseMoveToChr (1, app, Cursor.tillPrevChr, chrCmd)
|
parseMoveToChr (1, app, Cursor.tillPrevChr, chrCmd)
|
||||||
| #"y" => (* yank *) Finish.clearMode app
|
| #"y" => (* yank *) NormalFinish.clearMode app
|
||||||
| #"d" => (* delete *) parseDelete (strPos, str, count, app, chrCmd, time)
|
| #"d" => (* delete *) parseDelete (strPos, str, count, app, chrCmd, time)
|
||||||
| #"f" =>
|
| #"f" =>
|
||||||
(* to chr, forward *)
|
(* to chr, forward *)
|
||||||
@@ -233,11 +233,11 @@ struct
|
|||||||
(* to chr, backward *)
|
(* to chr, backward *)
|
||||||
parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd)
|
parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd)
|
||||||
| #"g" => (* go *) parseGo (count, app, chrCmd)
|
| #"g" => (* go *) parseGo (count, app, chrCmd)
|
||||||
| #"c" => (* change *) Finish.clearMode app
|
| #"c" => (* change *) NormalFinish.clearMode app
|
||||||
| _ =>
|
| _ =>
|
||||||
(* isn't a non-terminal cmd
|
(* isn't a non-terminal cmd
|
||||||
* this case should never happen*)
|
* this case should never happen*)
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
|
|
||||||
fun parseNormalModeCommand (app, str, chrCmd, time) =
|
fun parseNormalModeCommand (app, str, chrCmd, time) =
|
||||||
if String.size str = 0 then
|
if String.size str = 0 then
|
||||||
@@ -266,8 +266,10 @@ struct
|
|||||||
fun update (app, str, msg, time) =
|
fun update (app, str, msg, time) =
|
||||||
case msg of
|
case msg of
|
||||||
CHAR_EVENT chrCmd => parseNormalModeCommand (app, str, chrCmd, time)
|
CHAR_EVENT chrCmd => parseNormalModeCommand (app, str, chrCmd, time)
|
||||||
| KEY_ESC => Finish.clearMode app
|
| KEY_ESC => NormalFinish.clearMode app
|
||||||
| RESIZE_EVENT (width, height) => Finish.resizeText (app, width, height)
|
| RESIZE_EVENT (width, height) =>
|
||||||
| WITH_SEARCH_LIST searchList => Finish.withSearchList (app, searchList)
|
NormalFinish.resizeText (app, width, height)
|
||||||
|
| WITH_SEARCH_LIST searchList =>
|
||||||
|
NormalFinish.withSearchList (app, searchList)
|
||||||
| KEY_ENTER => app
|
| KEY_ENTER => app
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ struct
|
|||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -87,7 +87,7 @@ struct
|
|||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, bufferIdx
|
, bufferIdx
|
||||||
@@ -139,7 +139,7 @@ struct
|
|||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -189,7 +189,7 @@ struct
|
|||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -221,7 +221,7 @@ struct
|
|||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
AppWith.bufferAndCursorIdx
|
NormalModeWith.bufferAndCursorIdx
|
||||||
( app
|
( app
|
||||||
, buffer
|
, buffer
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -255,13 +255,13 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx)
|
val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx)
|
||||||
in
|
in
|
||||||
Finish.buildTextAndClear
|
NormalFinish.buildTextAndClear
|
||||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpMoveToChr (app: app_type, buffer, cursorIdx, count, fMove, chr) =
|
fun helpMoveToChr (app: app_type, buffer, cursorIdx, count, fMove, chr) =
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
Finish.buildTextAndClearAfterChr
|
NormalFinish.buildTextAndClearAfterChr
|
||||||
(app, buffer, cursorIdx, #searchList app, [], #bufferModifyTime app)
|
(app, buffer, cursorIdx, #searchList app, [], #bufferModifyTime app)
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
@@ -284,9 +284,9 @@ struct
|
|||||||
val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count)
|
val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 then
|
if newCursorIdx = ~1 then
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
Finish.buildTextAndClearAfterChr
|
NormalFinish.buildTextAndClearAfterChr
|
||||||
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
|
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -296,9 +296,9 @@ struct
|
|||||||
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 then
|
if newCursorIdx = ~1 then
|
||||||
Finish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
Finish.buildTextAndClearAfterChr
|
NormalFinish.buildTextAndClearAfterChr
|
||||||
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
|
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ struct
|
|||||||
NORMAL_SEARCH_MODE
|
NORMAL_SEARCH_MODE
|
||||||
{searchString = searchString, tempSearchList = tempSearchList}
|
{searchString = searchString, tempSearchList = tempSearchList}
|
||||||
in
|
in
|
||||||
AppWith.mode (app, mode, [])
|
NormalModeWith.mode (app, mode, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
(* todo: switch to normal mode, save tempSearchList and searchString,
|
(* todo: switch to normal mode, save tempSearchList and searchString,
|
||||||
@@ -28,7 +28,7 @@ struct
|
|||||||
fun update (app, {searchString, tempSearchList}, msg, time) =
|
fun update (app, {searchString, tempSearchList}, msg, time) =
|
||||||
case msg of
|
case msg of
|
||||||
CHAR_EVENT chr => parseChr (app, searchString, chr)
|
CHAR_EVENT chr => parseChr (app, searchString, chr)
|
||||||
| KEY_ESC => Finish.clearMode app
|
| KEY_ESC => NormalFinish.clearMode app
|
||||||
| KEY_ENTER => finishSearch (app, searchString, tempSearchList)
|
| KEY_ENTER => finishSearch (app, searchString, tempSearchList)
|
||||||
| RESIZE_EVENT (width, height) => app
|
| RESIZE_EVENT (width, height) => app
|
||||||
| WITH_SEARCH_LIST searchList => app
|
| WITH_SEARCH_LIST searchList => app
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ struct
|
|||||||
val searchList = SearchList.build (buffer, searchString)
|
val searchList = SearchList.build (buffer, searchString)
|
||||||
val buffer = LineGap.goToStart buffer
|
val buffer = LineGap.goToStart buffer
|
||||||
in
|
in
|
||||||
AppWith.searchList
|
NormalModeWith.searchList
|
||||||
(app, searchList, buffer, searchString, Time.now ())
|
(app, searchList, buffer, searchString, Time.now ())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
3
shf.mlb
3
shf.mlb
@@ -20,6 +20,7 @@ fcore/bin-search.sml
|
|||||||
fcore/search-list.sml
|
fcore/search-list.sml
|
||||||
|
|
||||||
fcore/app-type.sml
|
fcore/app-type.sml
|
||||||
|
fcore/normal-mode/normal-mode-with.sml
|
||||||
fcore/app-with.sml
|
fcore/app-with.sml
|
||||||
|
|
||||||
fcore/text-constants.sml
|
fcore/text-constants.sml
|
||||||
@@ -36,7 +37,7 @@ end
|
|||||||
fcore/cursor.sml
|
fcore/cursor.sml
|
||||||
fcore/text-window.sml
|
fcore/text-window.sml
|
||||||
|
|
||||||
fcore/finish.sml
|
fcore/normal-mode/normal-finish.sml
|
||||||
fcore/move.sml
|
fcore/move.sml
|
||||||
|
|
||||||
fcore/normal-mode/normal-move.sml
|
fcore/normal-mode/normal-move.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user