Skip to content

Commit

Permalink
Recommend BasicAutoloads instead of a home-rolled autoloader (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Apr 27, 2024
1 parent fbd483b commit 312bf73
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions docs/src/autoload.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,15 @@ to install first to most streamlined user experience last.
launching a new Julia session by a few milliseconds (for comparison, this is about 20x
faster than loading `Revise` in your startup.jl file).

3. [**Recommended**] Add Chairmarks to your default environment and put the following script in your
startup.jl file to automatically load it when you type `@b` or `@be` in the REPL:
3. [**Recommended**] Add Chairmarks and [BasicAutoloads](https://github.com/LilithHafner/BasicAutoloads.jl)
to your default environment and put the following script in your startup.jl file to
automatically load it when you type `@b` or `@be` in the REPL:

```julia
if isinteractive() && (local REPL = get(Base.loaded_modules, Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL"), nothing); REPL !== nothing)
# https://github.com/fredrikekre/.dotfiles/blob/65b96f492da775702c05dd2fd460055f0706457b/.julia/config/startup.jl
# Automatically load tooling on demand. These packages should be stdlibs or part of the default environment.
# - Chairmarks when encountering @b or @be
# - add more as desired...
local tooling = [
["@b", "@be"] => :Chairmarks,
# add more here...
]

local tooling_dict = Dict(Symbol(k) => v for (ks, v) in tooling for k in ks)
function load_tools(ast)
if ast isa Expr
if ast.head === :macrocall
pkg = get(tooling_dict, ast.args[1], nothing)
if pkg !== nothing && !isdefined(Main, pkg)
@info "Loading $pkg ..."
try
Core.eval(Main, :(using $pkg))
catch err
@info "Failed to automatically load $pkg" exception=err
end
end
end
foreach(load_tools, ast.args)
end
ast
end

pushfirst!(REPL.repl_ast_transforms, load_tools)
if isinteractive()
import BasicAutoloads
BasicAutoloads.register_autoloads([
["@b", "@be"] => :(using Chairmarks),
])
end
```

0 comments on commit 312bf73

Please sign in to comment.