Benefit from yamlfmt

What happened?

Nothing happened when I saved the file. However, manually invoking +buffer/format makes wonders.

What did you expect to happen?

I would like to format yaml files with yamlfmt when saving. My elisp fu is more or less non-existent so I feel lost. I’m fond of this formatter as it’s possible to specify indentless_arrays, which treats a hyphen (-) as a space = less indentation madness.

Steps to reproduce

  1. go install
  2. Make a configuration file in `~/.config/yamlfmt/.yamlfmt, e.g.,:
  indentless_arrays: true
  retain_line_breaks: true
  1. Favor the new formatter in ~/.doom.d/config.el
(setq-hook! 'yaml-mode-hook +format-with-lsp nil)
(setq-hook! 'yaml-mode +format-with 'yamlfmt)

(after! format-all
  (set-formatter! 'yamlfmt
    '("yamlfmt" "-")
    :modes 'yaml-mode))
  1. Create a simple yaml file:
  - foo: abc
    bar: cde
  - baz: "abz"
  1. Save the file. The desired result would be (without manually calling +buffer/format):
- foo: abc
  bar: cde
- baz: "abz"

System information

Loading data dump...

I’ve tried forking emacs-format-all-the-code and added a yamlfmt formatter myself, and specified the fork as a local repository without it changing the outcome. Does anyone have a solution for how to make this work?

I ended up favoring apheleia (disource discussion) over format-all, added a hook for enabling for yaml mode, and defined my formatting style according to Apheleia’s user guide.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.