3
NewbieNewbie
3

    May 29, 2007#16

    Okay, now when I reindent the following:

    Code: Select all

    function a ()
    {
        if (a==1) 
        {
             b = 1;
         }
         else
         {
             c = 2;
         }
    }
    I get the following:

    Code: Select all

    function a ()
    {
        if (a==1) 
        {
             b = 1;
         }
    else
         {
             c = 2;
         }
    }

    6,681583
    Grand MasterGrand Master
    6,681583

      May 29, 2007#17

      Sorry, but if you use different coding styles within your source files you will have never luck to get an UltraEdit indent/unindent setting which works. Maybe you better use some regular expression search and replaces to convert your code into the same coding style and don't mix it anymore in future.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        May 29, 2007#18

        I found a tool from Crossbow Software called SourceFormatX which seems to be very robust and handles any convolution of coding... Guess I'll integrate that one into UE...

        80
        Advanced UserAdvanced User
        80

          Jun 06, 2007#19

          Did you try Artistic Style? I have used it in quite a while, but it comes integrated with UE and worked well for me in the past. I think it supports C++ and Java.

          79
          Advanced UserAdvanced User
          79

            Dec 06, 2013#20

            Mofi wrote:... open the wordfile ... and delete the red part shown below. Save wordfile.txt and now the reindent selection will produce the result which you would have expected.

            /Indent Strings = "{" "if" "else" ":"
            Oh my god! I can't believe I gave up on reindenting selections in UE/UEStudio because the default C/C++ wordfile had that cruft in it.

            Note that even with that change reindent doesn't handle `case` labels very well, but that's a minor consideration compared to the garbage that was produced before where code got pushed continually farther and farther to the right.

            Thanks for having posted the fix; I only wish I came across it earlier. Like years ago.

            Edit:

            Unfortunately, the reindent still doesn't properly handle unbraced if or else clauses with a single statement. It doesn't look like the reindent configuration architecture used by UE (based on dumb token matching) doesn't really support that style anyway. So it's far from perfect, but the fixed wordfile still performs far better than before.

            6,681583
            Grand MasterGrand Master
            6,681583

              Dec 06, 2013#21

              The problem with ReIndent Selection command and the definition of the indent and unindent strings is the different styles available for conditions/loops (if, for, while) with only one statement.

              Code: Select all

              if(iValue == 2) return 0;
              else return 1;
              
              if(iValue == 2)
                 return 0;
              else
                 return 1;
              
              if(iValue == 2)
              {
                 return 0;
              }
              else
              {
                 return 1;
              }
              
              if(iValue == 2)
                 {
                 return 0;
                 }
              else
                 {
                 return 1;
                 }
              
              if(iValue == 2) {
                 return 0;
              }
              else {
                 return 1;
              }
              
              if(iValue == 2) {
                 return 0;
              } else {
                 return 1;
              }
              
              if(iValue == 2) {
                 return 0; }
              else {
                 return 1; }
              
              if(iValue == 2)
              {
                 return 0; }
              else {
                 return 1; }
              Yes, it is nearly unbelievable how humans make simple things really complicated.

              And there are also mixtures of those styles with using { and } for blocks with more than 1 statement and omitting the braces on a single statement.

              If not using consequently the same style in the C/C++/C#/JavaScript and other language files with similar coding syntax, it is impossible to use the simple ReIndent Selection command. In such cases a tool like Artistic Style is necessary which has true language intellisense and does really analyze the content of the file for reformatting it.

              I'm using only first and third style from the example code. This makes it possible to use

              Code: Select all

              /Indent Strings = "{"
              /Unindent Strings = "}"
              I used for UltraEdit scripts very long time the fifth style as this is what JavaScript developers usually use as it saves bytes. But in the meantime I switched for the scripts also to the style I use in C/C++ files as I found out that this is the best style also for my UltraEdit scripts with JavaScript code. I write very often comments at beginning of a block below if, for, while and I usually want a blank line between the condition/loop and the comment line for better readability. If this blank line is really completely empty or contains the opening { does not really matter in UltraEdit scripts where it is not necessary to save bytes as in JavaScript files or HTML files which must be downloaded by users. With { in same column as matching } it is much easier to see where a block begins and where it ends and if the structure is correct.


              Artistic Style support was improved with UE v20.00 by installing together with UE v20.00 version 2.03 of Artistic Style and updating the Artistic Style Formatter dialog to support all the options of this version of the tool. But I must add that the support for all the options of Artistic Style v2.03 was not done optimal by IDM as I found out during reading very, very carefully the documentation and revising the help page Artistic Style Formatter dialog. The space padding options controlling formatting around parentheses would have been better offered separately as check box options or in a multi-select list as it should be possible to combine them to get the wanted formatting.

              In the meantime the developers group of Artistic Style released v2.04 with some more new options and new features. This latest version of Artistic Style can be used from within UE v20.00 / UES v14.00 only by replacing file astyle.exe in subdirectory GNU of the program files directory of UE / UES and using a manually created options file specified in the Artistic Style Formatter dialog. Using a manually created options file for astyle.exe is currently also the only possibility combining the parentheses options.

              Note: Help page Artistic Style Formatter dialog within uedit32.chm was greatly improved in updated help installed with UE v20.00.0.1054 by coloring the characters which indicate the changes made on using an option. This helps to understand the differences between the available options controlling the formatting.

              Update:
              Artistic Style v2.04 is installed with UltraEdit v21.00.0.1027. The new features of this version in comparison to v2.03 are not supported via the dialog and can be used therefore only with using an options file. But the space padding options are now check box options which make it possible to enable multiple padding options to get the wanted format. Further with pressing button Cancel now all modifications on the Artistic Style options made since opening the dialog are discarded which was not the case in all previous versions of UltraEdit. And finally for those interested in how UltraEdit will call astyle.exe according to currently selected and enabled options in the dialog, there is a box at bottom displaying the command line options according to the settings in the dialog.
              Best regards from an UC/UE/UES for Windows user from Austria

              Read more posts (-9 remaining)