Skip to content

Commit

Permalink
allow setting the module which code gets evaluated in (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored and stevengj committed Apr 17, 2018
1 parent 9cba264 commit e11ae26
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ results. This limit can be increased to a custom value, like 1MB, as follows
IJulia.set_max_stdio(1 << 20)
```

### Setting the current module

The module that code in an input cell is evaluated in can be set using `IJulia.set_current_module(::Module)`.
It defaults to `Main`.

## Low-level Information

### Using older IPython versions
Expand Down
3 changes: 3 additions & 0 deletions src/IJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ however, it can be more convenient to *not* capture stdout and stderr output
const capture_stdout = true
const capture_stderr = true

set_current_module(m::Module) = current_module[] = m
const current_module = Ref{Module}(Main)

#######################################################################

"""
Expand Down
2 changes: 1 addition & 1 deletion src/execute_request.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function execute_request(socket, msg)

#run the code!
ans = result = ismatch(magics_regex, code) ? magics_help(code) :
include_string(Main, code, "In[$n]")
include_string(current_module[], code, "In[$n]")

if silent
result = nothing
Expand Down
2 changes: 1 addition & 1 deletion src/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function complete_types(comps)
expr = Meta.parse(c, raise=false)
if typeof(expr) == Symbol
try
ctype = complete_type(eval(Main, :(typeof($expr))))
ctype = complete_type(eval(current_module[], :(typeof($expr))))
end
elseif !isa(expr, Expr)
ctype = complete_type(expr)
Expand Down

0 comments on commit e11ae26

Please sign in to comment.