CLion: How to allow for several statements per line?

已回答

Hi there,

 

I often need to have multiple short statements on a single line in my C++ code. Though, code reformatting breaks this one-liner into mutliple lines, one per statement.

I understand this should be best practise, but I intend to keep my code as I want for now.

Also, I sometimes end up with one-liners inline code in .h files describing a class. I tend to avoid such cases as often as possible and to put all code in the .cpp, but in the reported case I do neither want to declare methods or even macros for a transient solution nor to have my one-liner be splitted. This is just transient code, but I want it to be tidy until I can handle the whole thing properly.

In both cases I took time to look for all options in Editor/Code Style/C-C++, but I did not manage to find the proper options. Can anyone help?

Best regards (and happy new year),

 

First request:

c *= pi; d = c+x*pi; e = /* blah */ ;

=> is split against my will to:

c *= pi;

d = c+x*pi;

e = /* blah */ ;

 

Second request:

void on_comboBoxV2Selection(int i) { comboBoxVolumeSelectionExecute(2, i); }
void on_comboBoxV3Selection(int i) { comboBoxVolumeSelectionExecute(3, i); }
void on_comboBoxV4Selection(int i) { comboBoxVolumeSelectionExecute(4, i); }

=>

void on_comboBoxV2Selection(int i)

{ comboBoxVolumeSelectionExecute(2, i); }

0

Hello!

For the first request I've created https://youtrack.jetbrains.com/issue/CPP-15091, feel free to comment or upvote in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

For the second request please try enabling File | Settings | Editor | Code Style | C/C++ > Wrapping and Braces > Keep when reformatting > Simple functions in one line.

0

Thank you very much!

Though, for request 2, the option was already selected.

When unselected, it gives:

void on_comboBoxV2Selection(int i)

{

   comboBoxVolumeSelectionExecute(2, i);

}

instead of:

void on_comboBoxV2Selection(int i)

{ comboBoxVolumeSelectionExecute(2, i); }

when I would have expected:

void on_comboBoxV2Selection(int i) {comboBoxVolumeSelectionExecute(2, i);}

I would like to get rid of the line break, even though 1 is better than 3!

 

Best regards,

1

请先登录再写评论。