Author Topic: c++11/17 and beautify of Pro 2016/2017 Beta  (Read 171 times)

millerkp

  • Community Member
  • Posts: 16
  • Hero Points: 0
c++11/17 and beautify of Pro 2016/2017 Beta
« on: October 10, 2017, 02:52:30 am »
It may seem a little picky, but for me, there is nothing more annoying then running a beautifier and having it mess up the formatting of just one junk of code.  If it was really bad, I just wouldn't use it.  But when it is just sooooooo close, I end up spending a lot of time trying to fix it.  You could argue that I am lazy programmer/poor typist; which I admit to at least one.

Take the code sample below.  I was playing with C++11's uniform initialization syntax, which allows for the initialization of struct members from the constructor parameters.  Cool right?  How c/c++ has grown.

Beautify seems to be treating the UIS as a normal member initialization and a code block.  I even downloaded the 2017 RC4  to see if this had been considered; it does not seem so.

There are a lot of knobs, so maybe I am just missing something.  Thought I would put this note out there and see what comes back.

Thank you,

K. Miller

Before beautify (yes, the poor indentation is intentional) :
#include <iostream>

class test
{
public:
test(int a, int b, int c) :
p {a, b, c, 0}
{
}

private:
struct {
int a, b, c, d;
} p;

public:
void output(void)
{
  std::cout << p.a << " " << p.b << " " << p.c << " " << p.d << std::endl;
}

};

main()
{
test t1(5,4,3);
t1.output();
}

After beautify:
#include <iostream>

class test
{
public:
    test(int a, int b, int c) :
        p
    {
        a, b, c, 0
    }
    {
    }

private:
    struct
    {
        int a, b, c, d;
    } p;

public:
    void output(void)
    {
        std::cout << p.a << " " << p.b << " " << p.c << " " << p.d << std::endl;
    }

};

main()
{
    test t1(5, 4, 3);
    t1.output();
}

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 785
  • Hero Points: 41
Re: c++11/17 and beautify of Pro 2016/2017 Beta
« Reply #1 on: October 10, 2017, 03:58:37 pm »
Looks like a bug to me.  Initially I tried it with the default profile in 2017 rc4, and that looks fine, but changing to profiles with different brace styles caused some different flavors of wrong formatting. 

Also, for me, it's just for the uniform initialization syntax inside of a constructor initialization list that's wrong.  Uniform initialization in a local inside of a function doesn't get mangled. 

I'm looking into it.  The fix probably won't make it into the v22 release, but would be in the subsequent v22 point release.

millerkp

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: c++11/17 and beautify of Pro 2016/2017 Beta
« Reply #2 on: October 10, 2017, 06:36:53 pm »
OK.  Sounds good as far as that goes.

More and more multi national projects are relying on formatters like clang-format and indent.  Some even have them built into the version control system or worse just checkers that fail the commit on invalid formatting.  It would be nice to be able to completely turn off formatting ie. no automatic indenting/spacing/code completion.  Even better would be allowing for a third party formatter plug-in on (should just be a simple system call).

Thank you,

K. Miller

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 785
  • Hero Points: 41
Re: c++11/17 and beautify of Pro 2016/2017 Beta
« Reply #3 on: October 10, 2017, 07:20:09 pm »
You can turn off the editing features that try to be smart, but there's not a single switch you can throw to turn everything off. (we do have a feature request for that though).  Each feature has it's own setting that needs to be disabled, so it takes some legwork to get everything to quiet down.

As for third party formatters, if they can read from stdin, and write formatted results to stdout, it's pretty easy to make a command that you can bind to a key to quickly format the buffer.

This is an example I copied from a post about the 'astyle' formatter, only the filter_command() parameter would need to change for a different formatter.  Save this to a .e file, "load" it from the slickedit command line, and then the "reformat_buffer" command should be available to run, or bind to a keypress, menu, or toolbar button.

Code: [Select]
#include "slick.sh"
#import "fileman.e"
#import "util.e"

_command void reformat_buffer() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
   _save_pos2(auto saved);
   select_all();
   filter_command('astyle --style=allman');
   _restore_pos2(saved);
}

millerkp

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: c++11/17 and beautify of Pro 2016/2017 Beta
« Reply #4 on: October 11, 2017, 02:08:19 am »
Thank you, that did the trick.  I knew there was a reason I love slickedit!

K. Miller