Menu

Preprocessor options- Indenting #region in CS

Help
2007-03-30
2012-11-10
  • Thunderchile

    Thunderchile - 2007-03-30

    First off, thank you for building this great utility! I've used it for a couple of weeks and it suits my needs perfectly except for one minor detail which I don't know how to handle. How can I indent preprocessor directives in CS code?

    Example problem: I have following small code in file FooClass1.cs
    using System;
    namespace FooNamespace
    {
    public class FooClass1
    {
    public void FooMethod()
    {
    int FooInt = 1;
    #region Here we have a region
    FooInt = 2;
    FooInt++;
    #endregion
    }
    }
    }

    I have the defaults.cfg (coming with uncrustify-0.33-win32.zip) and I use command Uncrustify.exe -c defaults.cfg FooClass1.cs. Should the pp_indent option affect the line with #region directive? The code indents just fine but no matter what value I use for pp_indent (ignore/add/remove/force) the #region and #endregion directives are indented to the start of the line.

    My goal is that the #region and #endregion directives should be indented to the same level as the "int FooInt = 1;" codeline.

    Thanks for the help in advance!

    Best regards
    ~Thunderchile

     
    • Tyler

      Tyler - 2007-10-29

      I'm using the new PP_IF_INDENT option with version 0.40 and I'm getting an error message for this (and similar) blocks:

      I used the default config file, except I used the suggested changes:
      pp_indent_at_level = true
      pp_if_indent_code = true
      pp_indent_if = 0

      Input:
      unsigned char i;
      #if DEBUG == 1
      char line[256];
      #endif
      i = 0;

      Output:
      testfile.c:1: Unmatched PP_IF_INDENT
      testfile.c:1: Unmatched PP_IF_INDENT
      unsigned char i;
      #if DEBUG == 1
      ........char line[256];
      #endif
      ........i = 0;

      If I add a second #endif it gives no warnings, and unindents both #endif lines.
      unsigned char i;
      #if DEBUG == 0
      ........char line[256];
      #endif
      #endif

      If I add {}s around the entire input block, then I don't get the PP_IF_INDENT warnings, but the output still looks wrong:
      {
      ........unsigned char i;
      ........#if DEBUG == 1
      ................char line[256];
      ........#endif
      ................i = 0;
      }

      Thanks,
      Tyler

       
      • Ben Gardner

        Ben Gardner - 2007-10-31

        Would you please submit a bug report and attach your config file?

        Thanks,
        Ben

         
    • Ben Gardner

      Ben Gardner - 2007-03-30

      There isn't specific support for the #region stuff right now.

      I'll add an option to control the indent of the #region/#endregion preprocessors.
      This would work pretty much the same as indent_label.

      Is there a need to specify the indent the code between the region/endregion?
      Ie:
      ...#region
      ...int Foo = 1;
      ...#endregion
      vs
      ...#region
      ......int Foo = 1;
      ...#endregion

      I can also add an option for that, but I don't see why anyone would want to do that...

       
      • Thunderchile

        Thunderchile - 2007-03-30

        Thanks for the fast answer! I don't have a need for specifying the code intendation between #region and #endregion, the first option is enough (for me atleast:)

         
    • Ben Gardner

      Ben Gardner - 2007-03-31

      I changed the default behavior to indent the #region stuff to brace level.
      I don't see why anyone would want it any other way.
      Grab the latest from SVN (r734) and give it a shot.

       
      • Thunderchile

        Thunderchile - 2007-03-31

        Just tried it and seems to work correctly. Good work, thanks!

         
    • Tyler

      Tyler - 2007-09-26

      Hey,
      Thanks for this great tool.

      Is this option still working?
      I'm new so I could easily be doing something stupid, but I seem to get the same results with pp_indent as Force / Add / Remove.

      I've got version 0.39. For add, here's the output I get:

      public void FooMethod()
      {
      int FooInt = 1;
      if (FooInt)
      {
      FooInt++;
      #region Here we have a region
      FooInt = 2;
      FooInt++;
      #endregion
      }
      }

      I expected this:
      public void FooMethod()
      {
      int FooInt = 1;
      if (FooInt)
      {
      FooInt++;
      #region Here we have a region
      FooInt = 2;
      FooInt++;
      #endregion
      }
      }

      Even though you made fun of it, I'd kind of like an option for this:
      public void FooMethod()
      {
      int FooInt = 1;
      if (FooInt)
      {
      FooInt++;
      #region Here we have a region
      FooInt = 2;
      FooInt++;
      #endregion
      }
      }

      Thanks,
      Tyler

       
      • Ben Gardner

        Ben Gardner - 2007-09-26

        pp_indent controls the indent of preprocessors inside #if stuff.

        For example, if pp_indent = force, you'd get output like:
        #if A
        .#include <hdrA.h>
        #else
        .#include <hdrB.h>
        #endif

        That isn't clear from the option description -- I'm open to suggestions on alternate text.

        If a file is processed as "language CS", then the #region stuff is indented to the current level.
        For all other languages, it is controlled with pp_indent.

        It looks like you want two new options.
        One to control the indent of #region stuff, similar to the indent_label option.

        The second option would indent code inside the #region/#endregion preprocessors.

        Would you please create a feature request for those two options?

        Thanks,
        Ben

         
    • Tyler

      Tyler - 2007-09-26

      Sigh. Sorry.

      Maybe more like this:

      I Get:
      public void FooMethod()
      {
      ....int FooInt = 1;
      ....if (FooInt)
      ....{
      ........FooInt++;
      #region Here we have a region
      ........FooInt = 2;
      ........FooInt++;
      #endregion
      ....}
      }

      Expected:
      public void FooMethod()
      {
      ....int FooInt = 1;
      ....if (FooInt)
      ....{
      ........FooInt++;
      ....#region Here we have a region
      ........FooInt = 2;
      ........FooInt++;
      ....#endregion
      ....}
      }

      Would Also Like:
      public void FooMethod()
      {
      ....int FooInt = 1;
      ....if (FooInt)
      ....{
      ........FooInt++;
      ........#region Here we have a region
      ............FooInt = 2;
      ............FooInt++;
      ........#endregion
      ....}
      }

       
    • Tyler

      Tyler - 2007-09-26

      Sorry,

      I may have misled you a little.
      I replied here because it seeemed close to what I'm trying to do.

      My language is just C.

      I have:
      {
      if (Foo)
      {
      Foo++;
      #if DEBUG == 1
      printf();
      #endif
      }
      }

      I'd like to see
      {
      ....if (Foo)
      ....{
      ........Foo++;
      ........#if DEBUG == 1
      ............printf();
      ........#endif
      ....}
      }

      I think I'm still asking for something new. If so I'll submit a request.

      Thanks again,
      Tyler

       
    • Ben Gardner

      Ben Gardner - 2007-09-26

      OK, that makes sense.
      Go ahead and add two feature requests.
      #1 an option indent #if/#else/#endif stuff like indent_label
      #2 an option to indent the code between #if/#else/#endif

      Ben

       
    • Tyler

      Tyler - 2007-10-12

      Thanks for adding these in Ben.
      I got a message that they're done around Oct 1st, but the most recent binary I can find is Sept 25th?
      Sorry if I'm missing something obvious.
      If not, roughly when should I expect a new version?

      Thanks,
      Tyler

       
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.