diff --git a/src/notebook/saving and loading.jl b/src/notebook/saving and loading.jl index 80831ebbb..cdac82902 100644 --- a/src/notebook/saving and loading.jl +++ b/src/notebook/saving and loading.jl @@ -32,7 +32,7 @@ Have a look at our [JuliaCon 2020 presentation](https://youtu.be/IAF8DjrQSSk?t=1 function save_notebook(io::IO, notebook::Notebook) println(io, _notebook_header) println(io, "# ", PLUTO_VERSION_STR) - + # Notebook metadata let nb_metadata_toml = strip(sprint(TOML.print, get_metadata_no_default(notebook))) if !isempty(nb_metadata_toml) @@ -56,7 +56,7 @@ function save_notebook(io::IO, notebook::Notebook) println(io) cells_ordered = collect(topological_order(notebook)) - + # NOTE: the notebook topological is cached on every update_dependency! call # .... so it is possible that a cell was added/removed since this last update. # .... in this case, it will not contain that cell since it is build from its @@ -91,13 +91,13 @@ function save_notebook(io::IO, notebook::Notebook) end end - + using_plutopkg = notebook.nbpkg_ctx !== nothing - + write_package = if using_plutopkg ptoml_contents = PkgCompat.read_project_file(notebook) mtoml_contents = PkgCompat.read_manifest_file(notebook) - + !isempty(strip(ptoml_contents)) else false @@ -109,14 +109,14 @@ function save_notebook(io::IO, notebook::Notebook) write(io, ptoml_contents) print(io, "\"\"\"") print(io, _cell_suffix) - + println(io, _cell_id_delimiter, string(_mtoml_cell_id)) print(io, "PLUTO_MANIFEST_TOML_CONTENTS = \"\"\"\n") write(io, mtoml_contents) print(io, "\"\"\"") print(io, _cell_suffix) end - + println(io, _cell_id_delimiter, "Cell order:") for c in notebook.cells @@ -137,7 +137,7 @@ function write_buffered(fn::Function, path) file_content = sprint(fn) write(path, file_content) end - + function save_notebook(notebook::Notebook, path::String) # @warn "Saving to file!!" exception=(ErrorException(""), backtrace()) notebook.last_save_time = time() diff --git a/src/runner/PlutoRunner/src/bonds.jl b/src/runner/PlutoRunner/src/bonds.jl index 431eff4c0..3bf792a6c 100644 --- a/src/runner/PlutoRunner/src/bonds.jl +++ b/src/runner/PlutoRunner/src/bonds.jl @@ -10,7 +10,7 @@ function transform_bond_value(s::Symbol, value_from_js) catch e @error "🚨 AbstractPlutoDingetjes: Bond value transformation errored." exception=(e, catch_backtrace()) (; - message=Text("🚨 AbstractPlutoDingetjes: Bond value transformation errored."), + message=Text("🚨 AbstractPlutoDingetjes: Bond value transformation errored."), exception=Text( sprint(showerror, e, stacktrace(catch_backtrace())) ), @@ -35,16 +35,16 @@ function possible_bond_values(s::Symbol; get_length::Bool=false) :InfinitePossibilities elseif (possible_values isa AbstractPlutoDingetjes.Bonds.NotGiven) # error("Bond \"$s\" did not specify its possible values with `AbstractPlutoDingetjes.Bond.possible_values()`. Try using PlutoUI for the `@bind` values.") - + # If you change this, change it everywhere in this file. :NotGiven else - get_length ? + get_length ? try length(possible_values) catch length(make_serializable(possible_values)) - end : + end : make_serializable(possible_values) end end @@ -118,7 +118,7 @@ x^2 The first cell will show a slider as the cell's output, ranging from 0 until 100. The second cell will show the square of `x`, and is updated in real-time as the slider is moved. """ -macro bind(def, element) +macro bind(def, element) if def isa Symbol quote $(load_integrations_if_needed)() @@ -133,13 +133,16 @@ end """ Will be inserted in saved notebooks that use the @bind macro, make sure that they still contain legal syntax when executed as a vanilla Julia script. Overloading `Base.get` for custom UI objects gives bound variables a sensible value. +Also turns off JuliaFormatter formatting to avoid issues with the formatter trying to change code that the user does not control. See https://domluna.github.io/JuliaFormatter.jl/stable/#Turn-off/on-formatting """ const fake_bind = """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"""