syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.56k stars 4.9k forks source link

Suggestion: Migrate to a better formatter like apheleia instead of srefactor #16412

Closed maikol-solis closed 2 weeks ago

maikol-solis commented 1 month ago

Hi!

apheleia (https://github.com/radian-software/apheleia) provides a better and stable way to format buffers. I have issues with srefactor because it doesn't format correctly my init.el.

For example, something like

   (latex :variables latex-backend 'lsp 
                     latex-refresh-preview t 
                     latex-enable-auto-fill nil latex-enable-folding t 
                     latex-enable-magic t)

is formatted like

   (latex :variables latex-backend'lsp latex-refresh-preview
          t latex-enable-auto-fill nil latex-enable-folding
          t latex-enable-magic t)

Best.

smile13241324 commented 1 month ago

You are right, I am actually using evil-indent all the time except in lsp managed buffers where this is handled by the lsp entirely, so I haven't noticed yet.

Lets see how the other package performs.

smile13241324 commented 1 month ago

Hmm this doesn't look like a drop in replacement different layers have different formatting functions in place so we cannot use the global config instead we have to configure this in more detail for our own, not to interfere with the existing infrastructure.

I may have a look into this when I find the time if nobody else wants to tackle this in the meantime.

smile13241324 commented 2 weeks ago

I have had a look into apheleia unfortunately this is only a controller for formatters it does not provide concrete formatter implementations except some sample ones for php, js and go.

While such a system is nice I would not focus on modernizing it as all newer modes move to LSP servers anyway which handle the formatting on a much more efficient manner outside of emacs. Legacy modes can work with srefactor as long as they are maintained.

One of the big exceptions there is elisp, here however I have not seen a suitable formatter for this yet. For now I have added an additional binding for SPC m = = which will format the buffer using core functions which use evil-indent internally. This gives reasonable results.

Now all elisp buffers are formatted on save by default just like in go. This should also make reviewing code change easier.

If you have found a suitable external formatter for elisp feel free to open a PR or feature ticket for it, until we have one we are using the internal one.