Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a way to use Pluto default show for types which define a custom show method #2997

Open
disberd opened this issue Aug 13, 2024 · 5 comments
Labels
display & PlutoRunner & AbstractPlutoDingetjes.jl

Comments

@disberd
Copy link
Contributor

disberd commented Aug 13, 2024

Currently, if I create a type MyType and define a override Base.show(io::IO, x::MyType) or Base.show(io::IO, ::MIME"text/plain", x::MyType), then I lose the default show method in Pluto, and there is not method to get it back.

It would be good to be able to decide I want my type to have a custom show in the REPL but do not impact the Pluto default show method.

I remember somebody raised this issue question before in either zulip/discourse but can't find it anymore.

Discussed this today at the dev call and @fonsp also agrees that we should have this capability

@disberd disberd changed the title Have a way to use Pluto default show for custom types which define a custom show method Have a way to use Pluto default show for types which define a custom show method Aug 13, 2024
@cstjean
Copy link

cstjean commented Aug 16, 2024

Having a way to "display this object as a Pluto object tree of ..." would also be very nice!

@MasonProtter
Copy link

Here's the Zulip thread with the request: https://julialang.zulipchat.com/#narrow/channel/243342-pluto.2Ejl/topic/show.20method

@MasonProtter
Copy link

MasonProtter commented Nov 1, 2024

Here's two potential ways to handle this:

  1. Give users a function they can call, so that e.g. they can write
Base.show(io::IO, ::MIME"text/html", x::MyType) = PlutoRunner.pluto_show(io, x)
  1. Define some trait they can overwrite that communicates to Pluto that it should use Pluto's tree-view instead of the regular show method
PlutoRunner.use_treeview(::MyType) = true

@cstjean
Copy link

cstjean commented Nov 5, 2024

Wouldn't it make sense to have a MIME"text/pluto"? Then users who don't want the HTML representation can write

Base.show(io::IO, mime::MIME"text/pluto", x::MyType) = @invoke show(io, mime, x::Any)

to get the default show(::IO, ::MIME"text/pluto", ::Any) fallback (which would itself follow the current logic of checking if a text/html is defined, and fallback to the tree viewer).

Furthermore,

  • Some library could choose to define separate text/html and text/pluto methods
  • No need to import PlutoRunner in a library to implement the above method

@fonsp
Copy link
Owner

fonsp commented Nov 5, 2024

We can add this the use_treeviewer trait to AbstractPlutoDingetjes! Feel free to make the PRs

@fonsp fonsp added the display & PlutoRunner & AbstractPlutoDingetjes.jl label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display & PlutoRunner & AbstractPlutoDingetjes.jl
Projects
None yet
Development

No branches or pull requests

4 participants