C brace position/style


#1

I guess this is more of a C coding style issue. Probably a bit of stupidity too. If I’m coding a snippet like this


static void close_filed(struct filed *f)
{

    if (f == NULL || f->f_file == -1)
    {
        return;
    }

    switch (f->f_type) 
    {
        case F_FILE:
        case F_TTY:
        case F_CONSOLE:
        case F_FORW:
            f->f_type = F_UNUSED;
        break;
    
        case F_PIPE:
            f->fu_pipe_pid = 0;
        break;
    }
    (void)close(f->f_file);
    f->f_file = -1;
}

I want the editor to put the braces where they appear and the break statement in line with the case so the block is documented.

The brace only seems broken when I’m trying to fix existing code, say,

[code]
if (f == NULL || f->f_file == -1)
return;

[code]

When I put my cursor at the end of the if line and hit return the first brace goes where it should, but if I don’t indent the return before adding the next brace it goes against the left margin.

Is there a method of fixing this which doesn’t involve hacking a bunch of files which will be overwritten with an update?

Thanks


#2

Please add a little bit of detail. Precisely how does the code look at the beginning, what do you want it to look like, and how does it actually end up? Pictures are preferred over words.


#3

I provided the exact detail. I want the code to look just like the example. That is the picture.


#4

If you’re talking about a pet peeve with how Atom indents text, I need to see a screenshot in order to see where your cursor position is and how things are indented. Based on exactly what’s happening, I can tell you what interaction is going on and potentially how to make things easier on yourself.


#5

I made things easier by switching to KATE.

It worked perfectly out of the box. At some point I might have another project where Atom could be tried on.

As much as I hate the 50,000 pound Eclipse, it actually has a really nice setup which doesn’t require hacking of config files to establish and enforce a C/C++ coding style.

One just has to endure those glacial load times and the unbelievable memory footprint.

Thank you for your time.

I tried Atom once before and it wasn’t ready for prime time then either. Actually 3 of us tried using it on the project we were working on and we all un-installed it. At some point it will stabilize and be a fine addition to the tool set. Just hasn’t gotten there yet.


#6

If the requirement to hack on config files to get things just the way you want them makes an editor not “ready for prime time”, then Atom will never be there. It’s not supposed to be Eclipse or NetBeans or IntelliJ or any of the others. It is first and foremost a platform on which an infinite variety of editor environments can be constructed, and the developers have no interest in enforcing specific code styles due to said styles being preference-based and language-specific. Atom has a lot of tools to allow users and package developers to set whatever style rules we want, and for people who like having their editors be massively configurable, Atom’s lack of opinions is an asset.