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

add REPL hooks #2

Open
stevengj opened this issue Aug 27, 2018 · 5 comments
Open

add REPL hooks #2

stevengj opened this issue Aug 27, 2018 · 5 comments
Labels
enhancement New feature or request

Comments

@stevengj
Copy link
Member

As suggested by @dawbarton, in JuliaLang/julia#28789 (comment), it is possible to hack the active REPL to use SoftGlobalScope. Would be nice to add this feature here, so that using SoftGlobalScope patches the active REPL if there is one.

Similar to this code in OhMyREPL.jl, we would do this in __init__ only in interactive mode.

@KristofferC, your advice on the cleanest way to patch the REPL's eval loop would be appreciated.

@stevengj stevengj added the enhancement New feature or request label Aug 27, 2018
@KristofferC
Copy link
Member

Revise has a similar use case where it wants to patch the REPL to revise methods upon each evaluation in the REPL. The code on how it manages to do that (https://github.com/timholy/Revise.jl/blob/382e872375de76f279556d076730a0fe5de4520f/src/Revise.jl#L743-L842) is likely useful.

The question now is of course, what happens when there are two REPL thieves in play at the same time... Perhaps we need a REPLThieves.jl package ;). cc @timholy.

@dawbarton
Copy link
Contributor

Yup, it looks like I did it exactly the same way as Revise does and doing it twice won't play nicely. It might well be possible to intercept the eval call in a slightly different way that does play nicely though. I can try to take a look at some point in the next few days...

@ssfrr
Copy link

ssfrr commented Sep 22, 2019

FWIW a while ago I wrote a small package to easily work with hooks for this sort of thing:

https://github.com/ssfrr/Hooks.jl

I never ended up registering it but this is the sort of problem it's designed to solve so it might be worth revisiting. It's also possible we could add a set of Base hooks to the Hooks.jl package so that multiple packages can subscribe to them.

@stevengj
Copy link
Member Author

Basically we need someone to create a REPLHooks package that allows you to add hooks to the REPL, then refactor Revise to use it, at which point SoftGlobalScope can use it too.

@stevengj
Copy link
Member Author

Note that Julia 1.5 now does this for us, and adds a general mechanism for REPL hooks (JuliaLang/julia#34626).

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

No branches or pull requests

4 participants