10

With Artistic Style code formatter, how do I achieve the opposite of --break-after-logical / -xL such that if I have...

if (thisVariable1 == thatVariable1
        || thisVariable2 == thatVariable2
        || thisVariable3 == thatVariable3)
    ...

...I get...

if (thisVariable1 == thatVariable1 || thisVariable2 == thatVariable2 || thisVariable3 == thatVariable3)
    ...
MD XF
  • 7,860
  • 7
  • 40
  • 71
puk
  • 16,318
  • 29
  • 119
  • 199
  • 12
    @CloseVoter: If a code beautifier doesn't fall into the category of "tools used primarily for programming", then I don't know what possibly could. – Ben Voigt Dec 16 '13 at 20:34
  • From reading the documentation: possibly `--unpad-paren / -U`? – Jongware Dec 16 '13 at 22:56
  • @Jongware just tried it and it did not work (nice idea though). – puk Dec 16 '13 at 23:06
  • I browsed the doc for commands containing `merge` or `join` and it seems this beautifier doesn't merge existing lines at all. Is that correct? – Jongware Dec 16 '13 at 23:10
  • @Jongware I guess multiline processing is beyond this beautifiers capabilities – puk Dec 16 '13 at 23:14
  • Is your code editor capable of a decent GREP? In TextWrangler, this should work: `\s+(?=\|\|)`, replace with a single space. (Assuming your `\s` picks up newlines as well, I believe it does in TW.) – Jongware Dec 16 '13 at 23:17
  • @Jongware yes I know I *could* do that --and thank you btw-- but I don't know whether I am ready to go down that road (ie. go through the entire C/C++ language specification) – puk Dec 16 '13 at 23:26
  • Personally I'm in favor of multi-line stuff like this that improves readability. However, in the spirit of answering the original question: you could remove all line breaks and re-format the code. If you only want to change specific things: Clang (and probably gcc) can generate an abstract syntax tree for your code; you should be able to parse it to look for multi-line if statements. Assuming Artistic Style supports it, just feed it the line range you want reformatted. – Brian Vandenberg Jul 22 '15 at 15:08

1 Answers1

5

Artistic style doesn't appear to make this possible.

That's quite sensible, since it actually obfuscates the code :

  • Vertical alignment improve legibility by emphasizing identical pattern, and distinct patterns as well (a single != would be harder to spot in a one-liner).
  • It also eases diff tracking.

I would actually write :

if  (  thisVariable1   == thatVariable1
    || thisVariable2   == thatVariable2
    || longerVariable3 == thatVariable3 )
    ...
YvesgereY
  • 3,778
  • 1
  • 20
  • 19