Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOFError in the REPL on pressing ctrl+t after typing a single character #45417

Closed
jishnub opened this issue May 22, 2022 · 3 comments · Fixed by #45420 or #46925
Closed

EOFError in the REPL on pressing ctrl+t after typing a single character #45417

jishnub opened this issue May 22, 2022 · 3 comments · Fixed by #45420 or #46925
Labels
bug Indicates an unexpected problem or unintended behavior REPL Julia's REPL (Read Eval Print Loop)

Comments

@jishnub
Copy link
Contributor

jishnub commented May 22, 2022

Steps to reproduce

julia> # press any alphanumeric character key here, eg 'a', followed by ctrl + t

julia> a┌ Error: Error in the keymap
│   exception =
│    EOFError: read end of file
│    Stacktrace:
│      [1] read
│        @ ./iobuffer.jl:217 [inlined]
│      [2] read
│        @ ./io.jl:776 [inlined]
│      [3] edit_transpose_chars(buf::IOBuffer)
│        @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:1094
│      [4] edit_transpose_chars(s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:1086
│      [5] (::REPL.LineEdit.var"#163#218")(::REPL.LineEdit.MIState, ::Any, ::Vararg{Any})
│        @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:2397
│      [6] #invokelatest#2
│        @ ./essentials.jl:799 [inlined]
│      [7] invokelatest
│        @ ./essentials.jl:796 [inlined]
│      [8] (::REPL.LineEdit.var"#27#28"{REPL.LineEdit.var"#163#218", String})(s::Any, p::Any)
│        @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:1533
│      [9] prompt!(term::REPL.Terminals.TextTerminal, prompt::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:2665
│     [10] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
│        @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:2567
│     [11] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
│        @ REPL ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/REPL.jl:1253
│     [12] (::REPL.var"#49#54"{REPL.LineEditREPL, REPL.REPLBackendRef})()
│        @ REPL ./task.jl:494
└ @ REPL.LineEdit ~/packages/julias/julia-latest/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:2667

julia> VERSION
v"1.9.0-DEV.624"

From the discourse thread, I understand that ctrl+t performs a character transpose. Perhaps this should be a no-op if there's only one character on the line?

@giordano giordano added the REPL Julia's REPL (Read Eval Print Loop) label May 22, 2022
@perryprog
Copy link
Contributor

perryprog commented May 22, 2022

Easiest fix is to (ironically) transpose the first two lines of edit_transpose_chars(buf::IOBuffer) to be

function LineEdit.edit_transpose_chars(buf::IOBuffer)
    eof(buf) && char_move_left(buf)
    position(buf) == 0 && return false
    char_move_left(buf)
    pos = position(buf)
    a, b = read(buf, Char), read(buf, Char)
    seek(buf, pos)
    write(buf, b, a)
    return true
end

While this will move the cursor left by one even when it doesn't transpose anything, that does actually matches the behavior of Emac's ^T when used in a buffer of just a single letter and the point is at the end of the line.

Edit: giving a shot at implementing this; seems like a fun first Julia PR! :)

@rfourquet rfourquet added the bug Indicates an unexpected problem or unintended behavior label Sep 22, 2022
@Keno
Copy link
Member

Keno commented Sep 24, 2022

I'm still seeing this issue when hitting ctrl-t on a completely empty buffer.

@perryprog
Copy link
Contributor

Whoops; sorry about that, and thanks for the catch. Should be fixed in the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
5 participants