NOTE: The package is actively maintained but due to lack of time, complex tasks are done at a slow pace. Simple tasks like adding or fixing formatter definitions are often done immediately. For faster progress, additional maintainers are welcome.
Lets you auto-format source code in many languages using the same command for all languages, instead of learning a different Emacs package and formatting command for each language.
Just do M-x format-all-buffer
and it will try its best to do the
right thing. To auto-format code on save, use the minor mode
format-all-mode
. Please see the documentation for that function for
instructions.
- Angular/Vue (prettier)
- Assembly (asmfmt)
- ATS (atsfmt)
- Bazel Starlark (buildifier)
- BibTeX (Emacs)
- C/C++/Objective-C (clang-format, astyle)
- C# (clang-format, astyle)
- Cabal (cabal-fmt)
- Clojure/ClojureScript (node-cljfmt)
- CMake (cmake-format)
- Crystal (crystal tool format)
- CSS/Less/SCSS (prettier)
- D (dfmt)
- Dart (dartfmt)
- Dhall (dhall format)
- Dockerfile (dockfmt)
- Elixir (mix format)
- Elm (elm-format)
- Emacs Lisp (Emacs)
- Fish Shell (fish_indent)
- Fortran 90 (fprettify)
- Gleam (gleam format)
- GLSL (clang-format)
- Go (gofmt, goimports)
- GraphQL (prettier)
- Haskell (brittany, hindent, ormolu, stylish-haskell)
- HTML/XHTML/XML (tidy)
- Java (clang-format, astyle)
- JavaScript/JSON/JSX (prettier, standard)
- Jsonnet (jsonnetfmt)
- Kotlin (ktlint)
- LaTeX (latexindent)
- Ledger (ledger-mode)
- Lua (lua-fmt, prettier plugin-lua)
- Markdown (prettier)
- Nix (nixpkgs-fmt, nixfmt)
- OCaml (ocp-indent)
- Perl (perltidy)
- PHP (prettier plugin-php)
- Protocol Buffers (clang-format)
- PureScript (purty)
- Python (black, yapf)
- R (styler)
- Reason (bsrefmt)
- ReScript (resfmt)
- Ruby (rufo)
- Rust (rustfmt)
- Scala (scalafmt)
- Shell script (beautysh, shfmt)
- Snakemake (snakefmt)
- Solidity (prettier-plugin-solidity)
- SQL (pgformatter, sqlformat)
- Swift (swiftformat)
- Terraform (terraform fmt)
- TOML (prettier-plugin-toml)
- TypeScript/TSX (prettier)
- Verilog (iStyle)
- YAML (prettier)
From MELPA
You will need to install external programs to do the formatting. If
format-all-buffer
can't find the right program, it will try to tell
you how to install it.
If you have installed a formatter but Emacs cannot find it, Emacs may
be using a PATH
different from your shell. The path searched by
Emacs is in the exec-path
variable. You can easily make it match
your shell's PATH
using the
exec-path-from-shell
package from MELPA.
M-x customize-group format-all
has a few basic settings.
However, the main thing you probably want to set is
format-all-formatters
. That variable is buffer-local, and can be
made project-local by setting it in a .dir-locals.el
file in a
project's directory. That file can be committed to version control to
share it with the whole project.
To enable format on save for most programming language buffers:
(add-hook 'prog-mode-hook 'format-all-mode)
.
The command format-all-ensure-formatter
will ensure that a default
formatter is selected in case you don't have one set; you can
customize the default formatter for each language. To ensure a
formatter is set whenever you enable format-all-mode
, you can use:
(add-hook 'format-all-mode-hook 'format-all-ensure-formatter)
.
Additionally, many of the external formatters support configuration files in the source code directory to control their formatting. Please see the documentation for each formatter.
New external formatters can be added easily if they can read code from standard input and format it to standard output. Feel free to submit a pull request or ask for help in GitHub issues.
GitHub issues are preferred. Email is also ok.
Feature requests are welcome. If you are interested in doing anything beyond adding new formatters in the current framework, please discuss in issues before writing code.
atom-beautify sports a very impressive set of formatters. We should aspire to that level of coverage for Emacs.
Unibeautify is a project to provide one shell command to run all beautifiers. atom-beautify will be rewritten to be based on it. Perhaps we should be too, once it stabilizes.