vscode julia path changed, code to avoid Main.Notebook module context changed

This commit is contained in:
2026-03-05 20:50:28 +01:00
parent 733fe8c290
commit 0e6b3d92fa
10 changed files with 90 additions and 31 deletions

View File

@@ -9,10 +9,23 @@ julia:
#| echo: false
#| output: false
using InteractiveUtils
import QuartoNotebookWorker
Base.stdout = QuartoNotebookWorker.with_context(stdout)
myactive_module() = Main.Notebook
Base.active_module() = myactive_module()
#struct M a::Int end; x = M(22); @show x
#should not print "Main.Notebook.M(22)" but only "M(22)"
function Base.show(io::IO, x::T) where T
if parentmodule(T) == @__MODULE__
# Print "TypeName(fields...)" without module prefix
print(io, nameof(T), "(")
fields = fieldnames(T)
for (i, f) in enumerate(fields)
print(io, getfield(x, f))
i < length(fields) && print(io, ", ")
end
print(io, ")")
else
invoke(Base.show, Tuple{IO, Any}, io, x)
end
end
```
# Working with Julia: The REPL, Packages, and Introspection