emacs-format-all-the-code icon indicating copy to clipboard operation
emacs-format-all-the-code copied to clipboard

Missing languages/formatters

Open lassik opened this issue 6 years ago • 35 comments

Common Lisp

  • I think the CL community usually uses Slime autoindent in Emacs
  • https://github.com/russellw/lisp-format

Scheme - https://github.com/russellw/scheme-format/ how easy is this to install?

Julia - https://github.com/invenia/JuliaFormat.jl

Erlang - erl_tidy with suitable command line adapter?

Scala

  • https://github.com/scala-ide/scalariform
  • https://github.com/scalameta/scalafmt

F# - https://github.com/fsprojects/fantomas

C# - https://github.com/dotnet/codeformatter

Tcl - ??

Awk - ??

R

  • https://cran.r-project.org/web/packages/formatR/index.html
  • https://cran.r-project.org/web/packages/styler/index.html
  • https://github.com/google/rfmt

MATLAB/Octave - https://github.com/davidvarga/MBeautifier

Pascal/Delphi

  • http://jedicodeformat.sourceforge.net/
  • https://github.com/minyoad/DelForEx
  • http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Formatter.EXE,_the_Command_Line_Formatter

Basic/Visual Basic - ??

CoffeeScript - https://www.npmjs.com/package/coffee-formatter

PureScript - https://gitlab.com/joneshf/purty/issues/43

Groovy - https://github.com/diffplug/spotless

lassik avatar May 04 '18 20:05 lassik

For elixir (1.6), see https://hexdocs.pm/mix/Mix.Tasks.Format.html It does say

If any of the files is -, then the output is read from stdin and written to stdout.

mandarvaze avatar Jun 08 '18 14:06 mandarvaze

Thanks! Now added in commit f3e920f

Do you know of a formatter for plain old Erlang?

lassik avatar Jun 08 '18 15:06 lassik

Added Kotlin support using ktlint in cee0eea. The formatter works kinda weird (doesn't fix some obviously bad spacing, etc.) but I think it's supposed to be like that.

lassik avatar Jun 08 '18 16:06 lassik

Quick google search got me https://github.com/fenollp/erlang-formatter (seems to be active)

I personally don't use Erlang - so can't comment more.

mandarvaze avatar Jun 08 '18 16:06 mandarvaze

It seems that the Erlang community has these solutions:

  • Run Emacs as a batch job (https://github.com/fenollp/erlang-formatter)
  • Run Vim as a batch job (https://github.com/vim-erlang/vim-erlang-runtime)
  • Run the standard erl_tidy module using an adapter:
    • https://github.com/mbucc/erlfmt
    • https://github.com/fenollp/erlang-formatter/blob/master/test/before/erl_tidy.escript
    • https://github.com/tsloughter/erl_tidy (rebar3 plugin)

I guess erl_tidy would be the way to go. Depending on a text editor to do the formatting is iffy, IMHO (even if it's Emacs). Editors are heavy dependencies and not really built for the task. The formatter used by format-all should be one that people can use just as well in Continuous Integration builds, etc.

I'll wait for someone who actually uses Erlang to confirm that erl_tidy is a sound choice, and which adapter to use (I have no idea what build tools, etc., the Erlang community uses..)

lassik avatar Jun 09 '18 19:06 lassik

Added SQL support using the sqlformat command from the Python sqlparse package. #11

lassik avatar Jul 02 '18 08:07 lassik

Added Java support using clang-format in commit be066888

lassik avatar Jul 18 '18 23:07 lassik

Added HTML/XHTML/XML support using HTML Tidy in commit 6b0bd2f

HTML Tidy ships with some operating systems. A modern version supporting HTML5 can be found at http://www.html-tidy.org/ The shell command should be tidy in both cases.

lassik avatar Jul 22 '18 09:07 lassik

Added YAML support using yq in commit 5688767

lassik avatar Jul 23 '18 09:07 lassik

Added Crystal support using crystal tool format in commit 4bfac6f

lassik avatar Jul 27 '18 15:07 lassik

Assed assembly language support using asmfmt in commit cbf665f

lassik avatar Aug 16 '18 11:08 lassik

Support for formatting haskell with brittany would be nice. It's the current state of the art, and integrated into, e.g., the haskell IDE engine. I can make a PR myself if I get some time soon!

patrl avatar Sep 15 '18 12:09 patrl

Thanks for chiming in :)

We thought a lot about how to do configuration for format-all and came to the conclusion that it's best to leave configurable formatting to Unibeautify (I'm working on Emacs support). So the primary goal of format-all now is to support the main "anti-bikeshedding" formatter for each language (i.e. one that always formats to a rigid style and doesn't allow configuration). Things like gofmt for Go or black for Python are good examples.

I skimmed brittany's readme and it looks like a good fit. If it's on track to become the de facto standard (anti-bikeshedding) formatter for Haskell, and produces output roughly like hindent but better, then we could simply switch from hindent to brittany.

lassik avatar Sep 15 '18 13:09 lassik

Ah, it's interesting to know the direction the project is heading in. Thank you by the way for this excellent project, it helps a lot with removing cruft from dotemacs.

There's some recent discussion on reddit, where the consensus seems to be that brittany is where it's at right now. It's worth noting btw that both hindent and brittany do allow custom configuration via yaml, so neither are completely rigid. I don't know of such a formatter for haskell.

patrl avatar Sep 15 '18 15:09 patrl

Thanks for the kind words, glad to hear it's useful :)

That Reddit thread sounds convincing too, so I switched Haskell from hindent to brittany. It works really well, so that was a 2 minute job :D Commit 97e6f7d

lassik avatar Sep 20 '18 17:09 lassik

BTW, if you happen to know a Haskeller who's also good at Node JS, Unibeautify doesn't yet have any Haskell formatter :)

lassik avatar Sep 20 '18 17:09 lassik

Oh awesome, thank you!!

patrl avatar Sep 22 '18 13:09 patrl

Clojure

  • cljfmt is most popular. Clojure/JVM startup is slow, so there are two ports to speed it up:
    • https://github.com/snoe/node-cljfmt
    • https://gitlab.com/konrad.mrozek/cljfmt-graalvm

Added Clojure/ClojureScript support using cljfmt in commit 666e1bc

lassik avatar Oct 30 '18 11:10 lassik

Golang can alternatively format with goimports, when using go-mode you can specify this via the custom variable gofmt-command.

terlar avatar Nov 10 '18 14:11 terlar

I experimented on supporting multiple formatters per language last week and almost got it done. I'll gather the energy to finish it ASAP. Got some pending Unibeautify work that would need attention as well. Most of my effort has gone into other things lately.

lassik avatar Nov 22 '18 15:11 lassik

Groovy would be great, so i can format gradle build files. :)

birdayz avatar Dec 07 '18 11:12 birdayz

This should work: https://github.com/diffplug/spotless Pull requests welcome ;) I can also try to add it at some point.

lassik avatar Dec 07 '18 11:12 lassik

Lua

  • https://github.com/trixnz/lua-fmt
  • https://github.com/denglf/FormatLua
  • https://github.com/LuaDevelopmentTools/luaformatter

@ellakk added Lua support using lua-fmt in commit 87c7a43. Thanks!

lassik avatar Dec 07 '18 20:12 lassik

Added Dhall support using dhall format in commit 217aea7.

lassik avatar Jan 25 '19 08:01 lassik

Added Dart support using dartfmt in commit 3f6dd7d

lassik avatar Jan 25 '19 09:01 lassik

PHP

  • https://prettier.io/ work in progress
  • https://github.com/FriendsOfPHP/PHP-CS-Fixer
  • https://github.com/squizlabs/PHP_CodeSniffer

@tangxinfa added support using prettier in commit 4029309. Thanks!

lassik avatar Jun 05 '19 09:06 lassik

I'm sorry IDK if I should post this here but I'll do it anyways.

For C# I suggest you check out: https://github.com/OmniSharp/omnisharp-emacs There is this little formatter function in that, the very same one that VCS uses apparently for C# (just guessing). It comes with Doom Emacs for csharp lang. On top of that it's independent from Dotnet. The functions of interest are omnisharp-code-format-entire-file and omnisharp-code-format-region. I tried to use set-formatter! but being a novice couldn't get it to work I guess that's because it's not a THUNK or something.

Anyways yeah, that would be a great addition.

Davoodeh avatar Dec 19 '20 19:12 Davoodeh

@Davoodeh Try M-x eval-expression (format-all--buffer-native 'csharp-mode 'omnisharp-code-format-entire-file). Does that work? If it does, we can package it into a formatter definition.

lassik avatar Dec 19 '20 19:12 lassik

No luck (probably due to my lack of understanding from Lisp and debugging it). I am probably not a good candidate to continue this convo with xD Couldn't find a workaround and also have no idea how this server works. Evaluation returns an error relating to OmniSharp. I suppose it's about a function that puts the cursor where it was before but just blindly guessing based on the words.

P.S: yeah it's independent from dotnet-sdk.

omnisharp--handle-server-response-packet error: 
(wrong-type-argument char-or-string-p nil).

Tried to handle this packet: ((Request_seq . 3) (Command . "/codeformat") (Running . t) (Success . t) (Message) (Body) (Seq . 497) (Type . "response"))

This can mean an error in the handler function: #[257 "\301\302"A\303\300\304 \305 $\207" [nil assoc Buffer omnisharp--set-buffer-contents-to line-number-at-pos omnisharp--current-column] 7 "

(fn INPUT0)"] [2 times] (t "")

Davoodeh avatar Dec 19 '20 21:12 Davoodeh

HyLang is missing as well.

Edit: Sorry, I put this in details since I'm not sure if it is correct or even if it's caused by the package.

Since it's a Lisp it works almost perfectly with 'emacs-lisp formatter which I managed to enable with (setq-hook! 'hy-mode-hook +format-with 'emacs-lisp) in my Doom. The only problem that it has is miss-treating {} as characters rather than brackets (like other brackets ()[]). for example:

{a b
 c d}
; formats to this which ruins the style and confuses Parinfer
{a b
c d}

Davoodeh avatar Dec 30 '20 20:12 Davoodeh