JonyEpsilon / gorilla-repl

A rich REPL for Clojure in the notebook style.
http://gorilla-repl.org
MIT License
887 stars 104 forks source link

Are there any plans for adding section folding? #163

Closed GregDavidson closed 9 years ago

GregDavidson commented 10 years ago

I love Gorilla and my worksheets quickly become unmanageably bulky. I see how to imply sections using Markdown headers. Is there an easy way to add some scripting to enable folding (hide/show) of sections? Thanks for any suggestions towards such a possibility!

JonyEpsilon commented 10 years ago

That would be great. The reason it's not there yet is that I haven't figured out how to do it!

In the code that Gorilla was descended from, I used an explicitly tree-structured worksheet, which makes it very natural to offer folding. For Gorilla I simplified to a list-structured worksheet, partly to reduce complexity, but also to make it easier to map the worksheet onto a plain clojure file for persistence.

At the minute, each Markdown segment is it's own little island as far as the HTML structure of the worksheet is concerned, so I can't see a natural way to implement the folding. It would be nice though, so I'll give it some more thought.

GregDavidson commented 10 years ago

I was thinking that some {Clojure,Java}Script code might add div elements around the sections implied by any header lines, along with a class which would be a hook for adding an onclick option to toggle hide/show on the section contents and on the characters which trigger it. Something like this:

<h?> <span class="hide_it show" title="click to hide section"> ↚</span> <span class="show_it hide" title="click to unhide section"> ↬</span> WHATEVER HEADER TEXT </h?> <div class="hideable show"> WHATEVER CONTENTS, INCLUDING SUB-SECTIONS </dev>

where h? is h1, h2, etc. and in the css: .show{} .hide{display: none;} the scripting onload adds actions to the hide_it and show_it nodes which toggle the classes of the two spans and the div between hide and show. (I like toggling between show & hide even though show doesn't actually do anything, it makes it more clear to me when I'm looking at the code that it's an element that may be hidden.)

JonyEpsilon commented 10 years ago

I don't think it could be done that way @GregDavidson unfortunately. The problem is that the "logical" .hideable sections that you'd want to be able to fold span multiple .segment div elements. So it wouldn't be possible to generate the required, valid HTML as the section could start in one div and end in another. HTML doesn't allow arbitrary tag order like this. :-(

It would be possible to do it by "brute force" using JS, but I feel like there might be a more elegant way to do it.

GregDavidson commented 10 years ago

I was imagining that part of what the ClojureScript/JS would do on-load would be to surround the sections following the headers with new divs, up until the next header of the same or lower number. That way there is only one div which the control on the header just before it needs to control.

JonyEpsilon commented 9 years ago

Given the incompatibility of Gorilla's worksheet structure with section-folding, I think I'm going to close this one as "won't fix" for the moment. That's not to say it's not a great idea, just that I don't think it's practical given the amount of effort it would take.