Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please include instructions on how to use keep-sorted #222

Open
andrewpollock opened this issue Jun 4, 2023 · 3 comments
Open

Please include instructions on how to use keep-sorted #222

andrewpollock opened this issue Jun 4, 2023 · 3 comments

Comments

@andrewpollock
Copy link

I'd like to have https://github.com/google/keep-sorted get invoked whenever I save a file, rather adopt https://pre-commit.com/

Could you include some instructions on how to do so?

@dbarnett
Copy link
Contributor

dbarnett commented Jun 4, 2023

Do you mean to add support for it? I don't see that we have that as a supported formatter.

@andrewpollock
Copy link
Author

@dbarnett I guess so? I figured it was more a case of configuring things to "just do it"?

@malcolmr
Copy link
Member

malcolmr commented Jun 5, 2023

One issue here is that vim-codefmt is largely based on the assumption that a particular filetype has a single formatter that we can invoke to format (on save, or on :FormatCode, etc), while keep-sorted is an addition to (almost) any filetype.

While you can register a keep-sorted formatter yourself (it's not well-documented, but it is supported: you can get the codefmt registry from your own code via maktaba#extension#GetRegistry('codefmt'), and then add your own extension just as in plugin/register.vim), the problem you'll run into is that you'd always need to invoke it manually (i.e. :FormatCode keep-sorted), because :AutoFormatBuffer (to format-on-save) sets the default formatter as 'the' formatter for the buffer, as well as enabling format-on-save.

(Perhaps you could use something like autocmd BufWritePre cpp FormatCode keep-sorted? That's basically what :AutoFormatBuffer does, but it's a bit indirect.)

I think adding good support for something as general as keep-sorted probably requires solving #44 first, so that you configure a chain of formatters for a filetype to run (say) clang-format and then keep-sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants