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

reorder cells in GUI according to order of command execution #270

Closed
talbym opened this issue Aug 9, 2020 · 8 comments
Closed

reorder cells in GUI according to order of command execution #270

talbym opened this issue Aug 9, 2020 · 8 comments

Comments

@talbym
Copy link

talbym commented Aug 9, 2020

suggestion: option to reorder the cells in the "Pluto web GUI editor" according to the order of command execution;
the created file.jl has this order already established for the commands, so that the file.jl could serve as a normal Julia script; it would be fine if by a function in the GUI, or at least when opening the file.jl again, there would be an option to apply the execution order as the new presented cell ordering in the GUI;

@ndgnuh
Copy link

ndgnuh commented Aug 9, 2020

Personally, I use this function:

 function sortcell(filename::String, outfile = filename)
           cells = filter(startswith("# ╔═╡"), (collect  eachline)(filename))[1:end-1]
           cells = map(cells) do cell
               replace(cell, "# ╔═╡" => "# ╠═")
           end
           cells = join(cells, "\n")
           file = read(filename, String); print(cells)
           file = replace(file, r"(\n?# ╠═.+)+" => "\n$cells")
           write(outfile, file)
 end

It's not elegant, but it works.

@fonsp
Copy link
Owner

fonsp commented Aug 12, 2020

Why would it be useful?

@talbym
Copy link
Author

talbym commented Aug 20, 2020

Why would it be useful?

It would be helpful for enhancing the readability of the code which already became developed. Using an interactive coding style for testing something on the code, and finally having found a solution to a problem, it could be helpful to not only find the sequence of execution in the file.jl, but to also use this sequence of execution as the new sequence for listing the code also in Pluto before continuing with works on the code. I think it many times could enhance readability of developed code if cells in Pluto as an option could be reordered to the order of command execution as by now only found in the file.jl. I would not suggest to force such reordering to always become applied, but, as the word suggests, provide such reordering as an "option".

@fonsp
Copy link
Owner

fonsp commented Aug 24, 2020

Could you summarize?

@fonsp
Copy link
Owner

fonsp commented Sep 2, 2020

#276 (comment)

@fonsp
Copy link
Owner

fonsp commented Sep 2, 2020

I don't feel like this should be part of Pluto's UI, because it adds a complicated button, and it makes reactivity feel like something to avoid, instead of a feature.

But @ndgnuh, feel free to add that script to https://github.com/fonsp/PlutoUtils.jl

@fonsp fonsp closed this as completed Sep 2, 2020
@ndgnuh
Copy link

ndgnuh commented Sep 2, 2020

My script feels hacky (it relies on those comments at the beginning of the line). So while it works, I don't think it should go in a package.

@fonsp
Copy link
Owner

fonsp commented Sep 2, 2020

in that case, play around with this:
#132 (comment)
you need to update the notebook's topology, i.e. compute dependencies between cells:
https://github.com/fonsp/Pluto.jl/blob/v0.11.10/src/evaluation/Run.jl#L97-L99
and you compute the topological order like so:
https://github.com/fonsp/Pluto.jl/blob/v0.11.10/src/evaluation/Run.jl#L34

Just reorder notebook.cells to be what you want it to be, and then
save_notebook(notebook, new_path)

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

3 participants