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

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

Open
dpsanders opened this issue Mar 24, 2019 · 26 comments
Labels

Comments

@dpsanders
Copy link

Typing [] gives []]

@KristofferC
Copy link
Owner

This used to work.

@KristofferC
Copy link
Owner

Does this only happen if OhMyREPL is loaded at startup?

@dpsanders
Copy link
Author

Yes it only happens if loaded at startup.

@KristofferC
Copy link
Owner

KristofferC commented Mar 24, 2019

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

@dpsanders dpsanders changed the title Explicitly typing closing bracket gives extra bracket Typing closing bracket gives extra bracket when package loaded from startup file Mar 24, 2019
@dpo
Copy link

dpo commented Apr 2, 2019

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

@KristofferC
Copy link
Owner

KristofferC commented Apr 2, 2019

I can only repro with [].

@dpo
Copy link

dpo commented Apr 2, 2019

My bad, nevermind.

@ssfrr
Copy link

ssfrr commented Apr 19, 2019

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

@dpsanders
Copy link
Author

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

@dpsanders
Copy link
Author

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

@timrandg
Copy link

timrandg commented Oct 6, 2020

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
Copy link

timrandg commented Oct 6, 2020

# 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

@carlocab
Copy link

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 jpalardy/vim-slime#254 and #224.

@arnauqb
Copy link

arnauqb commented Feb 23, 2021

@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?

@carlocab
Copy link

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.

@anandijain
Copy link

anandijain commented Mar 12, 2021

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

@KristofferC
Copy link
Owner

KristofferC commented Mar 12, 2021

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.

@mahiki
Copy link

mahiki commented Jul 25, 2021

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

@dpo
Copy link

dpo commented Sep 22, 2022

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?

@iamed2
Copy link

iamed2 commented Sep 23, 2022

@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.

@dpo
Copy link

dpo commented Sep 23, 2022

@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.

@axsk
Copy link

axsk commented Sep 29, 2022

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 ]].

@ghyatzo
Copy link
Contributor

ghyatzo commented Oct 7, 2022

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.

@dpo
Copy link

dpo commented Oct 7, 2022

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

@vancleve
Copy link

Should this issue be closed by #297 ?

@PhyX-Meow
Copy link

PhyX-Meow commented Jun 9, 2024

This seems to be back in julia 1.11-beta2.
My startup.jl:

using OhMyREPL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests