auto indentation in C/C++

auto indentation in C/C++

dodger57

    Jun 20, 2005#1

    How can I have braces automaticaly indented like this:

    Code: Select all

    if(whatever)
    {
    ....
    }
    instead of:

    Code: Select all

    if (whatever)
       {
             ....
       }

    6,616548
    Grand MasterGrand Master
    6,616548

      Jun 22, 2005#2

      Open your wordfile (Advanced - Configuration - Syntax Highlighting - button Open).

      Go to the appropriate language definition (in standard wordfile.txt it is /L1 for C/C++).

      Go to the line /Indent Strings = "{" "if" "else" ":"

      Delete "if" and "else".

      Save the wordfile. Now you get indent working as you want.
      Best regards from an UC/UE/UES for Windows user from Austria

      dodger57
      dodger57

        Jun 22, 2005#3

        I guess I will have to do that for all ctrl statements (for, while, do, etc).

        Why does it indent to that position? Isn't there a mechanism to tell ultraedit that the style I want is that?

        Other editors simply have indentation styles (emacs) you set it for, lets say, C++ or K&R or whatever and it will follow that style.

        Wouldn't it be great if UE could also be configured for that? After all, what if you participate in open source projects? They have different styles, companies have different styles too, I have my own style, etc.

        Even better, it would be great if UE could open any source file in the indentation stayl of my choosing, but preserve or save the file in the style I select when saving.

        6,616548
        Grand MasterGrand Master
        6,616548

          Jun 22, 2005#4

          The indent width can be individually specified based on the file extension at Advanced - Configuration - Edit. See help of UE for details.

          /Indent Strings = and /Unindent Strings = in the wordfile defines the strings, where un/indent should be executed.

          UE is a GENERAL text editor, so it does support indentation not only for C/C++.

          Automatically find out, which indent width the writer has used? Write this program code and I send you 10 files from my colleagues, where your code will fail to find the correct width, because the don't work with auto-indentation.
          Best regards from an UC/UE/UES for Windows user from Austria

          dodger57
          dodger57

            Jun 22, 2005#5

            The problem I am seeing with UE is that it indents C/C++ based on the assumption that open braces follow, in the same line, the control sentence it is opened for, for example:

            Code: Select all

            while(this) {
                ....
                if (whatever) {
                    ...
                }
                ...
            }
            
            Emacs, which is also a general editor, behaves the same if using the default c-mode, however if you set the style for, let's say, C++, it will respect not indenting the open brace (when it is positioned in the next line) so it will put it right below the previous indentation level.

            it would be nice if I could specify my style somehow. This is what I meant by using default styles for opening and saving files, is that you could reformat the whole file when oppened to your taste. Then save it with potientialy a different style (you would have to say which one).

            All this could be configurable. I was just thinking about how nice it would be.