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

#! format off does not completely disable formatting #107

Closed
j-fu opened this issue Nov 24, 2024 · 3 comments
Closed

#! format off does not completely disable formatting #107

j-fu opened this issue Nov 24, 2024 · 3 comments

Comments

@j-fu
Copy link

j-fu commented Nov 24, 2024

Hi, thanks for runic! I am in the process of being persuaded to agree that explicit return statements are a good thing for those reading my code. However:

Every time Pluto saves a notebook to disk, it writes the following statement to the notebook:

macro bind(def, element)
    #! format: off
    quote
        local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
        local el = $(esc(element))
        global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
        el
    end
    #! format: on
end

Runic wants to format this as

macro bind(def, element)
    #! format: off
    return quote
        local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
        local el = $(esc(element))
        global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
        el
    end
    #! format: on
end

While this might be changed to more "runic" code on the Pluto side (@fonsp),
in fact, runic fails the assumption that code in the region marked by formt on/off is not modified. So I guess this is a bug.

j-fu added a commit to WIAS-PDELib/GridVisualize.jl that referenced this issue Nov 25, 2024
j-fu added a commit to WIAS-PDELib/GridVisualize.jl that referenced this issue Nov 25, 2024
@fredrikekre
Copy link
Owner

fredrikekre commented Nov 25, 2024

Not sure I would call it a bug, but perhaps a result of how things are implemented. For the "add explicit return" formatting pass the syntax node of interest is the function node` (i.e. the whole function) and that one isn't within the toggle comments. Do you have control over this? In that case, using

#! format: off
macro bind(def, element)
    quote
        local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
        local el = $(esc(element))
        global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
        el
    end
end
#! format: on

would work as you expect.

@j-fu
Copy link
Author

j-fu commented Nov 25, 2024

Ok, so let us see if this will be changed in Pluto then.

@j-fu
Copy link
Author

j-fu commented Nov 27, 2024

Will be addressed in Pluto: fonsp/Pluto.jl#3106 (comment)

@j-fu j-fu closed this as completed Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants