OhMyREPL.jl icon indicating copy to clipboard operation
OhMyREPL.jl copied to clipboard

Typing closing bracket gives extra bracket when package loaded from startup file

Open dpsanders opened this issue 5 years ago • 27 comments

Typing [] gives []]

dpsanders avatar Mar 24 '19 15:03 dpsanders

This used to work.

KristofferC avatar Mar 24 '19 15:03 KristofferC

Does this only happen if OhMyREPL is loaded at startup?

KristofferC avatar Mar 24 '19 15:03 KristofferC

Yes it only happens if loaded at startup.

dpsanders avatar Mar 24 '19 15:03 dpsanders

The problem is that Pkg overwrites our keybinding for ] when the Pkg REPL loads (after OhMyREPL)...

KristofferC avatar Mar 24 '19 15:03 KristofferC

I have the same issue. ~~The same behavior occurs with double quotes: typing "" gives """ when loaded at startup. Same with curly braces.~~

dpo avatar Apr 02 '19 13:04 dpo

I can only repro with [].

KristofferC avatar Apr 02 '19 14:04 KristofferC

My bad, nevermind.

dpo avatar Apr 02 '19 14:04 dpo

Pretty hacky but for now I'm working around this by adding the following after using OhMyREPL in my startup.jl:

@async begin
    # reinstall keybindings to work around https://github.com/KristofferC/OhMyREPL.jl/issues/166
    sleep(1)
    OhMyREPL.Prompt.insert_keybindings()
end

ssfrr avatar Apr 19 '19 18:04 ssfrr

@ssfrr's solution no longer seems to work for me?

dpsanders avatar Mar 03 '20 21:03 dpsanders

@ssfrr's solution seems to be working now, thanks! Maybe this should be added to the README?

dpsanders avatar May 28 '20 19:05 dpsanders

This issue also affects vim-slime plug-in (to send block of code to julia REPL for evaluation). Without ssfrr's hack, an extra ']' is appended to any line of code that has a '[' upon vim-slime transfer. This causes arrays and list comprehension syntax to be corrupted by the appended bracket. But if ssfrr's hack is added to the startup.jl after OhMyREPL, the appended ']' no longer appears on vim-slime transfer to julia REPL.

timrandg avatar Oct 06 '20 04:10 timrandg

# startup.jl
# to automate adding OhMyREPL package to REPL on startup
atreplinit() do repl
    try
        @eval using OhMyREPL
    catch e
        @warn "error while importing OhMyREPL" e
    end

    @async begin
    # reinstall keybindings to work around https://github.com/KristofferC/OhMyREPL.jl/issues/166
    sleep(1)
    OhMyREPL.Prompt.insert_keybindings()
    end
end

timrandg avatar Oct 06 '20 04:10 timrandg

This issue also affects vim-slime plug-in (to send block of code to julia REPL for evaluation). Without ssfrr's hack, an extra ']' is appended to any line of code that has a '[' upon vim-slime transfer. This causes arrays and list comprehension syntax to be corrupted by the appended bracket. But if ssfrr's hack is added to the startup.jl after OhMyREPL, the appended ']' no longer appears on vim-slime transfer to julia REPL.

Do you use vim-slime with tmux? If so, I think it's because slime doesn't use bracketed paste by default. See https://github.com/jpalardy/vim-slime/pull/254 and #224.

carlocab avatar Oct 19 '20 22:10 carlocab

@carlocab Am I correct in saying that your fix to this problem was reverted in vim-slime? I am using tmux + vim-slime and facing the same issue. Did you find a workaround?

arnauqb avatar Feb 23 '21 08:02 arnauqb

It was reverted, yes. I haven't managed to look into a workaround -- I don't use vim-slime much lately, so the issue hasn't bothered me so much.

I think the idea would be to only selectively activate bracketed paste with tmux, but I'm not sure what the best way to do that is yet.

carlocab avatar Feb 23 '21 09:02 carlocab

It doesn't only happen if in startup.jl for me. The bodge doesn't work for me. While typing [] for me gives [] but any multiline copy-pasting involving [ will fail, ie

  eqs = [D(x) ~ σ*(y-x),
         D(y) ~ x*(ρ-z)-y,
         D(z) ~ x*y - β*z]

gives

julia> eqs = [D(x) ~ σ*(y-x),]
1-element Vector{Equation}:
 Differential(t)(x(t)) ~ σ*((y(t)) - (x(t)))

julia> D(y) ~ x*(ρ-z)-y,
            D(z) ~ x*y - β*z]
ERROR: syntax: extra token "]" after end of expression

anandijain avatar Mar 12 '21 01:03 anandijain

While typing [] for me gives [] but any multiline copy-pasting involving [ will fail, ie

This is (likely) an issue with Windows, you can turn off the bracket completion: https://kristofferc.github.io/OhMyREPL.jl/latest/features/bracket_complete/#Settings.

KristofferC avatar Mar 12 '21 14:03 KristofferC

This is (likely) an issue with Windows, you can turn off the bracket completion: https://kristofferc.github.io/OhMyREPL.jl/latest/features/bracket_complete/#Settings.

No I am on macOS observing same behavior with ] not closing. Using OhMyREPL. Screen Shot 2021-07-24 at 11 12 44 PM

The ssfrr hack above fixes the problem

mahiki avatar Jul 25 '21 06:07 mahiki

The workaround above again no longer works for me. macOS, iTerm2, Julia 1.8.1. My startup.jl contains:

atreplinit() do repl
    try
        @info "importing OhMyREPL (incl. fzf)"
        @eval using OhMyREPL
        @async begin
            # reinstall keybindings to work around https://github.com/KristofferC/OhMyREPL.jl/issues/166
            sleep(1)
            OhMyREPL.Prompt.insert_keybindings()
            OhMyREPL.enable_autocomplete_brackets(false)
        end
    catch e
        @error "error while importing OhMyREPL" e
    end
end

Is there any chance of disabling bracket autocompletion by default?

dpo avatar Sep 22 '22 22:09 dpo

@dpo I have the same system configuration, but my startup is doing:

using OhMyREPL

@async begin
    # reinstall keybindings to work around https://github.com/KristofferC/OhMyREPL.jl/issues/166
    sleep(1)
    OhMyREPL.Prompt.insert_keybindings()
end

This doesn't include graceful failure or logging (I have to pass --startup-file=no if I use an environment without OhMyREPL or deal with the error), but it seems to be working for me.

iamed2 avatar Sep 23 '22 19:09 iamed2

@iamed2 Thank you for the response.

I thought the atreplinit() ... bit was necessary. I got it from the docs. I hadn't noticed before that the @async bit was outside the try ... catch. I tried moving mine out, but the problem persists.

I have OhMyREPL in my global environment. Indeed, removing atreplinit() ... works. So I'm now even more confused. However, if I also have an atreplinit() bit where I import other packages, the dreaded bracket autocompletion returns.

My config works fine with Julia 1.7. It's with Julia 1.8 that it seems to break.

dpo avatar Sep 23 '22 19:09 dpo

I can just confirm that enable_autocomplete_brackets(false) has no effect / errors inside the async block in startup.jl. However, insert_keybindings does not seem to be necessary anymore to avoid the ]].

axsk avatar Sep 29 '22 10:09 axsk

Currently on julia 1.8.3 I have in my startup.jl

try
    println("Starting OhMyREPL...")
    using OhMyREPL
catch e
    @warn "Error initializing OhMyREPL" exception=(e, catch_backtrace())
end
@async begin
    while !isdefined(Base, :active_repl) sleep(0.1) end
    OhMyREPL.Prompt.insert_keybindings()
end

and it currently works, I switched to a sleeping while loop waiting to have a handle for the active repl, instead of just sleep(1) which seemd a bit too arbitrary for my tastes.

ghyatzo avatar Oct 07 '22 13:10 ghyatzo

@ghyatzo I tried with and without OhMyREPL.enable_autocomplete_brackets(false) inside your @async block, but neither works for me.

dpo avatar Oct 07 '22 21:10 dpo

Should this issue be closed by https://github.com/KristofferC/OhMyREPL.jl/pull/297 ?

vancleve avatar Jul 28 '23 04:07 vancleve