How to configure indenting of C/C++ code?

How to configure indenting of C/C++ code?

5
NewbieNewbie
5

    Feb 22, 2006#1

    Hello,

    I am trying to move to UltraEdit from jedit (it's slow), and I'm having trouble getting indentation to work in a way that is like the default in most other editors. I want my c code to look like this:

    Code: Select all

       while(total_bytes < message_size)
        {
        if((received_bytes = recv(sockfd, message + total_bytes, 
        sizeof(char) * (message_size - total_bytes), 0)) 
        == -1)
        {
        sprintf(errstr, "Could not recieve\n");
        perror(errstr);
        free(message);
        exit(1);
        }
        else
        {
        if(received_bytes == 0)
        {
        // connection terminated ... exit
        printf("Connection Lost\n");
        exit(0);
        }
     
        total_bytes += received_bytes;
        printf("Received So Far: %d\n", total_bytes);
        }
        
        }
    
    What do I need to do?

    6,686585
    Grand MasterGrand Master
    6,686585

      Re: indenting in c code

      Feb 22, 2006#2

      Open Advanced - Settings or Configuration - Word Wrap / Tab Settings.

      Click on button Change List, enter in the edit field c h  - extensions only without point and with a space as separator and press button Add. Close the dialog with OK.

      Now select the entry c h in the drop down list.

      Set or do not set Use spaces in place of tabs, enter the Tab Stop Value and the value for Indent Spaces. The UltraEdit help available by pressing the Help button should give you further infos.

      Click button Apply and then goto Editor Display - Syntax Highlighting.

      Check that syntax highlighting is enabled and there is a syntax highlighting language definition for C/C++.

      Open the wordfile by pressing button Open and close the configuration dialog with OK or Cancel.

      If you use standard wordfile.txt you should see in the first line /L1"C/C++".
      Update: On newer version of UltraEdit the opened wordfile is c_cplusplus.uew.

      A few lines below you will see following lines:

      Code: Select all

      /Indent Strings = "{" "if" "else" ":"
      /Unindent Strings = "}"
      According to your example you should delete all indent strings except "{". Save the wordfile and indention should work like you want it.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Re: indenting in c code

        Feb 22, 2006#3

        This seems to have worked and now highlighting is almost exactly how I want it.
        I have one more request though.
        When I write code for my CS class it needs to fit an 80 column limit so its easy to print. Sometimes I need to split a long function declaration up. I want UltraEdit to indent the next line when I press enter on a line with unclosed parenthesis, so the code looks like this:

        Code: Select all

        int main(this is long, really long, extremely long
                    and so i want to continue it here)
        {
            something;
            like;
            this;
        }
        I know editors like jedit do this automatically. Is this possible by changing settings in UltraEdit? If this is possible ... UltraEdit is the perfect editor for me!

        Michael

        6,686585
        Grand MasterGrand Master
        6,686585

          Re: indenting in c code

          Feb 23, 2006#4

          Maybe this can be done by adding "(" to the line /Indent Strings = and ")" to the line /Unindent Strings = in the wordfile for language C/C++. But I have not tested it.

          Hint: At menu View menu item Set Column Markers set first or second column marker to column 80 and enable the appropriate column marker in the View menu. You will see a thin line now at column 80 so you always know where you have to break a line. You can quickly toggle the showing of this line if you add a hotkey to Show Column Marker x.
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Re: indenting in c code

            Feb 23, 2006#5

            I tried setting ( and ) in the strings, but it doesn't quite do what I want.
            Here is the type of formatting I'm looking for. It's particularly important for long function calls, which happen often in things like MPI.
            It is done by some editors by default.

            Code: Select all

            MPI_Send(&gameboard[row][col],
             1,
             MPI_INT,
             get_rank(row,col,m,n),
             WORKTAG,
             MPI_COMM_WORLD);
            

              Re: indenting in c code

              Feb 23, 2006#6

              This is so frustrating! Now once I deleted everything but { and } from indent, UltraEdit doesn't handle this simple statement:

              Code: Select all

              if(condition)
                  action();
              
              Instead when I do ReIndent Selection UltraEdit does:

              Code: Select all

              if(condition)
              action();
              
              I don't understand why UltraEdit can't have a normal auto-indent system that handles all cases like jedit? This is such an otherwise polished and well done piece of software. I don't understand why at version 11 they still have not set up this feature like almost every other editor out there?

              33
              Basic UserBasic User
              33

                Re: indenting in c code

                Mar 04, 2006#7

                UltraEdit is a general purpose text editor that happens to be good at code as well. jEdit is a specialized code editor. So jEdit supports C/C++ indentation, while UltraEdit only provides simpler indentation rules working for many types of files, not just for specific scripting or programming languages.

                In short, there's no way to do what you want in UltraEdit.  Either you need to change your coding style to suit what the editor is capable of (which basically means using Allman brace positioning style), or you need to switch to an editor that does support your weird coding style.  :P