# Atreplinit and DrWatson's quickactivate at startup.jl file

**URL:** <https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969>\
**Category:** General Usage\
**Tags:** startup, atreplinit\
**Created:** [December 23, 2023, 11:26am UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969 "2023-12-23T11:26:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mocalvao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mocalvao/32/19318_2.png) [@mocalvao](https://discourse.julialang.org/u/mocalvao)\
**Post date:** [December 23, 2023, 11:26am UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969/1 "2023-12-23T11:26:26Z")

</div>

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:

```julia
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:

```julia
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,

```julia
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.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 23, 2023, 12:38pm UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969/2 "2023-12-23T12:38:17Z")

</div>

Why is everything within `atreplinit`?

---

<div class="post-metadata">

**Author:** ![mocalvao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mocalvao/32/19318_2.png) [@mocalvao](https://discourse.julialang.org/u/mocalvao)\
**Post date:** [December 23, 2023, 12:52pm UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969/3 "2023-12-23T12:52:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 23, 2023, 6:02pm UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969/4 "2023-12-23T18:02:51Z")

</div>

I can think a few options then.

1. Use `if Base.isinteractivd()`.
2. Use a single `@eval` block.

```julia
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`

---

<div class="post-metadata">

**Author:** ![mocalvao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mocalvao/32/19318_2.png) [@mocalvao](https://discourse.julialang.org/u/mocalvao)\
**Post date:** [December 24, 2023, 12:45pm UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969/5 "2023-12-24T12:45:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 24, 2023, 8:18pm UTC](https://discourse.julialang.org/t/atreplinit-and-drwatsons-quickactivate-at-startup-jl-file/107969/6 "2023-12-24T20:18:34Z")

</div>

> [@mocalvao](#):
>
> 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?

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.

```julia
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](https://julialang.github.io/IJulia.jl/stable/manual/usage/#:~:text=Detecting%20that%20code%20is%20running,IJulia).

I also encourage you to check out Pluto notebooks.

> **[Pluto.jl — interactive Julia programming environment](https://plutojl.org/)**
>
> A free, open source Julia programming environment. Designed to make learning and teaching scientific programming simple!
