uncrustify / uncrustify

Code beautifier
http://uncrustify.sourceforge.net/
GNU General Public License v2.0
2.87k stars 565 forks source link

Need more features on parameter packages #4317

Open imotosaiko opened 5 months ago

imotosaiko commented 5 months ago

First of all, a big thank you to the developers involved in uncrustify!

I've recently been learning and applying uncrustify to a project I'm involved in (C++), and I've noticed that uncrustify doesn't seem to have the same level of detail in regulating the format of parameter packs as it does in other areas.

  1. Lack of option to control the space between the ellipsis and the reference(or pointer).(Edited: After being reminded by the developer, this is just due to me not reading the configuration options carefully)

Simple example:

Source code:

template <typename ...ARG>
void func(ARG && ... args)
{}

Expected result:

template <typename ...ARG>
void func(ARG&&... args)
{}
  1. Lack of options to control space between ellipses and formal parameters(or a word, I looked at debug.txt and found that it was recognized as a word).

Using the same code as above, the expected result:

template <typename ...ARG>
void func(ARG &&...args)
{}

If any of the above is just a dumb thing to do due to my ignorance, please point it out! Thanks to all.

PoeticPete commented 5 months ago

Hi @imotosaiko! This cfg will handle case 1:

# Add or remove space before a reference sign '&'.
sp_before_byref                 = remove   # ignore/add/remove/force

# Add or remove space between '&&' and '...'.
sp_byref_ellipsis               = remove   # ignore/add/remove/force

# Whether to collapse empty blocks between '{' and '}' for functions only.
# If true, overrides nl_inside_empty_func.
nl_collapse_empty_body_functions = true    # true/false

I think you're right about case 2. sp_byref_ellipsis will remove the space, but I don't see any options to control the space between ellipses and parameter.

imotosaiko commented 5 months ago

Hi @imotosaiko! This cfg will handle case 1:

# Add or remove space before a reference sign '&'.
sp_before_byref                 = remove   # ignore/add/remove/force

# Add or remove space between '&&' and '...'.
sp_byref_ellipsis               = remove   # ignore/add/remove/force

# Whether to collapse empty blocks between '{' and '}' for functions only.
# If true, overrides nl_inside_empty_func.
nl_collapse_empty_body_functions = true    # true/false

I think you're right about case 2. sp_byref_ellipsis will remove the space, but I don't see any options to control the space between ellipses and parameter.

Thank you, this is very helpful to me.