Skip to content

Commit

Permalink
use less IOBuffer internals
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed May 9, 2022
1 parent b16afaf commit e793bb8
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ _edit_indent(buf::IOBuffer, b::Int, num::Int) =
num >= 0 ? edit_splice!(buf, b => b, ' '^num, rigid_mark=false) :
edit_splice!(buf, b => (b - num))

function mode_idx(hist #=::REPLHistoryProvider =#, mode::TextInterface)
function mode_idx(hist::HistoryProvider, mode::TextInterface)
c = :julia
for (k,v) in hist.mode_mapping
isequal(v, mode) && (c = k)
Expand All @@ -1323,29 +1323,25 @@ function edit_input(s)
filename *= ".sh"
end
buf = buffer(s)
data = buf.data
pos = position(buf)
size0 = buf.size
resize!(data, buf.size) # to not write garbage into filename
line = 1 + count(==(_newline), view(data, 1:pos))
str = String(take!(buf))
line = 1 + count(==(_newline), view(str, 1:pos))
ct0 = open(filename, "w") do io
write(io, data)
write(io, str)
ctime(io)
end
InteractiveUtils.edit(filename, line)
n, ct = open(filename) do io
readbytes!(io, empty!(buf.data), typemax(Int)),
str_mod, ct = open(filename) do io
readchomp(io),
ctime(io)
end
rm(filename)
@assert n == length(buf.data)
buf.size = n
buf.ptr = n+1
if ct0 != ct # something was changed, run the input
write(buf, str_mod)
commit_line(s)
:done
else # no change, the edit session probably unsuccessful
@assert n == size0
write(buf, str)
seek(buf, pos) # restore state from before edit
refresh_line(s)
end
Expand Down

0 comments on commit e793bb8

Please sign in to comment.