Atreplinit and DrWatson's quickactivate at startup.jl file

Dear all,
I would like to have a startup.jl file which, when Julia is called interactively, from the REPL, at a given directory, automatically:

  • uses OhMyREPL, DrWatson and Revise packages
  • activates a possible project in the directory, via DrWatson’s command quickactivate
  • sets Emacs as my preferred Julia editor
    To that end, my current startup.jl file reads:
atreplinit() do repl
    @eval using OhMyREPL
    @eval using DrWatson
    @eval using Revise
    
    if isfile("Project.toml") && isfile("Manifest.toml")
        quickactivate(".")
    end

    ENV["JULIA_EDITOR"]="emacs"
end

When I run julia, from the command line, however, the following error shows up:

MethodError: no method matching quickactivate(::String)
The applicable method may be too new: running in world age 33473, while current world is 33504.

Closest candidates are:
  quickactivate(::Any) (method too new to be called from this world context.)
   @ DrWatson ~/.julia/packages/DrWatson/86H4O/src/project_setup.jl:131
  quickactivate(::Any, ::Any) (method too new to be called from this world context.)
   @ DrWatson ~/.julia/packages/DrWatson/86H4O/src/project_setup.jl:131

Concerning this error, I have 2 questions:

  • What does this weird MethodError message mean? (I checked DrWatson’s project_setup.jl source file, but did not find anything illuminating…)
  • How can I correct my startup.jl file and still have my goals achieved?

Thanks in advance!

PS: my previous version of the startup.jl file worked like a charm,

using OhMyREPL
using DrWatson
using Revise

if isfile("Project.toml") && isfile("Manifest.toml")
    quickactivate(".")
end

ENV["JULIA_EDITOR"]="emacs"

but loaded the above mentioned packages, even when Julia was called noninteractively, which is sub-optimal.

Why is everything within atreplinit?

I want all commands to be executed only if at the REPL (called interactively)…

I can think a few options then.

  1. Use if Base.isinteractivd().
  2. Use a single @eval block.
atreplinit() do repl
    @eval begin
        using OhMyREPL
        using DrWatson
        using Revise
        if isfile("Project.toml") && isfile("Manifest.toml")
            quickactivate(".")
        end

        ENV["JULIA_EDITOR"]="emacs"
    end
end
  1. Use Base.invokelatest
2 Likes

Hi @mkitti,

Thanks for the reply. Correct me if I am wrong: I can just write the single code block you wrote above, starting with atreplinit() do repl and ending with the double end into my startup.jl file and everything should be ok, right? In fact, I have already tested this and it seems to be working.

However, I would like to understand better your two other mentioned options: they are not supposed to be used in the startup.jl file, but rather within Julia REPL itself, right? If so, then they would not work automatically, right after launching Julia from the command line; is this the case? Finally, how does this change, if at all, when I use IJulia’s notebook or jupyterlab?

Thanks in advance and Merry Christmas!

My suggestions were intended for the startup.jl. You do not need the REPL initialized to load Revise or DrWatson. Base.isinitialized should be a sufficient condition.

if Base.isinteractive() || isdefined(Main, :IJulia) & Main.IJulia.inited
    using Revise
    using DrWatson
    atreplinit() do repl
        @eval using OhMyREPL
    end
    if isfile("Project.toml") && isfile("Manifest.toml")
        invokelatest(quickactivate, ".")
    end

    ENV["JULIA_EDITOR"]="emacs"
end

invokelatest is just an example usage. It is not needed here. It can be used to address world age issues when dynamically loading packages or creating functions.

IJulia is a special condition.

Using IJulia · IJulia.

I also encourage you to check out Pluto notebooks.