diff --git a/fcore/app-with.sml b/fcore/app-with.sml index 8d38937..5e81dcc 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -2,141 +2,6 @@ structure AppWith = 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 - (* this function exists only for testing *) fun idx (app, newIdx) = let diff --git a/fcore/move.sml b/fcore/move.sml index 6c563ec..467ed3c 100644 --- a/fcore/move.sml +++ b/fcore/move.sml @@ -15,7 +15,7 @@ struct let val {searchList, bufferModifyTime, ...} = app in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, cursorIdx, searchList, [], bufferModifyTime) end else @@ -67,7 +67,7 @@ struct val buffer = LineGap.goToIdx (cursorIdx, buffer) val cursorIdx = Fn.fMove (buffer, cursorIdx, count) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, cursorIdx, searchList, [], bufferModifyTime) end end diff --git a/fcore/normal-mode/normal-delete.sml b/fcore/normal-mode/normal-delete.sml index 4693ff5..49486d1 100644 --- a/fcore/normal-mode/normal-delete.sml +++ b/fcore/normal-mode/normal-delete.sml @@ -16,7 +16,8 @@ struct val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time) + NormalFinish.buildTextAndClear + (app, buffer, low, searchList, initialMsg, time) end (* equivalent of vi's 'x' command **) @@ -31,7 +32,7 @@ struct val searchList = SearchList.buildRange (buffer, searchString, cursorIdx + 1111) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, cursorIdx, searchList, initialMsg, time) end else @@ -119,7 +120,7 @@ struct val buffer = LineGap.goToIdx (low, buffer) val cursorIdx = Cursor.clipIdx (buffer, low) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, cursorIdx, searchList, initialMsg, time) end else @@ -158,7 +159,7 @@ struct if Cursor.isCursorAtStartOfLine (buffer, cursorIdx) then (* if we are on \n, we don't want to delete or do anything * so reset the mode *) - Finish.clearMode app + NormalFinish.clearMode app else let (* viDlr takes us to the last chr in the line @@ -317,7 +318,7 @@ struct val mode = NORMAL_MODE "" in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx (app, buffer, cursorIdx, mode, startLine, searchList, drawMsg, time) end @@ -335,7 +336,8 @@ struct val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time) + NormalFinish.buildTextAndClear + (app, buffer, low, searchList, initialMsg, time) end fun deleteToNextMatch (app: app_type, count, time) = @@ -344,7 +346,7 @@ struct val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count) in if newCursorIdx = ~1 orelse newCursorIdx <= cursorIdx then - Finish.clearMode app + NormalFinish.clearMode app else helpDeleteToMatch (app, cursorIdx, newCursorIdx, time) end @@ -355,7 +357,7 @@ struct val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count) in if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then - Finish.clearMode app + NormalFinish.clearMode app else helpDeleteToMatch (app, newCursorIdx, cursorIdx, time) end @@ -383,7 +385,7 @@ struct val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time) end end @@ -411,14 +413,14 @@ struct val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time) end end fun finishAfterDeleteInside (app: app_type, origLow, high, time) = if origLow = high then - Finish.clearMode app + NormalFinish.clearMode app else let val {cursorIdx, buffer, searchString, ...} = app @@ -430,11 +432,12 @@ struct val initialMsg = [SEARCH (buffer, searchString)] 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) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, origLow, searchList, initialMsg, time) end @@ -477,7 +480,7 @@ struct val buffer = LineGap.goToIdx (low, buffer) val high = Cursor.matchPair (buffer, low) in - if low = high then Finish.clearMode app + if low = high then NormalFinish.clearMode app else deleteAndFinish (app, low, high - low + 1, buffer, time) end @@ -492,7 +495,7 @@ struct val buffer = LineGap.goToIdx (high, buffer) val low = Cursor.matchPair (buffer, high) in - if low = high then Finish.clearMode app + if low = high then NormalFinish.clearMode app else deleteAndFinish (app, low, high - low + 1, buffer, time) end @@ -502,7 +505,7 @@ struct val otherIdx = Cursor.matchPair (buffer, cursorIdx) in if otherIdx = cursorIdx then - Finish.clearMode app + NormalFinish.clearMode app else let val low = Int.min (cursorIdx, otherIdx) @@ -530,7 +533,7 @@ struct val buffer = LineGap.goToIdx (low, buffer) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time) end end diff --git a/fcore/finish.sml b/fcore/normal-mode/normal-finish.sml similarity index 94% rename from fcore/finish.sml rename to fcore/normal-mode/normal-finish.sml index e65c355..b04d8c7 100644 --- a/fcore/finish.sml +++ b/fcore/normal-mode/normal-finish.sml @@ -1,4 +1,4 @@ -structure Finish = +structure NormalFinish = struct open AppType @@ -7,7 +7,7 @@ struct open InputMsg fun clearMode app = - AppWith.mode (app, NORMAL_MODE "", []) + NormalModeWith.mode (app, NORMAL_MODE "", []) fun buildTextAndClear (app: app_type, buffer, cursorIdx, searchList, msgs, bufferModifyTime) = @@ -37,7 +37,7 @@ struct val mode = NORMAL_MODE "" in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx @@ -52,7 +52,7 @@ struct fun withSearchList (app: app_type, searchList) = let val {buffer, searchString, cursorIdx, bufferModifyTime, ...} = app - val app = AppWith.searchList + val app = NormalModeWith.searchList (app, searchList, buffer, searchString, bufferModifyTime) in buildTextAndClear @@ -87,7 +87,7 @@ struct , [] ) in - AppWith.bufferAndSize + NormalModeWith.bufferAndSize ( app , newBuffer , newWidth @@ -132,7 +132,7 @@ struct val mode = NORMAL_MODE "" in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx @@ -176,7 +176,7 @@ struct , [] ) in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx diff --git a/fcore/normal-mode/normal-mode-with.sml b/fcore/normal-mode/normal-mode-with.sml new file mode 100644 index 0000000..8b21f13 --- /dev/null +++ b/fcore/normal-mode/normal-mode-with.sml @@ -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 diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index dfa714a..e8a7b9c 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -12,7 +12,7 @@ struct NORMAL_SEARCH_MODE {searchString = "", tempSearchList = Vector.fromList []} in - AppWith.mode (app, mode, []) + NormalModeWith.mode (app, mode, []) end fun getNumLength (pos, str) = @@ -28,7 +28,7 @@ struct val str = str ^ Char.toString chr val mode = NORMAL_MODE str in - AppWith.mode (app, mode, []) + NormalModeWith.mode (app, mode, []) end fun parseMoveToChr (count, app, fMove, chrCmd) = @@ -39,7 +39,7 @@ struct #"e" => MoveToEndOfPrevWord.move (app, count) | #"E" => MoveToEndOfPrevWORD.move (app, count) | #"g" => NormalMove.moveToStart app - | _ => Finish.clearMode app + | _ => NormalFinish.clearMode app fun parseChr (app: app_type, count, chr, str, time) = case chr of @@ -55,7 +55,7 @@ struct | #"E" => MoveToEndOfWORD.move (app, count) | #"n" => NormalMove.moveToNextMatch (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 * so hardcode count as 1 *) | #"0" => @@ -75,7 +75,7 @@ struct val str = str ^ chr val mode = NORMAL_MODE str in - AppWith.mode (app, mode, []) + NormalModeWith.mode (app, mode, []) end else MoveToStartOfLine.move (app, 1) @@ -110,7 +110,7 @@ struct val str = if Char.isDigit chr then str ^ Char.toString chr else "" val mode = NORMAL_MODE str in - AppWith.mode (app, mode, []) + NormalModeWith.mode (app, mode, []) end 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) - | _ => Finish.clearMode app + | _ => NormalFinish.clearMode app fun parseDeleteAround (app, chr, time) = case chr of @@ -137,7 +137,7 @@ struct | #"]" => 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) = case chrCmd of @@ -174,14 +174,14 @@ struct | #"i" => appendChr (app, chrCmd, str) | #"a" => appendChr (app, chrCmd, str) (* invalid command: reset mode *) - | _ => Finish.clearMode app + | _ => NormalFinish.clearMode app fun parseDeleteGo (app, count, chrCmd, time) = case chrCmd of #"e" => NormalDelete.deleteByDfa (app, count, Cursor.endOfPrevWord, time) | #"E" => NormalDelete.deleteByDfa (app, count, Cursor.endOfPrevWORD, time) | #"g" => NormalDelete.deleteToStart (app, time) - | _ => Finish.clearMode app + | _ => NormalFinish.clearMode app fun parseDelete (strPos, str, count, app, chrCmd, time) = if strPos = String.size str - 1 then @@ -204,7 +204,7 @@ struct | #"g" => parseDeleteGo (app, count, chrCmd, time) | #"i" => parseDeleteInside (app, chrCmd, time) | #"a" => parseDeleteAround (app, chrCmd, time) - | _ => Finish.clearMode app + | _ => NormalFinish.clearMode app (* useful reference as list of non-terminal commands *) fun parseAfterCount (strPos, str, count, app, chrCmd, time) = @@ -224,7 +224,7 @@ struct | #"T" => (* to just before chr, backward *) 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) | #"f" => (* to chr, forward *) @@ -233,11 +233,11 @@ struct (* to chr, backward *) parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd) | #"g" => (* go *) parseGo (count, app, chrCmd) - | #"c" => (* change *) Finish.clearMode app + | #"c" => (* change *) NormalFinish.clearMode app | _ => (* isn't a non-terminal cmd * this case should never happen*) - Finish.clearMode app + NormalFinish.clearMode app fun parseNormalModeCommand (app, str, chrCmd, time) = if String.size str = 0 then @@ -266,8 +266,10 @@ struct fun update (app, str, msg, time) = case msg of CHAR_EVENT chrCmd => parseNormalModeCommand (app, str, chrCmd, time) - | KEY_ESC => Finish.clearMode app - | RESIZE_EVENT (width, height) => Finish.resizeText (app, width, height) - | WITH_SEARCH_LIST searchList => Finish.withSearchList (app, searchList) + | KEY_ESC => NormalFinish.clearMode app + | RESIZE_EVENT (width, height) => + NormalFinish.resizeText (app, width, height) + | WITH_SEARCH_LIST searchList => + NormalFinish.withSearchList (app, searchList) | KEY_ENTER => app end diff --git a/fcore/normal-mode/normal-move.sml b/fcore/normal-mode/normal-move.sml index 4d57474..2f76600 100644 --- a/fcore/normal-mode/normal-move.sml +++ b/fcore/normal-mode/normal-move.sml @@ -31,7 +31,7 @@ struct val mode = NORMAL_MODE "" in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx @@ -87,7 +87,7 @@ struct val mode = NORMAL_MODE "" in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , bufferIdx @@ -139,7 +139,7 @@ struct val mode = NORMAL_MODE "" in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx @@ -189,7 +189,7 @@ struct , [] ) in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx @@ -221,7 +221,7 @@ struct , [] ) in - AppWith.bufferAndCursorIdx + NormalModeWith.bufferAndCursorIdx ( app , buffer , cursorIdx @@ -255,13 +255,13 @@ struct val buffer = LineGap.goToIdx (cursorIdx, buffer) val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx) in - Finish.buildTextAndClear + NormalFinish.buildTextAndClear (app, buffer, cursorIdx, searchList, [], bufferModifyTime) end fun helpMoveToChr (app: app_type, buffer, cursorIdx, count, fMove, chr) = if count = 0 then - Finish.buildTextAndClearAfterChr + NormalFinish.buildTextAndClearAfterChr (app, buffer, cursorIdx, #searchList app, [], #bufferModifyTime app) else let @@ -284,9 +284,9 @@ struct val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count) in if newCursorIdx = ~1 then - Finish.clearMode app + NormalFinish.clearMode app else - Finish.buildTextAndClearAfterChr + NormalFinish.buildTextAndClearAfterChr (app, buffer, newCursorIdx, searchList, [], bufferModifyTime) end @@ -296,9 +296,9 @@ struct val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count) in if newCursorIdx = ~1 then - Finish.clearMode app + NormalFinish.clearMode app else - Finish.buildTextAndClearAfterChr + NormalFinish.buildTextAndClearAfterChr (app, buffer, newCursorIdx, searchList, [], bufferModifyTime) end end diff --git a/fcore/normal-mode/normal-search-mode.sml b/fcore/normal-mode/normal-search-mode.sml index 215dadc..fa24c0b 100644 --- a/fcore/normal-mode/normal-search-mode.sml +++ b/fcore/normal-mode/normal-search-mode.sml @@ -18,7 +18,7 @@ struct NORMAL_SEARCH_MODE {searchString = searchString, tempSearchList = tempSearchList} in - AppWith.mode (app, mode, []) + NormalModeWith.mode (app, mode, []) end (* todo: switch to normal mode, save tempSearchList and searchString, @@ -28,7 +28,7 @@ struct fun update (app, {searchString, tempSearchList}, msg, time) = case msg of CHAR_EVENT chr => parseChr (app, searchString, chr) - | KEY_ESC => Finish.clearMode app + | KEY_ESC => NormalFinish.clearMode app | KEY_ENTER => finishSearch (app, searchString, tempSearchList) | RESIZE_EVENT (width, height) => app | WITH_SEARCH_LIST searchList => app diff --git a/shell/shell.sml b/shell/shell.sml index fb90a9e..36f11b1 100644 --- a/shell/shell.sml +++ b/shell/shell.sml @@ -75,7 +75,7 @@ struct val searchList = SearchList.build (buffer, searchString) val buffer = LineGap.goToStart buffer in - AppWith.searchList + NormalModeWith.searchList (app, searchList, buffer, searchString, Time.now ()) end diff --git a/shf.mlb b/shf.mlb index 7e725c1..7bc160d 100644 --- a/shf.mlb +++ b/shf.mlb @@ -20,6 +20,7 @@ fcore/bin-search.sml fcore/search-list.sml fcore/app-type.sml +fcore/normal-mode/normal-mode-with.sml fcore/app-with.sml fcore/text-constants.sml @@ -36,7 +37,7 @@ end fcore/cursor.sml fcore/text-window.sml -fcore/finish.sml +fcore/normal-mode/normal-finish.sml fcore/move.sml fcore/normal-mode/normal-move.sml