origami.el
origami.el copied to clipboard
Persistent folds?
How hard would it be to get folds to persist for a file across buffer / Emacs sessions?
Not too hard. Origami builds a data structure by parsing the buffer each time it changes. It compares this data structure to the previous one, works out the differences and then changes the displayed folds accordingly. All that would be needed is to serialize this data structure on killing the buffer etc and then read it back in and apply it when the file is opened.
Is this a feature request or are you thinking of adding this functionality? I can't tell by the way you've phrased the question.
A feature request, but if you're too busy I might take a crack at it (though I'm an elisp novice) On Oct 28, 2015 9:00 PM, "Greg Sexton" [email protected] wrote:
Not too hard. Origami builds a data structure by parsing the buffer each time it changes. It compares this data structure to the previous one, works out the differences and then changes the displayed folds accordingly. All that would be needed is to serialize this data structure on killing the buffer etc and then read it back in and apply it when the file is opened.
Is this a feature request or are you thinking of adding this functionality? I can't tell by the way you've phrased the question.
— Reply to this email directly or view it on GitHub https://github.com/gregsexton/origami.el/issues/19#issuecomment-152069859 .
Honestly, I'm pretty busy with other commitments at the moment. Sounds like a cool feature but it's not likely to make my todo list for a while. Feel free to take a crack. I'll help you out with any questions you have. Do ask before making any major changes or design decisions though. Otherwise you risk me not merging.
Would it suffice to store the buffer-local value origami-history when the file is saved and restore it when loading the file?
(bump)
Yes. That sounds like a good strategy. You'll probably need to reload the history and then apply the latest tree with origami-apply-new-tree. Let me know how it goes! :)
@longouyang saving file-local variables persistently is an interesting problem. If you do find a solution, I'd love to see if it can be applied to other problems.
So I just got a basic solution working in the persist branch of my fork
It recursively serializes the entire history object, converting overlays to lambdas that are later evaluated.
So a history like this:
[([1 2305843009213693951 0 t nil root])
[1 2305843009213693951 0 t
([2 207 32 nil nil #<overlay from 34 to 207 in foo.el>])
root]
nil]
Gets saved as this:
(lambda
(buf)
(vector
(list
(vector 1 2305843009213693951 0 't nil 'root))
(vector 1 2305843009213693951 0 't
(list
(vector 2 207 32 nil nil
(let
((ov
(origami-create-overlay 34 207 0 buf)))
(origami-hide-overlay ov)
ov)))
'root)
nil))
(origami-hide-overlay is only called for hidden nodes)
This needs more testing and some cleaning up but the basic idea seems to work
Oh, and @PythonNut, I think vimish-fold has a completed persistence feature, so you might wanna look at that too.
There seems to be a more generic package dedicated to the problem of making any overlays persistent: https://github.com/mneilly/Emacs-Persistent-Overlays. Should work with hideshow and outline modes out-of-the-box. I couldn't make it work with origami the easy way though. Maybe you guys with deeper understanding of overlays can do it?
Does anyone work on that Issue today?