minor formatting changes to exception logging, and begin building from new search list functionality as well

This commit is contained in:
2025-08-05 13:59:10 +01:00
parent 01369627bf
commit 0729662eef
3 changed files with 48 additions and 33 deletions

View File

@@ -81,10 +81,11 @@ struct
fun fromStart (app, cursorIdx, buffer, searchString) =
if String.size searchString > 0 then
let
val buffer = LineGap.goToEnd buffer
val searchList = SearchLineGap.search (buffer, searchString)
val buffer = LineGap.goToStart buffer
in
helpFromStart
(app, cursorIdx, 0, buffer, searchString, SearchList.empty)
AppWith.searchList (app, searchList, buffer, searchString)
end
else
app
@@ -130,15 +131,11 @@ struct
end
fun fromRange (startIdx, length, buffer, searchString, searchList) =
if String.size searchString = 0 then
let
val buffer = LineGap.goToEnd buffer
val searchList = SearchLineGap.search (buffer, searchString)
val buffer = LineGap.goToStart buffer
in
(buffer, searchList)
else
let
val finishIdx = startIdx + length + String.size searchString
val bufferIdx = startIdx - String.size searchString
val bufferIdx = Int.max (bufferIdx, 0)
in
helpFromRange
(startIdx, bufferIdx, finishIdx, buffer, searchString, searchList)
end
end
end

View File

@@ -1,8 +1,21 @@
structure SearchLineGap =
struct
fun cons (num, acc) =
let
val num = Vector.fromList [num]
in
case acc of
hd :: tl =>
if Vector.length hd < 32 then
(Vector.concat [num, hd]) :: tl
else
num :: acc
| [] => num :: acc
end
fun searchStep (pos, hd, absIdx, tl, acc, searchPos, searchString) =
if searchPos < 0 then
(absIdx + 1) :: acc
cons (absIdx + 1, acc)
else if pos < 0 then
case tl of
hd :: tl =>
@@ -33,17 +46,22 @@ struct
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
end
fun search (buffer, searchString) =
if String.size searchString = 0 then
[]
else
let
val buffer = LineGap.goToEnd buffer
val {leftStrings, idx = absIdx, ...} = buffer
in
case leftStrings of
hd :: tl =>
loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
| [] => []
end
(* Prerequisite: move buffer/LineGap to end *)
fun search (buffer: LineGap.t, searchString) =
let
val acc =
if String.size searchString = 0 then
[]
else
let
val {leftStrings, idx = absIdx, ...} = buffer
in
case leftStrings of
hd :: tl =>
loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
| [] => []
end
in
{left = [], right = acc}
end
end

View File

@@ -19,18 +19,18 @@ struct
let
(* print stack trace for debugging purposes,
* and then raise another exception to exit the program *)
val errName = General.exnName e ^ "\n"
val stackTrace = MLton.Exn.history e
val stackTrace = String.concatWith "\n" stackTrace
val () = print "ERROR:\n"
val () = print (stackTrace ^ "\n\n")
val stackTrace = (String.concatWith "\n" stackTrace) ^ "\n"
val history = !textCommands ^ "\n\n"
val () = print ("HISTORY: " ^ history)
val textOutput = stackTrace ^ "\n" ^ history
val log = String.concat
["ERROR: ", errName, stackTrace, "HISTORY: ", history]
val () = print ("\n" ^ log)
val io = TextIO.openAppend "exceptions.log"
val () = TextIO.output (io, textOutput)
val () = TextIO.output (io, log)
val () = TextIO.closeOut io
in
raise e