:editor format refactor

Okay, this has been dead way longer than I would have liked…

Various things have come up, work, life etc, which for the most part have been resolved now.

In any case; I have pushed an emacs-lisp formatter to my work that if anyone is interested should attempt to use and provide examples of it failing.

I have also asked Henrik to review and potentially have it dogfood doom, so this final PR might end up being huge…

In terms of the other modules, I would ask that if anyone uses one of the languages above on a daily basis and can provide the “best” linter along with sane default arguments (if needed) that would save me having to make guesses and potentially choose a bad formatter :smiley:

Another minor-ish update, I’ve amended the post to clean it up a bit and added a table of contents to make navigating it a bit easier.

It’s also in sync with master as of this commit and refactored to handle the new modulep! macro.

Progress wise the first pass is about half way through having basic module integration, though I have found some missing modules in terms of tooling.

If you’re a user of any module that is crossed out, please do let me know of a working linter/formatter that:

  • Accepts input from stdin
  • Sends output to stdout
  • Can be installed/used as a script/executable or at worst through arguments to a tool

First intended pass is done!

Every module listed above has been actioned in some way now, either included and tested in an isolated case, already included upstream, or crossed out due to lacking tooling support/requiring a domain expert.

Next pass will be spending a bit more time on each module (as well as checking if I’ve missed any modules that make sense to add a formatter for) and then writing install documentation for each module (as well as workarounds for any known issues/weirdness)

As it stands, this is ready for testing by whomever wants to; I’m not an expert on every language so I would have no idea about best practices in most of the modules.

And as above, if you’re a user of any module that is crossed out, please do let me know of a working linter/formatter that:

  • Accepts input from stdin
  • Sends output to stdout
  • Can be installed/used as a script/executable or at worst through arguments to a tool

TL;DR large bulk of the work is done, please test if you can

Upstream does support nix, but it’s the nixfmt formatter which isn’t used very much. The community has not yet agreed on a canonical formatter but AFAIK, nixpkgs-fmt is used far more frequently, so maybe we should add that in here for now?

Thanks for bringing that to my attention!

This is almost certainly a good candidate for an upstream change, so I’ll test it tonight and create an upstream PR (and also make the change in doom so it’s not blocked)

Yea, I’m really not thrilled with the current state of code formatting in Julia. I’m hoping @kiranshila will get some more time to work on julafmt in the future, but for now GitHub - domluna/JuliaFormatter.jl: An opinionated code formatter for Julia. Plot twist - the opinion is your own. seems to be the standard, and it would probably be worth supporting that.

1 Like

That looks like it’s a library though, how would I use that to format a buffer? Is a wrapper script needed or something?

Yea, you’d probably want a wrapper script. https://codeberg.org/FelipeLema/julia-formatter.el seems relevant here.

That starts up a local web service, way more complex than this needs to be and definitely out of scope of apheleia

You can thank Julia’s JIT-AOT compiling + (current) lack of binary caching :crai:

Kiran’s juliafmt would be in rust and hence fine, but it’s still in alpha ATM.

This one looks like a no-for-now then.

Are you able to offer any input on ESS? If you use it :stuck_out_tongue: AFAICT all I need is an R formatter for that one, have a couple but I’m not sure how much that misses out

I haven’t really got any comments on that.

1 Like

Would it be possible to make format-all-mode an alias for apheleia-mode? This would make possible for people to seamlessly transition.

Also, for Go, the formatter also needs to be updated (it uses a Lisp expression).

I don’t understand what you want from this. The package will be replaced with no interaction needed.

Using a list is fine

People may have stuff like (add-hook 'python-mode-hook #'format-all-mode) (as hinted in the documentation). This won’t work anymore as they have to use to apheleia-mode. But maybe this is not worth the trouble.

This is:

  (set-formatter! 'gofmt
    '(("%s" (if (or +format-region-p
                    (not (executable-find "goimports")))
                "gofmt"
              "goimports"))))

This is not handled by the current code (despite the comment of set-formatter! saying otherwise) and apheleia does not know how to handle it either and tries to execute it as is.

I suppose it could be:

  (set-formatter! 'gofmt
    (if (or +format-region-p
                    (not (executable-find "goimports")))
                "gofmt"
              "goimports"))

Can’t imagine why, and yeah it probably is

OK well it’ll be removed anyway since it doesn’t do anything vs upstream