Is it possible to import everything but?

Both PlutoUI and Makie export Slider. It seems like the right type name for each, but causes naming conflics in notebooks. One then has to qualify the usage by PlutoUI.Slider. Is it possible to import everything but Slider from Makie? Something like using Makie: -Slider

Yes you can do:

using Makie: Slider as MSlider

as described here:
https://docs.julialang.org/en/v1/manual/modules/#Renaming-with-as

This way you avoid the name clash and can use the Makie Slider as MSlider.

18 Likes

Awesome. I did not know this!

2 Likes

It’s also worth noting that you can do, even on old version of julia:

using Makie
using PlutoUI

const Slider = Pluto.Slider
const MSlider = Makie.Slider

Further you can, if the arguments don’t over-lap do manual method merging.
For example, lets say only if the first argument is a Figure should it use the Makie one.

using Makie
using PlutoUI

Slider(f::Figure, args...; args...) = Makie.Slider(f, args...; kwargs...)
Slider(args...; args...) = PlutoUI.Slider(f, args...; kwargs...)
14 Likes

I have a macro (the package UsingMerge) which automates this process

2 Likes

if I do

using Makie: Slider as MSlider

, then the other functions from Makie are not imported. But if I do an additional using Makie, then the problem is back. Your answer tells me how to import something with another name, but I am still not sure exactly how to import everything but X. Any idea on how that can be done?

1 Like

You can just import everything and then provide a definition for the thing you don’t want to import. That causes it not to be imported. Example:

using Makie
Slider = "small burger"

The solution @oxinabox provides already does this with const bindings for Slider and MSlider. Or if you prefer a different slider from another package you can do this:

using Makie
using PlutoUI: Slider
5 Likes

What we really need are general regex transformations on import:

using Makie: r"\b([^aeiou]+)(\w+)\b" => s"\2\1ay"
iderSlay # Makie symbols are now in pig Latin

Might be a good PR to work on for 4/1/22?

17 Likes

I can only assume/hope this is trolling… if so :clap:

3 Likes

but only if regex import fully supports Unicode, so Physicists can auto-magically change notation…