KristofferC / OhMyREPL.jl

Syntax highlighting and other enhancements for the Julia REPL
https://kristofferc.github.io/OhMyREPL.jl/latest/
Other
768 stars 60 forks source link

Bug when `using OhMyREPL` in `startup.jl`: Adds too many `]`s. #269

Closed Jollywatt closed 1 year ago

Jollywatt commented 2 years ago

I’m experiencing a small (but annoying) bug with autocompleted square brackets.

The expected behaviour is that typing [x OR [x] produces [x] in the REPL (soft autocompletion). However, if I type [x], I get [x]], i.e., the autocompleted ] is not replaced by the manually-inserted ]. This only happens with []; other delimiters like (), {}, "", '' work as expected.

The strange thing about this is that it only happens when using OhMyREPL is in the startup.jl file. Running julia --startup-file=no followed by julia> using OhMyREPL works fine.

I’m struggling to debug why. Tested on macOS and Ubuntu with julia 1.7.2 and 1.7.3.

(@v1.7) pkg> st OhMyREPL
      Status `~/.julia/environments/v1.7/Project.toml`
  [5fb14364] OhMyREPL v0.5.12
Moelf commented 2 years ago

Duplicate of https://github.com/KristofferC/OhMyREPL.jl/issues/227#issuecomment-734997045

Jollywatt commented 2 years ago

Note this is related, but not a duplicate. Note this only happens when using a startup file.


Edit: Not a duplicate of #227 (comment), but is a duplicate of #166 .

Jollywatt commented 2 years ago

I’ve discovered that this bug (typing [1] and getting [1]]), which is only observed when loading OhMyREPL in the startup.jl file, is fixed by another call to OhMyREPL.__init__() in the REPL after startup.

This suggests that something happens after the startup.jl file is run, but before the julia> prompt is displayed, which overrides the keymap for “]”. Maybe there is some initialisation for the pkg> REPL mode which causes this?

Jollywatt commented 2 years ago

My hacky solution for the meantime is to have this in my startup.jl file:

using OhMyREPL

schedule(@task begin
    sleep(0.1)
    OhMyREPL.__init__()
end)

This reruns OhMyREPL.__init__() after the julia> prompt displays and fixes my issue.

Jollywatt commented 2 years ago

I just found a duplicate issue with the same hacky solution from three years ago! 😅

Duplicate: #166

Jollywatt commented 2 years ago

(Closing since duplicate)