Skip to content

Commit a3854fe

Browse files
author
Patrick Häcker
committed
Document possibly surprising syntax for submodule usage
1 parent a011fe9 commit a3854fe

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ using UseAll
1717

1818
After that, names such as `countfrom` can be used directly, without writing `Base.Iterators.countfrom`.
1919

20+
Submodules of the current module are detected automatically, so if you defined a module at the REPL you can write:
21+
22+
```julia
23+
module MyModule
24+
f(x) = x + 1
25+
end
26+
27+
@useall MyModule # The Julia parser does not accept `@useall .MyModule` here.
28+
```
29+
2030
This is useful while working in the REPL: By pulling names from a package or submodule into `Main`, you can execute copy-pasted code from a module. That means all your previous definitions in your REPL session or from your `startup.jl` remain available. You can also add the names from more than one module and can execute their copy-pasted code without doing anything else in-between.
2131

2232
It is also useful in closely coupled code, for example in a package's own `runtests.jl`, where explicit imports can become noisy and the code intentionally works with many internals of the same package.

src/UseAll.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ Unlike `using Module`, which only imports the explicitly exported names, `@useal
1111
all names — including private and imported ones — except for hidden compiler-generated names
1212
(starting with `#`) and names already present in the target module (such as `eval` and `include`).
1313
14-
Supports top-level packages and submodules:
14+
Supports top-level packages, submodules, and submodules of the current module:
1515
16-
@useall TOML Base.Iterators
16+
@useall TOML Base.Iterators MyModule
17+
18+
Submodules of the caller's module (e.g. defined in `Main`) are detected automatically:
19+
use `@useall MyModule` instead of `@useall .MyModule`, as the latter is invalid syntax in Julia.
1720
1821
When [Revise.jl](https://github.com/timholy/Revise.jl) is loaded, newly exported symbols are
1922
automatically imported after revision.

0 commit comments

Comments
 (0)