cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
949 stars 104 forks source link

Add always_dangle_first_parg #252

Open bukepo opened 3 years ago

bukepo commented 3 years ago

This commit adds a new configuration in format so that the first parg can be dangled at the statement line. This is a common style which is also used in CMakeLists.txt of cmake itself.

bukepo commented 3 years ago

The CI is broken.

cheshirekow commented 3 years ago

Looks like maybe a flake8 dependency isn't pinned on CI and got updated. I'll check into it.

cheshirekow commented 3 years ago

If I understand the intent of the feature correctly, is this duplicating the existing always_wrap option? https://cmake-format.readthedocs.io/en/latest/configopts.html#always-wrap

cheshirekow commented 3 years ago

Oh I see, I think you want to make the first argument not wrap (based on the test). So this has been requested dozens of times. As a general rule the "list of commands which" style options are a bit brittle because it leads to different behavior at the top of the tree (statement) than deeper in the tree (e.g. a kwarg) and so leads to a frustrating user experience (I can configure it here, but not there?).

There are some other tricky design considerations for this feature. Instead of requiring it to be enabled "per-statement" my implementation of the feature enables it for any statement where the first positional argument group is "small" (e.g. one or two args). I also considered enabling it if the first positional group would fit in the space available (any number) without wrapping. Would either of those implementations be preferable than what you have provided here?

bukepo commented 3 years ago

I think the main desire is not to wrap the NAME argument. However, the concept doesn't exist in the current model.

And I only want to apply the style to targets related commands, so that we can get a layout very much like a c++ class, where the class name is separated from public/private/protected members.

I like the idea to make such style options available to all nodes in the tree, but only when it's possible to select part of those nodes to apply. Have you considered introducing something like css selector which allows users to apply this style to wanted statements or kwargs?

bukepo commented 3 years ago

@cheshirekow would you mind adding this feature first? We can enhance it to a feature that can be applied to any tree node later. I hope to deploy cmake-format in my projects with this feature.