diff --git a/docs/src/library/internals.md b/docs/src/library/internals.md index a98985d2..558661be 100644 --- a/docs/src/library/internals.md +++ b/docs/src/library/internals.md @@ -10,16 +10,6 @@ IJulia.init ## Cell execution hooks -These functions can be used to modify the behavior of IJulia -by executing custom code before or after cells are executed -(or errors are handled). - -In Julia 1.5 or later, you can *also* add a transformation -function to `REPL.repl_ast_transforms` which takes every parsed -expression and transforms it to another expression. These -transformations are [used in the Julia REPL](https://github.com/JuliaLang/julia/issues/37047) (technically, they are the deaults for `Base.active_repl_backend.ast_transforms` in new REPL instances), -and are also executed by IJulia on each parsed code-cell expression. - ```@docs IJulia.pop_posterror_hook IJulia.pop_postexecute_hook @@ -29,6 +19,7 @@ IJulia.push_postexecute_hook IJulia.push_preexecute_hook ``` + ## Messaging ```@docs diff --git a/docs/src/manual/usage.md b/docs/src/manual/usage.md index a7a16312..8e208a5b 100644 --- a/docs/src/manual/usage.md +++ b/docs/src/manual/usage.md @@ -122,15 +122,6 @@ It defaults to `Main`. By default, IJulia evaluates user code using "soft" global scope, via the [SoftGlobalScope.jl package](https://github.com/stevengj/SoftGlobalScope.jl): this means that you don't need explicit `global` declarations to modify global variables in `for` loops and similar, which is convenient for interactive use. -To opt out of this behavior, making notebooks behave similarly to global code in Julia `.jl` files or the REPL in Julia 1.0…1.4, +To opt out of this behavior, making notebooks behave similarly to global code in Julia `.jl` files, you can set `IJulia.SOFTSCOPE[] = false` at runtime, or include the environment variable `IJULIA_SOFTSCOPE=no` environment of the IJulia kernel when it is launched. - -In Julia 1.5 or later, [soft-scope became the default -in the Julia REPL](https://julialang.org/blog/2020/08/julia-1.5-highlights/#the_return_of_quotsoft_scopequot_in_the_repl), and -IJulia once again matches the REPL behavior. The `IJULIA_SOFTSCOPE` -and `IJulia.SOFTSCOPE[]` can still be used to disable soft scope -in IJulia, however. More generally, the soft scoping can -be disabled in both the REPL and in IJulia by removing the -`REPL.softscope` function from the variable `REPL.repl_ast_transforms` -in your [`~/.julia/config/startup.jl`](https://docs.julialang.org/en/v1/manual/getting-started/) file. \ No newline at end of file diff --git a/src/execute_request.jl b/src/execute_request.jl index 03ea8046..d5548806 100644 --- a/src/execute_request.jl +++ b/src/execute_request.jl @@ -11,30 +11,11 @@ execute_msg = Msg(["julia"], Dict("username"=>"jlkernel", "session"=>uuid4()), D # request const stdio_bytes = Ref(0) -import REPL import REPL: helpmode # use a global array to accumulate "payloads" for the execute_reply message const execute_payloads = Dict[] -function execute_code(code::AbstractString, filename::AbstractString) - @static if !isdefined(REPL, :repl_ast_transforms) - return SOFTSCOPE[] ? softscope_include_string(current_module[], code, "In[$n]") : - include_string(current_module[], code, "In[$n]") - else - # use the default REPL ast transformations in Julia 1.5, - # which include the soft-scope transformation. - include_string(current_module[], code, "In[$n]") do ast - for xf in REPL.repl_ast_transforms - if xf !== REPL.softscope || SOFTSCOPE[] - ast = Base.invokelatest(xf, ast) - end - end - ast - end - end -end - function execute_request(socket, msg) code = msg.content["code"] @vprintln("EXECUTING ", code) @@ -84,7 +65,8 @@ function execute_request(socket, msg) else #run the code! occursin(magics_regex, code) && match(magics_regex, code).offset == 1 ? magics_help(code) : - execute_code(code, "In[$n]") + SOFTSCOPE[] ? softscope_include_string(current_module[], code, "In[$n]") : + include_string(current_module[], code, "In[$n]") end if silent