Atom-beautify: When beautify on save, don't unfold all the current code folds

Created on 6 Oct 2014  路  13Comments  路  Source: Glavin001/atom-beautify

I have, beautify-on-save checked and when I save one of my js files, it unfolds all the code blocks I have folded up so then I have to go back and refold them all. This is by no means a high priority issue, but more something that would be a really nice enhancement to have.

I also understand this might be something completely out of atom-beautifiers control too.

enhancement feature published

Most helpful comment

@Glavin001 Thanks so much! This is awesome! And thanks for not letting this issue die off.

All 13 comments

Will have to do a little research to investigate if that is doable from my end with Atom Beautify. Beautification writes out beautified code to the editor, consequently removing all the un/fold marks and then re-creating them for the new code.

Thanks for bringing this issue to my attention. Hopefully something can be figured out.

May be able to accomplish this in the same way it works currently for cursors (save previous states, and restore after beautify): https://github.com/Glavin001/atom-beautify/blob/master/lib/beautify.coffee#L30-L48

Since the code has the potential to change dramatically, this may not work.

Awesome! Thank you so much for looking into this. Sounds like you have a place to start. Thanks for keeping me updated. I look forward to trying it out if you get it working :)

Upon reflection I think this is something that should be handled inside of Atom. Unfortunately, I am not sure how they will accomplish this, however I suggest that their setText function on the TextEditor somehow diffs the input from the current text state and knows how to properly setup the folds in relatively the same state as before.

I hope that this is something they will support in the future.

something like that occurs with linter-jscs :(

Is there a little update on this? Constantly folding/unfolding does not make a lot of fun.

I would find this feature greatly useful as well.

Dear God, yes please. Have this feature would be a big time saver.

It looks like Atom now supports setTextViaDiff: https://atom.io/docs/api/v1.17.2/TextBuffer#instance-setTextViaDiff

Replace the current buffer contents by applying a diff based on the given text.

This would be our best shot to get this to work -- let Atom deal with the changing of the text and state of the folds.

This would require changing https://github.com/Glavin001/atom-beautify/blob/8ead568182b16bf2aa0086568692ed0d88c823bf/src/beautify.coffee#L120 and testing it out.

Pull Requests very welcome!!

Original (un-beautified)

<!doctype html>
<html>

  <head>
    <title>Test Page</title>
  </head>

  <body>
    <h1>Hello</h1><p>
      World!
    </p>
  </body>

</html>

image

Before (with folds)

image

After

Current Version (setText)

image

Next Version (setTextViaDiff)

It worked! All folds are preserved.

image

And if I manually unfold:

image

Looks good!

Published to v0.29.26

@Glavin001 Thanks so much! This is awesome! And thanks for not letting this issue die off.

Was this page helpful?
0 / 5 - 0 ratings