Obtain base path of sources to resolve error messages

I am working on making error message locations “clickable” in Emacs. How can I obtain the directory (in Julia) that ./loading.jl and the other files are resolved in the example below:

julia> include("/tmp/Foo.jl")
WARNING: replacing module Foo
ERROR: LoadError: UndefVarError: T not defined
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:576
 [2] include(::String) at ./sysimg.jl:14
while loading /tmp/Foo.jl, in expression starting on line 9

It should work for binary and source compiled distributions. Base.JULIA_HOME takes me to the executable, in can join it with ../share/julia/base/ for binary distributions or base/ for compiled source, but I imagine that there is something portable, I just could not find it.

Have a look at fullpath and related functions here for an implementation that seems to work quite well so far.

Edit: Which does exactly what you propose, so it probably won’t help much :slight_smile: Should’ve read all of your post before answering.

Thanks anyway. Forgot to mention: I need something that I can run on a “bare” installation (no packages). The idea is that I call

julia -qe <magic-base-path>

from Emacs and just process the output. The magic can be quite long, no problem with that. What about

normpath(joinpath(JULIA_HOME, Base.DATAROOTDIR, "julia", "base"))

Seems to work.

Sure, I didn’t mean to suggest you should depend on Atom for that :slight_smile:

Your solution seems to work pretty well though from what I can tell.

The next question is: how can I minimize runtime for this? Currently I run

julia --history-file=no --startup-file=no -qe \
print("OK" * normpath(joinpath(JULIA_HOME, Base.DATAROOTDIR, "julia", "base")))

where I examine the output for the prefix OK to check that things went well.

Is there anything else I can do besides disabling history and the startup file? It takes 0.2s which I can live with, but less is always better.