Smarter replacement for coreutils' fmt

The wrapping section of the wiki recommends using fmt from coreutils to format paragraphs, which works fine but fails to properly indent text such as Doxygen comments unless you specify the correct --prefix option somehow.

There are several ways to fix this of course, but for me, the easiest solution was to write a “smarter” fmt clone.

It’s a drop-in replacement written in Python with no dependencies, so all you have to do is to use:

map global normal = '|dfmt -w $kak_opt_autowrap_column<ret>'

in your kakrc.

Hope you’ll find it useful!

2 Likes

I’ve long hoped somebody would write a tool like this! Thanks!

Since the tool has no dependencies, how difficult would it be to make it available in a way that can be run directly from the git checkout without any install process? pipx is pretty easy to use, but adding your repo as a submodule to my dotfiles repo would be even easier.

Also, one nice thing that Vim’s gq does is it’s smart about nested quoting. If I have text like:

> > Some kind of very long text
> > that's being quoted by somebody else.
>
> Inline commentary by a third party
> which also wraps onto multiple lines

…then a lot of tools don’t recognise the nested quoting and will produce something like:

> > Some kind of very long text > that's
> being quoted by somebody else.
>
> Inline commentary by a third party which
> also wraps onto multiple lines

I don’t think your tool currently supports wrapping >-prefixed lines at all (so I can’t easily test it myself) but if it did, would it support nesting them?

Since the tool has no dependencies, how difficult would it be to make it available in a way that can be run directly from the git checkout without any install process

Not very hard, but if I ever need to add an external dependency, pipx will still work but the submodule will break …

I don’t think your tool currently supports wrapping > -prefixed lines at al

Nope, but the patch is trivial

would it support nesting them?

I don’t think so. I’ll open an issue on GitHub.

Thanks for the feedback :wink: