nvimdev / guard.nvim

async fast minimalist plugin make format easy in neovim
MIT License
448 stars 24 forks source link

clang-format formatting based on global vim settings #168

Open xavier7179 opened 19 hours ago

xavier7179 commented 19 hours ago

Feature description

I was wondering if there is a way to configure clang-format so that it looks for the file first, and, if not present, it does not only apply a preferred style but also sets indentation and tabs vs. space for Vim configurations? If so, could you make an example in the documentation?

xiaoshihou514 commented 17 hours ago

"File not present", meaning this is a temp buffer that's not saved yet?

xavier7179 commented 16 hours ago

I apologize. I needed clarification in the first place. I was referring to the -style=file option, which makes the command search for a .clang-format file (making it possible to have project-specific formatting rules)

xiaoshihou514 commented 16 hours ago

I think that's the default behavior given that the cwd is correct (:pwd)

xavier7179 commented 14 hours ago

Yes, indeed it is. Nevertheless, the style accepts a list of options that follow the file content structure. Unfortunately, there is no example of how to set them (and re-use the values of indents and tabs vs spaces that you can set with vim). Moreover, the command accepts a --fallback-style=<string> option that should fall back to a specific style when the file is missing. Although useful, <string> can only be a default style and not a more complex configuration as in the -style version. Thus, I was wondering if your plugin can handle it using an algorithmic approach...

xiaoshihou514 commented 11 hours ago

I guess I can create an example... That might take a while. Note that ft("foo"):fmt can take a function, check out the tests. https://github.com/nvimdev/guard.nvim/blob/cc8df48248eb795b71be21f7a30f08fc47a2c22d/spec/format_spec.lua#L71 If you managed to achieve what you wanted I am just going to put your solution as an example :)